Fix widgets not being cleaned up correctly. (#12616)

* Fix widgets not being cleaned up correctly.

Widgets could persist forever because they were still sticky when we end the messaging.
Ending the messaging emits an event to which we connect ui changes that move the widget out of the screen. It does not end up in a pip view however.

So we need to make sure the widget is not persistend anymore when we call `stopMessagingByUid` so that any dom changes that remove the AppTile happen when the widget is not persistend anymore and let it destroy.

This PR also makes the role for `MatrixRTCSessionManager` more strict. We do ONLY use it in `Call.ts` and `CallStore`  so that we dont end up in reaces where we updated the ui based on the session manager but not in sync with the call and callstore changes.

Rename activeCalls to connectedCalls. Active call can also be understood as a call where there are active participants but the user itself is not connected. Especially with the `hasActiveCallSession` field of the useRoomCall hook which is tracking active (not necassarly connected sessions)

* rest of the renaming

* fix test to adapt to reduced session manager event usage.
pull/28217/head
Timo 2024-06-17 13:00:41 +02:00 committed by GitHub
parent 28bcbd4056
commit 5c26d580d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 54 additions and 65 deletions

View File

@ -647,7 +647,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
case "logout": case "logout":
LegacyCallHandler.instance.hangupAllCalls(); LegacyCallHandler.instance.hangupAllCalls();
Promise.all([ Promise.all([
...[...CallStore.instance.activeCalls].map((call) => call.disconnect()), ...[...CallStore.instance.connectedCalls].map((call) => call.disconnect()),
cleanUpBroadcasts(this.stores), cleanUpBroadcasts(this.stores),
]).finally(() => Lifecycle.logout(this.stores.oidcClientStore)); ]).finally(() => Lifecycle.logout(this.stores.oidcClientStore));
break; break;

View File

@ -494,7 +494,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
WidgetEchoStore.on(UPDATE_EVENT, this.onWidgetEchoStoreUpdate); WidgetEchoStore.on(UPDATE_EVENT, this.onWidgetEchoStoreUpdate);
context.widgetStore.on(UPDATE_EVENT, this.onWidgetStoreUpdate); context.widgetStore.on(UPDATE_EVENT, this.onWidgetStoreUpdate);
CallStore.instance.on(CallStoreEvent.ActiveCalls, this.onActiveCalls); CallStore.instance.on(CallStoreEvent.ConnectedCalls, this.onConnectedCalls);
this.props.resizeNotifier.on("isResizing", this.onIsResizing); this.props.resizeNotifier.on("isResizing", this.onIsResizing);
@ -815,7 +815,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
} }
}; };
private onActiveCalls = (): void => { private onConnectedCalls = (): void => {
if (this.state.roomId === undefined) return; if (this.state.roomId === undefined) return;
const activeCall = CallStore.instance.getActiveCall(this.state.roomId); const activeCall = CallStore.instance.getActiveCall(this.state.roomId);
if (activeCall === null) { if (activeCall === null) {
@ -1056,7 +1056,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
); );
} }
CallStore.instance.off(CallStoreEvent.ActiveCalls, this.onActiveCalls); CallStore.instance.off(CallStoreEvent.ConnectedCalls, this.onConnectedCalls);
this.context.legacyCallHandler.off(LegacyCallHandlerEvent.CallState, this.onCallState); this.context.legacyCallHandler.off(LegacyCallHandlerEvent.CallState, this.onCallState);
// cancel any pending calls to the throttled updated // cancel any pending calls to the throttled updated

View File

