Skip to content

Commit

Permalink
feat: prevent flickering when a new stream arrives for an existing pa…
Browse files Browse the repository at this point in the history
…rticipant
  • Loading branch information
oliverlaz committed Oct 31, 2024
1 parent f5a4bb7 commit 6c79775
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/client/src/rtc/Subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,15 @@ export class Subscriber {
this.logger('error', `Unknown track type: ${rawTrackType}`);
return;
}

const previousStream = participantToUpdate[streamKindProp];

// replace the previous stream with the new one, prevents flickering
this.state.updateParticipant(participantToUpdate.sessionId, {
[streamKindProp]: primaryStream,
});

// now, dispose the previous stream
if (previousStream) {
this.logger(
'info',
Expand All @@ -229,9 +237,6 @@ export class Subscriber {
previousStream.removeTrack(t);
});
}
this.state.updateParticipant(participantToUpdate.sessionId, {
[streamKindProp]: primaryStream,
});
};

private onIceCandidate = (e: RTCPeerConnectionIceEvent) => {
Expand Down

0 comments on commit 6c79775

Please sign in to comment.