Member Junction
    Preparing search index...

    The recording capability a host may optionally provide.

    The host captures the call (mic + agent mix) at 48 kHz and runs ONE continuous Opus encoder for the whole call: mono, 32 kbps, 20 ms frames (960 samples). The runtime pulls the encoded packets every few seconds, cuts them into indexed MJOPUS1 shards, keeps each one in a durable local store until the server acknowledges it, and sends a terminal request when the call ends. The host never builds a container (no WAV, no Ogg) and never base64-encodes anything: the server assembles the final recording.wav from the shards.

    Every method is best-effort by contract: a recorder that fails mid-session must degrade to "no recording" rather than failing the call, because audio capture is never worth dropping a live conversation over.

    interface IRealtimeSessionRecorder {
        IsRecording: boolean;
        AttachRemoteStream(stream: MediaStream): void;
        NowOffsetMs(): number;
        ReplaceMicrophone?(micStream: MediaStream): void;
        Start(micStream: MediaStream, remoteStream: MediaStream | null): void;
        Stop(): Promise<number>;
        TakeEncodedPackets(): Uint8Array<ArrayBufferLike>[];
    }
    Index

    Properties

    IsRecording: boolean

    false when capture could not start (unsupported platform, no permission, no encoder).

    Methods

    • Mixes the agent's audio in once its track arrives, so the recording carries both sides.

      Parameters

      • stream: MediaStream

      Returns void

    • Milliseconds into the recording, derived from the samples captured so far on the 48 kHz sample clock (never wall clock), used to stamp per-turn cue offsets into the assembled file.

      Returns number

    • OPTIONAL: records the microphone stream's current track from now on, after its track was replaced (a device switch, or a lost device replaced by the default). A recorder bound to the old track would otherwise record silence. A recorder without it keeps its original binding.

      Parameters

      • micStream: MediaStream

      Returns void

    • Begins capture of the microphone, mixing in the agent's audio when it is already available.

      remoteStream is usually null here: on WebRTC the agent's track commonly lands slightly after the connection resolves, so the runtime also wires AttachRemoteStream.

      Parameters

      • micStream: MediaStream
      • remoteStream: MediaStream | null

      Returns void

    • Stops capture, flushes the encoder (its last packets become available to TakeEncodedPackets), and resolves the total number of samples captured at 48 kHz. That count may be less than packets × 960 when the encoder padded its last frame; the runtime trims the final shard to it. Idempotent: a second call resolves the same count.

      Returns Promise<number>

    • Returns the 20 ms Opus packets encoded since the previous call, in capture order, and forgets them; an empty array when none are ready. Synchronous and cheap: it hands over what the encoder already produced and never encodes on the caller's thread — the runtime calls it from pagehide, where there is no time to wait for an encoder.

      Returns Uint8Array<ArrayBufferLike>[]