@ -60,7 +60,7 @@ const JoinCallView: FC<JoinCallViewProps> = ({ room, resizing, call, skipLobby,
const disconnectAllOtherCalls: () => Promise<void> = useCallback(async () => { const disconnectAllOtherCalls: () => Promise<void> = useCallback(async () => {
// The stickyPromise has to resolve before the widget actually becomes sticky. // The stickyPromise has to resolve before the widget actually becomes sticky.
// We only let the widget become sticky after disconnecting all other active calls. // We only let the widget become sticky after disconnecting all other active calls.
const calls = [...CallStore.instance.activeCalls].filter( const calls = [...CallStore.instance.connectedCalls].filter(
(call) => SdkContextClass.instance.roomViewStore.getRoomId() !== call.roomId, (call) => SdkContextClass.instance.roomViewStore.getRoomId() !== call.roomId,
); );
await Promise.all(calls.map(async (call) => await call.disconnect())); await Promise.all(calls.map(async (call) => await call.disconnect()));

View File

@ -176,13 +176,13 @@ export const useRoomCall = (
// We only want to prompt to pin the widget if it's not element call based. // We only want to prompt to pin the widget if it's not element call based.
const isECWidget = WidgetType.CALL.matches(widget?.type ?? ""); const isECWidget = WidgetType.CALL.matches(widget?.type ?? "");
const promptPinWidget = !isECWidget && canPinWidget && !widgetPinned; const promptPinWidget = !isECWidget && canPinWidget && !widgetPinned;
const activeCalls = useEventEmitterState(CallStore.instance, CallStoreEvent.ActiveCalls, () => const connectedCalls = useEventEmitterState(CallStore.instance, CallStoreEvent.ConnectedCalls, () =>
Array.from(CallStore.instance.activeCalls), Array.from(CallStore.instance.connectedCalls),
); );
const { canInviteGuests } = useGuestAccessInformation(room); const { canInviteGuests } = useGuestAccessInformation(room);
const state = useMemo((): State => { const state = useMemo((): State => {
if (activeCalls.find((call) => call.roomId != room.roomId)) { if (connectedCalls.find((call) => call.roomId != room.roomId)) {
return State.Ongoing; return State.Ongoing;
} }
if (hasGroupCall && (hasJitsiWidget || hasManagedHybridWidget)) { if (hasGroupCall && (hasJitsiWidget || hasManagedHybridWidget)) {
@ -200,7 +200,7 @@ export const useRoomCall = (
} }
return State.NoCall; return State.NoCall;
}, [ }, [
activeCalls, connectedCalls,
canInviteGuests, canInviteGuests,
hasGroupCall, hasGroupCall,
hasJitsiWidget, hasJitsiWidget,

View File

@ -963,7 +963,7 @@ export class ElementCall extends Call {
private onRTCSessionEnded = (roomId: string, session: MatrixRTCSession): void => { private onRTCSessionEnded = (roomId: string, session: MatrixRTCSession): void => {
// Don't destroy the call on hangup for video call rooms. // Don't destroy the call on hangup for video call rooms.
if (roomId == this.roomId && !this.room.isCallRoom()) { if (roomId === this.roomId && !this.room.isCallRoom()) {
this.destroy(); this.destroy();
} }
}; };

View File

@ -70,8 +70,12 @@ export default class ActiveWidgetStore extends EventEmitter {
public destroyPersistentWidget(widgetId: string, roomId: string | null): void { public destroyPersistentWidget(widgetId: string, roomId: string | null): void {
if (!this.getWidgetPersistence(widgetId, roomId)) return; if (!this.getWidgetPersistence(widgetId, roomId)) return;
WidgetMessagingStore.instance.stopMessagingByUid(WidgetUtils.calcWidgetUid(widgetId, roomId ?? undefined)); // We first need to set the widget persistence to false
this.setWidgetPersistence(widgetId, roomId, false); this.setWidgetPersistence(widgetId, roomId, false);
// Then we can stop the messaging. Stopping the messaging emits - we might move the widget out of sight.
// If we would do this before setting the persistence to false, it would stay in the DOM (hidden) because
// its still persistent. We need to avoid this.
WidgetMessagingStore.instance.stopMessagingByUid(WidgetUtils.calcWidgetUid(widgetId, roomId ?? undefined));
} }
public setWidgetPersistence(widgetId: string, roomId: string | null, val: boolean): void { public setWidgetPersistence(widgetId: string, roomId: string | null, val: boolean): void {

View File

@ -34,7 +34,7 @@ export enum CallStoreEvent {
// Signals a change in the call associated with a given room // Signals a change in the call associated with a given room
Call = "call", Call = "call",
// Signals a change in the active calls // Signals a change in the active calls
ActiveCalls = "active_calls", ConnectedCalls = "connected_calls",
} }
export class CallStore extends AsyncStoreWithClient<{}> { export class CallStore extends AsyncStoreWithClient<{}> {
@ -66,8 +66,7 @@ export class CallStore extends AsyncStoreWithClient<{}> {
} }
this.matrixClient.on(GroupCallEventHandlerEvent.Incoming, this.onGroupCall); this.matrixClient.on(GroupCallEventHandlerEvent.Incoming, this.onGroupCall);
this.matrixClient.on(GroupCallEventHandlerEvent.Outgoing, this.onGroupCall); this.matrixClient.on(GroupCallEventHandlerEvent.Outgoing, this.onGroupCall);
this.matrixClient.matrixRTC.on(MatrixRTCSessionManagerEvents.SessionStarted, this.onRTCSession); this.matrixClient.matrixRTC.on(MatrixRTCSessionManagerEvents.SessionStarted, this.onRTCSessionStart);
this.matrixClient.matrixRTC.on(MatrixRTCSessionManagerEvents.SessionEnded, this.onRTCSession);
WidgetStore.instance.on(UPDATE_EVENT, this.onWidgets); WidgetStore.instance.on(UPDATE_EVENT, this.onWidgets);
// If the room ID of a previously connected call is still in settings at // If the room ID of a previously connected call is still in settings at
@ -95,28 +94,27 @@ export class CallStore extends AsyncStoreWithClient<{}> {
} }
this.callListeners.clear(); this.callListeners.clear();
this.calls.clear(); this.calls.clear();
this._activeCalls.clear(); this._connectedCalls.clear();
if (this.matrixClient) { if (this.matrixClient) {
this.matrixClient.off(GroupCallEventHandlerEvent.Incoming, this.onGroupCall); this.matrixClient.off(GroupCallEventHandlerEvent.Incoming, this.onGroupCall);
this.matrixClient.off(GroupCallEventHandlerEvent.Outgoing, this.onGroupCall); this.matrixClient.off(GroupCallEventHandlerEvent.Outgoing, this.onGroupCall);
this.matrixClient.off(GroupCallEventHandlerEvent.Ended, this.onGroupCall); this.matrixClient.off(GroupCallEventHandlerEvent.Ended, this.onGroupCall);
this.matrixClient.matrixRTC.off(MatrixRTCSessionManagerEvents.SessionStarted, this.onRTCSession); this.matrixClient.matrixRTC.off(MatrixRTCSessionManagerEvents.SessionStarted, this.onRTCSessionStart);
this.matrixClient.matrixRTC.off(MatrixRTCSessionManagerEvents.SessionEnded, this.onRTCSession);
} }
WidgetStore.instance.off(UPDATE_EVENT, this.onWidgets); WidgetStore.instance.off(UPDATE_EVENT, this.onWidgets);
} }
private _activeCalls: Set<Call> = new Set(); private _connectedCalls: Set<Call> = new Set();
/** /**
* The calls to which the user is currently connected. * The calls to which the user is currently connected.
*/ */
public get activeCalls(): Set<Call> { public get connectedCalls(): Set<Call> {
return this._activeCalls; return this._connectedCalls;
} }
private set activeCalls(value: Set<Call>) { private set connectedCalls(value: Set<Call>) {
this._activeCalls = value; this._connectedCalls = value;
this.emit(CallStoreEvent.ActiveCalls, value); this.emit(CallStoreEvent.ConnectedCalls, value);
// The room IDs are persisted to settings so we can detect unclean disconnects // The room IDs are persisted to settings so we can detect unclean disconnects
SettingsStore.setValue( SettingsStore.setValue(
@ -137,9 +135,9 @@ export class CallStore extends AsyncStoreWithClient<{}> {
if (call) { if (call) {
const onConnectionState = (state: ConnectionState): void => { const onConnectionState = (state: ConnectionState): void => {
if (state === ConnectionState.Connected) { if (state === ConnectionState.Connected) {
this.activeCalls = new Set([...this.activeCalls, call]); this.connectedCalls = new Set([...this.connectedCalls, call]);
} else if (state === ConnectionState.Disconnected) { } else if (state === ConnectionState.Disconnected) {
this.activeCalls = new Set([...this.activeCalls].filter((c) => c !== call)); this.connectedCalls = new Set([...this.connectedCalls].filter((c) => c !== call));
} }
}; };
const onDestroy = (): void => { const onDestroy = (): void => {
@ -181,7 +179,7 @@ export class CallStore extends AsyncStoreWithClient<{}> {
*/ */
public getActiveCall(roomId: string): Call | null { public getActiveCall(roomId: string): Call | null {
const call = this.getCall(roomId); const call = this.getCall(roomId);
return call !== null && this.activeCalls.has(call) ? call : null; return call !== null && this.connectedCalls.has(call) ? call : null;
} }
private onWidgets = (roomId: string | null): void => { private onWidgets = (roomId: string | null): void => {
@ -200,7 +198,7 @@ export class CallStore extends AsyncStoreWithClient<{}> {
}; };
private onGroupCall = (groupCall: GroupCall): void => this.updateRoom(groupCall.room); private onGroupCall = (groupCall: GroupCall): void => this.updateRoom(groupCall.room);
private onRTCSession = (roomId: string, session: MatrixRTCSession): void => { private onRTCSessionStart = (roomId: string, session: MatrixRTCSession): void => {
this.updateRoom(session.room); this.updateRoom(session.room);
}; };
} }

View File

@ -85,11 +85,11 @@ export class Algorithm extends EventEmitter {
public updatesInhibited = false; public updatesInhibited = false;
public start(): void { public start(): void {
CallStore.instance.on(CallStoreEvent.ActiveCalls, this.onActiveCalls); CallStore.instance.on(CallStoreEvent.ConnectedCalls, this.onConnectedCalls);
} }
public stop(): void { public stop(): void {
CallStore.instance.off(CallStoreEvent.ActiveCalls, this.onActiveCalls); CallStore.instance.off(CallStoreEvent.ConnectedCalls, this.onConnectedCalls);
} }
public get stickyRoom(): Room | null { public get stickyRoom(): Room | null {
@ -302,7 +302,7 @@ export class Algorithm extends EventEmitter {
return this._stickyRoom; return this._stickyRoom;
} }
private onActiveCalls = (): void => { private onConnectedCalls = (): void => {
// In case we're unsticking a room, sort it back into natural order // In case we're unsticking a room, sort it back into natural order
this.recalculateStickyRoom(); this.recalculateStickyRoom();
@ -396,12 +396,12 @@ export class Algorithm extends EventEmitter {
return; return;
} }
if (CallStore.instance.activeCalls.size) { if (CallStore.instance.connectedCalls.size) {
// We operate on the sticky rooms map // We operate on the sticky rooms map
if (!this._cachedStickyRooms) this.initCachedStickyRooms(); if (!this._cachedStickyRooms) this.initCachedStickyRooms();
const rooms = this._cachedStickyRooms![updatedTag]; const rooms = this._cachedStickyRooms![updatedTag];
const activeRoomIds = new Set([...CallStore.instance.activeCalls].map((call) => call.roomId)); const activeRoomIds = new Set([...CallStore.instance.connectedCalls].map((call) => call.roomId));
const activeRooms: Room[] = []; const activeRooms: Room[] = [];
const inactiveRooms: Room[] = []; const inactiveRooms: Room[] = [];

View File

@ -345,7 +345,6 @@ export class StopGapWidget extends EventEmitter {
async (ev: CustomEvent<IStickyActionRequest>) => { async (ev: CustomEvent<IStickyActionRequest>) => {
if (this.messaging?.hasCapability(MatrixCapabilities.AlwaysOnScreen)) { if (this.messaging?.hasCapability(MatrixCapabilities.AlwaysOnScreen)) {
ev.preventDefault(); ev.preventDefault();
this.messaging.transport.reply(ev.detail, <IWidgetApiRequestEmptyData>{}); // ack
if (ev.detail.data.value) { if (ev.detail.data.value) {
// If the widget wants to become sticky we wait for the stickyPromise to resolve // If the widget wants to become sticky we wait for the stickyPromise to resolve
if (this.stickyPromise) await this.stickyPromise(); if (this.stickyPromise) await this.stickyPromise();
@ -356,6 +355,8 @@ export class StopGapWidget extends EventEmitter {
this.roomId ?? null, this.roomId ?? null,
ev.detail.data.value, ev.detail.data.value,
); );
// Send the ack after the widget actually has become sticky.
this.messaging.transport.reply(ev.detail, <IWidgetApiRequestEmptyData>{});
} }
}, },
); );

View File

@ -16,10 +16,6 @@ limitations under the License.
import React, { useCallback, useEffect, useMemo, useState } from "react"; import React, { useCallback, useEffect, useMemo, useState } from "react";
import { MatrixEvent } from "matrix-js-sdk/src/matrix"; import { MatrixEvent } from "matrix-js-sdk/src/matrix";
// eslint-disable-next-line no-restricted-imports
import { MatrixRTCSessionManagerEvents } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSessionManager";
// eslint-disable-next-line no-restricted-imports
import { MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSession";
import { Button, Tooltip } from "@vector-im/compound-web"; import { Button, Tooltip } from "@vector-im/compound-web";
import { Icon as VideoCallIcon } from "@vector-im/compound-design-tokens/icons/video-call-solid.svg"; import { Icon as VideoCallIcon } from "@vector-im/compound-design-tokens/icons/video-call-solid.svg";
@ -41,7 +37,7 @@ import { useDispatcher } from "../hooks/useDispatcher";
import { ActionPayload } from "../dispatcher/payloads"; import { ActionPayload } from "../dispatcher/payloads";
import { Call } from "../models/Call"; import { Call } from "../models/Call";
import { AudioID } from "../LegacyCallHandler"; import { AudioID } from "../LegacyCallHandler";
import { useEventEmitter, useTypedEventEmitter } from "../hooks/useEventEmitter"; import { useEventEmitter } from "../hooks/useEventEmitter";
import { CallStore, CallStoreEvent } from "../stores/CallStore"; import { CallStore, CallStoreEvent } from "../stores/CallStore";
export const getIncomingCallToastKey = (callId: string, roomId: string): string => `call_${callId}_${roomId}`; export const getIncomingCallToastKey = (callId: string, roomId: string): string => `call_${callId}_${roomId}`;
@ -83,11 +79,11 @@ export function IncomingCallToast({ notifyEvent }: Props): JSX.Element {
const room = MatrixClientPeg.safeGet().getRoom(roomId) ?? undefined; const room = MatrixClientPeg.safeGet().getRoom(roomId) ?? undefined;
const call = useCall(roomId); const call = useCall(roomId);
const audio = useMemo(() => document.getElementById(AudioID.Ring) as HTMLMediaElement, []); const audio = useMemo(() => document.getElementById(AudioID.Ring) as HTMLMediaElement, []);
const [activeCalls, setActiveCalls] = useState<Call[]>(Array.from(CallStore.instance.activeCalls)); const [connectedCalls, setConnectedCalls] = useState<Call[]>(Array.from(CallStore.instance.connectedCalls));
useEventEmitter(CallStore.instance, CallStoreEvent.ActiveCalls, () => { useEventEmitter(CallStore.instance, CallStoreEvent.ConnectedCalls, () => {
setActiveCalls(Array.from(CallStore.instance.activeCalls)); setConnectedCalls(Array.from(CallStore.instance.connectedCalls));
}); });
const otherCallIsOngoing = activeCalls.find((call) => call.roomId !== roomId); const otherCallIsOngoing = connectedCalls.find((call) => call.roomId !== roomId);
// Start ringing if not already. // Start ringing if not already.
useEffect(() => { useEffect(() => {
const isRingToast = (notifyEvent.getContent() as unknown as { notify_type: string })["notify_type"] == "ring"; const isRingToast = (notifyEvent.getContent() as unknown as { notify_type: string })["notify_type"] == "ring";
@ -105,13 +101,15 @@ export function IncomingCallToast({ notifyEvent }: Props): JSX.Element {
}, [audio, notifyEvent, roomId]); }, [audio, notifyEvent, roomId]);
// Dismiss if session got ended remotely. // Dismiss if session got ended remotely.
const onSessionEnded = useCallback( const onCall = useCallback(
(endedSessionRoomId: string, session: MatrixRTCSession): void => { (call: Call, callRoomId: string): void => {
if (roomId == endedSessionRoomId && session.callId == notifyEvent.getContent().call_id) { const roomId = notifyEvent.getRoomId();
if (!roomId && roomId !== callRoomId) return;
if (call === null || call.participants.size === 0) {
dismissToast(); dismissToast();
} }
}, },
[dismissToast, notifyEvent, roomId], [dismissToast, notifyEvent],
); );
// Dismiss on timeout. // Dismiss on timeout.
@ -160,11 +158,7 @@ export function IncomingCallToast({ notifyEvent }: Props): JSX.Element {
[dismissToast], [dismissToast],
); );
useTypedEventEmitter( useEventEmitter(CallStore.instance, CallStoreEvent.Call, onCall);
MatrixClientPeg.safeGet().matrixRTC,
MatrixRTCSessionManagerEvents.SessionEnded,
onSessionEnded,
);
return ( return (
<> <>

View File

@ -769,7 +769,7 @@ describe("<MatrixChat />", () => {
jest.spyOn(PosthogAnalytics.instance, "logout").mockImplementation(() => {}); jest.spyOn(PosthogAnalytics.instance, "logout").mockImplementation(() => {});
jest.spyOn(EventIndexPeg, "deleteEventIndex").mockImplementation(async () => {}); jest.spyOn(EventIndexPeg, "deleteEventIndex").mockImplementation(async () => {});
jest.spyOn(CallStore.instance, "activeCalls", "get").mockReturnValue(new Set([call1, call2])); jest.spyOn(CallStore.instance, "connectedCalls", "get").mockReturnValue(new Set([call1, call2]));
mockPlatformPeg({ mockPlatformPeg({
destroyPickleKey: jest.fn(), destroyPickleKey: jest.fn(),

View File

@ -492,7 +492,7 @@ describe("RoomHeader", () => {
it("buttons are disabled if there is an ongoing call", async () => { it("buttons are disabled if there is an ongoing call", async () => {
mockRoomMembers(room, 3); mockRoomMembers(room, 3);
jest.spyOn(CallStore.prototype, "activeCalls", "get").mockReturnValue( jest.spyOn(CallStore.prototype, "connectedCalls", "get").mockReturnValue(
new Set([{ roomId: "some_other_room" } as Call]), new Set([{ roomId: "some_other_room" } as Call]),
); );
const { container } = render(<RoomHeader room={room} />, getWrapper()); const { container } = render(<RoomHeader room={room} />, getWrapper());
@ -514,7 +514,7 @@ describe("RoomHeader", () => {
it("join button is disabled if there is an other ongoing call", async () => { it("join button is disabled if there is an other ongoing call", async () => {
mockRoomMembers(room, 3); mockRoomMembers(room, 3);
jest.spyOn(UseCall, "useParticipantCount").mockReturnValue(3); jest.spyOn(UseCall, "useParticipantCount").mockReturnValue(3);
jest.spyOn(CallStore.prototype, "activeCalls", "get").mockReturnValue( jest.spyOn(CallStore.prototype, "connectedCalls", "get").mockReturnValue(
new Set([{ roomId: "some_other_room" } as Call]), new Set([{ roomId: "some_other_room" } as Call]),
); );
const { container } = render(<RoomHeader room={room} />, getWrapper()); const { container } = render(<RoomHeader room={room} />, getWrapper());

View File

@ -20,10 +20,6 @@ import { mocked, Mocked } from "jest-mock";
import { Room, RoomStateEvent, MatrixEvent, MatrixEventEvent, MatrixClient } from "matrix-js-sdk/src/matrix"; import { Room, RoomStateEvent, MatrixEvent, MatrixEventEvent, MatrixClient } from "matrix-js-sdk/src/matrix";
import { ClientWidgetApi, Widget } from "matrix-widget-api"; import { ClientWidgetApi, Widget } from "matrix-widget-api";
// eslint-disable-next-line no-restricted-imports // eslint-disable-next-line no-restricted-imports
import { MatrixRTCSessionManagerEvents } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSessionManager";
// eslint-disable-next-line no-restricted-imports
import { MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSession";
// eslint-disable-next-line no-restricted-imports
import { ICallNotifyContent } from "matrix-js-sdk/src/matrixrtc/types"; import { ICallNotifyContent } from "matrix-js-sdk/src/matrixrtc/types";
import type { RoomMember } from "matrix-js-sdk/src/matrix"; import type { RoomMember } from "matrix-js-sdk/src/matrix";
@ -82,6 +78,7 @@ describe("IncomingCallEvent", () => {
client.getRoom.mockImplementation((roomId) => (roomId === room.roomId ? room : null)); client.getRoom.mockImplementation((roomId) => (roomId === room.roomId ? room : null));
client.getRooms.mockReturnValue([room]); client.getRooms.mockReturnValue([room]);
client.reEmitter.reEmit(room, [RoomStateEvent.Events]); client.reEmitter.reEmit(room, [RoomStateEvent.Events]);
MockedCall.create(room, "1");
await Promise.all( await Promise.all(
[CallStore.instance, WidgetMessagingStore.instance].map((store) => [CallStore.instance, WidgetMessagingStore.instance].map((store) =>
@ -89,7 +86,6 @@ describe("IncomingCallEvent", () => {
), ),
); );
MockedCall.create(room, "1");
const maybeCall = CallStore.instance.getCall(room.roomId); const maybeCall = CallStore.instance.getCall(room.roomId);
if (!(maybeCall instanceof MockedCall)) throw new Error("Failed to create call"); if (!(maybeCall instanceof MockedCall)) throw new Error("Failed to create call");
call = maybeCall; call = maybeCall;
@ -179,7 +175,7 @@ describe("IncomingCallEvent", () => {
defaultDispatcher.unregister(dispatcherRef); defaultDispatcher.unregister(dispatcherRef);
}); });
it("skips lobby when using shift key click", async () => { it("Dismiss toast if user starts call and skips lobby when using shift key click", async () => {
renderToast(); renderToast();
const dispatcherSpy = jest.fn(); const dispatcherSpy = jest.fn();
@ -250,11 +246,7 @@ describe("IncomingCallEvent", () => {
it("closes toast when the matrixRTC session has ended", async () => { it("closes toast when the matrixRTC session has ended", async () => {
renderToast(); renderToast();
call.destroy();
client.matrixRTC.emit(MatrixRTCSessionManagerEvents.SessionEnded, room.roomId, {
callId: notifyContent.call_id,
room: room,
} as unknown as MatrixRTCSession);
await waitFor(() => await waitFor(() =>
expect(toastStore.dismissToast).toHaveBeenCalledWith( expect(toastStore.dismissToast).toHaveBeenCalledWith(