Files
element-call/src/controls.ts
T

60 lines
1.7 KiB
TypeScript
Raw Normal View History

/*
Copyright 2024 New Vector Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import { Subject } from "rxjs";
export interface Controls {
2025-04-29 22:12:07 +02:00
canEnterPip(): boolean;
enablePip(): void;
disablePip(): void;
setAvailableOutputDevices(devices: OutputDevice[]): void;
setOutputDevice(id: string): void;
2025-04-29 22:12:07 +02:00
onOutputDeviceSelect?: (id: string) => void;
setOutputEnabled(enabled: boolean): void;
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;
}
export const setPipEnabled$ = new Subject<boolean>();
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>();
window.controls = {
canEnterPip(): boolean {
return setPipEnabled$.observed;
},
enablePip(): void {
if (!setPipEnabled$.observed) throw new Error("No call is running");
setPipEnabled$.next(true);
},
disablePip(): void {
if (!setPipEnabled$.observed) throw new Error("No call is running");
setPipEnabled$.next(false);
},
setAvailableOutputDevices(devices: OutputDevice[]): void {
if (!setAvailableOutputDevices$.observed)
2025-04-29 22:12:07 +02:00
throw new Error("Output controls are disabled");
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
},
};