|
| 1 | +## WebRTC Statistics |
| 2 | + |
| 3 | +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. |
| 4 | + |
| 5 | +### Enabling WebRTC Statistics |
| 6 | + |
| 7 | +To enable WebRTC statistics logging: |
| 8 | + |
| 9 | +```Kotlin |
| 10 | +val credentialConfig = CredentialConfig( |
| 11 | + sipUser = sipUsername ?: "", |
| 12 | + sipPassword = sipPass ?: "", |
| 13 | + sipCallerIDName = this.callerIdName, |
| 14 | + sipCallerIDNumber = callerIdNumber, |
| 15 | + logLevel = LogLevel.ALL, |
| 16 | + debug = false // Enable debug mode for WebRTC statistics |
| 17 | +) |
| 18 | + |
| 19 | +// or With Token Login |
| 20 | + |
| 21 | +val credentialConfig = TokenConfig( |
| 22 | + sipToken= sipToken ?: "", |
| 23 | + sipCallerIDName = this.callerIdName, |
| 24 | + sipCallerIDNumber = callerIdNumber, |
| 25 | + logLevel = LogLevel.ALL, |
| 26 | + debug = false |
| 27 | +) |
| 28 | +``` |
| 29 | + |
| 30 | +### Understanding WebRTC Statistics |
| 31 | + |
| 32 | +When `debug: true` is configured: |
| 33 | +- WebRTC statistics logs are automatically collected during calls |
| 34 | +- Logs are sent to the Telnyx portal and are accessible in the Object Storage section |
| 35 | +- Statistics are linked to the SIP credential used for testing |
| 36 | +- The logs help the Telnyx support team diagnose issues and optimize call quality |
| 37 | +- All statistics are presented in the Telnyx portal under the Object Storage section |
| 38 | + |
| 39 | + |
| 40 | +### Real-time Call Quality Monitoring |
| 41 | + |
| 42 | +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. |
| 43 | + |
| 44 | +#### Using onCallQualityChanged |
| 45 | + |
| 46 | +```Kotlin |
| 47 | +// When creating a new call set debug to true for CallQualityMetrics |
| 48 | +val outgoingCall = telnyxClient.newInvite(callerName, callerNumber, destinationNumber, clientState, customHeaders, |
| 49 | + debug // debug value |
| 50 | +) |
| 51 | +//When accepting a call |
| 52 | +val incomingCall = telnyxCommon.getTelnyxClient(context).acceptCall(callId, callerIdNumber, customHeaders, |
| 53 | + debug // debug value |
| 54 | +) |
| 55 | + |
| 56 | +// Set the onCallQualityChange callback |
| 57 | +incomingCall.onCallQualityChange = { callQualityMetrics -> |
| 58 | + // Handle call quality metrics |
| 59 | + println("Call quality: ${callQualityMetrics.quality}") |
| 60 | + println("MOS score: ${callQualityMetrics.mos}") |
| 61 | + println("Jitter: ${callQualityMetrics.jitter} ms") |
| 62 | + println("Round-trip time: ${callQualityMetrics.rtt} ms") |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +``` |
| 67 | + |
| 68 | +#### CallQualityMetrics Properties |
| 69 | + |
| 70 | +The `CallQualityMetrics` object provides the following properties: |
| 71 | + |
| 72 | +| Property | Type | Description | |
| 73 | +|----------|------|-------------| |
| 74 | +| `jitter` | Double | Jitter in seconds (multiply by 1000 for milliseconds) | |
| 75 | +| `rtt` | Double | Round-trip time in seconds (multiply by 1000 for milliseconds) | |
| 76 | +| `mos` | Double | Mean Opinion Score (1.0-5.0) | |
| 77 | +| `quality` | CallQuality | Call quality rating based on MOS | |
| 78 | +| `inboundAudio` | Map<String, Any>? | Inbound audio statistics | |
| 79 | +| `outboundAudio` | Map<String, Any>? | Outbound audio statistics | |
| 80 | +| `remoteInboundAudio` | Map<String, Any>? | Remote inbound audio statistics | |
| 81 | +| `remoteOutboundAudio` | Map<String, Any>? | Remote outbound audio statistics | |
| 82 | + |
| 83 | +#### CallQuality Enum |
| 84 | + |
| 85 | +The `CallQuality` enum provides the following values: |
| 86 | + |
| 87 | +| Value | MOS Range | Description | |
| 88 | +|-------|-----------|-------------| |
| 89 | +| `.excellent` | MOS > 4.2 | Excellent call quality | |
| 90 | +| `.good` | 4.1 <= MOS <= 4.2 | Good call quality | |
| 91 | +| `.fair` | 3.7 <= MOS <= 4.0 | Fair call quality | |
| 92 | +| `.poor` | 3.1 <= MOS <= 3.6 | Poor call quality | |
| 93 | +| `.bad` | MOS <= 3.0 | Bad call quality | |
| 94 | +| `.unknown` | N/A | Unable to calculate quality | |
| 95 | + |
| 96 | +#### Best Practices for Call Quality Monitoring |
| 97 | + |
| 98 | +1. **User Feedback**: |
| 99 | + - Consider showing a visual indicator of call quality to users |
| 100 | + - For poor quality calls, provide suggestions (e.g., "Try moving to an area with better connectivity") |
| 101 | + |
| 102 | +2. **Logging**: |
| 103 | + - Log quality metrics for later analysis |
| 104 | + - Track quality trends over time to identify patterns |
| 105 | + |
| 106 | +3. **Adaptive Behavior**: |
| 107 | + - Implement adaptive behaviors based on call quality |
| 108 | + - For example, suggest switching to audio-only if video quality is poor |
| 109 | + |
| 110 | +4. **Performance Considerations**: |
| 111 | + - The callback is triggered periodically (approximately every 2 seconds) |
| 112 | + |
| 113 | +### Important Notes |
| 114 | + |
| 115 | +1. **Log Access**: |
| 116 | + - 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 |
| 117 | + - Logs are stored in the Object Storage section of your Telnyx portal |
| 118 | + |
| 119 | +2. **Troubleshooting Support**: |
| 120 | + - WebRTC statistics are primarily intended to assist the Telnyx support team |
| 121 | + - When requesting support, enable `debug: true` in `TxClient` for all instances |
| 122 | + - Provide the `debug ID` or `callId` when contacting support |
| 123 | + - Statistics logging is disabled by default to optimize performance |
| 124 | + |
| 125 | +3. **Best Practices**: |
| 126 | + - Enable `debug: true` only when troubleshooting is needed |
| 127 | + - Remember to provide the `debug ID` or `callId` in support requests |
| 128 | + - Consider disabling debug mode in production unless actively investigating issues |
| 129 | + |
| 130 | +--- |
| 131 | +</br> |
0 commit comments