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
|
|
|
*/
|
|
|
|
|
|
2025-05-19 14:14:08 +02:00
|
|
|
import { BehaviorSubject, Subject } from "rxjs";
|
2024-08-27 07:47:20 -04:00
|
|
|
|
|
|
|
|
export interface Controls {
|
2025-04-29 22:12:07 +02:00
|
|
|
canEnterPip(): boolean;
|
|
|
|
|
enablePip(): void;
|
|
|
|
|
disablePip(): void;
|
2025-05-22 18:58:18 +02:00
|
|
|
/** @deprecated use setAvailableAudioDevices instead*/
|
2025-05-15 17:20:12 +02:00
|
|
|
setAvailableOutputDevices(devices: OutputDevice[]): void;
|
2025-05-22 18:58:18 +02:00
|
|
|
setAvailableAudioDevices(devices: OutputDevice[]): void;
|
|
|
|
|
/** @deprecated use setAudioDevice instead*/
|
2025-05-15 17:20:12 +02:00
|
|
|
setOutputDevice(id: string): void;
|
2025-05-22 18:58:18 +02:00
|
|
|
setAudioDevice(id: string): void;
|
|
|
|
|
/** @deprecated use onAudioDeviceSelect instead*/
|
2025-04-29 22:12:07 +02:00
|
|
|
onOutputDeviceSelect?: (id: string) => void;
|
2025-05-22 18:58:18 +02:00
|
|
|
onAudioDeviceSelect?: (id: string) => void;
|
|
|
|
|
/** @deprecated use setAudioEnabled instead*/
|
2025-04-29 22:12:07 +02:00
|
|
|
setOutputEnabled(enabled: boolean): void;
|
2025-05-22 18:58:18 +02:00
|
|
|
setAudioEnabled(enabled: boolean): void;
|
|
|
|
|
/** @deprecated use showNativeAudioDevicePicker instead*/
|
2025-05-16 12:28:49 +02:00
|
|
|
showNativeOutputDevicePicker?: () => void;
|
2025-05-22 18:58:18 +02:00
|
|
|
showNativeAudioDevicePicker?: () => 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;
|
2024-08-27 07:47:20 -04:00
|
|
|
}
|
|
|
|
|
|
2025-05-19 14:14:08 +02:00
|
|
|
/**
|
|
|
|
|
* If pipMode is enabled, EC will render a adapted call view layout.
|
|
|
|
|
*/
|
2024-12-17 04:01:56 +00:00
|
|
|
export const setPipEnabled$ = new Subject<boolean>();
|
2025-05-19 14:14:08 +02:00
|
|
|
// 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[]>([]);
|
2025-05-19 14:14:08 +02:00
|
|
|
// 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-19 14:14:08 +02:00
|
|
|
/**
|
2025-05-21 12:51:00 +02:00
|
|
|
* This allows the os to mute the call if the user
|
2025-05-19 14:14:08 +02:00
|
|
|
* 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-22 18:58:18 +02:00
|
|
|
export const setAudioEnabled$ = 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-22 18:58:18 +02:00
|
|
|
setAvailableAudioDevices(devices: OutputDevice[]): void {
|
2025-05-21 12:51:00 +02:00
|
|
|
availableOutputDevices$.next(devices);
|
2025-05-15 17:20:12 +02:00
|
|
|
},
|
2025-05-22 18:58:18 +02:00
|
|
|
setAudioDevice(id: string): void {
|
2025-05-21 12:51:00 +02:00
|
|
|
outputDevice$.next(id);
|
2025-04-29 22:12:07 +02:00
|
|
|
},
|
2025-05-22 18:58:18 +02:00
|
|
|
setAudioEnabled(enabled: boolean): void {
|
|
|
|
|
if (!setAudioEnabled$.observed)
|
2025-05-19 14:14:08 +02:00
|
|
|
throw new Error(
|
2025-05-22 18:58:18 +02:00
|
|
|
"Output controls are disabled. No setAudioEnabled$ observer",
|
2025-05-19 14:14:08 +02:00
|
|
|
);
|
2025-05-22 18:58:18 +02:00
|
|
|
setAudioEnabled$.next(enabled);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// wrappers for the deprecated controls fields
|
|
|
|
|
setOutputEnabled(enabled: boolean): void {
|
|
|
|
|
this.setAudioEnabled(enabled);
|
|
|
|
|
},
|
|
|
|
|
setAvailableOutputDevices(devices: OutputDevice[]): void {
|
|
|
|
|
this.setAvailableAudioDevices(devices);
|
|
|
|
|
},
|
|
|
|
|
setOutputDevice(id: string): void {
|
|
|
|
|
this.setAudioDevice(id);
|
2025-04-29 22:12:07 +02:00
|
|
|
},
|
2024-08-27 07:47:20 -04:00
|
|
|
};
|