Skip to content

Commit

Permalink
Make sure that ParticipantConnected fires before related TrackEvents (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasIO committed Jul 29, 2022
1 parent 050bd43 commit d040aff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-pumas-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-client': patch
---

Make sure that ParticipantConnected fires before related TrackEvents
8 changes: 4 additions & 4 deletions src/room/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -726,10 +726,7 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
// when it's disconnected, send updates
if (info.state === ParticipantInfo_State.DISCONNECTED) {
this.handleParticipantDisconnected(info.sid, remoteParticipant);
} else if (isNewParticipant) {
// fire connected event
this.emitWhenConnected(RoomEvent.ParticipantConnected, remoteParticipant);
} else {
} else if (!isNewParticipant) {
// just update, no events
remoteParticipant.updateInfo(info);
}
Expand Down Expand Up @@ -929,6 +926,9 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
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);
}

// also forward events
Expand Down

0 comments on commit d040aff

Please sign in to comment.