@observertc/observer-js 0.42.9 → 1.0.1-57a1811.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 +38 -41
- package/lib/ObservedCall.d.ts.map +1 -1
- package/lib/ObservedCall.js +97 -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 +49 -127
- package/lib/ObservedClient.d.ts.map +1 -1
- package/lib/ObservedClient.js +201 -750
- 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 +23 -69
- package/lib/ObservedDataChannel.d.ts.map +1 -1
- package/lib/ObservedDataChannel.js +67 -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 +44 -0
- package/lib/ObservedIceCandidatePair.d.ts.map +1 -0
- package/lib/ObservedIceCandidatePair.js +111 -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 +128 -78
- package/lib/ObservedPeerConnection.d.ts.map +1 -1
- package/lib/ObservedPeerConnection.js +624 -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 +31 -51
- package/lib/Observer.d.ts.map +1 -1
- package/lib/Observer.js +75 -229
- 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 +24 -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 +116 -166
- package/src/ObservedCertificate.ts +43 -0
- package/src/ObservedClient.ts +213 -1060
- package/src/ObservedCodec.ts +49 -0
- package/src/ObservedDataChannel.ts +68 -181
- package/src/ObservedIceCandidate.ts +64 -0
- package/src/ObservedIceCandidatePair.ts +118 -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 +827 -405
- 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 +91 -302
- 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 +24 -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
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { EventEmitter } from 'stream';
|
|
2
|
+
import { ObservedPeerConnection } from './ObservedPeerConnection';
|
|
3
|
+
import { ObservedTurnServer } from './ObservedTurnServer';
|
|
4
|
+
import { createLogger } from './common/logger';
|
|
5
|
+
|
|
6
|
+
const logger = createLogger('ObservedTURN');
|
|
7
|
+
|
|
8
|
+
export type ObservedTURNEventMap = {
|
|
9
|
+
'update': [ObservedTURN];
|
|
10
|
+
'close': [];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export declare interface ObservedTURN {
|
|
14
|
+
on<U extends keyof ObservedTURNEventMap>(event: U, listener: (...args: ObservedTURNEventMap[U]) => void): this;
|
|
15
|
+
off<U extends keyof ObservedTURNEventMap>(event: U, listener: (...args: ObservedTURNEventMap[U]) => void): this;
|
|
16
|
+
once<U extends keyof ObservedTURNEventMap>(event: U, listener: (...args: ObservedTURNEventMap[U]) => void): this;
|
|
17
|
+
emit<U extends keyof ObservedTURNEventMap>(event: U, ...args: ObservedTURNEventMap[U]): boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class ObservedTURN extends EventEmitter {
|
|
21
|
+
public totalBytesSent = 0;
|
|
22
|
+
public totalBytesReceived = 0;
|
|
23
|
+
public totalPacketsSent = 0;
|
|
24
|
+
public totalPacketsReceived = 0;
|
|
25
|
+
|
|
26
|
+
public packetsSentPerSecond = 0;
|
|
27
|
+
public packetsReceivedPerSecond = 0;
|
|
28
|
+
public outboundBitrate = 0;
|
|
29
|
+
public inboundBitrate = 0;
|
|
30
|
+
public numberOfClients = 0;
|
|
31
|
+
|
|
32
|
+
public readonly servers = new Map<string, ObservedTurnServer>();
|
|
33
|
+
|
|
34
|
+
public constructor(
|
|
35
|
+
) {
|
|
36
|
+
super();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public update() {
|
|
40
|
+
const clientIds = new Set<string>();
|
|
41
|
+
|
|
42
|
+
this.packetsReceivedPerSecond = 0;
|
|
43
|
+
this.packetsSentPerSecond = 0;
|
|
44
|
+
this.outboundBitrate = 0;
|
|
45
|
+
this.inboundBitrate = 0;
|
|
46
|
+
|
|
47
|
+
for (const server of this.servers.values()) {
|
|
48
|
+
server.update();
|
|
49
|
+
server.observedPeerConnections.forEach((pc) => clientIds.add(pc.client.clientId));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
this.numberOfClients = clientIds.size;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public addPeerConnection(peerConnection: ObservedPeerConnection) {
|
|
56
|
+
const turnPairs = peerConnection.selectedIceCandidatePairs.filter((pair) => pair.getLocalCandidate()?.candidateType === 'relay' && pair.getRemoteCandidate()?.url?.startsWith('turn:'));
|
|
57
|
+
|
|
58
|
+
if (turnPairs.length !== 1) {
|
|
59
|
+
return (logger.warn(`Expected exactly one TURN pair, but found for peerconnection ${peerConnection.peerConnectionId}`, turnPairs.length), undefined);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const candidatePair = turnPairs[0];
|
|
63
|
+
const rawUrl = candidatePair.getRemoteCandidate()?.url;
|
|
64
|
+
|
|
65
|
+
if (!rawUrl) {
|
|
66
|
+
return (logger.warn(`No remote candidate URL found for peerconnection ${peerConnection.peerConnectionId}`), undefined);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const turnUrl = new URL(rawUrl);
|
|
70
|
+
const turnServerUrl = `${turnUrl.protocol}//${turnUrl.hostname}:${turnUrl.port}`;
|
|
71
|
+
let turnServer = this.servers.get(turnServerUrl);
|
|
72
|
+
|
|
73
|
+
if (!turnServer) {
|
|
74
|
+
turnServer = new ObservedTurnServer(turnServerUrl, this);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return turnServer;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public removePeerConnection(peerConnection: ObservedPeerConnection) {
|
|
81
|
+
for (const turnServer of this.servers.values()) {
|
|
82
|
+
turnServer.observedPeerConnections.delete(peerConnection.peerConnectionId);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ObservedIceCandidatePair } from './ObservedIceCandidatePair';
|
|
2
|
+
import { ObservedPeerConnection } from './ObservedPeerConnection';
|
|
3
|
+
import { ObservedTURN } from './ObservedTURN';
|
|
4
|
+
|
|
5
|
+
export class ObservedTurnServer {
|
|
6
|
+
public totalBytesSent = 0;
|
|
7
|
+
public totalBytesReceived = 0;
|
|
8
|
+
public totalPacketsSent = 0;
|
|
9
|
+
public totalPacketsReceived = 0;
|
|
10
|
+
|
|
11
|
+
public packetsSentPerSecond = 0;
|
|
12
|
+
public packetsReceivedPerSecond = 0;
|
|
13
|
+
public outboundBitrate = 0;
|
|
14
|
+
public inboundBitrate = 0;
|
|
15
|
+
|
|
16
|
+
public deltaBytesSent = 0;
|
|
17
|
+
public deltaBytesReceived = 0;
|
|
18
|
+
public deltaPacketsSent = 0;
|
|
19
|
+
public deltaPacketsReceived = 0;
|
|
20
|
+
|
|
21
|
+
public readonly observedPeerConnections = new Map<string, ObservedPeerConnection>();
|
|
22
|
+
|
|
23
|
+
public updated = Date.now();
|
|
24
|
+
|
|
25
|
+
public constructor(
|
|
26
|
+
public readonly url: string,
|
|
27
|
+
public readonly observedTURN: ObservedTURN,
|
|
28
|
+
) {
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public updateTurnUsage(...selectedcandidatepairs: ObservedIceCandidatePair[]) {
|
|
33
|
+
for (const selectedcandidatepair of selectedcandidatepairs) {
|
|
34
|
+
this.deltaBytesReceived += selectedcandidatepair.deltaBytesReceived;
|
|
35
|
+
this.deltaBytesSent += selectedcandidatepair.deltaBytesSent;
|
|
36
|
+
this.deltaPacketsReceived += selectedcandidatepair.deltaPacketsReceived;
|
|
37
|
+
this.deltaPacketsSent += selectedcandidatepair.deltaPacketsSent;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public update() {
|
|
42
|
+
const now = Date.now();
|
|
43
|
+
const deltaInS = (now - this.updated) / 1000;
|
|
44
|
+
|
|
45
|
+
this.packetsSentPerSecond = this.deltaPacketsSent / deltaInS;
|
|
46
|
+
this.packetsReceivedPerSecond = this.deltaPacketsReceived / deltaInS;
|
|
47
|
+
this.outboundBitrate = (this.deltaBytesReceived * 8) / deltaInS;
|
|
48
|
+
this.inboundBitrate = (this.deltaBytesSent * 8) / deltaInS;
|
|
49
|
+
|
|
50
|
+
this.totalBytesSent += this.deltaBytesSent;
|
|
51
|
+
this.totalBytesReceived += this.deltaBytesReceived;
|
|
52
|
+
this.totalPacketsSent += this.deltaPacketsSent;
|
|
53
|
+
this.totalPacketsReceived += this.deltaPacketsReceived;
|
|
54
|
+
|
|
55
|
+
this.observedTURN.totalBytesSent += this.deltaBytesSent;
|
|
56
|
+
this.observedTURN.totalBytesReceived += this.deltaBytesReceived;
|
|
57
|
+
this.observedTURN.totalPacketsSent += this.deltaPacketsSent;
|
|
58
|
+
this.observedTURN.totalPacketsReceived += this.deltaPacketsReceived;
|
|
59
|
+
|
|
60
|
+
this.observedTURN.inboundBitrate += this.inboundBitrate;
|
|
61
|
+
this.observedTURN.outboundBitrate += this.outboundBitrate;
|
|
62
|
+
this.observedTURN.packetsReceivedPerSecond += this.packetsReceivedPerSecond;
|
|
63
|
+
this.observedTURN.packetsSentPerSecond += this.packetsSentPerSecond;
|
|
64
|
+
|
|
65
|
+
this.deltaBytesSent = 0;
|
|
66
|
+
this.deltaBytesReceived = 0;
|
|
67
|
+
this.deltaPacketsSent = 0;
|
|
68
|
+
this.deltaPacketsReceived = 0;
|
|
69
|
+
|
|
70
|
+
this.updated = now;
|
|
71
|
+
}
|
|
72
|
+
}
|