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.
- 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 +52 -17
- package/dist/livekit-client.e2ee.worker.mjs.map +1 -1
- package/dist/livekit-client.esm.mjs +69 -40
- 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/KeyProvider.d.ts +1 -1
- package/dist/src/e2ee/KeyProvider.d.ts.map +1 -1
- package/dist/src/e2ee/worker/FrameCryptor.d.ts +1 -0
- package/dist/src/e2ee/worker/FrameCryptor.d.ts.map +1 -1
- package/dist/src/e2ee/worker/ParticipantKeyHandler.d.ts +2 -2
- package/dist/src/e2ee/worker/ParticipantKeyHandler.d.ts.map +1 -1
- package/dist/src/room/Room.d.ts +1 -0
- package/dist/src/room/Room.d.ts.map +1 -1
- package/dist/src/room/events.d.ts +5 -1
- package/dist/src/room/events.d.ts.map +1 -1
- package/dist/src/room/track/LocalAudioTrack.d.ts.map +1 -1
- package/dist/src/room/track/LocalTrack.d.ts +1 -0
- package/dist/src/room/track/LocalTrack.d.ts.map +1 -1
- package/dist/src/room/track/Track.d.ts +2 -0
- package/dist/src/room/track/Track.d.ts.map +1 -1
- package/dist/ts4.2/src/e2ee/KeyProvider.d.ts +1 -1
- package/dist/ts4.2/src/e2ee/worker/FrameCryptor.d.ts +1 -0
- package/dist/ts4.2/src/e2ee/worker/ParticipantKeyHandler.d.ts +2 -2
- package/dist/ts4.2/src/room/Room.d.ts +1 -0
- package/dist/ts4.2/src/room/events.d.ts +5 -1
- package/dist/ts4.2/src/room/track/LocalTrack.d.ts +1 -0
- package/dist/ts4.2/src/room/track/Track.d.ts +2 -0
- package/package.json +1 -1
- package/src/e2ee/KeyProvider.ts +6 -1
- package/src/e2ee/worker/FrameCryptor.ts +26 -0
- package/src/e2ee/worker/ParticipantKeyHandler.ts +9 -5
- package/src/e2ee/worker/e2ee.worker.ts +16 -17
- package/src/room/Room.ts +18 -4
- package/src/room/events.ts +4 -0
- package/src/room/track/LocalAudioTrack.ts +1 -0
- package/src/room/track/LocalTrack.ts +42 -33
- 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
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
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
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
252
|
+
const streamConstraints: MediaStreamConstraints = {
|
253
|
+
audio: false,
|
254
|
+
video: false,
|
255
|
+
};
|
251
256
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
+
if (this.kind === Track.Kind.Video) {
|
258
|
+
streamConstraints.video = constraints;
|
259
|
+
} else {
|
260
|
+
streamConstraints.audio = constraints;
|
261
|
+
}
|
257
262
|
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
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
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
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
|
-
|
276
|
-
|
280
|
+
await this.setMediaStreamTrack(newTrack);
|
281
|
+
this._constraints = constraints;
|
277
282
|
|
278
|
-
|
279
|
-
|
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;
|
package/src/room/track/Track.ts
CHANGED
@@ -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
|
};
|