|
| 1 | +--- |
| 2 | +title: Azure Communication Services User Facing Diagnostics (iOS) |
| 3 | +titleSuffix: An Azure Communication Services concept document |
| 4 | +description: Provides usage samples of the User Facing Diagnostics feature iOS Native. |
| 5 | +author: lucianopa-msft |
| 6 | +ms.author: lucianopa |
| 7 | + |
| 8 | +services: azure-communication-services |
| 9 | +ms.date: 04/06/2023 |
| 10 | +ms.topic: include |
| 11 | +ms.service: azure-communication-services |
| 12 | +ms.subservice: calling |
| 13 | +--- |
| 14 | + |
| 15 | +## Accessing diagnostics |
| 16 | + |
| 17 | +User-facing diagnostics is an extended feature of the core `Call` API and allows you to diagnose an active call. |
| 18 | + |
| 19 | +```swift |
| 20 | +let userFacingDiagnostics = self.call?.feature(Features.diagnostics) |
| 21 | +``` |
| 22 | + |
| 23 | +## User Facing Diagnostic events |
| 24 | + |
| 25 | +- Implement the delegates for `media` and `network` diagnostic sources. `MediaDiagnosticsDelegate` and `NetworkDiagnosticsDelegate` respectively. |
| 26 | + |
| 27 | +```swift |
| 28 | +extension CallObserver: MediaDiagnosticsDelegate { |
| 29 | + func mediaDiagnostics(_ mediaDiagnostics: MediaDiagnostics, |
| 30 | + didChangeCameraFreezeValue args: FlagDiagnosticChangedEventArgs) { |
| 31 | + let newValue = args.value |
| 32 | + // Handle the diagnostic event value changed... |
| 33 | + } |
| 34 | + |
| 35 | + func mediaDiagnostics(_ mediaDiagnostics: MediaDiagnostics, |
| 36 | + didChangeSpeakerMutedValue args: FlagDiagnosticChangedEventArgs) { |
| 37 | + let newValue = args.value |
| 38 | + // Handle the diagnostic event value changed... |
| 39 | + } |
| 40 | + |
| 41 | + func mediaDiagnostics(_ mediaDiagnostics: MediaDiagnostics, |
| 42 | + didChangeCameraStartFailedValue args: FlagDiagnosticChangedEventArgs) { |
| 43 | + let newValue = args.value |
| 44 | + // Handle the diagnostic event value changed... |
| 45 | + } |
| 46 | + |
| 47 | + func mediaDiagnostics(_ mediaDiagnostics: MediaDiagnostics, |
| 48 | + didChangeSpeakerNotFunctioningValue args: FlagDiagnosticChangedEventArgs) { |
| 49 | + let newValue = args.value |
| 50 | + // Handle the diagnostic event value changed... |
| 51 | + } |
| 52 | + |
| 53 | + func mediaDiagnostics(_ mediaDiagnostics: MediaDiagnostics, |
| 54 | + didChangeCameraPermissionDeniedValue args: FlagDiagnosticChangedEventArgs) { |
| 55 | + let newValue = args.value |
| 56 | + // Handle the diagnostic event value changed... |
| 57 | + } |
| 58 | + |
| 59 | + func mediaDiagnostics(_ mediaDiagnostics: MediaDiagnostics, |
| 60 | + didChangeMicrophoneNotFunctioningValue args: FlagDiagnosticChangedEventArgs) { |
| 61 | + let newValue = args.value |
| 62 | + // Handle the diagnostic event value changed... |
| 63 | + } |
| 64 | + |
| 65 | + func mediaDiagnostics(_ mediaDiagnostics: MediaDiagnostics, |
| 66 | + didChangeMicrophoneMuteUnexpectedlyValue args: FlagDiagnosticChangedEventArgs) { |
| 67 | + let newValue = args.value |
| 68 | + // Handle the diagnostic event value changed... |
| 69 | + } |
| 70 | + |
| 71 | + func mediaDiagnostics(_ mediaDiagnostics: MediaDiagnostics, |
| 72 | + didChangeCameraStartTimedOutValue args: FlagDiagnosticChangedEventArgs) { |
| 73 | + let newValue = args.value |
| 74 | + // Handle the diagnostic event value changed... |
| 75 | + } |
| 76 | + |
| 77 | + func mediaDiagnostics(_ mediaDiagnostics: MediaDiagnostics, |
| 78 | + didChangeSpeakerVolumeIsZeroValue args: FlagDiagnosticChangedEventArgs) { |
| 79 | + let newValue = args.value |
| 80 | + // Handle the diagnostic event value changed... |
| 81 | + } |
| 82 | + |
| 83 | + func mediaDiagnostics(_ mediaDiagnostics: MediaDiagnostics, |
| 84 | + didChangeNoSpeakerDevicesEnumeratedValue args: FlagDiagnosticChangedEventArgs) { |
| 85 | + let newValue = args.value |
| 86 | + // Handle the diagnostic event value changed... |
| 87 | + } |
| 88 | + |
| 89 | + func mediaDiagnostics(_ mediaDiagnostics: MediaDiagnostics, |
| 90 | + didChangeNoMicrophoneDevicesEnumeratedValue args: FlagDiagnosticChangedEventArgs) { |
| 91 | + let newValue = args.value |
| 92 | + // Handle the diagnostic event value changed... |
| 93 | + } |
| 94 | + |
| 95 | + func mediaDiagnostics(_ mediaDiagnostics: MediaDiagnostics, |
| 96 | + didChangeSpeakingWhileMicrophoneIsMutedValue args: FlagDiagnosticChangedEventArgs) { |
| 97 | + let newValue = args.value |
| 98 | + // Handle the diagnostic event value changed... |
| 99 | + } |
| 100 | + |
| 101 | + func mediaDiagnostics(_ mediaDiagnostics: MediaDiagnostics, |
| 102 | + didChangeSpeakerNotFunctioningDeviceInUseValue args: FlagDiagnosticChangedEventArgs) { |
| 103 | + let newValue = args.value |
| 104 | + // Handle the diagnostic event value changed... |
| 105 | + } |
| 106 | + |
| 107 | + func mediaDiagnostics(_ mediaDiagnostics: MediaDiagnostics, |
| 108 | + didChangeMicrophoneNotFunctioningDeviceInUseValue args: FlagDiagnosticChangedEventArgs) { |
| 109 | + let newValue = args.value |
| 110 | + // Handle the diagnostic event value changed... |
| 111 | + } |
| 112 | +} |
| 113 | + |
| 114 | +extension CallObserver: NetworkDiagnosticsDelegate { |
| 115 | + func networkDiagnostics(_ networkDiagnostics: NetworkDiagnostics, |
| 116 | + didChangeNoNetworkValue args: FlagDiagnosticChangedEventArgs) { |
| 117 | + let newValue = args.value |
| 118 | + // Handle the diagnostic event value changed... |
| 119 | + } |
| 120 | + |
| 121 | + func networkDiagnostics(_ networkDiagnostics: NetworkDiagnostics, |
| 122 | + didChangeNetworkReconnectValue args: QualityDiagnosticChangedEventArgs) { |
| 123 | + let newValue = args.value |
| 124 | + // Handle the diagnostic event value changed... |
| 125 | + } |
| 126 | + |
| 127 | + func networkDiagnostics(_ networkDiagnostics: NetworkDiagnostics, |
| 128 | + didChangeNetworkSendQualityValue args: QualityDiagnosticChangedEventArgs) { |
| 129 | + let newValue = args.value |
| 130 | + // Handle the diagnostic event value changed... |
| 131 | + } |
| 132 | + |
| 133 | + func networkDiagnostics(_ networkDiagnostics: NetworkDiagnostics, |
| 134 | + didChangeNetworkReceiveQualityValue args: QualityDiagnosticChangedEventArgs) { |
| 135 | + let newValue = args.value |
| 136 | + // Handle the diagnostic event value changed... |
| 137 | + } |
| 138 | + |
| 139 | + func networkDiagnostics(_ networkDiagnostics: NetworkDiagnostics, |
| 140 | + didChangeNetworkRelaysNotReachableValue args: FlagDiagnosticChangedEventArgs) { |
| 141 | + let newValue = args.value |
| 142 | + // Handle the diagnostic event value changed... |
| 143 | + } |
| 144 | +} |
| 145 | +``` |
| 146 | + |
| 147 | +- Hold a reference to `media` and `network` diagnostics and set delegate object for listening to events. |
| 148 | + |
| 149 | +```swift |
| 150 | +self.mediaDiagnostics = userFacingDiagnostics?.media |
| 151 | +self.networkDiagnostics = userFacingDiagnostics?.network |
| 152 | +self.mediaDiagnostics?.delegate = self.callObserver |
| 153 | +self.networkDiagnostics?.delegate = self.callObserver |
| 154 | +``` |
| 155 | + |
| 156 | +## Get the latest User Facing Diagnostics |
| 157 | + |
| 158 | +- Get the latest diagnostic values that were raised. If we still didn't receive a value for the diagnostic, `nil` or `.unknown` is returned. |
| 159 | + |
| 160 | +```swift |
| 161 | +let lastSpeakerNotFunctionValue = self.mediaDiagnostics.latest.speakerNotFunctioning // Boolean? |
| 162 | +let lastNetworkRelayNotReachableValue = self.networkDiagnostics.latest.networkRelaysNotReachable // Boolean? |
| 163 | +let lastReceiveQualityValue = self.networkDiagnostics.latest.networkReceiveQuality // DiagnosticQuality (.good, .poor, .bad) |
| 164 | +// or .unknown if there isn't a diagnostic for this. |
| 165 | +``` |
0 commit comments