2023-08-31 14:27:15 +01:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2023-08-31 14:27:15 +01:00
|
|
|
Copyright 2023 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-09 14:57:16 +01:00
|
|
|
Please see LICENSE files in the repository root for full details.
|
2023-08-31 14:27:15 +01:00
|
|
|
*/
|
|
|
|
|
|
2025-02-05 13:25:06 +00:00
|
|
|
import { type CallType } from "matrix-js-sdk/src/webrtc/call";
|
|
|
|
|
import { type Room } from "matrix-js-sdk/src/matrix";
|
2023-08-31 14:27:15 +01:00
|
|
|
|
2026-07-14 13:58:34 +01:00
|
|
|
import type LegacyCallHandler from "../../LegacyCallHandler";
|
2024-11-04 09:49:41 +00:00
|
|
|
import { getPlatformCallTypeProps, PlatformCallType } from "../../hooks/room/useRoomCall";
|
2023-08-31 14:27:15 +01:00
|
|
|
import defaultDispatcher from "../../dispatcher/dispatcher";
|
2025-02-05 13:25:06 +00:00
|
|
|
import { type ViewRoomPayload } from "../../dispatcher/payloads/ViewRoomPayload";
|
2023-08-31 14:27:15 +01:00
|
|
|
import { Action } from "../../dispatcher/actions";
|
2024-11-04 09:49:41 +00:00
|
|
|
import PosthogTrackers from "../../PosthogTrackers";
|
2023-08-31 14:27:15 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Helper to place a call in a room that works with all the legacy modes
|
|
|
|
|
* @param room the room to place the call in
|
|
|
|
|
* @param callType the type of call
|
|
|
|
|
* @param platformCallType the platform to pass the call on
|
2025-09-25 13:46:37 +01:00
|
|
|
* @param skipLobby Has the user indicated they would like to skip the lobby. Otherwise, defer to platform defaults.
|
2023-08-31 14:27:15 +01:00
|
|
|
*/
|
2024-01-29 17:06:12 +01:00
|
|
|
export const placeCall = async (
|
2026-07-14 13:58:34 +01:00
|
|
|
legacyCallHandler: LegacyCallHandler,
|
2024-01-29 17:06:12 +01:00
|
|
|
room: Room,
|
|
|
|
|
callType: CallType,
|
|
|
|
|
platformCallType: PlatformCallType,
|
2025-11-17 11:50:22 +00:00
|
|
|
skipLobby: boolean | undefined,
|
|
|
|
|
voiceOnly: boolean,
|
2024-01-29 17:06:12 +01:00
|
|
|
): Promise<void> => {
|
2024-11-04 09:49:41 +00:00
|
|
|
const { analyticsName } = getPlatformCallTypeProps(platformCallType);
|
|
|
|
|
PosthogTrackers.trackInteraction(analyticsName);
|
|
|
|
|
|
2024-01-31 16:18:52 +01:00
|
|
|
if (platformCallType == PlatformCallType.LegacyCall || platformCallType == PlatformCallType.JitsiCall) {
|
2026-07-14 13:58:34 +01:00
|
|
|
await legacyCallHandler.placeCall(room.roomId, callType);
|
2024-01-31 16:18:52 +01:00
|
|
|
} else if (platformCallType == PlatformCallType.ElementCall) {
|
|
|
|
|
defaultDispatcher.dispatch<ViewRoomPayload>({
|
|
|
|
|
action: Action.ViewRoom,
|
|
|
|
|
room_id: room.roomId,
|
|
|
|
|
view_call: true,
|
2025-11-17 11:50:22 +00:00
|
|
|
voiceOnly,
|
2024-01-31 16:18:52 +01:00
|
|
|
skipLobby,
|
|
|
|
|
metricsTrigger: undefined,
|
|
|
|
|
});
|
2023-08-31 14:27:15 +01:00
|
|
|
}
|
|
|
|
|
};
|