@fishjam-cloud/react-client
Version:
React client library for Fishjam
32 lines • 1.32 kB
TypeScript
import type { PeerId } from "../types/public";
/**
* Voice activity detection. Use this hook to check if voice is detected in the audio track for given peer(s).
*
* Remote peer VAD is driven by `vadNotification` messages from the backend.
* If the local peer's id is included in `peerIds`, local VAD is determined client-side
* by polling the microphone's audio level (see `useLocalVAD`).
*
* @param options - Options object.
* @param options.peerIds - List of peer ids to subscribe to for VAD notifications.
* Include the local peer's id to also track whether the local user is speaking.
*
* Example usage:
* ```tsx
* import { useVAD, type PeerId } from "@fishjam-cloud/react-client";
*
* function WhoIsTalkingComponent({ peerIds }: { peerIds: PeerId[] }) {
* const peersInfo = useVAD({ peerIds });
* const activePeers = (Object.keys(peersInfo) as PeerId[]).filter((peerId) => peersInfo[peerId]);
*
* return "Now talking: " + activePeers.join(", ");
* }
* ```
* @category Connection
* @group Hooks
* @returns A record where each key is a peer id and the boolean value indicates
* whether voice activity is currently detected for that peer.
*/
export declare const useVAD: (options: {
peerIds: ReadonlyArray<PeerId>;
}) => Record<PeerId, boolean>;
//# sourceMappingURL=useVAD.d.ts.map