Reference

Audio Channels

← Back to Wire Protocol

What the SDK does on the two peer connections.

A WebRTC peer connection that publishes the mic. SDP and ICE travel over the Socket.IO socket (the asr-webrtc-* events in §4a and §4c), not over HTTP. There is no separate signaling channel to manage.

ICE config (iceConfig() in src/experience/wire.js):

new RTCPeerConnection({
  iceServers: [{
    urls: [ "turn:<turnServerUrl>:80?transport=udp",
            "turn:<turnServerUrl>:443?transport=udp",
            "turn:<turnServerUrl>:80?transport=tcp",
            "turns:<turnServerUrl>:443?transport=tcp" ],
    username, credential }],
  iceTransportPolicy: "all",
  bundlePolicy: "max-bundle"
})

TURN servers

Source Meaning
Server turn Short-lived TURN credentials for this session, sent as turn in onServerConnected (§4b). The SDK also reads turn from clientConfiguration, joinComplete and stvNewSession. Listed first, so they win when both entries work.
turnServerUrl TURN host from appInit. The SDK expands it into the four URLs above and lists it after the server entry.
turnCredentials Optional { username, credential } for turnServerUrl. appInit returns none, so the SDK's default TURN credentials apply unless you pass your own. Own credentials for a host the server entry doesn't name are used alone, and the server entry is not sent there. The SDK reads this object once, when the session is created. Changing it later has no effect.

Server TURN credentials. No app code is needed. The SDK reads them, checks them and keeps them out of logs, events and errors.

Signaling sequence:

→ asr-webrtc-init {sessionId}
← asr-webrtc-ready
  create offer
→ asr-webrtc-offer {offer, is_reconnect}
← asr-webrtc-answer {answer}
  setRemoteDescription
ICE trickles both ways: → asr-webrtc-ice-candidate, ← asr-ice-candidate

Some agents run in audio/phone mode. Their stvNewSession reply carries status: "audio/phone mode - no STV session" and no session_id or webrtc_url (§4b).

KalturaAvatarSession handles that reply as follows:

This SDK does not implement an audio-mode WebRTC downlink. The mic uplink connects, but the agent's spoken reply does not reach you through this SDK. Audio/phone mode is not a supported feature. For video agents, use the §5 and §6 paths.

A receive-only WebRTC peer connection fed by WHEP (WebRTC-HTTP Egress Protocol). Signaling is plain SDP over HTTP, independent of the socket.

URL: the SDK POSTs to the webrtc_url from the stvNewSession reply, verbatim. If the reply has no webrtc_url, the SDK builds {srsBaseUrl}/rtc/v1/whep/?app=app&stream={session_id} from the srsBaseUrl session option (whepUrl() in wire.js). The SDK never sends cast_mode in stvNewSession.

ICE config:

iceTransportPolicy: "relay"     // 'all' on Firefox
bundlePolicy: "max-bundle"

It uses the same TURN URL block and options as §5.

WHEP request:

POST {webrtc_url}
Content-Type: application/sdp
body: <client offer SDP>          → response body: <answer SDP>  (HTTP 201)

Timeout and retry: each POST gets 5 s, and reading the answer body counts toward it. A try that times out or fails on the network is retried after 1 s, up to 3 tries in all, inside the connect deadline. An HTTP status is never retried, because each status has its own meaning (below). If every try fails, connect() rejects with whep_timeout (the last try timed out) or whep_failed (the last try failed on the network). Both carry phase: 'whep' and retryable: true. Tune with timeouts.whepTry, whepTries and whepBackoff.

Teardown: the SDK sends DELETE to the WHEP resource named by the 201's Location header. The SDK builds the release URL as the POSTed subscribe URL plus the header's /viewer/… suffix (whepResourceUrl() in wire.js). An absolute Location is used as-is. Any other relative one resolves against the subscribe URL. A custom client must build the URL the same way, or the DELETE misses and the viewer slot stays held. The DELETE has a 3 s deadline (timeouts.whepRelease) and never throws. A teardown DELETE is sent with keepalive, so it outlives a page that closes right after (Resilience: page exit). A DELETE can only name a resource whose answer arrived, so a POST aborted in flight leaves nothing to release.

WHEP status codes: 404 and 409 mean the avatar session cannot take this subscribe (it is gone, or a viewer is already attached, for example after a timed-out try whose answer was lost). The SDK asks for a new avatar session once on the live socket and POSTs again, both at connect and during media recovery. A second 404 or 409 rejects with stv_session_gone. Any other non-2xx rejects connect() with whep_failed, the HTTP status, and a hint in detail for 415. If the re-subscribe during media recovery still fails, the SDK does a cold reconnect.

Doc Covers
Wire Protocol · Connection Basics Channels at a glance and the socket connection
Wire Protocol · Events Catalog The asr-webrtc-* signaling events referenced above
Wire Protocol Back to the index
Click to talk with Nova — she knows this whole SDK.
Nova AI assistant — knows this whole site

Nova is an AI assistant and can make mistakes. Check important details in the docs. Reloading starts a fresh chat.