From f1a14f1e3de4445e34dda1a4847457dd6fb50ff5 Mon Sep 17 00:00:00 2001 From: Paul Tagliamonte Date: Tue, 17 Oct 2023 12:55:45 -0400 Subject: [PATCH] Guard all the vaules in the Metrics for `undefined`. (#891) We've seen a few cases where the WebRTC metrics report contains undefined values when the stream hasn't started yet. JavaScript, when we send to the backend, drops `undefined` members of the object, for example: ``` > JSON.stringify({rtc_frames_dropped: undefined}) < '{}' ``` This will fail the backend validation logic and cause an error to get emitted to the front-end reporting the missing key. I don't think this does anything to the session, but it's an error we can avoid by guarding more of the statistics with a || 0. Some of the values had this already, this just adds a few more. Signed-off-by: Paul R. Tagliamonte --- src/lang/std/engineConnection.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lang/std/engineConnection.ts b/src/lang/std/engineConnection.ts index 92abfb063..f3ec96efe 100644 --- a/src/lang/std/engineConnection.ts +++ b/src/lang/std/engineConnection.ts @@ -450,18 +450,18 @@ export class EngineConnection { videoTrackStats.forEach((videoTrackReport) => { if (videoTrackReport.type === 'inbound-rtp') { client_metrics.rtc_frames_decoded = - videoTrackReport.framesDecoded + videoTrackReport.framesDecoded || 0 client_metrics.rtc_frames_dropped = - videoTrackReport.framesDropped + videoTrackReport.framesDropped || 0 client_metrics.rtc_frames_received = - videoTrackReport.framesReceived + videoTrackReport.framesReceived || 0 client_metrics.rtc_frames_per_second = videoTrackReport.framesPerSecond || 0 client_metrics.rtc_freeze_count = videoTrackReport.freezeCount || 0 - client_metrics.rtc_jitter_sec = videoTrackReport.jitter + client_metrics.rtc_jitter_sec = videoTrackReport.jitter || 0.0 client_metrics.rtc_keyframes_decoded = - videoTrackReport.keyFramesDecoded + videoTrackReport.keyFramesDecoded || 0 client_metrics.rtc_total_freezes_duration_sec = videoTrackReport.totalFreezesDuration || 0 } else if (videoTrackReport.type === 'transport') {