livekit-client 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) 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 +52 -17
  4. package/dist/livekit-client.e2ee.worker.mjs.map +1 -1
  5. package/dist/livekit-client.esm.mjs +69 -40
  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/track/LocalAudioTrack.d.ts.map +1 -1
  20. package/dist/src/room/track/LocalTrack.d.ts +1 -0
  21. package/dist/src/room/track/LocalTrack.d.ts.map +1 -1
  22. package/dist/src/room/track/Track.d.ts +2 -0
  23. package/dist/src/room/track/Track.d.ts.map +1 -1
  24. package/dist/ts4.2/src/e2ee/KeyProvider.d.ts +1 -1
  25. package/dist/ts4.2/src/e2ee/worker/FrameCryptor.d.ts +1 -0
  26. package/dist/ts4.2/src/e2ee/worker/ParticipantKeyHandler.d.ts +2 -2
  27. package/dist/ts4.2/src/room/Room.d.ts +1 -0
  28. package/dist/ts4.2/src/room/events.d.ts +5 -1
  29. package/dist/ts4.2/src/room/track/LocalTrack.d.ts +1 -0
  30. package/dist/ts4.2/src/room/track/Track.d.ts +2 -0
  31. package/package.json +1 -1
  32. package/src/e2ee/KeyProvider.ts +6 -1
  33. package/src/e2ee/worker/FrameCryptor.ts +26 -0
  34. package/src/e2ee/worker/ParticipantKeyHandler.ts +9 -5
  35. package/src/e2ee/worker/e2ee.worker.ts +16 -17
  36. package/src/room/Room.ts +18 -4
  37. package/src/room/events.ts +4 -0
  38. package/src/room/track/LocalAudioTrack.ts +1 -0
  39. package/src/room/track/LocalTrack.ts +42 -33
  40. package/src/room/track/Track.ts +2 -0
@@ -42,6 +42,8 @@ export default abstract class LocalTrack<
42
42
 
43
43
  protected audioContext?: AudioContext;
44
44
 
