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

Fix lack of media when a user reconnects #3318

Merged
merged 2 commits into from
Apr 26, 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
4 changes: 4 additions & 0 deletions spec/unit/webrtc/groupCall.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ describe("Group Call", function () {
call = new MockMatrixCall(room.roomId, groupCall.groupCallId);

await groupCall.create();

const deviceCallMap = new Map<string, MatrixCall>();
deviceCallMap.set(FAKE_DEVICE_ID_1, call.typed());
(groupCall as any).calls.set(FAKE_USER_ID_1, deviceCallMap);
});

it("ignores changes, if we can't get user id of opponent", async () => {
Expand Down
15 changes: 13 additions & 2 deletions src/webrtc/groupCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,11 @@ export class GroupCall extends TypedEventEmitter<
);

if (prevCall) prevCall.hangup(CallErrorCode.Replaced, false);
// We must do this before we start initialising / answering the call as we
// need to know it is the active call for this user+deviceId and to not ignore
// events from it.
deviceMap.set(newCall.getOpponentDeviceId()!, newCall);
this.calls.set(opponentUserId, deviceMap);

this.initCall(newCall);

Expand All @@ -895,8 +900,6 @@ export class GroupCall extends TypedEventEmitter<
}
newCall.answerWithCallFeeds(feeds);

deviceMap.set(newCall.getOpponentDeviceId()!, newCall);
this.calls.set(opponentUserId, deviceMap);
this.emit(GroupCallEvent.CallsChanged, this.calls);
};

Expand Down Expand Up @@ -1138,6 +1141,14 @@ export class GroupCall extends TypedEventEmitter<
const remoteUsermediaFeed = call.remoteUsermediaFeed;
const remoteFeedChanged = remoteUsermediaFeed !== currentUserMediaFeed;

const deviceMap = this.calls.get(opponentMemberId);
const currentCallForUserDevice = deviceMap?.get(opponentDeviceId);
if (currentCallForUserDevice?.callId !== call.callId) {
// the call in question is not the current call for this user/deviceId
// so ignore feed events from it otherwise we'll remove our real feeds
return;
}

if (remoteFeedChanged) {
if (!currentUserMediaFeed && remoteUsermediaFeed) {
this.addUserMediaFeed(remoteUsermediaFeed);
Expand Down