@observertc/observer-js 0.30.2-beta → 0.30.4-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -75,6 +75,8 @@ export class ObservedInboundTrack<Kind extends MediaKind> extends EventEmitter {
75
75
 
76
76
  return new ObservedInboundTrack<K>(model, peerConnection, storageProvider);
77
77
  }
78
+
79
+ public created = Date.now();
78
80
 
79
81
  private readonly _stats = new Map<number, ObservedInboundTrackStats<Kind>>();
80
82
  private readonly _execute = createSingleExecutor();
@@ -82,16 +84,27 @@ export class ObservedInboundTrack<Kind extends MediaKind> extends EventEmitter {
82
84
  private _closed = false;
83
85
  private _updated = Date.now();
84
86
  private _remoteOutboundTrack?: ObservedOutboundTrack<Kind>;
85
- public bitrate = -1;
86
- public rttInMs = -1;
87
- public lostPackets = 0;
88
- public receivedPackets = 0;
89
- public receivedFrames = 0;
90
- public decodedFrames = 0;
91
- public droppedFrames = 0;
92
- public receivedSamples = 0;
93
- public silentConcealedSamples = 0;
87
+ public bitrate = 0;
88
+ public rttInMs?: number;
94
89
  public fractionLoss = 0;
90
+
91
+ public totalLostPackets = 0;
92
+ public totalReceivedPackets = 0;
93
+ public totalBytesReceived = 0;
94
+ public totalReceivedFrames = 0;
95
+ public totalDecodedFrames = 0;
96
+ public totalDroppedFrames = 0;
97
+ public totalReceivedSamples = 0;
98
+ public totalSilentConcealedSamples = 0;
99
+
100
+ public deltaLostPackets = 0;
101
+ public deltaReceivedPackets = 0;
102
+ public deltaBytesReceived = 0;
103
+ public deltaReceivedFrames = 0;
104
+ public deltaDecodedFrames = 0;
105
+ public deltaDroppedFrames = 0;
106
+ public deltaReceivedSamples = 0;
107
+ public deltaSilentConcealedSamples = 0;
95
108
 
96
109
  private constructor(
97
110
  private readonly _model: Models.InboundTrack,
@@ -161,6 +174,10 @@ export class ObservedInboundTrack<Kind extends MediaKind> extends EventEmitter {
161
174
  return this.peerConnection.reports;
162
175
  }
163
176
 
177
+ public get uptimeInMs() {
178
+ return this._updated - this.created;
179
+ }
180
+
164
181
  public set remoteOutboundTrack(track: ObservedOutboundTrack<Kind> | undefined) {
165
182
  if (this._closed) return;
166
183
  if (this._remoteOutboundTrack) return;
@@ -190,6 +207,19 @@ export class ObservedInboundTrack<Kind extends MediaKind> extends EventEmitter {
190
207
  .finally(() => this.emit('close'));
191
208
  }
192
209
 
210
+ public resetMetrics() {
211
+ this.bitrate = 0;
212
+ this.rttInMs = undefined;
213
+ this.deltaBytesReceived = 0;
214
+ this.deltaLostPackets = 0;
215
+ this.deltaReceivedFrames = 0;
216
+ this.deltaDecodedFrames = 0;
217
+ this.deltaDroppedFrames = 0;
218
+ this.deltaReceivedSamples = 0;
219
+ this.deltaSilentConcealedSamples = 0;
220
+ this.fractionLoss = 0;
221
+ }
222
+
193
223
  public async update(sample: ObservedInboundTrackStatsUpdate<Kind>, timestamp: number) {
194
224
  if (this._closed) return;
195
225
  let executeSave = false;
@@ -205,6 +235,11 @@ export class ObservedInboundTrack<Kind extends MediaKind> extends EventEmitter {
205
235
  ...sample,
206
236
  timestamp,
207
237
  sampleSeq: -1,
238
+
239
+ remoteClientId: sample.remoteClientId ?? this.remoteOutboundTrack?.peerConnection.client.clientId,
240
+ remoteUserId: this.remoteOutboundTrack?.peerConnection.client.userId,
241
+ remoteTrackId: this.remoteOutboundTrack?.trackId,
242
+ remotePeerConnectionId: this.remoteOutboundTrack?.peerConnection.peerConnectionId,
208
243
  };
209
244
 
210
245
  if (this.kind === 'audio') this.reports.addInboundAudioTrackReport(report);
@@ -264,14 +299,24 @@ export class ObservedInboundTrack<Kind extends MediaKind> extends EventEmitter {
264
299
 
265
300
  this.bitrate = [ ...this._stats.values() ].reduce((acc, stat) => acc + stat.bitrate, 0);
266
301
  this.rttInMs = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.rttInMs ?? 0), 0) / (this._stats.size || 1);
267
- this.lostPackets = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.lostPackets ?? 0), 0);
268
- this.receivedPackets = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.receivedPackets ?? 0), 0);
269
- this.receivedFrames = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.receivedFrames ?? 0), 0);
270
- this.decodedFrames = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.decodedFrames ?? 0), 0);
271
- this.droppedFrames = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.droppedFrames ?? 0), 0);
272
- this.receivedSamples = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.receivedSamples ?? 0), 0);
273
- this.silentConcealedSamples = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.silentConcealedSamples ?? 0), 0);
274
- this.fractionLoss = 0 < this.receivedPackets && 0 < this.lostPackets ? (this.lostPackets / (this.receivedPackets + this.lostPackets)) : 0;
302
+ this.totalLostPackets = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.lostPackets ?? 0), 0);
303
+ this.totalReceivedPackets = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.receivedPackets ?? 0), 0);
304
+ this.totalBytesReceived = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.bytesReceived ?? 0), 0);
305
+ this.totalReceivedFrames = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.receivedFrames ?? 0), 0);
306
+ this.totalDecodedFrames = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.decodedFrames ?? 0), 0);
307
+ this.totalDroppedFrames = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.droppedFrames ?? 0), 0);
308
+ this.totalReceivedSamples = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.receivedSamples ?? 0), 0);
309
+ this.totalSilentConcealedSamples = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.silentConcealedSamples ?? 0), 0);
310
+
311
+ this.deltaLostPackets = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.lostPackets ?? 0), 0);
312
+ this.deltaReceivedPackets = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.receivedPackets ?? 0), 0);
313
+ this.deltaBytesReceived = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.bytesReceived ?? 0), 0);
314
+ this.deltaReceivedFrames = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.receivedFrames ?? 0), 0);
315
+ this.deltaDecodedFrames = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.decodedFrames ?? 0), 0);
316
+ this.deltaDroppedFrames = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.droppedFrames ?? 0), 0);
317
+ this.deltaReceivedSamples = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.receivedSamples ?? 0), 0);
318
+ this.deltaSilentConcealedSamples = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.silentConcealedSamples ?? 0), 0);
319
+ this.fractionLoss = 0 < this.deltaReceivedPackets && 0 < this.deltaLostPackets ? (this.deltaLostPackets / (this.deltaReceivedPackets + this.deltaLostPackets)) : 0;
275
320
 
