Best Practices

WSS Socket Connection Failures

The audio streaming feature requires an active WebSocket connection throughout the call. If the initial connection attempt fails or if an established connection is dropped, Plivo will automatically retry the WebSocket connection twice before disconnecting the stream. Plivo also recommends using callbacks to monitor any connection failures. You can set this up by specifying the status_callback_url in your XML.

  • StartStream: Sent as soon as audio streaming begins.
  • StopStream: Sent when streaming stops.
  • DroppedStream: Sent for one of the following reasons:
    • WebSocket connection failed during initiation.
    • WebSocket connection was terminated during streaming.
    • WebSocket connection was terminated due to a slow connection.
  • DegradedStream: Sent when a slow connection is detected. Plivo buffers audio packets for up to 40 seconds, and when the buffer - reaches 30%, 60%, or 90% capacity, this event is triggered.

Disconnecting Stream & Websockets

Plivo automatically handles disconnecting the stream and WebSocket when your call is terminated, so there is no need to manually disconnect the WebSocket from your end.

Audio stream logs on Plivo Console

Plivo displays details of audio streams linked to a call on the respective Call Detail Record (CDR) page. In your audio stream log, you’ll find details including:

  • Stream uuid: A unique identifier for the audio stream associated with the call log.
  • Stream start time: The start time for the audio stream, displayed in UTC.
  • Stream end time: The end time for the audio stream ended, displayed in UTC.
  • Duration: The duration of the audio stream expressed in seconds.
  • Rounded bill duration: The total amount billed based on the billing interval, expressed in seconds.
  • Billed amount: The total charges incurred for the corresponding stream uuid.
  • Hangup reason: Specifies the cause behind the termination of the stream. Potential termination reasons include:
    • API request: The stream is disconnected through an API request.
    • Call hangup: The call ended and the stream was disconnected.
    • Connection error: A connection issue caused the stream to end.
    • Stream timeout: The stream ended when the duration specified in the stream_timeout parameter was reached.
  • Debug logs: A hyperlink leading customers to detailed audio streaming debug logs. These logs give you access to a list of events that occurred during audio streaming, aiding in debugging any stream-related issues.

Debuglogs

Sample debug log for an audio stream

        Params: {
                CallUUID: 7aea0680-1f8c-46c2-a04f-990e2e0d52eb
                Error: connection disconnected with the remote service
                Event: DroppedStream
                From: 14849386985
                ParentAuthID : AUTH_ID
                ServiceURL : wss://yourstream.ngrok.io/audiostream
                StreamID: 26b95870-2b2f-45be-88dc-aedd0fcccec6
                Timestamp: 2024-10-14 13:42:33
                To: sip:something@phone.plivo.com
                status_callback_method : POST
                status_callback_url : https://yourdomain.com/callbacks
           }