45
+ private restartLock: Mutex;
46
+
45
47
  /**
46
48
  *
47
49
  * @param mediaTrack
@@ -62,6 +64,7 @@ export default abstract class LocalTrack<
62
64
  this.muteLock = new Mutex();
63
65
  this.pauseUpstreamLock = new Mutex();
64
66
  this.processorLock = new Mutex();
67
+ this.restartLock = new Mutex();
65
68
  this.setMediaStreamTrack(mediaTrack, true);
66
69
 
67
70
  // added to satisfy TS compiler, constraints are synced with MediaStreamTrack
@@ -239,44 +242,49 @@ export default abstract class LocalTrack<
239
242
  }
240
243
 
241
244
  protected async restart(constraints?: MediaTrackConstraints) {
242
- if (!constraints) {
243
- constraints = this._constraints;
244
- }
245
- this.log.debug('restarting track with constraints', { ...this.logContext, constraints });
245
+ const unlock = await this.restartLock.lock();
246
+ try {
247
+ if (!constraints) {
248
+ constraints = this._constraints;
249
+ }
250
+ this.log.debug('restarting track with constraints', { ...this.logContext, constraints });
246
251
 
247
- const streamConstraints: MediaStreamConstraints = {
248
- audio: false,
249
- video: false,
250
- };
252
+ const streamConstraints: MediaStreamConstraints = {
253
+ audio: false,
254
+ video: false,
255
+ };
251
256
 
252
- if (this.kind === Track.Kind.Video) {
253
- streamConstraints.video = constraints;
254
- } else {
255
- streamConstraints.audio = constraints;
256
- }
257
+ if (this.kind === Track.Kind.Video) {
258
+ streamConstraints.video = constraints;
259
+ } else {
260
+ streamConstraints.audio = constraints;
261
+ }
257
262
 
258
- // these steps are duplicated from setMediaStreamTrack because we must stop
259
- // the previous tracks before new tracks can be acquired
260
- this.attachedElements.forEach((el) => {
261
- detachTrack(this.mediaStreamTrack, el);
262
- });
263
- this._mediaStreamTrack.removeEventListener('ended', this.handleEnded);
264
- // on Safari, the old audio track must be stopped before attempting to acquire
265
- // the new track, otherwise the new track will stop with
266
- // 'A MediaStreamTrack ended due to a capture failure`
267
- this._mediaStreamTrack.stop();
263
+ // these steps are duplicated from setMediaStreamTrack because we must stop
264
+ // the previous tracks before new tracks can be acquired
265
+ this.attachedElements.forEach((el) => {
266
+ detachTrack(this.mediaStreamTrack, el);
267
+ });
268
+ this._mediaStreamTrack.removeEventListener('ended', this.handleEnded);
269
+ // on Safari, the old audio track must be stopped before attempting to acquire
270
+ // the new track, otherwise the new track will stop with
271
+ // 'A MediaStreamTrack ended due to a capture failure`
272
+ this._mediaStreamTrack.stop();
268
273
 
269
- // create new track and attach
270
- const mediaStream = await navigator.mediaDevices.getUserMedia(streamConstraints);
271
- const newTrack = mediaStream.getTracks()[0];
272
- newTrack.addEventListener('ended', this.handleEnded);
273
- this.log.debug('re-acquired MediaStreamTrack', this.logContext);
274
+ // create new track and attach
275
+ const mediaStream = await navigator.mediaDevices.getUserMedia(streamConstraints);
276
+ const newTrack = mediaStream.getTracks()[0];
277
+ newTrack.addEventListener('ended', this.handleEnded);
278
+ this.log.debug('re-acquired MediaStreamTrack', this.logContext);
274
279
 
275
- await this.setMediaStreamTrack(newTrack);
276
- this._constraints = constraints;
280
+ await this.setMediaStreamTrack(newTrack);
281
+ this._constraints = constraints;
277
282
 
278
- this.emit(TrackEvent.Restarted, this);
279
- return this;
283
+ this.emit(TrackEvent.Restarted, this);
284
+ return this;
285
+ } finally {
286
+ unlock();
287
+ }
280
288
  }
281
289
 
282
290
  protected setTrackMuted(muted: boolean) {
@@ -459,6 +467,7 @@ export default abstract class LocalTrack<
459
467
  }
460
468
  await this.sender?.replaceTrack(this.processor.processedTrack);
461
469
  }
470
+ this.emit(TrackEvent.TrackProcessorUpdate, this.processor);
462
471
  } finally {
463
472
  unlock();
464
473
  }
@@ -484,8 +493,8 @@ export default abstract class LocalTrack<
484
493
  this.processor = undefined;
485
494
  this.processorElement?.remove();
486
495
  this.processorElement = undefined;
487
-
488
496
  await this.restart();
497
+ this.emit(TrackEvent.TrackProcessorUpdate);
489
498
  }
490
499
 
491
500
  protected abstract monitorSender(): void;
@@ -11,6 +11,7 @@ import { StreamState as ProtoStreamState } from '../../proto/livekit_rtc_pb';
11
11
  import { TrackEvent } from '../events';
12
12
  import type { LoggerOptions } from '../types';
13
13
  import { isFireFox, isSafari, isWeb } from '../utils';
14
+ import type { TrackProcessor } from './processor/types';
14
15
  import { getLogContextFromTrack } from './utils';
15
16
 
16
17
  const BACKGROUND_REACTION_DELAY = 5000;
@@ -502,4 +503,5 @@ export type TrackEventCallbacks = {
502
503
  elementDetached: (element: HTMLMediaElement) => void;
503
504
  upstreamPaused: (track: any) => void;
504
505
  upstreamResumed: (track: any) => void;
506
+ trackProcessorUpdate: (processor?: TrackProcessor<Track.Kind, any>) => void;
505
507
  };