livekit-client 1.12.1 → 1.12.2
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +7 -3
- 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 +389 -301
- package/dist/livekit-client.e2ee.worker.mjs.map +1 -1
- package/dist/livekit-client.esm.mjs +12735 -14958
- 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 +2 -2
- package/dist/src/api/SignalClient.d.ts.map +1 -1
- package/dist/src/connectionHelper/ConnectionCheck.d.ts +3 -2
- package/dist/src/connectionHelper/ConnectionCheck.d.ts.map +1 -1
- package/dist/src/connectionHelper/checks/Checker.d.ts +3 -2
- package/dist/src/connectionHelper/checks/Checker.d.ts.map +1 -1
- package/dist/src/connectionHelper/checks/webrtc.d.ts.map +1 -1
- package/dist/src/connectionHelper/checks/websocket.d.ts.map +1 -1
- package/dist/src/e2ee/E2eeManager.d.ts +4 -2
- package/dist/src/e2ee/E2eeManager.d.ts.map +1 -1
- package/dist/src/e2ee/KeyProvider.d.ts +4 -2
- package/dist/src/e2ee/KeyProvider.d.ts.map +1 -1
- package/dist/src/e2ee/constants.d.ts +1 -0
- package/dist/src/e2ee/constants.d.ts.map +1 -1
- package/dist/src/e2ee/types.d.ts +1 -0
- package/dist/src/e2ee/types.d.ts.map +1 -1
- package/dist/src/e2ee/worker/FrameCryptor.d.ts +4 -2
- package/dist/src/e2ee/worker/FrameCryptor.d.ts.map +1 -1
- package/dist/src/e2ee/worker/ParticipantKeyHandler.d.ts +14 -3
- package/dist/src/e2ee/worker/ParticipantKeyHandler.d.ts.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/proto/livekit_models_pb.d.ts +1264 -0
- package/dist/src/proto/livekit_models_pb.d.ts.map +1 -0
- package/dist/src/proto/livekit_rtc_pb.d.ts +1373 -0
- package/dist/src/proto/livekit_rtc_pb.d.ts.map +1 -0
- package/dist/src/room/PCTransport.d.ts +2 -1
- package/dist/src/room/PCTransport.d.ts.map +1 -1
- package/dist/src/room/RTCEngine.d.ts +9 -5
- package/dist/src/room/RTCEngine.d.ts.map +1 -1
- package/dist/src/room/RegionUrlProvider.d.ts +4 -1
- package/dist/src/room/RegionUrlProvider.d.ts.map +1 -1
- package/dist/src/room/Room.d.ts +15 -11
- package/dist/src/room/Room.d.ts.map +1 -1
- package/dist/src/room/participant/LocalParticipant.d.ts +2 -2
- package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
- package/dist/src/room/participant/Participant.d.ts +5 -3
- package/dist/src/room/participant/Participant.d.ts.map +1 -1
- package/dist/src/room/participant/ParticipantTrackPermission.d.ts +1 -1
- package/dist/src/room/participant/ParticipantTrackPermission.d.ts.map +1 -1
- package/dist/src/room/participant/RemoteParticipant.d.ts +2 -3
- package/dist/src/room/participant/RemoteParticipant.d.ts.map +1 -1
- package/dist/src/room/timers.d.ts +5 -4
- package/dist/src/room/timers.d.ts.map +1 -1
- package/dist/src/room/track/LocalTrack.d.ts +3 -0
- package/dist/src/room/track/LocalTrack.d.ts.map +1 -1
- package/dist/src/room/track/LocalTrackPublication.d.ts +1 -1
- package/dist/src/room/track/LocalTrackPublication.d.ts.map +1 -1
- package/dist/src/room/track/LocalVideoTrack.d.ts +2 -2
- package/dist/src/room/track/LocalVideoTrack.d.ts.map +1 -1
- package/dist/src/room/track/RemoteTrackPublication.d.ts +1 -1
- package/dist/src/room/track/RemoteTrackPublication.d.ts.map +1 -1
- package/dist/src/room/track/Track.d.ts +6 -4
- package/dist/src/room/track/Track.d.ts.map +1 -1
- package/dist/src/room/track/TrackPublication.d.ts +7 -5
- package/dist/src/room/track/TrackPublication.d.ts.map +1 -1
- package/dist/src/room/track/create.d.ts.map +1 -1
- package/dist/src/room/track/options.d.ts +7 -0
- package/dist/src/room/track/options.d.ts.map +1 -1
- package/dist/src/room/track/utils.d.ts +5 -1
- package/dist/src/room/track/utils.d.ts.map +1 -1
- package/dist/src/room/utils.d.ts +3 -1
- package/dist/src/room/utils.d.ts.map +1 -1
- package/dist/src/test/mocks.d.ts +4 -3
- package/dist/src/test/mocks.d.ts.map +1 -1
- package/dist/ts4.2/src/api/SignalClient.d.ts +2 -2
- package/dist/ts4.2/src/connectionHelper/ConnectionCheck.d.ts +3 -2
- package/dist/ts4.2/src/connectionHelper/checks/Checker.d.ts +3 -2
- package/dist/ts4.2/src/e2ee/E2eeManager.d.ts +4 -2
- package/dist/ts4.2/src/e2ee/KeyProvider.d.ts +4 -2
- package/dist/ts4.2/src/e2ee/constants.d.ts +1 -0
- package/dist/ts4.2/src/e2ee/types.d.ts +1 -0
- package/dist/ts4.2/src/e2ee/worker/FrameCryptor.d.ts +4 -2
- package/dist/ts4.2/src/e2ee/worker/ParticipantKeyHandler.d.ts +14 -3
- package/dist/ts4.2/src/index.d.ts +1 -1
- package/dist/ts4.2/src/proto/livekit_models_pb.d.ts +1264 -0
- package/dist/ts4.2/src/proto/livekit_rtc_pb.d.ts +1373 -0
- package/dist/ts4.2/src/room/PCTransport.d.ts +2 -1
- package/dist/ts4.2/src/room/RTCEngine.d.ts +9 -5
- package/dist/ts4.2/src/room/RegionUrlProvider.d.ts +4 -1
- package/dist/ts4.2/src/room/Room.d.ts +15 -11
- package/dist/ts4.2/src/room/participant/LocalParticipant.d.ts +2 -2
- package/dist/ts4.2/src/room/participant/Participant.d.ts +5 -3
- package/dist/ts4.2/src/room/participant/ParticipantTrackPermission.d.ts +1 -1
- package/dist/ts4.2/src/room/participant/RemoteParticipant.d.ts +2 -3
- package/dist/ts4.2/src/room/timers.d.ts +5 -4
- package/dist/ts4.2/src/room/track/LocalTrack.d.ts +3 -0
- package/dist/ts4.2/src/room/track/LocalTrackPublication.d.ts +1 -1
- package/dist/ts4.2/src/room/track/LocalVideoTrack.d.ts +2 -2
- package/dist/ts4.2/src/room/track/RemoteTrackPublication.d.ts +1 -1
- package/dist/ts4.2/src/room/track/Track.d.ts +6 -4
- package/dist/ts4.2/src/room/track/TrackPublication.d.ts +7 -5
- package/dist/ts4.2/src/room/track/options.d.ts +7 -0
- package/dist/ts4.2/src/room/track/utils.d.ts +5 -1
- package/dist/ts4.2/src/room/utils.d.ts +3 -1
- package/dist/ts4.2/src/test/mocks.d.ts +4 -3
- package/package.json +10 -10
- package/src/api/SignalClient.ts +104 -101
- package/src/connectionHelper/ConnectionCheck.ts +3 -2
- package/src/connectionHelper/checks/Checker.ts +3 -3
- package/src/connectionHelper/checks/webrtc.ts +66 -2
- package/src/connectionHelper/checks/websocket.ts +4 -0
- package/src/e2ee/E2eeManager.ts +4 -3
- package/src/e2ee/KeyProvider.ts +3 -2
- package/src/e2ee/constants.ts +4 -0
- package/src/e2ee/types.ts +1 -0
- package/src/e2ee/worker/FrameCryptor.test.ts +1 -3
- package/src/e2ee/worker/FrameCryptor.ts +5 -5
- package/src/e2ee/worker/ParticipantKeyHandler.ts +37 -6
- package/src/e2ee/worker/e2ee.worker.ts +1 -1
- package/src/index.ts +1 -1
- package/src/proto/livekit_models_pb.ts +2096 -0
- package/src/proto/livekit_rtc_pb.ts +2332 -0
- package/src/room/PCTransport.ts +1 -1
- package/src/room/RTCEngine.ts +24 -18
- package/src/room/RegionUrlProvider.ts +11 -2
- package/src/room/Room.test.ts +1 -0
- package/src/room/Room.ts +158 -79
- package/src/room/participant/LocalParticipant.ts +43 -59
- package/src/room/participant/Participant.ts +6 -4
- package/src/room/participant/ParticipantTrackPermission.ts +3 -3
- package/src/room/participant/RemoteParticipant.ts +5 -6
- package/src/room/participant/publishUtils.test.ts +1 -0
- package/src/room/track/LocalTrack.ts +24 -9
- package/src/room/track/LocalTrackPublication.ts +1 -1
- package/src/room/track/LocalVideoTrack.test.ts +2 -1
- package/src/room/track/LocalVideoTrack.ts +22 -22
- package/src/room/track/RemoteTrackPublication.ts +12 -7
- package/src/room/track/RemoteVideoTrack.test.ts +5 -4
- package/src/room/track/Track.ts +9 -6
- package/src/room/track/TrackPublication.ts +7 -5
- package/src/room/track/create.ts +9 -17
- package/src/room/track/facingMode.test.ts +1 -0
- package/src/room/track/options.ts +6 -0
- package/src/room/track/utils.test.ts +1 -0
- package/src/room/track/utils.ts +44 -2
- package/src/room/utils.test.ts +16 -0
- package/src/room/utils.ts +20 -4
- package/src/test/mocks.ts +7 -5
- package/src/utils/AsyncQueue.test.ts +1 -0
- package/src/utils/browserParser.test.ts +33 -3
- package/src/utils/browserParser.ts +1 -1
- package/dist/src/proto/google/protobuf/timestamp.d.ts +0 -146
- package/dist/src/proto/google/protobuf/timestamp.d.ts.map +0 -1
- package/dist/src/proto/livekit_models.d.ts +0 -2399
- package/dist/src/proto/livekit_models.d.ts.map +0 -1
- package/dist/src/proto/livekit_rtc.d.ts +0 -14352
- package/dist/src/proto/livekit_rtc.d.ts.map +0 -1
- package/dist/ts4.2/src/proto/google/protobuf/timestamp.d.ts +0 -150
- package/dist/ts4.2/src/proto/livekit_models.d.ts +0 -2659
- package/dist/ts4.2/src/proto/livekit_rtc.d.ts +0 -15764
- package/src/proto/google/protobuf/timestamp.ts +0 -230
- package/src/proto/livekit_models.ts +0 -4006
- package/src/proto/livekit_rtc.ts +0 -4672
@@ -1,6 +1,7 @@
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
2
2
|
// TODO code inspired by https://github.com/webrtc/samples/blob/gh-pages/src/content/insertable-streams/endtoend-encryption/js/worker.js
|
3
|
-
import EventEmitter from '
|
3
|
+
import { EventEmitter } from 'events';
|
4
|
+
import type TypedEventEmitter from 'typed-emitter';
|
4
5
|
import { workerLogger } from '../../logger';
|
5
6
|
import type { VideoCodec } from '../../room/track/options';
|
6
7
|
import { ENCRYPTION_ALGORITHM, IV_LENGTH, UNENCRYPTED_BYTES } from '../constants';
|
@@ -26,7 +27,7 @@ export interface TransformerInfo {
|
|
26
27
|
abortController: AbortController;
|
27
28
|
}
|
28
29
|
|
29
|
-
export class BaseFrameCryptor extends EventEmitter<CryptorCallbacks> {
|
30
|
+
export class BaseFrameCryptor extends (EventEmitter as new () => TypedEventEmitter<CryptorCallbacks>) {
|
30
31
|
encodeFunction(
|
31
32
|
encodedFrame: RTCEncodedVideoFrame | RTCEncodedAudioFrame,
|
32
33
|
controller: TransformStreamDefaultController,
|
@@ -271,6 +272,7 @@ export class FrameCryptor extends BaseFrameCryptor {
|
|
271
272
|
if (this.keys.getKeySet(keyIndex) && this.keys.hasValidKey) {
|
272
273
|
try {
|
273
274
|
const decodedFrame = await this.decryptFrame(encodedFrame, keyIndex);
|
275
|
+
this.keys.decryptionSuccess();
|
274
276
|
if (decodedFrame) {
|
275
277
|
return controller.enqueue(decodedFrame);
|
276
278
|
}
|
@@ -285,7 +287,7 @@ export class FrameCryptor extends BaseFrameCryptor {
|
|
285
287
|
CryptorErrorReason.InvalidKey,
|
286
288
|
),
|
287
289
|
);
|
288
|
-
this.keys.
|
290
|
+
this.keys.decryptionFailure();
|
289
291
|
}
|
290
292
|
} else {
|
291
293
|
workerLogger.warn('decoding frame failed', { error });
|
@@ -395,8 +397,6 @@ export class FrameCryptor extends BaseFrameCryptor {
|
|
395
397
|
this.keys.setKeyFromMaterial(initialMaterial.material, keyIndex);
|
396
398
|
}
|
397
399
|
|
398
|
-
this.keys.hasValidKey = false;
|
399
|
-
|
400
400
|
workerLogger.warn('maximum ratchet attempts exceeded, resetting key');
|
401
401
|
this.emit(
|
402
402
|
CryptorEvent.Error,
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import EventEmitter from '
|
1
|
+
import { EventEmitter } from 'events';
|
2
|
+
import type TypedEventEmitter from 'typed-emitter';
|
2
3
|
import { workerLogger } from '../../logger';
|
3
4
|
import { KEYRING_SIZE } from '../constants';
|
4
5
|
import type { KeyProviderOptions, KeySet, ParticipantKeyHandlerCallbacks } from '../types';
|
@@ -15,7 +16,7 @@ import { deriveKeys, importKey, ratchet } from '../utils';
|
|
15
16
|
* if decryption fails or can be triggered manually on both sender and receiver side.
|
16
17
|
*
|
17
18
|
*/
|
18
|
-
export class ParticipantKeyHandler extends EventEmitter<ParticipantKeyHandlerCallbacks> {
|
19
|
+
export class ParticipantKeyHandler extends (EventEmitter as new () => TypedEventEmitter<ParticipantKeyHandlerCallbacks>) {
|
19
20
|
private currentKeyIndex: number;
|
20
21
|
|
21
22
|
private cryptoKeyRing: Array<KeySet>;
|
@@ -28,7 +29,13 @@ export class ParticipantKeyHandler extends EventEmitter<ParticipantKeyHandlerCal
|
|
28
29
|
|
29
30
|
private participantId: string | undefined;
|
30
31
|
|
31
|
-
|
32
|
+
private decryptionFailureCount = 0;
|
33
|
+
|
34
|
+
private _hasValidKey: boolean = true;
|
35
|
+
|
36
|
+
get hasValidKey() {
|
37
|
+
return this._hasValidKey;
|
38
|
+
}
|
32
39
|
|
33
40
|
constructor(
|
34
41
|
participantId: string | undefined,
|
@@ -42,13 +49,37 @@ export class ParticipantKeyHandler extends EventEmitter<ParticipantKeyHandlerCal
|
|
42
49
|
this.keyProviderOptions = keyProviderOptions;
|
43
50
|
this.ratchetPromiseMap = new Map();
|
44
51
|
this.participantId = participantId;
|
45
|
-
this.
|
52
|
+
this.resetKeyStatus();
|
46
53
|
}
|
47
54
|
|
48
55
|
setEnabled(enabled: boolean) {
|
49
56
|
this.enabled = enabled;
|
50
57
|
}
|
51
58
|
|
59
|
+
decryptionFailure() {
|
60
|
+
if (this.keyProviderOptions.failureTolerance < 0) {
|
61
|
+
return;
|
62
|
+
}
|
63
|
+
this.decryptionFailureCount += 1;
|
64
|
+
|
65
|
+
if (this.decryptionFailureCount > this.keyProviderOptions.failureTolerance) {
|
66
|
+
this._hasValidKey = false;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
decryptionSuccess() {
|
71
|
+
this.resetKeyStatus();
|
72
|
+
}
|
73
|
+
|
74
|
+
/**
|
75
|
+
* Call this after user initiated ratchet or a new key has been set in order to make sure to mark potentially
|
76
|
+
* invalid keys as valid again
|
77
|
+
*/
|
78
|
+
resetKeyStatus() {
|
79
|
+
this.decryptionFailureCount = 0;
|
80
|
+
this._hasValidKey = true;
|
81
|
+
}
|
82
|
+
|
52
83
|
/**
|
53
84
|
* Ratchets the current key (or the one at keyIndex if provided) and
|
54
85
|
* returns the ratcheted material
|
@@ -95,7 +126,7 @@ export class ParticipantKeyHandler extends EventEmitter<ParticipantKeyHandlerCal
|
|
95
126
|
*/
|
96
127
|
async setKey(material: CryptoKey, keyIndex = 0) {
|
97
128
|
await this.setKeyFromMaterial(material, keyIndex);
|
98
|
-
this.
|
129
|
+
this.resetKeyStatus();
|
99
130
|
}
|
100
131
|
|
101
132
|
/**
|
@@ -122,7 +153,7 @@ export class ParticipantKeyHandler extends EventEmitter<ParticipantKeyHandlerCal
|
|
122
153
|
|
123
154
|
async setCurrentKeyIndex(index: number) {
|
124
155
|
this.currentKeyIndex = index % this.cryptoKeyRing.length;
|
125
|
-
this.
|
156
|
+
this.resetKeyStatus();
|
126
157
|
}
|
127
158
|
|
128
159
|
isEnabled() {
|
@@ -102,7 +102,7 @@ onmessage = (ev) => {
|
|
102
102
|
async function handleRatchetRequest(data: RatchetRequestMessage['data']) {
|
103
103
|
const keyHandler = getParticipantKeyHandler(data.participantId);
|
104
104
|
await keyHandler.ratchetKey(data.keyIndex);
|
105
|
-
keyHandler.
|
105
|
+
keyHandler.resetKeyStatus();
|
106
106
|
}
|
107
107
|
|
108
108
|
function getTrackCryptor(participantId: string, trackId: string) {
|
package/src/index.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { LogLevel, setLogExtension, setLogLevel } from './logger';
|
2
|
-
import { DataPacket_Kind, DisconnectReason, VideoQuality } from './proto/
|
2
|
+
import { DataPacket_Kind, DisconnectReason, VideoQuality } from './proto/livekit_models_pb';
|
3
3
|
import DefaultReconnectPolicy from './room/DefaultReconnectPolicy';
|
4
4
|
import Room, { ConnectionState, RoomState } from './room/Room';
|
5
5
|
import LocalParticipant from './room/participant/LocalParticipant';
|