@observertc/observer-js 0.42.8 → 1.0.1-198a187.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/.prettierrc +6 -6
- package/README.md +0 -104
- package/lib/ObservedCall.d.ts +63 -43
- package/lib/ObservedCall.d.ts.map +1 -1
- package/lib/ObservedCall.js +188 -108
- package/lib/ObservedCallEventMonitor.d.ts +104 -0
- package/lib/ObservedCallEventMonitor.d.ts.map +1 -0
- package/lib/ObservedCallEventMonitor.js +314 -0
- package/lib/ObservedCallSummary.d.ts +18 -0
- package/lib/ObservedCallSummary.d.ts.map +1 -0
- package/lib/ObservedCertificate.d.ts +19 -0
- package/lib/ObservedCertificate.d.ts.map +1 -0
- package/lib/ObservedCertificate.js +38 -0
- package/lib/ObservedClient.d.ts +80 -130
- package/lib/ObservedClient.d.ts.map +1 -1
- package/lib/ObservedClient.js +584 -744
- 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/ObservedCodec.d.ts +22 -0
- package/lib/ObservedCodec.d.ts.map +1 -0
- package/lib/ObservedCodec.js +45 -0
- package/lib/ObservedDataChannel.d.ts +25 -69
- package/lib/ObservedDataChannel.d.ts.map +1 -1
- package/lib/ObservedDataChannel.js +69 -109
- package/lib/ObservedIceCandidate.d.ts +29 -0
- package/lib/ObservedIceCandidate.d.ts.map +1 -0
- package/lib/ObservedIceCandidate.js +59 -0
- package/lib/ObservedIceCandidatePair.d.ts +45 -0
- package/lib/ObservedIceCandidatePair.d.ts.map +1 -0
- package/lib/ObservedIceCandidatePair.js +127 -0
- package/lib/ObservedIceTransport.d.ts +36 -0
- package/lib/ObservedIceTransport.d.ts.map +1 -0
- package/lib/ObservedIceTransport.js +93 -0
- package/lib/ObservedInboundRtp.d.ts +92 -0
- package/lib/ObservedInboundRtp.d.ts.map +1 -0
- package/lib/ObservedInboundRtp.js +193 -0
- package/lib/ObservedInboundTrack.d.ts +32 -0
- package/lib/ObservedInboundTrack.d.ts.map +1 -0
- package/lib/ObservedInboundTrack.js +60 -0
- package/lib/ObservedMediaPlayout.d.ts +22 -0
- package/lib/ObservedMediaPlayout.d.ts.map +1 -0
- package/lib/ObservedMediaPlayout.js +42 -0
- package/lib/ObservedMediaSource.d.ts +28 -0
- package/lib/ObservedMediaSource.d.ts.map +1 -0
- package/lib/ObservedMediaSource.js +55 -0
- package/lib/ObservedOutboundRtp.d.ts +62 -0
- package/lib/ObservedOutboundRtp.d.ts.map +1 -0
- package/lib/ObservedOutboundRtp.js +144 -0
- package/lib/ObservedOutboundTrack.d.ts +32 -0
- package/lib/ObservedOutboundTrack.d.ts.map +1 -0
- package/lib/ObservedOutboundTrack.js +60 -0
- package/lib/ObservedPeerConnection.d.ts +154 -80
- package/lib/ObservedPeerConnection.d.ts.map +1 -1
- package/lib/ObservedPeerConnection.js +709 -357
- package/lib/ObservedPeerConnectionTransport.d.ts +17 -0
- package/lib/ObservedPeerConnectionTransport.d.ts.map +1 -0
- package/lib/ObservedPeerConnectionTransport.js +34 -0
- package/lib/ObservedRemoteInboundRtp.d.ts +30 -0
- package/lib/ObservedRemoteInboundRtp.d.ts.map +1 -0
- package/lib/ObservedRemoteInboundRtp.js +60 -0
- package/lib/ObservedRemoteOutboundRtp.d.ts +30 -0
- package/lib/ObservedRemoteOutboundRtp.d.ts.map +1 -0
- package/lib/ObservedRemoteOutboundRtp.js +60 -0
- 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 +49 -54
- package/lib/Observer.d.ts.map +1 -1
- package/lib/Observer.js +138 -225
- package/lib/ObserverEventMonitor.d.ts +138 -0
- package/lib/ObserverEventMonitor.d.ts.map +1 -0
- package/lib/ObserverEventMonitor.js +433 -0
- package/lib/ObserverSummary.d.ts +13 -0
- package/lib/ObserverSummary.d.ts.map +1 -0
- package/lib/ObserverSummary.js +2 -0
- package/lib/common/Middleware.d.ts +10 -1
- package/lib/common/Middleware.d.ts.map +1 -1
- package/lib/common/Middleware.js +55 -36
- package/lib/common/logger.d.ts +8 -4
- package/lib/common/logger.d.ts.map +1 -1
- package/lib/common/logger.js +44 -68
- package/lib/common/types.d.ts +0 -21
- package/lib/common/types.d.ts.map +1 -1
- package/lib/common/types.js +1 -0
- package/lib/common/utils.d.ts +3 -1
- package/lib/common/utils.d.ts.map +1 -1
- package/lib/common/utils.js +23 -3
- package/lib/detectors/Detector.d.ts +5 -0
- package/lib/detectors/Detector.d.ts.map +1 -0
- package/lib/detectors/Detector.js +3 -0
- package/lib/detectors/Detectors.d.ts +11 -0
- package/lib/detectors/Detectors.d.ts.map +1 -0
- package/lib/detectors/Detectors.js +34 -0
- package/lib/index.d.ts +26 -24
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +45 -41
- package/lib/monitors/TurnUsageMonitor.d.ts +0 -52
- package/lib/monitors/TurnUsageMonitor.d.ts.map +1 -1
- package/lib/monitors/TurnUsageMonitor.js +145 -120
- package/lib/schema/ClientEventTypes.d.ts +228 -0
- package/lib/schema/ClientEventTypes.d.ts.map +1 -0
- package/lib/schema/ClientEventTypes.js +41 -0
- package/lib/schema/ClientMetaTypes.d.ts +34 -0
- package/lib/schema/ClientMetaTypes.d.ts.map +1 -0
- package/lib/schema/ClientMetaTypes.js +16 -0
- package/lib/schema/ClientSample.d.ts +1333 -0
- package/lib/schema/ClientSample.d.ts.map +1 -0
- package/lib/schema/ClientSample.js +4 -0
- package/lib/scores/CalculatedScore.d.ts +6 -0
- package/lib/scores/CalculatedScore.d.ts.map +1 -0
- package/lib/scores/CalculatedScore.js +2 -0
- package/lib/scores/DefaultCallScoreCalculator.d.ts +7 -0
- package/lib/scores/DefaultCallScoreCalculator.d.ts.map +1 -0
- package/lib/scores/DefaultCallScoreCalculator.js +21 -0
- package/lib/scores/ScoreCalculator.d.ts +4 -0
- package/lib/scores/ScoreCalculator.d.ts.map +1 -0
- package/lib/scores/ScoreCalculator.js +2 -0
- package/lib/updaters/CallUpdater.d.ts +5 -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 +15 -0
- package/lib/updaters/OnAllCallObserverUpdater.d.ts.map +1 -0
- package/lib/updaters/OnAllCallObserverUpdater.js +50 -0
- package/lib/updaters/OnAllClientCallUpdater.d.ts +15 -0
- package/lib/updaters/OnAllClientCallUpdater.d.ts.map +1 -0
- package/lib/updaters/OnAllClientCallUpdater.js +53 -0
- package/lib/updaters/OnAnyCallObserverUpdater.d.ts +12 -0
- package/lib/updaters/OnAnyCallObserverUpdater.d.ts.map +1 -0
- package/lib/updaters/OnAnyCallObserverUpdater.js +37 -0
- package/lib/updaters/OnAnyClientCallUpdater.d.ts +12 -0
- package/lib/updaters/OnAnyClientCallUpdater.d.ts.map +1 -0
- package/lib/updaters/OnAnyClientCallUpdater.js +36 -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/lib/utils/MediasoupRemoteTrackResolver.d.ts +25 -0
- package/lib/utils/MediasoupRemoteTrackResolver.d.ts.map +1 -0
- package/lib/utils/MediasoupRemoteTrackResolver.js +110 -0
- package/lib/utils/RemoteTrackResolver.d.ts +7 -0
- package/lib/utils/RemoteTrackResolver.d.ts.map +1 -0
- package/lib/utils/RemoteTrackResolver.js +2 -0
- package/package.json +4 -4
- package/src/ObservedCall.ts +276 -164
- package/src/ObservedCallEventMonitor.ts +392 -0
- package/src/ObservedCallSummary.ts +22 -0
- package/src/ObservedCertificate.ts +43 -0
- package/src/ObservedClient.ts +630 -1006
- package/src/ObservedClientEventMonitor.ts +301 -0
- package/src/ObservedClientSummary.ts +24 -0
- package/src/ObservedCodec.ts +49 -0
- package/src/ObservedDataChannel.ts +71 -181
- package/src/ObservedIceCandidate.ts +64 -0
- package/src/ObservedIceCandidatePair.ts +134 -0
- package/src/ObservedIceTransport.ts +99 -0
- package/src/ObservedInboundRtp.ts +205 -0
- package/src/ObservedInboundTrack.ts +75 -0
- package/src/ObservedMediaPlayout.ts +49 -0
- package/src/ObservedMediaSource.ts +60 -0
- package/src/ObservedOutboundRtp.ts +156 -0
- package/src/ObservedOutboundTrack.ts +74 -0
- package/src/ObservedPeerConnection.ts +917 -402
- package/src/ObservedPeerConnectionTransport.ts +38 -0
- package/src/ObservedRemoteInboundRtp.ts +64 -0
- package/src/ObservedRemoteOutboundRtp.ts +65 -0
- package/src/ObservedTURN.ts +86 -0
- package/src/ObservedTurnServer.ts +72 -0
- package/src/Observer.ts +187 -296
- package/src/ObserverEventMonitor.ts +551 -0
- package/src/ObserverSummary.ts +15 -0
- package/src/common/Middleware.ts +70 -42
- package/src/common/logger.ts +60 -69
- package/src/common/types.ts +0 -42
- package/src/common/utils.ts +24 -2
- package/src/detectors/Detector.ts +6 -0
- package/src/detectors/Detectors.ts +38 -0
- package/src/index.ts +26 -88
- package/src/monitors/TurnUsageMonitor.ts +164 -164
- package/src/schema/ClientEventTypes.ts +280 -0
- package/src/schema/ClientMetaTypes.ts +41 -0
- package/src/schema/ClientSample.ts +1682 -0
- package/src/scores/CalculatedScore.ts +6 -0
- package/src/scores/DefaultCallScoreCalculator.ts +23 -0
- package/src/scores/ScoreCalculator.ts +3 -0
- package/src/updaters/CallUpdater.ts +5 -0
- package/src/updaters/ObserverUpdater.ts +5 -0
- package/src/updaters/OnAllCallObserverUpdater.ts +59 -0
- package/src/updaters/OnAllClientCallUpdater.ts +61 -0
- package/src/updaters/OnAnyCallObserverUpdater.ts +41 -0
- package/src/updaters/OnAnyClientCallUpdater.ts +39 -0
- package/src/updaters/OnIntervalUpdater.ts +19 -0
- package/src/updaters/Updater.ts +5 -0
- package/src/utils/MediasoupRemoteTrackResolver.ts +155 -0
- package/src/utils/RemoteTrackResolver.ts +12 -0
- package/tsconfig.json +3 -3
- package/lib/ObservedICE.d.ts +0 -64
- package/lib/ObservedICE.d.ts.map +0 -1
- package/lib/ObservedICE.js +0 -141
- package/lib/ObservedInboundAudioTrack.d.ts +0 -96
- package/lib/ObservedInboundAudioTrack.d.ts.map +0 -1
- package/lib/ObservedInboundAudioTrack.js +0 -217
- package/lib/ObservedInboundVideoTrack.d.ts +0 -101
- package/lib/ObservedInboundVideoTrack.d.ts.map +0 -1
- package/lib/ObservedInboundVideoTrack.js +0 -232
- package/lib/ObservedOutboundAudioTrack.d.ts +0 -87
- package/lib/ObservedOutboundAudioTrack.d.ts.map +0 -1
- package/lib/ObservedOutboundAudioTrack.js +0 -186
- package/lib/ObservedOutboundVideoTrack.d.ts +0 -91
- package/lib/ObservedOutboundVideoTrack.d.ts.map +0 -1
- package/lib/ObservedOutboundVideoTrack.js +0 -193
- package/lib/ObservedSfu.d.ts +0 -59
- package/lib/ObservedSfu.d.ts.map +0 -1
- package/lib/ObservedSfu.js +0 -157
- package/lib/ObservedSfuInboundRtpPad.d.ts +0 -42
- package/lib/ObservedSfuInboundRtpPad.d.ts.map +0 -1
- package/lib/ObservedSfuInboundRtpPad.js +0 -71
- package/lib/ObservedSfuOutboundRtpPad.d.ts +0 -42
- package/lib/ObservedSfuOutboundRtpPad.d.ts.map +0 -1
- package/lib/ObservedSfuOutboundRtpPad.js +0 -72
- package/lib/ObservedSfuSctpChannel.d.ts +0 -42
- package/lib/ObservedSfuSctpChannel.d.ts.map +0 -1
- package/lib/ObservedSfuSctpChannel.js +0 -57
- package/lib/ObservedSfuTransport.d.ts +0 -58
- package/lib/ObservedSfuTransport.d.ts.map +0 -1
- package/lib/ObservedSfuTransport.js +0 -120
- package/lib/RemoteTrackAssigner.d.ts +0 -14
- package/lib/RemoteTrackAssigner.d.ts.map +0 -1
- package/lib/RemoteTrackAssigner.js +0 -52
- package/lib/ReportsCollector.d.ts +0 -109
- package/lib/ReportsCollector.d.ts.map +0 -1
- package/lib/ReportsCollector.js +0 -207
- package/lib/common/CalculatedScore.d.ts +0 -80
- package/lib/common/CalculatedScore.d.ts.map +0 -1
- package/lib/common/CalculatedScore.js +0 -162
- package/lib/common/CallEventType.d.ts +0 -63
- package/lib/common/CallEventType.d.ts.map +0 -1
- package/lib/common/CallEventType.js +0 -39
- package/lib/common/CallMetaReports.d.ts +0 -42
- package/lib/common/CallMetaReports.d.ts.map +0 -1
- package/lib/common/CallMetaReports.js +0 -36
- package/lib/common/QualityScoreUtils.d.ts +0 -1
- package/lib/common/QualityScoreUtils.d.ts.map +0 -1
- package/lib/common/QualityScoreUtils.js +0 -1
- package/lib/common/TypedEventEmitter.d.ts +0 -22
- package/lib/common/TypedEventEmitter.d.ts.map +0 -1
- package/lib/common/TypedEventEmitter.js +0 -11
- package/lib/common/callEventReports.d.ts +0 -10
- package/lib/common/callEventReports.d.ts.map +0 -1
- package/lib/common/callEventReports.js +0 -112
- package/lib/monitors/CallSummary.d.ts +0 -37
- package/lib/monitors/CallSummary.d.ts.map +0 -1
- package/lib/monitors/CallSummaryMonitor.d.ts +0 -32
- package/lib/monitors/CallSummaryMonitor.d.ts.map +0 -1
- package/lib/monitors/CallSummaryMonitor.js +0 -152
- package/lib/monitors/ClientIssueMonitor.d.ts +0 -32
- package/lib/monitors/ClientIssueMonitor.d.ts.map +0 -1
- package/lib/monitors/ClientIssueMonitor.js +0 -49
- package/lib/monitors/SfuServerMonitor.d.ts +0 -79
- package/lib/monitors/SfuServerMonitor.d.ts.map +0 -1
- package/lib/monitors/SfuServerMonitor.js +0 -198
- package/src/ObservedICE.ts +0 -237
- package/src/ObservedInboundAudioTrack.ts +0 -344
- package/src/ObservedInboundVideoTrack.ts +0 -361
- package/src/ObservedOutboundAudioTrack.ts +0 -307
- package/src/ObservedOutboundVideoTrack.ts +0 -319
- package/src/ObservedSfu.ts +0 -231
- package/src/ObservedSfuInboundRtpPad.ts +0 -106
- package/src/ObservedSfuOutboundRtpPad.ts +0 -107
- package/src/ObservedSfuSctpChannel.ts +0 -103
- package/src/ObservedSfuTransport.ts +0 -185
- package/src/RemoteTrackAssigner.ts +0 -68
- package/src/ReportsCollector.ts +0 -336
- package/src/common/CalculatedScore.ts +0 -188
- package/src/common/CallEventType.ts +0 -69
- package/src/common/CallMetaReports.ts +0 -82
- package/src/common/QualityScoreUtils.ts +0 -0
- package/src/common/TypedEventEmitter.ts +0 -32
- package/src/common/callEventReports.ts +0 -178
- package/src/monitors/CallSummary.ts +0 -38
- package/src/monitors/CallSummaryMonitor.ts +0 -192
- package/src/monitors/ClientIssueMonitor.ts +0 -88
- package/src/monitors/SfuServerMonitor.ts +0 -285
- /package/lib/{monitors/CallSummary.js → ObservedCallSummary.js} +0 -0
package/src/Observer.ts
CHANGED
|
@@ -1,48 +1,37 @@
|
|
|
1
1
|
import { createLogger } from './common/logger';
|
|
2
|
-
import { ObservedCall,
|
|
3
|
-
import { ReportsCollector } from './ReportsCollector';
|
|
2
|
+
import { ObservedCall, ObservedCallSettings } from './ObservedCall';
|
|
4
3
|
import { EventEmitter } from 'events';
|
|
5
|
-
import {
|
|
6
|
-
import { createCallEndedEventReport, createCallStartedEventReport } from './common/callEventReports';
|
|
7
|
-
import { ObserverSinkContext } from './common/types';
|
|
8
|
-
import { ObservedSfu, ObservedSfuModel } from './ObservedSfu';
|
|
9
|
-
import { CallSummaryMonitor, CallSummaryMonitorConfig } from './monitors/CallSummaryMonitor';
|
|
10
|
-
import { TurnUsageMonitor } from './monitors/TurnUsageMonitor';
|
|
4
|
+
import { ClientEvent, ClientMetaData, ClientIssue, ExtensionStat, ClientSample } from './schema/ClientSample';
|
|
11
5
|
import { ObservedClient } from './ObservedClient';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
6
|
+
import { ObservedTURN } from './ObservedTURN';
|
|
7
|
+
import { Detectors } from './detectors/Detectors';
|
|
8
|
+
import { Updater } from './updaters/Updater';
|
|
9
|
+
import { OnIntervalUpdater } from './updaters/OnIntervalUpdater';
|
|
10
|
+
import { OnAllCallObserverUpdater } from './updaters/OnAllCallObserverUpdater';
|
|
11
|
+
import { OnAnyCallObserverUpdater } from './updaters/OnAnyCallObserverUpdater';
|
|
12
|
+
import { ObserverEventMonitor } from './ObserverEventMonitor';
|
|
13
|
+
import { MediasoupRemoteTrackResolver } from './utils/MediasoupRemoteTrackResolver';
|
|
15
14
|
|
|
16
15
|
const logger = createLogger('Observer');
|
|
17
16
|
|
|
18
17
|
export type ObserverEvents = {
|
|
18
|
+
'client-event': [ObservedClient, ClientEvent];
|
|
19
|
+
'call-updated': [ObservedCall],
|
|
20
|
+
'client-issue': [ObservedClient, ClientIssue],
|
|
21
|
+
'client-metadata': [ObservedClient, ClientMetaData],
|
|
22
|
+
'client-extension-stats': [ObservedClient, ExtensionStat],
|
|
19
23
|
'newcall': [ObservedCall],
|
|
20
|
-
'
|
|
21
|
-
'reports': [ObserverSinkContext],
|
|
24
|
+
'update': [],
|
|
22
25
|
'close': [],
|
|
23
26
|
}
|
|
24
27
|
|
|
25
|
-
export type ObserverConfig = {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
*
|
|
33
|
-
*/
|
|
34
|
-
defaultServiceId: string;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Sets the default mediaUnitId for samples.
|
|
38
|
-
*
|
|
39
|
-
* For more information about a mediaUnitId please visit https://observertc.org
|
|
40
|
-
*/
|
|
41
|
-
defaultMediaUnitId: string;
|
|
42
|
-
|
|
43
|
-
maxReports?: number | undefined;
|
|
44
|
-
maxCollectingTimeInMs?: number | undefined;
|
|
45
|
-
};
|
|
28
|
+
export type ObserverConfig<AppData extends Record<string, unknown> = Record<string, unknown>> = {
|
|
29
|
+
updatePolicy?: 'update-on-any-call-updated' | 'update-when-all-call-updated' | 'update-on-interval',
|
|
30
|
+
updateIntervalInMs?: number,
|
|
31
|
+
defaultCallUpdatePolicy?: ObservedCallSettings['updatePolicy'],
|
|
32
|
+
defaultCallUpdateIntervalInMs?: number,
|
|
33
|
+
appData?: AppData,
|
|
34
|
+
}
|
|
46
35
|
|
|
47
36
|
export declare interface Observer {
|
|
48
37
|
on<U extends keyof ObserverEvents>(event: U, listener: (...args: ObserverEvents[U]) => void): this;
|
|
@@ -51,313 +40,215 @@ export declare interface Observer {
|
|
|
51
40
|
emit<U extends keyof ObserverEvents>(event: U, ...args: ObserverEvents[U]): boolean;
|
|
52
41
|
}
|
|
53
42
|
|
|
54
|
-
export class Observer extends EventEmitter {
|
|
55
|
-
public
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
43
|
+
export class Observer<AppData extends Record<string, unknown> = Record<string, unknown>> extends EventEmitter {
|
|
44
|
+
public readonly detectors: Detectors;
|
|
45
|
+
|
|
46
|
+
public readonly observedTURN = new ObservedTURN();
|
|
47
|
+
public readonly observedCalls = new Map<string, ObservedCall>();
|
|
48
|
+
public updater?: Updater;
|
|
49
|
+
|
|
50
|
+
public closed = false;
|
|
51
|
+
|
|
52
|
+
public totalAddedCall = 0;
|
|
53
|
+
public totalRemovedCall = 0;
|
|
54
|
+
public totalRttLt50Measurements = 0;
|
|
55
|
+
public totalRttLt150Measurements = 0;
|
|
56
|
+
public totalRttLt300Measurements = 0;
|
|
57
|
+
public totalRttGtOrEq300Measurements = 0;
|
|
58
|
+
public totalClientIssues = 0;
|
|
59
|
+
|
|
60
|
+
public numberOfClientsUsingTurn = 0;
|
|
61
|
+
public numberOfClients = 0;
|
|
62
|
+
public numberOfInboundRtpStreams = 0;
|
|
63
|
+
public numberOfOutboundRtpStreams = 0;
|
|
64
|
+
public numberOfDataChannels = 0;
|
|
65
|
+
public numberOfPeerConnections = 0;
|
|
66
|
+
|
|
67
|
+
public get numberOfCalls() {
|
|
68
|
+
return this.observedCalls.size;
|
|
71
69
|
}
|
|
72
70
|
|
|
73
|
-
|
|
74
|
-
private readonly _observedCalls = new Map<string, ObservedCall>();
|
|
75
|
-
private readonly _observedSfus = new Map<string, ObservedSfu>();
|
|
76
|
-
private readonly _monitors = new Map<string, { close:() => void, once: (e: 'close', l: () => void) => void }>();
|
|
71
|
+
private _timer?: ReturnType<typeof setInterval>;
|
|
77
72
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
) {
|
|
73
|
+
public constructor(public readonly config: ObserverConfig<AppData> = {
|
|
74
|
+
updatePolicy: 'update-when-all-call-updated',
|
|
75
|
+
updateIntervalInMs: undefined,
|
|
76
|
+
appData: {} as AppData,
|
|
77
|
+
}) {
|
|
83
78
|
super();
|
|
84
79
|
this.setMaxListeners(Infinity);
|
|
80
|
+
this.update = this.update.bind(this);
|
|
85
81
|
|
|
86
|
-
|
|
82
|
+
if (this.config.updateIntervalInMs) {
|
|
83
|
+
if (this.config.updatePolicy && this.config.updatePolicy !== 'update-on-interval') {
|
|
84
|
+
throw new Error('update policy must be update-on-interval if updateIntervalInMs is set in config');
|
|
85
|
+
}
|
|
86
|
+
this._timer = setInterval(this.update.bind(this), this.config.updateIntervalInMs);
|
|
87
|
+
}
|
|
87
88
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (this.config.maxReports < collectedReports) {
|
|
92
|
-
this._emitReports();
|
|
89
|
+
if (this.config.updateIntervalInMs) {
|
|
90
|
+
if (this.config.updatePolicy !== 'update-on-interval') {
|
|
91
|
+
throw new Error('updatePolicy must be update-on-interval if updateIntervalInMs is set in config');
|
|
93
92
|
}
|
|
94
|
-
}
|
|
93
|
+
}
|
|
94
|
+
switch (this.config.updatePolicy) {
|
|
95
|
+
case 'update-on-any-call-updated':
|
|
96
|
+
this.updater = new OnAllCallObserverUpdater(this);
|
|
97
|
+
break;
|
|
98
|
+
case 'update-when-all-call-updated':
|
|
99
|
+
this.updater = new OnAnyCallObserverUpdater(this);
|
|
100
|
+
break;
|
|
101
|
+
case 'update-on-interval':
|
|
102
|
+
if (!this.config.updateIntervalInMs) {
|
|
103
|
+
throw new Error('updateIntervalInMs setting in config must be set if updatePolicy is update-on-interval');
|
|
104
|
+
}
|
|
105
|
+
this.updater = new OnIntervalUpdater(
|
|
106
|
+
this.config.updateIntervalInMs,
|
|
107
|
+
this.update.bind(this),
|
|
108
|
+
);
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
this.detectors = new Detectors();
|
|
113
|
+
}
|
|
95
114
|
|
|
96
|
-
|
|
115
|
+
public get appData() {
|
|
116
|
+
return this.config.appData;
|
|
117
|
+
}
|
|
97
118
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
this.reports.on('newreport', onNewReport);
|
|
103
|
-
this.reports.on('reports', onReports);
|
|
119
|
+
public getObservedCall<T extends Record<string, unknown> = Record<string, unknown>>(callId: string): ObservedCall<T> | undefined {
|
|
120
|
+
if (this.closed || !this.observedCalls.has(callId)) return;
|
|
121
|
+
|
|
122
|
+
return this.observedCalls.get(callId) as ObservedCall<T>;
|
|
104
123
|
}
|
|
105
124
|
|
|
106
125
|
public createObservedCall<T extends Record<string, unknown> = Record<string, unknown>>(
|
|
107
|
-
|
|
126
|
+
settings: ObservedCallSettings<T>
|
|
108
127
|
): ObservedCall<T> {
|
|
109
|
-
if (this.
|
|
128
|
+
if (this.closed) {
|
|
110
129
|
throw new Error('Attempted to create a call source on a closed observer');
|
|
111
130
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
reportCallEnded = true,
|
|
116
|
-
reportCallStarted = true,
|
|
117
|
-
...model
|
|
118
|
-
} = config;
|
|
119
|
-
const call = new ObservedCall({
|
|
120
|
-
...model,
|
|
121
|
-
serviceId: this.config.defaultServiceId,
|
|
122
|
-
}, this, appData);
|
|
123
|
-
|
|
124
|
-
if (this._closed) throw new Error('Cannot create an observed call on a closed observer');
|
|
125
|
-
if (this._observedCalls.has(call.callId)) throw new Error(`Observed Call with id ${call.callId} already exists`);
|
|
126
|
-
|
|
127
|
-
call.once('close', () => {
|
|
128
|
-
this._observedCalls.delete(call.callId);
|
|
129
|
-
reportCallEnded && this.reports.addCallEventReport(createCallEndedEventReport(
|
|
130
|
-
call.serviceId,
|
|
131
|
-
call.roomId,
|
|
132
|
-
call.callId,
|
|
133
|
-
call.observationEnded ?? Date.now(),
|
|
134
|
-
));
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
this._observedCalls.set(call.callId, call);
|
|
138
|
-
reportCallStarted && this.reports.addCallEventReport(createCallStartedEventReport(
|
|
139
|
-
call.serviceId,
|
|
140
|
-
call.roomId,
|
|
141
|
-
call.callId,
|
|
142
|
-
call.observationStarted,
|
|
143
|
-
));
|
|
144
|
-
|
|
145
|
-
this.emit('newcall', call);
|
|
146
|
-
|
|
147
|
-
return call;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
public createObservedSfu<AppData extends Record<string, unknown> = Record<string, unknown>>(
|
|
151
|
-
model: ObservedSfuModel,
|
|
152
|
-
appData: AppData,
|
|
153
|
-
): ObservedSfu<AppData> {
|
|
154
|
-
if (this._closed) {
|
|
155
|
-
throw new Error('Attempted to create an sfu source on a closed observer');
|
|
131
|
+
if (!settings.updatePolicy) {
|
|
132
|
+
settings.updatePolicy = this.config.defaultCallUpdatePolicy;
|
|
133
|
+
settings.updateIntervalInMs = this.config.defaultCallUpdateIntervalInMs;
|
|
156
134
|
}
|
|
135
|
+
const observedCall = new ObservedCall(settings, this);
|
|
136
|
+
const onCallUpdated = () => this._onObservedCallUpdated(observedCall);
|
|
157
137
|
|
|
158
|
-
|
|
138
|
+
if (this.observedCalls.has(observedCall.callId)) throw new Error(`Observed Call with id ${observedCall.callId} already exists`);
|
|
159
139
|
|
|
160
|
-
if (
|
|
161
|
-
|
|
140
|
+
if (settings.remoteTrackResolvePolicy === 'mediasoup-sfu') {
|
|
141
|
+
observedCall.remoteTrackResolver = new MediasoupRemoteTrackResolver(observedCall);
|
|
142
|
+
}
|
|
162
143
|
|
|
163
|
-
|
|
164
|
-
this.
|
|
144
|
+
observedCall.once('close', () => {
|
|
145
|
+
this.observedCalls.delete(observedCall.callId);
|
|
146
|
+
observedCall.off('update', onCallUpdated);
|
|
147
|
+
++this.totalRemovedCall;
|
|
165
148
|
});
|
|
166
149
|
|
|
167
|
-
this.
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
return sfu;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
public createCallSummaryMonitor(options?: CallSummaryMonitorConfig & { timeoutAfterCallClose?: number }): CallSummaryMonitor {
|
|
174
|
-
if (this._closed) throw new Error('Cannot create a call summary monitor on a closed observer');
|
|
175
|
-
|
|
176
|
-
const existingMonitor = this._monitors.get(CallSummaryMonitor.name);
|
|
177
|
-
|
|
178
|
-
if (existingMonitor) return existingMonitor as CallSummaryMonitor;
|
|
179
|
-
|
|
180
|
-
const monitor = new CallSummaryMonitor(options);
|
|
181
|
-
const onNewCall = (call: ObservedCall) => {
|
|
182
|
-
monitor.addCall(call);
|
|
183
|
-
|
|
184
|
-
call.once('close', () => setTimeout(() => {
|
|
185
|
-
const summary = monitor.takeSummary(call.callId);
|
|
150
|
+
this.observedCalls.set(observedCall.callId, observedCall);
|
|
151
|
+
observedCall.on('update', onCallUpdated);
|
|
152
|
+
++this.totalAddedCall;
|
|
186
153
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}, options?.timeoutAfterCallClose ?? 1000));
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
monitor.once('close', () => {
|
|
193
|
-
this._monitors.delete(CallSummaryMonitor.name);
|
|
194
|
-
this.off('newcall', onNewCall);
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
this._monitors.set(CallSummaryMonitor.name, monitor);
|
|
198
|
-
this.on('newcall', onNewCall);
|
|
154
|
+
this.emit('newcall', observedCall);
|
|
199
155
|
|
|
200
|
-
|
|
201
|
-
monitor.close();
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
return monitor;
|
|
156
|
+
return observedCall;
|
|
205
157
|
}
|
|
206
158
|
|
|
207
|
-
public
|
|
208
|
-
if (this.
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
const monitor = new TurnUsageMonitor();
|
|
215
|
-
|
|
216
|
-
const onNewCall = (call: ObservedCall) => {
|
|
217
|
-
const onNewClient = (client: ObservedClient) => {
|
|
218
|
-
const onNewPeerConnection = (pc: ObservedPeerConnection) => {
|
|
219
|
-
const onUsingTurnChanged = (usingTurn: boolean) => {
|
|
220
|
-
if (usingTurn) monitor.addPeerConnection(pc);
|
|
221
|
-
else monitor.removePeerConnection(pc);
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
pc.once('close', () => {
|
|
225
|
-
pc.ICE.off('usingturnchanged', onUsingTurnChanged);
|
|
226
|
-
monitor.removePeerConnection(pc);
|
|
227
|
-
});
|
|
228
|
-
pc.ICE.on('usingturnchanged', onUsingTurnChanged);
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
client.once('close', () => client.off('newpeerconnection', onNewPeerConnection));
|
|
232
|
-
client.on('newpeerconnection', onNewPeerConnection);
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
call.once('close', () => call.off('newclient', onNewClient));
|
|
236
|
-
call.on('newclient', onNewClient);
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
monitor.once('close', () => {
|
|
240
|
-
this._monitors.delete(TurnUsageMonitor.name);
|
|
241
|
-
this.off('newcall', onNewCall);
|
|
242
|
-
});
|
|
159
|
+
public close() {
|
|
160
|
+
if (this.closed) {
|
|
161
|
+
return logger.debug('Attempted to close twice');
|
|
162
|
+
}
|
|
163
|
+
this.closed = true;
|
|
164
|
+
clearInterval(this._timer);
|
|
165
|
+
this._timer = undefined;
|
|
243
166
|
|
|
244
|
-
this.
|
|
245
|
-
this.on('newcall', onNewCall);
|
|
167
|
+
this.observedCalls.forEach((call) => call.close());
|
|
246
168
|
|
|
247
|
-
this.
|
|
248
|
-
monitor.close();
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
return monitor;
|
|
169
|
+
this.emit('close');
|
|
252
170
|
}
|
|
253
171
|
|
|
254
|
-
public
|
|
255
|
-
if (this.
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
if (existingMonitor) return existingMonitor as SfuServerMonitor;
|
|
260
|
-
|
|
261
|
-
const monitor = new SfuServerMonitor({
|
|
262
|
-
tooHighRttAlertSettings: {
|
|
263
|
-
minNumberOfPeerConnections: 10,
|
|
264
|
-
percentageOfPeerConnectionsHighWatermark: 0.5,
|
|
265
|
-
percentageOfPeerConnectionsLowWatermark: 0.2,
|
|
266
|
-
threshold: 'rtt-gt-300',
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
const onNewCall = (call: ObservedCall) => {
|
|
271
|
-
const onNewClient = (client: ObservedClient) => {
|
|
272
|
-
const onNewPeerConnection = (pc: ObservedPeerConnection) => {
|
|
273
|
-
monitor.addPeerConnection(pc);
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
client.once('close', () => client.off('newpeerconnection', onNewPeerConnection));
|
|
277
|
-
client.on('newpeerconnection', onNewPeerConnection);
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
call.once('close', () => call.off('newclient', onNewClient));
|
|
281
|
-
call.on('newclient', onNewClient);
|
|
282
|
-
};
|
|
172
|
+
public accept(sample: ClientSample) {
|
|
173
|
+
if (this.closed) return;
|
|
174
|
+
if (!sample.callId) return logger.warn('Received sample without callId. %o', sample);
|
|
175
|
+
if (!sample.clientId) return logger.warn('Received sample without clientId %o', sample);
|
|
283
176
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
this.
|
|
177
|
+
const call = this.getObservedCall(sample.callId) ?? this.createObservedCall({
|
|
178
|
+
callId: sample.callId,
|
|
179
|
+
updateIntervalInMs: this.config.defaultCallUpdateIntervalInMs,
|
|
180
|
+
updatePolicy: this.config.defaultCallUpdatePolicy,
|
|
287
181
|
});
|
|
288
182
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
this.once('close', () => {
|
|
293
|
-
monitor.close();
|
|
183
|
+
const client = call.getObservedClient(sample.clientId) ?? call.createObservedClient({
|
|
184
|
+
clientId: sample.clientId,
|
|
294
185
|
});
|
|
295
186
|
|
|
296
|
-
|
|
187
|
+
client.accept(sample);
|
|
297
188
|
}
|
|
298
189
|
|
|
299
|
-
public
|
|
300
|
-
if (this.
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
if (existingMonitor) return existingMonitor as ClientIssueMonitor;
|
|
305
|
-
|
|
306
|
-
const monitor = new ClientIssueMonitor();
|
|
307
|
-
|
|
308
|
-
const onNewCall = (call: ObservedCall) => monitor.addCall(call);
|
|
309
|
-
|
|
310
|
-
monitor.once('close', () => {
|
|
311
|
-
this._monitors.delete(ClientIssueMonitor.name);
|
|
312
|
-
this.off('newcall', onNewCall);
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
this._monitors.set(ClientIssueMonitor.name, monitor);
|
|
316
|
-
this.on('newcall', onNewCall);
|
|
317
|
-
|
|
318
|
-
this.once('close', () => {
|
|
319
|
-
monitor.close();
|
|
320
|
-
});
|
|
190
|
+
public update() {
|
|
191
|
+
if (this.closed) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
321
194
|
|
|
322
|
-
|
|
323
|
-
|
|
195
|
+
this.numberOfInboundRtpStreams = 0;
|
|
196
|
+
this.numberOfOutboundRtpStreams = 0;
|
|
197
|
+
this.numberOfPeerConnections = 0;
|
|
198
|
+
this.numberOfDataChannels = 0;
|
|
199
|
+
this.numberOfClients = 0;
|
|
200
|
+
this.numberOfClientsUsingTurn = 0;
|
|
201
|
+
|
|
202
|
+
for (const call of this.observedCalls.values()) {
|
|
203
|
+
this.numberOfInboundRtpStreams += call.numberOfInboundRtpStreams;
|
|
204
|
+
this.numberOfOutboundRtpStreams += call.numberOfOutboundRtpStreams;
|
|
205
|
+
this.numberOfPeerConnections += call.numberOfPeerConnections;
|
|
206
|
+
this.numberOfDataChannels += call.numberOfDataChannels;
|
|
207
|
+
this.numberOfClients += call.numberOfClients;
|
|
208
|
+
this.numberOfClientsUsingTurn += call.clientsUsedTurn.size;
|
|
209
|
+
}
|
|
324
210
|
|
|
325
|
-
|
|
326
|
-
return this._observedCalls;
|
|
327
|
-
}
|
|
211
|
+
this.observedTURN.update();
|
|
328
212
|
|
|
329
|
-
|
|
330
|
-
return this._observedSfus;
|
|
213
|
+
this.emit('update');
|
|
331
214
|
}
|
|
332
215
|
|
|
333
|
-
|
|
334
|
-
|
|
216
|
+
private _onObservedCallUpdated(call: ObservedCall) {
|
|
217
|
+
this.totalRttLt50Measurements += call.deltaRttLt50Measurements;
|
|
218
|
+
this.totalRttLt150Measurements += call.deltaRttLt150Measurements;
|
|
219
|
+
this.totalRttLt300Measurements += call.deltaRttLt300Measurements;
|
|
220
|
+
this.totalRttGtOrEq300Measurements += call.deltaRttGtOrEq300Measurements;
|
|
221
|
+
this.totalClientIssues += call.deltaNumberOfIssues;
|
|
335
222
|
}
|
|
336
223
|
|
|
337
|
-
public
|
|
338
|
-
|
|
339
|
-
return logger.debug('Attempted to close twice');
|
|
340
|
-
}
|
|
341
|
-
this._closed = true;
|
|
342
|
-
|
|
343
|
-
this._observedCalls.forEach((call) => call.close());
|
|
344
|
-
|
|
345
|
-
this.emit('close');
|
|
224
|
+
public createEventMonitor<CTX = unknown>(ctx?: CTX): ObserverEventMonitor<CTX> {
|
|
225
|
+
return new ObserverEventMonitor<CTX>(this, ctx ?? {} as CTX);
|
|
346
226
|
}
|
|
347
227
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
228
|
+
// public resetSummaryMetrics() {
|
|
229
|
+
// this.totalAddedCall = 0;
|
|
230
|
+
// this.totalRemovedCall = 0;
|
|
231
|
+
// this.totalRttLt50Measurements = 0;
|
|
232
|
+
// this.totalRttLt150Measurements = 0;
|
|
233
|
+
// this.totalRttLt300Measurements = 0;
|
|
234
|
+
// this.totalRttGtOrEq300Measurements = 0;
|
|
235
|
+
// this.totalClientIssues = 0;
|
|
236
|
+
// }
|
|
237
|
+
|
|
238
|
+
// public createSummary(): ObserverSummary {
|
|
239
|
+
// return {
|
|
240
|
+
// totalAddedCall: this.totalAddedCall,
|
|
241
|
+
// totalRemovedCall: this.totalRemovedCall,
|
|
242
|
+
// totalRttLt50Measurements: this.totalRttLt50Measurements,
|
|
243
|
+
// totalRttLt150Measurements: this.totalRttLt150Measurements,
|
|
244
|
+
// totalRttLt300Measurements: this.totalRttLt300Measurements,
|
|
245
|
+
// totalRttGtOrEq300Measurements: this.totalRttGtOrEq300Measurements,
|
|
246
|
+
|
|
247
|
+
// totalClientIssues: this.totalClientIssues,
|
|
248
|
+
// currentActiveCalls: this.observedCalls.size,
|
|
249
|
+
// currentNumberOfClients: this.numberOfClients,
|
|
250
|
+
// currentNumberOfClientsUsingTURN: this.numberOfClientsUsedTurn,
|
|
251
|
+
// };
|
|
252
|
+
// }
|
|
355
253
|
|
|
356
|
-
if (this.config.maxCollectingTimeInMs) {
|
|
357
|
-
this._reportTimer = setTimeout(() => {
|
|
358
|
-
this._reportTimer = undefined;
|
|
359
|
-
this._emitReports();
|
|
360
|
-
}, this.config.maxCollectingTimeInMs);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
254
|
}
|