From 6d34209cacc7951e132feef3499ab59030036b3d Mon Sep 17 00:00:00 2001 From: eswarclynn Date: Thu, 22 Feb 2024 12:21:05 +0530 Subject: [PATCH] fix: add subscriber video stats to analyics --- .../src/analytics/stats/BaseStatsAnalytics.ts | 5 +++++ .../src/analytics/stats/SubscribeStatsAnalytics.ts | 10 +++++++++- .../hms-video-store/src/analytics/stats/interfaces.ts | 7 +++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/hms-video-store/src/analytics/stats/BaseStatsAnalytics.ts b/packages/hms-video-store/src/analytics/stats/BaseStatsAnalytics.ts index df5ac55f2b..936c249a91 100644 --- a/packages/hms-video-store/src/analytics/stats/BaseStatsAnalytics.ts +++ b/packages/hms-video-store/src/analytics/stats/BaseStatsAnalytics.ts @@ -158,6 +158,11 @@ export abstract class RunningTrackAnalytics { return latestValue - firstValue; } + protected calculateDifferenceAverage(key: keyof TempPublishStats, round = true) { + const avg = this.calculateDifferenceForSample(key) / this.tempStats.length; + return round ? Math.round(avg) : avg; + } + protected calculateInstancesOfHigh(key: keyof TempPublishStats, threshold: number) { const checkStat = this.getLatestStat()[key]; if (typeof checkStat !== 'number') { diff --git a/packages/hms-video-store/src/analytics/stats/SubscribeStatsAnalytics.ts b/packages/hms-video-store/src/analytics/stats/SubscribeStatsAnalytics.ts index 181e77aeaf..e1bbf5cfa7 100644 --- a/packages/hms-video-store/src/analytics/stats/SubscribeStatsAnalytics.ts +++ b/packages/hms-video-store/src/analytics/stats/SubscribeStatsAnalytics.ts @@ -96,7 +96,15 @@ class RunningRemoteTrackAnalytics extends RunningTrackAnalytics { }; if (latestStat.kind === 'video') { - return removeUndefinedFromObject(baseSample); + return removeUndefinedFromObject( + Object.assign(baseSample, { + avg_frames_received_per_sec: this.calculateDifferenceAverage('framesReceived'), + avg_frames_dropped_per_sec: this.calculateDifferenceAverage('framesDropped'), + avg_frames_decoded_per_sec: this.calculateDifferenceAverage('framesDecoded'), + frame_width: this.calculateAverage('frameWidth'), + frame_height: this.calculateAverage('frameHeight'), + }), + ); } else { const audio_concealed_samples = (latestStat.concealedSamples || 0) - diff --git a/packages/hms-video-store/src/analytics/stats/interfaces.ts b/packages/hms-video-store/src/analytics/stats/interfaces.ts index 6d3519ad9b..ad2d239582 100644 --- a/packages/hms-video-store/src/analytics/stats/interfaces.ts +++ b/packages/hms-video-store/src/analytics/stats/interfaces.ts @@ -87,4 +87,11 @@ export interface RemoteVideoSample extends RemoteBaseSample { avg_frames_decoded_per_sec?: number; total_pli_count?: number; total_nack_count?: number; + frame_width?: number; + frame_height?: number; + pause_count?: number; + pause_duration_seconds?: number; + freeze_count?: number; + freeze_duration_seconds?: number; + avg_jitter_buffer_delay?: number; }