Skip to content

Commit 6c79775

Browse files
committed
feat: prevent flickering when a new stream arrives for an existing participant
1 parent f5a4bb7 commit 6c79775

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

packages/client/src/rtc/Subscriber.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,15 @@ export class Subscriber {
218218
this.logger('error', `Unknown track type: ${rawTrackType}`);
219219
return;
220220
}
221+
221222
const previousStream = participantToUpdate[streamKindProp];
223+
224+
// replace the previous stream with the new one, prevents flickering
225+
this.state.updateParticipant(participantToUpdate.sessionId, {
226+
[streamKindProp]: primaryStream,
227+
});
228+
229+
// now, dispose the previous stream
222230
if (previousStream) {
223231
this.logger(
224232
'info',
@@ -229,9 +237,6 @@ export class Subscriber {
229237
previousStream.removeTrack(t);
230238
});
231239
}
232-
this.state.updateParticipant(participantToUpdate.sessionId, {
233-
[streamKindProp]: primaryStream,
234-
});
235240
};
236241

237242
private onIceCandidate = (e: RTCPeerConnectionIceEvent) => {

0 commit comments

Comments
 (0)