Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Fix bug where one party's media would sometimes not be shown #6731

Merged
merged 5 commits into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
50 changes: 33 additions & 17 deletions src/CallHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,8 @@ export default class CallHandler extends EventEmitter {
this.pause(AudioID.Ringback);
}

this.calls.set(mappedRoomId, newCall);
this.emit(CallHandlerEvent.CallsChanged, this.calls);
this.removeCallForRoom(mappedRoomId);
this.addCallForRoom(mappedRoomId, newCall);
this.setCallListeners(newCall);
this.setCallState(newCall, newCall.state);
});
Expand Down Expand Up @@ -521,8 +521,7 @@ export default class CallHandler extends EventEmitter {
this.removeCallForRoom(mappedRoomId);
mappedRoomId = newMappedRoomId;
console.log("Moving call to room " + mappedRoomId);
this.calls.set(mappedRoomId, call);
this.emit(CallHandlerEvent.CallChangeRoom, call);
this.addCallForRoom(mappedRoomId, call, true);
}
}
});
Expand Down Expand Up @@ -756,9 +755,15 @@ export default class CallHandler extends EventEmitter {
console.log("Current turn creds expire in " + timeUntilTurnCresExpire + " ms");
const call = MatrixClientPeg.get().createCall(mappedRoomId);

console.log("Adding call for room ", roomId);
this.calls.set(roomId, call);
this.emit(CallHandlerEvent.CallsChanged, this.calls);
try {
this.addCallForRoom(roomId, call);
} catch (e) {
Modal.createTrackedDialog('Call Handler', 'Existing Call with user', ErrorDialog, {
title: _t('Already in call'),
description: _t("You're already in a call with this person."),
});
return;
}
if (transferee) {
this.transferees[call.callId] = transferee;
}
Expand Down Expand Up @@ -810,13 +815,8 @@ export default class CallHandler extends EventEmitter {
return;
}

if (this.getCallForRoom(room.roomId)) {
Modal.createTrackedDialog('Call Handler', 'Existing Call with user', ErrorDialog, {
title: _t('Already in call'),
description: _t("You're already in a call with this person."),
});
return;
}
// We leave the check for whether there's already a call in this room until later,
// otherwise it can race.

const members = room.getJoinedMembers();
if (members.length <= 1) {
Expand Down Expand Up @@ -870,9 +870,8 @@ export default class CallHandler extends EventEmitter {
}

Analytics.trackEvent('voip', 'receiveCall', 'type', call.type);
console.log("Adding call for room ", mappedRoomId);
this.calls.set(mappedRoomId, call);
this.emit(CallHandlerEvent.CallsChanged, this.calls);

this.addCallForRoom(mappedRoomId, call);
this.setCallListeners(call);
// Explicitly handle first state change
this.onCallStateChanged(call.state, null, call);
Expand Down Expand Up @@ -1150,4 +1149,21 @@ export default class CallHandler extends EventEmitter {
messaging.transport.send(ElementWidgetActions.HangupCall, {});
});
}

private addCallForRoom(roomId: string, call: MatrixCall, changedRooms=false): void {
dbkr marked this conversation as resolved.
Show resolved Hide resolved
if (this.calls.has(roomId)) {
console.log(`Couldn't add call to room ${roomId}: already have a call for this room`);
throw new Error("Already have a call for room " + roomId);
}

console.log("setting call for room " + roomId);
this.calls.set(roomId, call);

// Should we always emit CallsChanged too?
if (changedRooms) {
this.emit(CallHandlerEvent.CallChangeRoom, call);
} else {
this.emit(CallHandlerEvent.CallsChanged, this.calls);
}
}
}
4 changes: 2 additions & 2 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@
"A microphone and webcam are plugged in and set up correctly": "A microphone and webcam are plugged in and set up correctly",
"Permission is granted to use the webcam": "Permission is granted to use the webcam",
"No other application is using the webcam": "No other application is using the webcam",
"Already in call": "Already in call",
"You're already in a call with this person.": "You're already in a call with this person.",
"VoIP is unsupported": "VoIP is unsupported",
"You cannot place VoIP calls in this browser.": "You cannot place VoIP calls in this browser.",
"Too Many Calls": "Too Many Calls",
"You've reached the maximum number of simultaneous calls.": "You've reached the maximum number of simultaneous calls.",
"Already in call": "Already in call",
"You're already in a call with this person.": "You're already in a call with this person.",
"You cannot place a call with yourself.": "You cannot place a call with yourself.",
"Unable to look up phone number": "Unable to look up phone number",
"There was an error looking up the phone number": "There was an error looking up the phone number",
Expand Down