livekit-client 1.12.0 → 1.12.2
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +19 -1
- 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 +442 -334
- package/dist/livekit-client.e2ee.worker.mjs.map +1 -1
- package/dist/livekit-client.esm.mjs +12303 -14499
- 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 -3
- package/dist/src/e2ee/worker/FrameCryptor.d.ts.map +1 -1
- package/dist/src/e2ee/worker/ParticipantKeyHandler.d.ts +21 -2
- 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 +8 -7
- 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/src/utils/browserParser.d.ts +2 -0
- package/dist/src/utils/browserParser.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 -3
- package/dist/ts4.2/src/e2ee/worker/ParticipantKeyHandler.d.ts +21 -2
- 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 +8 -7
- 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/dist/ts4.2/src/utils/browserParser.d.ts +2 -0
- 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 +14 -16
- package/src/e2ee/worker/ParticipantKeyHandler.ts +48 -2
- package/src/e2ee/worker/e2ee.worker.ts +12 -6
- 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 +175 -86
- 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 +24 -21
- 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 +18 -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 +5 -0
- 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,9 +1,32 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
/******************************************************************************
|
2
|
+
Copyright (c) Microsoft Corporation.
|
3
|
+
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
5
|
+
purpose with or without fee is hereby granted.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
14
|
+
***************************************************************************** */
|
15
|
+
/* global Reflect, Promise */
|
16
|
+
|
17
|
+
|
18
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
19
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
20
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
21
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
22
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
23
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
24
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
25
|
+
});
|
5
26
|
}
|
6
27
|
|
28
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
29
|
+
|
7
30
|
var loglevel = {exports: {}};
|
8
31
|
|
9
32
|
/*
|
@@ -290,6 +313,8 @@ const ENCRYPTION_ALGORITHM = 'AES-GCM';
|
|
290
313
|
// encrypted with an old key. We use a size of 16 which corresponds to the four bits
|
291
314
|
// in the frame trailer.
|
292
315
|
const KEYRING_SIZE = 16;
|
316
|
+
// How many consecutive frames can fail decrypting before a particular key gets marked as invalid
|
317
|
+
const DECRYPTION_FAILURE_TOLERANCE = 10;
|
293
318
|
// We copy the first bytes of the VP8 payload unencrypted.
|
294
319
|
// For keyframes this is 10 bytes, for non-keyframes (delta) 3. See
|
295
320
|
// https://tools.ietf.org/html/rfc6386#section-9.1
|
@@ -313,7 +338,8 @@ const SALT = 'LKFrameEncryptionKey';
|
|
313
338
|
const KEY_PROVIDER_DEFAULTS = {
|
314
339
|
sharedKey: false,
|
315
340
|
ratchetSalt: SALT,
|
316
|
-
ratchetWindowSize: 8
|
341
|
+
ratchetWindowSize: 8,
|
342
|
+
failureTolerance: DECRYPTION_FAILURE_TOLERANCE
|
317
343
|
};
|
318
344
|
|
319
345
|
class LivekitError extends Error {
|
@@ -364,349 +390,386 @@ class CryptorError extends LivekitError {
|
|
364
390
|
}
|
365
391
|
}
|
366
392
|
|
367
|
-
|
368
|
-
Copyright (c) Microsoft Corporation.
|
369
|
-
|
370
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
371
|
-
purpose with or without fee is hereby granted.
|
372
|
-
|
373
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
374
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
375
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
376
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
377
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
378
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
379
|
-
PERFORMANCE OF THIS SOFTWARE.
|
380
|
-
***************************************************************************** */
|
381
|
-
/* global Reflect, Promise */
|
382
|
-
|
383
|
-
|
384
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
385
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
386
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
387
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
388
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
389
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
390
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
391
|
-
});
|
392
|
-
}
|
393
|
-
|
394
|
-
var eventemitter3 = {exports: {}};
|
393
|
+
var events = {exports: {}};
|
395
394
|
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
function
|
395
|
+
var R = typeof Reflect === 'object' ? Reflect : null;
|
396
|
+
var ReflectApply = R && typeof R.apply === 'function' ? R.apply : function ReflectApply(target, receiver, args) {
|
397
|
+
return Function.prototype.apply.call(target, receiver, args);
|
398
|
+
};
|
399
|
+
var ReflectOwnKeys;
|
400
|
+
if (R && typeof R.ownKeys === 'function') {
|
401
|
+
ReflectOwnKeys = R.ownKeys;
|
402
|
+
} else if (Object.getOwnPropertySymbols) {
|
403
|
+
ReflectOwnKeys = function ReflectOwnKeys(target) {
|
404
|
+
return Object.getOwnPropertyNames(target).concat(Object.getOwnPropertySymbols(target));
|
405
|
+
};
|
406
|
+
} else {
|
407
|
+
ReflectOwnKeys = function ReflectOwnKeys(target) {
|
408
|
+
return Object.getOwnPropertyNames(target);
|
409
|
+
};
|
410
|
+
}
|
411
|
+
function ProcessEmitWarning(warning) {
|
412
|
+
if (console && console.warn) console.warn(warning);
|
413
|
+
}
|
414
|
+
var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) {
|
415
|
+
return value !== value;
|
416
|
+
};
|
417
|
+
function EventEmitter() {
|
418
|
+
EventEmitter.init.call(this);
|
419
|
+
}
|
420
|
+
events.exports = EventEmitter;
|
421
|
+
events.exports.once = once;
|
409
422
|
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
// overridden or used as an attack vector.
|
416
|
-
//
|
417
|
-
if (Object.create) {
|
418
|
-
Events.prototype = Object.create(null);
|
423
|
+
// Backwards-compat with node 0.10.x
|
424
|
+
EventEmitter.EventEmitter = EventEmitter;
|
425
|
+
EventEmitter.prototype._events = undefined;
|
426
|
+
EventEmitter.prototype._eventsCount = 0;
|
427
|
+
EventEmitter.prototype._maxListeners = undefined;
|
419
428
|
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
429
|
+
// By default EventEmitters will print a warning if more than 10 listeners are
|
430
|
+
// added to it. This is a useful default which helps finding memory leaks.
|
431
|
+
var defaultMaxListeners = 10;
|
432
|
+
function checkListener(listener) {
|
433
|
+
if (typeof listener !== 'function') {
|
434
|
+
throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
|
425
435
|
}
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
436
|
+
}
|
437
|
+
Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
|
438
|
+
enumerable: true,
|
439
|
+
get: function () {
|
440
|
+
return defaultMaxListeners;
|
441
|
+
},
|
442
|
+
set: function (arg) {
|
443
|
+
if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {
|
444
|
+
throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.');
|
445
|
+
}
|
446
|
+
defaultMaxListeners = arg;
|
447
|
+
}
|
448
|
+
});
|
449
|
+
EventEmitter.init = function () {
|
450
|
+
if (this._events === undefined || this._events === Object.getPrototypeOf(this)._events) {
|
451
|
+
this._events = Object.create(null);
|
452
|
+
this._eventsCount = 0;
|
440
453
|
}
|
454
|
+
this._maxListeners = this._maxListeners || undefined;
|
455
|
+
};
|
441
456
|
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
* @param {Function} fn The listener function.
|
448
|
-
* @param {*} context The context to invoke the listener with.
|
449
|
-
* @param {Boolean} once Specify if the listener is a one-time listener.
|
450
|
-
* @returns {EventEmitter}
|
451
|
-
* @private
|
452
|
-
*/
|
453
|
-
function addListener(emitter, event, fn, context, once) {
|
454
|
-
if (typeof fn !== 'function') {
|
455
|
-
throw new TypeError('The listener must be a function');
|
456
|
-
}
|
457
|
-
var listener = new EE(fn, context || emitter, once),
|
458
|
-
evt = prefix ? prefix + event : event;
|
459
|
-
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);else emitter._events[evt] = [emitter._events[evt], listener];
|
460
|
-
return emitter;
|
457
|
+
// Obviously not all Emitters should be limited to 10. This function allows
|
458
|
+
// that to be increased. Set to zero for unlimited.
|
459
|
+
EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
|
460
|
+
if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) {
|
461
|
+
throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.');
|
461
462
|
}
|
463
|
+
this._maxListeners = n;
|
464
|
+
return this;
|
465
|
+
};
|
466
|
+
function _getMaxListeners(that) {
|
467
|
+
if (that._maxListeners === undefined) return EventEmitter.defaultMaxListeners;
|
468
|
+
return that._maxListeners;
|
469
|
+
}
|
470
|
+
EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
|
471
|
+
return _getMaxListeners(this);
|
472
|
+
};
|
473
|
+
EventEmitter.prototype.emit = function emit(type) {
|
474
|
+
var args = [];
|
475
|
+
for (var i = 1; i < arguments.length; i++) args.push(arguments[i]);
|
476
|
+
var doError = type === 'error';
|
477
|
+
var events = this._events;
|
478
|
+
if (events !== undefined) doError = doError && events.error === undefined;else if (!doError) return false;
|
462
479
|
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
480
|
+
// If there is no 'error' event listener then throw.
|
481
|
+
if (doError) {
|
482
|
+
var er;
|
483
|
+
if (args.length > 0) er = args[0];
|
484
|
+
if (er instanceof Error) {
|
485
|
+
// Note: The comments on the `throw` lines are intentional, they show
|
486
|
+
// up in Node's output if this results in an unhandled exception.
|
487
|
+
throw er; // Unhandled 'error' event
|
488
|
+
}
|
489
|
+
// At least give some kind of context to the user
|
490
|
+
var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));
|
491
|
+
err.context = er;
|
492
|
+
throw err; // Unhandled 'error' event
|
472
493
|
}
|
473
494
|
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
this._events = new Events();
|
483
|
-
this._eventsCount = 0;
|
495
|
+
var handler = events[type];
|
496
|
+
if (handler === undefined) return false;
|
497
|
+
if (typeof handler === 'function') {
|
498
|
+
ReflectApply(handler, this, args);
|
499
|
+
} else {
|
500
|
+
var len = handler.length;
|
501
|
+
var listeners = arrayClone(handler, len);
|
502
|
+
for (var i = 0; i < len; ++i) ReflectApply(listeners[i], this, args);
|
484
503
|
}
|
504
|
+
return true;
|
505
|
+
};
|
506
|
+
function _addListener(target, type, listener, prepend) {
|
507
|
+
var m;
|
508
|
+
var events;
|
509
|
+
var existing;
|
510
|
+
checkListener(listener);
|
511
|
+
events = target._events;
|
512
|
+
if (events === undefined) {
|
513
|
+
events = target._events = Object.create(null);
|
514
|
+
target._eventsCount = 0;
|
515
|
+
} else {
|
516
|
+
// To avoid recursion in the case that type === "newListener"! Before
|
517
|
+
// adding it to the listeners, first emit "newListener".
|
518
|
+
if (events.newListener !== undefined) {
|
519
|
+
target.emit('newListener', type, listener.listener ? listener.listener : listener);
|
485
520
|
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
*
|
490
|
-
* @returns {Array}
|
491
|
-
* @public
|
492
|
-
*/
|
493
|
-
EventEmitter.prototype.eventNames = function eventNames() {
|
494
|
-
var names = [],
|
495
|
-
events,
|
496
|
-
name;
|
497
|
-
if (this._eventsCount === 0) return names;
|
498
|
-
for (name in events = this._events) {
|
499
|
-
if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
|
521
|
+
// Re-assign `events` because a newListener handler could have caused the
|
522
|
+
// this._events to be assigned to a new object
|
523
|
+
events = target._events;
|
500
524
|
}
|
501
|
-
|
502
|
-
|
525
|
+
existing = events[type];
|
526
|
+
}
|
527
|
+
if (existing === undefined) {
|
528
|
+
// Optimize the case of one listener. Don't need the extra array object.
|
529
|
+
existing = events[type] = listener;
|
530
|
+
++target._eventsCount;
|
531
|
+
} else {
|
532
|
+
if (typeof existing === 'function') {
|
533
|
+
// Adding the second element, need to change to array.
|
534
|
+
existing = events[type] = prepend ? [listener, existing] : [existing, listener];
|
535
|
+
// If we've already got an array, just append.
|
536
|
+
} else if (prepend) {
|
537
|
+
existing.unshift(listener);
|
538
|
+
} else {
|
539
|
+
existing.push(listener);
|
503
540
|
}
|
504
|
-
return names;
|
505
|
-
};
|
506
541
|
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
|
520
|
-
ee[i] = handlers[i].fn;
|
542
|
+
// Check for listener leak
|
543
|
+
m = _getMaxListeners(target);
|
544
|
+
if (m > 0 && existing.length > m && !existing.warned) {
|
545
|
+
existing.warned = true;
|
546
|
+
// No error code for this since it is a Warning
|
547
|
+
// eslint-disable-next-line no-restricted-syntax
|
548
|
+
var w = new Error('Possible EventEmitter memory leak detected. ' + existing.length + ' ' + String(type) + ' listeners ' + 'added. Use emitter.setMaxListeners() to ' + 'increase limit');
|
549
|
+
w.name = 'MaxListenersExceededWarning';
|
550
|
+
w.emitter = target;
|
551
|
+
w.type = type;
|
552
|
+
w.count = existing.length;
|
553
|
+
ProcessEmitWarning(w);
|
521
554
|
}
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
if (
|
537
|
-
return
|
555
|
+
}
|
556
|
+
return target;
|
557
|
+
}
|
558
|
+
EventEmitter.prototype.addListener = function addListener(type, listener) {
|
559
|
+
return _addListener(this, type, listener, false);
|
560
|
+
};
|
561
|
+
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
562
|
+
EventEmitter.prototype.prependListener = function prependListener(type, listener) {
|
563
|
+
return _addListener(this, type, listener, true);
|
564
|
+
};
|
565
|
+
function onceWrapper() {
|
566
|
+
if (!this.fired) {
|
567
|
+
this.target.removeListener(this.type, this.wrapFn);
|
568
|
+
this.fired = true;
|
569
|
+
if (arguments.length === 0) return this.listener.call(this.target);
|
570
|
+
return this.listener.apply(this.target, arguments);
|
571
|
+
}
|
572
|
+
}
|
573
|
+
function _onceWrap(target, type, listener) {
|
574
|
+
var state = {
|
575
|
+
fired: false,
|
576
|
+
wrapFn: undefined,
|
577
|
+
target: target,
|
578
|
+
type: type,
|
579
|
+
listener: listener
|
538
580
|
};
|
581
|
+
var wrapped = onceWrapper.bind(state);
|
582
|
+
wrapped.listener = listener;
|
583
|
+
state.wrapFn = wrapped;
|
584
|
+
return wrapped;
|
585
|
+
}
|
586
|
+
EventEmitter.prototype.once = function once(type, listener) {
|
587
|
+
checkListener(listener);
|
588
|
+
this.on(type, _onceWrap(this, type, listener));
|
589
|
+
return this;
|
590
|
+
};
|
591
|
+
EventEmitter.prototype.prependOnceListener = function prependOnceListener(type, listener) {
|
592
|
+
checkListener(listener);
|
593
|
+
this.prependListener(type, _onceWrap(this, type, listener));
|
594
|
+
return this;
|
595
|
+
};
|
539
596
|
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
if (
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
return listeners.fn.call(listeners.context, a1), true;
|
561
|
-
case 3:
|
562
|
-
return listeners.fn.call(listeners.context, a1, a2), true;
|
563
|
-
case 4:
|
564
|
-
return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
565
|
-
case 5:
|
566
|
-
return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
567
|
-
case 6:
|
568
|
-
return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
569
|
-
}
|
570
|
-
for (i = 1, args = new Array(len - 1); i < len; i++) {
|
571
|
-
args[i - 1] = arguments[i];
|
572
|
-
}
|
573
|
-
listeners.fn.apply(listeners.context, args);
|
574
|
-
} else {
|
575
|
-
var length = listeners.length,
|
576
|
-
j;
|
577
|
-
for (i = 0; i < length; i++) {
|
578
|
-
if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
|
579
|
-
switch (len) {
|
580
|
-
case 1:
|
581
|
-
listeners[i].fn.call(listeners[i].context);
|
582
|
-
break;
|
583
|
-
case 2:
|
584
|
-
listeners[i].fn.call(listeners[i].context, a1);
|
585
|
-
break;
|
586
|
-
case 3:
|
587
|
-
listeners[i].fn.call(listeners[i].context, a1, a2);
|
588
|
-
break;
|
589
|
-
case 4:
|
590
|
-
listeners[i].fn.call(listeners[i].context, a1, a2, a3);
|
591
|
-
break;
|
592
|
-
default:
|
593
|
-
if (!args) for (j = 1, args = new Array(len - 1); j < len; j++) {
|
594
|
-
args[j - 1] = arguments[j];
|
595
|
-
}
|
596
|
-
listeners[i].fn.apply(listeners[i].context, args);
|
597
|
-
}
|
597
|
+
// Emits a 'removeListener' event if and only if the listener was removed.
|
598
|
+
EventEmitter.prototype.removeListener = function removeListener(type, listener) {
|
599
|
+
var list, events, position, i, originalListener;
|
600
|
+
checkListener(listener);
|
601
|
+
events = this._events;
|
602
|
+
if (events === undefined) return this;
|
603
|
+
list = events[type];
|
604
|
+
if (list === undefined) return this;
|
605
|
+
if (list === listener || list.listener === listener) {
|
606
|
+
if (--this._eventsCount === 0) this._events = Object.create(null);else {
|
607
|
+
delete events[type];
|
608
|
+
if (events.removeListener) this.emit('removeListener', type, list.listener || listener);
|
609
|
+
}
|
610
|
+
} else if (typeof list !== 'function') {
|
611
|
+
position = -1;
|
612
|
+
for (i = list.length - 1; i >= 0; i--) {
|
613
|
+
if (list[i] === listener || list[i].listener === listener) {
|
614
|
+
originalListener = list[i].listener;
|
615
|
+
position = i;
|
616
|
+
break;
|
598
617
|
}
|
599
618
|
}
|
600
|
-
return
|
601
|
-
|
602
|
-
|
603
|
-
/**
|
604
|
-
* Add a listener for a given event.
|
605
|
-
*
|
606
|
-
* @param {(String|Symbol)} event The event name.
|
607
|
-
* @param {Function} fn The listener function.
|
608
|
-
* @param {*} [context=this] The context to invoke the listener with.
|
609
|
-
* @returns {EventEmitter} `this`.
|
610
|
-
* @public
|
611
|
-
*/
|
612
|
-
EventEmitter.prototype.on = function on(event, fn, context) {
|
613
|
-
return addListener(this, event, fn, context, false);
|
614
|
-
};
|
615
|
-
|
616
|
-
/**
|
617
|
-
* Add a one-time listener for a given event.
|
618
|
-
*
|
619
|
-
* @param {(String|Symbol)} event The event name.
|
620
|
-
* @param {Function} fn The listener function.
|
621
|
-
* @param {*} [context=this] The context to invoke the listener with.
|
622
|
-
* @returns {EventEmitter} `this`.
|
623
|
-
* @public
|
624
|
-
*/
|
625
|
-
EventEmitter.prototype.once = function once(event, fn, context) {
|
626
|
-
return addListener(this, event, fn, context, true);
|
627
|
-
};
|
628
|
-
|
629
|
-
/**
|
630
|
-
* Remove the listeners of a given event.
|
631
|
-
*
|
632
|
-
* @param {(String|Symbol)} event The event name.
|
633
|
-
* @param {Function} fn Only remove the listeners that match this function.
|
634
|
-
* @param {*} context Only remove the listeners that have this context.
|
635
|
-
* @param {Boolean} once Only remove one-time listeners.
|
636
|
-
* @returns {EventEmitter} `this`.
|
637
|
-
* @public
|
638
|
-
*/
|
639
|
-
EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
|
640
|
-
var evt = prefix ? prefix + event : event;
|
641
|
-
if (!this._events[evt]) return this;
|
642
|
-
if (!fn) {
|
643
|
-
clearEvent(this, evt);
|
644
|
-
return this;
|
619
|
+
if (position < 0) return this;
|
620
|
+
if (position === 0) list.shift();else {
|
621
|
+
spliceOne(list, position);
|
645
622
|
}
|
646
|
-
|
647
|
-
if (
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
}
|
623
|
+
if (list.length === 1) events[type] = list[0];
|
624
|
+
if (events.removeListener !== undefined) this.emit('removeListener', type, originalListener || listener);
|
625
|
+
}
|
626
|
+
return this;
|
627
|
+
};
|
628
|
+
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
629
|
+
EventEmitter.prototype.removeAllListeners = function removeAllListeners(type) {
|
630
|
+
var listeners, events, i;
|
631
|
+
events = this._events;
|
632
|
+
if (events === undefined) return this;
|
657
633
|
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
634
|
+
// not listening for removeListener, no need to emit
|
635
|
+
if (events.removeListener === undefined) {
|
636
|
+
if (arguments.length === 0) {
|
637
|
+
this._events = Object.create(null);
|
638
|
+
this._eventsCount = 0;
|
639
|
+
} else if (events[type] !== undefined) {
|
640
|
+
if (--this._eventsCount === 0) this._events = Object.create(null);else delete events[type];
|
662
641
|
}
|
663
642
|
return this;
|
664
|
-
}
|
643
|
+
}
|
665
644
|
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
var evt;
|
675
|
-
if (event) {
|
676
|
-
evt = prefix ? prefix + event : event;
|
677
|
-
if (this._events[evt]) clearEvent(this, evt);
|
678
|
-
} else {
|
679
|
-
this._events = new Events();
|
680
|
-
this._eventsCount = 0;
|
645
|
+
// emit removeListener for all listeners on all events
|
646
|
+
if (arguments.length === 0) {
|
647
|
+
var keys = Object.keys(events);
|
648
|
+
var key;
|
649
|
+
for (i = 0; i < keys.length; ++i) {
|
650
|
+
key = keys[i];
|
651
|
+
if (key === 'removeListener') continue;
|
652
|
+
this.removeAllListeners(key);
|
681
653
|
}
|
654
|
+
this.removeAllListeners('removeListener');
|
655
|
+
this._events = Object.create(null);
|
656
|
+
this._eventsCount = 0;
|
682
657
|
return this;
|
683
|
-
};
|
684
|
-
|
685
|
-
//
|
686
|
-
// Alias methods names because people roll like that.
|
687
|
-
//
|
688
|
-
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
689
|
-
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
|
690
|
-
|
691
|
-
//
|
692
|
-
// Expose the prefix.
|
693
|
-
//
|
694
|
-
EventEmitter.prefixed = prefix;
|
695
|
-
|
696
|
-
//
|
697
|
-
// Allow `EventEmitter` to be imported as module namespace.
|
698
|
-
//
|
699
|
-
EventEmitter.EventEmitter = EventEmitter;
|
700
|
-
|
701
|
-
//
|
702
|
-
// Expose the module.
|
703
|
-
//
|
704
|
-
{
|
705
|
-
module.exports = EventEmitter;
|
706
658
|
}
|
707
|
-
|
708
|
-
|
709
|
-
|
659
|
+
listeners = events[type];
|
660
|
+
if (typeof listeners === 'function') {
|
661
|
+
this.removeListener(type, listeners);
|
662
|
+
} else if (listeners !== undefined) {
|
663
|
+
// LIFO order
|
664
|
+
for (i = listeners.length - 1; i >= 0; i--) {
|
665
|
+
this.removeListener(type, listeners[i]);
|
666
|
+
}
|
667
|
+
}
|
668
|
+
return this;
|
669
|
+
};
|
670
|
+
function _listeners(target, type, unwrap) {
|
671
|
+
var events = target._events;
|
672
|
+
if (events === undefined) return [];
|
673
|
+
var evlistener = events[type];
|
674
|
+
if (evlistener === undefined) return [];
|
675
|
+
if (typeof evlistener === 'function') return unwrap ? [evlistener.listener || evlistener] : [evlistener];
|
676
|
+
return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
|
677
|
+
}
|
678
|
+
EventEmitter.prototype.listeners = function listeners(type) {
|
679
|
+
return _listeners(this, type, true);
|
680
|
+
};
|
681
|
+
EventEmitter.prototype.rawListeners = function rawListeners(type) {
|
682
|
+
return _listeners(this, type, false);
|
683
|
+
};
|
684
|
+
EventEmitter.listenerCount = function (emitter, type) {
|
685
|
+
if (typeof emitter.listenerCount === 'function') {
|
686
|
+
return emitter.listenerCount(type);
|
687
|
+
} else {
|
688
|
+
return listenerCount.call(emitter, type);
|
689
|
+
}
|
690
|
+
};
|
691
|
+
EventEmitter.prototype.listenerCount = listenerCount;
|
692
|
+
function listenerCount(type) {
|
693
|
+
var events = this._events;
|
694
|
+
if (events !== undefined) {
|
695
|
+
var evlistener = events[type];
|
696
|
+
if (typeof evlistener === 'function') {
|
697
|
+
return 1;
|
698
|
+
} else if (evlistener !== undefined) {
|
699
|
+
return evlistener.length;
|
700
|
+
}
|
701
|
+
}
|
702
|
+
return 0;
|
703
|
+
}
|
704
|
+
EventEmitter.prototype.eventNames = function eventNames() {
|
705
|
+
return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];
|
706
|
+
};
|
707
|
+
function arrayClone(arr, n) {
|
708
|
+
var copy = new Array(n);
|
709
|
+
for (var i = 0; i < n; ++i) copy[i] = arr[i];
|
710
|
+
return copy;
|
711
|
+
}
|
712
|
+
function spliceOne(list, index) {
|
713
|
+
for (; index + 1 < list.length; index++) list[index] = list[index + 1];
|
714
|
+
list.pop();
|
715
|
+
}
|
716
|
+
function unwrapListeners(arr) {
|
717
|
+
var ret = new Array(arr.length);
|
718
|
+
for (var i = 0; i < ret.length; ++i) {
|
719
|
+
ret[i] = arr[i].listener || arr[i];
|
720
|
+
}
|
721
|
+
return ret;
|
722
|
+
}
|
723
|
+
function once(emitter, name) {
|
724
|
+
return new Promise(function (resolve, reject) {
|
725
|
+
function errorListener(err) {
|
726
|
+
emitter.removeListener(name, resolver);
|
727
|
+
reject(err);
|
728
|
+
}
|
729
|
+
function resolver() {
|
730
|
+
if (typeof emitter.removeListener === 'function') {
|
731
|
+
emitter.removeListener('error', errorListener);
|
732
|
+
}
|
733
|
+
resolve([].slice.call(arguments));
|
734
|
+
}
|
735
|
+
eventTargetAgnosticAddListener(emitter, name, resolver, {
|
736
|
+
once: true
|
737
|
+
});
|
738
|
+
if (name !== 'error') {
|
739
|
+
addErrorHandlerIfEventEmitter(emitter, errorListener, {
|
740
|
+
once: true
|
741
|
+
});
|
742
|
+
}
|
743
|
+
});
|
744
|
+
}
|
745
|
+
function addErrorHandlerIfEventEmitter(emitter, handler, flags) {
|
746
|
+
if (typeof emitter.on === 'function') {
|
747
|
+
eventTargetAgnosticAddListener(emitter, 'error', handler, flags);
|
748
|
+
}
|
749
|
+
}
|
750
|
+
function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
|
751
|
+
if (typeof emitter.on === 'function') {
|
752
|
+
if (flags.once) {
|
753
|
+
emitter.once(name, listener);
|
754
|
+
} else {
|
755
|
+
emitter.on(name, listener);
|
756
|
+
}
|
757
|
+
} else if (typeof emitter.addEventListener === 'function') {
|
758
|
+
// EventTarget does not have `error` event semantics like Node
|
759
|
+
// EventEmitters, we do not listen for `error` events here.
|
760
|
+
emitter.addEventListener(name, function wrapListener(arg) {
|
761
|
+
// IE does not have builtin `{ once: true }` support so we
|
762
|
+
// have to do it manually.
|
763
|
+
if (flags.once) {
|
764
|
+
emitter.removeEventListener(name, wrapListener);
|
765
|
+
}
|
766
|
+
listener(arg);
|
767
|
+
});
|
768
|
+
} else {
|
769
|
+
throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter);
|
770
|
+
}
|
771
|
+
}
|
772
|
+
var eventsExports = events.exports;
|
710
773
|
|
711
774
|
const CryptorEvent = {
|
712
775
|
Error: 'cryptorError'
|
@@ -802,7 +865,7 @@ function ratchet(material, salt) {
|
|
802
865
|
});
|
803
866
|
}
|
804
867
|
|
805
|
-
class BaseFrameCryptor extends EventEmitter {
|
868
|
+
class BaseFrameCryptor extends eventsExports.EventEmitter {
|
806
869
|
encodeFunction(encodedFrame, controller) {
|
807
870
|
throw Error('not implemented for subclass');
|
808
871
|
}
|
@@ -818,7 +881,6 @@ class FrameCryptor extends BaseFrameCryptor {
|
|
818
881
|
constructor(opts) {
|
819
882
|
var _a;
|
820
883
|
super();
|
821
|
-
this.isKeyInvalid = false;
|
822
884
|
this.sendCounts = new Map();
|
823
885
|
this.keys = opts.keys;
|
824
886
|
this.participantId = opts.participantId;
|
@@ -963,19 +1025,19 @@ class FrameCryptor extends BaseFrameCryptor {
|
|
963
1025
|
}
|
964
1026
|
const data = new Uint8Array(encodedFrame.data);
|
965
1027
|
const keyIndex = data[encodedFrame.data.byteLength - 1];
|
966
|
-
if (this.keys.getKeySet(keyIndex)) {
|
1028
|
+
if (this.keys.getKeySet(keyIndex) && this.keys.hasValidKey) {
|
967
1029
|
try {
|
968
1030
|
const decodedFrame = yield this.decryptFrame(encodedFrame, keyIndex);
|
1031
|
+
this.keys.decryptionSuccess();
|
969
1032
|
if (decodedFrame) {
|
970
1033
|
return controller.enqueue(decodedFrame);
|
971
1034
|
}
|
972
|
-
this.isKeyInvalid = false;
|
973
1035
|
} catch (error) {
|
974
1036
|
if (error instanceof CryptorError && error.reason === CryptorErrorReason.InvalidKey) {
|
975
|
-
if (
|
1037
|
+
if (this.keys.hasValidKey) {
|
976
1038
|
workerLogger.warn('invalid key');
|
977
1039
|
this.emit(CryptorEvent.Error, new CryptorError("invalid key for participant ".concat(this.participantId), CryptorErrorReason.InvalidKey));
|
978
|
-
this.
|
1040
|
+
this.keys.decryptionFailure();
|
979
1041
|
}
|
980
1042
|
} else {
|
981
1043
|
workerLogger.warn('decoding frame failed', {
|
@@ -983,8 +1045,6 @@ class FrameCryptor extends BaseFrameCryptor {
|
|
983
1045
|
});
|
984
1046
|
}
|
985
1047
|
}
|
986
|
-
} else {
|
987
|
-
this.emit(CryptorEvent.Error, new CryptorError("key missing for participant ".concat(this.participantId), CryptorErrorReason.MissingKey));
|
988
1048
|
}
|
989
1049
|
return controller.enqueue(encodedFrame);
|
990
1050
|
});
|
@@ -1059,6 +1119,7 @@ class FrameCryptor extends BaseFrameCryptor {
|
|
1059
1119
|
this.keys.setKeyFromMaterial(initialMaterial.material, keyIndex);
|
1060
1120
|
}
|
1061
1121
|
workerLogger.warn('maximum ratchet attempts exceeded, resetting key');
|
1122
|
+
this.emit(CryptorEvent.Error, new CryptorError("valid key missing for participant ".concat(this.participantId), CryptorErrorReason.MissingKey));
|
1062
1123
|
}
|
1063
1124
|
} else {
|
1064
1125
|
throw new CryptorError('Decryption failed, most likely because of an invalid key', CryptorErrorReason.InvalidKey);
|
@@ -1244,19 +1305,45 @@ function isFrameServerInjected(frameData, trailerBytes) {
|
|
1244
1305
|
* if decryption fails or can be triggered manually on both sender and receiver side.
|
1245
1306
|
*
|
1246
1307
|
*/
|
1247
|
-
class ParticipantKeyHandler extends EventEmitter {
|
1308
|
+
class ParticipantKeyHandler extends eventsExports.EventEmitter {
|
1309
|
+
get hasValidKey() {
|
1310
|
+
return this._hasValidKey;
|
1311
|
+
}
|
1248
1312
|
constructor(participantId, isEnabled, keyProviderOptions) {
|
1249
1313
|
super();
|
1314
|
+
this.decryptionFailureCount = 0;
|
1315
|
+
this._hasValidKey = true;
|
1250
1316
|
this.currentKeyIndex = 0;
|
1251
1317
|
this.cryptoKeyRing = new Array(KEYRING_SIZE);
|
1252
1318
|
this.enabled = isEnabled;
|
1253
1319
|
this.keyProviderOptions = keyProviderOptions;
|
1254
1320
|
this.ratchetPromiseMap = new Map();
|
1255
1321
|
this.participantId = participantId;
|
1322
|
+
this.resetKeyStatus();
|
1256
1323
|
}
|
1257
1324
|
setEnabled(enabled) {
|
1258
1325
|
this.enabled = enabled;
|
1259
1326
|
}
|
1327
|
+
decryptionFailure() {
|
1328
|
+
if (this.keyProviderOptions.failureTolerance < 0) {
|
1329
|
+
return;
|
1330
|
+
}
|
1331
|
+
this.decryptionFailureCount += 1;
|
1332
|
+
if (this.decryptionFailureCount > this.keyProviderOptions.failureTolerance) {
|
1333
|
+
this._hasValidKey = false;
|
1334
|
+
}
|
1335
|
+
}
|
1336
|
+
decryptionSuccess() {
|
1337
|
+
this.resetKeyStatus();
|
1338
|
+
}
|
1339
|
+
/**
|
1340
|
+
* Call this after user initiated ratchet or a new key has been set in order to make sure to mark potentially
|
1341
|
+
* invalid keys as valid again
|
1342
|
+
*/
|
1343
|
+
resetKeyStatus() {
|
1344
|
+
this.decryptionFailureCount = 0;
|
1345
|
+
this._hasValidKey = true;
|
1346
|
+
}
|
1260
1347
|
/**
|
1261
1348
|
* Ratchets the current key (or the one at keyIndex if provided) and
|
1262
1349
|
* returns the ratcheted material
|
@@ -1289,6 +1376,19 @@ class ParticipantKeyHandler extends EventEmitter {
|
|
1289
1376
|
this.ratchetPromiseMap.set(currentKeyIndex, ratchetPromise);
|
1290
1377
|
return ratchetPromise;
|
1291
1378
|
}
|
1379
|
+
/**
|
1380
|
+
* takes in a key material with `deriveBits` and `deriveKey` set as key usages
|
1381
|
+
* and derives encryption keys from the material and sets it on the key ring buffer
|
1382
|
+
* together with the material
|
1383
|
+
* also resets the valid key property and updates the currentKeyIndex
|
1384
|
+
*/
|
1385
|
+
setKey(material) {
|
1386
|
+
let keyIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
1387
|
+
return __awaiter(this, void 0, void 0, function* () {
|
1388
|
+
yield this.setKeyFromMaterial(material, keyIndex);
|
1389
|
+
this.resetKeyStatus();
|
1390
|
+
});
|
1391
|
+
}
|
1292
1392
|
/**
|
1293
1393
|
* takes in a key material with `deriveBits` and `deriveKey` set as key usages
|
1294
1394
|
* and derives encryption keys from the material and sets it on the key ring buffer
|
@@ -1319,6 +1419,7 @@ class ParticipantKeyHandler extends EventEmitter {
|
|
1319
1419
|
setCurrentKeyIndex(index) {
|
1320
1420
|
return __awaiter(this, void 0, void 0, function* () {
|
1321
1421
|
this.currentKeyIndex = index % this.cryptoKeyRing.length;
|
1422
|
+
this.resetKeyStatus();
|
1322
1423
|
});
|
1323
1424
|
}
|
1324
1425
|
isEnabled() {
|
@@ -1386,7 +1487,7 @@ onmessage = ev => {
|
|
1386
1487
|
workerLogger.debug('set shared key');
|
1387
1488
|
setSharedKey(data.key, data.keyIndex);
|
1388
1489
|
} else if (data.participantId) {
|
1389
|
-
getParticipantKeyHandler(data.participantId).
|
1490
|
+
getParticipantKeyHandler(data.participantId).setKey(data.key, data.keyIndex);
|
1390
1491
|
} else {
|
1391
1492
|
workerLogger.error('no participant Id was provided and shared key usage is disabled');
|
1392
1493
|
}
|
@@ -1403,9 +1504,16 @@ onmessage = ev => {
|
|
1403
1504
|
});
|
1404
1505
|
break;
|
1405
1506
|
case 'ratchetRequest':
|
1406
|
-
|
1507
|
+
handleRatchetRequest(data);
|
1407
1508
|
}
|
1408
1509
|
};
|
1510
|
+
function handleRatchetRequest(data) {
|
1511
|
+
return __awaiter(this, void 0, void 0, function* () {
|
1512
|
+
const keyHandler = getParticipantKeyHandler(data.participantId);
|
1513
|
+
yield keyHandler.ratchetKey(data.keyIndex);
|
1514
|
+
keyHandler.resetKeyStatus();
|
1515
|
+
});
|
1516
|
+
}
|
1409
1517
|
function getTrackCryptor(participantId, trackId) {
|
1410
1518
|
let cryptor = participantCryptors.find(c => c.getTrackId() === trackId);
|
1411
1519
|
if (!cryptor) {
|
@@ -1436,7 +1544,7 @@ function getParticipantKeyHandler(participantId) {
|
|
1436
1544
|
if (!keys) {
|
1437
1545
|
keys = new ParticipantKeyHandler(participantId, true, keyProviderOptions);
|
1438
1546
|
if (sharedKey) {
|
1439
|
-
keys.
|
1547
|
+
keys.setKey(sharedKey);
|
1440
1548
|
}
|
1441
1549
|
participantKeys.set(participantId, keys);
|
1442
1550
|
}
|
@@ -1473,9 +1581,9 @@ function setEncryptionEnabled(enable, participantId) {
|
|
1473
1581
|
function setSharedKey(key, index) {
|
1474
1582
|
workerLogger.debug('setting shared key');
|
1475
1583
|
sharedKey = key;
|
1476
|
-
publisherKeys === null || publisherKeys === void 0 ? void 0 : publisherKeys.
|
1584
|
+
publisherKeys === null || publisherKeys === void 0 ? void 0 : publisherKeys.setKey(key, index);
|
1477
1585
|
for (const [, keyHandler] of participantKeys) {
|
1478
|
-
keyHandler.
|
1586
|
+
keyHandler.setKey(key, index);
|
1479
1587
|
}
|
1480
1588
|
}
|
1481
1589
|
function setupCryptorErrorEvents(cryptor) {
|