livekit-client 2.0.1 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. package/dist/livekit-client.e2ee.worker.js +1 -1
  2. package/dist/livekit-client.e2ee.worker.js.map +1 -1
  3. package/dist/livekit-client.e2ee.worker.mjs +53 -18
  4. package/dist/livekit-client.e2ee.worker.mjs.map +1 -1
  5. package/dist/livekit-client.esm.mjs +94 -57
  6. package/dist/livekit-client.esm.mjs.map +1 -1
  7. package/dist/livekit-client.umd.js +1 -1
  8. package/dist/livekit-client.umd.js.map +1 -1
  9. package/dist/src/e2ee/KeyProvider.d.ts +1 -1
  10. package/dist/src/e2ee/KeyProvider.d.ts.map +1 -1
  11. package/dist/src/e2ee/worker/FrameCryptor.d.ts +1 -0
  12. package/dist/src/e2ee/worker/FrameCryptor.d.ts.map +1 -1
  13. package/dist/src/e2ee/worker/ParticipantKeyHandler.d.ts +2 -2
  14. package/dist/src/e2ee/worker/ParticipantKeyHandler.d.ts.map +1 -1
  15. package/dist/src/room/Room.d.ts +1 -0
  16. package/dist/src/room/Room.d.ts.map +1 -1
  17. package/dist/src/room/events.d.ts +5 -1
  18. package/dist/src/room/events.d.ts.map +1 -1
  19. package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
  20. package/dist/src/room/track/LocalAudioTrack.d.ts +8 -7
  21. package/dist/src/room/track/LocalAudioTrack.d.ts.map +1 -1
  22. package/dist/src/room/track/LocalTrack.d.ts +11 -9
  23. package/dist/src/room/track/LocalTrack.d.ts.map +1 -1
  24. package/dist/src/room/track/LocalTrackPublication.d.ts +2 -2
  25. package/dist/src/room/track/LocalVideoTrack.d.ts +3 -3
  26. package/dist/src/room/track/LocalVideoTrack.d.ts.map +1 -1
  27. package/dist/src/room/track/RemoteAudioTrack.d.ts +2 -1
  28. package/dist/src/room/track/RemoteAudioTrack.d.ts.map +1 -1
  29. package/dist/src/room/track/RemoteTrack.d.ts +2 -2
  30. package/dist/src/room/track/RemoteTrack.d.ts.map +1 -1
  31. package/dist/src/room/track/RemoteVideoTrack.d.ts +2 -1
  32. package/dist/src/room/track/RemoteVideoTrack.d.ts.map +1 -1
  33. package/dist/src/room/track/Track.d.ts +5 -3
  34. package/dist/src/room/track/Track.d.ts.map +1 -1
  35. package/dist/src/room/track/processor/types.d.ts +4 -0
  36. package/dist/src/room/track/processor/types.d.ts.map +1 -1
  37. package/dist/ts4.2/src/e2ee/KeyProvider.d.ts +1 -1
  38. package/dist/ts4.2/src/e2ee/worker/FrameCryptor.d.ts +1 -0
  39. package/dist/ts4.2/src/e2ee/worker/ParticipantKeyHandler.d.ts +2 -2
  40. package/dist/ts4.2/src/room/Room.d.ts +1 -0
  41. package/dist/ts4.2/src/room/events.d.ts +5 -1
  42. package/dist/ts4.2/src/room/track/LocalAudioTrack.d.ts +8 -7
  43. package/dist/ts4.2/src/room/track/LocalTrack.d.ts +11 -9
  44. package/dist/ts4.2/src/room/track/LocalTrackPublication.d.ts +2 -2
  45. package/dist/ts4.2/src/room/track/LocalVideoTrack.d.ts +3 -3
  46. package/dist/ts4.2/src/room/track/RemoteAudioTrack.d.ts +2 -1
  47. package/dist/ts4.2/src/room/track/RemoteTrack.d.ts +2 -2
  48. package/dist/ts4.2/src/room/track/RemoteVideoTrack.d.ts +2 -1
  49. package/dist/ts4.2/src/room/track/Track.d.ts +5 -3
  50. package/dist/ts4.2/src/room/track/processor/types.d.ts +4 -0
  51. package/package.json +1 -1
  52. package/src/api/SignalClient.ts +1 -1
  53. package/src/e2ee/KeyProvider.ts +6 -1
  54. package/src/e2ee/worker/FrameCryptor.ts +26 -0
  55. package/src/e2ee/worker/ParticipantKeyHandler.ts +9 -5
  56. package/src/e2ee/worker/e2ee.worker.ts +17 -14
  57. package/src/room/Room.ts +21 -4
  58. package/src/room/events.ts +4 -0
  59. package/src/room/participant/LocalParticipant.ts +0 -1
  60. package/src/room/track/LocalAudioTrack.ts +9 -11
  61. package/src/room/track/LocalTrack.ts +78 -56
  62. package/src/room/track/LocalVideoTrack.ts +3 -3
  63. package/src/room/track/RemoteAudioTrack.ts +1 -1
  64. package/src/room/track/RemoteTrack.ts +4 -2
  65. package/src/room/track/RemoteVideoTrack.ts +1 -1
  66. package/src/room/track/Track.ts +7 -3
  67. package/src/room/track/processor/types.ts +4 -0
