You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-06 12:02:40 +03:00
Fix race in creating calls (#2662)
* Fix race in creating calls We ran an async function between checking for an existing call and adding the new one to the map, so it would have been possible to start creating another call while we were placing the first call. This changes the code to add the call to the map as soon as we've created it. Also adds more logging. * Switch to logger.debug * Fix unit tests
This commit is contained in:
@@ -533,6 +533,7 @@ describe('Group Call', function() {
|
|||||||
let newCall: MatrixCall;
|
let newCall: MatrixCall;
|
||||||
while (
|
while (
|
||||||
(newCall = groupCall1.getCallByUserId(client2.userId)) === undefined ||
|
(newCall = groupCall1.getCallByUserId(client2.userId)) === undefined ||
|
||||||
|
newCall.peerConn === undefined ||
|
||||||
newCall.callId == oldCall.callId
|
newCall.callId == oldCall.callId
|
||||||
) {
|
) {
|
||||||
await flushPromises();
|
await flushPromises();
|
||||||
@@ -643,6 +644,7 @@ describe('Group Call', function() {
|
|||||||
groupCall.localCallFeed.setAudioVideoMuted = jest.fn();
|
groupCall.localCallFeed.setAudioVideoMuted = jest.fn();
|
||||||
const setAVMutedArray = groupCall.calls.map(call => {
|
const setAVMutedArray = groupCall.calls.map(call => {
|
||||||
call.localUsermediaFeed.setAudioVideoMuted = jest.fn();
|
call.localUsermediaFeed.setAudioVideoMuted = jest.fn();
|
||||||
|
call.localUsermediaFeed.isVideoMuted = jest.fn().mockReturnValue(true);
|
||||||
return call.localUsermediaFeed.setAudioVideoMuted;
|
return call.localUsermediaFeed.setAudioVideoMuted;
|
||||||
});
|
});
|
||||||
const tracksArray = groupCall.calls.reduce((acc, call) => {
|
const tracksArray = groupCall.calls.reduce((acc, call) => {
|
||||||
|
@@ -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;
|
newCall.isPtt = this.isPtt;
|
||||||
|
|
||||||
const requestScreenshareFeed = opponentDevice.feeds.some(
|
const requestScreenshareFeed = opponentDevice.feeds.some(
|
||||||
(feed) => feed.purpose === SDPStreamMetadataPurpose.Screenshare);
|
(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 {
|
try {
|
||||||
await newCall.placeCallWithCallFeeds(
|
await newCall.placeCallWithCallFeeds(
|
||||||
@@ -881,18 +891,13 @@ export class GroupCall extends TypedEventEmitter<
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
this.removeCall(newCall, CallErrorCode.SignallingFailed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.dataChannelsEnabled) {
|
if (this.dataChannelsEnabled) {
|
||||||
newCall.createDataChannel("datachannel", this.dataChannelOptions);
|
newCall.createDataChannel("datachannel", this.dataChannelOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (existingCall) {
|
|
||||||
this.replaceCall(existingCall, newCall, CallErrorCode.NewSession);
|
|
||||||
} else {
|
|
||||||
this.addCall(newCall);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public getDeviceForMember(userId: string): IGroupCallRoomMemberDevice {
|
public getDeviceForMember(userId: string): IGroupCallRoomMemberDevice {
|
||||||
|
Reference in New Issue
Block a user