Clean up some unused code related to calls (#29997)

* Remove the unused 'preload' option

* Remove unused layout tracking code
This commit is contained in:
Robin
2025-05-22 10:08:42 -04:00
committed by GitHub
parent f5125ac2b8
commit 87447c7f91
2 changed files with 3 additions and 117 deletions

View File

@@ -85,15 +85,9 @@ export enum ConnectionState {
export const isConnected = (state: ConnectionState): boolean => export const isConnected = (state: ConnectionState): boolean =>
state === ConnectionState.Connected || state === ConnectionState.Disconnecting; state === ConnectionState.Connected || state === ConnectionState.Disconnecting;
export enum Layout {
Tile = "tile",
Spotlight = "spotlight",
}
export enum CallEvent { export enum CallEvent {
ConnectionState = "connection_state", ConnectionState = "connection_state",
Participants = "participants", Participants = "participants",
Layout = "layout",
Close = "close", Close = "close",
Destroy = "destroy", Destroy = "destroy",
} }
@@ -104,7 +98,6 @@ interface CallEventHandlerMap {
participants: Map<RoomMember, Set<string>>, participants: Map<RoomMember, Set<string>>,
prevParticipants: Map<RoomMember, Set<string>>, prevParticipants: Map<RoomMember, Set<string>>,
) => void; ) => void;
[CallEvent.Layout]: (layout: Layout) => void;
[CallEvent.Close]: () => void; [CallEvent.Close]: () => void;
[CallEvent.Destroy]: () => void; [CallEvent.Destroy]: () => void;
} }
@@ -658,14 +651,6 @@ export class ElementCall extends Call {
private settingsStoreCallEncryptionWatcher?: string; private settingsStoreCallEncryptionWatcher?: string;
private terminationTimer?: number; private terminationTimer?: number;
private _layout = Layout.Tile;
public get layout(): Layout {
return this._layout;
}
protected set layout(value: Layout) {
this._layout = value;
this.emit(CallEvent.Layout, value);
}
public get presented(): boolean { public get presented(): boolean {
return super.presented; return super.presented;
@@ -686,7 +671,6 @@ export class ElementCall extends Call {
const params = new URLSearchParams({ const params = new URLSearchParams({
embed: "true", // We're embedding EC within another application embed: "true", // We're embedding EC within another application
// Template variables are used, so that this can be configured using the widget data. // Template variables are used, so that this can be configured using the widget data.
preload: "$preload", // We want it to load in the background.
skipLobby: "$skipLobby", // Skip the lobby in case we show a lobby component of our own. skipLobby: "$skipLobby", // Skip the lobby in case we show a lobby component of our own.
returnToLobby: "$returnToLobby", // Returns to the lobby (instead of blank screen) when the call ends. (For video rooms) returnToLobby: "$returnToLobby", // Returns to the lobby (instead of blank screen) when the call ends. (For video rooms)
perParticipantE2EE: "$perParticipantE2EE", perParticipantE2EE: "$perParticipantE2EE",
@@ -756,17 +740,13 @@ export class ElementCall extends Call {
} }
// Creates a new widget if there isn't any widget of typ Call in this room. // Creates a new widget if there isn't any widget of typ Call in this room.
// Defaults for creating a new widget are: skipLobby = false, preload = false // Defaults for creating a new widget are: skipLobby = false
// When there is already a widget the current widget configuration will be used or can be overwritten // When there is already a widget the current widget configuration will be used or can be overwritten
// by passing the according parameters (skipLobby, preload). // by passing the according parameters (skipLobby).
//
// `preload` is deprecated. We used it for optimizing EC by using a custom EW call lobby and preloading the iframe.
// now it should always be false.
private static createOrGetCallWidget( private static createOrGetCallWidget(
roomId: string, roomId: string,
client: MatrixClient, client: MatrixClient,
skipLobby: boolean | undefined, skipLobby: boolean | undefined,
preload: boolean | undefined,
returnToLobby: boolean | undefined, returnToLobby: boolean | undefined,
): IApp { ): IApp {
const ecWidget = WidgetStore.instance.getApps(roomId).find((app) => WidgetType.CALL.matches(app.type)); const ecWidget = WidgetStore.instance.getApps(roomId).find((app) => WidgetType.CALL.matches(app.type));
@@ -777,9 +757,6 @@ export class ElementCall extends Call {
if (skipLobby !== undefined) { if (skipLobby !== undefined) {
overwrites.skipLobby = skipLobby; overwrites.skipLobby = skipLobby;
} }
if (preload !== undefined) {
overwrites.preload = preload;
}
if (returnToLobby !== undefined) { if (returnToLobby !== undefined) {
overwrites.returnToLobby = returnToLobby; overwrites.returnToLobby = returnToLobby;
} }
@@ -804,7 +781,6 @@ export class ElementCall extends Call {
{}, {},
{ {
skipLobby: skipLobby ?? false, skipLobby: skipLobby ?? false,
preload: preload ?? false,
returnToLobby: returnToLobby ?? false, returnToLobby: returnToLobby ?? false,
}, },
), ),
@@ -870,7 +846,6 @@ export class ElementCall extends Call {
room.roomId, room.roomId,
room.client, room.client,
undefined, undefined,
undefined,
isVideoRoom(room), isVideoRoom(room),
); );
return new ElementCall(session, availableOrCreatedWidget, room.client); return new ElementCall(session, availableOrCreatedWidget, room.client);
@@ -880,7 +855,7 @@ export class ElementCall extends Call {
} }
public static create(room: Room, skipLobby = false): void { public static create(room: Room, skipLobby = false): void {
ElementCall.createOrGetCallWidget(room.roomId, room.client, skipLobby, false, isVideoRoom(room)); ElementCall.createOrGetCallWidget(room.roomId, room.client, skipLobby, isVideoRoom(room));
} }
protected async sendCallNotify(): Promise<void> { protected async sendCallNotify(): Promise<void> {
@@ -912,19 +887,6 @@ export class ElementCall extends Call {
audioInput: MediaDeviceInfo | null, audioInput: MediaDeviceInfo | null,
videoInput: MediaDeviceInfo | null, videoInput: MediaDeviceInfo | null,
): Promise<void> { ): Promise<void> {
// The JoinCall action is only send if the widget is waiting for it.
if (this.widget.data?.preload) {
try {
await this.messaging!.transport.send(ElementWidgetActions.JoinCall, {
audioInput: audioInput?.label ?? null,
videoInput: videoInput?.label ?? null,
});
} catch (e) {
throw new Error(`Failed to join call in room ${this.roomId}: ${e}`);
}
}
this.messaging!.on(`action:${ElementWidgetActions.TileLayout}`, this.onTileLayout);
this.messaging!.on(`action:${ElementWidgetActions.SpotlightLayout}`, this.onSpotlightLayout);
this.messaging!.on(`action:${ElementWidgetActions.HangupCall}`, this.onHangup); this.messaging!.on(`action:${ElementWidgetActions.HangupCall}`, this.onHangup);
this.messaging!.once(`action:${ElementWidgetActions.Close}`, this.onClose); this.messaging!.once(`action:${ElementWidgetActions.Close}`, this.onClose);
this.messaging!.on(`action:${ElementWidgetActions.DeviceMute}`, this.onDeviceMute); this.messaging!.on(`action:${ElementWidgetActions.DeviceMute}`, this.onDeviceMute);
@@ -968,8 +930,6 @@ export class ElementCall extends Call {
} }
public setDisconnected(): void { public setDisconnected(): void {
this.messaging!.off(`action:${ElementWidgetActions.TileLayout}`, this.onTileLayout);
this.messaging!.off(`action:${ElementWidgetActions.SpotlightLayout}`, this.onSpotlightLayout);
this.messaging!.off(`action:${ElementWidgetActions.HangupCall}`, this.onHangup); this.messaging!.off(`action:${ElementWidgetActions.HangupCall}`, this.onHangup);
this.messaging!.off(`action:${ElementWidgetActions.DeviceMute}`, this.onDeviceMute); this.messaging!.off(`action:${ElementWidgetActions.DeviceMute}`, this.onDeviceMute);
super.setDisconnected(); super.setDisconnected();
@@ -994,15 +954,6 @@ export class ElementCall extends Call {
if (this.session.memberships.length === 0 && !this.presented && !this.room.isCallRoom()) this.destroy(); if (this.session.memberships.length === 0 && !this.presented && !this.room.isCallRoom()) this.destroy();
}; };
/**
* Sets the call's layout.
* @param layout The layout to switch to.
*/
public async setLayout(layout: Layout): Promise<void> {
const action = layout === Layout.Tile ? ElementWidgetActions.TileLayout : ElementWidgetActions.SpotlightLayout;
await this.messaging!.transport.send(action, {});
}
private readonly onMembershipChanged = (): void => this.updateParticipants(); private readonly onMembershipChanged = (): void => this.updateParticipants();
private updateParticipants(): void { private updateParticipants(): void {
@@ -1046,18 +997,6 @@ export class ElementCall extends Call {
this.close(); this.close();
}; };
private readonly onTileLayout = async (ev: CustomEvent<IWidgetApiRequest>): Promise<void> => {
ev.preventDefault();
this.layout = Layout.Tile;
this.messaging!.transport.reply(ev.detail, {}); // ack
};
private readonly onSpotlightLayout = async (ev: CustomEvent<IWidgetApiRequest>): Promise<void> => {
ev.preventDefault();
this.layout = Layout.Spotlight;
this.messaging!.transport.reply(ev.detail, {}); // ack
};
public clean(): Promise<void> { public clean(): Promise<void> {
return Promise.resolve(); return Promise.resolve();
} }

View File

@@ -34,7 +34,6 @@ import type { Mocked } from "jest-mock";
import type { ClientWidgetApi } from "matrix-widget-api"; import type { ClientWidgetApi } from "matrix-widget-api";
import { import {
type JitsiCallMemberContent, type JitsiCallMemberContent,
Layout,
Call, Call,
CallEvent, CallEvent,
ConnectionState, ConnectionState,
@@ -895,13 +894,6 @@ describe("ElementCall", () => {
expect(call.connectionState).toBe(ConnectionState.Connected); expect(call.connectionState).toBe(ConnectionState.Connected);
}); });
it("fails to connect if the widget returns an error", async () => {
// we only send a JoinCall action if the widget is preloading
call.widget.data = { ...call.widget, preload: true };
mocked(messaging.transport).send.mockRejectedValue(new Error("never!!1! >:("));
await expect(call.start()).rejects.toBeDefined();
});
it("fails to disconnect if the widget returns an error", async () => { it("fails to disconnect if the widget returns an error", async () => {
await callConnectProcedure(call); await callConnectProcedure(call);
mocked(messaging.transport).send.mockRejectedValue(new Error("never!!1! >:(")); mocked(messaging.transport).send.mockRejectedValue(new Error("never!!1! >:("));
@@ -948,33 +940,6 @@ describe("ElementCall", () => {
expect(call.connectionState).toBe(ConnectionState.Disconnected); expect(call.connectionState).toBe(ConnectionState.Disconnected);
}); });
it("tracks layout", async () => {
await callConnectProcedure(call);
expect(call.layout).toBe(Layout.Tile);
messaging.emit(
`action:${ElementWidgetActions.SpotlightLayout}`,
new CustomEvent("widgetapirequest", { detail: {} }),
);
expect(call.layout).toBe(Layout.Spotlight);
messaging.emit(
`action:${ElementWidgetActions.TileLayout}`,
new CustomEvent("widgetapirequest", { detail: {} }),
);
expect(call.layout).toBe(Layout.Tile);
});
it("sets layout", async () => {
await callConnectProcedure(call);
await call.setLayout(Layout.Spotlight);
expect(messaging.transport.send).toHaveBeenCalledWith(ElementWidgetActions.SpotlightLayout, {});
await call.setLayout(Layout.Tile);
expect(messaging.transport.send).toHaveBeenCalledWith(ElementWidgetActions.TileLayout, {});
});
it("acknowledges mute_device widget action", async () => { it("acknowledges mute_device widget action", async () => {
await callConnectProcedure(call); await callConnectProcedure(call);
const preventDefault = jest.fn(); const preventDefault = jest.fn();
@@ -1014,24 +979,6 @@ describe("ElementCall", () => {
call.off(CallEvent.Participants, onParticipants); call.off(CallEvent.Participants, onParticipants);
}); });
it("emits events when layout changes", async () => {
await callConnectProcedure(call);
const onLayout = jest.fn();
call.on(CallEvent.Layout, onLayout);
messaging.emit(
`action:${ElementWidgetActions.SpotlightLayout}`,
new CustomEvent("widgetapirequest", { detail: {} }),
);
messaging.emit(
`action:${ElementWidgetActions.TileLayout}`,
new CustomEvent("widgetapirequest", { detail: {} }),
);
expect(onLayout.mock.calls).toEqual([[Layout.Spotlight], [Layout.Tile]]);
call.off(CallEvent.Layout, onLayout);
});
it("ends the call immediately if the session ended", async () => { it("ends the call immediately if the session ended", async () => {
await callConnectProcedure(call); await callConnectProcedure(call);
const onDestroy = jest.fn(); const onDestroy = jest.fn();