Skip to content

Commit ca00094

Browse files
authored
Fix bug where switching media caused media in subsequent calls to fail (#3489)
1 parent 9c6d5a6 commit ca00094

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/webrtc/mediaHandler.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,19 @@ export class MediaHandler extends TypedEventEmitter<
334334
this.emit(MediaHandlerEvent.LocalStreamsChanged);
335335

336336
if (this.localUserMediaStream === mediaStream) {
337+
// if we have this stream cahced, remove it, because we've stopped it
337338
this.localUserMediaStream = undefined;
339+
} else {
340+
// If it's not the same stream. remove any tracks from the cached stream that
341+
// we have just stopped, and if we do stop any, call the same method on the
342+
// cached stream too in order to stop all its tracks (in case they are different)
343+
// and un-cache it.
344+
for (const track of mediaStream.getTracks()) {
345+
if (this.localUserMediaStream?.getTrackById(track.id)) {
346+
this.stopUserMediaStream(this.localUserMediaStream);
347+
break;
348+
}
349+
}
338350
}
339351
}
340352

0 commit comments

Comments
 (0)