Parse a raw WebSocket frame from Plivo's audio stream.
Supported Plivo event types:
start -- stream established; stream_id maps to streamSid,
call_uuid maps to callSid.media -- audio chunk; media.payload contains base64-encoded mu-law
PCM bytes.stop -- stream ended (call terminated or stream explicitly closed).Any other event type is silently dropped by returning null. Malformed
JSON or messages missing required fields (event, stream_id) also
return null.
Raw WebSocket frame payload (JSON string or Buffer from Plivo).
Normalised MediaStreamIncoming event, or null for
unknown event types or malformed messages.
Encode mu-law audio for transmission back to Plivo.
Plivo requires audio to be base64-encoded and wrapped in a playAudio
JSON envelope. Unlike Twilio, the streamSid / stream_id is NOT
included in the outbound message -- Plivo implicitly routes the audio
to the caller on the same WebSocket connection.
Raw mu-law PCM bytes to send to the caller.
Unused by Plivo's playAudio format (accepted for
interface parity with other parsers).
JSON string: { event: 'playAudio', media: { payload: '<base64>' } }
Parses the Plivo Audio Stream WebSocket protocol.
Plivo sends JSON-encoded messages for stream lifecycle events (
start,stop) and audio chunks (media). The audio payload is base64-encoded mu-law PCM, delivered in apayloadfield inside themediaobject.Outgoing audio is wrapped in a
playAudioJSON envelope, which is the format Plivo expects when the server streams audio back to the caller. No explicit connection acknowledgment is required after the handshake.See
https://www.plivo.com/docs/voice/xml/stream