mirror of
https://github.com/vector-im/element-call.git
synced 2026-09-25 22:35:49 +00:00
* Give the microphone level its own observable * Add a microphone level meter * Show speakers and microphones in the quick audio menu * Wire speaker selection through the call footer * Add stories for the meter and the device menu * Add end-to-end specs for the quick audio menu * Keep the footer while a menu opened from it is open * Use the shared audio capture stub in the lobby test --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
35 lines
991 B
TypeScript
35 lines
991 B
TypeScript
/*
|
|
Copyright 2026 Element Creations Ltd.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
Please see LICENSE in the repository root for full details.
|
|
*/
|
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
import {
|
|
type MicrophoneState,
|
|
observeMicrophoneState$,
|
|
} from "../state/MicrophoneLevel";
|
|
import { constant } from "../state/Behavior";
|
|
|
|
const IDLE: MicrophoneState = { type: "level", level$: constant(0) };
|
|
|
|
/** The live level of a microphone, captured only while `active`. */
|
|
export function useMicrophoneLevel(
|
|
deviceId: string | undefined,
|
|
active: boolean,
|
|
): MicrophoneState {
|
|
const [state, setState] = useState<MicrophoneState>(IDLE);
|
|
|
|
useEffect(() => {
|
|
if (!active) return;
|
|
// Idle first, so a new device doesn't start from the previous level.
|
|
setState(IDLE);
|
|
const subscription = observeMicrophoneState$(deviceId).subscribe(setState);
|
|
return (): void => subscription.unsubscribe();
|
|
}, [deviceId, active]);
|
|
|
|
return state;
|
|
}
|