276
321
  if (executeSave) await this._save();
277
322
 
@@ -25,6 +25,12 @@ export type ObservedOutboundTrackStats<K extends MediaKind> = ObservedOutboundTr
25
25
  ssrc: number;
26
26
  bitrate: number;
27
27
  rttInMs?: number;
28
+
29
+ deltaLostPackets: number;
30
+ deltaSentPackets: number;
31
+ deltaSentBytes: number;
32
+ deltaSentFrames?: number;
33
+ deltaEncodedFrames?: number;
28
34
  };
29
35
 
30
36
  // export type ObservedOutboundTrackStatsUpdate<K extends MediaKind> = {
@@ -64,9 +70,22 @@ export class ObservedOutboundTrack<Kind extends MediaKind> extends EventEmitter
64
70
  return new ObservedOutboundTrack<K>(model, peerConnection, storageProvider);
65
71
  }
66
72
 
67
- public bitrate?: number;
73
+ public bitrate = 0;
68
74
  public rttInMs?: number;
69
75
 
76
+ public totalLostPackets = 0;
77
+ public totalSentPackets = 0;
78
+ public totalSentBytes = 0;
79
+ public totalSentFrames = 0;
80
+
81
+ public deltaLostPackets = 0;
82
+ public deltaSentPackets = 0;
83
+ public deltaSentBytes = 0;
84
+ public deltaSentFrames = 0;
85
+ public deltaEncodedFrames = 0;
86
+
87
+ public created = Date.now();
88
+
70
89
  private readonly _stats = new Map<number, ObservedOutboundTrackStats<Kind>>();
71
90
  private readonly _execute = createSingleExecutor();
72
91
 
