@observertc/observer-js 0.42.9 → 1.0.1-23e88d8.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 +25 -41
- package/lib/ObservedCall.d.ts.map +1 -1
- package/lib/ObservedCall.js +61 -109
- 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 +33 -143
- package/lib/ObservedClient.d.ts.map +1 -1
- package/lib/ObservedClient.js +156 -757
- 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 +20 -70
- package/lib/ObservedDataChannel.d.ts.map +1 -1
- package/lib/ObservedDataChannel.js +39 -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 +40 -0
- package/lib/ObservedIceCandidatePair.d.ts.map +1 -0
- package/lib/ObservedIceCandidatePair.js +83 -0
- package/lib/ObservedIceTransport.d.ts +32 -0
- package/lib/ObservedIceTransport.d.ts.map +1 -0
- package/lib/ObservedIceTransport.js +65 -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 +29 -0
- package/lib/ObservedInboundTrack.d.ts.map +1 -0
- package/lib/ObservedInboundTrack.js +57 -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 +29 -0
- package/lib/ObservedOutboundTrack.d.ts.map +1 -0
- package/lib/ObservedOutboundTrack.js +57 -0
- package/lib/ObservedPeerConnection.d.ts +118 -78
- package/lib/ObservedPeerConnection.d.ts.map +1 -1
- package/lib/ObservedPeerConnection.js +556 -359
- 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/Observer.d.ts +30 -53
- package/lib/Observer.d.ts.map +1 -1
- package/lib/Observer.js +52 -225
- 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 +1 -0
- package/lib/common/utils.d.ts.map +1 -1
- package/lib/common/utils.js +13 -1
- 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 +23 -25
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +41 -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 +33 -0
- package/lib/schema/ClientEventTypes.d.ts.map +1 -0
- package/lib/schema/ClientEventTypes.js +38 -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/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/utils/CallUpdater.d.ts +5 -0
- package/lib/utils/CallUpdater.d.ts.map +1 -0
- package/lib/utils/CallUpdater.js +2 -0
- package/lib/utils/OnAllClientCallUpdater.d.ts +16 -0
- package/lib/utils/OnAllClientCallUpdater.d.ts.map +1 -0
- package/lib/utils/OnAllClientCallUpdater.js +58 -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/lib/utils/onAnyClientCallUpdater.d.ts +14 -0
- package/lib/utils/onAnyClientCallUpdater.d.ts.map +1 -0
- package/lib/utils/onAnyClientCallUpdater.js +51 -0
- package/package.json +4 -4
- package/src/ObservedCall.ts +74 -167
- package/src/ObservedCertificate.ts +43 -0
- package/src/ObservedClient.ts +173 -1085
- package/src/ObservedCodec.ts +49 -0
- package/src/ObservedDataChannel.ts +36 -178
- package/src/ObservedIceCandidate.ts +64 -0
- package/src/ObservedIceCandidatePair.ts +92 -0
- package/src/ObservedIceTransport.ts +70 -0
- package/src/ObservedInboundRtp.ts +205 -0
- package/src/ObservedInboundTrack.ts +70 -0
- package/src/ObservedMediaPlayout.ts +49 -0
- package/src/ObservedMediaSource.ts +60 -0
- package/src/ObservedOutboundRtp.ts +156 -0
- package/src/ObservedOutboundTrack.ts +69 -0
- package/src/ObservedPeerConnection.ts +743 -401
- package/src/ObservedPeerConnectionTransport.ts +38 -0
- package/src/ObservedRemoteInboundRtp.ts +64 -0
- package/src/ObservedRemoteOutboundRtp.ts +65 -0
- package/src/Observer.ts +65 -285
- 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 +12 -0
- package/src/detectors/Detector.ts +6 -0
- package/src/detectors/Detectors.ts +38 -0
- package/src/index.ts +23 -90
- package/src/monitors/TurnUsageMonitor.ts +164 -164
- package/src/schema/ClientEventTypes.ts +36 -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/utils/CallUpdater.ts +5 -0
- package/src/utils/OnAllClientCallUpdater.ts +68 -0
- package/src/utils/RemoteTrackResolver.ts +12 -0
- package/src/utils/onAnyClientCallUpdater.ts +59 -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 → scores/CalculatedScore.js} +0 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ObservedPeerConnection } from './ObservedPeerConnection';
|
|
2
|
+
import { PeerConnectionTransportStats } from './schema/ClientSample';
|
|
3
|
+
|
|
4
|
+
export class ObservedPeerConnectionTransport implements PeerConnectionTransportStats {
|
|
5
|
+
private _visited = false;
|
|
6
|
+
public appData?: Record<string, unknown>;
|
|
7
|
+
|
|
8
|
+
dataChannelsOpened?: number | undefined;
|
|
9
|
+
dataChannelsClosed?: number | undefined;
|
|
10
|
+
attachments?: Record<string, unknown> | undefined;
|
|
11
|
+
|
|
12
|
+
public constructor(
|
|
13
|
+
public timestamp: number,
|
|
14
|
+
public id: string,
|
|
15
|
+
private readonly _peerConnection: ObservedPeerConnection
|
|
16
|
+
) {}
|
|
17
|
+
|
|
18
|
+
public get visited() {
|
|
19
|
+
const visited = this._visited;
|
|
20
|
+
|
|
21
|
+
this._visited = false;
|
|
22
|
+
|
|
23
|
+
return visited;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public getPeerConnection() {
|
|
27
|
+
return this._peerConnection;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public update(stats: PeerConnectionTransportStats) {
|
|
31
|
+
this._visited = true;
|
|
32
|
+
|
|
33
|
+
this.timestamp = stats.timestamp;
|
|
34
|
+
this.dataChannelsOpened = stats.dataChannelsOpened;
|
|
35
|
+
this.dataChannelsClosed = stats.dataChannelsClosed;
|
|
36
|
+
this.attachments = stats.attachments;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { MediaKind } from './common/types';
|
|
2
|
+
import { ObservedPeerConnection } from './ObservedPeerConnection';
|
|
3
|
+
import { RemoteInboundRtpStats } from './schema/ClientSample';
|
|
4
|
+
|
|
5
|
+
export class ObservedRemoteInboundRtp implements RemoteInboundRtpStats {
|
|
6
|
+
private _visited = false;
|
|
7
|
+
public appData?: Record<string, unknown>;
|
|
8
|
+
transportId?: string | undefined;
|
|
9
|
+
codecId?: string | undefined;
|
|
10
|
+
packetsReceived?: number | undefined;
|
|
11
|
+
packetsLost?: number | undefined;
|
|
12
|
+
jitter?: number | undefined;
|
|
13
|
+
localId?: string | undefined;
|
|
14
|
+
roundTripTime?: number | undefined;
|
|
15
|
+
totalRoundTripTime?: number | undefined;
|
|
16
|
+
fractionLost?: number | undefined;
|
|
17
|
+
roundTripTimeMeasurements?: number | undefined;
|
|
18
|
+
attachments?: Record<string, unknown> | undefined;
|
|
19
|
+
|
|
20
|
+
public constructor(
|
|
21
|
+
public timestamp: number,
|
|
22
|
+
public id: string,
|
|
23
|
+
public ssrc: number,
|
|
24
|
+
public kind: MediaKind,
|
|
25
|
+
private readonly _peerConnection: ObservedPeerConnection
|
|
26
|
+
) {}
|
|
27
|
+
|
|
28
|
+
public get visited() {
|
|
29
|
+
const visited = this._visited;
|
|
30
|
+
|
|
31
|
+
this._visited = false;
|
|
32
|
+
|
|
33
|
+
return visited;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public getPeerConnection() {
|
|
37
|
+
return this._peerConnection;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public getOutboundRtp() {
|
|
41
|
+
return this._peerConnection.observedOutboundRtps.get(this.ssrc);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public getCodec() {
|
|
45
|
+
return this._peerConnection.observedCodecs.get(this.codecId ?? '');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public update(stats: RemoteInboundRtpStats) {
|
|
49
|
+
this._visited = true;
|
|
50
|
+
|
|
51
|
+
this.timestamp = stats.timestamp;
|
|
52
|
+
this.transportId = stats.transportId;
|
|
53
|
+
this.codecId = stats.codecId;
|
|
54
|
+
this.packetsReceived = stats.packetsReceived;
|
|
55
|
+
this.packetsLost = stats.packetsLost;
|
|
56
|
+
this.jitter = stats.jitter;
|
|
57
|
+
this.localId = stats.localId;
|
|
58
|
+
this.roundTripTime = stats.roundTripTime;
|
|
59
|
+
this.totalRoundTripTime = stats.totalRoundTripTime;
|
|
60
|
+
this.fractionLost = stats.fractionLost;
|
|
61
|
+
this.roundTripTimeMeasurements = stats.roundTripTimeMeasurements;
|
|
62
|
+
this.attachments = stats.attachments;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { MediaKind } from './common/types';
|
|
2
|
+
import { ObservedPeerConnection } from './ObservedPeerConnection';
|
|
3
|
+
import { RemoteOutboundRtpStats } from './schema/ClientSample';
|
|
4
|
+
|
|
5
|
+
export class ObservedRemoteOutboundRtp implements RemoteOutboundRtpStats {
|
|
6
|
+
private _visited = false;
|
|
7
|
+
public appData?: Record<string, unknown>;
|
|
8
|
+
|
|
9
|
+
transportId?: string | undefined;
|
|
10
|
+
codecId?: string | undefined;
|
|
11
|
+
packetsSent?: number | undefined;
|
|
12
|
+
bytesSent?: number | undefined;
|
|
13
|
+
localId?: string | undefined;
|
|
14
|
+
remoteTimestamp?: number | undefined;
|
|
15
|
+
reportsSent?: number | undefined;
|
|
16
|
+
roundTripTime?: number | undefined;
|
|
17
|
+
totalRoundTripTime?: number | undefined;
|
|
18
|
+
roundTripTimeMeasurements?: number | undefined;
|
|
19
|
+
attachments?: Record<string, unknown> | undefined;
|
|
20
|
+
|
|
21
|
+
public constructor(
|
|
22
|
+
public timestamp: number,
|
|
23
|
+
public id: string,
|
|
24
|
+
public ssrc: number,
|
|
25
|
+
public kind: MediaKind,
|
|
26
|
+
private readonly _peerConnection: ObservedPeerConnection
|
|
27
|
+
) {}
|
|
28
|
+
|
|
29
|
+
public get visited() {
|
|
30
|
+
const visited = this._visited;
|
|
31
|
+
|
|
32
|
+
this._visited = false;
|
|
33
|
+
|
|
34
|
+
return visited;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public getPeerConnection() {
|
|
38
|
+
return this._peerConnection;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public getInboundRtp() {
|
|
42
|
+
return this._peerConnection.observedInboundRtps.get(this.ssrc);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public getCodec() {
|
|
46
|
+
return this._peerConnection.observedCodecs.get(this.codecId ?? '');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public update(stats: RemoteOutboundRtpStats) {
|
|
50
|
+
this._visited = true;
|
|
51
|
+
|
|
52
|
+
this.timestamp = stats.timestamp;
|
|
53
|
+
this.transportId = stats.transportId;
|
|
54
|
+
this.codecId = stats.codecId;
|
|
55
|
+
this.packetsSent = stats.packetsSent;
|
|
56
|
+
this.bytesSent = stats.bytesSent;
|
|
57
|
+
this.localId = stats.localId;
|
|
58
|
+
this.remoteTimestamp = stats.remoteTimestamp;
|
|
59
|
+
this.reportsSent = stats.reportsSent;
|
|
60
|
+
this.roundTripTime = stats.roundTripTime;
|
|
61
|
+
this.totalRoundTripTime = stats.totalRoundTripTime;
|
|
62
|
+
this.roundTripTimeMeasurements = stats.roundTripTimeMeasurements;
|
|
63
|
+
this.attachments = stats.attachments;
|
|
64
|
+
}
|
|
65
|
+
}
|
package/src/Observer.ts
CHANGED
|
@@ -1,48 +1,22 @@
|
|
|
1
1
|
import { createLogger } from './common/logger';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { Middleware, MiddlewareProcessor } from './common/Middleware';
|
|
3
|
+
import { ObservedCall, ObservedCallSettings } from './ObservedCall';
|
|
4
4
|
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';
|
|
5
|
+
import { ClientEvent, ClientMetaData, ClientIssue, ExtensionStat } from './schema/ClientSample';
|
|
11
6
|
import { ObservedClient } from './ObservedClient';
|
|
12
|
-
import { ObservedPeerConnection } from './ObservedPeerConnection';
|
|
13
|
-
import { ClientIssueMonitor } from './monitors/ClientIssueMonitor';
|
|
14
|
-
import { SfuServerMonitor } from './monitors/SfuServerMonitor';
|
|
15
7
|
|
|
16
8
|
const logger = createLogger('Observer');
|
|
17
9
|
|
|
18
10
|
export type ObserverEvents = {
|
|
19
11
|
'newcall': [ObservedCall],
|
|
20
|
-
'newsfu': [ObservedSfu],
|
|
21
|
-
'reports': [ObserverSinkContext],
|
|
22
12
|
'close': [],
|
|
23
13
|
}
|
|
24
14
|
|
|
25
|
-
export type
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
*
|
|
31
|
-
* For more information about a serviceId please visit https://observertc.org
|
|
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
|
-
};
|
|
15
|
+
export type ProcessorInputContext<T> = {
|
|
16
|
+
call: ObservedCall;
|
|
17
|
+
client: ObservedClient;
|
|
18
|
+
data: T;
|
|
19
|
+
}
|
|
46
20
|
|
|
47
21
|
export declare interface Observer {
|
|
48
22
|
on<U extends keyof ObserverEvents>(event: U, listener: (...args: ObserverEvents[U]) => void): this;
|
|
@@ -51,313 +25,119 @@ export declare interface Observer {
|
|
|
51
25
|
emit<U extends keyof ObserverEvents>(event: U, ...args: ObserverEvents[U]): boolean;
|
|
52
26
|
}
|
|
53
27
|
|
|
28
|
+
export type ObserverSummary = {
|
|
29
|
+
rttlt50: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
54
32
|
export class Observer extends EventEmitter {
|
|
55
|
-
public
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
fetchSamples: true,
|
|
62
|
-
maxIdleTimeInMs: 300 * 1000,
|
|
63
|
-
},
|
|
64
|
-
sink: {},
|
|
65
|
-
logLevel: 'info',
|
|
66
|
-
},
|
|
67
|
-
providedConfig
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
return new Observer(config);
|
|
71
|
-
}
|
|
33
|
+
public readonly processors = {
|
|
34
|
+
events: new MiddlewareProcessor<ProcessorInputContext<ClientEvent>>(),
|
|
35
|
+
metaData: new MiddlewareProcessor<ProcessorInputContext<ClientMetaData>>(),
|
|
36
|
+
issues: new MiddlewareProcessor<ProcessorInputContext<ClientIssue>>(),
|
|
37
|
+
extensionStats: new MiddlewareProcessor<ProcessorInputContext<ExtensionStat>>(),
|
|
38
|
+
};
|
|
72
39
|
|
|
73
|
-
public readonly
|
|
74
|
-
|
|
75
|
-
private readonly _observedSfus = new Map<string, ObservedSfu>();
|
|
76
|
-
private readonly _monitors = new Map<string, { close:() => void, once: (e: 'close', l: () => void) => void }>();
|
|
40
|
+
public readonly observedCalls = new Map<string, ObservedCall>();
|
|
41
|
+
public closed = false;
|
|
77
42
|
|
|
78
|
-
private _reportTimer?: ReturnType<typeof setTimeout>;
|
|
79
|
-
private _closed = false;
|
|
80
43
|
public constructor(
|
|
81
|
-
public readonly config: ObserverConfig,
|
|
82
44
|
) {
|
|
83
45
|
super();
|
|
84
46
|
this.setMaxListeners(Infinity);
|
|
47
|
+
}
|
|
85
48
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (!this.config.maxReports || this._closed) return;
|
|
91
|
-
if (this.config.maxReports < collectedReports) {
|
|
92
|
-
this._emitReports();
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
this._emitReports();
|
|
97
|
-
|
|
98
|
-
this.once('close', () => {
|
|
99
|
-
this.reports.off('newreport', onNewReport);
|
|
100
|
-
this.reports.off('reports', onReports);
|
|
101
|
-
});
|
|
102
|
-
this.reports.on('newreport', onNewReport);
|
|
103
|
-
this.reports.on('reports', onReports);
|
|
49
|
+
public getObservedCall<T extends Record<string, unknown> = Record<string, unknown>>(callId: string): ObservedCall<T> | undefined {
|
|
50
|
+
if (this.closed || !this.observedCalls.has(callId)) return;
|
|
51
|
+
|
|
52
|
+
return this.observedCalls.get(callId) as ObservedCall<T>;
|
|
104
53
|
}
|
|
105
54
|
|
|
106
55
|
public createObservedCall<T extends Record<string, unknown> = Record<string, unknown>>(
|
|
107
|
-
|
|
56
|
+
settings: ObservedCallSettings<T>
|
|
108
57
|
): ObservedCall<T> {
|
|
109
|
-
if (this.
|
|
58
|
+
if (this.closed) {
|
|
110
59
|
throw new Error('Attempted to create a call source on a closed observer');
|
|
111
60
|
}
|
|
112
61
|
|
|
113
|
-
const
|
|
114
|
-
appData,
|
|
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');
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const sfu = new ObservedSfu<AppData>(model, this, appData);
|
|
62
|
+
const observedCall = new ObservedCall(settings, this);
|
|
159
63
|
|
|
160
|
-
if (this.
|
|
161
|
-
if (this._observedSfus.has(sfu.sfuId)) throw new Error(`Observed SFU with id ${sfu.sfuId} already exists`);
|
|
64
|
+
if (this.observedCalls.has(observedCall.callId)) throw new Error(`Observed Call with id ${observedCall.callId} already exists`);
|
|
162
65
|
|
|
163
|
-
|
|
164
|
-
this.
|
|
66
|
+
observedCall.once('close', () => {
|
|
67
|
+
this.observedCalls.delete(observedCall.callId);
|
|
165
68
|
});
|
|
166
69
|
|
|
167
|
-
this.
|
|
168
|
-
this.emit('newsfu', sfu);
|
|
169
|
-
|
|
170
|
-
return sfu;
|
|
171
|
-
}
|
|
70
|
+
this.observedCalls.set(observedCall.callId, observedCall);
|
|
172
71
|
|
|
173
|
-
|
|
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);
|
|
72
|
+
this.emit('newcall', observedCall);
|
|
177
73
|
|
|
178
|
-
|
|
74
|
+
return observedCall;
|
|
75
|
+
}
|
|
179
76
|
|
|
180
|
-
|
|
181
|
-
const onNewCall = (call: ObservedCall) => {
|
|
182
|
-
monitor.addCall(call);
|
|
77
|
+
public addClientEventMiddleware(...middlewares: Middleware<ProcessorInputContext<ClientEvent>>[]): Observer {
|
|
183
78
|
|
|
184
|
-
|
|
185
|
-
const summary = monitor.takeSummary(call.callId);
|
|
79
|
+
this.processors.events.addMiddleware(...middlewares);
|
|
186
80
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}, options?.timeoutAfterCallClose ?? 1000));
|
|
190
|
-
};
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
191
83
|
|
|
192
|
-
|
|
193
|
-
this._monitors.delete(CallSummaryMonitor.name);
|
|
194
|
-
this.off('newcall', onNewCall);
|
|
195
|
-
});
|
|
84
|
+
public removeClientEventMiddleware(...middlewares: Middleware<ProcessorInputContext<ClientEvent>>[]): Observer {
|
|
196
85
|
|
|
197
|
-
this.
|
|
198
|
-
this.on('newcall', onNewCall);
|
|
199
|
-
|
|
200
|
-
this.once('close', () => {
|
|
201
|
-
monitor.close();
|
|
202
|
-
});
|
|
86
|
+
this.processors.events.removeMiddleware(...middlewares);
|
|
203
87
|
|
|
204
|
-
return
|
|
88
|
+
return this;
|
|
205
89
|
}
|
|
206
90
|
|
|
207
|
-
public
|
|
208
|
-
if (this._closed) throw new Error('Cannot create a turn usage monitor on a closed observer');
|
|
91
|
+
public addClientMetaDataMiddleware(...middlewares: Middleware<ProcessorInputContext<ClientMetaData>>[]): Observer {
|
|
209
92
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
if (existingMonitor) return existingMonitor as TurnUsageMonitor;
|
|
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
|
-
});
|
|
93
|
+
this.processors.metaData.addMiddleware(...middlewares);
|
|
243
94
|
|
|
244
|
-
this
|
|
245
|
-
this.on('newcall', onNewCall);
|
|
246
|
-
|
|
247
|
-
this.once('close', () => {
|
|
248
|
-
monitor.close();
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
return monitor;
|
|
95
|
+
return this;
|
|
252
96
|
}
|
|
253
97
|
|
|
254
|
-
public
|
|
255
|
-
if (this._closed) throw new Error('Cannot create a turn usage monitor on a closed observer');
|
|
256
|
-
|
|
257
|
-
const existingMonitor = this._monitors.get(SfuServerMonitor.name);
|
|
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
|
-
});
|
|
98
|
+
public removeClientMetaDataMiddleware(...middlewares: Middleware<ProcessorInputContext<ClientMetaData>>[]): Observer {
|
|
269
99
|
|
|
270
|
-
|
|
271
|
-
const onNewClient = (client: ObservedClient) => {
|
|
272
|
-
const onNewPeerConnection = (pc: ObservedPeerConnection) => {
|
|
273
|
-
monitor.addPeerConnection(pc);
|
|
274
|
-
};
|
|
100
|
+
this.processors.metaData.removeMiddleware(...middlewares);
|
|
275
101
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
};
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
279
104
|
|
|
280
|
-
|
|
281
|
-
call.on('newclient', onNewClient);
|
|
282
|
-
};
|
|
105
|
+
public addClientIssueMiddleware(...middlewares: Middleware<ProcessorInputContext<ClientIssue>>[]): Observer {
|
|
283
106
|
|
|
284
|
-
|
|
285
|
-
this._monitors.delete(SfuServerMonitor.name);
|
|
286
|
-
this.off('newcall', onNewCall);
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
this._monitors.set(SfuServerMonitor.name, monitor);
|
|
290
|
-
this.on('newcall', onNewCall);
|
|
291
|
-
|
|
292
|
-
this.once('close', () => {
|
|
293
|
-
monitor.close();
|
|
294
|
-
});
|
|
107
|
+
this.processors.issues.addMiddleware(...middlewares);
|
|
295
108
|
|
|
296
|
-
return
|
|
109
|
+
return this;
|
|
297
110
|
}
|
|
298
111
|
|
|
299
|
-
public
|
|
300
|
-
if (this._closed) throw new Error('Cannot create a turn usage monitor on a closed observer');
|
|
112
|
+
public removeClientIssueMiddleware(...middlewares: Middleware<ProcessorInputContext<ClientIssue>>[]): Observer {
|
|
301
113
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
if (existingMonitor) return existingMonitor as ClientIssueMonitor;
|
|
114
|
+
this.processors.issues.removeMiddleware(...middlewares);
|
|
305
115
|
|
|
306
|
-
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
307
118
|
|
|
308
|
-
|
|
119
|
+
public addExtensionStatMiddleware(...middlewares: Middleware<ProcessorInputContext<ExtensionStat>>[]): Observer {
|
|
309
120
|
|
|
310
|
-
|
|
311
|
-
this._monitors.delete(ClientIssueMonitor.name);
|
|
312
|
-
this.off('newcall', onNewCall);
|
|
313
|
-
});
|
|
121
|
+
this.processors.extensionStats.addMiddleware(...middlewares);
|
|
314
122
|
|
|
315
|
-
this
|
|
316
|
-
this.on('newcall', onNewCall);
|
|
317
|
-
|
|
318
|
-
this.once('close', () => {
|
|
319
|
-
monitor.close();
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
return monitor;
|
|
123
|
+
return this;
|
|
323
124
|
}
|
|
324
125
|
|
|
325
|
-
public
|
|
326
|
-
return this._observedCalls;
|
|
327
|
-
}
|
|
126
|
+
public removeExtensionStatMiddleware(...middlewares: Middleware<ProcessorInputContext<ExtensionStat>>[]): Observer {
|
|
328
127
|
|
|
329
|
-
|
|
330
|
-
return this._observedSfus;
|
|
331
|
-
}
|
|
128
|
+
this.processors.extensionStats.removeMiddleware(...middlewares);
|
|
332
129
|
|
|
333
|
-
|
|
334
|
-
return this._closed;
|
|
130
|
+
return this;
|
|
335
131
|
}
|
|
336
132
|
|
|
337
133
|
public close() {
|
|
338
|
-
if (this.
|
|
134
|
+
if (this.closed) {
|
|
339
135
|
return logger.debug('Attempted to close twice');
|
|
340
136
|
}
|
|
341
|
-
this.
|
|
137
|
+
this.closed = true;
|
|
342
138
|
|
|
343
|
-
this.
|
|
139
|
+
this.observedCalls.forEach((call) => call.close());
|
|
344
140
|
|
|
345
141
|
this.emit('close');
|
|
346
142
|
}
|
|
347
|
-
|
|
348
|
-
private _emitReports() {
|
|
349
|
-
if (this._reportTimer) {
|
|
350
|
-
clearTimeout(this._reportTimer);
|
|
351
|
-
this._reportTimer = undefined;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
this.reports.emit();
|
|
355
|
-
|
|
356
|
-
if (this.config.maxCollectingTimeInMs) {
|
|
357
|
-
this._reportTimer = setTimeout(() => {
|
|
358
|
-
this._reportTimer = undefined;
|
|
359
|
-
this._emitReports();
|
|
360
|
-
}, this.config.maxCollectingTimeInMs);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
143
|
}
|