@observertc/observer-js 1.0.1-9d3744d.0 → 1.0.1-b52220e.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 +2 -5
- package/lib/ObservedCall.d.ts.map +1 -1
- package/lib/ObservedCall.js +4 -30
- package/lib/ObservedClient.d.ts +11 -1
- package/lib/ObservedClient.d.ts.map +1 -1
- package/lib/ObservedClient.js +185 -4
- package/lib/ObservedClientEventMonitor.d.ts +89 -0
- package/lib/ObservedClientEventMonitor.d.ts.map +1 -0
- package/lib/ObservedClientEventMonitor.js +247 -0
- package/lib/ObservedDataChannel.d.ts +2 -0
- package/lib/ObservedDataChannel.d.ts.map +1 -1
- package/lib/ObservedDataChannel.js +2 -0
- package/lib/ObservedInboundTrack.d.ts +2 -0
- package/lib/ObservedInboundTrack.d.ts.map +1 -1
- package/lib/ObservedInboundTrack.js +2 -0
- package/lib/ObservedOutboundTrack.d.ts +2 -0
- package/lib/ObservedOutboundTrack.d.ts.map +1 -1
- package/lib/ObservedOutboundTrack.js +2 -0
- package/lib/ObservedPeerConnection.d.ts.map +1 -1
- package/lib/ObservedPeerConnection.js +2 -0
- package/lib/Observer.d.ts +1 -1
- package/lib/Observer.d.ts.map +1 -1
- package/lib/Observer.js +3 -3
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -1
- package/lib/schema/ClientEventTypes.d.ts +60 -0
- package/lib/schema/ClientEventTypes.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/ObservedCall.ts +4 -35
- package/src/ObservedClient.ts +205 -5
- package/src/ObservedClientEventMonitor.ts +301 -0
- package/src/ObservedDataChannel.ts +3 -0
- package/src/ObservedInboundTrack.ts +3 -0
- package/src/ObservedOutboundTrack.ts +3 -0
- package/src/ObservedPeerConnection.ts +2 -0
- package/src/Observer.ts +3 -3
- package/src/index.ts +1 -0
- package/src/schema/ClientEventTypes.ts +64 -0
package/src/ObservedClient.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { ClientMetaTypes } from './schema/ClientMetaTypes';
|
|
|
10
10
|
import { parseJsonAs } from './common/utils';
|
|
11
11
|
import { CalculatedScore } from './scores/CalculatedScore';
|
|
12
12
|
import { Detectors } from './detectors/Detectors';
|
|
13
|
+
import { ObservedClientEventMonitor } from './ObservedClientEventMonitor';
|
|
13
14
|
|
|
14
15
|
const logger = createLogger('ObservedClient');
|
|
15
16
|
|
|
@@ -64,6 +65,7 @@ export class ObservedClient<AppData extends Record<string, unknown> = Record<str
|
|
|
64
65
|
|
|
65
66
|
public joinedAt?: number;
|
|
66
67
|
public leftAt?: number;
|
|
68
|
+
public closedAt?: number;
|
|
67
69
|
// the timestamp of the CLIENT_JOINED event
|
|
68
70
|
public operationSystem?: MetaData.OperationSystem;
|
|
69
71
|
public engine?: MetaData.Engine;
|
|
@@ -136,6 +138,8 @@ export class ObservedClient<AppData extends Record<string, unknown> = Record<str
|
|
|
136
138
|
public readonly mediaDevices: MetaData.MediaDeviceInfo[] = [];
|
|
137
139
|
public issues: ClientIssue[] = [];
|
|
138
140
|
|
|
141
|
+
private _injections: Pick<ClientSample, 'clientEvents' | 'clientIssues' | 'extensionStats' | 'attachments' | 'clientMetaItems'> = {};
|
|
142
|
+
|
|
139
143
|
public constructor(settings: ObservedClientSettings<AppData>, public readonly call: ObservedCall) {
|
|
140
144
|
super();
|
|
141
145
|
this.setMaxListeners(Infinity);
|
|
@@ -160,6 +164,8 @@ export class ObservedClient<AppData extends Record<string, unknown> = Record<str
|
|
|
160
164
|
|
|
161
165
|
Array.from(this.observedPeerConnections.values()).forEach((peerConnection) => peerConnection.close());
|
|
162
166
|
|
|
167
|
+
this.closedAt = Date.now();
|
|
168
|
+
|
|
163
169
|
this.emit('close');
|
|
164
170
|
}
|
|
165
171
|
|
|
@@ -204,9 +210,15 @@ export class ObservedClient<AppData extends Record<string, unknown> = Record<str
|
|
|
204
210
|
this.usingTCP = false;
|
|
205
211
|
this.currentMinRttInMs = undefined;
|
|
206
212
|
this.currentMaxRttInMs = undefined;
|
|
207
|
-
|
|
213
|
+
|
|
214
|
+
this._mergeInjections(sample);
|
|
215
|
+
|
|
216
|
+
const clientEventsPostBuffer: ClientEvent[] = [];
|
|
217
|
+
|
|
208
218
|
for (const clientEvent of sample.clientEvents ?? []) {
|
|
209
|
-
this._processClientEvent(clientEvent);
|
|
219
|
+
this._processClientEvent(clientEvent, clientEventsPostBuffer);
|
|
220
|
+
|
|
221
|
+
this.call.observer.emit('client-event', this, clientEvent);
|
|
210
222
|
}
|
|
211
223
|
|
|
212
224
|
for (const metaData of sample.clientMetaItems ?? []) {
|
|
@@ -280,7 +292,9 @@ export class ObservedClient<AppData extends Record<string, unknown> = Record<str
|
|
|
280
292
|
}
|
|
281
293
|
}
|
|
282
294
|
|
|
283
|
-
|
|
295
|
+
for (const clientEvent of clientEventsPostBuffer) {
|
|
296
|
+
this._processClientEvent(clientEvent);
|
|
297
|
+
}
|
|
284
298
|
|
|
285
299
|
// emit new attachments?
|
|
286
300
|
this.attachments = sample.attachments;
|
|
@@ -327,7 +341,7 @@ export class ObservedClient<AppData extends Record<string, unknown> = Record<str
|
|
|
327
341
|
}
|
|
328
342
|
}
|
|
329
343
|
|
|
330
|
-
private _processClientEvent(event: ClientEvent) {
|
|
344
|
+
private _processClientEvent(event: ClientEvent, postBuffer?: ClientEvent[]) {
|
|
331
345
|
// eslint-disable-next-line no-console
|
|
332
346
|
// console.warn('ClientEvent', event);
|
|
333
347
|
switch (event.type) {
|
|
@@ -356,9 +370,150 @@ export class ObservedClient<AppData extends Record<string, unknown> = Record<str
|
|
|
356
370
|
}
|
|
357
371
|
break;
|
|
358
372
|
}
|
|
373
|
+
case ClientEventTypes.PEER_CONNECTION_OPENED: {
|
|
374
|
+
const payload = parseJsonAs<Record<string, unknown>>(event.payload);
|
|
375
|
+
|
|
376
|
+
if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string') {
|
|
377
|
+
const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
|
|
378
|
+
|
|
379
|
+
if (observedPeerConnection) {
|
|
380
|
+
observedPeerConnection.openedAt = event.timestamp;
|
|
381
|
+
} else if (postBuffer) {
|
|
382
|
+
postBuffer.push(event);
|
|
383
|
+
} else {
|
|
384
|
+
logger.warn('Received PEER_CONNECTION_OPENED event without a corresponding observedPeerConnection', event);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
}
|
|
388
|
+
break;
|
|
389
|
+
}
|
|
390
|
+
case ClientEventTypes.PEER_CONNECTION_CLOSED: {
|
|
391
|
+
const payload = parseJsonAs<Record<string, unknown>>(event.payload);
|
|
392
|
+
|
|
393
|
+
if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string') {
|
|
394
|
+
const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
|
|
395
|
+
|
|
396
|
+
if (observedPeerConnection) {
|
|
397
|
+
observedPeerConnection.closedAt = event.timestamp;
|
|
398
|
+
} else if (postBuffer) {
|
|
399
|
+
postBuffer.push(event);
|
|
400
|
+
} else {
|
|
401
|
+
logger.warn('Received PEER_CONNECTION_CLOSED event without a corresponding observedPeerConnection', event);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
break;
|
|
405
|
+
}
|
|
406
|
+
case ClientEventTypes.MEDIA_TRACK_ADDED: {
|
|
407
|
+
const payload = parseJsonAs<Record<string, unknown>>(event.payload);
|
|
408
|
+
|
|
409
|
+
if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string' && payload?.trackId && typeof payload.trackId === 'string') {
|
|
410
|
+
const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
|
|
411
|
+
const observedTrack = observedPeerConnection?.observedInboundTracks.get(payload.trackId) ?? observedPeerConnection?.observedOutboundTracks.get(payload.trackId);
|
|
412
|
+
|
|
413
|
+
if (observedTrack) {
|
|
414
|
+
observedTrack.addedAt = event.timestamp;
|
|
415
|
+
} else if (postBuffer) {
|
|
416
|
+
postBuffer.push(event);
|
|
417
|
+
} else {
|
|
418
|
+
logger.warn('Received MEDIA_TRACK_ADDED event without a corresponding observedPeerConnection or observedTrack', event);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
break;
|
|
422
|
+
}
|
|
423
|
+
case ClientEventTypes.MEDIA_TRACK_REMOVED: {
|
|
424
|
+
const payload = parseJsonAs<Record<string, unknown>>(event.payload);
|
|
425
|
+
|
|
426
|
+
if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string' && payload?.trackId && typeof payload.trackId === 'string') {
|
|
427
|
+
const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
|
|
428
|
+
const observedTrack = observedPeerConnection?.observedInboundTracks.get(payload.trackId) ?? observedPeerConnection?.observedOutboundTracks.get(payload.trackId);
|
|
429
|
+
|
|
430
|
+
if (observedTrack) {
|
|
431
|
+
observedTrack.removedAt = event.timestamp;
|
|
432
|
+
} else if (postBuffer) {
|
|
433
|
+
postBuffer.push(event);
|
|
434
|
+
} else {
|
|
435
|
+
logger.warn('Received MEDIA_TRACK_REMOVED event without a corresponding observedPeerConnection or observedTrack', event);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
break;
|
|
439
|
+
}
|
|
440
|
+
case ClientEventTypes.DATA_CHANNEL_OPEN: {
|
|
441
|
+
const payload = parseJsonAs<Record<string, unknown>>(event.payload);
|
|
442
|
+
|
|
443
|
+
if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string' && payload?.dataChannelId && typeof payload.dataChannelId === 'string') {
|
|
444
|
+
const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
|
|
445
|
+
const observedDataChannel = observedPeerConnection?.observedDataChannels.get(payload.dataChannelId);
|
|
446
|
+
|
|
447
|
+
if (observedDataChannel) {
|
|
448
|
+
observedDataChannel.addedAt = event.timestamp;
|
|
449
|
+
} else if (postBuffer) {
|
|
450
|
+
postBuffer.push(event);
|
|
451
|
+
} else {
|
|
452
|
+
logger.warn('Received DATA_CHANNEL_OPENED event without a corresponding observedPeerConnection or observedDataChannel', event);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
break;
|
|
456
|
+
}
|
|
457
|
+
case ClientEventTypes.DATA_CHANNEL_CLOSED: {
|
|
458
|
+
const payload = parseJsonAs<Record<string, unknown>>(event.payload);
|
|
459
|
+
|
|
460
|
+
if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string' && payload?.dataChannelId && typeof payload.dataChannelId === 'string') {
|
|
461
|
+
const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
|
|
462
|
+
const observedDataChannel = observedPeerConnection?.observedDataChannels.get(payload.dataChannelId);
|
|
463
|
+
|
|
464
|
+
if (observedDataChannel) {
|
|
465
|
+
observedDataChannel.removedAt = event.timestamp;
|
|
466
|
+
} else if (postBuffer) {
|
|
467
|
+
postBuffer.push(event);
|
|
468
|
+
} else {
|
|
469
|
+
logger.warn('Received DATA_CHANNEL_CLOSE event without a corresponding observedPeerConnection or observedDataChannel', event);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
break;
|
|
473
|
+
}
|
|
474
|
+
|
|
359
475
|
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
public injectMetaData(metaData: ClientMetaData) {
|
|
479
|
+
if (this.closed) return;
|
|
480
|
+
|
|
481
|
+
if (!this._injections.clientMetaItems) this._injections.clientMetaItems = [];
|
|
482
|
+
|
|
483
|
+
this._injections.clientMetaItems.push(metaData);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
public injectEvent(event: ClientEvent) {
|
|
487
|
+
if (this.closed) return;
|
|
488
|
+
|
|
489
|
+
if (!this._injections.clientEvents) this._injections.clientEvents = [];
|
|
360
490
|
|
|
361
|
-
this.
|
|
491
|
+
this._injections.clientEvents.push(event);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
public injectIssue(issue: ClientIssue) {
|
|
495
|
+
if (this.closed) return;
|
|
496
|
+
|
|
497
|
+
if (!this._injections.clientIssues) this._injections.clientIssues = [];
|
|
498
|
+
|
|
499
|
+
this._injections.clientIssues.push(issue);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
public injectExtensionStat(stat: ExtensionStat) {
|
|
503
|
+
if (this.closed) return;
|
|
504
|
+
|
|
505
|
+
if (!this._injections.extensionStats) this._injections.extensionStats = [];
|
|
506
|
+
|
|
507
|
+
this._injections.extensionStats.push(stat);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
public injectAttachment(key: string, value: unknown) {
|
|
511
|
+
if (this.closed) return;
|
|
512
|
+
|
|
513
|
+
if (!this._injections.attachments) this._injections.attachments = {};
|
|
514
|
+
|
|
515
|
+
this._injections.attachments[key] = value;
|
|
516
|
+
|
|
362
517
|
}
|
|
363
518
|
|
|
364
519
|
public addMetadata(metadata: ClientMetaData) {
|
|
@@ -423,6 +578,51 @@ export class ObservedClient<AppData extends Record<string, unknown> = Record<str
|
|
|
423
578
|
return observedPeerConnection;
|
|
424
579
|
}
|
|
425
580
|
|
|
581
|
+
public createEventMonitor<CTX = unknown>(ctx?: CTX): ObservedClientEventMonitor<CTX> {
|
|
582
|
+
return new ObservedClientEventMonitor<CTX>(this, ctx ?? {} as CTX);
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
private _mergeInjections(sample: ClientSample): ClientSample {
|
|
586
|
+
if (this.closed) return sample;
|
|
587
|
+
|
|
588
|
+
if (this._injections.clientEvents) {
|
|
589
|
+
if (!sample.clientEvents) sample.clientEvents = [];
|
|
590
|
+
sample.clientEvents.push(...this._injections.clientEvents);
|
|
591
|
+
|
|
592
|
+
this._injections.clientEvents = undefined;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
if (this._injections.clientIssues) {
|
|
596
|
+
if (!sample.clientIssues) sample.clientIssues = [];
|
|
597
|
+
sample.clientIssues.push(...this._injections.clientIssues);
|
|
598
|
+
|
|
599
|
+
this._injections.clientIssues = undefined;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
if (this._injections.extensionStats) {
|
|
603
|
+
if (!sample.extensionStats) sample.extensionStats = [];
|
|
604
|
+
sample.extensionStats.push(...this._injections.extensionStats);
|
|
605
|
+
|
|
606
|
+
this._injections.extensionStats = undefined;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
if (this._injections.attachments) {
|
|
610
|
+
if (!sample.attachments) sample.attachments = {};
|
|
611
|
+
Object.assign(sample.attachments, this._injections.attachments);
|
|
612
|
+
|
|
613
|
+
this._injections.attachments = undefined;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
if (this._injections.clientMetaItems) {
|
|
617
|
+
if (!sample.clientMetaItems) sample.clientMetaItems = [];
|
|
618
|
+
sample.clientMetaItems.push(...this._injections.clientMetaItems);
|
|
619
|
+
|
|
620
|
+
this._injections.clientMetaItems = undefined;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
return sample;
|
|
624
|
+
}
|
|
625
|
+
|
|
426
626
|
// public resetSummaryMetrics() {
|
|
427
627
|
// this.totalDataChannelBytesReceived = 0;
|
|
428
628
|
// this.totalDataChannelBytesSent = 0;
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { ObservedCertificate } from './ObservedCertificate';
|
|
2
|
+
import { ObservedClient } from './ObservedClient';
|
|
3
|
+
import { ObservedCodec } from './ObservedCodec';
|
|
4
|
+
import { ObservedDataChannel } from './ObservedDataChannel';
|
|
5
|
+
import { ObservedIceCandidate } from './ObservedIceCandidate';
|
|
6
|
+
import { ObservedIceCandidatePair } from './ObservedIceCandidatePair';
|
|
7
|
+
import { ObservedIceTransport } from './ObservedIceTransport';
|
|
8
|
+
import { ObservedInboundRtp } from './ObservedInboundRtp';
|
|
9
|
+
import { ObservedInboundTrack } from './ObservedInboundTrack';
|
|
10
|
+
import { ObservedMediaPlayout } from './ObservedMediaPlayout';
|
|
11
|
+
import { ObservedMediaSource } from './ObservedMediaSource';
|
|
12
|
+
import { ObservedOutboundRtp } from './ObservedOutboundRtp';
|
|
13
|
+
import { ObservedOutboundTrack } from './ObservedOutboundTrack';
|
|
14
|
+
import { ObservedPeerConnection } from './ObservedPeerConnection';
|
|
15
|
+
import { ClientIssue, ClientMetaData, ExtensionStat } from './schema/ClientSample';
|
|
16
|
+
|
|
17
|
+
export class ObservedClientEventMonitor<Context> {
|
|
18
|
+
public constructor(
|
|
19
|
+
public readonly observedClient: ObservedClient,
|
|
20
|
+
public readonly context: Context,
|
|
21
|
+
) {
|
|
22
|
+
this._onPeerConnconnectionAdded = this._onPeerConnconnectionAdded.bind(this);
|
|
23
|
+
this._onPeerConnectionRemoved = this._onPeerConnectionRemoved.bind(this);
|
|
24
|
+
this._onCertificateAdded = this._onCertificateAdded.bind(this);
|
|
25
|
+
this._onCertificateRemoved = this._onCertificateRemoved.bind(this);
|
|
26
|
+
this._onInboundTrackAdded = this._onInboundTrackAdded.bind(this);
|
|
27
|
+
this._onInboundTrackRemoved = this._onInboundTrackRemoved.bind(this);
|
|
28
|
+
this._onOutboundTrackAdded = this._onOutboundTrackAdded.bind(this);
|
|
29
|
+
this._onOutboundTrackRemoved = this._onOutboundTrackRemoved.bind(this);
|
|
30
|
+
this._onInboundRtpAdded = this._onInboundRtpAdded.bind(this);
|
|
31
|
+
this._onInboundRtpRemoved = this._onInboundRtpRemoved.bind(this);
|
|
32
|
+
this._onOutboundRtpAdded = this._onOutboundRtpAdded.bind(this);
|
|
33
|
+
this._onOutboundRtpRemoved = this._onOutboundRtpRemoved.bind(this);
|
|
34
|
+
this._onDataChannelAdded = this._onDataChannelAdded.bind(this);
|
|
35
|
+
this._onDataChannelRemoved = this._onDataChannelRemoved.bind(this);
|
|
36
|
+
this._onAddedIceTransport = this._onAddedIceTransport.bind(this);
|
|
37
|
+
this._onRemovedIceTransport = this._onRemovedIceTransport.bind(this);
|
|
38
|
+
this._onIceCandidateAdded = this._onIceCandidateAdded.bind(this);
|
|
39
|
+
this._onIceCandidateRemoved = this._onIceCandidateRemoved.bind(this);
|
|
40
|
+
this._onAddedIceCandidatePair = this._onAddedIceCandidatePair.bind(this);
|
|
41
|
+
this._onRemovedIceCandidatePair = this._onRemovedIceCandidatePair.bind(this);
|
|
42
|
+
this._onAddedMediaCodec = this._onAddedMediaCodec.bind(this);
|
|
43
|
+
this._onRemovedMediaCodec = this._onRemovedMediaCodec.bind(this);
|
|
44
|
+
this._onAddedMediaPlayout = this._onAddedMediaPlayout.bind(this);
|
|
45
|
+
this._onRemovedMediaPlayout = this._onRemovedMediaPlayout.bind(this);
|
|
46
|
+
this._onMediaSourceAdded = this._onMediaSourceAdded.bind(this);
|
|
47
|
+
this._onMediaSourceRemoved = this._onMediaSourceRemoved.bind(this);
|
|
48
|
+
this._onClientClosed = this._onClientClosed.bind(this);
|
|
49
|
+
this._onClientIssue = this._onClientIssue.bind(this);
|
|
50
|
+
this._onClientMetadata = this._onClientMetadata.bind(this);
|
|
51
|
+
this._onClientJoined = this._onClientJoined.bind(this);
|
|
52
|
+
this._onClientLeft = this._onClientLeft.bind(this);
|
|
53
|
+
this._onUserMediaError = this._onUserMediaError.bind(this);
|
|
54
|
+
this._onUsingTurn = this._onUsingTurn.bind(this);
|
|
55
|
+
|
|
56
|
+
this.observedClient.on('newpeerconnection', this._onPeerConnconnectionAdded);
|
|
57
|
+
this.observedClient.on('issue', this._onClientIssue);
|
|
58
|
+
this.observedClient.on('metaData', this._onClientMetadata);
|
|
59
|
+
this.observedClient.on('joined', this._onClientJoined);
|
|
60
|
+
this.observedClient.on('left', this._onClientLeft);
|
|
61
|
+
this.observedClient.on('rejoined', this._onClientJoined);
|
|
62
|
+
this.observedClient.on('usermediaerror', this._onUserMediaError);
|
|
63
|
+
this.observedClient.on('usingturn', this._onUsingTurn);
|
|
64
|
+
|
|
65
|
+
this.observedClient.once('close', this._onClientClosed);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public onClientClosed?: (client: ObservedClient, ctx: Context) => void;
|
|
69
|
+
private _onClientClosed() {
|
|
70
|
+
this.onClientClosed?.(this.observedClient, this.context);
|
|
71
|
+
|
|
72
|
+
this.observedClient.off('newpeerconnection', this._onPeerConnconnectionAdded);
|
|
73
|
+
this.observedClient.off('issue', this._onClientIssue);
|
|
74
|
+
this.observedClient.off('metaData', this._onClientMetadata);
|
|
75
|
+
this.observedClient.off('joined', this._onClientJoined);
|
|
76
|
+
this.observedClient.off('left', this._onClientLeft);
|
|
77
|
+
this.observedClient.off('rejoined', this._onClientJoined);
|
|
78
|
+
this.observedClient.off('usermediaerror', this._onUserMediaError);
|
|
79
|
+
this.observedClient.off('usingturn', this._onUsingTurn);
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public onPeerConnectionAdded?: (peerConnection: ObservedPeerConnection, ctx: Context) => void;
|
|
84
|
+
private _onPeerConnconnectionAdded(peerConnection: ObservedPeerConnection) {
|
|
85
|
+
this.onPeerConnectionAdded?.(peerConnection, this.context);
|
|
86
|
+
|
|
87
|
+
peerConnection.once('close', () => this._onPeerConnectionRemoved(peerConnection));
|
|
88
|
+
|
|
89
|
+
peerConnection.on('added-certificate', this._onCertificateAdded);
|
|
90
|
+
peerConnection.on('removed-certificate', this._onCertificateRemoved);
|
|
91
|
+
peerConnection.on('added-inbound-track', this._onInboundTrackAdded);
|
|
92
|
+
peerConnection.on('removed-inbound-track', this._onInboundTrackRemoved);
|
|
93
|
+
peerConnection.on('added-outbound-track', this._onOutboundTrackAdded);
|
|
94
|
+
peerConnection.on('removed-outbound-track', this._onOutboundTrackRemoved);
|
|
95
|
+
peerConnection.on('added-inbound-rtp', this._onInboundRtpAdded);
|
|
96
|
+
peerConnection.on('removed-inbound-rtp', this._onInboundRtpRemoved);
|
|
97
|
+
peerConnection.on('added-outbound-rtp', this._onOutboundRtpAdded);
|
|
98
|
+
peerConnection.on('removed-outbound-rtp', this._onOutboundRtpRemoved);
|
|
99
|
+
peerConnection.on('added-data-channel', this._onDataChannelAdded);
|
|
100
|
+
peerConnection.on('removed-data-channel', this._onDataChannelRemoved);
|
|
101
|
+
peerConnection.on('added-ice-transport', this._onAddedIceTransport);
|
|
102
|
+
peerConnection.on('removed-ice-transport', this._onRemovedIceTransport);
|
|
103
|
+
peerConnection.on('added-ice-candidate', this._onIceCandidateAdded);
|
|
104
|
+
peerConnection.on('removed-ice-candidate', this._onIceCandidateRemoved);
|
|
105
|
+
peerConnection.on('added-ice-candidate-pair', this._onAddedIceCandidatePair);
|
|
106
|
+
peerConnection.on('removed-ice-candidate-pair', this._onRemovedIceCandidatePair);
|
|
107
|
+
peerConnection.on('added-codec', this._onAddedMediaCodec);
|
|
108
|
+
peerConnection.on('removed-codec', this._onRemovedMediaCodec);
|
|
109
|
+
peerConnection.on('added-media-playout', this._onAddedMediaPlayout);
|
|
110
|
+
peerConnection.on('removed-media-playout', this._onRemovedMediaPlayout);
|
|
111
|
+
peerConnection.on('added-media-source', this._onMediaSourceAdded);
|
|
112
|
+
peerConnection.on('removed-media-source', this._onMediaSourceRemoved);
|
|
113
|
+
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public onPeerConnectionRemoved?: (peerConnection: ObservedPeerConnection, ctx: Context) => void;
|
|
117
|
+
private _onPeerConnectionRemoved(peerConnection: ObservedPeerConnection) {
|
|
118
|
+
this.onPeerConnectionRemoved?.(peerConnection, this.context);
|
|
119
|
+
|
|
120
|
+
peerConnection.off('added-certificate', this._onCertificateAdded);
|
|
121
|
+
peerConnection.off('removed-certificate', this._onCertificateRemoved);
|
|
122
|
+
peerConnection.off('added-inbound-track', this._onInboundTrackAdded);
|
|
123
|
+
peerConnection.off('removed-inbound-track', this._onInboundTrackRemoved);
|
|
124
|
+
peerConnection.off('added-outbound-track', this._onOutboundTrackAdded);
|
|
125
|
+
peerConnection.off('removed-outbound-track', this._onOutboundTrackRemoved);
|
|
126
|
+
peerConnection.off('added-inbound-rtp', this._onInboundRtpAdded);
|
|
127
|
+
peerConnection.off('removed-inbound-rtp', this._onInboundRtpRemoved);
|
|
128
|
+
peerConnection.off('added-outbound-rtp', this._onOutboundRtpAdded);
|
|
129
|
+
peerConnection.off('removed-outbound-rtp', this._onOutboundRtpRemoved);
|
|
130
|
+
peerConnection.off('added-data-channel', this._onDataChannelAdded);
|
|
131
|
+
peerConnection.off('removed-data-channel', this._onDataChannelRemoved);
|
|
132
|
+
peerConnection.off('added-ice-transport', this._onAddedIceTransport);
|
|
133
|
+
peerConnection.off('removed-ice-transport', this._onRemovedIceTransport);
|
|
134
|
+
peerConnection.off('added-ice-candidate', this._onIceCandidateAdded);
|
|
135
|
+
peerConnection.off('removed-ice-candidate', this._onIceCandidateRemoved);
|
|
136
|
+
peerConnection.off('added-ice-candidate-pair', this._onAddedIceCandidatePair);
|
|
137
|
+
peerConnection.off('removed-ice-candidate-pair', this._onRemovedIceCandidatePair);
|
|
138
|
+
peerConnection.off('added-codec', this._onAddedMediaCodec);
|
|
139
|
+
peerConnection.off('removed-codec', this._onRemovedMediaCodec);
|
|
140
|
+
peerConnection.off('added-media-playout', this._onAddedMediaPlayout);
|
|
141
|
+
peerConnection.off('removed-media-playout', this._onRemovedMediaPlayout);
|
|
142
|
+
peerConnection.off('added-media-source', this._onMediaSourceAdded);
|
|
143
|
+
peerConnection.off('removed-media-source', this._onMediaSourceRemoved);
|
|
144
|
+
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
public onCertificateAdded?: (certificate: ObservedCertificate, ctx: Context) => void;
|
|
148
|
+
private _onCertificateAdded(certificate: ObservedCertificate) {
|
|
149
|
+
this.onCertificateAdded?.(certificate, this.context);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
public onCertificateRemoved?: (certificate: ObservedCertificate, ctx: Context) => void;
|
|
153
|
+
private _onCertificateRemoved(certificate: ObservedCertificate) {
|
|
154
|
+
this.onCertificateRemoved?.(certificate, this.context);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
public onInboundTrackAdded?: (inboundTrack: ObservedInboundTrack, ctx: Context) => void;
|
|
158
|
+
private _onInboundTrackAdded(inboundTrack: ObservedInboundTrack) {
|
|
159
|
+
this.onInboundTrackAdded?.(inboundTrack, this.context);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
public onInboundTrackRemoved?: (inboundTrack: ObservedInboundTrack, ctx: Context) => void;
|
|
163
|
+
private _onInboundTrackRemoved(inboundTrack: ObservedInboundTrack) {
|
|
164
|
+
this.onInboundTrackRemoved?.(inboundTrack, this.context);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
public onOutboundTrackAdded?: (outboundTrack: ObservedOutboundTrack, ctx: Context) => void;
|
|
168
|
+
private _onOutboundTrackAdded(outboundTrack: ObservedOutboundTrack) {
|
|
169
|
+
this.onOutboundTrackAdded?.(outboundTrack, this.context);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
public onOutboundTrackRemoved?: (outboundTrack: ObservedOutboundTrack, ctx: Context) => void;
|
|
173
|
+
private _onOutboundTrackRemoved(outboundTrack: ObservedOutboundTrack) {
|
|
174
|
+
this.onOutboundTrackRemoved?.(outboundTrack, this.context);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
public onInboundRtpAdded?: (inboundRtp: ObservedInboundRtp, ctx: Context) => void;
|
|
178
|
+
private _onInboundRtpAdded(inboundRtp: ObservedInboundRtp) {
|
|
179
|
+
this.onInboundRtpAdded?.(inboundRtp, this.context);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
public onInboundRtpRemoved?: (inboundRtp: ObservedInboundRtp, ctx: Context) => void;
|
|
183
|
+
private _onInboundRtpRemoved(inboundRtp: ObservedInboundRtp) {
|
|
184
|
+
this.onInboundRtpRemoved?.(inboundRtp, this.context);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
public onOutboundRtpAdded?: (outboundRtp: ObservedOutboundRtp, ctx: Context) => void;
|
|
188
|
+
private _onOutboundRtpAdded(outboundRtp: ObservedOutboundRtp) {
|
|
189
|
+
this.onOutboundRtpAdded?.(outboundRtp, this.context);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
public onOutboundRtpRemoved?: (outboundRtp: ObservedOutboundRtp, ctx: Context) => void;
|
|
193
|
+
private _onOutboundRtpRemoved(outboundRtp: ObservedOutboundRtp) {
|
|
194
|
+
this.onOutboundRtpRemoved?.(outboundRtp, this.context);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
public onDataChannelAdded?: (dataChannel: ObservedDataChannel, ctx: Context) => void;
|
|
198
|
+
private _onDataChannelAdded(dataChannel: ObservedDataChannel) {
|
|
199
|
+
this.onDataChannelAdded?.(dataChannel, this.context);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
public onDataChannelRemoved?: (dataChannel: ObservedDataChannel, ctx: Context) => void;
|
|
203
|
+
private _onDataChannelRemoved(dataChannel: ObservedDataChannel) {
|
|
204
|
+
this.onDataChannelRemoved?.(dataChannel, this.context);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
public onAddedIceTransport?: (iceTransport: ObservedIceTransport, ctx: Context) => void;
|
|
208
|
+
private _onAddedIceTransport(iceTransport: ObservedIceTransport) {
|
|
209
|
+
this.onAddedIceTransport?.(iceTransport, this.context);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
public onRemovedIceTransport?: (iceTransport: ObservedIceTransport, ctx: Context) => void;
|
|
213
|
+
private _onRemovedIceTransport(iceTransport: ObservedIceTransport) {
|
|
214
|
+
this.onRemovedIceTransport?.(iceTransport, this.context);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
public onIceCandidateAdded?: (iceCandidate: ObservedIceCandidate, ctx: Context) => void;
|
|
218
|
+
private _onIceCandidateAdded(iceCandidate: ObservedIceCandidate) {
|
|
219
|
+
this.onIceCandidateAdded?.(iceCandidate, this.context);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
public onIceCandidateRemoved?: (iceCandidate: ObservedIceCandidate, ctx: Context) => void;
|
|
223
|
+
private _onIceCandidateRemoved(iceCandidate: ObservedIceCandidate) {
|
|
224
|
+
this.onIceCandidateRemoved?.(iceCandidate, this.context);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
public onAddedIceCandidatePair?: (candidatePair: ObservedIceCandidatePair, ctx: Context) => void;
|
|
228
|
+
private _onAddedIceCandidatePair(candidatePair: ObservedIceCandidatePair) {
|
|
229
|
+
this.onAddedIceCandidatePair?.(candidatePair, this.context);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
public onRemovedIceCandidatePair?: (candidatePair: ObservedIceCandidatePair, ctx: Context) => void;
|
|
233
|
+
private _onRemovedIceCandidatePair(candidatePair: ObservedIceCandidatePair) {
|
|
234
|
+
this.onRemovedIceCandidatePair?.(candidatePair, this.context);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
public onAddedMediaCodec?: (codec: ObservedCodec, ctx: Context) => void;
|
|
238
|
+
private _onAddedMediaCodec(codec: ObservedCodec) {
|
|
239
|
+
this.onAddedMediaCodec?.(codec, this.context);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
public onRemovedMediaCodec?: (codec: ObservedCodec, ctx: Context) => void;
|
|
243
|
+
private _onRemovedMediaCodec(codec: ObservedCodec) {
|
|
244
|
+
this.onRemovedMediaCodec?.(codec, this.context);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
public onAddedMediaPlayout?: (mediaPlayout: ObservedMediaPlayout, ctx: Context) => void;
|
|
248
|
+
private _onAddedMediaPlayout(mediaPlayout: ObservedMediaPlayout) {
|
|
249
|
+
this.onAddedMediaPlayout?.(mediaPlayout, this.context);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
public onRemovedMediaPlayout?: (mediaPlayout: ObservedMediaPlayout, ctx: Context) => void;
|
|
253
|
+
private _onRemovedMediaPlayout(mediaPlayout: ObservedMediaPlayout) {
|
|
254
|
+
this.onRemovedMediaPlayout?.(mediaPlayout, this.context);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
public onMediaSourceAdded?: (mediaSource: ObservedMediaSource, ctx: Context) => void;
|
|
258
|
+
private _onMediaSourceAdded(mediaSource: ObservedMediaSource) {
|
|
259
|
+
this.onMediaSourceAdded?.(mediaSource, this.context);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
public onMediaSourceRemoved?: (mediaSource: ObservedMediaSource, ctx: Context) => void;
|
|
263
|
+
private _onMediaSourceRemoved(mediaSource: ObservedMediaSource) {
|
|
264
|
+
this.onMediaSourceRemoved?.(mediaSource, this.context);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
public onClientIssue?: (issue: ClientIssue, ctx: Context) => void;
|
|
268
|
+
private _onClientIssue(issue: ClientIssue) {
|
|
269
|
+
this.onClientIssue?.(issue, this.context);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
public onClientMetadata?: (metadata: ClientMetaData, ctx: Context) => void;
|
|
273
|
+
private _onClientMetadata(metadata: ClientMetaData) {
|
|
274
|
+
this.onClientMetadata?.(metadata, this.context);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
public onClientExtensionStats?: (extensionStats: ExtensionStat, ctx: Context) => void;
|
|
278
|
+
private _onClientExtensionStats(extensionStats: ExtensionStat) {
|
|
279
|
+
this.onClientExtensionStats?.(extensionStats, this.context);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
public onClientJoined?: (client: ObservedClient, ctx: Context) => void;
|
|
283
|
+
private _onClientJoined() {
|
|
284
|
+
this.onClientJoined?.(this.observedClient, this.context);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
public onClientLeft?: (client: ObservedClient, ctx: Context) => void;
|
|
288
|
+
private _onClientLeft() {
|
|
289
|
+
this.onClientLeft?.(this.observedClient, this.context);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
public onUserMediaError?: (error: string, observedClient: ObservedClient, ctx: Context) => void;
|
|
293
|
+
private _onUserMediaError(error: string) {
|
|
294
|
+
this.onUserMediaError?.(error, this.observedClient, this.context);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
public onUsingTurn?: (client: ObservedClient, ctx: Context) => void;
|
|
298
|
+
private _onUsingTurn() {
|
|
299
|
+
this.onUsingTurn?.(this.observedClient, this.context);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
@@ -16,6 +16,9 @@ export class ObservedDataChannel implements DataChannelStats {
|
|
|
16
16
|
bytesReceived?: number | undefined;
|
|
17
17
|
attachments?: Record<string, unknown> | undefined;
|
|
18
18
|
|
|
19
|
+
public addedAt?: number | undefined;
|
|
20
|
+
public removedAt?: number | undefined;
|
|
21
|
+
|
|
19
22
|
public deltaBytesSent = 0;
|
|
20
23
|
public deltaBytesReceived = 0;
|
|
21
24
|
public deltaMessagesSent = 0;
|
|
@@ -16,6 +16,9 @@ export class ObservedInboundTrack implements InboundTrackSample {
|
|
|
16
16
|
|
|
17
17
|
private _visited = false;
|
|
18
18
|
|
|
19
|
+
public addedAt?: number | undefined;
|
|
20
|
+
public removedAt?: number | undefined;
|
|
21
|
+
|
|
19
22
|
attachments?: Record<string, unknown> | undefined;
|
|
20
23
|
|
|
21
24
|
constructor(
|
package/src/Observer.ts
CHANGED
|
@@ -54,7 +54,7 @@ export class Observer extends EventEmitter {
|
|
|
54
54
|
public totalRttGtOrEq300Measurements = 0;
|
|
55
55
|
public totalClientIssues = 0;
|
|
56
56
|
|
|
57
|
-
public
|
|
57
|
+
public numberOfClientsUsingTurn = 0;
|
|
58
58
|
public numberOfClients = 0;
|
|
59
59
|
public numberOfInboundRtpStreams = 0;
|
|
60
60
|
public numberOfOutboundRtpStreams = 0;
|
|
@@ -186,7 +186,7 @@ export class Observer extends EventEmitter {
|
|
|
186
186
|
this.numberOfPeerConnections = 0;
|
|
187
187
|
this.numberOfDataChannels = 0;
|
|
188
188
|
this.numberOfClients = 0;
|
|
189
|
-
this.
|
|
189
|
+
this.numberOfClientsUsingTurn = 0;
|
|
190
190
|
|
|
191
191
|
for (const call of this.observedCalls.values()) {
|
|
192
192
|
this.numberOfInboundRtpStreams += call.numberOfInboundRtpStreams;
|
|
@@ -194,7 +194,7 @@ export class Observer extends EventEmitter {
|
|
|
194
194
|
this.numberOfPeerConnections += call.numberOfPeerConnections;
|
|
195
195
|
this.numberOfDataChannels += call.numberOfDataChannels;
|
|
196
196
|
this.numberOfClients += call.numberOfClients;
|
|
197
|
-
this.
|
|
197
|
+
this.numberOfClientsUsingTurn += call.clientsUsedTurn.size;
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
this.observedTURN.update();
|
package/src/index.ts
CHANGED
|
@@ -23,5 +23,6 @@ export { ClientEventTypes } from './schema/ClientEventTypes';
|
|
|
23
23
|
export { ClientMetaTypes } from './schema/ClientMetaTypes';
|
|
24
24
|
export { ClientSample } from './schema/ClientSample';
|
|
25
25
|
export { ScoreCalculator } from './scores/ScoreCalculator';
|
|
26
|
+
export { ObservedClientEventMonitor } from './ObservedClientEventMonitor';
|
|
26
27
|
|
|
27
28
|
export { Middleware } from './common/Middleware';
|