@@ -96,10 +115,6 @@ export class ObservedOutboundTrack<Kind extends MediaKind> extends EventEmitter
96
115
  return this._model.sfuStreamId;
97
116
  }
98
117
 
99
- public get closed() {
100
- return this._closed;
101
- }
102
-
103
118
  public get remoteInboundTracks(): ReadonlyMap<string, ObservedInboundTrack<Kind>> {
104
119
  return this._remoteInboundTracks;
105
120
  }
@@ -111,7 +126,19 @@ export class ObservedOutboundTrack<Kind extends MediaKind> extends EventEmitter
111
126
  public get updated() {
112
127
  return this._updated;
113
128
  }
129
+
130
+ public get stats(): ReadonlyMap<number, ObservedOutboundTrackStats<Kind>> {
131
+ return this._stats;
132
+ }
114
133
 
134
+ public get uptimeInMs() {
135
+ return this._updated - this.created;
136
+ }
137
+
138
+ public get closed() {
139
+ return this._closed;
140
+ }
141
+
115
142
  public close() {
116
143
  if (this._closed) return;
117
144
 
@@ -122,8 +149,15 @@ export class ObservedOutboundTrack<Kind extends MediaKind> extends EventEmitter
122
149
  .finally(() => this.emit('close'));
123
150
  }
124
151
 
125
- public get stats(): ReadonlyMap<number, ObservedOutboundTrackStats<Kind>> {
126
- return this._stats;
152
+ public resetMetrics() {
153
+ this.bitrate = 0;
154
+ this.rttInMs = 0;
155
+
156
+ this.deltaLostPackets = 0;
157
+ this.deltaSentPackets = 0;
158
+ this.deltaSentBytes = 0;
159
+ this.deltaSentFrames = 0;
160
+ this.deltaEncodedFrames = 0;
127
161
  }
128
162
 
129
163
  public async update(sample: ObservedOutboundTrackStatsUpdate<Kind>, timestamp: number): Promise<void> {
@@ -150,13 +184,30 @@ export class ObservedOutboundTrack<Kind extends MediaKind> extends EventEmitter
150
184
  const lastStat = this._stats.get(sample.ssrc);
151
185
  const rttInMs = sample.roundTripTime ? sample.roundTripTime * 1000 : undefined;
152
186
  const bitrate = ((sample.bytesSent ?? 0) - (lastStat?.bytesSent ?? 0)) * 8 / (elapsedTimeInMs / 1000);
153
- // const lostPackets = (sample.packetsLost ?? 0) - (lastStat?.packetsLost ?? 0);
154
- // const sentPackets = (sample.packetsSent ?? 0) - (lastStat?.packetsSent ?? 0);
187
+ const deltaLostPackets = (sample.packetsLost ?? 0) - (lastStat?.packetsLost ?? 0);
188
+ const deltaSentPackets = (sample.packetsSent ?? 0) - (lastStat?.packetsSent ?? 0);
189
+ const deltaSentBytes = (sample.bytesSent ?? 0) - (lastStat?.bytesSent ?? 0);
190
+ let deltaEncodedFrames: number | undefined;
191
+ let deltaSentFrames: number | undefined;
192
+
193
+ if (this.kind === 'video') {
194
+ const videoSample = sample as OutboundVideoTrack;
195
+ const lastVideoStats = lastStat as OutboundVideoTrack | undefined;
196
+
197
+ deltaEncodedFrames = (videoSample.framesEncoded ?? 0) - (lastVideoStats?.framesEncoded ?? 0);
198
+ deltaSentFrames = (videoSample.framesSent ?? 0) - (lastVideoStats?.framesSent ?? 0);
199
+ }
155
200
  const stats: ObservedOutboundTrackStats<Kind> = {
156
201
  ...sample,
157
202
  rttInMs,
158
203
  bitrate,
159
204
  ssrc: sample.ssrc,
205
+
206
+ deltaLostPackets,
207
+ deltaSentPackets,
208
+ deltaSentBytes,
209
+ deltaEncodedFrames,
210
+ deltaSentFrames,
160
211
  };
161
212
 
162
213
  this._stats.set(sample.ssrc, stats);
@@ -164,6 +215,16 @@ export class ObservedOutboundTrack<Kind extends MediaKind> extends EventEmitter
164
215
  this.bitrate = [ ...this._stats.values() ].reduce((acc, stat) => acc + stat.bitrate, 0);
165
216
  this.rttInMs = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.rttInMs ?? 0), 0) / (this._stats.size || 1);
