Class TwilioMediaStreamParser<P>

Twilio media parser with an explicit documented carrier profile and a retained legacy profile. Carrier mode requires PCMU 8 kHz mono and preserves carrier timestamps and chunk counters. Legacy mode exists for existing callers and fixtures; it is not a live-carrier conformance claim.

Type Parameters

  • P extends "legacy" | "carrier" = "legacy"

Implements

Constructors

Methods

  • Parse a raw WebSocket frame from Twilio's media stream.

    Supported Twilio event types:

    • start -- stream established, includes callSid and media format metadata.
    • media -- audio chunk (inbound track only; outbound echoes are discarded to prevent feedback loops).
    • dtmf -- DTMF keypress detected on the audio stream.
    • stop -- stream ended (call hangup or stream disconnect).
    • mark -- named synchronisation marker confirming playback reached a point.

    Messages with missing event or streamSid fields, malformed JSON, or unrecognised event types are silently dropped (return null).

    In the carrier profile (parseCarrierMedia) a start must declare PCMU at 8 kHz mono, the numeric strings sequenceNumber, media.chunk and media.timestamp are read as integers, and a malformed payload is dropped; an unsupported start format, an error event or an oversized frame throws.

    Parameters

    • data: string | Buffer<ArrayBufferLike>

      Raw WebSocket frame payload (always a JSON string from Twilio).

    Returns null | MediaStreamIncoming

    Normalised MediaStreamIncoming event, or null for outbound audio tracks, unknown event types, or malformed messages.

Properties

protocol: P

Selected once; the no-argument constructor preserves released behavior.