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 race in creating calls #2662

Merged
merged 3 commits into from
Sep 13, 2022
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
2 changes: 2 additions & 0 deletions spec/unit/webrtc/groupCall.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ describe('Group Call', function() {
let newCall: MatrixCall;
while (
(newCall = groupCall1.getCallByUserId(client2.userId)) === undefined ||
newCall.peerConn === undefined ||
newCall.callId == oldCall.callId
) {
await flushPromises();
Expand Down Expand Up @@ -643,6 +644,7 @@ describe('Group Call', function() {
groupCall.localCallFeed.setAudioVideoMuted = jest.fn();
const setAVMutedArray = groupCall.calls.map(call => {
call.localUsermediaFeed.setAudioVideoMuted = jest.fn();
call.localUsermediaFeed.isVideoMuted = jest.fn().mockReturnValue(true);
return call.localUsermediaFeed.setAudioVideoMuted;
});
const tracksArray = groupCall.calls.reduce((acc, call) => {
Expand Down
19 changes: 12 additions & 7 deletions src/webrtc/groupCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -856,12 +856,22 @@ export class GroupCall extends TypedEventEmitter<
},
);

if (existingCall) {
logger.debug(`Replacing call ${existingCall.callId} to ${member.userId} with ${newCall.callId}`);
this.replaceCall(existingCall, newCall, CallErrorCode.NewSession);
} else {
logger.debug(`Adding call ${newCall.callId} to ${member.userId}`);
this.addCall(newCall);
}

newCall.isPtt = this.isPtt;

const requestScreenshareFeed = opponentDevice.feeds.some(
(feed) => feed.purpose === SDPStreamMetadataPurpose.Screenshare);

logger.log(`Placing call to ${member.userId}.`);
logger.debug(
`Placing call to ${member.userId}/${opponentDevice.device_id} session ID ${opponentDevice.session_id}.`,
);

try {
await newCall.placeCallWithCallFeeds(
Expand All @@ -881,18 +891,13 @@ export class GroupCall extends TypedEventEmitter<
),
);
}
this.removeCall(newCall, CallErrorCode.SignallingFailed);
return;
}

if (this.dataChannelsEnabled) {
newCall.createDataChannel("datachannel", this.dataChannelOptions);
}

if (existingCall) {
this.replaceCall(existingCall, newCall, CallErrorCode.NewSession);
} else {
this.addCall(newCall);
}
};

public getDeviceForMember(userId: string): IGroupCallRoomMemberDevice {
Expand Down