Overview
The SFU periodically sends a set of control-plane messages, which the SDK turns into fourChannelDelegate events:
There’s also
didUpdateLocalQuality (since 1.9.0), which is available on both engines and computed locally by the SDK; see Local network quality below.
The quality and layer events exist only on the SeaStart (SFU) engine. They travel over the signaling DataChannel on the subscribing PeerConnection, and the Wangsu (CDN) engine has no such path, so with CDN you don’t receive them and
getConnectionQuality() also returns nil. didChangeActiveSpeakers is the exception: on Wangsu channels the SDK computes remote speakers locally (covering subscribed audio only), so it fires on both engines. Use Channel.streamVendor to tell the current engine—see Types.Network quality: two event streams, don’t mix them up
Quality uses two event streams, because the two kinds of needs differ in trigger frequency by an order of magnitude:didReceiveQualityReport—fires on every server report; it’s a stream of raw valuesdidChangeConnectionQuality—fires only when the level changes; it signals a state change
QualityReport has two QualitySample values, pub (uplink, client to SFU) and sub (downlink, SFU to client); for field meanings, see Types. Key points:
levelis the level given by the server; for bothscore(0–100) andmos(1.0–4.5), higher is betterlossis a ratio (0–1), not a percentagerttandjitterare in milliseconds;bitrateis in kbps- When figuring out “whose problem it is”, look at both sides: a poor
pubmeans a problem with your own uplink; a poorsubmeans a problem with the downlink or the remote side’s uplink
evaluation.overall in ConnectionQualityChange takes the worse of the uplink and downlink levels (unknown < excellent < good < poor < lost), and evaluation.mos takes the smaller of the two—both follow “the side the user perceives as weakest”. previous is the level before the change, and is .unknown on the first change.
Cold start: show the level as soon as the page opens
Events arrive only on changes, so when the UI is first created you have no value yet. CallgetConnectionQuality() once to fill in the current snapshot:
nil when no report has been received yet (which is different from “a report was received but the level is unknown”).
After a reconnect, the SDK clears the quality cache (latest evaluation, level-change baseline, speaker snapshot), so the UI doesn’t keep showing a stale
poor level after recovery. So after a reconnect, getConnectionQuality() briefly returns nil until a new report arrives—this is intentional; just treat it as “no data yet” in the UI.Local network quality
didUpdateLocalQuality (since 1.9.0) is computed by the SDK locally from WebRTC statistics, about every 2 seconds, and fires on both the SeaStart and Wangsu (CDN) engines. Wangsu channels have no server-side quality reports, so signal-strength icons and network details panels can only use it.
channel.getLocalQuality(). It returns nil before the first sampling round completes after joining (about 2 seconds) or after you leave the channel.
A few notes:
- It measures the segment from your device to the access point (round-trip time comes from ICE connectivity checks) and doesn’t include the remote side; it tells you “how my network is doing”.
- Round-trip time and packet loss are each mapped to a level, and the worse one is used; for thresholds see
LocalQualityLevel. - When you’re neither publishing nor subscribing to any track, both directions are
unknown: there’s no media connection to measure, and it isn’t a fault—for example, when you’re alone in the channel with the microphone and camera off. - It’s independent of
didReceiveQualityReportsent by the SFU. SeaStart channels have both, but their values are measured differently, so don’t compare them directly.
Active speakers
snapshot.speakers is the full list: the SDK has already merged the server’s incremental protocol (who started speaking, who stopped) into a complete snapshot, sorted by level in descending order. So:
- Your app just overwrites the UI state as a whole; you don’t need to maintain a set of “who is still speaking” yourself
- When nobody is speaking,
speakersis an empty array—the event isn’t skipped levelis a normalized linear volume (0–1), which you can use directly to draw a volume bar
ActiveSpeakerInfo carries uid and trackId—the same user may have multiple audio tracks, so use the latter when you need to pinpoint the exact track.
Your own volume (since 1.6.0)
The snapshot includes you as well: the entry withisLocal == true, whose trackId is your published audio track. It appears only while you are publishing audio, not muted, and actually speaking—matching what the remote side hears. The server doesn’t send your volume back to you, so the SDK computes this entry locally with the same algorithm the server uses to detect speakers. It is therefore on the same scale as remote speakers (both quantized in steps of 1/8), and one threshold is enough:
srtc.activeSpeakerOptions:
In 1.5.5 and earlier, your own volume required implementing an
AudioProcessor and attaching it to audioCaptureProcessor to compute from captured audio. After upgrading, simply remove that code. Keeping it causes no conflict (the SDK’s metering and your processor run in the same chain without replacing each other), but the volume you compute yourself is not on the same scale as remote speakers.Simulcast: switch layers manually
When the publisher has simulcast enabled, the same video has multiple layers. By default the SFU selects a layer automatically based on bandwidth, and notifies you throughdidSwitchLayer after switching (reason is a server reason such as bwe_down / bwe_up):
didSwitchLayer fires as well, with reason set to client.
Throws:
SRTCError.engineNotSupported(_:)—the current engine isn’t SeaStart (for example, when using CDN)SRTCError.transportNotReady—the signaling channel isn’t ready yet (just joined, or reconnecting)SRTCError.webrtcError(_:)—sending on the signaling channel failed (usually buffer congestion)