Files
element-call/src/controls.ts
T

78 lines
2.5 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 { BehaviorSubject, 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;
2025-05-16 15:50:19 +02:00
isEarpiece?: boolean;
isSpeaker?: boolean;
2025-05-16 17:06:54 +02:00
isExternalHeadset?: boolean;
}
/**
* If pipMode is enabled, EC will render a adapted call view layout.
*/
export const setPipEnabled$ = new Subject<boolean>();
// BehaviorSubject since the client might set this before we have subscribed (GroupCallView still in "loading" state)
// We want the that has been set during loading to be be available immediately once loaded.
export const setAvailableOutputDevices$ = new BehaviorSubject<OutputDevice[]>(
[],
);
// BehaviorSubject since the client might set this before we have subscribed (GroupCallView still in "loading" state)
// We want the that has been set during loading to be be available immediately once loaded.
export const setOutputDevice$ = new BehaviorSubject<string | undefined>(
undefined,
);
/**
* This is currently unused. It might be possible to allow the os to mute the call this way if the user
* presses the volume down button when it is at the minimum volume.
*
* This should also be used to display a darkened overlay screen letting the user know that audio is muted.
*/
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 {
setAvailableOutputDevices$.next(devices);
},
setOutputDevice(id: string): void {
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)
throw new Error(
"Output controls are disabled. No setOutputEnabled$ observer",
);
2025-05-16 11:32:32 +02:00
setOutputEnabled$.next(!enabled);
2025-04-29 22:12:07 +02:00
},
};