livekit-client 2.5.5 → 2.5.6
Sign up to get free protection for your applications and to get access to all the features.
- 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 +5180 -494
- package/dist/livekit-client.e2ee.worker.mjs.map +1 -1
- package/dist/livekit-client.esm.mjs +7 -7
- 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/e2ee/worker/FrameCryptor.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/e2ee/E2eeManager.ts +8 -8
- package/src/e2ee/worker/FrameCryptor.ts +10 -4
- package/src/e2ee/worker/e2ee.worker.ts +81 -77
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"FrameCryptor.d.ts","sourceRoot":"","sources":["../../../../src/e2ee/worker/FrameCryptor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,iBAAiB,MAAM,eAAe,CAAC;AAEnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAG3D,OAAO,EAAE,gBAAgB,EAAgB,MAAM,WAAW,CAAC;AAC3D,OAAO,KAAK,EAAwB,kBAAkB,EAAU,MAAM,UAAU,CAAC;AAEjF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAGrE,eAAO,MAAM,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAa,CAAC;AAEpE,MAAM,WAAW,uBAAuB;IACtC,KAAK,IAAI,CAAC,EAAE,OAAO,GAAG,gBAAgB,CAAC;CACxC;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,cAAc,CAAC;IACzB,QAAQ,EAAE,cAAc,CAAC;IACzB,WAAW,EAAE,eAAe,CAAC;IAC7B,eAAe,EAAE,eAAe,CAAC;CAClC;+CAEgE,iBAAiB,CAAC,gBAAgB,CAAC;AAApG,qBAAa,gBAAiB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,UAAU,EAAE,gCAAgC;IAiE9C;;;OAGG;YACW,YAAY;IA4H1B;;;;;;;;;;;;;;;;;;OAkBG;IACH,OAAO,CAAC,MAAM;IAqBd,OAAO,CAAC,mBAAmB;IAgE3B;;OAEG;IACH,OAAO,CAAC,aAAa;CAQtB;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,EAAE,CA0B5D;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,QAAQ,CAEzD;AAID,oBAAY,QAAQ;IAClB,uCAAuC;IACvC,aAAa,IAAI;IACjB,mCAAmC;IACnC,iBAAiB,IAAI;IACrB,mCAAmC;IACnC,iBAAiB,IAAI;IACrB,mCAAmC;IACnC,iBAAiB,IAAI;IACrB,oCAAoC;IACpC,SAAS,IAAI;IACb,2CAA2C;IAC3C,GAAG,IAAI;IACP,6BAA6B;IAC7B,GAAG,IAAI;IACP,4BAA4B;IAC5B,GAAG,IAAI;IACP,4BAA4B;IAC5B,GAAG,IAAI;IACP,sBAAsB;IACtB,OAAO,KAAK;IACZ,oBAAoB;IACpB,UAAU,KAAK;IACf,kBAAkB;IAClB,WAAW,KAAK;IAChB,uCAAuC;IACvC,OAAO,KAAK;IACZ,sBAAsB;IACtB,WAAW,KAAK;IAChB,oCAAoC;IACpC,UAAU,KAAK;IACf,0BAA0B;IAC1B,GAAG,KAAK;IAIR,qEAAqE;IACrE,SAAS,KAAK;IACd,4BAA4B;IAC5B,SAAS,KAAK;IACd,0FAA0F;IAC1F,eAAe,KAAK;CAGrB;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,GAAG,OAAO,CAQ/F"}
|
package/package.json
CHANGED
package/src/e2ee/E2eeManager.ts
CHANGED
@@ -115,6 +115,11 @@ export class E2EEManager extends (EventEmitter as new () => TypedEventEmitter<E2
|
|
115
115
|
break;
|
116
116
|
|
117
117
|
case 'enable':
|
118
|
+
if (data.enabled) {
|
119
|
+
this.keyProvider.getKeys().forEach((keyInfo) => {
|
120
|
+
this.postKey(keyInfo);
|
121
|
+
});
|
122
|
+
}
|
118
123
|
if (
|
119
124
|
this.encryptionEnabled !== data.enabled &&
|
120
125
|
data.participantIdentity === this.room?.localParticipant.identity
|
@@ -134,11 +139,6 @@ export class E2EEManager extends (EventEmitter as new () => TypedEventEmitter<E2
|
|
134
139
|
}
|
135
140
|
this.emit(EncryptionEvent.ParticipantEncryptionStatusChanged, data.enabled, participant);
|
136
141
|
}
|
137
|
-
if (this.encryptionEnabled) {
|
138
|
-
this.keyProvider.getKeys().forEach((keyInfo) => {
|
139
|
-
this.postKey(keyInfo);
|
140
|
-
});
|
141
|
-
}
|
142
142
|
break;
|
143
143
|
case 'ratchetKey':
|
144
144
|
this.keyProvider.emit(KeyProviderEvent.KeyRatcheted, data.material, data.keyIndex);
|
@@ -196,13 +196,13 @@ export class E2EEManager extends (EventEmitter as new () => TypedEventEmitter<E2
|
|
196
196
|
if (!this.room) {
|
197
197
|
throw new TypeError(`expected room to be present on signal connect`);
|
198
198
|
}
|
199
|
+
keyProvider.getKeys().forEach((keyInfo) => {
|
200
|
+
this.postKey(keyInfo);
|
201
|
+
});
|
199
202
|
this.setParticipantCryptorEnabled(
|
200
203
|
this.room.localParticipant.isE2EEEnabled,
|
201
204
|
this.room.localParticipant.identity,
|
202
205
|
);
|
203
|
-
keyProvider.getKeys().forEach((keyInfo) => {
|
204
|
-
this.postKey(keyInfo);
|
205
|
-
});
|
206
206
|
});
|
207
207
|
room.localParticipant.on(ParticipantEvent.LocalTrackPublished, async (publication) => {
|
208
208
|
this.setupE2EESender(publication.track!, publication.track!.sender!);
|
@@ -233,11 +233,17 @@ export class FrameCryptor extends BaseFrameCryptor {
|
|
233
233
|
}
|
234
234
|
const keySet = this.keys.getKeySet();
|
235
235
|
if (!keySet) {
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
236
|
+
this.emit(
|
237
|
+
CryptorEvent.Error,
|
238
|
+
new CryptorError(
|
239
|
+
`key set not found for ${
|
240
|
+
this.participantIdentity
|
241
|
+
} at index ${this.keys.getCurrentKeyIndex()}`,
|
242
|
+
CryptorErrorReason.MissingKey,
|
243
|
+
this.participantIdentity,
|
244
|
+
),
|
240
245
|
);
|
246
|
+
return;
|
241
247
|
}
|
242
248
|
const { encryptionKey } = keySet;
|
243
249
|
const keyIndex = this.keys.getCurrentKeyIndex();
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { workerLogger } from '../../logger';
|
2
2
|
import { VideoCodec } from '../../room/track/options';
|
3
|
+
import { AsyncQueue } from '../../utils/AsyncQueue';
|
3
4
|
import { KEY_PROVIDER_DEFAULTS } from '../constants';
|
4
5
|
import { CryptorErrorReason } from '../errors';
|
5
6
|
import { CryptorEvent, KeyHandlerEvent } from '../events';
|
@@ -17,6 +18,7 @@ import { ParticipantKeyHandler } from './ParticipantKeyHandler';
|
|
17
18
|
const participantCryptors: FrameCryptor[] = [];
|
18
19
|
const participantKeys: Map<string, ParticipantKeyHandler> = new Map();
|
19
20
|
let sharedKeyHandler: ParticipantKeyHandler | undefined;
|
21
|
+
let messageQueue = new AsyncQueue();
|
20
22
|
|
21
23
|
let isEncryptionEnabled: boolean = false;
|
22
24
|
|
@@ -31,85 +33,87 @@ let rtpMap: Map<number, VideoCodec> = new Map();
|
|
31
33
|
workerLogger.setDefaultLevel('info');
|
32
34
|
|
33
35
|
onmessage = (ev) => {
|
34
|
-
|
36
|
+
messageQueue.run(async () => {
|
37
|
+
const { kind, data }: E2EEWorkerMessage = ev.data;
|
35
38
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
workerLogger.info(
|
52
|
-
`updated e2ee enabled status for ${data.participantIdentity} to ${data.enabled}`,
|
53
|
-
);
|
54
|
-
// acknowledge enable call successful
|
55
|
-
postMessage(ev.data);
|
56
|
-
break;
|
57
|
-
case 'decode':
|
58
|
-
let cryptor = getTrackCryptor(data.participantIdentity, data.trackId);
|
59
|
-
cryptor.setupTransform(
|
60
|
-
kind,
|
61
|
-
data.readableStream,
|
62
|
-
data.writableStream,
|
63
|
-
data.trackId,
|
64
|
-
data.codec,
|
65
|
-
);
|
66
|
-
break;
|
67
|
-
case 'encode':
|
68
|
-
let pubCryptor = getTrackCryptor(data.participantIdentity, data.trackId);
|
69
|
-
pubCryptor.setupTransform(
|
70
|
-
kind,
|
71
|
-
data.readableStream,
|
72
|
-
data.writableStream,
|
73
|
-
data.trackId,
|
74
|
-
data.codec,
|
75
|
-
);
|
76
|
-
break;
|
77
|
-
case 'setKey':
|
78
|
-
if (useSharedKey) {
|
79
|
-
setSharedKey(data.key, data.keyIndex);
|
80
|
-
} else if (data.participantIdentity) {
|
39
|
+
switch (kind) {
|
40
|
+
case 'init':
|
41
|
+
workerLogger.setLevel(data.loglevel);
|
42
|
+
workerLogger.info('worker initialized');
|
43
|
+
keyProviderOptions = data.keyProviderOptions;
|
44
|
+
useSharedKey = !!data.keyProviderOptions.sharedKey;
|
45
|
+
// acknowledge init successful
|
46
|
+
const ackMsg: InitAck = {
|
47
|
+
kind: 'initAck',
|
48
|
+
data: { enabled: isEncryptionEnabled },
|
49
|
+
};
|
50
|
+
postMessage(ackMsg);
|
51
|
+
break;
|
52
|
+
case 'enable':
|
53
|
+
setEncryptionEnabled(data.enabled, data.participantIdentity);
|
81
54
|
workerLogger.info(
|
82
|
-
`
|
55
|
+
`updated e2ee enabled status for ${data.participantIdentity} to ${data.enabled}`,
|
83
56
|
);
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
57
|
+
// acknowledge enable call successful
|
58
|
+
postMessage(ev.data);
|
59
|
+
break;
|
60
|
+
case 'decode':
|
61
|
+
let cryptor = getTrackCryptor(data.participantIdentity, data.trackId);
|
62
|
+
cryptor.setupTransform(
|
63
|
+
kind,
|
64
|
+
data.readableStream,
|
65
|
+
data.writableStream,
|
66
|
+
data.trackId,
|
67
|
+
data.codec,
|
68
|
+
);
|
69
|
+
break;
|
70
|
+
case 'encode':
|
71
|
+
let pubCryptor = getTrackCryptor(data.participantIdentity, data.trackId);
|
72
|
+
pubCryptor.setupTransform(
|
73
|
+
kind,
|
74
|
+
data.readableStream,
|
75
|
+
data.writableStream,
|
76
|
+
data.trackId,
|
77
|
+
data.codec,
|
78
|
+
);
|
79
|
+
break;
|
80
|
+
case 'setKey':
|
81
|
+
if (useSharedKey) {
|
82
|
+
await setSharedKey(data.key, data.keyIndex);
|
83
|
+
} else if (data.participantIdentity) {
|
84
|
+
workerLogger.info(
|
85
|
+
`set participant sender key ${data.participantIdentity} index ${data.keyIndex}`,
|
86
|
+
);
|
87
|
+
await getParticipantKeyHandler(data.participantIdentity).setKey(data.key, data.keyIndex);
|
88
|
+
} else {
|
89
|
+
workerLogger.error('no participant Id was provided and shared key usage is disabled');
|
101
90
|
}
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
91
|
+
break;
|
92
|
+
case 'removeTransform':
|
93
|
+
unsetCryptorParticipant(data.trackId, data.participantIdentity);
|
94
|
+
break;
|
95
|
+
case 'updateCodec':
|
96
|
+
getTrackCryptor(data.participantIdentity, data.trackId).setVideoCodec(data.codec);
|
97
|
+
break;
|
98
|
+
case 'setRTPMap':
|
99
|
+
// this is only used for the local participant
|
100
|
+
rtpMap = data.map;
|
101
|
+
participantCryptors.forEach((cr) => {
|
102
|
+
if (cr.getParticipantIdentity() === data.participantIdentity) {
|
103
|
+
cr.setRtpMap(data.map);
|
104
|
+
}
|
105
|
+
});
|
106
|
+
break;
|
107
|
+
case 'ratchetRequest':
|
108
|
+
handleRatchetRequest(data);
|
109
|
+
break;
|
110
|
+
case 'setSifTrailer':
|
111
|
+
handleSifTrailer(data.trailer);
|
112
|
+
break;
|
113
|
+
default:
|
114
|
+
break;
|
115
|
+
}
|
116
|
+
});
|
113
117
|
};
|
114
118
|
|
115
119
|
async function handleRatchetRequest(data: RatchetRequestMessage['data']) {
|
@@ -210,9 +214,9 @@ function setEncryptionEnabled(enable: boolean, participantIdentity: string) {
|
|
210
214
|
encryptionEnabledMap.set(participantIdentity, enable);
|
211
215
|
}
|
212
216
|
|
213
|
-
function setSharedKey(key: CryptoKey, index?: number) {
|
217
|
+
async function setSharedKey(key: CryptoKey, index?: number) {
|
214
218
|
workerLogger.info('set shared key', { index });
|
215
|
-
getSharedKeyHandler().setKey(key, index);
|
219
|
+
await getSharedKeyHandler().setKey(key, index);
|
216
220
|
}
|
217
221
|
|
218
222
|
function setupCryptorErrorEvents(cryptor: FrameCryptor) {
|