Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove legacy code paths for tracks arriving before participant info #854

Merged
merged 4 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eight-ravens-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-client": patch
---

Remove legacy code paths for tracks arriving before participant info
25 changes: 15 additions & 10 deletions src/room/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,15 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
log.warn('tried to create RemoteParticipant for local participant');
return;
}
const participant = this.getOrCreateParticipant(participantId);

const participant = this.participants.get(participantId) as RemoteParticipant | undefined;

if (!participant) {
log.error(
`Tried to add a track for a participant, that's not present. Sid: ${participantId}`,
);
return;
}

let adaptiveStreamSettings: AdaptiveStreamSettings | undefined;
if (this.options.adaptiveStream) {
Expand Down Expand Up @@ -1445,20 +1453,17 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
return participant;
}

private getOrCreateParticipant(id: string, info?: ParticipantInfo): RemoteParticipant {
private getOrCreateParticipant(id: string, info: ParticipantInfo): RemoteParticipant {
if (this.participants.has(id)) {
return this.participants.get(id) as RemoteParticipant;
}
// it's possible for the RTC track to arrive before signaling data
// when this happens, we'll create the participant and make the track work
const participant = this.createParticipant(id, info);
this.participants.set(id, participant);
if (info) {
this.identityToSid.set(info.identity, info.sid);
// if we have valid info and the participant wasn't in the map before, we can assume the participant is new
// firing here to make sure that `ParticipantConnected` fires before the initial track events
this.emitWhenConnected(RoomEvent.ParticipantConnected, participant);
}

this.identityToSid.set(info.identity, info.sid);
// if we have valid info and the participant wasn't in the map before, we can assume the participant is new
// firing here to make sure that `ParticipantConnected` fires before the initial track events
this.emitWhenConnected(RoomEvent.ParticipantConnected, participant);

// also forward events
// trackPublished is only fired for tracks added after both local participant
Expand Down