Files
suaveplan/packages/ui/react/react-audio-stream/src/hooks/use-stream-levels/use-stream-levels.ts
2026-05-27 23:47:53 +01:00

16 lines
620 B
TypeScript

import type { LevelSample } from "../../session/session-shape/session-shape.types.js";
import { useStreamContextOrThrow } from "../internal/use-stream-context.js";
/**
* Returns realtime peak/RMS for the local microphone (when `peerId` is
* omitted) or for the named peer. Levels come from the peer chain's
* analyzer slot owned by chunks A+B; this hook is a pure projection.
*/
export function useStreamLevels(peerId?: string): LevelSample {
const { session } = useStreamContextOrThrow();
if (peerId === undefined) {
return session.getLocalLevel();
}
return session.getPeerLevel(peerId);
}