Skip to content

Commit

Permalink
Start processing member state events only after we've set out own (#2000
Browse files Browse the repository at this point in the history
)

This avoids a race condition where the other side would first receive the to-device messages and only then the member state event which would result in the call being ignored

Signed-off-by: Šimon Brandner <[email protected]>
  • Loading branch information
SimonBrandner authored Oct 25, 2021
1 parent b4d8c0b commit fc8a867
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/webrtc/groupCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export class GroupCall extends EventEmitter {

this.addParticipant(this.room.getMember(this.client.getUserId()));

this.sendMemberStateEvent();
const sendMemberStateEventPromise = this.sendMemberStateEvent();

this.activeSpeaker = null;

Expand All @@ -262,9 +262,14 @@ export class GroupCall extends EventEmitter {

logger.log("Processing initial members");

for (const stateEvent of memberStateEvents) {
this.onMemberStateChanged(stateEvent);
}
// This avoids a race condition where the other side would first receive
// the to-device messages and only then the member state event which
// would result in the call being ignored
sendMemberStateEventPromise.then(() => {
for (const stateEvent of memberStateEvents) {
this.onMemberStateChanged(stateEvent);
}
});

this.client.on("Call.incoming", this.onIncomingCall);

Expand Down

0 comments on commit fc8a867

Please sign in to comment.