getSenderStats method

Future<List<VideoSenderStats>> getSenderStats()

Implementation

Future<List<VideoSenderStats>> getSenderStats() async {
  if (sender == null) {
    return [];
  }

  final stats = await sender!.getStats();
  List<VideoSenderStats> items = [];
  for (var v in stats) {
    if (v.type == 'outbound-rtp') {
      VideoSenderStats vs = VideoSenderStats(v.id, v.timestamp);
      vs.frameHeight = getNumValFromReport(v.values, 'frameHeight');
      vs.frameWidth = getNumValFromReport(v.values, 'frameWidth');
      vs.framesPerSecond = getNumValFromReport(v.values, 'framesPerSecond');
      vs.firCount = getNumValFromReport(v.values, 'firCount');
      vs.pliCount = getNumValFromReport(v.values, 'pliCount');
      vs.nackCount = getNumValFromReport(v.values, 'nackCount');
      vs.packetsSent = getNumValFromReport(v.values, 'packetsSent');
      vs.bytesSent = getNumValFromReport(v.values, 'bytesSent');
      vs.framesSent = getNumValFromReport(v.values, 'framesSent');
      vs.rid = getStringValFromReport(v.values, 'rid');
      vs.encoderImplementation =
          getStringValFromReport(v.values, 'encoderImplementation');
      vs.retransmittedPacketsSent =
          getNumValFromReport(v.values, 'retransmittedPacketsSent');
      vs.qualityLimitationReason =
          getStringValFromReport(v.values, 'qualityLimitationReason');
      vs.qualityLimitationResolutionChanges =
          getNumValFromReport(v.values, 'qualityLimitationResolutionChanges');

      // locate the appropriate remote-inbound-rtp item
      final remoteId = getStringValFromReport(v.values, 'remoteId');
      final r = stats.firstWhereOrNull((element) => element.id == remoteId);
      if (r != null) {
        vs.jitter = getNumValFromReport(r.values, 'jitter');
        vs.packetsLost = getNumValFromReport(r.values, 'packetsLost');
        vs.roundTripTime = getNumValFromReport(r.values, 'roundTripTime');
      }
      final c = stats.firstWhereOrNull((element) => element.type == 'codec');
      if (c != null) {
        vs.mimeType = getStringValFromReport(c.values, 'mimeType');
        vs.payloadType = getNumValFromReport(c.values, 'payloadType');
        vs.channels = getNumValFromReport(c.values, 'channels');
        vs.clockRate = getNumValFromReport(c.values, 'clockRate');
      }
      items.add(vs);
    }
  }
  return items;
}