livekit-client 2.24.0 → 2.24.1
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/README.md +3 -4
- package/dist/core/api/SignalClient.mjs +3 -1
- package/dist/core/api/SignalClient.mjs.map +1 -1
- package/dist/core/e2ee/E2eeManager.mjs +7 -10
- package/dist/core/e2ee/E2eeManager.mjs.map +1 -1
- package/dist/core/package.json.mjs +1 -1
- package/dist/core/room/rpc/client/RpcClientManager.mjs +18 -0
- package/dist/core/room/rpc/client/RpcClientManager.mjs.map +1 -1
- package/dist/core/room/rpc/extension.mjs +1 -0
- package/dist/core/room/rpc/extension.mjs.map +1 -1
- package/dist/core/room/rpc/utils.mjs +2 -0
- package/dist/core/room/rpc/utils.mjs.map +1 -1
- package/dist/core/room/utils.mjs +4 -1
- package/dist/core/room/utils.mjs.map +1 -1
- package/dist/core/ts4.2/e2ee/E2eeManager.d.ts +1 -0
- package/dist/core/ts4.2/room/rpc/extension.d.ts +3 -3
- package/dist/core/ts4.2/room/rpc/utils.d.ts +1 -0
- package/dist/core/types/src/e2ee/E2eeManager.d.ts +1 -0
- package/dist/core/types/src/room/rpc/extension.d.ts +3 -3
- package/dist/core/types/src/room/rpc/utils.d.ts +1 -0
- package/dist/livekit-client.e2ee.worker.js +1 -1
- package/dist/livekit-client.e2ee.worker.js.map +1 -1
- package/dist/livekit-client.e2ee.worker.mjs +6 -3
- package/dist/livekit-client.e2ee.worker.mjs.map +1 -1
- package/dist/livekit-client.esm.mjs +48 -21
- package/dist/livekit-client.esm.mjs.map +1 -1
- package/dist/livekit-client.fm.worker.js.map +1 -1
- package/dist/livekit-client.fm.worker.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.map +1 -1
- package/dist/src/e2ee/E2eeManager.d.ts +1 -0
- package/dist/src/e2ee/E2eeManager.d.ts.map +1 -1
- package/dist/src/e2ee/worker/FrameCryptor.d.ts.map +1 -1
- package/dist/src/room/rpc/client/RpcClientManager.d.ts +5 -0
- package/dist/src/room/rpc/client/RpcClientManager.d.ts.map +1 -1
- package/dist/src/room/rpc/extension.d.ts +3 -3
- package/dist/src/room/rpc/extension.d.ts.map +1 -1
- package/dist/src/room/rpc/legacyExtension.d.ts +1 -1
- package/dist/src/room/rpc/utils.d.ts +1 -0
- package/dist/src/room/rpc/utils.d.ts.map +1 -1
- package/dist/src/room/utils.d.ts.map +1 -1
- package/dist/ts4.2/e2ee/E2eeManager.d.ts +1 -0
- package/dist/ts4.2/room/rpc/client/RpcClientManager.d.ts +5 -0
- package/dist/ts4.2/room/rpc/extension.d.ts +3 -3
- package/dist/ts4.2/room/rpc/legacyExtension.d.ts +1 -1
- package/dist/ts4.2/room/rpc/utils.d.ts +1 -0
- package/package.json +1 -1
- package/src/api/SignalClient.test.ts +43 -0
- package/src/api/SignalClient.ts +6 -1
- package/src/e2ee/E2eeManager.test.ts +86 -2
- package/src/e2ee/E2eeManager.ts +11 -9
- package/src/e2ee/worker/FrameCryptor.test.ts +26 -0
- package/src/e2ee/worker/FrameCryptor.ts +7 -4
- package/src/room/Room.test.ts +24 -0
- package/src/room/rpc/client/RpcClientManager.test.ts +29 -0
- package/src/room/rpc/client/RpcClientManager.ts +17 -0
- package/src/room/rpc/extension.ts +4 -1
- package/src/room/rpc/utils.ts +2 -0
- package/src/room/utils.test.ts +36 -1
- package/src/room/utils.ts +11 -1
|
@@ -337,6 +337,35 @@ describe('RpcClientManager', () => {
|
|
|
337
337
|
await expect(completionPromise).rejects.toThrow('Recipient disconnected');
|
|
338
338
|
});
|
|
339
339
|
|
|
340
|
+
it('rejects every pending RPC and clears its timers when the room disconnects', async () => {
|
|
341
|
+
vi.useFakeTimers();
|
|
342
|
+
|
|
343
|
+
try {
|
|
344
|
+
const [ackedId, ackedPromise] = await rpcClientManager.performRpc({
|
|
345
|
+
destinationIdentity: 'remote-a',
|
|
346
|
+
method: 'm',
|
|
347
|
+
payload: 'p',
|
|
348
|
+
responseTimeout: 300_000,
|
|
349
|
+
});
|
|
350
|
+
rpcClientManager.handleIncomingRpcAck(ackedId);
|
|
351
|
+
|
|
352
|
+
const [, unackedPromise] = await rpcClientManager.performRpc({
|
|
353
|
+
destinationIdentity: 'remote-b',
|
|
354
|
+
method: 'm',
|
|
355
|
+
payload: 'p',
|
|
356
|
+
responseTimeout: 300_000,
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
rpcClientManager.handleRoomDisconnected();
|
|
360
|
+
|
|
361
|
+
await expect(ackedPromise).rejects.toThrow('Connection closed');
|
|
362
|
+
await expect(unackedPromise).rejects.toThrow('Connection closed');
|
|
363
|
+
expect(vi.getTimerCount()).toBe(0);
|
|
364
|
+
} finally {
|
|
365
|
+
vi.useRealTimers();
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
|
|
340
369
|
it('should send V2 RPC request and ensure that a non matching response does not complete the RPC', async () => {
|
|
341
370
|
// Step 1: send an example rpc request
|
|
342
371
|
const [, completionPromise] = await rpcClientManager.performRpc({
|
|
@@ -283,4 +283,21 @@ export default class RpcClientManager extends (EventEmitter as new () => TypedEm
|
|
|
283
283
|
}
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* No ack or response can arrive once the local participant has left the room.
|
|
289
|
+
* @internal
|
|
290
|
+
*/
|
|
291
|
+
handleRoomDisconnected() {
|
|
292
|
+
for (const { resolve } of this.pendingAcks.values()) {
|
|
293
|
+
// clears the ack timer
|
|
294
|
+
resolve();
|
|
295
|
+
}
|
|
296
|
+
this.pendingAcks.clear();
|
|
297
|
+
|
|
298
|
+
for (const { completionFuture } of this.pendingResponses.values()) {
|
|
299
|
+
completionFuture.reject?.(RpcError.builtIn('CONNECTION_CLOSED'));
|
|
300
|
+
}
|
|
301
|
+
this.pendingResponses.clear();
|
|
302
|
+
}
|
|
286
303
|
}
|
|
@@ -6,6 +6,7 @@ import { DataChannelKind } from '../data-channel/types';
|
|
|
6
6
|
import { dataStreams } from '../data-stream/extension';
|
|
7
7
|
import { RoomEvent } from '../events';
|
|
8
8
|
import type {
|
|
9
|
+
ConnectionHooks,
|
|
9
10
|
DataPacketOwner,
|
|
10
11
|
ExtensionContext,
|
|
11
12
|
LocalParticipantApiProvider,
|
|
@@ -85,7 +86,8 @@ export const rpc = {
|
|
|
85
86
|
ctx: ExtensionContext,
|
|
86
87
|
): RoomApiProvider<RpcRoomApi> &
|
|
87
88
|
LocalParticipantApiProvider<RpcLocalParticipantApi> &
|
|
88
|
-
DataPacketOwner
|
|
89
|
+
DataPacketOwner &
|
|
90
|
+
ConnectionHooks {
|
|
89
91
|
const { incoming, outgoing } = ctx.get(dataStreams);
|
|
90
92
|
const clientProtocol = (identity: string) =>
|
|
91
93
|
room.remoteParticipants.get(identity)?.clientProtocol ?? CLIENT_PROTOCOL_DEFAULT;
|
|
@@ -149,6 +151,7 @@ export const rpc = {
|
|
|
149
151
|
},
|
|
150
152
|
rpcAck: (ack) => client.handleIncomingRpcAck(ack.requestId),
|
|
151
153
|
},
|
|
154
|
+
onDisconnect: () => client.handleRoomDisconnected(),
|
|
152
155
|
room: { registerRpcMethod, unregisterRpcMethod },
|
|
153
156
|
localParticipant: {
|
|
154
157
|
performRpc: (params) =>
|
package/src/room/rpc/utils.ts
CHANGED
|
@@ -106,6 +106,7 @@ export class RpcError extends Error {
|
|
|
106
106
|
RECIPIENT_DISCONNECTED: 1503,
|
|
107
107
|
RESPONSE_PAYLOAD_TOO_LARGE: 1504,
|
|
108
108
|
SEND_FAILED: 1505,
|
|
109
|
+
CONNECTION_CLOSED: 1506,
|
|
109
110
|
|
|
110
111
|
UNSUPPORTED_METHOD: 1400,
|
|
111
112
|
RECIPIENT_NOT_FOUND: 1401,
|
|
@@ -124,6 +125,7 @@ export class RpcError extends Error {
|
|
|
124
125
|
RECIPIENT_DISCONNECTED: 'Recipient disconnected',
|
|
125
126
|
RESPONSE_PAYLOAD_TOO_LARGE: 'Response payload too large',
|
|
126
127
|
SEND_FAILED: 'Failed to send',
|
|
128
|
+
CONNECTION_CLOSED: 'Connection closed',
|
|
127
129
|
|
|
128
130
|
UNSUPPORTED_METHOD: 'Method not supported at destination',
|
|
129
131
|
RECIPIENT_NOT_FOUND: 'Recipient not found',
|
package/src/room/utils.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ClientInfo_Capability } from '@livekit/protocol';
|
|
1
|
+
import { ClientInfo_Capability, ClientInfo_SDK } from '@livekit/protocol';
|
|
2
2
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
3
3
|
import {
|
|
4
4
|
stubMissingCompressionStreams,
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
extractMaxAgeFromRequestHeaders,
|
|
11
11
|
getClientInfo,
|
|
12
12
|
isAppleMobile,
|
|
13
|
+
isBrowserSupported,
|
|
13
14
|
isCompressionStreamSupported,
|
|
14
15
|
isDeflateRawCompressionSupported,
|
|
15
16
|
isIPadOS,
|
|
@@ -48,6 +49,21 @@ describe('getClientInfo', () => {
|
|
|
48
49
|
ClientInfo_Capability.CAP_PACKET_TRAILER,
|
|
49
50
|
]);
|
|
50
51
|
});
|
|
52
|
+
|
|
53
|
+
describe('sdk', () => {
|
|
54
|
+
afterEach(() => {
|
|
55
|
+
vi.unstubAllGlobals();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('reports JS in a browser', () => {
|
|
59
|
+
expect(getClientInfo().sdk).toEqual(ClientInfo_SDK.JS);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('reports REACT_NATIVE on react native', () => {
|
|
63
|
+
vi.stubGlobal('navigator', { userAgent: '', product: 'ReactNative' });
|
|
64
|
+
expect(getClientInfo().sdk).toEqual(ClientInfo_SDK.REACT_NATIVE);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
51
67
|
});
|
|
52
68
|
|
|
53
69
|
describe('splitUtf8', () => {
|
|
@@ -617,3 +633,22 @@ describe('empty audio stream track refcounting', () => {
|
|
|
617
633
|
expect(closedContexts).toBe(2);
|
|
618
634
|
});
|
|
619
635
|
});
|
|
636
|
+
|
|
637
|
+
describe('isBrowserSupported', () => {
|
|
638
|
+
afterEach(() => {
|
|
639
|
+
vi.unstubAllGlobals();
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
it('requires WeakRef where machina is not rewritten (source and core entry)', () => {
|
|
643
|
+
vi.stubGlobal(
|
|
644
|
+
'RTCPeerConnection',
|
|
645
|
+
class {
|
|
646
|
+
addTransceiver() {}
|
|
647
|
+
},
|
|
648
|
+
);
|
|
649
|
+
expect(isBrowserSupported()).toBe(true);
|
|
650
|
+
|
|
651
|
+
vi.stubGlobal('WeakRef', undefined);
|
|
652
|
+
expect(isBrowserSupported()).toBe(false);
|
|
653
|
+
});
|
|
654
|
+
});
|
package/src/room/utils.ts
CHANGED
|
@@ -263,10 +263,20 @@ export function supportsAudioOutputSelection(): boolean {
|
|
|
263
263
|
return supportsSetSinkId();
|
|
264
264
|
}
|
|
265
265
|
|
|
266
|
+
/**
|
|
267
|
+
* machina, the signalling state machine, calls `WeakRef` and `Object.hasOwn`. A build that bundles
|
|
268
|
+
* machina rewrites those calls and sets this to `false` (`machina-browser-compat` in
|
|
269
|
+
* rollup.config.js). The core entry leaves machina external, so there the browser must have both.
|
|
270
|
+
*/
|
|
271
|
+
const machinaNeedsNativeApis = true;
|
|
272
|
+
|
|
266
273
|
export function isBrowserSupported() {
|
|
267
274
|
if (typeof RTCPeerConnection === 'undefined') {
|
|
268
275
|
return false;
|
|
269
276
|
}
|
|
277
|
+
if (machinaNeedsNativeApis && (typeof WeakRef === 'undefined' || !('hasOwn' in Object))) {
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
270
280
|
return supportsTransceiver() || supportsAddTrack();
|
|
271
281
|
}
|
|
272
282
|
|
|
@@ -506,7 +516,7 @@ export interface ObservableMediaElement extends HTMLMediaElement {
|
|
|
506
516
|
export function getClientInfo(capabilities?: ClientInfo_Capability[]): ClientInfo {
|
|
507
517
|
const info = new ClientInfo({
|
|
508
518
|
capabilities,
|
|
509
|
-
sdk: ClientInfo_SDK.JS,
|
|
519
|
+
sdk: isReactNative() ? ClientInfo_SDK.REACT_NATIVE : ClientInfo_SDK.JS,
|
|
510
520
|
protocol: protocolVersion,
|
|
511
521
|
clientProtocol,
|
|
512
522
|
version,
|