livekit-client 2.15.8 → 2.15.10
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 +589 -205
- 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/api/SignalClient.d.ts +31 -2
- package/dist/src/api/SignalClient.d.ts.map +1 -1
- package/dist/src/api/WebSocketStream.d.ts +29 -0
- package/dist/src/api/WebSocketStream.d.ts.map +1 -0
- package/dist/src/api/utils.d.ts +2 -0
- package/dist/src/api/utils.d.ts.map +1 -1
- package/dist/src/connectionHelper/checks/turn.d.ts.map +1 -1
- package/dist/src/connectionHelper/checks/websocket.d.ts.map +1 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/options.d.ts +6 -0
- package/dist/src/options.d.ts.map +1 -1
- package/dist/src/room/PCTransport.d.ts +1 -0
- package/dist/src/room/PCTransport.d.ts.map +1 -1
- package/dist/src/room/PCTransportManager.d.ts +6 -4
- package/dist/src/room/PCTransportManager.d.ts.map +1 -1
- package/dist/src/room/RTCEngine.d.ts +1 -1
- package/dist/src/room/RTCEngine.d.ts.map +1 -1
- package/dist/src/room/Room.d.ts.map +1 -1
- package/dist/src/room/defaults.d.ts.map +1 -1
- package/dist/src/room/token-source/utils.d.ts +1 -1
- package/dist/src/room/token-source/utils.d.ts.map +1 -1
- package/dist/src/room/utils.d.ts +6 -0
- package/dist/src/room/utils.d.ts.map +1 -1
- package/dist/ts4.2/api/SignalClient.d.ts +31 -2
- package/dist/ts4.2/api/WebSocketStream.d.ts +29 -0
- package/dist/ts4.2/api/utils.d.ts +2 -0
- package/dist/ts4.2/index.d.ts +2 -2
- package/dist/ts4.2/options.d.ts +6 -0
- package/dist/ts4.2/room/PCTransport.d.ts +1 -0
- package/dist/ts4.2/room/PCTransportManager.d.ts +6 -4
- package/dist/ts4.2/room/RTCEngine.d.ts +1 -1
- package/dist/ts4.2/room/token-source/utils.d.ts +1 -1
- package/dist/ts4.2/room/utils.d.ts +6 -0
- package/package.json +1 -1
- package/src/api/SignalClient.test.ts +769 -0
- package/src/api/SignalClient.ts +319 -162
- package/src/api/WebSocketStream.test.ts +625 -0
- package/src/api/WebSocketStream.ts +118 -0
- package/src/api/utils.ts +10 -0
- package/src/connectionHelper/checks/turn.ts +1 -0
- package/src/connectionHelper/checks/webrtc.ts +1 -1
- package/src/connectionHelper/checks/websocket.ts +1 -0
- package/src/index.ts +2 -0
- package/src/options.ts +7 -0
- package/src/room/PCTransport.ts +7 -3
- package/src/room/PCTransportManager.ts +39 -35
- package/src/room/RTCEngine.ts +59 -17
- package/src/room/Room.ts +5 -2
- package/src/room/defaults.ts +1 -0
- package/src/room/participant/LocalParticipant.ts +2 -2
- package/src/room/token-source/TokenSource.ts +2 -2
- package/src/room/token-source/utils.test.ts +63 -0
- package/src/room/token-source/utils.ts +10 -5
- package/src/room/utils.ts +29 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { TokenSourceResponse } from '@livekit/protocol';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { decodeTokenPayload, isResponseTokenValid } from './utils';
|
|
4
|
+
|
|
5
|
+
// Test JWTs created for test purposes only.
|
|
6
|
+
// None of these actually auth against anything.
|
|
7
|
+
const TOKENS = {
|
|
8
|
+
// Nbf date set at 1234567890 seconds (Fri Feb 13 2009 23:31:30 GMT+0000)
|
|
9
|
+
// Exp date set at 9876543210 seconds (Fri Dec 22 2282 20:13:30 GMT+0000)
|
|
10
|
+
// A dummy roomConfig value is also set, with room_config.name = "test room name", and room_config.agents = [{"agentName": "test agent name","metadata":"test agent metadata"}]
|
|
11
|
+
VALID:
|
|
12
|
+
'eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwiZXhwIjo5ODc2NTQzMjEwLCJuYmYiOjEyMzQ1Njc4OTAsImlhdCI6MTIzNDU2Nzg5MCwicm9vbUNvbmZpZyI6eyJuYW1lIjoidGVzdCByb29tIG5hbWUiLCJlbXB0eVRpbWVvdXQiOjAsImRlcGFydHVyZVRpbWVvdXQiOjAsIm1heFBhcnRpY2lwYW50cyI6MCwibWluUGxheW91dERlbGF5IjowLCJtYXhQbGF5b3V0RGVsYXkiOjAsInN5bmNTdHJlYW1zIjpmYWxzZSwiYWdlbnRzIjpbeyJhZ2VudE5hbWUiOiJ0ZXN0IGFnZW50IG5hbWUiLCJtZXRhZGF0YSI6InRlc3QgYWdlbnQgbWV0YWRhdGEifV0sIm1ldGFkYXRhIjoiIn19.EDetpHG8cSubaApzgWJaQrpCiSy9KDBlfCfVdIydbQ-_CHiNnXOK_f_mCJbTf9A-duT1jmvPOkLrkkWFT60XPQ',
|
|
13
|
+
|
|
14
|
+
// Nbf date set at 9876543210 seconds (Fri Dec 22 2282 20:13:30 GMT+0000)
|
|
15
|
+
// Exp date set at 9876543211 seconds (Fri Dec 22 2282 20:13:31 GMT+0000)
|
|
16
|
+
NBF_IN_FUTURE:
|
|
17
|
+
'eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwiZXhwIjo5ODc2NTQzMjExLCJuYmYiOjk4NzY1NDMyMTAsImlhdCI6MTIzNDU2Nzg5MH0.DcMmdKrD76eJg7IUBZqoTRDvBaXtCcwtuE5h7IwVXhG_6nvgxN_ix30_AmLgnYhvhkN-x9dTRPoHg-CME72AbQ',
|
|
18
|
+
|
|
19
|
+
// Nbf date set at 1234567890 seconds (Fri Feb 13 2009 23:31:30 GMT+0000)
|
|
20
|
+
// Exp date set at 1234567891 seconds (Fri Feb 13 2009 23:31:31 GMT+0000)
|
|
21
|
+
EXP_IN_PAST:
|
|
22
|
+
'eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwiZXhwIjoxMjM0NTY3ODkxLCJuYmYiOjEyMzQ1Njc4OTAsImlhdCI6MTIzNDU2Nzg5MH0.OYP1NITayotBYt0mioInLJmaIM0bHyyR-yG6iwKyQDzhoGha15qbsc7dOJlzz4za1iW5EzCgjc2_xGxqaSu5XA',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
describe('isResponseTokenValid', () => {
|
|
26
|
+
it('should find a valid jwt not expired', () => {
|
|
27
|
+
const isValid = isResponseTokenValid(
|
|
28
|
+
TokenSourceResponse.fromJson({
|
|
29
|
+
serverUrl: 'ws://localhost:7800',
|
|
30
|
+
participantToken: TOKENS.VALID,
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
33
|
+
expect(isValid).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
it('should find a long ago expired jwt as expired', () => {
|
|
36
|
+
const isValid = isResponseTokenValid(
|
|
37
|
+
TokenSourceResponse.fromJson({
|
|
38
|
+
serverUrl: 'ws://localhost:7800',
|
|
39
|
+
participantToken: TOKENS.EXP_IN_PAST,
|
|
40
|
+
}),
|
|
41
|
+
);
|
|
42
|
+
expect(isValid).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
it('should find a jwt that has not become active yet as expired', () => {
|
|
45
|
+
const isValid = isResponseTokenValid(
|
|
46
|
+
TokenSourceResponse.fromJson({
|
|
47
|
+
serverUrl: 'ws://localhost:7800',
|
|
48
|
+
participantToken: TOKENS.NBF_IN_FUTURE,
|
|
49
|
+
}),
|
|
50
|
+
);
|
|
51
|
+
expect(isValid).toBe(false);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe('decodeTokenPayload', () => {
|
|
56
|
+
it('should extract roomconfig metadata from a token', () => {
|
|
57
|
+
const payload = decodeTokenPayload(TOKENS.VALID);
|
|
58
|
+
expect(payload.roomConfig?.name).toBe('test room name');
|
|
59
|
+
expect(payload.roomConfig?.agents).toHaveLength(1);
|
|
60
|
+
expect(payload.roomConfig?.agents![0].agentName).toBe('test agent name');
|
|
61
|
+
expect(payload.roomConfig?.agents![0].metadata).toBe('test agent metadata');
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -5,16 +5,21 @@ import type { RoomConfigurationObject, TokenPayload } from './types';
|
|
|
5
5
|
const ONE_SECOND_IN_MILLISECONDS = 1000;
|
|
6
6
|
const ONE_MINUTE_IN_MILLISECONDS = 60 * ONE_SECOND_IN_MILLISECONDS;
|
|
7
7
|
|
|
8
|
-
export function
|
|
8
|
+
export function isResponseTokenValid(response: TokenSourceResponse) {
|
|
9
9
|
const jwtPayload = decodeTokenPayload(response.participantToken);
|
|
10
|
-
if (!jwtPayload?.exp) {
|
|
10
|
+
if (!jwtPayload?.nbf || !jwtPayload?.exp) {
|
|
11
11
|
return true;
|
|
12
12
|
}
|
|
13
|
-
const expInMilliseconds = jwtPayload.exp * ONE_SECOND_IN_MILLISECONDS;
|
|
14
|
-
const expiresAt = new Date(expInMilliseconds - ONE_MINUTE_IN_MILLISECONDS);
|
|
15
13
|
|
|
16
14
|
const now = new Date();
|
|
17
|
-
|
|
15
|
+
|
|
16
|
+
const nbfInMilliseconds = jwtPayload.nbf * ONE_SECOND_IN_MILLISECONDS;
|
|
17
|
+
const nbfDate = new Date(nbfInMilliseconds);
|
|
18
|
+
|
|
19
|
+
const expInMilliseconds = jwtPayload.exp * ONE_SECOND_IN_MILLISECONDS;
|
|
20
|
+
const expDate = new Date(expInMilliseconds - ONE_MINUTE_IN_MILLISECONDS);
|
|
21
|
+
|
|
22
|
+
return nbfDate <= now && expDate > now;
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
export function decodeTokenPayload(token: string) {
|
package/src/room/utils.ts
CHANGED
|
@@ -151,6 +151,15 @@ export function supportsSetSinkId(elm?: HTMLMediaElement): boolean {
|
|
|
151
151
|
return 'setSinkId' in elm;
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Checks whether or not setting an audio output via {@link Room#setActiveDevice}
|
|
156
|
+
* is supported for the current browser.
|
|
157
|
+
*/
|
|
158
|
+
export function supportsAudioOutputSelection(): boolean {
|
|
159
|
+
// Note: this is method publicly exported under a user friendly name and currently only proxying `supportsSetSinkId`
|
|
160
|
+
return supportsSetSinkId();
|
|
161
|
+
}
|
|
162
|
+
|
|
154
163
|
export function isBrowserSupported() {
|
|
155
164
|
if (typeof RTCPeerConnection === 'undefined') {
|
|
156
165
|
return false;
|
|
@@ -418,6 +427,26 @@ export function getEmptyAudioStreamTrack() {
|
|
|
418
427
|
return emptyAudioStreamTrack.clone();
|
|
419
428
|
}
|
|
420
429
|
|
|
430
|
+
export function getStereoAudioStreamTrack() {
|
|
431
|
+
const ctx = new AudioContext();
|
|
432
|
+
const oscLeft = ctx.createOscillator();
|
|
433
|
+
const oscRight = ctx.createOscillator();
|
|
434
|
+
oscLeft.frequency.value = 440;
|
|
435
|
+
oscRight.frequency.value = 220;
|
|
436
|
+
const merger = ctx.createChannelMerger(2);
|
|
437
|
+
oscLeft.connect(merger, 0, 0); // left channel
|
|
438
|
+
oscRight.connect(merger, 0, 1); // right channel
|
|
439
|
+
const dst = ctx.createMediaStreamDestination();
|
|
440
|
+
merger.connect(dst);
|
|
441
|
+
oscLeft.start();
|
|
442
|
+
oscRight.start();
|
|
443
|
+
const [stereoTrack] = dst.stream.getAudioTracks();
|
|
444
|
+
if (!stereoTrack) {
|
|
445
|
+
throw Error('Could not get stereo media stream audio track');
|
|
446
|
+
}
|
|
447
|
+
return stereoTrack;
|
|
448
|
+
}
|
|
449
|
+
|
|
421
450
|
export class Future<T> {
|
|
422
451
|
promise: Promise<T>;
|
|
423
452
|
|