Files
element-call/src/controls.ts
T

74 lines
2.4 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)
2025-05-21 12:51:00 +02:00
// We want the devices that have been set during loading to be available immediately once loaded.
export const availableOutputDevices$ = new BehaviorSubject<OutputDevice[]>([]);
// BehaviorSubject since the client might set this before we have subscribed (GroupCallView still in "loading" state)
2025-05-21 12:51:00 +02:00
// We want the device that has been set during loading to be available immediately once loaded.
export const outputDevice$ = new BehaviorSubject<string | undefined>(undefined);
/**
2025-05-21 12:51:00 +02:00
* This allows the os to mute the call 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 {
2025-05-21 12:51:00 +02:00
availableOutputDevices$.next(devices);
},
setOutputDevice(id: string): void {
2025-05-21 12:51:00 +02:00
outputDevice$.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-21 12:51:00 +02:00
setOutputEnabled$.next(enabled);
2025-04-29 22:12:07 +02:00
},
};