applyRemoteInboundAudioStats function

void applyRemoteInboundAudioStats(
  1. AudioSenderStats stats, {
  2. required Map outbound,
  3. required Map? lookupById(
    1. String id
    ),
})

Copies the remote end's view of our uplink — loss, jitter, round-trip time — from the remote-inbound-rtp entry linked to an outbound-rtp one.

Extracted so the mapping is testable without a live peer connection: it is the exact place the values were being read from the wrong report, and the silence that produced (null -> reported as a perfect 0) hid every speaker's uplink problems in production.

Leaves the fields untouched when there is no linked report yet, so "not known" stays distinguishable from "no loss".

Implementation

void applyRemoteInboundAudioStats(
  AudioSenderStats stats, {
  required Map<dynamic, dynamic> outbound,
  required Map<dynamic, dynamic>? Function(String id) lookupById,
}) {
  final remoteId = getStringValFromReport(outbound, 'remoteId');
  if (remoteId == null || remoteId.isEmpty) return;
  final remote = lookupById(remoteId);
  if (remote == null) return;
  stats.packetsLost = getNumValFromReport(remote, 'packetsLost');
  stats.jitter = getNumValFromReport(remote, 'jitter');
  stats.roundTripTime = getNumValFromReport(remote, 'roundTripTime');
}