@observertc/observer-js 1.0.1-c3edea3.0 → 1.0.1-ec27289.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 +41 -7
- package/lib/ObservedCall.d.ts.map +1 -1
- package/lib/ObservedCall.js +125 -13
- package/lib/ObservedCallSummary.d.ts +18 -0
- package/lib/ObservedCallSummary.d.ts.map +1 -0
- package/lib/ObservedClient.d.ts +70 -11
- package/lib/ObservedClient.d.ts.map +1 -1
- package/lib/ObservedClient.js +394 -72
- package/lib/ObservedClientEventMonitor.d.ts +89 -0
- package/lib/ObservedClientEventMonitor.d.ts.map +1 -0
- package/lib/ObservedClientEventMonitor.js +247 -0
- package/lib/ObservedClientSummary.d.ts +23 -0
- package/lib/ObservedClientSummary.d.ts.map +1 -0
- package/lib/ObservedClientSummary.js +2 -0
- package/lib/ObservedDataChannel.d.ts +6 -0
- package/lib/ObservedDataChannel.d.ts.map +1 -1
- package/lib/ObservedDataChannel.js +30 -0
- package/lib/ObservedIceCandidatePair.d.ts +4 -0
- package/lib/ObservedIceCandidatePair.d.ts.map +1 -1
- package/lib/ObservedIceCandidatePair.js +28 -0
- package/lib/ObservedIceTransport.d.ts +4 -0
- package/lib/ObservedIceTransport.d.ts.map +1 -1
- package/lib/ObservedIceTransport.js +28 -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 +14 -2
- package/lib/ObservedPeerConnection.d.ts.map +1 -1
- package/lib/ObservedPeerConnection.js +106 -14
- package/lib/ObservedTURN.d.ts +31 -0
- package/lib/ObservedTURN.d.ts.map +1 -0
- package/lib/ObservedTURN.js +58 -0
- package/lib/ObservedTurnServer.d.ts +25 -0
- package/lib/ObservedTurnServer.d.ts.map +1 -0
- package/lib/ObservedTurnServer.js +59 -0
- package/lib/Observer.d.ts +38 -21
- package/lib/Observer.d.ts.map +1 -1
- package/lib/Observer.js +114 -40
- package/lib/ObserverSummary.d.ts +13 -0
- package/lib/ObserverSummary.d.ts.map +1 -0
- package/lib/ObserverSummary.js +2 -0
- package/lib/common/utils.d.ts +2 -1
- package/lib/common/utils.d.ts.map +1 -1
- package/lib/common/utils.js +11 -3
- package/lib/index.d.ts +5 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +7 -1
- package/lib/schema/ClientEventTypes.d.ts +100 -0
- package/lib/schema/ClientEventTypes.d.ts.map +1 -0
- package/lib/schema/ClientEventTypes.js +38 -0
- package/lib/schema/{metaTypes.d.ts → ClientMetaTypes.d.ts} +2 -2
- package/lib/schema/ClientMetaTypes.d.ts.map +1 -0
- package/lib/schema/ClientMetaTypes.js +16 -0
- package/lib/updaters/CallUpdater.d.ts.map +1 -0
- package/lib/updaters/CallUpdater.js +2 -0
- package/lib/updaters/ObserverUpdater.d.ts +5 -0
- package/lib/updaters/ObserverUpdater.d.ts.map +1 -0
- package/lib/updaters/ObserverUpdater.js +2 -0
- package/lib/updaters/OnAllCallObserverUpdater_.d.ts +13 -0
- package/lib/updaters/OnAllCallObserverUpdater_.d.ts.map +1 -0
- package/lib/updaters/OnAllCallObserverUpdater_.js +38 -0
- package/lib/updaters/OnAllClientCallUpdater.d.ts +13 -0
- package/lib/updaters/OnAllClientCallUpdater.d.ts.map +1 -0
- package/lib/updaters/OnAllClientCallUpdater.js +37 -0
- package/lib/updaters/OnAnyCallObserverUpdater_.d.ts +11 -0
- package/lib/updaters/OnAnyCallObserverUpdater_.d.ts.map +1 -0
- package/lib/updaters/OnAnyCallObserverUpdater_.js +27 -0
- package/lib/updaters/OnAnyClientCallUpdater.d.ts +11 -0
- package/lib/updaters/OnAnyClientCallUpdater.d.ts.map +1 -0
- package/lib/updaters/OnAnyClientCallUpdater.js +27 -0
- package/lib/updaters/OnIntervalUpdater.d.ts +10 -0
- package/lib/updaters/OnIntervalUpdater.d.ts.map +1 -0
- package/lib/updaters/OnIntervalUpdater.js +17 -0
- package/lib/updaters/Updater.d.ts +6 -0
- package/lib/updaters/Updater.d.ts.map +1 -0
- package/lib/updaters/Updater.js +2 -0
- package/package.json +1 -1
- package/src/ObservedCall.ts +205 -16
- package/src/ObservedCallSummary.ts +22 -0
- package/src/ObservedClient.ts +492 -78
- package/src/ObservedClientEventMonitor.ts +301 -0
- package/src/ObservedClientSummary.ts +24 -0
- package/src/ObservedDataChannel.ts +32 -0
- package/src/ObservedIceCandidatePair.ts +26 -0
- package/src/ObservedIceTransport.ts +29 -0
- package/src/ObservedInboundTrack.ts +3 -0
- package/src/ObservedOutboundTrack.ts +3 -0
- package/src/ObservedPeerConnection.ts +120 -16
- package/src/ObservedTURN.ts +86 -0
- package/src/ObservedTurnServer.ts +72 -0
- package/src/Observer.ts +164 -64
- package/src/ObserverSummary.ts +15 -0
- package/src/common/utils.ts +12 -2
- package/src/index.ts +5 -0
- package/src/schema/ClientEventTypes.ts +112 -0
- package/src/schema/{metaTypes.ts → ClientMetaTypes.ts} +1 -1
- package/src/updaters/ObserverUpdater.ts +5 -0
- package/src/updaters/OnAllCallObserverUpdater_.ts +46 -0
- package/src/updaters/OnAllClientCallUpdater.ts +46 -0
- package/src/updaters/OnAnyCallObserverUpdater_.ts +32 -0
- package/src/updaters/OnAnyClientCallUpdater.ts +32 -0
- package/src/updaters/OnIntervalUpdater.ts +19 -0
- package/src/updaters/Updater.ts +5 -0
- package/tsconfig.json +1 -1
- package/lib/schema/eventTypes.d.ts +0 -33
- package/lib/schema/eventTypes.d.ts.map +0 -1
- package/lib/schema/eventTypes.js +0 -38
- package/lib/schema/metaTypes.d.ts.map +0 -1
- package/lib/schema/metaTypes.js +0 -16
- package/lib/utils/CallUpdater.d.ts.map +0 -1
- package/lib/utils/OnAllClientCallUpdater.d.ts +0 -16
- package/lib/utils/OnAllClientCallUpdater.d.ts.map +0 -1
- package/lib/utils/OnAllClientCallUpdater.js +0 -58
- package/lib/utils/onAnyClientCallUpdater.d.ts +0 -14
- package/lib/utils/onAnyClientCallUpdater.d.ts.map +0 -1
- package/lib/utils/onAnyClientCallUpdater.js +0 -51
- package/src/schema/eventTypes.ts +0 -36
- package/src/utils/OnAllClientCallUpdater.ts +0 -68
- package/src/utils/onAnyClientCallUpdater.ts +0 -59
- /package/lib/{utils/CallUpdater.js → ObservedCallSummary.js} +0 -0
- /package/lib/{utils → updaters}/CallUpdater.d.ts +0 -0
- /package/src/{utils → updaters}/CallUpdater.ts +0 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OnAnyCallObserverUpdater = void 0;
|
|
4
|
+
class OnAnyCallObserverUpdater {
|
|
5
|
+
observver;
|
|
6
|
+
name = 'OnAnyCallObserverUpdater';
|
|
7
|
+
description = 'Call Observer\'s update() method on any of the ObservedCall is updated';
|
|
8
|
+
constructor(observver) {
|
|
9
|
+
this.observver = observver;
|
|
10
|
+
this._onNewObservedCall = this._onNewObservedCall.bind(this);
|
|
11
|
+
this.observver.once('close', () => {
|
|
12
|
+
this.observver.off('newcall', this._onNewObservedCall);
|
|
13
|
+
});
|
|
14
|
+
this.observver.on('newcall', this._onNewObservedCall);
|
|
15
|
+
}
|
|
16
|
+
close() {
|
|
17
|
+
// do nothing, because we unsubscribe once close is emitted from observer
|
|
18
|
+
}
|
|
19
|
+
_onNewObservedCall(observedCall) {
|
|
20
|
+
const onUpdate = () => this.observver.update();
|
|
21
|
+
observedCall.once('close', () => {
|
|
22
|
+
observedCall.off('update', onUpdate);
|
|
23
|
+
});
|
|
24
|
+
observedCall.on('update', onUpdate);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.OnAnyCallObserverUpdater = OnAnyCallObserverUpdater;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ObservedCall } from '../ObservedCall';
|
|
2
|
+
import { Updater } from './Updater';
|
|
3
|
+
export declare class OnAnyClientCallUpdater implements Updater {
|
|
4
|
+
private _observedCall;
|
|
5
|
+
readonly name = "OnAnyClientCallUpdater";
|
|
6
|
+
readonly description = "Call the update() method of the ObservedCall when any of the client has been updated";
|
|
7
|
+
constructor(_observedCall: ObservedCall);
|
|
8
|
+
close(): void;
|
|
9
|
+
private _onNewObservedClient;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=OnAnyClientCallUpdater.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OnAnyClientCallUpdater.d.ts","sourceRoot":"","sources":["../../src/updaters/OnAnyClientCallUpdater.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,qBAAa,sBAAuB,YAAW,OAAO;IAKpD,OAAO,CAAC,aAAa;IAJtB,QAAQ,CAAC,IAAI,4BAA4B;IACzC,QAAQ,CAAC,WAAW,0FAA0F;gBAGrG,aAAa,EAAE,YAAY;IAU7B,KAAK,IAAI,IAAI;IAIpB,OAAO,CAAC,oBAAoB;CAQ5B"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OnAnyClientCallUpdater = void 0;
|
|
4
|
+
class OnAnyClientCallUpdater {
|
|
5
|
+
_observedCall;
|
|
6
|
+
name = 'OnAnyClientCallUpdater';
|
|
7
|
+
description = 'Call the update() method of the ObservedCall when any of the client has been updated';
|
|
8
|
+
constructor(_observedCall) {
|
|
9
|
+
this._observedCall = _observedCall;
|
|
10
|
+
this._onNewObservedClient = this._onNewObservedClient.bind(this);
|
|
11
|
+
this._observedCall.once('close', () => {
|
|
12
|
+
this._observedCall.off('newclient', this._onNewObservedClient);
|
|
13
|
+
});
|
|
14
|
+
this._observedCall.on('newclient', this._onNewObservedClient);
|
|
15
|
+
}
|
|
16
|
+
close() {
|
|
17
|
+
// do nothing, as close once emitted unsubscription happened
|
|
18
|
+
}
|
|
19
|
+
_onNewObservedClient(observedClient) {
|
|
20
|
+
const onUpdate = () => this._observedCall.update();
|
|
21
|
+
observedClient.once('close', () => {
|
|
22
|
+
observedClient.off('update', onUpdate);
|
|
23
|
+
});
|
|
24
|
+
observedClient.on('update', onUpdate);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.OnAnyClientCallUpdater = OnAnyClientCallUpdater;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Updater } from './Updater';
|
|
2
|
+
export declare class OnIntervalUpdater implements Updater {
|
|
3
|
+
private readonly _update;
|
|
4
|
+
readonly name = "OnIntervalUpdater";
|
|
5
|
+
readonly description = "Call the update() method given in the constructor once the interval elapsed";
|
|
6
|
+
timer: ReturnType<typeof setInterval>;
|
|
7
|
+
constructor(intervalInMs: number, _update: () => void);
|
|
8
|
+
close(): void;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=OnIntervalUpdater.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OnIntervalUpdater.d.ts","sourceRoot":"","sources":["../../src/updaters/OnIntervalUpdater.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,qBAAa,iBAAkB,YAAW,OAAO;IAQ/C,OAAO,CAAC,QAAQ,CAAC,OAAO;IAPzB,QAAQ,CAAC,IAAI,uBAAuB;IACpC,QAAQ,CAAC,WAAW,iFAAiF;IAE9F,KAAK,EAAE,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;gBAG5C,YAAY,EAAE,MAAM,EACH,OAAO,EAAE,MAAM,IAAI;IAK9B,KAAK,IAAI,IAAI;CAGpB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OnIntervalUpdater = void 0;
|
|
4
|
+
class OnIntervalUpdater {
|
|
5
|
+
_update;
|
|
6
|
+
name = 'OnIntervalUpdater';
|
|
7
|
+
description = 'Call the update() method given in the constructor once the interval elapsed';
|
|
8
|
+
timer;
|
|
9
|
+
constructor(intervalInMs, _update) {
|
|
10
|
+
this._update = _update;
|
|
11
|
+
this.timer = setInterval(() => this._update(), intervalInMs);
|
|
12
|
+
}
|
|
13
|
+
close() {
|
|
14
|
+
clearInterval(this.timer);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.OnIntervalUpdater = OnIntervalUpdater;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Updater.d.ts","sourceRoot":"","sources":["../../src/updaters/Updater.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,KAAK,IAAI,IAAI,CAAC;CACd"}
|
package/package.json
CHANGED
package/src/ObservedCall.ts
CHANGED
|
@@ -6,15 +6,17 @@ import { CalculatedScore } from './scores/CalculatedScore';
|
|
|
6
6
|
import { DefaultCallScoreCalculator } from './scores/DefaultCallScoreCalculator';
|
|
7
7
|
import { Detectors } from './detectors/Detectors';
|
|
8
8
|
import { RemoteTrackResolver } from './utils/RemoteTrackResolver';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
9
|
+
import { OnAllClientCallUpdater } from './updaters/OnAllClientCallUpdater';
|
|
10
|
+
import { Updater } from './updaters/Updater';
|
|
11
|
+
import { OnIntervalUpdater } from './updaters/OnIntervalUpdater';
|
|
12
|
+
import { OnAnyClientCallUpdater } from './updaters/OnAnyClientCallUpdater';
|
|
12
13
|
|
|
13
14
|
export type ObservedCallSettings<AppData extends Record<string, unknown> = Record<string, unknown>> = {
|
|
14
15
|
callId: string;
|
|
15
16
|
appData?: AppData;
|
|
16
17
|
remoteTrackResolvePolicy?: 'p2p' | 'mediasoup-sfu',
|
|
17
|
-
|
|
18
|
+
updatePolicy?: 'update-on-any-client-updated' | 'update-when-all-client-updated' | 'update-on-interval',
|
|
19
|
+
updateIntervalInMs?: number,
|
|
18
20
|
};
|
|
19
21
|
|
|
20
22
|
export type ObservedCallEvents = {
|
|
@@ -34,20 +36,62 @@ export declare interface ObservedCall {
|
|
|
34
36
|
|
|
35
37
|
export class ObservedCall<AppData extends Record<string, unknown> = Record<string, unknown>> extends EventEmitter {
|
|
36
38
|
public readonly detectors: Detectors;
|
|
39
|
+
public updater?: Updater;
|
|
40
|
+
public scoreCalculator: ScoreCalculator;
|
|
37
41
|
public readonly callId: string;
|
|
38
42
|
public readonly observedClients = new Map<string, ObservedClient>();
|
|
43
|
+
public readonly clientsUsedTurn = new Set<string>();
|
|
39
44
|
public readonly calculatedScore: CalculatedScore = {
|
|
40
45
|
weight: 1,
|
|
41
46
|
value: undefined,
|
|
42
47
|
};
|
|
43
48
|
public remoteTrackResolver?: RemoteTrackResolver;
|
|
44
|
-
public callUpdater?: CallUpdater;
|
|
45
49
|
|
|
46
|
-
public
|
|
50
|
+
public totalAddedClients = 0;
|
|
51
|
+
public totalRemovedClients = 0;
|
|
52
|
+
|
|
53
|
+
public totalClientsReceivedAudioBytes = 0;
|
|
54
|
+
public totalClientsReceivedVideoBytes = 0;
|
|
55
|
+
public totalClientsReceivedDataChannelBytes = 0;
|
|
56
|
+
public totalClientsReceivedBytes = 0;
|
|
57
|
+
|
|
58
|
+
public totalClientsSentAudioBytes = 0;
|
|
59
|
+
public totalClientsSentDataChannelBytes = 0;
|
|
60
|
+
public totalClientsSentVideoBytes = 0;
|
|
61
|
+
public totalClientsSentBytes = 0;
|
|
62
|
+
|
|
63
|
+
public totalRttLt50Measurements = 0;
|
|
64
|
+
public totalRttLt150Measurements = 0;
|
|
65
|
+
public totalRttLt300Measurements = 0;
|
|
66
|
+
public totalRttGtOrEq300Measurements = 0;
|
|
67
|
+
|
|
68
|
+
public numberOfIssues = 0;
|
|
69
|
+
public numberOfPeerConnections = 0;
|
|
70
|
+
public numberOfInboundRtpStreams = 0;
|
|
71
|
+
public numberOfOutboundRtpStreams = 0;
|
|
72
|
+
public numberOfDataChannels = 0;
|
|
73
|
+
|
|
74
|
+
public maxNumberOfClients = 0;
|
|
75
|
+
public deltaNumberOfIssues = 0;
|
|
76
|
+
|
|
77
|
+
public deltaRttLt50Measurements = 0;
|
|
78
|
+
public deltaRttLt150Measurements = 0;
|
|
79
|
+
public deltaRttLt300Measurements = 0;
|
|
80
|
+
public deltaRttGtOrEq300Measurements = 0;
|
|
81
|
+
|
|
82
|
+
public appData: AppData;
|
|
47
83
|
public closed = false;
|
|
48
|
-
public
|
|
49
|
-
public
|
|
50
|
-
public
|
|
84
|
+
public startedAt?: number;
|
|
85
|
+
public endedAt?: number;
|
|
86
|
+
public closedAt?: number;
|
|
87
|
+
|
|
88
|
+
private _callStartedEvent: {
|
|
89
|
+
emitted: boolean,
|
|
90
|
+
timer?: ReturnType<typeof setTimeout>,
|
|
91
|
+
};
|
|
92
|
+
private _callEndedEvent: {
|
|
93
|
+
emitted: boolean
|
|
94
|
+
};
|
|
51
95
|
|
|
52
96
|
public constructor(
|
|
53
97
|
settings: ObservedCallSettings<AppData>,
|
|
@@ -57,16 +101,30 @@ export class ObservedCall<AppData extends Record<string, unknown> = Record<strin
|
|
|
57
101
|
this.setMaxListeners(Infinity);
|
|
58
102
|
|
|
59
103
|
this.callId = settings.callId;
|
|
60
|
-
this.appData = settings.appData;
|
|
104
|
+
this.appData = settings.appData ?? {} as AppData;
|
|
61
105
|
this.scoreCalculator = new DefaultCallScoreCalculator(this);
|
|
62
106
|
this.detectors = new Detectors();
|
|
63
107
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
108
|
+
if (settings.updateIntervalInMs) {
|
|
109
|
+
if (settings.updatePolicy !== 'update-on-interval') {
|
|
110
|
+
throw new Error('updatePolicy must be update-on-interval if updateIntervalInMs is set in config');
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
switch (settings.updatePolicy) {
|
|
114
|
+
case 'update-on-any-client-updated':
|
|
115
|
+
this.updater = new OnAllClientCallUpdater(this);
|
|
116
|
+
break;
|
|
117
|
+
case 'update-when-all-client-updated':
|
|
118
|
+
this.updater = new OnAnyClientCallUpdater(this);
|
|
67
119
|
break;
|
|
68
|
-
case '
|
|
69
|
-
|
|
120
|
+
case 'update-on-interval':
|
|
121
|
+
if (!settings.updateIntervalInMs) {
|
|
122
|
+
throw new Error('updateIntervalInMs setting in config must be set if updatePolicy is update-on-interval');
|
|
123
|
+
}
|
|
124
|
+
this.updater = new OnIntervalUpdater(
|
|
125
|
+
settings.updateIntervalInMs,
|
|
126
|
+
this.update.bind(this),
|
|
127
|
+
);
|
|
70
128
|
break;
|
|
71
129
|
}
|
|
72
130
|
|
|
@@ -74,6 +132,17 @@ export class ObservedCall<AppData extends Record<string, unknown> = Record<strin
|
|
|
74
132
|
case 'mediasoup-sfu':
|
|
75
133
|
break;
|
|
76
134
|
}
|
|
135
|
+
|
|
136
|
+
this._callStartedEvent = {
|
|
137
|
+
emitted: false,
|
|
138
|
+
};
|
|
139
|
+
this._callEndedEvent = {
|
|
140
|
+
emitted: false,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
public get numberOfClients() {
|
|
145
|
+
return this.observedClients.size;
|
|
77
146
|
}
|
|
78
147
|
|
|
79
148
|
public get score() {
|
|
@@ -82,10 +151,14 @@ export class ObservedCall<AppData extends Record<string, unknown> = Record<strin
|
|
|
82
151
|
|
|
83
152
|
public close() {
|
|
84
153
|
if (this.closed) return;
|
|
154
|
+
this.update(); // last update before closing
|
|
85
155
|
this.closed = true;
|
|
86
156
|
|
|
157
|
+
this.updater?.close();
|
|
158
|
+
|
|
87
159
|
[ ...this.observedClients.values() ].forEach((client) => client.close());
|
|
88
160
|
|
|
161
|
+
this.closedAt = Date.now();
|
|
89
162
|
this.emit('close');
|
|
90
163
|
}
|
|
91
164
|
|
|
@@ -101,19 +174,28 @@ export class ObservedCall<AppData extends Record<string, unknown> = Record<strin
|
|
|
101
174
|
|
|
102
175
|
const result = new ObservedClient<ClientAppData>(settings, this);
|
|
103
176
|
const wasEmpty = this.observedClients.size === 0;
|
|
104
|
-
const onUpdate = () => this.
|
|
177
|
+
const onUpdate = () => this._onClientUpdate(result);
|
|
178
|
+
const joined = () => this._clientJoined(result);
|
|
179
|
+
const left = () => this._clientLeft(result);
|
|
105
180
|
|
|
106
181
|
result.once('close', () => {
|
|
107
182
|
result.off('update', onUpdate);
|
|
183
|
+
result.off('joined', joined);
|
|
184
|
+
result.off('left', left);
|
|
108
185
|
this.observedClients.delete(settings.clientId);
|
|
109
186
|
|
|
110
187
|
if (this.observedClients.size === 0) {
|
|
111
188
|
this.emit('empty');
|
|
112
189
|
}
|
|
190
|
+
++this.totalRemovedClients;
|
|
113
191
|
});
|
|
114
192
|
result.on('update', onUpdate);
|
|
193
|
+
result.on('joined', joined);
|
|
194
|
+
result.on('left', left);
|
|
195
|
+
++this.totalAddedClients;
|
|
115
196
|
|
|
116
197
|
this.observedClients.set(settings.clientId, result);
|
|
198
|
+
this.maxNumberOfClients = Math.max(this.maxNumberOfClients, this.observedClients.size);
|
|
117
199
|
|
|
118
200
|
this.emit('newclient', result);
|
|
119
201
|
|
|
@@ -125,9 +207,116 @@ export class ObservedCall<AppData extends Record<string, unknown> = Record<strin
|
|
|
125
207
|
}
|
|
126
208
|
|
|
127
209
|
public update() {
|
|
210
|
+
if (this.closed) return;
|
|
211
|
+
|
|
212
|
+
this.numberOfInboundRtpStreams = 0;
|
|
213
|
+
this.numberOfOutboundRtpStreams = 0;
|
|
214
|
+
this.numberOfPeerConnections = 0;
|
|
215
|
+
this.numberOfDataChannels = 0;
|
|
216
|
+
|
|
217
|
+
for (const client of this.observedClients.values()) {
|
|
218
|
+
this.numberOfInboundRtpStreams += client.numberOfInboundRtpStreams;
|
|
219
|
+
this.numberOfOutboundRtpStreams += client.numberOfOutboundRtpStreams;
|
|
220
|
+
this.numberOfPeerConnections += client.numberOfPeerConnections;
|
|
221
|
+
this.numberOfDataChannels += client.numberOfDataChannels;
|
|
222
|
+
}
|
|
223
|
+
|
|
128
224
|
this.detectors.update();
|
|
129
225
|
this.scoreCalculator.update();
|
|
130
226
|
|
|
131
227
|
this.emit('update');
|
|
228
|
+
|
|
229
|
+
this.deltaNumberOfIssues = 0;
|
|
230
|
+
this.deltaRttLt50Measurements = 0;
|
|
231
|
+
this.deltaRttLt150Measurements = 0;
|
|
232
|
+
this.deltaRttLt300Measurements = 0;
|
|
233
|
+
this.deltaRttGtOrEq300Measurements = 0;
|
|
132
234
|
}
|
|
235
|
+
|
|
236
|
+
private _onClientUpdate(client: ObservedClient) {
|
|
237
|
+
this.totalClientsReceivedAudioBytes += client.deltaReceivedAudioBytes;
|
|
238
|
+
this.totalClientsReceivedVideoBytes += client.deltaReceivedVideoBytes;
|
|
239
|
+
this.totalClientsReceivedDataChannelBytes += client.deltaDataChannelBytesReceived;
|
|
240
|
+
this.totalClientsReceivedBytes += client.deltaTransportReceivedBytes;
|
|
241
|
+
this.totalClientsSentAudioBytes += client.deltaSentAudioBytes;
|
|
242
|
+
this.totalClientsSentVideoBytes += client.deltaSentVideoBytes;
|
|
243
|
+
this.totalClientsSentDataChannelBytes += client.deltaDataChannelBytesSent;
|
|
244
|
+
this.totalClientsSentBytes += client.deltaTransportSentBytes;
|
|
245
|
+
|
|
246
|
+
this.deltaRttLt50Measurements += client.deltaRttLt50Measurements;
|
|
247
|
+
this.deltaRttLt150Measurements += client.deltaRttLt150Measurements;
|
|
248
|
+
this.deltaRttLt300Measurements += client.deltaRttLt300Measurements;
|
|
249
|
+
this.deltaRttGtOrEq300Measurements += client.deltaRttGtOrEq300Measurements;
|
|
250
|
+
|
|
251
|
+
this.totalRttLt50Measurements += client.deltaRttLt50Measurements;
|
|
252
|
+
this.totalRttLt150Measurements += client.deltaRttLt150Measurements;
|
|
253
|
+
this.totalRttLt300Measurements += client.deltaRttLt300Measurements;
|
|
254
|
+
this.totalRttGtOrEq300Measurements += client.deltaRttGtOrEq300Measurements;
|
|
255
|
+
|
|
256
|
+
this.deltaNumberOfIssues += client.deltaNumberOfIssues;
|
|
257
|
+
this.numberOfIssues += client.deltaNumberOfIssues;
|
|
258
|
+
|
|
259
|
+
if (client.usingTURN) {
|
|
260
|
+
this.clientsUsedTurn.add(client.clientId);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
private _clientJoined(client: ObservedClient) {
|
|
265
|
+
if (!client.joinedAt) return;
|
|
266
|
+
|
|
267
|
+
this.startedAt = Math.min(this.startedAt ?? client.joinedAt, client.joinedAt);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
private _clientLeft(client: ObservedClient) {
|
|
271
|
+
if (!client.leftAt) return;
|
|
272
|
+
|
|
273
|
+
this.endedAt = Math.max(this.endedAt ?? client.leftAt, client.leftAt);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// public resetSummaryMetrics() {
|
|
277
|
+
// this.totalAddedClients = 0;
|
|
278
|
+
// this.totalRemovedClients = 0;
|
|
279
|
+
|
|
280
|
+
// this.totalClientsReceivedAudioBytes = 0;
|
|
281
|
+
// this.totalClientsReceivedVideoBytes = 0;
|
|
282
|
+
// this.totalClientsReceivedBytes = 0;
|
|
283
|
+
|
|
284
|
+
// this.totalClientsSentAudioBytes = 0;
|
|
285
|
+
// this.totalClientsSentVideoBytes = 0;
|
|
286
|
+
// this.totalClientsSentBytes = 0;
|
|
287
|
+
|
|
288
|
+
// this.totalRttLt50Measurements = 0;
|
|
289
|
+
// this.totalRttLt150Measurements = 0;
|
|
290
|
+
// this.totalRttLt300Measurements = 0;
|
|
291
|
+
// this.totalRttGtOrEq300Measurements = 0;
|
|
292
|
+
|
|
293
|
+
// this.numberOfIssues = 0;
|
|
294
|
+
|
|
295
|
+
// this.clientsUsedTurn.clear();
|
|
296
|
+
|
|
297
|
+
// }
|
|
298
|
+
|
|
299
|
+
// public createSummary(): ObservedCallSummary {
|
|
300
|
+
// return {
|
|
301
|
+
// currentActiveClients: this.observedClients.size,
|
|
302
|
+
// totalAddedClients: this.totalAddedClients,
|
|
303
|
+
// totalRemovedClients: this.totalRemovedClients,
|
|
304
|
+
|
|
305
|
+
// totalClientsReceivedAudioBytes: this.totalClientsReceivedBytes,
|
|
306
|
+
// totalClientsReceivedVideoBytes: this.totalClientsReceivedVideoBytes,
|
|
307
|
+
// totalClientsReceivedBytes: this.totalClientsReceivedBytes,
|
|
308
|
+
|
|
309
|
+
// totalClientsSentAudioBytes: this.totalClientsSentAudioBytes,
|
|
310
|
+
// totalClientsSentVideoBytes: this.totalClientsSentVideoBytes,
|
|
311
|
+
// totalClientsSentBytes: this.totalClientsSentBytes,
|
|
312
|
+
|
|
313
|
+
// totalRttLt50Measurements: this.totalRttLt50Measurements,
|
|
314
|
+
// totalRttLt150Measurements: this.totalRttLt150Measurements,
|
|
315
|
+
// totalRttLt300Measurements: this.totalRttLt300Measurements,
|
|
316
|
+
// totalRttGtOrEq300Measurements: this.totalRttGtOrEq300Measurements,
|
|
317
|
+
|
|
318
|
+
// numberOfIssues: this.numberOfIssues,
|
|
319
|
+
// numberOfClientsUsedTurn: this.clientsUsedTurn.size,
|
|
320
|
+
// };
|
|
321
|
+
// }
|
|
133
322
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type ObservedCallSummary = {
|
|
2
|
+
currentActiveClients: number;
|
|
3
|
+
|
|
4
|
+
totalAddedClients: number;
|
|
5
|
+
totalRemovedClients: number;
|
|
6
|
+
|
|
7
|
+
totalClientsSentBytes: number,
|
|
8
|
+
totalClientsReceivedBytes: number,
|
|
9
|
+
totalClientsReceivedAudioBytes: number,
|
|
10
|
+
totalClientsReceivedVideoBytes: number,
|
|
11
|
+
totalClientsSentAudioBytes: number,
|
|
12
|
+
totalClientsSentVideoBytes: number,
|
|
13
|
+
|
|
14
|
+
totalRttLt50Measurements: number,
|
|
15
|
+
totalRttLt150Measurements: number,
|
|
16
|
+
totalRttLt300Measurements: number,
|
|
17
|
+
totalRttGtOrEq300Measurements: number,
|
|
18
|
+
|
|
19
|
+
numberOfIssues: number,
|
|
20
|
+
|
|
21
|
+
numberOfClientsUsedTurn: number;
|
|
22
|
+
}
|