Avoid creating multiple call objects for the same widget (#30839)
* Extract some setup code out of the call tests * Don't force all rooms to be rechecked for calls when starting a call * Remove misleading unused group call callbacks The GroupCallEventHandler hasn't been relevant to our Element Call group calls for some time; instead we look at the state of the MatrixRTCSessionManager and WidgetStore to determine whether a call has been started. * Avoid creating multiple call objects for the same widget * fix test --------- Co-authored-by: Will Hunt <will@half-shot.uk>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2025 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { type CallMembership, MatrixRTCSessionManagerEvents } from "matrix-js-sdk/src/matrixrtc";
|
||||
|
||||
import { ElementCall } from "../../../src/models/Call";
|
||||
import { CallStore } from "../../../src/stores/CallStore";
|
||||
import {
|
||||
setUpClientRoomAndStores,
|
||||
cleanUpClientRoomAndStores,
|
||||
setupAsyncStoreWithClient,
|
||||
enableCalls,
|
||||
} from "../../test-utils";
|
||||
|
||||
enableCalls();
|
||||
|
||||
test("CallStore constructs one call for one MatrixRTC session", () => {
|
||||
const { client, room } = setUpClientRoomAndStores();
|
||||
try {
|
||||
setupAsyncStoreWithClient(CallStore.instance, client);
|
||||
const getSpy = jest.spyOn(ElementCall, "get");
|
||||
|
||||
// Simulate another user starting a new MatrixRTC session
|
||||
const session = client.matrixRTC.getRoomSession(room);
|
||||
session.memberships.push({} as CallMembership);
|
||||
client.matrixRTC.emit(MatrixRTCSessionManagerEvents.SessionStarted, room.roomId, session);
|
||||
|
||||
expect(getSpy).toHaveBeenCalledTimes(1);
|
||||
expect(getSpy).toHaveReturnedWith(expect.any(ElementCall));
|
||||
expect(CallStore.instance.getCall(room.roomId)).not.toBe(null);
|
||||
} finally {
|
||||
cleanUpClientRoomAndStores(client, room);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user