Skip to content

Commit 2782b74

Browse files
authored
Don't restart track when processor stops (#1081)
* Don't restart track when processor stops * Initialize new processor before stopping old one * Create early-readers-eat.md
1 parent 356ee10 commit 2782b74

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

.changeset/early-readers-eat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"livekit-client": patch
3+
---
4+
5+
Don't restart track when processor stops

src/room/track/LocalTrack.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,13 @@ export default abstract class LocalTrack<
448448
const unlock = await this.processorLock.lock();
449449
try {
450450
this.log.debug('setting up processor', this.logContext);
451+
const processorOptions = {
452+
kind: this.kind,
453+
track: this._mediaStreamTrack,
454+
element: this.processorElement,
455+
audioContext: this.audioContext,
456+
};
457+
await processor.init(processorOptions);
451458
if (this.processor) {
452459
await this.stopProcessor();
453460
}
@@ -466,14 +473,6 @@ export default abstract class LocalTrack<
466473
this.log.error('failed to play processor element', { ...this.logContext, error }),
467474
);
468475

469-
const processorOptions = {
470-
kind: this.kind,
471-
track: this._mediaStreamTrack,
472-
element: this.processorElement,
473-
audioContext: this.audioContext,
474-
};
475-
476-
await processor.init(processorOptions);
477476
this.processor = processor;
478477
if (this.processor.processedTrack) {
479478
for (const el of this.attachedElements) {
@@ -510,7 +509,10 @@ export default abstract class LocalTrack<
510509
this.processor = undefined;
511510
this.processorElement?.remove();
512511
this.processorElement = undefined;
513-
await this.restart();
512+
// apply original track constraints in case the processor changed them
513+
await this._mediaStreamTrack.applyConstraints(this._constraints);
514+
// force re-setting of the mediaStreamTrack on the sender
515+
await this.setMediaStreamTrack(this._mediaStreamTrack, true);
514516
this.emit(TrackEvent.TrackProcessorUpdate);
515517
}
516518

0 commit comments

Comments
 (0)