2024-08-27 07:47:20 -04:00
|
|
|
/*
|
2024-09-06 10:22:13 +02:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2024-08-27 07:47:20 -04:00
|
|
|
|
2025-02-18 17:59:58 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-06 10:22:13 +02:00
|
|
|
Please see LICENSE in the repository root for full details.
|
2024-08-27 07:47:20 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { Subject } from "rxjs";
|
|
|
|
|
|
|
|
|
|
export interface Controls {
|
2025-04-29 22:12:07 +02:00
|
|
|
canEnterPip(): boolean;
|
|
|
|
|
enablePip(): void;
|
|
|
|
|
disablePip(): void;
|
2025-05-15 17:20:12 +02:00
|
|
|
setAvailableOutputDevices(devices: OutputDevice[]): void;
|
|
|
|
|
setOutputDevice(id: string): void;
|
2025-04-29 22:12:07 +02:00
|
|
|
onOutputDeviceSelect?: (id: string) => void;
|
|
|
|
|
setOutputEnabled(enabled: boolean): void;
|
2025-05-16 12:28:49 +02:00
|
|
|
showNativeOutputDevicePicker?: () => void;
|
2025-04-29 22:12:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface OutputDevice {
|
|
|
|
|
id: string;
|
|
|
|
|
name: string;
|
2025-05-14 19:55:08 +02:00
|
|
|
forEarpiece?: boolean;
|
2024-08-27 07:47:20 -04:00
|
|
|
}
|
|
|
|
|
|
2024-12-17 04:01:56 +00:00
|
|
|
export const setPipEnabled$ = new Subject<boolean>();
|
2025-05-15 17:20:12 +02:00
|
|
|
export const setAvailableOutputDevices$ = new Subject<OutputDevice[]>();
|
|
|
|
|
export const setOutputDevice$ = new Subject<string>();
|
2025-05-16 11:32:32 +02:00
|
|
|
export const setOutputEnabled$ = new Subject<boolean>();
|
2024-08-27 07:47:20 -04:00
|
|
|
|
|
|
|
|
window.controls = {
|
|
|
|
|
canEnterPip(): boolean {
|
2024-12-17 04:01:56 +00:00
|
|
|
return setPipEnabled$.observed;
|
2024-08-27 07:47:20 -04:00
|
|
|
},
|
|
|
|
|
enablePip(): void {
|
2024-12-17 04:01:56 +00:00
|
|
|
if (!setPipEnabled$.observed) throw new Error("No call is running");
|
|
|
|
|
setPipEnabled$.next(true);
|
2024-08-27 07:47:20 -04:00
|
|
|
},
|
|
|
|
|
disablePip(): void {
|
2024-12-17 04:01:56 +00:00
|
|
|
if (!setPipEnabled$.observed) throw new Error("No call is running");
|
|
|
|
|
setPipEnabled$.next(false);
|
2024-08-27 07:47:20 -04:00
|
|
|
},
|
2025-05-15 17:20:12 +02:00
|
|
|
setAvailableOutputDevices(devices: OutputDevice[]): void {
|
|
|
|
|
if (!setAvailableOutputDevices$.observed)
|
2025-04-29 22:12:07 +02:00
|
|
|
throw new Error("Output controls are disabled");
|
2025-05-15 17:20:12 +02:00
|
|
|
setAvailableOutputDevices$.next(devices);
|
|
|
|
|
},
|
|
|
|
|
setOutputDevice(id: string): void {
|
|
|
|
|
if (!setOutputDevice$.observed)
|
|
|
|
|
throw new Error("Output controls are disabled");
|
|
|
|
|
setOutputDevice$.next(id);
|
2025-04-29 22:12:07 +02:00
|
|
|
},
|
|
|
|
|
setOutputEnabled(enabled: boolean): void {
|
2025-05-16 11:32:32 +02:00
|
|
|
if (!setOutputEnabled$.observed)
|
2025-04-29 22:12:07 +02:00
|
|
|
throw new Error("Output controls are disabled");
|
2025-05-16 11:32:32 +02:00
|
|
|
setOutputEnabled$.next(!enabled);
|
2025-04-29 22:12:07 +02:00
|
|
|
},
|
2024-08-27 07:47:20 -04:00
|
|
|
};
|