Skip to main content

WebRTC Statistics ​

The SDK provides WebRTC statistics functionality to assist with troubleshooting and monitoring call quality. This feature is controlled through the debug flag in the TxClient configuration.

Enabling WebRTC Statistics ​

To enable WebRTC statistics logging:

let txConfig = TxConfig(sipUser: sipUser,
password: password,
pushDeviceToken: "DEVICE_APNS_TOKEN",
debug: true) // Enable WebRTC statistics

Understanding WebRTC Statistics ​

When debug: true is configured:

  • WebRTC statistics logs are automatically collected during calls
  • Logs are sent to the Telnyx portal and are accessible in the Object Storage section
  • Statistics are linked to the SIP credential used for testing
  • The logs help the Telnyx support team diagnose issues and optimize call quality
  • All statistics are presented in the Telnyx portal under the Object Storage section

Real-time Call Quality Monitoring ​

The SDK provides real-time call quality metrics through the onCallQualityChange callback on the Call object. This allows you to monitor call quality in real-time and provide feedback to users.

Using onCallQualityChanged ​

// When creating a new call set debug to true for CallQualityMetrics
let call = try telnyxClient.newCall(callerName: "Caller name",
callerNumber: "155531234567",
destinationNumber: "18004377950",
callId: UUID.init(),
debug:true) // Enable Call Quality

//When accepting a call
telnyxClient?.answerFromCallkit(answerAction: action,
debug:true) // Enable Call Quality

or

call?.answer(debug:true) // Enable Call Quality

// Set the onCallQualityChange callback
call.onCallQualityChange = { metrics in
// Handle call quality metrics
print("Call quality: \(metrics.quality.rawValue)")
print("MOS score: \(metrics.mos)")
print("Jitter: \(metrics.jitter * 1000) ms")
print("Round-trip time: \(metrics.rtt * 1000) ms")

// Update UI based on call quality
switch metrics.quality {
case .excellent, .good:
// Show excellent/good quality indicator
self.qualityIndicator.backgroundColor = .green
case .fair:
// Show fair quality indicator
self.qualityIndicator.backgroundColor = .yellow
case .poor, .bad:
// Show poor/bad quality indicator
self.qualityIndicator.backgroundColor = .red
// Optionally show a message to the user
case .unknown:
// Quality couldn't be determined
self.qualityIndicator.backgroundColor = .gray
}
}

CallQualityMetrics Properties ​

The CallQualityMetrics object provides the following properties:

PropertyTypeDescription
jitterDoubleJitter in seconds (multiply by 1000 for milliseconds)
rttDoubleRound-trip time in seconds (multiply by 1000 for milliseconds)
mosDoubleMean Opinion Score (1.0-5.0)
qualityCallQualityCall quality rating based on MOS
inboundAudio[String: Any]?Inbound audio statistics
outboundAudio[String: Any]?Outbound audio statistics
remoteInboundAudio[String: Any]?Remote inbound audio statistics
remoteOutboundAudio[String: Any]?Remote outbound audio statistics

CallQuality Enum ​

The CallQuality enum provides the following values:

ValueMOS RangeDescription
.excellentMOS > 4.2Excellent call quality
.good4.1 <= MOS <= 4.2Good call quality
.fair3.7 <= MOS <= 4.0Fair call quality
.poor3.1 <= MOS <= 3.6Poor call quality
.badMOS <= 3.0Bad call quality
.unknownN/AUnable to calculate quality

Best Practices for Call Quality Monitoring ​

  1. User Feedback:

    • Consider showing a visual indicator of call quality to users
    • For poor quality calls, provide suggestions (e.g., "Try moving to an area with better connectivity")
  2. Logging:

    • Log quality metrics for later analysis
    • Track quality trends over time to identify patterns
  3. Adaptive Behavior:

    • Implement adaptive behaviors based on call quality
    • For example, suggest switching to audio-only if video quality is poor
  4. Performance Considerations:

    • The callback is triggered periodically (approximately every 2 seconds)

Important Notes ​

  1. Log Access:

    • If you run the app using SIP credential A with debug: true, the WebRTC logs will be available in the Telnyx portal account associated with credential A
    • Logs are stored in the Object Storage section of your Telnyx portal
  2. Troubleshooting Support:

    • WebRTC statistics are primarily intended to assist the Telnyx support team
    • When requesting support, enable debug: true in TxClient for all instances
    • Provide the debug ID or callId when contacting support
    • Statistics logging is disabled by default to optimize performance
  3. Best Practices:

    • Enable debug: true only when troubleshooting is needed
    • Remember to provide the debug ID or callId in support requests
    • Consider disabling debug mode in production unless actively investigating issues