Skip to content

en US sdk transports

AKStream documentation edited this page Nov 12, 2026 · 2 revisions

WebRTC automatic, UDP and TCP connections

Web/H5, Android, iOS and UniApp Web/native clients share mediaTransport. The default is auto; explicit udp and tcp select the corresponding TURN relay transport. Use a MediaServer build containing the TURN/TCP compatibility fix and matching SDKs. Updating documentation or client code does not upgrade an older installed server.

Mode Client behavior Use case
auto Preserve the ICE policy and URLs from connection-settings; ICE can select direct or relayed connections Recommended default; direct connections usually cost less
udp Keep only UDP TURN URLs and enforce relay; no TCP or direct fallback Test or require UDP relaying
tcp Keep only TCP TURN URLs and enforce relay; no UDP or direct fallback Networks blocking client UDP, or a requirement for client TCP relaying

UDP/TCP here describes client to TURN. With ordinary TURN/TCP, TURN → MediaServer still uses UDP, which must remain reachable on the server side. TCP retransmissions and head-of-line blocking may increase delay under packet loss; TCP does not guarantee better video quality.

Minimal integration

Web/H5:

const rtc = new AkRtcWebClient(serverUrl, events, { mediaTransport: 'tcp' })
await rtc.join(roomId, accessTicket, { platform: 'pc-web' })

Alternatively call rtc.setMediaTransport('udp') before joining and read the choice using rtc.getMediaTransport(). Values other than auto, udp and tcp fail validation. To change an active session, call leave(), set the mode and join with a new ticket. Consumed one-time tickets cannot be reused. Camera, microphone, subscriptions and screen sharing use the same session policy.

Android:

client.setMediaTransport("tcp");
client.joinWithAccessTicket(serverUrl, roomId, accessTicket, passcode);

iOS:

try client.setMediaTransport("tcp")
client.joinWithAccessTicket(baseURL: serverUrl, roomID: roomId,
                           accessTicket: accessTicket, passcode: passcode)

Both native SDKs expose getMediaTransport(). ReplayKit and WebView native screen publishers inherit the main session choice. Update both the SDK and host distribution artifacts.

UniApp UTS accepts a creation default or an explicit join payload override:

const id = createRtcClient({ serverUrl, mediaTransport: 'tcp', onEvent })
invokeRtcClient(id, 'join', JSON.stringify({ roomId, accessTicket, passcode }), onResult)

The JavaScript facade accepts await uniClient.join({ roomId, accessTicket, mediaTransport: 'tcp' }). Native uni-app/uni-app x requires a custom base containing the updated AAR/XCFramework; replacing a page does not update embedded native SDKs.

WeChat Mini Program live-pusher/live-player uses RTMP/HTTP-FLV rather than browser WebRTC. That target accepts only auto; explicit UDP/TCP selection returns an unsupported error. Do not advertise TURN/TCP for that media path.

Deployment and credentials

  1. The business backend issues a one-time RTC ticket. After admission, the SDK reads the current room's connection-settings. Management API tokens and media administration secrets stay off clients.
  2. Explicit modes filter server-provided URLs and preserve their associated usernames and credentials. Changing a UDP URL or port to TCP cannot enable a missing service capability.
  3. UDP TURN uses the configured ICE UDP listener; TCP TURN uses the ICE TCP listener. Example URLs are turn:media.example.com:3478?transport=udp and turn:media.example.com:3479?transport=tcp. Use actual node settings and allow the matching NAT mappings, firewall rules and relay port range.
  4. Direct ICE-TCP uses a separate RTC TCP media listener. It is not a TURN listener. auto can negotiate direct ICE-TCP; the explicit tcp option forces TURN/TCP.
  5. turn:...?transport=tcp is not TLS. turns: requires a configured TLS TURN service, trusted certificate and matching credentials. The SDK does not enable TLS or deploy an external TURN server.

With no matching URL, Web/H5 throws RTC_TRANSPORT_UNAVAILABLE; native SDK failure callbacks explain the reason, and UniApp reports it through the invocation result or error event. There is no silent protocol fallback. A configured URL still needs a compatible server, valid credentials and reachable ports.

Verify the selected route

A relay candidate's protocol may be udp even with a TCP TURN connection. For the selected candidate pair, inspect the local candidate's relayProtocol:

const stats = await peer.getStats() // A RTCPeerConnection owned by your integration
for (const pair of stats.values()) {
  if (pair.type !== 'candidate-pair' || pair.state !== 'succeeded' || !pair.nominated) continue
  const local = stats.get(pair.localCandidateId)
  console.log(local?.candidateType, local?.protocol, local?.relayProtocol)
}
// TCP relay: relay / udp / tcp. Do not log credentials or complete SDP.

Do not depend on private SDK fields. Use browser WebRTC diagnostics or statistics from a native PeerConnection you own, together with SDK media diagnostics. Confirm increasing audio/video byte counts, decoded video frames and audio playback. An isolated 701 error, successful TCP handshake, Binding response or initial 401 challenge is not a media acceptance test.

Web/H5, native and UniApp demos expose Automatic / UDP relay / TCP relay before joining. Test two-person audio/video over both UDP and TCP, followed by screen sharing, network changes and leave cleanup. Browser families, physical devices, corporate proxies and public networks require separate acceptance. See acceptance and troubleshooting.

For native WeChat Mini Program integration and limitations, see the Mini Program guide and SDK API.

Clone this wiki locally