@@ -9980,6 +9980,9 @@ class BaseKeyProvider extends eventsExports.EventEmitter {
9980
9980
  participantIdentity,
9981
9981
  keyIndex
9982
9982
  };
9983
+ if (!this.options.sharedKey && !participantIdentity) {
9984
+ throw new Error('participant identity needs to be passed for encryption key if sharedKey option is false');
9985
+ }
9983
9986
  this.keyInfoMap.set("".concat(participantIdentity !== null && participantIdentity !== void 0 ? participantIdentity : 'shared', "-").concat(keyIndex !== null && keyIndex !== void 0 ? keyIndex : 0), keyInfo);
9984
9987
  this.emit(KeyProviderEvent.SetKey, keyInfo);
9985
9988
  }
@@ -10595,6 +10598,10 @@ var TrackEvent;
10595
10598
  * Fires on RemoteTrackPublication
10596
10599
  */
10597
10600
  TrackEvent["SubscriptionFailed"] = "subscriptionFailed";
10601
+ /**
10602
+ * @internal
10603
+ */
10604
+ TrackEvent["TrackProcessorUpdate"] = "trackProcessorUpdate";
10598
10605
  })(TrackEvent || (TrackEvent = {}));
10599
10606
 
10600
10607
  function r(r, e, n) {
@@ -10703,7 +10710,7 @@ function getMatch(exp, ua) {
10703
10710
  return match && match.length >= id && match[id] || '';
10704
10711
  }
10705
10712
 
10706
- var version$1 = "2.0.1";
10713
+ var version$1 = "2.0.3";
10707
10714
 
10708
10715
  const version = version$1;
10709
10716
  const protocolVersion = 12;
@@ -14206,6 +14213,7 @@ class LocalTrack extends Track {
14206
14213
  this.muteLock = new Mutex();
14207
14214
  this.pauseUpstreamLock = new Mutex();
14208
14215
  this.processorLock = new Mutex();
14216
+ this.restartLock = new Mutex();
14209
14217
  this.setMediaStreamTrack(mediaTrack, true);
14210
14218
  // added to satisfy TS compiler, constraints are synced with MediaStreamTrack
14211
14219
  this._constraints = mediaTrack.getConstraints();
@@ -14270,20 +14278,27 @@ class LocalTrack extends Track {
14270
14278
  this._constraints = newTrack.getConstraints();
14271
14279
  }
14272
14280
  let processedTrack;
14273
- if (this.processor && newTrack && this.processorElement) {
14274
- this.log.debug('restarting processor', this.logContext);
14275
- if (this.kind === 'unknown') {
14276
- throw TypeError('cannot set processor on track of unknown kind');
14281
+ if (this.processor && newTrack) {
14282
+ const unlock = yield this.processorLock.lock();
14283
+ try {
14284
+ this.log.debug('restarting processor', this.logContext);
14285
+ if (this.kind === 'unknown') {
14286
+ throw TypeError('cannot set processor on track of unknown kind');
14287
+ }
14288
+ if (this.processorElement) {
14289
+ attachToElement(newTrack, this.processorElement);
14290
+ // ensure the processorElement itself stays muted
14291
+ this.processorElement.muted = true;
14292
+ }
14293
+ yield this.processor.restart({
14294
+ track: newTrack,
14295
+ kind: this.kind,
14296
+ element: this.processorElement
14297
+ });
14298
+ processedTrack = this.processor.processedTrack;
14299
+ } finally {
14300
+ unlock();
14277
14301
  }
14278
- attachToElement(newTrack, this.processorElement);
14279
- // ensure the processorElement itself stays muted
14280
- this.processorElement.muted = true;
14281
- yield this.processor.restart({
14282
- track: newTrack,
14283
- kind: this.kind,
14284
- element: this.processorElement
14285
- });
14286
- processedTrack = this.processor.processedTrack;
14287
14302
  }
14288
14303
  if (this.sender) {
14289
14304
  yield this.sender.replaceTrack(processedTrack !== null && processedTrack !== void 0 ? processedTrack : newTrack);
@@ -14376,40 +14391,45 @@ class LocalTrack extends Track {
14376
14391
  }
14377
14392
  restart(constraints) {
14378
14393
  return __awaiter(this, void 0, void 0, function* () {
14379
- if (!constraints) {
14380
- constraints = this._constraints;
14381
- }
14382
- this.log.debug('restarting track with constraints', Object.assign(Object.assign({}, this.logContext), {
14383
- constraints
14384
- }));
14385
- const streamConstraints = {
14386
- audio: false,
14387
- video: false
14388
- };
14389
- if (this.kind === Track.Kind.Video) {
14390
- streamConstraints.video = constraints;
14391
- } else {
14392
- streamConstraints.audio = constraints;
14394
+ const unlock = yield this.restartLock.lock();
14395
+ try {
14396
+ if (!constraints) {
14397
+ constraints = this._constraints;
14398
+ }
14399
+ this.log.debug('restarting track with constraints', Object.assign(Object.assign({}, this.logContext), {
14400
+ constraints
14401
+ }));
14402
+ const streamConstraints = {
14403
+ audio: false,
14404
+ video: false
14405
+ };
14406
+ if (this.kind === Track.Kind.Video) {
14407
+ streamConstraints.video = constraints;
14408
+ } else {
14409
+ streamConstraints.audio = constraints;
14410
+ }
14411
+ // these steps are duplicated from setMediaStreamTrack because we must stop
14412
+ // the previous tracks before new tracks can be acquired
14413
+ this.attachedElements.forEach(el => {
14414
+ detachTrack(this.mediaStreamTrack, el);
14415
+ });
14416
+ this._mediaStreamTrack.removeEventListener('ended', this.handleEnded);
14417
+ // on Safari, the old audio track must be stopped before attempting to acquire
14418
+ // the new track, otherwise the new track will stop with
14419
+ // 'A MediaStreamTrack ended due to a capture failure`
14420
+ this._mediaStreamTrack.stop();
14421
+ // create new track and attach
14422
+ const mediaStream = yield navigator.mediaDevices.getUserMedia(streamConstraints);
14423
+ const newTrack = mediaStream.getTracks()[0];
14424
+ newTrack.addEventListener('ended', this.handleEnded);
14425
+ this.log.debug('re-acquired MediaStreamTrack', this.logContext);
14426
+ yield this.setMediaStreamTrack(newTrack);
14427
+ this._constraints = constraints;
14428
+ this.emit(TrackEvent.Restarted, this);
14429
+ return this;
14430
+ } finally {
14431
+ unlock();
14393
14432
  }
14394
- // these steps are duplicated from setMediaStreamTrack because we must stop
14395
- // the previous tracks before new tracks can be acquired
14396
- this.attachedElements.forEach(el => {
14397
- detachTrack(this.mediaStreamTrack, el);
14398
- });
14399
- this._mediaStreamTrack.removeEventListener('ended', this.handleEnded);
14400
- // on Safari, the old audio track must be stopped before attempting to acquire
14401
- // the new track, otherwise the new track will stop with
14402
- // 'A MediaStreamTrack ended due to a capture failure`
14403
- this._mediaStreamTrack.stop();
14404
- // create new track and attach
14405
- const mediaStream = yield navigator.mediaDevices.getUserMedia(streamConstraints);
14406
- const newTrack = mediaStream.getTracks()[0];
14407
- newTrack.addEventListener('ended', this.handleEnded);
14408
- this.log.debug('re-acquired MediaStreamTrack', this.logContext);
14409
- yield this.setMediaStreamTrack(newTrack);
14410
- this._constraints = constraints;
14411
- this.emit(TrackEvent.Restarted, this);
14412
- return this;
14413
14433
  });
14414
14434
  }
14415
14435
  setTrackMuted(muted) {
@@ -14548,7 +14568,8 @@ class LocalTrack extends Track {
14548
14568
  const processorOptions = {
14549
14569
  kind: this.kind,
14550
14570
  track: this._mediaStreamTrack,
14551
- element: this.processorElement
14571
+ element: this.processorElement,
14572
+ audioContext: this.audioContext
14552
14573
  };
14553
14574
  yield processor.init(processorOptions);
14554
14575
  this.processor = processor;
@@ -14561,6 +14582,7 @@ class LocalTrack extends Track {
14561
14582
  }
14562
14583
  yield (_b = this.sender) === null || _b === void 0 ? void 0 : _b.replaceTrack(this.processor.processedTrack);
14563
14584
  }
14585
+ this.emit(TrackEvent.TrackProcessorUpdate, this.processor);
14564
14586
  } finally {
14565
14587
  unlock();
14566
14588
  }
@@ -14587,6 +14609,7 @@ class LocalTrack extends Track {
14587
14609
  (_b = this.processorElement) === null || _b === void 0 ? void 0 : _b.remove();
14588
14610
  this.processorElement = undefined;
14589
14611
  yield this.restart();
14612
+ this.emit(TrackEvent.TrackProcessorUpdate);
14590
14613
  });
14591
14614
  }
14592
14615
  }
@@ -15123,7 +15146,9 @@ class SignalClient {
15123
15146
  let resp;
15124
15147
  if (typeof ev.data === 'string') {
15125
15148
  const json = JSON.parse(ev.data);
15126
- resp = SignalResponse.fromJson(json);
15149
+ resp = SignalResponse.fromJson(json, {
15150
+ ignoreUnknownFields: true
15151
+ });
15127
15152
  } else if (ev.data instanceof ArrayBuffer) {
15128
15153
  resp = SignalResponse.fromBinary(new Uint8Array(ev.data));
15129
15154
  } else {
@@ -18420,9 +18445,6 @@ class LocalAudioTrack extends LocalTrack {
18420
18445
  if (this.processor) {
18421
18446
  yield this.stopProcessor();
18422
18447
  }
18423
- if (this.kind === 'unknown') {
18424
- throw TypeError('cannot set processor on track of unknown kind');
18425
- }
18426
18448
  const processorOptions = {
18427
18449
  kind: this.kind,
18428
18450
  track: this._mediaStreamTrack,
@@ -18434,6 +18456,7 @@ class LocalAudioTrack extends LocalTrack {
18434
18456
  if (this.processor.processedTrack) {
18435
18457
  yield (_a = this.sender) === null || _a === void 0 ? void 0 : _a.replaceTrack(this.processor.processedTrack);
18436
18458
  }
18459
+ this.emit(TrackEvent.TrackProcessorUpdate, this.processor);
18437
18460
  } finally {
18438
18461
  unlock();
18439
18462
  }
@@ -22034,14 +22057,20 @@ class Room extends eventsExports.EventEmitter {
22034
22057
  const pi = joinResponse.participant;
22035
22058
  this.localParticipant.sid = pi.sid;
22036
22059
  this.localParticipant.identity = pi.identity;
22060
+ if (this.options.e2ee && this.e2eeManager) {
22061
+ try {
22062
+ this.e2eeManager.setSifTrailer(joinResponse.sifTrailer);
22063
+ } catch (e) {
22064
+ this.log.error(e instanceof Error ? e.message : 'Could not set SifTrailer', Object.assign(Object.assign({}, this.logContext), {
22065
+ error: e
22066
+ }));
22067
+ }
22068
+ }
22037
22069
  // populate remote participants, these should not trigger new events
22038
22070
  this.handleParticipantUpdates([pi, ...joinResponse.otherParticipants]);
22039
22071
  if (joinResponse.room) {
22040
22072
  this.handleRoomUpdate(joinResponse.room);
22041
22073
  }
22042
- if (this.options.e2ee && this.e2eeManager) {
22043
- this.e2eeManager.setSifTrailer(joinResponse.sifTrailer);
22044
- }
22045
22074
  };
22046
22075
  this.attemptConnection = (url, token, opts, abortController) => __awaiter(this, void 0, void 0, function* () {
22047
22076
  var _h, _j, _k;
@@ -22476,8 +22505,14 @@ class Room extends eventsExports.EventEmitter {
22476
22505
  this.onLocalTrackUnmuted = pub => {
22477
22506
  this.emit(RoomEvent.TrackUnmuted, pub, this.localParticipant);
22478
22507
  };
22508
+ this.onTrackProcessorUpdate = processor => {
22509
+ var _a;
22510
+ (_a = processor === null || processor === void 0 ? void 0 : processor.onPublish) === null || _a === void 0 ? void 0 : _a.call(processor, this);
22511
+ };
22479
22512
  this.onLocalTrackPublished = pub => __awaiter(this, void 0, void 0, function* () {
22480
- var _r;
22513
+ var _r, _s, _t, _u, _v;
22514
+ (_r = pub.track) === null || _r === void 0 ? void 0 : _r.on(TrackEvent.TrackProcessorUpdate, this.onTrackProcessorUpdate);
22515
+ (_u = (_t = (_s = pub.track) === null || _s === void 0 ? void 0 : _s.getProcessor()) === null || _t === void 0 ? void 0 : _t.onPublish) === null || _u === void 0 ? void 0 : _u.call(_t, this);
22481
22516
  this.emit(RoomEvent.LocalTrackPublished, pub, this.localParticipant);
22482
22517
  if (pub.track instanceof LocalAudioTrack) {
22483
22518
  const trackIsSilent = yield pub.track.checkForSilence();
@@ -22485,7 +22520,7 @@ class Room extends eventsExports.EventEmitter {
22485
22520
  this.emit(RoomEvent.LocalAudioSilenceDetected, pub);
22486
22521
  }
22487
22522
  }
22488
- const deviceId = yield (_r = pub.track) === null || _r === void 0 ? void 0 : _r.getDeviceId();
22523
+ const deviceId = yield (_v = pub.track) === null || _v === void 0 ? void 0 : _v.getDeviceId();
22489
22524
  const deviceKind = sourceToKind(pub.source);
22490
22525
  if (deviceKind && deviceId && deviceId !== this.localParticipant.activeDeviceMap.get(deviceKind)) {
22491
22526
  this.localParticipant.activeDeviceMap.set(deviceKind, deviceId);
@@ -22493,6 +22528,8 @@ class Room extends eventsExports.EventEmitter {
22493
22528
  }
22494
22529
  });
22495
22530
  this.onLocalTrackUnpublished = pub => {
22531
+ var _a;
22532
+ (_a = pub.track) === null || _a === void 0 ? void 0 : _a.off(TrackEvent.TrackProcessorUpdate, this.onTrackProcessorUpdate);
22496
22533
  this.emit(RoomEvent.LocalTrackUnpublished, pub, this.localParticipant);
22497
22534
  };
22498
22535
  this.onLocalConnectionQualityChanged = quality => {