diff --git a/packages/hms-video-store/src/analytics/stats/BaseStatsAnalytics.ts b/packages/hms-video-store/src/analytics/stats/BaseStatsAnalytics.ts index 936c249a91..480ffba9f5 100644 --- a/packages/hms-video-store/src/analytics/stats/BaseStatsAnalytics.ts +++ b/packages/hms-video-store/src/analytics/stats/BaseStatsAnalytics.ts @@ -68,7 +68,7 @@ export abstract class BaseStatsAnalytics { protected abstract handleStatsUpdate(hmsStats: HMSWebrtcStats): void; } -type TempPublishStats = HMSTrackStats & { availableOutgoingBitrate?: number }; +type TempPublishStats = HMSTrackStats & { availableOutgoingBitrate?: number; calculatedJitterBufferDelay?: number }; export abstract class RunningTrackAnalytics { readonly sampleWindowSize: number; diff --git a/packages/hms-video-store/src/analytics/stats/SubscribeStatsAnalytics.ts b/packages/hms-video-store/src/analytics/stats/SubscribeStatsAnalytics.ts index e1bbf5cfa7..fe84d5230b 100644 --- a/packages/hms-video-store/src/analytics/stats/SubscribeStatsAnalytics.ts +++ b/packages/hms-video-store/src/analytics/stats/SubscribeStatsAnalytics.ts @@ -49,8 +49,12 @@ export class SubscribeStatsAnalytics extends BaseStatsAnalytics { Object.keys(remoteTracksStats).forEach(trackID => { const trackStats = remoteTracksStats[trackID]; const track = this.store.getTrackById(trackID); + const calculatedJitterBufferDelay = + trackStats.jitterBufferDelay && + trackStats.jitterBufferEmittedCount && + trackStats.jitterBufferDelay / trackStats.jitterBufferEmittedCount; if (this.trackAnalytics.has(trackID)) { - this.trackAnalytics.get(trackID)?.pushTempStat({ ...trackStats }); + this.trackAnalytics.get(trackID)?.pushTempStat({ ...trackStats, calculatedJitterBufferDelay }); } else { if (track) { const trackAnalytics = new RunningRemoteTrackAnalytics({ @@ -59,7 +63,7 @@ export class SubscribeStatsAnalytics extends BaseStatsAnalytics { ssrc: trackStats.ssrc.toString(), kind: trackStats.kind, }); - trackAnalytics.pushTempStat({ ...trackStats }); + trackAnalytics.pushTempStat({ ...trackStats, calculatedJitterBufferDelay }); this.trackAnalytics.set(trackID, trackAnalytics); } } @@ -103,6 +107,11 @@ class RunningRemoteTrackAnalytics extends RunningTrackAnalytics { avg_frames_decoded_per_sec: this.calculateDifferenceAverage('framesDecoded'), frame_width: this.calculateAverage('frameWidth'), frame_height: this.calculateAverage('frameHeight'), + pause_count: this.calculateDifferenceForSample('pauseCount'), + pause_duration_seconds: this.calculateDifferenceForSample('totalPausesDuration'), + freeze_count: this.calculateDifferenceForSample('freezeCount'), + freeze_duration_seconds: this.calculateDifferenceForSample('totalFreezesDuration'), + avg_jitter_buffer_delay: this.calculateAverage('calculatedJitterBufferDelay'), }), ); } else { diff --git a/packages/hms-video-store/src/interfaces/webrtc-stats.ts b/packages/hms-video-store/src/interfaces/webrtc-stats.ts index 44b8631c1e..b1487169aa 100644 --- a/packages/hms-video-store/src/interfaces/webrtc-stats.ts +++ b/packages/hms-video-store/src/interfaces/webrtc-stats.ts @@ -50,6 +50,12 @@ export interface MissingInboundStats extends RTCInboundRtpStreamStats, MissingCo fecPacketsDiscarded?: number; fecPacketsReceived?: number; totalSamplesDuration?: number; + pauseCount?: number; + totalPausesDuration?: number; + freezeCount?: number; + totalFreezesDuration?: number; + jitterBufferDelay?: number; + jitterBufferEmittedCount?: number; } export type PeerConnectionType = 'publish' | 'subscribe';