Skip to content

Commit

Permalink
Clean up simulcast codecs in unpublish (#332)
Browse files Browse the repository at this point in the history
* reset multicodec senders in unpublish

* dont stop tracks when resetting senders

* remove simulcast codec tracks when unpublishing

* set sender to undefined after removing track

* make sure negotiation happens after removing tracks

* changeset
  • Loading branch information
lukasIO authored Jul 20, 2022
1 parent cd67a57 commit b3df000
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/purple-carrots-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-client': patch
---

Clean up simulcast codecs in unpublishTrack
12 changes: 11 additions & 1 deletion src/room/participant/LocalParticipant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -723,9 +723,19 @@ export default class LocalParticipant extends Participant {
) {
try {
this.engine.publisher.pc.removeTrack(track.sender);
this.engine.negotiate();
if (track instanceof LocalVideoTrack) {
for (const [, trackInfo] of track.simulcastCodecs) {
if (trackInfo.sender) {
this.engine.publisher.pc.removeTrack(trackInfo.sender);
trackInfo.sender = undefined;
}
}
track.simulcastCodecs.clear();
}
} catch (e) {
log.warn('failed to remove track', { error: e, method: 'unpublishTrack' });
} finally {
this.engine.negotiate();
}
}

Expand Down
10 changes: 3 additions & 7 deletions src/room/track/LocalVideoTrack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,15 @@ export class SimulcastTrackInfo {
const refreshSubscribedCodecAfterNewCodec = 5000;

export default class LocalVideoTrack extends LocalTrack {
/* internal */
/* @internal */
signalClient?: SignalClient;

private prevStats?: Map<string, VideoSenderStats>;

private encodings?: RTCRtpEncodingParameters[];

private simulcastCodecs: Map<VideoCodec, SimulcastTrackInfo> = new Map<
VideoCodec,
SimulcastTrackInfo
>();
/* @internal */
simulcastCodecs: Map<VideoCodec, SimulcastTrackInfo> = new Map<VideoCodec, SimulcastTrackInfo>();

private subscribedCodecs?: SubscribedCodec[];

Expand Down Expand Up @@ -78,9 +76,7 @@ export default class LocalVideoTrack extends LocalTrack {
this._mediaStreamTrack.getConstraints();
this.simulcastCodecs.forEach((trackInfo) => {
trackInfo.mediaStreamTrack.stop();
trackInfo.sender = undefined;
});
this.simulcastCodecs.clear();
super.stop();
}

Expand Down

0 comments on commit b3df000

Please sign in to comment.