Parse a raw WebSocket message received from the telephony provider.
Implementations must handle both Buffer (binary frames) and string
(text frames) inputs, since different providers and WebSocket libraries
deliver data in different forms.
Raw message bytes or string as delivered by the WS frame.
A normalised MediaStreamIncoming event, or null if the
message should be silently ignored (e.g. unknown event type, outbound
audio track, heartbeat frames, etc.).
Encode mu-law audio for transmission back to the telephony provider.
The returned type varies by provider:
string wrapping base64-encoded audio in a
{ event: 'media', streamSid, media: { payload } } envelope.Buffer unchanged (binary WS frame).string with a { event: 'playAudio', media: { payload } } envelope.Raw mu-law PCM bytes to send to the caller.
Provider stream identifier required by some formats.
A Buffer (for providers that accept raw binary) or a JSON
string (for providers that wrap audio in an envelope).
Optional formatGenerate the initial connection acknowledgment message, if the provider requires one immediately after the WebSocket handshake.
{ event: 'connected', protocol: 'Call', version: '1.0.0' }.null (no handshake needed).The stream identifier established during the handshake.
A JSON string to send as the first WS message, or null if the
provider does not need an explicit acknowledgment.
Contract for parsing and formatting provider-specific WebSocket media stream messages.
The interface has three responsibilities:
See
connectedack.playAudiooutbound, no ack.