Overview
Subscribe to a remote stream and assign networkStatsDelegate so you receive statistics callbacks. On iOS, video, audio, and media link stats (including network condition events) are delivered through a single OTSubscriberKitNetworkStatsDelegate—not separate listener objects like on Android.
The callback handling is implemented in the next step.
1. Subscribe and Register the Network Stats Delegate
When a remote stream is created, build an OTSubscriber, set delegates, and subscribe:
func session(_ session: OTSession, streamCreated stream: OTStream) {
guard subscriber == nil else { return }
let subscriber = OTSubscriber(stream: stream, delegate: self)
subscriber.networkStatsDelegate = self // OTSubscriberKitNetworkStatsDelegate
self.subscriber = subscriber
var error: OTError?
session.subscribe(subscriber, error: &error)
if let error {
print("Subscribe error: \(error)")
}
}
| Delegate | What it delivers |
|---|---|
OTSubscriberDelegate |
Connection lifecycle, subscriber view |
OTSubscriberKitNetworkStatsDelegate |
Video/audio stats, media link stats, network condition events |
iOS-specific: Set networkStatsDelegate on the subscriber instance. There is no separate “media link listener” registration—implement mediaLinkStatsUpdated and networkConditionChanged on the same delegate type.
2. Clear State When the Stream Ends
Reset observability state when the stream is destroyed:
func session(_ session: OTSession, streamDestroyed stream: OTStream) {
subscriber = nil
latestObservabilityStats = nil
latestMediaLinkSnapshot = nil
DispatchQueue.main.async {
self.subView = nil
}
}
In subscriberDidConnect, assign the subscriber view for SwiftUI:
func subscriberDidConnect(toStream subscriberKit: OTSubscriberKit) {
if let view = subscriber?.view {
DispatchQueue.main.async {
self.subView = view
}
}
}
Next: Implement the network stats delegate methods and merge data for the overlay.
Client Observability
Learn how to use client observability to monitor real-time quality metrics for a video call with Vonage Video SDK.