Surfaces ↓
Voice
client.voice Daemon -> webapp voice/NLU surface: mic state-change events and the
reply to voice.stateGet.
Requests
you ask, the daemon answers; await the tagged result and check .ok
stateGet(): Promise<TypedRequestResult<VoiceStateReply, never>>
push form: onStateReply (subscribe instead of awaiting)
Webapp asks for the current VoiceState (muted / capturing).
const res = await client.voice.stateGet();
if (res.ok) {
console.log(res.response.state);
} type Result =
| { ok: true; response: VoiceStateReply }
| { ok: false; kind: 'domain'; error: never }
| { ok: false; kind: 'protocol'; error: WireError }; Commands
fire-and-forget; the promise resolves once the daemon has taken the message
cancel(): Promise<void>
await client.voice.cancel(); pushToTalk(): Promise<void>
await client.voice.pushToTalk(); Events
the daemon pushes these unprompted; subscribing returns an unsubscribe function
onStateChanged(handler: (VoiceState) => void): () => void
const off = client.voice.onStateChanged((state) => {
console.log(state.muted);
});
// call off() to unsubscribe Types
shapes referenced above, as the SDK types them
Current mic state.
type VoiceState = {
muted: boolean;
capturing: boolean; // True while a capture session is actively recording.
}; Response to voice.stateGet.
type VoiceStateReply = {
state: VoiceState;
}; Payload for voice.muteMic.
type MicMute = {
preserve: boolean; // When true and a capture session is already in progress, let it keep running instead of cutting it short.
}; Payload for voice.unmuteMic.
type MicUnmute = {
preserve: boolean; // Accepted for symmetry with `MicMute`; the daemon ignores it on unmute.
};