getReceiverStats method

Future<AudioReceiverStats?> getReceiverStats()

Implementation

Future<AudioReceiverStats?> getReceiverStats() async {
  if (receiver == null) {
    return null;
  }

  final stats = await receiver!.getStats();
  AudioReceiverStats? receiverStats;
  for (var v in stats) {
    if (v.type == 'inbound-rtp') {
      receiverStats ??= AudioReceiverStats(v.id, v.timestamp);

      receiverStats.jitter = getNumValFromReport(v.values, 'jitter');
      receiverStats.packetsLost =
          getNumValFromReport(v.values, 'packetsLost');
      receiverStats.jitterBufferDelay =
          getNumValFromReport(v.values, 'jitterBufferDelay');
      receiverStats.bytesReceived =
          getNumValFromReport(v.values, 'bytesReceived');
      receiverStats.packetsReceived =
          getNumValFromReport(v.values, 'packetsReceived');
      receiverStats.concealedSamples =
          getNumValFromReport(v.values, 'concealedSamples');
      receiverStats.concealmentEvents =
          getNumValFromReport(v.values, 'concealmentEvents');
      receiverStats.silentConcealedSamples =
          getNumValFromReport(v.values, 'silentConcealedSamples');
      receiverStats.silentConcealmentEvents =
          getNumValFromReport(v.values, 'silentConcealmentEvents');
      receiverStats.totalAudioEnergy =
          getNumValFromReport(v.values, 'totalAudioEnergy');
      receiverStats.totalSamplesDuration =
          getNumValFromReport(v.values, 'totalSamplesDuration');

      final c = stats.firstWhereOrNull((element) => element.type == 'codec');
      if (c != null) {
        receiverStats.mimeType = getStringValFromReport(c.values, 'mimeType');
        receiverStats.payloadType =
            getNumValFromReport(c.values, 'payloadType');
        receiverStats.channels = getNumValFromReport(c.values, 'channels');
        receiverStats.clockRate = getNumValFromReport(c.values, 'clockRate');
      }
      break;
    }
  }
  return receiverStats;
}