in src/statscollector/StatsCollector.ts [306:369]
private processRawMetricReports(rawMetricReports: RawMetricReport[]): void {
this.clientMetricReport.currentSsrcs = {};
const timeStamp = Date.now();
for (const rawMetricReport of rawMetricReports) {
if (this.isVideoSourceMetricReport(rawMetricReport)) {
// Video source metrics will be added to all uplink video streams,
// so this will be handled after all uplink metrics are processed.
continue;
}
const isStream = this.isStreamRawMetricReport(rawMetricReport);
if (isStream) {
const existingStreamMetricReport = this.clientMetricReport.streamMetricReports[
Number(rawMetricReport.ssrc)
];
if (!existingStreamMetricReport) {
const streamMetricReport = new StreamMetricReport();
streamMetricReport.mediaType = this.getMediaType(rawMetricReport);
streamMetricReport.direction = this.getDirectionType(rawMetricReport);
if (
streamMetricReport.mediaType === MediaType.VIDEO &&
streamMetricReport.direction === Direction.UPSTREAM
) {
streamMetricReport.streamId = this.videoStreamIndex.sendVideoStreamIdFromRid(
rawMetricReport.rid
);
} else if (!this.videoStreamIndex.allStreams().empty()) {
streamMetricReport.streamId = this.videoStreamIndex.streamIdForSSRC(
Number(rawMetricReport.ssrc)
);
/* istanbul ignore else */
if (this.videoStreamIndex.groupIdForSSRC !== undefined) {
streamMetricReport.groupId = this.videoStreamIndex.groupIdForSSRC(
Number(rawMetricReport.ssrc)
);
}
}
this.clientMetricReport.streamMetricReports[
Number(rawMetricReport.ssrc)
] = streamMetricReport;
} else {
// Update stream ID in case we have overridden it locally in the case of remote video
// updates completed without a negotiation
if (
existingStreamMetricReport.mediaType === MediaType.VIDEO &&
existingStreamMetricReport.direction === Direction.UPSTREAM
) {
existingStreamMetricReport.streamId = this.videoStreamIndex.sendVideoStreamIdFromRid(
rawMetricReport.rid
);
} else {
existingStreamMetricReport.streamId = this.videoStreamIndex.streamIdForSSRC(
Number(rawMetricReport.ssrc)
);
}
}
this.clientMetricReport.currentSsrcs[Number(rawMetricReport.ssrc)] = 1;
}
this.updateMetricValues(rawMetricReport, isStream);
}
this.clientMetricReport.removeDestroyedSsrcs();
this.clientMetricReport.previousTimestampMs = this.clientMetricReport.currentTimestampMs;
this.clientMetricReport.currentTimestampMs = timeStamp;
this.clientMetricReport.print();
}