From 7c14ea0682445a35e2ec3509d5d92eafe8091ee7 Mon Sep 17 00:00:00 2001 From: Balazs Kreith Date: Fri, 20 Oct 2023 17:31:20 +0300 Subject: [PATCH 1/8] 3.3.0 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 53edc4a..14adb1e 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { "name": "@observertc/client-monitor-js", - "version": "3.2.0", + "version": "3.3.0", "description": "ObserveRTC Client Integration Javascript Library", "main": "lib/index.js", "types": "lib/index.d.ts", "engines": { "node": ">=10" }, - "files":[ + "files": [ "lib" ], "scripts": { From b942459306b48df86dab24c5a05a0727d08244a5 Mon Sep 17 00:00:00 2001 From: Balazs Kreith Date: Fri, 20 Oct 2023 18:56:54 +0300 Subject: [PATCH 2/8] introduce `delta`, and `total` to peer connections and storageStats --- src/detectors/CongestionDetector.ts | 8 ++--- src/entries/PeerConnectionEntryManifest.ts | 42 ++++++++++++++-------- src/entries/StatsEntryInterfaces.ts | 5 +++ src/entries/StatsStorage.ts | 42 ++++++++++++++-------- 4 files changed, 63 insertions(+), 34 deletions(-) diff --git a/src/detectors/CongestionDetector.ts b/src/detectors/CongestionDetector.ts index 2a88a0e..5bdcdc5 100644 --- a/src/detectors/CongestionDetector.ts +++ b/src/detectors/CongestionDetector.ts @@ -68,11 +68,11 @@ export function createCongestionDetector(config: CongestionDetectorConfig & { const peerConnectionStates = new Map(); const isCongested = (now: number, state: PeerConnectionState, peerConnection: PeerConnectionEntry): boolean => { const { - totalInboundPacketsLost = 0, - totalInboundPacketsReceived = 0, + deltaInboundPacketsLost: totalInboundPacketsLost = 0, + deltaInboundPacketsReceived: totalInboundPacketsReceived = 0, avgRttInS = -1, - totalOutboundPacketsSent = 0, - totalOutboundPacketsLost = 0, + deltaOutboundPacketsSent: totalOutboundPacketsSent = 0, + deltaOutboundPacketsLost: totalOutboundPacketsLost = 0, } = peerConnection; if (state.congested !== undefined && (now - state.congested) < config.minDurationThresholdInMs) { diff --git a/src/entries/PeerConnectionEntryManifest.ts b/src/entries/PeerConnectionEntryManifest.ts index 149a3fa..9cbb0e6 100644 --- a/src/entries/PeerConnectionEntryManifest.ts +++ b/src/entries/PeerConnectionEntryManifest.ts @@ -37,11 +37,18 @@ interface InnerOutboundRtpEntry extends OutboundRtpEntry { export class PeerConnectionEntryManifest implements PeerConnectionEntry { - public totalInboundPacketsLost?: number; - public totalInboundPacketsReceived?: number; - public totalOutboundPacketsLost?: number; - public totalOutbounPacketsReceived?: number; - public totalOutboundPacketsSent?: number; + public totalInboundPacketsLost = 0; + public totalInboundPacketsReceived = 0; + public totalOutboundPacketsLost = 0; + public totalOutbounPacketsReceived = 0; + public totalOutboundPacketsSent = 0; + + public deltaInboundPacketsLost?: number; + public deltaInboundPacketsReceived?: number; + public deltaOutboundPacketsLost?: number; + public deltaOutbounPacketsReceived?: number; + public deltaOutboundPacketsSent?: number; + public avgRttInS?: number; public sendingAudioBitrate?: number; public sendingVideoBitrate?: number; @@ -480,11 +487,11 @@ export class PeerConnectionEntryManifest implements PeerConnectionEntry { } private _updateMetrics() { - this.totalInboundPacketsLost = 0; - this.totalInboundPacketsReceived = 0; - this.totalOutboundPacketsLost = 0; - this.totalOutbounPacketsReceived = 0; - this.totalOutboundPacketsSent = 0; + this.deltaInboundPacketsLost = 0; + this.deltaInboundPacketsReceived = 0; + this.deltaOutboundPacketsLost = 0; + this.deltaOutbounPacketsReceived = 0; + this.deltaOutboundPacketsSent = 0; this.sendingAudioBitrate = 0; this.sendingVideoBitrate = 0; this.receivingAudioBitrate = 0; @@ -496,14 +503,18 @@ export class PeerConnectionEntryManifest implements PeerConnectionEntry { } else if (inboundRtpEntry.stats.kind === 'video') { this.receivingVideoBitrate += inboundRtpEntry.receivingBitrate ?? 0; } - this.totalInboundPacketsLost += inboundRtpEntry.lostPackets ?? 0; - this.totalInboundPacketsReceived += inboundRtpEntry.receivedPackets ?? 0; + this.deltaInboundPacketsLost += inboundRtpEntry.lostPackets ?? 0; + this.deltaInboundPacketsReceived += inboundRtpEntry.receivedPackets ?? 0; } for (const remoteInboundRtpEntry of this.remoteInboundRtps()) { - this.totalOutboundPacketsLost += remoteInboundRtpEntry.stats.packetsLost ?? 0; - this.totalOutbounPacketsReceived += remoteInboundRtpEntry.stats.packetsReceived ?? 0; + this.deltaOutboundPacketsLost += remoteInboundRtpEntry.stats.packetsLost ?? 0; + this.deltaOutbounPacketsReceived += remoteInboundRtpEntry.stats.packetsReceived ?? 0; } + this.totalInboundPacketsLost += this.deltaInboundPacketsLost; + this.totalInboundPacketsReceived += this.deltaInboundPacketsReceived; + this.totalOutboundPacketsLost += this.deltaOutboundPacketsLost; + this.totalOutbounPacketsReceived += this.deltaOutbounPacketsReceived; for (const remoteInboundRtpEntry of this.remoteInboundRtps()) { const { roundTripTime } = remoteInboundRtpEntry.stats; @@ -533,9 +544,10 @@ export class PeerConnectionEntryManifest implements PeerConnectionEntry { } else if (outboundRtpEntry.stats.kind === 'video') { this.sendingVideoBitrate += outboundRtpEntry.sendingBitrate ?? 0; } - this.totalOutboundPacketsSent += outboundRtpEntry.sentPackets ?? 0; + this.deltaOutboundPacketsSent += outboundRtpEntry.sentPackets ?? 0; outboundRtpEntry.updateStabilityScore(avgRttInS); } + this.totalOutboundPacketsSent += this.deltaOutboundPacketsSent; this.avgRttInS = avgRttInS; } diff --git a/src/entries/StatsEntryInterfaces.ts b/src/entries/StatsEntryInterfaces.ts index c09cf61..485daae 100644 --- a/src/entries/StatsEntryInterfaces.ts +++ b/src/entries/StatsEntryInterfaces.ts @@ -329,6 +329,11 @@ export interface PeerConnectionEntry { readonly totalOutboundPacketsLost?: number; readonly totalOutbounPacketsReceived?: number; readonly totalOutboundPacketsSent?: number; + readonly deltaInboundPacketsLost?: number; + readonly deltaInboundPacketsReceived?: number; + readonly deltaOutboundPacketsLost?: number; + readonly deltaOutbounPacketsReceived?: number; + readonly deltaOutboundPacketsSent?: number; readonly avgRttInS?: number; readonly sendingAudioBitrate?: number; readonly sendingVideoBitrate?: number; diff --git a/src/entries/StatsStorage.ts b/src/entries/StatsStorage.ts index 864f0f6..88d61fa 100644 --- a/src/entries/StatsStorage.ts +++ b/src/entries/StatsStorage.ts @@ -44,11 +44,18 @@ export class StatsStorage { public sendingVideoBitrate?: number; public receivingAudioBitrate?: number; public receivingVideoBitrate?: number; - public totalInboundPacketsLost?: number; - public totalInboundPacketsReceived?: number; - public totalOutboundPacketsSent?: number; - public totalOutbounPacketsReceived?: number; - public totalOutboundPacketsLost?: number; + + public totalInboundPacketsLost = 0; + public totalInboundPacketsReceived = 0; + public totalOutboundPacketsSent = 0; + public totalOutbounPacketsReceived = 0; + public totalOutboundPacketsLost = 0; + + public deltaInboundPacketsLost?: number; + public deltaInboundPacketsReceived?: number; + public deltaOutboundPacketsSent?: number; + public deltaOutbounPacketsReceived?: number; + public deltaOutboundPacketsLost?: number; public totalAvailableIncomingBitrate?: number; public totalAvailableOutgoingBitrate?: number; public avgRttInS?: number; @@ -447,11 +454,11 @@ export class StatsStorage { this.sendingVideoBitrate = 0; this.receivingAudioBitrate = 0; this.receivingVideoBitrate = 0; - this.totalInboundPacketsLost = 0; - this.totalInboundPacketsReceived = 0; - this.totalOutboundPacketsSent = 0; - this.totalOutbounPacketsReceived = 0; - this.totalOutboundPacketsLost = 0; + this.deltaInboundPacketsLost = 0; + this.deltaInboundPacketsReceived = 0; + this.deltaOutboundPacketsSent = 0; + this.deltaOutbounPacketsReceived = 0; + this.deltaOutboundPacketsLost = 0; this.totalAvailableIncomingBitrate = 0; this.totalAvailableOutgoingBitrate = 0; for (const peerConnectionEntry of this._peerConnections.values()) { @@ -465,12 +472,17 @@ export class StatsStorage { this.sendingVideoBitrate += peerConnectionEntry.sendingVideoBitrate ?? 0; this.receivingAudioBitrate += peerConnectionEntry.receivingAudioBitrate ?? 0; this.receivingVideoBitrate += peerConnectionEntry.receivingVideoBitrate ?? 0; - this.totalInboundPacketsLost += peerConnectionEntry.totalInboundPacketsLost ?? 0; - this.totalInboundPacketsReceived += peerConnectionEntry.totalInboundPacketsReceived ?? 0; - this.totalOutboundPacketsSent += peerConnectionEntry.totalOutboundPacketsSent ?? 0; - this.totalOutbounPacketsReceived += peerConnectionEntry.totalOutbounPacketsReceived ?? 0; - this.totalOutboundPacketsLost += peerConnectionEntry.totalOutboundPacketsLost ?? 0; + this.deltaInboundPacketsLost += peerConnectionEntry.deltaInboundPacketsLost ?? 0; + this.deltaInboundPacketsReceived += peerConnectionEntry.deltaInboundPacketsReceived ?? 0; + this.deltaOutboundPacketsSent += peerConnectionEntry.deltaOutboundPacketsSent ?? 0; + this.deltaOutbounPacketsReceived += peerConnectionEntry.deltaOutbounPacketsReceived ?? 0; + this.deltaOutboundPacketsLost += peerConnectionEntry.deltaOutboundPacketsLost ?? 0; } + this.totalInboundPacketsLost += this.deltaInboundPacketsLost; + this.totalInboundPacketsReceived += this.deltaInboundPacketsReceived; + this.totalOutboundPacketsSent += this.deltaOutboundPacketsSent; + this.totalOutbounPacketsReceived += this.deltaOutbounPacketsReceived; + this.totalOutboundPacketsLost += this.deltaOutboundPacketsLost; this.highestSeenSendingBitrate = Math.max( this.highestSeenSendingBitrate ?? 0, From 281d237ad2f4f8b8f58160c766fabd58a50fb88b Mon Sep 17 00:00:00 2001 From: Balazs Kreith Date: Fri, 20 Oct 2023 19:06:04 +0300 Subject: [PATCH 3/8] add total bytes as well --- src/entries/PeerConnectionEntryManifest.ts | 14 ++++++++++++++ src/entries/StatsEntryInterfaces.ts | 15 ++++++++++----- src/entries/StatsStorage.ts | 9 +++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/entries/PeerConnectionEntryManifest.ts b/src/entries/PeerConnectionEntryManifest.ts index 9cbb0e6..329ae4d 100644 --- a/src/entries/PeerConnectionEntryManifest.ts +++ b/src/entries/PeerConnectionEntryManifest.ts @@ -42,6 +42,10 @@ export class PeerConnectionEntryManifest implements PeerConnectionEntry { public totalOutboundPacketsLost = 0; public totalOutbounPacketsReceived = 0; public totalOutboundPacketsSent = 0; + public totalSentAudioBytes = 0; + public totalSentVideoBytes = 0; + public totalReceivedAudioBytes = 0; + public totalReceivedVideoBytes = 0; public deltaInboundPacketsLost?: number; public deltaInboundPacketsReceived?: number; @@ -505,6 +509,11 @@ export class PeerConnectionEntryManifest implements PeerConnectionEntry { } this.deltaInboundPacketsLost += inboundRtpEntry.lostPackets ?? 0; this.deltaInboundPacketsReceived += inboundRtpEntry.receivedPackets ?? 0; + if (inboundRtpEntry.stats.kind === 'video') { + this.totalReceivedVideoBytes += inboundRtpEntry.stats.bytesReceived ?? 0; + } else if (inboundRtpEntry.stats.kind === 'audio') { + this.totalReceivedAudioBytes += inboundRtpEntry.stats.bytesReceived ?? 0; + } } for (const remoteInboundRtpEntry of this.remoteInboundRtps()) { @@ -546,6 +555,11 @@ export class PeerConnectionEntryManifest implements PeerConnectionEntry { } this.deltaOutboundPacketsSent += outboundRtpEntry.sentPackets ?? 0; outboundRtpEntry.updateStabilityScore(avgRttInS); + if (outboundRtpEntry.stats.kind === 'video') { + this.totalSentAudioBytes += outboundRtpEntry.stats.bytesSent ?? 0; + } else if (outboundRtpEntry.stats.kind === 'audio') { + this.totalSentVideoBytes += outboundRtpEntry.stats.bytesSent ?? 0; + } } this.totalOutboundPacketsSent += this.deltaOutboundPacketsSent; diff --git a/src/entries/StatsEntryInterfaces.ts b/src/entries/StatsEntryInterfaces.ts index 485daae..6e2521a 100644 --- a/src/entries/StatsEntryInterfaces.ts +++ b/src/entries/StatsEntryInterfaces.ts @@ -324,11 +324,16 @@ export interface PeerConnectionEntry { readonly label: string | undefined; readonly events: TypedEvents; - readonly totalInboundPacketsLost?: number; - readonly totalInboundPacketsReceived?: number; - readonly totalOutboundPacketsLost?: number; - readonly totalOutbounPacketsReceived?: number; - readonly totalOutboundPacketsSent?: number; + readonly totalInboundPacketsLost: number; + readonly totalInboundPacketsReceived: number; + readonly totalOutboundPacketsLost: number; + readonly totalOutbounPacketsReceived: number; + readonly totalOutboundPacketsSent: number; + readonly totalSentAudioBytes: number; + readonly totalSentVideoBytes: number; + readonly totalReceivedAudioBytes: number; + readonly totalReceivedVideoBytes: number; + readonly deltaInboundPacketsLost?: number; readonly deltaInboundPacketsReceived?: number; readonly deltaOutboundPacketsLost?: number; diff --git a/src/entries/StatsStorage.ts b/src/entries/StatsStorage.ts index 88d61fa..9996e1b 100644 --- a/src/entries/StatsStorage.ts +++ b/src/entries/StatsStorage.ts @@ -50,6 +50,10 @@ export class StatsStorage { public totalOutboundPacketsSent = 0; public totalOutbounPacketsReceived = 0; public totalOutboundPacketsLost = 0; + public totalSentAudioBytes = 0; + public totalSentVideoBytes = 0; + public totalReceivedAudioBytes = 0; + public totalReceivedVideoBytes = 0; public deltaInboundPacketsLost?: number; public deltaInboundPacketsReceived?: number; @@ -454,6 +458,7 @@ export class StatsStorage { this.sendingVideoBitrate = 0; this.receivingAudioBitrate = 0; this.receivingVideoBitrate = 0; + this.deltaInboundPacketsLost = 0; this.deltaInboundPacketsReceived = 0; this.deltaOutboundPacketsSent = 0; @@ -477,6 +482,10 @@ export class StatsStorage { this.deltaOutboundPacketsSent += peerConnectionEntry.deltaOutboundPacketsSent ?? 0; this.deltaOutbounPacketsReceived += peerConnectionEntry.deltaOutbounPacketsReceived ?? 0; this.deltaOutboundPacketsLost += peerConnectionEntry.deltaOutboundPacketsLost ?? 0; + this.totalSentAudioBytes += peerConnectionEntry.totalSentAudioBytes ?? 0; + this.totalSentVideoBytes += peerConnectionEntry.totalSentVideoBytes ?? 0; + this.totalReceivedAudioBytes += peerConnectionEntry.totalReceivedAudioBytes ?? 0; + this.totalReceivedVideoBytes += peerConnectionEntry.totalReceivedVideoBytes ?? 0; } this.totalInboundPacketsLost += this.deltaInboundPacketsLost; this.totalInboundPacketsReceived += this.deltaInboundPacketsReceived; From 8e5ad1e93bff0d7b5040252ab69e5e03c9c28ac3 Mon Sep 17 00:00:00 2001 From: Balazs Kreith Date: Fri, 20 Oct 2023 19:10:33 +0300 Subject: [PATCH 4/8] typo --- src/entries/PeerConnectionEntryManifest.ts | 10 +++++----- src/entries/StatsEntryInterfaces.ts | 4 ++-- src/entries/StatsStorage.ts | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/entries/PeerConnectionEntryManifest.ts b/src/entries/PeerConnectionEntryManifest.ts index 329ae4d..17818e2 100644 --- a/src/entries/PeerConnectionEntryManifest.ts +++ b/src/entries/PeerConnectionEntryManifest.ts @@ -40,7 +40,7 @@ export class PeerConnectionEntryManifest implements PeerConnectionEntry { public totalInboundPacketsLost = 0; public totalInboundPacketsReceived = 0; public totalOutboundPacketsLost = 0; - public totalOutbounPacketsReceived = 0; + public totalOutboundPacketsReceived = 0; public totalOutboundPacketsSent = 0; public totalSentAudioBytes = 0; public totalSentVideoBytes = 0; @@ -50,7 +50,7 @@ export class PeerConnectionEntryManifest implements PeerConnectionEntry { public deltaInboundPacketsLost?: number; public deltaInboundPacketsReceived?: number; public deltaOutboundPacketsLost?: number; - public deltaOutbounPacketsReceived?: number; + public deltaOutboundPacketsReceived?: number; public deltaOutboundPacketsSent?: number; public avgRttInS?: number; @@ -494,7 +494,7 @@ export class PeerConnectionEntryManifest implements PeerConnectionEntry { this.deltaInboundPacketsLost = 0; this.deltaInboundPacketsReceived = 0; this.deltaOutboundPacketsLost = 0; - this.deltaOutbounPacketsReceived = 0; + this.deltaOutboundPacketsReceived = 0; this.deltaOutboundPacketsSent = 0; this.sendingAudioBitrate = 0; this.sendingVideoBitrate = 0; @@ -518,12 +518,12 @@ export class PeerConnectionEntryManifest implements PeerConnectionEntry { for (const remoteInboundRtpEntry of this.remoteInboundRtps()) { this.deltaOutboundPacketsLost += remoteInboundRtpEntry.stats.packetsLost ?? 0; - this.deltaOutbounPacketsReceived += remoteInboundRtpEntry.stats.packetsReceived ?? 0; + this.deltaOutboundPacketsReceived += remoteInboundRtpEntry.stats.packetsReceived ?? 0; } this.totalInboundPacketsLost += this.deltaInboundPacketsLost; this.totalInboundPacketsReceived += this.deltaInboundPacketsReceived; this.totalOutboundPacketsLost += this.deltaOutboundPacketsLost; - this.totalOutbounPacketsReceived += this.deltaOutbounPacketsReceived; + this.totalOutboundPacketsReceived += this.deltaOutboundPacketsReceived; for (const remoteInboundRtpEntry of this.remoteInboundRtps()) { const { roundTripTime } = remoteInboundRtpEntry.stats; diff --git a/src/entries/StatsEntryInterfaces.ts b/src/entries/StatsEntryInterfaces.ts index 6e2521a..5b0709e 100644 --- a/src/entries/StatsEntryInterfaces.ts +++ b/src/entries/StatsEntryInterfaces.ts @@ -327,7 +327,7 @@ export interface PeerConnectionEntry { readonly totalInboundPacketsLost: number; readonly totalInboundPacketsReceived: number; readonly totalOutboundPacketsLost: number; - readonly totalOutbounPacketsReceived: number; + readonly totalOutboundPacketsReceived: number; readonly totalOutboundPacketsSent: number; readonly totalSentAudioBytes: number; readonly totalSentVideoBytes: number; @@ -337,7 +337,7 @@ export interface PeerConnectionEntry { readonly deltaInboundPacketsLost?: number; readonly deltaInboundPacketsReceived?: number; readonly deltaOutboundPacketsLost?: number; - readonly deltaOutbounPacketsReceived?: number; + readonly deltaOutboundPacketsReceived?: number; readonly deltaOutboundPacketsSent?: number; readonly avgRttInS?: number; readonly sendingAudioBitrate?: number; diff --git a/src/entries/StatsStorage.ts b/src/entries/StatsStorage.ts index 9996e1b..f00c8e7 100644 --- a/src/entries/StatsStorage.ts +++ b/src/entries/StatsStorage.ts @@ -480,7 +480,7 @@ export class StatsStorage { this.deltaInboundPacketsLost += peerConnectionEntry.deltaInboundPacketsLost ?? 0; this.deltaInboundPacketsReceived += peerConnectionEntry.deltaInboundPacketsReceived ?? 0; this.deltaOutboundPacketsSent += peerConnectionEntry.deltaOutboundPacketsSent ?? 0; - this.deltaOutbounPacketsReceived += peerConnectionEntry.deltaOutbounPacketsReceived ?? 0; + this.deltaOutbounPacketsReceived += peerConnectionEntry.deltaOutboundPacketsReceived ?? 0; this.deltaOutboundPacketsLost += peerConnectionEntry.deltaOutboundPacketsLost ?? 0; this.totalSentAudioBytes += peerConnectionEntry.totalSentAudioBytes ?? 0; this.totalSentVideoBytes += peerConnectionEntry.totalSentVideoBytes ?? 0; From ddb6e7fba29b8fe5b37354611dfe0f19dc2d9ad3 Mon Sep 17 00:00:00 2001 From: Balazs Kreith Date: Fri, 20 Oct 2023 19:25:34 +0300 Subject: [PATCH 5/8] add data channel bytes --- src/entries/PeerConnectionEntryManifest.ts | 13 +++++++++++++ src/entries/StatsEntryInterfaces.ts | 5 +++++ src/entries/StatsStorage.ts | 18 ++++++++++++++---- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/entries/PeerConnectionEntryManifest.ts b/src/entries/PeerConnectionEntryManifest.ts index 17818e2..db2e380 100644 --- a/src/entries/PeerConnectionEntryManifest.ts +++ b/src/entries/PeerConnectionEntryManifest.ts @@ -42,6 +42,8 @@ export class PeerConnectionEntryManifest implements PeerConnectionEntry { public totalOutboundPacketsLost = 0; public totalOutboundPacketsReceived = 0; public totalOutboundPacketsSent = 0; + public totalDataChannelBytesSent = 0; + public totalDataChannelBytesReceived = 0; public totalSentAudioBytes = 0; public totalSentVideoBytes = 0; public totalReceivedAudioBytes = 0; @@ -52,6 +54,8 @@ export class PeerConnectionEntryManifest implements PeerConnectionEntry { public deltaOutboundPacketsLost?: number; public deltaOutboundPacketsReceived?: number; public deltaOutboundPacketsSent?: number; + public deltaDataChannelBytesSent?: number; + public deltaDataChannelBytesReceived?: number; public avgRttInS?: number; public sendingAudioBitrate?: number; @@ -500,6 +504,9 @@ export class PeerConnectionEntryManifest implements PeerConnectionEntry { this.sendingVideoBitrate = 0; this.receivingAudioBitrate = 0; this.receivingVideoBitrate = 0; + this.deltaDataChannelBytesSent = 0; + this.deltaDataChannelBytesReceived = 0; + const roundTripTimesInS = []; for (const inboundRtpEntry of this.inboundRtps()) { if (inboundRtpEntry.stats.kind === 'audio') { @@ -563,6 +570,12 @@ export class PeerConnectionEntryManifest implements PeerConnectionEntry { } this.totalOutboundPacketsSent += this.deltaOutboundPacketsSent; + for (const dataChannelEntry of this.dataChannels()) { + this.deltaDataChannelBytesSent += dataChannelEntry.stats.bytesSent ?? 0; + this.deltaDataChannelBytesReceived += dataChannelEntry.stats.bytesReceived ?? 0; + } + this.totalDataChannelBytesReceived += this.deltaDataChannelBytesReceived; + this.totalDataChannelBytesSent += this.deltaDataChannelBytesSent; this.avgRttInS = avgRttInS; } diff --git a/src/entries/StatsEntryInterfaces.ts b/src/entries/StatsEntryInterfaces.ts index 5b0709e..447b2eb 100644 --- a/src/entries/StatsEntryInterfaces.ts +++ b/src/entries/StatsEntryInterfaces.ts @@ -333,12 +333,17 @@ export interface PeerConnectionEntry { readonly totalSentVideoBytes: number; readonly totalReceivedAudioBytes: number; readonly totalReceivedVideoBytes: number; + readonly totalDataChannelBytesSent: number; + readonly totalDataChannelBytesReceived: number; readonly deltaInboundPacketsLost?: number; readonly deltaInboundPacketsReceived?: number; readonly deltaOutboundPacketsLost?: number; readonly deltaOutboundPacketsReceived?: number; readonly deltaOutboundPacketsSent?: number; + readonly deltaDataChannelBytesSent?: number; + readonly deltaDataChannelBytesReceived?: number; + readonly avgRttInS?: number; readonly sendingAudioBitrate?: number; readonly sendingVideoBitrate?: number; diff --git a/src/entries/StatsStorage.ts b/src/entries/StatsStorage.ts index f00c8e7..db01433 100644 --- a/src/entries/StatsStorage.ts +++ b/src/entries/StatsStorage.ts @@ -50,6 +50,8 @@ export class StatsStorage { public totalOutboundPacketsSent = 0; public totalOutbounPacketsReceived = 0; public totalOutboundPacketsLost = 0; + public totalDataChannelBytesSent = 0; + public totalDataChannelBytesReceived = 0; public totalSentAudioBytes = 0; public totalSentVideoBytes = 0; public totalReceivedAudioBytes = 0; @@ -60,6 +62,8 @@ export class StatsStorage { public deltaOutboundPacketsSent?: number; public deltaOutbounPacketsReceived?: number; public deltaOutboundPacketsLost?: number; + public deltaDataChannelBytesSent?: number; + public deltaDataChannelBytesReceived?: number; public totalAvailableIncomingBitrate?: number; public totalAvailableOutgoingBitrate?: number; public avgRttInS?: number; @@ -464,6 +468,8 @@ export class StatsStorage { this.deltaOutboundPacketsSent = 0; this.deltaOutbounPacketsReceived = 0; this.deltaOutboundPacketsLost = 0; + this.deltaDataChannelBytesSent = 0; + this.deltaDataChannelBytesReceived = 0; this.totalAvailableIncomingBitrate = 0; this.totalAvailableOutgoingBitrate = 0; for (const peerConnectionEntry of this._peerConnections.values()) { @@ -477,21 +483,25 @@ export class StatsStorage { this.sendingVideoBitrate += peerConnectionEntry.sendingVideoBitrate ?? 0; this.receivingAudioBitrate += peerConnectionEntry.receivingAudioBitrate ?? 0; this.receivingVideoBitrate += peerConnectionEntry.receivingVideoBitrate ?? 0; + this.deltaDataChannelBytesSent += peerConnectionEntry.deltaDataChannelBytesSent ?? 0; + this.deltaDataChannelBytesReceived += peerConnectionEntry.deltaDataChannelBytesReceived ?? 0; this.deltaInboundPacketsLost += peerConnectionEntry.deltaInboundPacketsLost ?? 0; this.deltaInboundPacketsReceived += peerConnectionEntry.deltaInboundPacketsReceived ?? 0; this.deltaOutboundPacketsSent += peerConnectionEntry.deltaOutboundPacketsSent ?? 0; this.deltaOutbounPacketsReceived += peerConnectionEntry.deltaOutboundPacketsReceived ?? 0; this.deltaOutboundPacketsLost += peerConnectionEntry.deltaOutboundPacketsLost ?? 0; - this.totalSentAudioBytes += peerConnectionEntry.totalSentAudioBytes ?? 0; - this.totalSentVideoBytes += peerConnectionEntry.totalSentVideoBytes ?? 0; - this.totalReceivedAudioBytes += peerConnectionEntry.totalReceivedAudioBytes ?? 0; - this.totalReceivedVideoBytes += peerConnectionEntry.totalReceivedVideoBytes ?? 0; } this.totalInboundPacketsLost += this.deltaInboundPacketsLost; this.totalInboundPacketsReceived += this.deltaInboundPacketsReceived; this.totalOutboundPacketsSent += this.deltaOutboundPacketsSent; this.totalOutbounPacketsReceived += this.deltaOutbounPacketsReceived; this.totalOutboundPacketsLost += this.deltaOutboundPacketsLost; + this.totalDataChannelBytesSent += this.deltaDataChannelBytesSent; + this.totalDataChannelBytesReceived += this.deltaDataChannelBytesReceived; + this.totalSentAudioBytes += this.sendingAudioBitrate; + this.totalSentVideoBytes += this.sendingVideoBitrate; + this.totalReceivedAudioBytes += this.receivingAudioBitrate; + this.totalReceivedVideoBytes += this.receivingVideoBitrate; this.highestSeenSendingBitrate = Math.max( this.highestSeenSendingBitrate ?? 0, From 59db6de0e0fa40d9a50b8fe2f151aedd1c625549 Mon Sep 17 00:00:00 2001 From: Balazs Kreith Date: Fri, 20 Oct 2023 20:25:51 +0300 Subject: [PATCH 6/8] save --- src/entries/PeerConnectionEntryManifest.ts | 27 ++++++++++++++-------- src/entries/StatsEntryInterfaces.ts | 4 ++++ src/entries/StatsStorage.ts | 21 +++++++++++++---- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/entries/PeerConnectionEntryManifest.ts b/src/entries/PeerConnectionEntryManifest.ts index db2e380..f90da62 100644 --- a/src/entries/PeerConnectionEntryManifest.ts +++ b/src/entries/PeerConnectionEntryManifest.ts @@ -56,6 +56,11 @@ export class PeerConnectionEntryManifest implements PeerConnectionEntry { public deltaOutboundPacketsSent?: number; public deltaDataChannelBytesSent?: number; public deltaDataChannelBytesReceived?: number; + public deltaReceivedAudioBytes?: number; + public deltaReceivedVideoBytes?: number; + public deltaSentAudioBytes?: number; + public deltaSentVideoBytes?: number; + public avgRttInS?: number; public sendingAudioBitrate?: number; @@ -506,21 +511,22 @@ export class PeerConnectionEntryManifest implements PeerConnectionEntry { this.receivingVideoBitrate = 0; this.deltaDataChannelBytesSent = 0; this.deltaDataChannelBytesReceived = 0; + this.deltaReceivedAudioBytes = 0; + this.deltaReceivedVideoBytes = 0; + this.deltaSentAudioBytes = 0; + this.deltaSentVideoBytes = 0; const roundTripTimesInS = []; for (const inboundRtpEntry of this.inboundRtps()) { if (inboundRtpEntry.stats.kind === 'audio') { this.receivingAudioBitrate += inboundRtpEntry.receivingBitrate ?? 0; + this.deltaReceivedAudioBytes += inboundRtpEntry?.stats?.bytesReceived ?? 0; } else if (inboundRtpEntry.stats.kind === 'video') { this.receivingVideoBitrate += inboundRtpEntry.receivingBitrate ?? 0; + this.deltaReceivedVideoBytes += inboundRtpEntry?.stats?.bytesReceived ?? 0; } this.deltaInboundPacketsLost += inboundRtpEntry.lostPackets ?? 0; this.deltaInboundPacketsReceived += inboundRtpEntry.receivedPackets ?? 0; - if (inboundRtpEntry.stats.kind === 'video') { - this.totalReceivedVideoBytes += inboundRtpEntry.stats.bytesReceived ?? 0; - } else if (inboundRtpEntry.stats.kind === 'audio') { - this.totalReceivedAudioBytes += inboundRtpEntry.stats.bytesReceived ?? 0; - } } for (const remoteInboundRtpEntry of this.remoteInboundRtps()) { @@ -531,6 +537,8 @@ export class PeerConnectionEntryManifest implements PeerConnectionEntry { this.totalInboundPacketsReceived += this.deltaInboundPacketsReceived; this.totalOutboundPacketsLost += this.deltaOutboundPacketsLost; this.totalOutboundPacketsReceived += this.deltaOutboundPacketsReceived; + this.totalReceivedAudioBytes += this.deltaReceivedAudioBytes; + this.totalReceivedVideoBytes += this.deltaReceivedVideoBytes; for (const remoteInboundRtpEntry of this.remoteInboundRtps()) { const { roundTripTime } = remoteInboundRtpEntry.stats; @@ -557,18 +565,17 @@ export class PeerConnectionEntryManifest implements PeerConnectionEntry { for (const outboundRtpEntry of this._outboundRtps.values()) { if (outboundRtpEntry.stats.kind === 'audio') { this.sendingAudioBitrate += outboundRtpEntry.sendingBitrate ?? 0; + this.deltaSentAudioBytes += outboundRtpEntry?.stats?.bytesSent ?? 0; } else if (outboundRtpEntry.stats.kind === 'video') { this.sendingVideoBitrate += outboundRtpEntry.sendingBitrate ?? 0; + this.deltaSentVideoBytes += outboundRtpEntry?.stats?.bytesSent ?? 0; } this.deltaOutboundPacketsSent += outboundRtpEntry.sentPackets ?? 0; outboundRtpEntry.updateStabilityScore(avgRttInS); - if (outboundRtpEntry.stats.kind === 'video') { - this.totalSentAudioBytes += outboundRtpEntry.stats.bytesSent ?? 0; - } else if (outboundRtpEntry.stats.kind === 'audio') { - this.totalSentVideoBytes += outboundRtpEntry.stats.bytesSent ?? 0; - } } this.totalOutboundPacketsSent += this.deltaOutboundPacketsSent; + this.totalSentAudioBytes += this.deltaSentAudioBytes; + this.totalSentVideoBytes += this.deltaSentVideoBytes; for (const dataChannelEntry of this.dataChannels()) { this.deltaDataChannelBytesSent += dataChannelEntry.stats.bytesSent ?? 0; diff --git a/src/entries/StatsEntryInterfaces.ts b/src/entries/StatsEntryInterfaces.ts index 447b2eb..ec6210e 100644 --- a/src/entries/StatsEntryInterfaces.ts +++ b/src/entries/StatsEntryInterfaces.ts @@ -341,6 +341,10 @@ export interface PeerConnectionEntry { readonly deltaOutboundPacketsLost?: number; readonly deltaOutboundPacketsReceived?: number; readonly deltaOutboundPacketsSent?: number; + readonly deltaSentAudioBytes?: number; + readonly deltaSentVideoBytes?: number; + readonly deltaReceivedAudioBytes?: number; + readonly deltaReceivedVideoBytes?: number; readonly deltaDataChannelBytesSent?: number; readonly deltaDataChannelBytesReceived?: number; diff --git a/src/entries/StatsStorage.ts b/src/entries/StatsStorage.ts index db01433..03ab82d 100644 --- a/src/entries/StatsStorage.ts +++ b/src/entries/StatsStorage.ts @@ -64,6 +64,10 @@ export class StatsStorage { public deltaOutboundPacketsLost?: number; public deltaDataChannelBytesSent?: number; public deltaDataChannelBytesReceived?: number; + public deltaSentAudioBytes?: number; + public deltaSentVideoBytes?: number; + public deltaReceivedAudioBytes?: number; + public deltaReceivedVideoBytes?: number; public totalAvailableIncomingBitrate?: number; public totalAvailableOutgoingBitrate?: number; public avgRttInS?: number; @@ -470,6 +474,10 @@ export class StatsStorage { this.deltaOutboundPacketsLost = 0; this.deltaDataChannelBytesSent = 0; this.deltaDataChannelBytesReceived = 0; + this.deltaSentAudioBytes = 0; + this.deltaSentVideoBytes = 0; + this.deltaReceivedAudioBytes = 0; + this.deltaReceivedVideoBytes = 0; this.totalAvailableIncomingBitrate = 0; this.totalAvailableOutgoingBitrate = 0; for (const peerConnectionEntry of this._peerConnections.values()) { @@ -490,6 +498,11 @@ export class StatsStorage { this.deltaOutboundPacketsSent += peerConnectionEntry.deltaOutboundPacketsSent ?? 0; this.deltaOutbounPacketsReceived += peerConnectionEntry.deltaOutboundPacketsReceived ?? 0; this.deltaOutboundPacketsLost += peerConnectionEntry.deltaOutboundPacketsLost ?? 0; + + this.deltaSentAudioBytes += peerConnectionEntry.deltaSentAudioBytes ?? 0; + this.deltaSentVideoBytes += peerConnectionEntry.deltaSentVideoBytes ?? 0; + this.deltaReceivedAudioBytes += peerConnectionEntry.deltaReceivedAudioBytes ?? 0; + this.deltaReceivedVideoBytes += peerConnectionEntry.deltaReceivedVideoBytes ?? 0; } this.totalInboundPacketsLost += this.deltaInboundPacketsLost; this.totalInboundPacketsReceived += this.deltaInboundPacketsReceived; @@ -498,10 +511,10 @@ export class StatsStorage { this.totalOutboundPacketsLost += this.deltaOutboundPacketsLost; this.totalDataChannelBytesSent += this.deltaDataChannelBytesSent; this.totalDataChannelBytesReceived += this.deltaDataChannelBytesReceived; - this.totalSentAudioBytes += this.sendingAudioBitrate; - this.totalSentVideoBytes += this.sendingVideoBitrate; - this.totalReceivedAudioBytes += this.receivingAudioBitrate; - this.totalReceivedVideoBytes += this.receivingVideoBitrate; + this.totalSentAudioBytes += this.deltaSentAudioBytes; + this.totalSentVideoBytes += this.deltaSentVideoBytes; + this.totalReceivedAudioBytes += this.deltaReceivedAudioBytes; + this.totalReceivedVideoBytes += this.deltaReceivedVideoBytes; this.highestSeenSendingBitrate = Math.max( this.highestSeenSendingBitrate ?? 0, From 082dcd98f14983bb827a8c2406d7f2b932c98a61 Mon Sep 17 00:00:00 2001 From: Balazs Kreith Date: Fri, 20 Oct 2023 21:42:17 +0300 Subject: [PATCH 7/8] save --- src/entries/PeerConnectionEntryManifest.ts | 10 ++++++---- src/entries/StatsEntryInterfaces.ts | 2 ++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/entries/PeerConnectionEntryManifest.ts b/src/entries/PeerConnectionEntryManifest.ts index f90da62..5aeb5a3 100644 --- a/src/entries/PeerConnectionEntryManifest.ts +++ b/src/entries/PeerConnectionEntryManifest.ts @@ -286,6 +286,7 @@ export class PeerConnectionEntryManifest implements PeerConnectionEntry { entry.avgJitterBufferDelayInMs = (((stats.jitterBufferDelay ?? 0) - (entry.stats.jitterBufferDelay ?? 0)) / ((Math.max(stats.jitterBufferEmittedCount ?? 1, 1)) - (entry.stats.jitterBufferEmittedCount ?? 0))) * 1000.0; entry.receivedPackets = (stats.packetsReceived ?? 0) - (entry.stats.packetsReceived ?? 0); entry.receivingBitrate = (((stats.bytesReceived ?? 0) - (entry.stats.bytesReceived ?? 0)) * 8) / elapsedTimeInSec; + entry.receivedBytes = ((stats.bytesReceived ?? 0) - (entry.stats.bytesReceived ?? 0)); entry.lostPackets = (stats.packetsLost ?? 0) - (entry.stats.packetsLost ?? 0); entry.receivedFrames = (stats.framesReceived ?? 0) - (entry.stats.framesReceived ?? 0); entry.decodedFrames = (stats.framesDecoded ?? 0) - (entry.stats.framesDecoded ?? 0); @@ -329,6 +330,7 @@ export class PeerConnectionEntryManifest implements PeerConnectionEntry { } const elapsedTimeInSec = (stats.timestamp - entry.stats.timestamp) / 1000.0; entry.sendingBitrate = (((stats.bytesSent ?? 0) - (entry.stats.bytesSent ?? 0)) * 8) / elapsedTimeInSec; + entry.sentBytes = ((stats.bytesSent ?? 0) - (entry.stats.bytesSent ?? 0)); entry.sentPackets = (stats.packetsSent ?? 0) - (entry.stats.packetsSent ?? 0); entry.stats = stats; entry.visited = true; @@ -520,10 +522,10 @@ export class PeerConnectionEntryManifest implements PeerConnectionEntry { for (const inboundRtpEntry of this.inboundRtps()) { if (inboundRtpEntry.stats.kind === 'audio') { this.receivingAudioBitrate += inboundRtpEntry.receivingBitrate ?? 0; - this.deltaReceivedAudioBytes += inboundRtpEntry?.stats?.bytesReceived ?? 0; + this.deltaReceivedAudioBytes += inboundRtpEntry.receivedBytes ?? 0; } else if (inboundRtpEntry.stats.kind === 'video') { this.receivingVideoBitrate += inboundRtpEntry.receivingBitrate ?? 0; - this.deltaReceivedVideoBytes += inboundRtpEntry?.stats?.bytesReceived ?? 0; + this.deltaReceivedVideoBytes += inboundRtpEntry.receivedBytes ?? 0; } this.deltaInboundPacketsLost += inboundRtpEntry.lostPackets ?? 0; this.deltaInboundPacketsReceived += inboundRtpEntry.receivedPackets ?? 0; @@ -565,10 +567,10 @@ export class PeerConnectionEntryManifest implements PeerConnectionEntry { for (const outboundRtpEntry of this._outboundRtps.values()) { if (outboundRtpEntry.stats.kind === 'audio') { this.sendingAudioBitrate += outboundRtpEntry.sendingBitrate ?? 0; - this.deltaSentAudioBytes += outboundRtpEntry?.stats?.bytesSent ?? 0; + this.deltaSentAudioBytes += outboundRtpEntry.sentBytes ?? 0; } else if (outboundRtpEntry.stats.kind === 'video') { this.sendingVideoBitrate += outboundRtpEntry.sendingBitrate ?? 0; - this.deltaSentVideoBytes += outboundRtpEntry?.stats?.bytesSent ?? 0; + this.deltaSentVideoBytes += outboundRtpEntry.sentBytes ?? 0; } this.deltaOutboundPacketsSent += outboundRtpEntry.sentPackets ?? 0; outboundRtpEntry.updateStabilityScore(avgRttInS); diff --git a/src/entries/StatsEntryInterfaces.ts b/src/entries/StatsEntryInterfaces.ts index ec6210e..fce8cb5 100644 --- a/src/entries/StatsEntryInterfaces.ts +++ b/src/entries/StatsEntryInterfaces.ts @@ -68,6 +68,7 @@ export interface InboundRtpEntry extends ReceivedRtpStreamEntry, StatsEntryAbs { score?: number, avgJitterBufferDelayInMs?: number, receivingBitrate?: number, + receivedBytes?: number, lostPackets?: number, receivedPackets?: number, receivedFrames?: number, @@ -107,6 +108,7 @@ export interface OutboundRtpEntry extends SenderRtpStreamEntry, StatsEntryAbs { // calculated fields score?: number; sendingBitrate?: number, + sentBytes?: number, sentPackets?: number, /** * Gets the SSRC of the Rtp session From 7a34132b145a8d5c37a674f4b5ad1fa4950fa05f Mon Sep 17 00:00:00 2001 From: Balazs Kreith Date: Sat, 21 Oct 2023 08:26:17 +0300 Subject: [PATCH 8/8] filter out negative values --- src/entries/PeerConnectionEntryManifest.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/entries/PeerConnectionEntryManifest.ts b/src/entries/PeerConnectionEntryManifest.ts index 5aeb5a3..9d54a9e 100644 --- a/src/entries/PeerConnectionEntryManifest.ts +++ b/src/entries/PeerConnectionEntryManifest.ts @@ -329,8 +329,8 @@ export class PeerConnectionEntryManifest implements PeerConnectionEntry { this._emitter.emit('outbound-rtp-added', entry); } const elapsedTimeInSec = (stats.timestamp - entry.stats.timestamp) / 1000.0; + entry.sentBytes = Math.max(0, ((stats.bytesSent ?? 0) - (entry.stats.bytesSent ?? 0))); entry.sendingBitrate = (((stats.bytesSent ?? 0) - (entry.stats.bytesSent ?? 0)) * 8) / elapsedTimeInSec; - entry.sentBytes = ((stats.bytesSent ?? 0) - (entry.stats.bytesSent ?? 0)); entry.sentPackets = (stats.packetsSent ?? 0) - (entry.stats.packetsSent ?? 0); entry.stats = stats; entry.visited = true; @@ -343,7 +343,7 @@ export class PeerConnectionEntryManifest implements PeerConnectionEntry { this._remoteInboundRtps.set(stats.id, entry); this._emitter.emit('remote-inbound-rtp-added', entry); } - entry.receivedPackets = (stats.packetsReceived ?? 0) - (entry.stats.packetsReceived ?? 0); + entry.receivedPackets = Math.max(0, (stats.packetsReceived ?? 0) - (entry.stats.packetsReceived ?? 0)); entry.lostPackets = (stats.packetsLost ?? 0) - (entry.stats.packetsLost ?? 0); entry.stats = stats; entry.visited = true; @@ -544,21 +544,21 @@ export class PeerConnectionEntryManifest implements PeerConnectionEntry { for (const remoteInboundRtpEntry of this.remoteInboundRtps()) { const { roundTripTime } = remoteInboundRtpEntry.stats; - if (roundTripTime) { + if (roundTripTime && 0 < roundTripTime) { roundTripTimesInS.push(roundTripTime) } } for (const remoteOutboundRtp of this.remoteOutboundRtps()) { const { roundTripTime } = remoteOutboundRtp.stats; - if (roundTripTime) { + if (roundTripTime && 0 < roundTripTime) { roundTripTimesInS.push(roundTripTime) } } for (const iceCandidatePair of this.iceCandidatePairs()) { const { currentRoundTripTime } = iceCandidatePair.stats; - if (currentRoundTripTime) { + if (currentRoundTripTime && 0 < currentRoundTripTime) { roundTripTimesInS.push(currentRoundTripTime) } }