@observertc/observer-js 0.41.7 → 0.42.0
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.
- package/lib/ObservedCall.d.ts +10 -3
- package/lib/ObservedCall.d.ts.map +1 -1
- package/lib/ObservedCall.js +28 -0
- package/lib/ObservedClient.d.ts +4 -0
- package/lib/ObservedClient.d.ts.map +1 -1
- package/lib/ObservedClient.js +81 -32
- package/lib/ObservedInboundAudioTrack.d.ts +94 -0
- package/lib/ObservedInboundAudioTrack.d.ts.map +1 -0
- package/lib/ObservedInboundAudioTrack.js +215 -0
- package/lib/ObservedInboundVideoTrack.d.ts +98 -0
- package/lib/ObservedInboundVideoTrack.d.ts.map +1 -0
- package/lib/{ObservedInboundTrack.js → ObservedInboundVideoTrack.js} +53 -44
- package/lib/ObservedOutboundAudioTrack.d.ts +85 -0
- package/lib/ObservedOutboundAudioTrack.d.ts.map +1 -0
- package/lib/{ObservedOutboundTrack.js → ObservedOutboundAudioTrack.js} +35 -58
- package/lib/ObservedOutboundVideoTrack.d.ts +88 -0
- package/lib/ObservedOutboundVideoTrack.d.ts.map +1 -0
- package/lib/ObservedOutboundVideoTrack.js +204 -0
- package/lib/ObservedPeerConnection.d.ts +26 -16
- package/lib/ObservedPeerConnection.d.ts.map +1 -1
- package/lib/ObservedPeerConnection.js +157 -86
- package/lib/RemoteTrackAssigner.d.ts +14 -0
- package/lib/RemoteTrackAssigner.d.ts.map +1 -0
- package/lib/RemoteTrackAssigner.js +52 -0
- package/lib/common/CalculatedScore.d.ts +79 -0
- package/lib/common/CalculatedScore.d.ts.map +1 -0
- package/lib/common/CalculatedScore.js +155 -0
- package/lib/common/QualityScoreUtils.d.ts +1 -0
- package/lib/common/QualityScoreUtils.d.ts.map +1 -0
- package/lib/common/QualityScoreUtils.js +1 -0
- package/lib/common/utils.d.ts +1 -0
- package/lib/common/utils.d.ts.map +1 -1
- package/lib/common/utils.js +14 -1
- package/lib/index.d.ts +4 -2
- package/lib/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/ObservedCall.ts +40 -4
- package/src/ObservedClient.ts +77 -17
- package/src/ObservedInboundAudioTrack.ts +336 -0
- package/src/{ObservedInboundTrack.ts → ObservedInboundVideoTrack.ts} +85 -66
- package/src/{ObservedOutboundTrack.ts → ObservedOutboundAudioTrack.ts} +59 -74
- package/src/ObservedOutboundVideoTrack.ts +326 -0
- package/src/ObservedPeerConnection.ts +205 -131
- package/src/RemoteTrackAssigner.ts +68 -0
- package/src/common/CalculatedScore.ts +180 -0
- package/src/common/QualityScoreUtils.ts +0 -0
- package/src/common/utils.ts +17 -1
- package/src/index.ts +4 -2
- package/src/monitors/CallSummaryMonitor.ts +3 -3
- package/lib/ObservedInboundTrack.d.ts +0 -96
- package/lib/ObservedInboundTrack.d.ts.map +0 -1
- package/lib/ObservedOutboundTrack.d.ts +0 -84
- package/lib/ObservedOutboundTrack.d.ts.map +0 -1
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { ObservedPeerConnection } from './ObservedPeerConnection';
|
|
3
|
+
import { OutboundVideoTrack } from '@observertc/sample-schemas-js';
|
|
4
|
+
import { OutboundAudioTrackReport, OutboundVideoTrackReport } from '@observertc/report-schemas-js';
|
|
5
|
+
import { ObservedInboundVideoTrack } from './ObservedInboundVideoTrack';
|
|
6
|
+
import { calculateBaseVideoScore, CalculatedScore } from './common/CalculatedScore';
|
|
7
|
+
import { ClientIssue } from './monitors/CallSummary';
|
|
8
|
+
|
|
9
|
+
export type ObservedOutboundVideoTrackModel = {
|
|
10
|
+
trackId: string;
|
|
11
|
+
sfuStreamId?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type ObservedOutboundVideoTrackEvents = {
|
|
15
|
+
qualitylimitationchanged: [string];
|
|
16
|
+
update: [{
|
|
17
|
+
elapsedTimeInMs: number;
|
|
18
|
+
}],
|
|
19
|
+
score: [CalculatedScore],
|
|
20
|
+
close: [],
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type ObservedOutboundVideoTrackStats = OutboundVideoTrack & {
|
|
24
|
+
ssrc: number;
|
|
25
|
+
bitrate: number;
|
|
26
|
+
rttInMs?: number;
|
|
27
|
+
|
|
28
|
+
deltaLostPackets: number;
|
|
29
|
+
deltaSentPackets: number;
|
|
30
|
+
deltaSentBytes: number;
|
|
31
|
+
deltaSentFrames?: number;
|
|
32
|
+
deltaEncodedFrames?: number;
|
|
33
|
+
|
|
34
|
+
statsTimestamp: number;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// export type ObservedOutboundTrackStatsUpdate = {
|
|
38
|
+
// [Property in keyof ObservedOutboundTrackStats<K>]: ObservedOutboundTrackStats<K>[Property];
|
|
39
|
+
// }
|
|
40
|
+
|
|
41
|
+
export declare interface ObservedOutboundVideoTrack {
|
|
42
|
+
on<U extends keyof ObservedOutboundVideoTrackEvents>(event: U, listener: (...args: ObservedOutboundVideoTrackEvents[U]) => void): this;
|
|
43
|
+
off<U extends keyof ObservedOutboundVideoTrackEvents>(event: U, listener: (...args: ObservedOutboundVideoTrackEvents[U]) => void): this;
|
|
44
|
+
once<U extends keyof ObservedOutboundVideoTrackEvents>(event: U, listener: (...args: ObservedOutboundVideoTrackEvents[U]) => void): this;
|
|
45
|
+
emit<U extends keyof ObservedOutboundVideoTrackEvents>(event: U, ...args: ObservedOutboundVideoTrackEvents[U]): boolean;
|
|
46
|
+
update(sample: OutboundVideoTrack, timestamp: number): void;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export class ObservedOutboundVideoTrack extends EventEmitter {
|
|
50
|
+
public readonly created = Date.now();
|
|
51
|
+
public visited = false;
|
|
52
|
+
|
|
53
|
+
public contentType: 'lowmotion' | 'standard' | 'highmotion' = 'standard';
|
|
54
|
+
public codec: 'vp8' | 'vp9' | 'h264' = 'vp8';
|
|
55
|
+
public highestLayer?: ObservedOutboundVideoTrackStats;
|
|
56
|
+
|
|
57
|
+
public bitrate = 0;
|
|
58
|
+
public jitter?: number;
|
|
59
|
+
public rttInMs?: number;
|
|
60
|
+
public marker?: string;
|
|
61
|
+
|
|
62
|
+
public totalLostPackets = 0;
|
|
63
|
+
public totalSentPackets = 0;
|
|
64
|
+
public totalSentBytes = 0;
|
|
65
|
+
public totalSentFrames = 0;
|
|
66
|
+
|
|
67
|
+
public deltaLostPackets = 0;
|
|
68
|
+
public deltaSentPackets = 0;
|
|
69
|
+
public deltaSentBytes = 0;
|
|
70
|
+
public deltaSentFrames = 0;
|
|
71
|
+
public deltaEncodedFrames = 0;
|
|
72
|
+
|
|
73
|
+
public sendingBitrate = 0;
|
|
74
|
+
|
|
75
|
+
private readonly _stats = new Map<number, ObservedOutboundVideoTrackStats>();
|
|
76
|
+
private _lastMaxStatsTimestamp = 0;
|
|
77
|
+
|
|
78
|
+
private _closed = false;
|
|
79
|
+
private _updated = Date.now();
|
|
80
|
+
public readonly remoteInboundTracks = new Map<string, ObservedInboundVideoTrack>();
|
|
81
|
+
|
|
82
|
+
public score?: CalculatedScore;
|
|
83
|
+
public ωpendingIssuesForScores: ClientIssue[] = [];
|
|
84
|
+
|
|
85
|
+
public constructor(
|
|
86
|
+
private readonly _model: ObservedOutboundVideoTrackModel,
|
|
87
|
+
public readonly peerConnection: ObservedPeerConnection,
|
|
88
|
+
) {
|
|
89
|
+
super();
|
|
90
|
+
this.setMaxListeners(Infinity);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public get serviceId() {
|
|
94
|
+
return this.peerConnection.serviceId;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public get roomId() {
|
|
98
|
+
return this.peerConnection.roomId;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public get callId() {
|
|
102
|
+
return this.peerConnection.callId;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
public get clientId() {
|
|
106
|
+
return this.peerConnection.clientId;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
public get mediaUnitId() {
|
|
110
|
+
return this.peerConnection.mediaUnitId;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
public get peerConnectionId() {
|
|
114
|
+
return this.peerConnection.peerConnectionId;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public get trackId() {
|
|
118
|
+
return this._model.trackId;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
public get sfuStreamId() {
|
|
122
|
+
return this._model.sfuStreamId;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public get reports() {
|
|
126
|
+
return this.peerConnection.reports;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
public get updated() {
|
|
130
|
+
return this._updated;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
public get statsTimestamp() {
|
|
134
|
+
return this._lastMaxStatsTimestamp;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
public get stats(): ReadonlyMap<number, ObservedOutboundVideoTrackStats> {
|
|
138
|
+
return this._stats;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
public get closed() {
|
|
142
|
+
return this._closed;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
public close() {
|
|
146
|
+
if (this._closed) return;
|
|
147
|
+
this._closed = true;
|
|
148
|
+
|
|
149
|
+
this.emit('close');
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
public update(sample: OutboundVideoTrack, statsTimestamp: number): void {
|
|
153
|
+
if (this._closed) return;
|
|
154
|
+
|
|
155
|
+
const now = Date.now();
|
|
156
|
+
const report: OutboundAudioTrackReport | OutboundVideoTrackReport = {
|
|
157
|
+
serviceId: this.peerConnection.client.serviceId,
|
|
158
|
+
roomId: this.peerConnection.client.call.roomId,
|
|
159
|
+
callId: this.peerConnection.client.call.callId,
|
|
160
|
+
clientId: this.peerConnection.client.clientId,
|
|
161
|
+
userId: this.peerConnection.client.userId,
|
|
162
|
+
mediaUnitId: this.peerConnection.client.mediaUnitId,
|
|
163
|
+
peerConnectionId: this.peerConnection.peerConnectionId,
|
|
164
|
+
...sample,
|
|
165
|
+
timestamp: statsTimestamp,
|
|
166
|
+
sampleSeq: -1,
|
|
167
|
+
marker: this.marker,
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
this.reports.addOutboundVideoTrackReport(report);
|
|
171
|
+
|
|
172
|
+
const elapsedTimeInMs = Math.max(1, now - this._updated);
|
|
173
|
+
const lastStat = this._stats.get(sample.ssrc);
|
|
174
|
+
const rttInMs = sample.roundTripTime ? sample.roundTripTime * 1000 : undefined;
|
|
175
|
+
let bitrate = 0;
|
|
176
|
+
let deltaLostPackets = 0;
|
|
177
|
+
let deltaSentPackets = 0;
|
|
178
|
+
let deltaSentBytes = 0;
|
|
179
|
+
|
|
180
|
+
if (sample.bytesSent && lastStat?.bytesSent && lastStat.bytesSent < sample.bytesSent) {
|
|
181
|
+
bitrate = (sample.bytesSent - lastStat.bytesSent) * 8 / (elapsedTimeInMs / 1000);
|
|
182
|
+
}
|
|
183
|
+
if (sample.packetsLost && lastStat?.packetsLost && lastStat.packetsLost < sample.packetsLost) {
|
|
184
|
+
deltaLostPackets = sample.packetsLost - lastStat.packetsLost;
|
|
185
|
+
}
|
|
186
|
+
if (sample.packetsSent && lastStat?.packetsSent && lastStat.packetsSent < sample.packetsSent) {
|
|
187
|
+
deltaSentPackets = sample.packetsSent - lastStat.packetsSent;
|
|
188
|
+
}
|
|
189
|
+
if (sample.bytesSent && lastStat?.bytesSent && lastStat.bytesSent < sample.bytesSent) {
|
|
190
|
+
deltaSentBytes = sample.bytesSent - lastStat.bytesSent;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
let deltaEncodedFrames: number | undefined;
|
|
194
|
+
let deltaSentFrames: number | undefined;
|
|
195
|
+
|
|
196
|
+
const videoSample = sample as OutboundVideoTrack;
|
|
197
|
+
const lastVideoStats = lastStat as OutboundVideoTrack | undefined;
|
|
198
|
+
|
|
199
|
+
if (videoSample?.framesEncoded && lastVideoStats?.framesEncoded && lastVideoStats.framesEncoded < videoSample.framesEncoded) {
|
|
200
|
+
deltaEncodedFrames = videoSample.framesEncoded - lastVideoStats.framesEncoded;
|
|
201
|
+
}
|
|
202
|
+
if (videoSample?.framesSent && lastVideoStats?.framesSent && lastVideoStats.framesSent < videoSample.framesSent) {
|
|
203
|
+
deltaSentFrames = videoSample.framesSent - lastVideoStats.framesSent;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (videoSample.qualityLimitationReason && lastVideoStats?.qualityLimitationReason !== videoSample.qualityLimitationReason) {
|
|
207
|
+
this.emit('qualitylimitationchanged', videoSample.qualityLimitationReason);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const stats: ObservedOutboundVideoTrackStats = {
|
|
211
|
+
...sample,
|
|
212
|
+
rttInMs,
|
|
213
|
+
bitrate,
|
|
214
|
+
ssrc: sample.ssrc,
|
|
215
|
+
|
|
216
|
+
deltaLostPackets,
|
|
217
|
+
deltaSentPackets,
|
|
218
|
+
deltaSentBytes,
|
|
219
|
+
deltaEncodedFrames,
|
|
220
|
+
deltaSentFrames,
|
|
221
|
+
|
|
222
|
+
statsTimestamp,
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
this._stats.set(sample.ssrc, stats);
|
|
226
|
+
|
|
227
|
+
// this.bitrate = [ ...this._stats.values() ].reduce((acc, stat) => acc + stat.bitrate, 0);
|
|
228
|
+
// this.rttInMs = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.rttInMs ?? 0), 0) / (this._stats.size || 1);
|
|
229
|
+
|
|
230
|
+
// this.totalLostPackets = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.packetsLost ?? 0), 0);
|
|
231
|
+
// this.totalSentPackets = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.packetsSent ?? 0), 0);
|
|
232
|
+
// this.totalSentBytes = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.bytesSent ?? 0), 0);
|
|
233
|
+
// this.totalSentFrames = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.deltaSentPackets ?? 0), 0);
|
|
234
|
+
|
|
235
|
+
// this.deltaEncodedFrames = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.deltaEncodedFrames ?? 0), 0);
|
|
236
|
+
// this.deltaSentFrames = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.deltaSentFrames ?? 0), 0);
|
|
237
|
+
// this.deltaLostPackets = [ ...this._stats.values() ].reduce((acc, stat) => acc + stat.deltaLostPackets, 0);
|
|
238
|
+
// this.deltaSentPackets = [ ...this._stats.values() ].reduce((acc, stat) => acc + stat.deltaSentPackets, 0);
|
|
239
|
+
// this.deltaSentBytes = [ ...this._stats.values() ].reduce((acc, stat) => acc + stat.deltaSentBytes, 0);
|
|
240
|
+
|
|
241
|
+
// setting up sfu connection as it is not always available at the first sample
|
|
242
|
+
|
|
243
|
+
this.visited = true;
|
|
244
|
+
this._updated = now;
|
|
245
|
+
this.emit('update', {
|
|
246
|
+
elapsedTimeInMs,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
private _lastUpdateMetrics?: number;
|
|
251
|
+
|
|
252
|
+
public updateMetrics() {
|
|
253
|
+
let maxStatsTimestamp = 0;
|
|
254
|
+
let rttInMsSum = 0;
|
|
255
|
+
let jitterSum = 0;
|
|
256
|
+
let size = 0;
|
|
257
|
+
|
|
258
|
+
this.bitrate = 0;
|
|
259
|
+
this.rttInMs = undefined;
|
|
260
|
+
|
|
261
|
+
this.sendingBitrate = 0;
|
|
262
|
+
this.deltaLostPackets = 0;
|
|
263
|
+
this.deltaSentPackets = 0;
|
|
264
|
+
this.deltaSentBytes = 0;
|
|
265
|
+
this.deltaSentFrames = 0;
|
|
266
|
+
this.deltaEncodedFrames = 0;
|
|
267
|
+
|
|
268
|
+
const highestLayer = { ssrc: 0, bitrate: -1 };
|
|
269
|
+
|
|
270
|
+
for (const [ ssrc, stats ] of this._stats) {
|
|
271
|
+
if (stats.statsTimestamp <= this._lastMaxStatsTimestamp) continue;
|
|
272
|
+
|
|
273
|
+
this.deltaLostPackets += stats.deltaLostPackets ?? 0;
|
|
274
|
+
this.deltaSentPackets += stats.deltaSentPackets ?? 0;
|
|
275
|
+
this.deltaSentBytes += stats.deltaSentBytes ?? 0;
|
|
276
|
+
this.deltaSentFrames += stats.deltaSentFrames ?? 0;
|
|
277
|
+
this.deltaEncodedFrames += stats.deltaEncodedFrames ?? 0;
|
|
278
|
+
this.bitrate += stats.bitrate;
|
|
279
|
+
|
|
280
|
+
maxStatsTimestamp = Math.max(maxStatsTimestamp, stats.statsTimestamp);
|
|
281
|
+
|
|
282
|
+
rttInMsSum += stats.rttInMs ?? 0;
|
|
283
|
+
jitterSum += stats.jitter ?? 0;
|
|
284
|
+
++size;
|
|
285
|
+
|
|
286
|
+
if (stats.bitrate > highestLayer.bitrate) {
|
|
287
|
+
highestLayer.ssrc = ssrc;
|
|
288
|
+
highestLayer.bitrate = stats.bitrate;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const now = Date.now();
|
|
293
|
+
|
|
294
|
+
if (this._lastUpdateMetrics) {
|
|
295
|
+
this.sendingBitrate = (this.deltaSentBytes * 8) / ((now - this._lastUpdateMetrics) / 1000);
|
|
296
|
+
}
|
|
297
|
+
this._lastUpdateMetrics = now;
|
|
298
|
+
this.highestLayer = this._stats.get(highestLayer.ssrc);
|
|
299
|
+
this.totalLostPackets += this.deltaLostPackets;
|
|
300
|
+
this.totalSentPackets += this.deltaSentPackets;
|
|
301
|
+
this.totalSentBytes += this.deltaSentBytes;
|
|
302
|
+
this.totalSentFrames += this.deltaSentFrames;
|
|
303
|
+
|
|
304
|
+
this.rttInMs = rttInMsSum / Math.max(size, 1);
|
|
305
|
+
this.jitter = jitterSum / Math.max(size, 1);
|
|
306
|
+
|
|
307
|
+
this._lastMaxStatsTimestamp = maxStatsTimestamp;
|
|
308
|
+
this._updateQualityScore(maxStatsTimestamp);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
private _updateQualityScore(timestamp: number) {
|
|
312
|
+
const newIssues = this.ωpendingIssuesForScores;
|
|
313
|
+
const score = calculateBaseVideoScore(this, newIssues);
|
|
314
|
+
|
|
315
|
+
if (0 < newIssues.length) {
|
|
316
|
+
this.ωpendingIssuesForScores = [];
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (!score) return (this.score = undefined);
|
|
320
|
+
|
|
321
|
+
score.timestamp = timestamp;
|
|
322
|
+
this.score = score;
|
|
323
|
+
|
|
324
|
+
this.emit('score', this.score);
|
|
325
|
+
}
|
|
326
|
+
}
|