166
217
 
218
+ this.totalLostPackets = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.packetsLost ?? 0), 0);
219
+ this.totalSentPackets = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.packetsSent ?? 0), 0);
220
+ this.totalSentBytes = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.bytesSent ?? 0), 0);
221
+
222
+ this.deltaEncodedFrames = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.deltaEncodedFrames ?? 0), 0);
223
+ this.deltaSentFrames = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.deltaSentFrames ?? 0), 0);
224
+ this.deltaLostPackets = [ ...this._stats.values() ].reduce((acc, stat) => acc + stat.deltaLostPackets, 0);
225
+ this.deltaSentPackets = [ ...this._stats.values() ].reduce((acc, stat) => acc + stat.deltaSentPackets, 0);
226
+ this.deltaSentBytes = [ ...this._stats.values() ].reduce((acc, stat) => acc + stat.deltaSentBytes, 0);
227
+
167
228
  // setting up sfu connection as it is not always available at the first sample
168
229
  if (sample.sfuStreamId && !this._model.sfuStreamId) {
169
230
  this._model.sfuStreamId = sample.sfuStreamId;
@@ -16,10 +16,6 @@ export type ObservedPeerConnectionEvents = {
16
16
  newinboudvideotrack: [ObservedInboundTrack<'video'>],
17
17
  newoutboundaudiotrack: [ObservedOutboundTrack<'audio'>],
18
18
  newoutboundvideotrack: [ObservedOutboundTrack<'video'>],
19
-
20
- iceconnectionstatechange: [string],
21
- icegatheringstatechange: [string],
22
- connectionstatechange: [string],
23
19
  };
24
20
 
25
21
  export type ObservedPeerConnectionConfig = {
@@ -56,27 +52,35 @@ export class ObservedPeerConnection extends EventEmitter {
56
52
  return new ObservedPeerConnection(model, client, storageProvider);
57
53
  }
58
54
 
55
+ public created = Date.now();
56
+
59
57
  public totalInboundPacketsLost = 0;
60
58
  public totalInboundPacketsReceived = 0;
61
- public totalOutboundPacketsLost = 0;
62
- public totalOutboundPacketsReceived = 0;
63
59
  public totalOutboundPacketsSent = 0;
64
60
  public totalDataChannelBytesSent = 0;
65
61
  public totalDataChannelBytesReceived = 0;
62
+
66
63
  public totalSentAudioBytes = 0;
67
64
  public totalSentVideoBytes = 0;
65
+ public totalSentAudioPackets = 0;
66
+ public totalSentVideoPackets = 0;
67
+ public totalReceivedAudioPacktes = 0;
68
+ public totalReceivedVideoPackets = 0;
68
69
  public totalReceivedAudioBytes = 0;
69
70
  public totalReceivedVideoBytes = 0;
70
71
 
71
- public deltaInboundPacketsLost = 0;
72
- public deltaInboundPacketsReceived = 0;
73
- public deltaOutboundPacketsLost = 0;
74
- public deltaOutboundPacketsReceived = 0;
75
- public deltaOutboundPacketsSent = 0;
72
+ public deltaInboundLostPackets = 0;
73
+ public deltaInboundReceivedPackets = 0;
74
+ public deltaOutboundSentPackets = 0;
76
75
  public deltaDataChannelBytesSent = 0;
77
76
  public deltaDataChannelBytesReceived = 0;
77
+ public deltaInboundReceivedBytes = 0;
78
+ public deltaOutboundSentBytes = 0;
79
+
78
80
  public deltaReceivedAudioBytes = 0;
79
81
  public deltaReceivedVideoBytes = 0;
82
+ public deltaReceivedAudioPackets = 0;
83
+ public deltaReceivedVideoPackets = 0;
80
84
  public deltaSentAudioBytes = 0;
81
85
  public deltaSentVideoBytes = 0;
82
86
  public sendingAudioBitrate = 0;
@@ -148,6 +152,10 @@ export class ObservedPeerConnection extends EventEmitter {
148
152
  return this._outboundVideoTracks;
149
153
  }
150
154
 
155
+ public get uptimeInMs() {
156
+ return this._updated - this.created;
157
+ }
158
+
151
159
  public get closed() {
152
160
  return this._closed;
153
161
  }
@@ -166,16 +174,15 @@ export class ObservedPeerConnection extends EventEmitter {
166
174
  .finally(() => this.emit('close'));
167
175
  }
168
176
 
169
- public updateMetrics() {
170
- this.deltaInboundPacketsLost = 0;
171
- this.deltaInboundPacketsReceived = 0;
172
- this.deltaOutboundPacketsLost = 0;
173
- this.deltaOutboundPacketsReceived = 0;
174
- this.deltaOutboundPacketsSent = 0;
175
- this.sendingAudioBitrate = 0;
176
- this.sendingVideoBitrate = 0;
177
- this.receivingAudioBitrate = 0;
178
- this.receivingVideoBitrate = 0;
177
+ public getTrack(trackId: string): ObservedInboundTrack<'audio'> | ObservedInboundTrack<'video'> | ObservedOutboundTrack<'audio'> | ObservedOutboundTrack<'video'> | undefined {
178
+ return this._inboundAudioTracks.get(trackId) ?? this._inboundVideoTracks.get(trackId) ?? this._outboundAudioTracks.get(trackId) ?? this._outboundVideoTracks.get(trackId);
179
+ }
180
+
181
+ public resetMetrics() {
182
+ this.deltaInboundLostPackets = 0;
183
+ this.deltaInboundReceivedPackets = 0;
184
+ this.deltaOutboundSentPackets = 0;
185
+
179
186
  this.deltaDataChannelBytesSent = 0;
180
187
  this.deltaDataChannelBytesReceived = 0;
181
188
  this.deltaReceivedAudioBytes = 0;
@@ -183,13 +190,101 @@ export class ObservedPeerConnection extends EventEmitter {
183
190
  this.deltaSentAudioBytes = 0;
184
191
  this.deltaSentVideoBytes = 0;
185
192
 
193
+ this._inboundAudioTracks.forEach((track) => track.resetMetrics());
194
+ this._inboundVideoTracks.forEach((track) => track.resetMetrics());
195
+ this._outboundAudioTracks.forEach((track) => track.resetMetrics());
196
+ this._outboundVideoTracks.forEach((track) => track.resetMetrics());
197
+ }
198
+
199
+ public updateMetrics() {
200
+ this.totalInboundPacketsLost = 0;
201
+ this.totalInboundPacketsReceived = 0;
202
+ this.totalOutboundPacketsSent = 0;
203
+ this.totalDataChannelBytesSent = 0;
204
+ this.totalDataChannelBytesReceived = 0;
205
+
206
+ this.totalSentAudioBytes = 0;
207
+ this.totalSentVideoBytes = 0;
208
+ this.totalReceivedAudioBytes = 0;
209
+ this.totalReceivedVideoBytes = 0;
210
+ this.sendingAudioBitrate = 0;
211
+ this.sendingVideoBitrate = 0;
212
+ this.receivingAudioBitrate = 0;
213
+ this.receivingVideoBitrate = 0;
214
+
215
+ let sumRttInS = 0;
216
+
186
217
  this._inboundAudioTracks.forEach((track) => {
187
- this.deltaReceivedAudioBytes += track.receivedPackets;
218
+ this.deltaInboundLostPackets += track.deltaLostPackets;
219
+ this.deltaInboundReceivedPackets += track.deltaReceivedPackets;
220
+ this.deltaInboundReceivedBytes += track.deltaBytesReceived;
221
+
222
+ this.deltaReceivedAudioBytes += track.deltaBytesReceived;
223
+ this.deltaReceivedAudioPackets += track.deltaReceivedPackets;
224
+
225
+ this.receivingAudioBitrate += track.bitrate;
226
+
227
+ this.totalInboundPacketsLost += track.totalLostPackets;
228
+ this.totalInboundPacketsReceived += track.totalReceivedPackets;
229
+ this.totalReceivedAudioBytes += track.totalBytesReceived;
230
+ this.totalReceivedAudioPacktes += track.totalReceivedPackets;
231
+
232
+ sumRttInS = (track.rttInMs ?? 0) / 1000.0;
188
233
  });
189
234
 
190
235
  this._inboundVideoTracks.forEach((track) => {
191
- this.deltaReceivedVideoBytes += track.receivedPackets;
236
+ this.deltaInboundLostPackets += track.deltaLostPackets;
237
+ this.deltaInboundReceivedPackets += track.deltaReceivedPackets;
238
+ this.deltaInboundReceivedBytes += track.deltaBytesReceived;
239
+
240
+ this.deltaReceivedVideoBytes += track.deltaBytesReceived;
241
+ this.deltaReceivedVideoPackets += track.deltaReceivedPackets;
242
+
243
+ this.receivingVideoBitrate += track.bitrate;
244
+
245
+ this.totalInboundPacketsLost += track.totalLostPackets;
246
+ this.totalInboundPacketsReceived += track.totalReceivedPackets;
247
+ this.totalReceivedVideoBytes += track.totalBytesReceived;
248
+ this.totalReceivedVideoPackets += track.totalReceivedPackets;
249
+
250
+ sumRttInS = (track.rttInMs ?? 0) / 1000.0;
251
+ });
252
+
253
+ this._outboundAudioTracks.forEach((track) => {
254
+ this.deltaOutboundSentPackets += track.deltaSentPackets;
255
+ this.deltaOutboundSentBytes += track.deltaSentBytes;
256
+
257
+ this.deltaSentAudioBytes += track.deltaSentBytes;
258
+ this.deltaSentAudioBytes += track.deltaSentPackets;
259
+
260
+ this.sendingAudioBitrate += track.bitrate;
261
+
262
+ this.totalOutboundPacketsSent += track.totalSentPackets;
263
+ this.totalSentAudioBytes += track.totalSentBytes;
264
+ this.totalSentAudioPackets += track.totalSentPackets;
265
+
266
+ sumRttInS = (track.rttInMs ?? 0) / 1000.0;
192
267
  });
268
+
269
+ this._outboundVideoTracks.forEach((track) => {
270
+ this.deltaOutboundSentPackets += track.deltaSentPackets;
271
+ this.deltaOutboundSentBytes += track.deltaSentBytes;
272
+
273
+ this.deltaSentVideoBytes += track.deltaSentBytes;
274
+ this.deltaSentVideoBytes += track.deltaSentPackets;
275
+
276
+ this.sendingVideoBitrate += track.bitrate;
277
+
278
+ this.totalOutboundPacketsSent += track.totalSentPackets;
279
+ this.totalSentVideoBytes += track.totalSentBytes;
280
+ this.totalSentVideoPackets += track.totalSentPackets;
281
+
282
+ sumRttInS = (track.rttInMs ?? 0) / 1000.0;
283
+ });
284
+
285
+ const nrOfBelongings = this._inboundAudioTracks.size + this._inboundVideoTracks.size + this._outboundAudioTracks.size + this._outboundVideoTracks.size;
286
+
287
+ this.avgRttInS = 0 < nrOfBelongings ? sumRttInS / nrOfBelongings : undefined;
193
288
  }
194
289
 
195
290
  public update(sample: PeerConnectionTransport, timestamp: number) {
@@ -228,6 +323,13 @@ export class ObservedPeerConnection extends EventEmitter {
228
323
  kind: 'audio',
229
324
  trackId: config.trackId,
230
325
  }, this, this._storageProvider);
326
+
327
+ const pendingTracksTimestamp = this.client.ωpendingCreatedTracksTimestamp.get(result.trackId);
328
+
329
+ if (pendingTracksTimestamp) {
330
+ this.client.ωpendingCreatedTracksTimestamp.delete(result.trackId);
331
+ result.created = pendingTracksTimestamp;
332
+ }
231
333
 
232
334
  result.on('close', () => {
233
335
  this._inboundAudioTracks.delete(result.trackId);
@@ -250,6 +352,13 @@ export class ObservedPeerConnection extends EventEmitter {
250
352
  kind: 'video',
251
353
  trackId: config.trackId,
252
354
  }, this, this._storageProvider);
355
+
356
+ const pendingTracksTimestamp = this.client.ωpendingCreatedTracksTimestamp.get(result.trackId);
357
+
358
+ if (pendingTracksTimestamp) {
359
+ this.client.ωpendingCreatedTracksTimestamp.delete(result.trackId);
360
+ result.created = pendingTracksTimestamp;
361
+ }
253
362
 
254
363
  result.on('close', () => {
255
364
  this._inboundVideoTracks.delete(result.trackId);
@@ -273,6 +382,13 @@ export class ObservedPeerConnection extends EventEmitter {
273
382
  trackId: config.trackId,
274
383
  }, this, this._storageProvider);
275
384
 
385
+ const pendingTracksTimestamp = this.client.ωpendingCreatedTracksTimestamp.get(result.trackId);
386
+
387
+ if (pendingTracksTimestamp) {
388
+ this.client.ωpendingCreatedTracksTimestamp.delete(result.trackId);
389
+ result.created = pendingTracksTimestamp;
390
+ }
391
+
276
392
  result.on('close', () => {
277
393
  this._outboundAudioTracks.delete(result.trackId);
278
394
  this._model.outboundTrackIds = this._model.outboundTrackIds.filter((id) => id !== result.trackId);
@@ -299,6 +415,13 @@ export class ObservedPeerConnection extends EventEmitter {
299
415
  trackId: config.trackId,
300
416
  }, this, this._storageProvider);
301
417
 
418
+ const pendingTracksTimestamp = this.client.ωpendingCreatedTracksTimestamp.get(result.trackId);
419
+
420
+ if (pendingTracksTimestamp) {
421
+ this.client.ωpendingCreatedTracksTimestamp.delete(result.trackId);
422
+ result.created = pendingTracksTimestamp;
423
+ }
424
+
302
425
  result.on('close', () => {
303
426
  this._outboundVideoTracks.delete(result.trackId);
304
427
  result.sfuStreamId && this.client.call.sfuStreamIdToOutboundVideoTrack.set(result.sfuStreamId, result);
@@ -1,23 +0,0 @@
1
- import { CallEventReport, CallMetaReport, ClientDataChannelReport, ClientExtensionReport, IceCandidatePairReport, InboundAudioTrackReport, InboundVideoTrackReport, ObserverEventReport, OutboundAudioTrackReport, OutboundVideoTrackReport, PeerConnectionTransportReport, SfuEventReport, SfuExtensionReport, SfuInboundRtpPadReport, SfuMetaReport, SfuOutboundRtpPadReport, SfuSctpStreamReport, SFUTransportReport } from '@observertc/report-schemas-js';
2
- export type ObservedReports = ReturnType<typeof createObservedReports>;
3
- export declare function createObservedReports(): {
4
- callEventReports: CallEventReport[];
5
- callMetaReports: CallMetaReport[];
6
- clientDataChannelReports: ClientDataChannelReport[];
7
- clientExtensionReports: ClientExtensionReport[];
8
- iceCandidatePairReports: IceCandidatePairReport[];
9
- inboundAudioTrackReports: InboundAudioTrackReport[];
10
- inboundVideoTrackReports: InboundVideoTrackReport[];
11
- observerEventReports: ObserverEventReport[];
12
- outboundAudioTrackReports: OutboundAudioTrackReport[];
13
- outboundVideoTrackReports: OutboundVideoTrackReport[];
14
- peerConnectionTransportReports: PeerConnectionTransportReport[];
15
- sfuEventReports: SfuEventReport[];
16
- sfuExtensionReports: SfuExtensionReport[];
17
- sfuInboundRtpPadReports: SfuInboundRtpPadReport[];
18
- sfuMetaReports: SfuMetaReport[];
19
- sfuOutboundRtpPadReports: SfuOutboundRtpPadReport[];
20
- sfuSctpStreamReports: SfuSctpStreamReport[];
21
- sfuTransportReports: SFUTransportReport[];
22
- };
23
- //# sourceMappingURL=ReportsCollector.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ReportsCollector.d.ts","sourceRoot":"","sources":["../../src/common/ReportsCollector.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,eAAe,EACf,cAAc,EACd,uBAAuB,EACvB,qBAAqB,EACrB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,mBAAmB,EACnB,wBAAwB,EACxB,wBAAwB,EACxB,6BAA6B,EAC7B,cAAc,EACd,kBAAkB,EAClB,sBAAsB,EACtB,aAAa,EACb,uBAAuB,EACvB,mBAAmB,EACnB,kBAAkB,EAClB,MAAM,+BAA+B,CAAC;AA4BvC,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEvE,wBAAgB,qBAAqB;;;;;;;;;;;;;;;;;;;EAqBpC"}
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createObservedReports = void 0;
4
- function createObservedReports() {
5
- return {
6
- callEventReports: [],
7
- callMetaReports: [],
8
- clientDataChannelReports: [],
9
- clientExtensionReports: [],
10
- iceCandidatePairReports: [],
11
- inboundAudioTrackReports: [],
12
- inboundVideoTrackReports: [],
13
- observerEventReports: [],
14
- outboundAudioTrackReports: [],
15
- outboundVideoTrackReports: [],
16
- peerConnectionTransportReports: [],
17
- sfuEventReports: [],
18
- sfuExtensionReports: [],
19
- sfuInboundRtpPadReports: [],
20
- sfuMetaReports: [],
21
- sfuOutboundRtpPadReports: [],
22
- sfuSctpStreamReports: [],
23
- sfuTransportReports: [],
24
- };
25
- }
26
- exports.createObservedReports = createObservedReports;
@@ -1,71 +0,0 @@
1
- import {
2
- CallEventReport,
3
- CallMetaReport,
4
- ClientDataChannelReport,
5
- ClientExtensionReport,
6
- IceCandidatePairReport,
7
- InboundAudioTrackReport,
8
- InboundVideoTrackReport,
9
- ObserverEventReport,
10
- OutboundAudioTrackReport,
11
- OutboundVideoTrackReport,
12
- PeerConnectionTransportReport,
13
- SfuEventReport,
14
- SfuExtensionReport,
15
- SfuInboundRtpPadReport,
16
- SfuMetaReport,
17
- SfuOutboundRtpPadReport,
18
- SfuSctpStreamReport,
19
- SFUTransportReport,
20
- } from '@observertc/report-schemas-js';
21
-
22
- // export interface ReportsCollector {
23
- // addCallEventReport(report: CallEventReport): void;
24
- // addCallMetaReport(report: CallMetaReport): void;
25
- // addClientDataChannelReport(report: ClientDataChannelReport): void;
26
- // addClientExtensionReport(report: ClientExtensionReport): void;
27
- // addIceCandidatePairReport(report: IceCandidatePairReport): void;
28
- // addInboundAudioTrackReport(report: InboundAudioTrackReport): void;
29
- // addInboundVideoTrackReport(report: InboundVideoTrackReport): void;
30
- // addPeerConnectionTransportReports(report: PeerConnectionTransportReport): void;
31
- // addObserverEventReport(report: ObserverEventReport): void;
32
- // addOutboundAudioTrackReport(report: OutboundAudioTrackReport): void;
33
- // addOutboundVideoTrackReport(report: OutboundVideoTrackReport): void;
34
- // addSfuEventReport(report: SfuEventReport): void;
35
- // addSfuExtensionReport(report: SfuExtensionReport): void;
36
- // addSfuInboundRtpPadReport(report: SfuInboundRtpPadReport): void;
37
- // addSfuOutboundRtpPadReport(report: SfuOutboundRtpPadReport): void;
38
- // addSfuSctpStreamReport(report: SfuSctpStreamReport): void;
39
- // addSfuTransportReport(report: SFUTransportReport): void;
40
- // addSfuMetaReport(report: SfuMetaReport): void;
41
-
42
- // getCallEventReports(): CallEventReport[];
43
- // getClientExtensionReports(): ClientExtensionReport[];
44
- // getSfuEventReports(): SfuEventReport[];
45
- // getSfuExtensionReports(): SfuExtensionReport[];
46
- // }
47
-
48
- export type ObservedReports = ReturnType<typeof createObservedReports>;
49
-
50
- export function createObservedReports() {
51
- return {
52
- callEventReports: [] as CallEventReport[],
53
- callMetaReports: [] as CallMetaReport[],
54
- clientDataChannelReports: [] as ClientDataChannelReport[],
55
- clientExtensionReports: [] as ClientExtensionReport[],
56
- iceCandidatePairReports: [] as IceCandidatePairReport[],
57
- inboundAudioTrackReports: [] as InboundAudioTrackReport[],
58
- inboundVideoTrackReports: [] as InboundVideoTrackReport[],
59
- observerEventReports: [] as ObserverEventReport[],
60
- outboundAudioTrackReports: [] as OutboundAudioTrackReport[],
61
- outboundVideoTrackReports: [] as OutboundVideoTrackReport[],
62
- peerConnectionTransportReports: [] as PeerConnectionTransportReport[],
63
- sfuEventReports: [] as SfuEventReport[],
64
- sfuExtensionReports: [] as SfuExtensionReport[],
65
- sfuInboundRtpPadReports: [] as SfuInboundRtpPadReport[],
66
- sfuMetaReports: [] as SfuMetaReport[],
67
- sfuOutboundRtpPadReports: [] as SfuOutboundRtpPadReport[],
68
- sfuSctpStreamReports: [] as SfuSctpStreamReport[],
69
- sfuTransportReports: [] as SFUTransportReport[],
70
- };
71
- }