monitorStats method

void monitorStats(
  1. WebRTCVideoStats stats, {
  2. required WebRTCAudioStats audioStats,
  3. required dynamic onLevelChanged(
    1. AudioLevel
    ),
  4. required String id,
  5. required bool isMe,
})

Implementation

void monitorStats(
  WebRTCVideoStats stats, {
  required WebRTCAudioStats audioStats,
  required Function(AudioLevel) onLevelChanged,
  required String id,
  required bool isMe,
}) {
  onIceConnectionState = (state) async {
    switch (state) {
      case RTCIceConnectionState.RTCIceConnectionStateConnected:
        if (isMe) {
          final senders = await getSenders();
          stats.addSenders(id, senders);

          audioStats.setSender = AudioStatsParams(
            peerConnection: this,
            callBack: onLevelChanged,
          );
        } else {
          final receivers = await getReceivers();
          stats.addReceivers(id, receivers);

          audioStats.addReceiver(
            AudioStatsParams(
              peerConnection: this,
              callBack: onLevelChanged,
              receivers: receivers,
            ),
          );
        }

        break;
      case RTCIceConnectionState.RTCIceConnectionStateClosed:
        if (isMe) {
          stats.removeSenders();
          audioStats.setSender = null;
        } else {
          stats.removeReceivers(id);
          audioStats.removeReceiver(peerConnectionId);
        }
        break;
      default:
        break;
    }
  };
}