You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-07-30 04:23:07 +03:00
Resolve races between initLocalCallFeed and leave
Unfortunately there are still other methods that could race with leave and result in broken group call state, such as enter and terminate. For the future, should consider writing a more careful specification of how the whole group call state machine is meant to work.
This commit is contained in:
@ -23,7 +23,7 @@ import {
|
|||||||
Room,
|
Room,
|
||||||
RoomMember,
|
RoomMember,
|
||||||
} from '../../../src';
|
} from '../../../src';
|
||||||
import { GroupCall, GroupCallEvent } from "../../../src/webrtc/groupCall";
|
import { GroupCall, GroupCallEvent, GroupCallState } from "../../../src/webrtc/groupCall";
|
||||||
import { MatrixClient } from "../../../src/client";
|
import { MatrixClient } from "../../../src/client";
|
||||||
import {
|
import {
|
||||||
installWebRTCMocks,
|
installWebRTCMocks,
|
||||||
@ -174,6 +174,13 @@ describe('Group Call', function() {
|
|||||||
groupCall.leave();
|
groupCall.leave();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("stops initializing local call feed when leaving", async () => {
|
||||||
|
const initPromise = groupCall.initLocalCallFeed();
|
||||||
|
groupCall.leave();
|
||||||
|
await expect(initPromise).rejects.toBeDefined();
|
||||||
|
expect(groupCall.state).toBe(GroupCallState.LocalCallFeedUninitialized);
|
||||||
|
});
|
||||||
|
|
||||||
it("sends state event to room when creating", async () => {
|
it("sends state event to room when creating", async () => {
|
||||||
await groupCall.create();
|
await groupCall.create();
|
||||||
|
|
||||||
|
@ -257,13 +257,26 @@ export class GroupCall extends TypedEventEmitter<
|
|||||||
|
|
||||||
let stream: MediaStream;
|
let stream: MediaStream;
|
||||||
|
|
||||||
|
let disposed = false;
|
||||||
|
const onState = (state: GroupCallState) => {
|
||||||
|
if (state === GroupCallState.LocalCallFeedUninitialized) {
|
||||||
|
disposed = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.on(GroupCallEvent.GroupCallStateChanged, onState);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
stream = await this.client.getMediaHandler().getUserMediaStream(true, this.type === GroupCallType.Video);
|
stream = await this.client.getMediaHandler().getUserMediaStream(true, this.type === GroupCallType.Video);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.setState(GroupCallState.LocalCallFeedUninitialized);
|
this.setState(GroupCallState.LocalCallFeedUninitialized);
|
||||||
throw error;
|
throw error;
|
||||||
|
} finally {
|
||||||
|
this.off(GroupCallEvent.GroupCallStateChanged, onState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The call could've been disposed while we were waiting
|
||||||
|
if (disposed) throw new Error("Group call disposed");
|
||||||
|
|
||||||
const userId = this.client.getUserId()!;
|
const userId = this.client.getUserId()!;
|
||||||
|
|
||||||
const callFeed = new CallFeed({
|
const callFeed = new CallFeed({
|
||||||
|
Reference in New Issue
Block a user