livekit-client 2.1.0 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/livekit-client.esm.mjs +2212 -2100
- package/dist/livekit-client.esm.mjs.map +1 -1
- package/dist/livekit-client.umd.js +1 -1
- package/dist/livekit-client.umd.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/room/PCTransport.d.ts.map +1 -1
- package/dist/src/room/RTCEngine.d.ts +4 -4
- package/dist/src/room/RTCEngine.d.ts.map +1 -1
- package/dist/src/room/Room.d.ts +5 -2
- package/dist/src/room/Room.d.ts.map +1 -1
- package/dist/src/room/events.d.ts +20 -1
- package/dist/src/room/events.d.ts.map +1 -1
- package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
- package/dist/src/room/participant/Participant.d.ts +2 -1
- package/dist/src/room/participant/Participant.d.ts.map +1 -1
- package/dist/src/room/track/RemoteTrack.d.ts +1 -0
- package/dist/src/room/track/RemoteTrack.d.ts.map +1 -1
- package/dist/src/room/track/Track.d.ts +4 -0
- package/dist/src/room/track/Track.d.ts.map +1 -1
- package/dist/src/room/track/TrackPublication.d.ts +3 -1
- package/dist/src/room/track/TrackPublication.d.ts.map +1 -1
- package/dist/src/room/types.d.ts +8 -0
- package/dist/src/room/types.d.ts.map +1 -1
- package/dist/src/room/utils.d.ts +4 -2
- package/dist/src/room/utils.d.ts.map +1 -1
- package/dist/src/utils/browserParser.d.ts +1 -0
- package/dist/src/utils/browserParser.d.ts.map +1 -1
- package/dist/ts4.2/src/index.d.ts +1 -1
- package/dist/ts4.2/src/room/RTCEngine.d.ts +4 -4
- package/dist/ts4.2/src/room/Room.d.ts +5 -2
- package/dist/ts4.2/src/room/events.d.ts +20 -1
- package/dist/ts4.2/src/room/participant/Participant.d.ts +2 -1
- package/dist/ts4.2/src/room/track/RemoteTrack.d.ts +1 -0
- package/dist/ts4.2/src/room/track/Track.d.ts +4 -0
- package/dist/ts4.2/src/room/track/TrackPublication.d.ts +3 -1
- package/dist/ts4.2/src/room/types.d.ts +8 -0
- package/dist/ts4.2/src/room/utils.d.ts +4 -2
- package/dist/ts4.2/src/utils/browserParser.d.ts +1 -0
- package/package.json +8 -8
- package/src/index.ts +1 -1
- package/src/room/PCTransport.ts +0 -2
- package/src/room/RTCEngine.ts +11 -61
- package/src/room/Room.ts +27 -1
- package/src/room/events.ts +23 -0
- package/src/room/participant/LocalParticipant.ts +3 -5
- package/src/room/participant/Participant.ts +5 -1
- package/src/room/track/RemoteTrack.ts +13 -0
- package/src/room/track/Track.ts +9 -0
- package/src/room/track/TrackPublication.ts +3 -1
- package/src/room/types.ts +9 -0
- package/src/room/utils.ts +46 -29
- package/src/utils/browserParser.test.ts +4 -0
- package/src/utils/browserParser.ts +11 -1
package/src/room/utils.ts
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
import { ClientInfo, ClientInfo_SDK } from '@livekit/protocol';
|
2
|
-
import type { DetectableBrowser } from '../utils/browserParser';
|
1
|
+
import { ClientInfo, ClientInfo_SDK, Transcription as TranscriptionModel } from '@livekit/protocol';
|
3
2
|
import { getBrowser } from '../utils/browserParser';
|
4
3
|
import { protocolVersion, version } from '../version';
|
5
4
|
import CriticalTimers from './timers';
|
@@ -7,7 +6,7 @@ import type LocalAudioTrack from './track/LocalAudioTrack';
|
|
7
6
|
import type RemoteAudioTrack from './track/RemoteAudioTrack';
|
8
7
|
import { VideoCodec, videoCodecs } from './track/options';
|
9
8
|
import { getNewAudioContext } from './track/utils';
|
10
|
-
import type { LiveKitReactNativeInfo } from './types';
|
9
|
+
import type { LiveKitReactNativeInfo, TranscriptionSegment } from './types';
|
11
10
|
|
12
11
|
const separator = '|';
|
13
12
|
export const ddExtensionURI =
|
@@ -107,31 +106,6 @@ export function supportsSetSinkId(elm?: HTMLMediaElement): boolean {
|
|
107
106
|
return 'setSinkId' in elm;
|
108
107
|
}
|
109
108
|
|
110
|
-
const setCodecPreferencesVersions: Record<DetectableBrowser, string> = {
|
111
|
-
Chrome: '100',
|
112
|
-
Safari: '15',
|
113
|
-
Firefox: '100',
|
114
|
-
};
|
115
|
-
|
116
|
-
export function supportsSetCodecPreferences(transceiver: RTCRtpTransceiver): boolean {
|
117
|
-
if (!isWeb()) {
|
118
|
-
return false;
|
119
|
-
}
|
120
|
-
if (!('setCodecPreferences' in transceiver)) {
|
121
|
-
return false;
|
122
|
-
}
|
123
|
-
const browser = getBrowser();
|
124
|
-
if (!browser?.name || !browser.version) {
|
125
|
-
// version is required
|
126
|
-
return false;
|
127
|
-
}
|
128
|
-
const v = setCodecPreferencesVersions[browser.name];
|
129
|
-
if (v) {
|
130
|
-
return compareVersions(browser.version, v) >= 0;
|
131
|
-
}
|
132
|
-
return false;
|
133
|
-
}
|
134
|
-
|
135
109
|
export function isBrowserSupported() {
|
136
110
|
if (typeof RTCPeerConnection === 'undefined') {
|
137
111
|
return false;
|
@@ -158,7 +132,35 @@ export function isSafari17(): boolean {
|
|
158
132
|
|
159
133
|
export function isMobile(): boolean {
|
160
134
|
if (!isWeb()) return false;
|
161
|
-
|
135
|
+
|
136
|
+
return (
|
137
|
+
// @ts-expect-error `userAgentData` is not yet part of typescript
|
138
|
+
navigator.userAgentData?.mobile ??
|
139
|
+
/Tablet|iPad|Mobile|Android|BlackBerry/.test(navigator.userAgent)
|
140
|
+
);
|
141
|
+
}
|
142
|
+
|
143
|
+
export function isE2EESimulcastSupported() {
|
144
|
+
const browser = getBrowser();
|
145
|
+
const supportedSafariVersion = '17.2'; // see https://bugs.webkit.org/show_bug.cgi?id=257803
|
146
|
+
if (browser) {
|
147
|
+
if (browser.name !== 'Safari' && browser.os !== 'iOS') {
|
148
|
+
return true;
|
149
|
+
} else if (
|
150
|
+
browser.os === 'iOS' &&
|
151
|
+
browser.osVersion &&
|
152
|
+
compareVersions(supportedSafariVersion, browser.osVersion) >= 0
|
153
|
+
) {
|
154
|
+
return true;
|
155
|
+
} else if (
|
156
|
+
browser.name === 'Safari' &&
|
157
|
+
compareVersions(supportedSafariVersion, browser.version) >= 0
|
158
|
+
) {
|
159
|
+
return true;
|
160
|
+
} else {
|
161
|
+
return false;
|
162
|
+
}
|
163
|
+
}
|
162
164
|
}
|
163
165
|
|
164
166
|
export function isWeb(): boolean {
|
@@ -525,3 +527,18 @@ export function toHttpUrl(url: string): string {
|
|
525
527
|
}
|
526
528
|
return url;
|
527
529
|
}
|
530
|
+
|
531
|
+
export function extractTranscriptionSegments(
|
532
|
+
transcription: TranscriptionModel,
|
533
|
+
): TranscriptionSegment[] {
|
534
|
+
return transcription.segments.map(({ id, text, language, startTime, endTime, final }) => {
|
535
|
+
return {
|
536
|
+
id,
|
537
|
+
text,
|
538
|
+
startTime: Number.parseInt(startTime.toString()),
|
539
|
+
endTime: Number.parseInt(endTime.toString()),
|
540
|
+
final,
|
541
|
+
language,
|
542
|
+
};
|
543
|
+
});
|
544
|
+
}
|
@@ -29,12 +29,14 @@ describe('browser parser', () => {
|
|
29
29
|
expect(details?.name).toBe('Safari');
|
30
30
|
expect(details?.version).toBe('16.3');
|
31
31
|
expect(details?.os).toBe('macOS');
|
32
|
+
expect(details?.osVersion).toBe('10.15.7');
|
32
33
|
});
|
33
34
|
it('parses Safari iOS correctly', () => {
|
34
35
|
const details = getBrowser(iOSSafariUA, true);
|
35
36
|
expect(details?.name).toBe('Safari');
|
36
37
|
expect(details?.version).toBe('16.5');
|
37
38
|
expect(details?.os).toBe('iOS');
|
39
|
+
expect(details?.osVersion).toBe('16.5.1');
|
38
40
|
});
|
39
41
|
it('parses Firefox correctly', () => {
|
40
42
|
const details = getBrowser(firefoxUA, true);
|
@@ -46,6 +48,7 @@ describe('browser parser', () => {
|
|
46
48
|
expect(details?.name).toBe('Firefox');
|
47
49
|
expect(details?.version).toBe('115.0');
|
48
50
|
expect(details?.os).toBe('iOS');
|
51
|
+
expect(details?.osVersion).toBe('13.4.1');
|
49
52
|
});
|
50
53
|
it('parses Chrome correctly', () => {
|
51
54
|
const details = getBrowser(chromeUA, true);
|
@@ -57,6 +60,7 @@ describe('browser parser', () => {
|
|
57
60
|
expect(details?.name).toBe('Chrome');
|
58
61
|
expect(details?.version).toBe('115.0.5790.130');
|
59
62
|
expect(details?.os).toBe('iOS');
|
63
|
+
expect(details?.osVersion).toBe('16.5');
|
60
64
|
});
|
61
65
|
it('detects brave as chromium based', () => {
|
62
66
|
const details = getBrowser(braveUA, true);
|
@@ -10,6 +10,7 @@ export type BrowserDetails = {
|
|
10
10
|
name: DetectableBrowser;
|
11
11
|
version: string;
|
12
12
|
os?: DetectableOS;
|
13
|
+
osVersion?: string;
|
13
14
|
};
|
14
15
|
|
15
16
|
let browserDetails: BrowserDetails | undefined;
|
@@ -17,7 +18,7 @@ let browserDetails: BrowserDetails | undefined;
|
|
17
18
|
/**
|
18
19
|
* @internal
|
19
20
|
*/
|
20
|
-
export function getBrowser(userAgent?: string, force = true) {
|
21
|
+
export function getBrowser(userAgent?: string, force = true): BrowserDetails | undefined {
|
21
22
|
if (typeof userAgent === 'undefined' && typeof navigator === 'undefined') {
|
22
23
|
return;
|
23
24
|
}
|
@@ -37,6 +38,7 @@ const browsersList = [
|
|
37
38
|
name: 'Firefox',
|
38
39
|
version: getMatch(/(?:firefox|iceweasel|fxios)[\s/](\d+(\.?_?\d+)+)/i, ua),
|
39
40
|
os: ua.toLowerCase().includes('fxios') ? 'iOS' : undefined,
|
41
|
+
osVersion: getOSVersion(ua),
|
40
42
|
};
|
41
43
|
return browser;
|
42
44
|
},
|
@@ -48,6 +50,7 @@ const browsersList = [
|
|
48
50
|
name: 'Chrome',
|
49
51
|
version: getMatch(/(?:chrome|chromium|crios|crmo)\/(\d+(\.?_?\d+)+)/i, ua),
|
50
52
|
os: ua.toLowerCase().includes('crios') ? 'iOS' : undefined,
|
53
|
+
osVersion: getOSVersion(ua),
|
51
54
|
};
|
52
55
|
|
53
56
|
return browser;
|
@@ -61,6 +64,7 @@ const browsersList = [
|
|
61
64
|
name: 'Safari',
|
62
65
|
version: getMatch(commonVersionIdentifier, ua),
|
63
66
|
os: ua.includes('mobile/') ? 'iOS' : 'macOS',
|
67
|
+
osVersion: getOSVersion(ua),
|
64
68
|
};
|
65
69
|
|
66
70
|
return browser;
|
@@ -72,3 +76,9 @@ function getMatch(exp: RegExp, ua: string, id = 1) {
|
|
72
76
|
const match = ua.match(exp);
|
73
77
|
return (match && match.length >= id && match[id]) || '';
|
74
78
|
}
|
79
|
+
|
80
|
+
function getOSVersion(ua: string) {
|
81
|
+
return ua.includes('mac os')
|
82
|
+
? getMatch(/\(.+?(\d+_\d+(:?_\d+)?)/, ua, 1).replace(/_/g, '.')
|
83
|
+
: undefined;
|
84
|
+
}
|