@observertc/observer-js 1.0.0-beta.3 → 1.0.0-beta.5
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/README.md +790 -386
- package/dist/index.d.mts +2795 -0
- package/dist/index.d.ts +2795 -0
- package/dist/index.js +3765 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +3699 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +28 -15
- package/.eslintrc.json +0 -143
- package/.prettierignore +0 -5
- package/.prettierrc +0 -7
- package/jest.config.js +0 -9
- package/lib/ObservedCall.d.ts +0 -70
- package/lib/ObservedCall.d.ts.map +0 -1
- package/lib/ObservedCall.js +0 -196
- package/lib/ObservedCallEventMonitor.d.ts +0 -107
- package/lib/ObservedCallEventMonitor.d.ts.map +0 -1
- package/lib/ObservedCallEventMonitor.js +0 -321
- package/lib/ObservedCallSummary.d.ts +0 -18
- package/lib/ObservedCallSummary.d.ts.map +0 -1
- package/lib/ObservedCallSummary.js +0 -2
- package/lib/ObservedCertificate.d.ts +0 -19
- package/lib/ObservedCertificate.d.ts.map +0 -1
- package/lib/ObservedCertificate.js +0 -38
- package/lib/ObservedClient.d.ts +0 -115
- package/lib/ObservedClient.d.ts.map +0 -1
- package/lib/ObservedClient.js +0 -714
- package/lib/ObservedClientEventMonitor.d.ts +0 -91
- package/lib/ObservedClientEventMonitor.d.ts.map +0 -1
- package/lib/ObservedClientEventMonitor.js +0 -254
- package/lib/ObservedClientSummary.d.ts +0 -23
- package/lib/ObservedClientSummary.d.ts.map +0 -1
- package/lib/ObservedClientSummary.js +0 -2
- package/lib/ObservedCodec.d.ts +0 -22
- package/lib/ObservedCodec.d.ts.map +0 -1
- package/lib/ObservedCodec.js +0 -45
- package/lib/ObservedDataChannel.d.ts +0 -30
- package/lib/ObservedDataChannel.d.ts.map +0 -1
- package/lib/ObservedDataChannel.js +0 -75
- package/lib/ObservedIceCandidate.d.ts +0 -29
- package/lib/ObservedIceCandidate.d.ts.map +0 -1
- package/lib/ObservedIceCandidate.js +0 -59
- package/lib/ObservedIceCandidatePair.d.ts +0 -45
- package/lib/ObservedIceCandidatePair.d.ts.map +0 -1
- package/lib/ObservedIceCandidatePair.js +0 -127
- package/lib/ObservedIceTransport.d.ts +0 -36
- package/lib/ObservedIceTransport.d.ts.map +0 -1
- package/lib/ObservedIceTransport.js +0 -93
- package/lib/ObservedInboundRtp.d.ts +0 -92
- package/lib/ObservedInboundRtp.d.ts.map +0 -1
- package/lib/ObservedInboundRtp.js +0 -193
- package/lib/ObservedInboundTrack.d.ts +0 -34
- package/lib/ObservedInboundTrack.d.ts.map +0 -1
- package/lib/ObservedInboundTrack.js +0 -92
- package/lib/ObservedMediaPlayout.d.ts +0 -22
- package/lib/ObservedMediaPlayout.d.ts.map +0 -1
- package/lib/ObservedMediaPlayout.js +0 -42
- package/lib/ObservedMediaSource.d.ts +0 -28
- package/lib/ObservedMediaSource.d.ts.map +0 -1
- package/lib/ObservedMediaSource.js +0 -55
- package/lib/ObservedOutboundRtp.d.ts +0 -62
- package/lib/ObservedOutboundRtp.d.ts.map +0 -1
- package/lib/ObservedOutboundRtp.js +0 -144
- package/lib/ObservedOutboundTrack.d.ts +0 -34
- package/lib/ObservedOutboundTrack.d.ts.map +0 -1
- package/lib/ObservedOutboundTrack.js +0 -65
- package/lib/ObservedPeerConnection.d.ts +0 -207
- package/lib/ObservedPeerConnection.d.ts.map +0 -1
- package/lib/ObservedPeerConnection.js +0 -788
- package/lib/ObservedPeerConnectionTransport.d.ts +0 -17
- package/lib/ObservedPeerConnectionTransport.d.ts.map +0 -1
- package/lib/ObservedPeerConnectionTransport.js +0 -34
- package/lib/ObservedRemoteInboundRtp.d.ts +0 -30
- package/lib/ObservedRemoteInboundRtp.d.ts.map +0 -1
- package/lib/ObservedRemoteInboundRtp.js +0 -60
- package/lib/ObservedRemoteOutboundRtp.d.ts +0 -30
- package/lib/ObservedRemoteOutboundRtp.d.ts.map +0 -1
- package/lib/ObservedRemoteOutboundRtp.js +0 -60
- package/lib/ObservedTURN.d.ts +0 -31
- package/lib/ObservedTURN.d.ts.map +0 -1
- package/lib/ObservedTURN.js +0 -58
- package/lib/ObservedTurnServer.d.ts +0 -25
- package/lib/ObservedTurnServer.d.ts.map +0 -1
- package/lib/ObservedTurnServer.js +0 -59
- package/lib/Observer.d.ts +0 -62
- package/lib/Observer.d.ts.map +0 -1
- package/lib/Observer.js +0 -160
- package/lib/ObserverEventMonitor.d.ts +0 -141
- package/lib/ObserverEventMonitor.d.ts.map +0 -1
- package/lib/ObserverEventMonitor.js +0 -440
- package/lib/ObserverSummary.d.ts +0 -13
- package/lib/ObserverSummary.d.ts.map +0 -1
- package/lib/ObserverSummary.js +0 -2
- package/lib/Reports.d.ts +0 -85
- package/lib/Reports.d.ts.map +0 -1
- package/lib/Reports.js +0 -2
- package/lib/common/Middleware.d.ts +0 -17
- package/lib/common/Middleware.d.ts.map +0 -1
- package/lib/common/Middleware.js +0 -60
- package/lib/common/SingleExecutor.d.ts +0 -3
- package/lib/common/SingleExecutor.d.ts.map +0 -1
- package/lib/common/SingleExecutor.js +0 -31
- package/lib/common/logger.d.ts +0 -17
- package/lib/common/logger.d.ts.map +0 -1
- package/lib/common/logger.js +0 -50
- package/lib/common/types.d.ts +0 -3
- package/lib/common/types.d.ts.map +0 -1
- package/lib/common/types.js +0 -3
- package/lib/common/utils.d.ts +0 -11
- package/lib/common/utils.d.ts.map +0 -1
- package/lib/common/utils.js +0 -63
- package/lib/detectors/Detector.d.ts +0 -5
- package/lib/detectors/Detector.d.ts.map +0 -1
- package/lib/detectors/Detector.js +0 -3
- package/lib/detectors/Detectors.d.ts +0 -11
- package/lib/detectors/Detectors.d.ts.map +0 -1
- package/lib/detectors/Detectors.js +0 -34
- package/lib/index.d.ts +0 -29
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -49
- package/lib/mediasoup/ObservedMediaRouter.d.ts +0 -10
- package/lib/mediasoup/ObservedMediaRouter.d.ts.map +0 -1
- package/lib/mediasoup/ObservedMediaRouter.js +0 -6
- package/lib/monitors/TurnUsageMonitor.d.ts +0 -1
- package/lib/monitors/TurnUsageMonitor.d.ts.map +0 -1
- package/lib/monitors/TurnUsageMonitor.js +0 -146
- package/lib/schema/ClientEventTypes.d.ts +0 -228
- package/lib/schema/ClientEventTypes.d.ts.map +0 -1
- package/lib/schema/ClientEventTypes.js +0 -41
- package/lib/schema/ClientMetaTypes.d.ts +0 -34
- package/lib/schema/ClientMetaTypes.d.ts.map +0 -1
- package/lib/schema/ClientMetaTypes.js +0 -16
- package/lib/schema/ClientSample.d.ts +0 -1333
- package/lib/schema/ClientSample.d.ts.map +0 -1
- package/lib/schema/ClientSample.js +0 -4
- package/lib/scores/CalculatedScore.d.ts +0 -6
- package/lib/scores/CalculatedScore.d.ts.map +0 -1
- package/lib/scores/CalculatedScore.js +0 -2
- package/lib/scores/DefaultCallScoreCalculator.d.ts +0 -7
- package/lib/scores/DefaultCallScoreCalculator.d.ts.map +0 -1
- package/lib/scores/DefaultCallScoreCalculator.js +0 -21
- package/lib/scores/ScoreCalculator.d.ts +0 -4
- package/lib/scores/ScoreCalculator.d.ts.map +0 -1
- package/lib/scores/ScoreCalculator.js +0 -2
- package/lib/updaters/CallUpdater.d.ts +0 -5
- package/lib/updaters/CallUpdater.d.ts.map +0 -1
- package/lib/updaters/CallUpdater.js +0 -2
- package/lib/updaters/ObserverUpdater.d.ts +0 -5
- package/lib/updaters/ObserverUpdater.d.ts.map +0 -1
- package/lib/updaters/ObserverUpdater.js +0 -2
- package/lib/updaters/OnAllCallObserverUpdater.d.ts +0 -15
- package/lib/updaters/OnAllCallObserverUpdater.d.ts.map +0 -1
- package/lib/updaters/OnAllCallObserverUpdater.js +0 -50
- package/lib/updaters/OnAllClientCallUpdater.d.ts +0 -15
- package/lib/updaters/OnAllClientCallUpdater.d.ts.map +0 -1
- package/lib/updaters/OnAllClientCallUpdater.js +0 -53
- package/lib/updaters/OnAnyCallObserverUpdater.d.ts +0 -12
- package/lib/updaters/OnAnyCallObserverUpdater.d.ts.map +0 -1
- package/lib/updaters/OnAnyCallObserverUpdater.js +0 -37
- package/lib/updaters/OnAnyClientCallUpdater.d.ts +0 -12
- package/lib/updaters/OnAnyClientCallUpdater.d.ts.map +0 -1
- package/lib/updaters/OnAnyClientCallUpdater.js +0 -36
- package/lib/updaters/OnIntervalUpdater.d.ts +0 -10
- package/lib/updaters/OnIntervalUpdater.d.ts.map +0 -1
- package/lib/updaters/OnIntervalUpdater.js +0 -17
- package/lib/updaters/Updater.d.ts +0 -6
- package/lib/updaters/Updater.d.ts.map +0 -1
- package/lib/updaters/Updater.js +0 -2
- package/lib/utils/MediasoupRemoteTrackResolver.d.ts +0 -25
- package/lib/utils/MediasoupRemoteTrackResolver.d.ts.map +0 -1
- package/lib/utils/MediasoupRemoteTrackResolver.js +0 -110
- package/lib/utils/RemoteTrackResolver.d.ts +0 -7
- package/lib/utils/RemoteTrackResolver.d.ts.map +0 -1
- package/lib/utils/RemoteTrackResolver.js +0 -2
- package/src/ObservedCall.ts +0 -308
- package/src/ObservedCallEventMonitor.ts +0 -402
- package/src/ObservedCallSummary.ts +0 -22
- package/src/ObservedCertificate.ts +0 -43
- package/src/ObservedClient.ts +0 -883
- package/src/ObservedClientEventMonitor.ts +0 -309
- package/src/ObservedClientSummary.ts +0 -24
- package/src/ObservedCodec.ts +0 -49
- package/src/ObservedDataChannel.ts +0 -85
- package/src/ObservedIceCandidate.ts +0 -64
- package/src/ObservedIceCandidatePair.ts +0 -134
- package/src/ObservedIceTransport.ts +0 -99
- package/src/ObservedInboundRtp.ts +0 -205
- package/src/ObservedInboundTrack.ts +0 -105
- package/src/ObservedMediaPlayout.ts +0 -49
- package/src/ObservedMediaSource.ts +0 -60
- package/src/ObservedOutboundRtp.ts +0 -156
- package/src/ObservedOutboundTrack.ts +0 -82
- package/src/ObservedPeerConnection.ts +0 -1104
- package/src/ObservedPeerConnectionTransport.ts +0 -38
- package/src/ObservedRemoteInboundRtp.ts +0 -64
- package/src/ObservedRemoteOutboundRtp.ts +0 -65
- package/src/ObservedTURN.ts +0 -86
- package/src/ObservedTurnServer.ts +0 -72
- package/src/Observer.ts +0 -248
- package/src/ObserverEventMonitor.ts +0 -561
- package/src/ObserverSummary.ts +0 -15
- package/src/Reports.ts +0 -87
- package/src/common/Middleware.ts +0 -84
- package/src/common/SingleExecutor.ts +0 -36
- package/src/common/logger.ts +0 -82
- package/src/common/types.ts +0 -4
- package/src/common/utils.ts +0 -69
- package/src/detectors/Detector.ts +0 -6
- package/src/detectors/Detectors.ts +0 -38
- package/src/index.ts +0 -32
- package/src/mediasoup/ObservedMediaRouter.ts +0 -10
- package/src/monitors/TurnUsageMonitor.ts +0 -187
- package/src/schema/ClientEventTypes.ts +0 -280
- package/src/schema/ClientMetaTypes.ts +0 -41
- package/src/schema/ClientSample.ts +0 -1682
- package/src/scores/CalculatedScore.ts +0 -6
- package/src/scores/DefaultCallScoreCalculator.ts +0 -23
- package/src/scores/ScoreCalculator.ts +0 -3
- package/src/updaters/CallUpdater.ts +0 -5
- package/src/updaters/ObserverUpdater.ts +0 -5
- package/src/updaters/OnAllCallObserverUpdater.ts +0 -59
- package/src/updaters/OnAllClientCallUpdater.ts +0 -61
- package/src/updaters/OnAnyCallObserverUpdater.ts +0 -41
- package/src/updaters/OnAnyClientCallUpdater.ts +0 -39
- package/src/updaters/OnIntervalUpdater.ts +0 -19
- package/src/updaters/Updater.ts +0 -5
- package/src/utils/MediasoupRemoteTrackResolver.ts +0 -155
- package/src/utils/RemoteTrackResolver.ts +0 -12
- package/tsconfig.json +0 -19
- package/tslint.json +0 -6
package/lib/ObservedClient.js
DELETED
|
@@ -1,714 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ObservedClient = void 0;
|
|
4
|
-
const events_1 = require("events");
|
|
5
|
-
const ObservedPeerConnection_1 = require("./ObservedPeerConnection");
|
|
6
|
-
const logger_1 = require("./common/logger");
|
|
7
|
-
const ClientEventTypes_1 = require("./schema/ClientEventTypes");
|
|
8
|
-
const ClientMetaTypes_1 = require("./schema/ClientMetaTypes");
|
|
9
|
-
const utils_1 = require("./common/utils");
|
|
10
|
-
const Detectors_1 = require("./detectors/Detectors");
|
|
11
|
-
const logger = (0, logger_1.createLogger)('ObservedClient');
|
|
12
|
-
class ObservedClient extends events_1.EventEmitter {
|
|
13
|
-
call;
|
|
14
|
-
detectors;
|
|
15
|
-
clientId;
|
|
16
|
-
observedPeerConnections = new Map();
|
|
17
|
-
calculatedScore = {
|
|
18
|
-
weight: 1,
|
|
19
|
-
value: undefined,
|
|
20
|
-
};
|
|
21
|
-
settings;
|
|
22
|
-
appData;
|
|
23
|
-
attachments;
|
|
24
|
-
updated = Date.now();
|
|
25
|
-
acceptedSamples = 0;
|
|
26
|
-
closed = false;
|
|
27
|
-
joinedAt;
|
|
28
|
-
leftAt;
|
|
29
|
-
closedAt;
|
|
30
|
-
lastSampleTimestamp;
|
|
31
|
-
// the timestamp of the CLIENT_JOINED event
|
|
32
|
-
operationSystem;
|
|
33
|
-
engine;
|
|
34
|
-
platform;
|
|
35
|
-
browser;
|
|
36
|
-
mediaConstraints = [];
|
|
37
|
-
usingTURN = false;
|
|
38
|
-
usingTCP = false;
|
|
39
|
-
availableOutgoingBitrate = 0;
|
|
40
|
-
availableIncomingBitrate = 0;
|
|
41
|
-
// public totalInboundPacketsLost = 0;
|
|
42
|
-
// public totalInboundPacketsReceived = 0;
|
|
43
|
-
// public totalOutboundPacketsSent = 0;
|
|
44
|
-
// public totalDataChannelBytesSent = 0;
|
|
45
|
-
// public totalDataChannelBytesReceived = 0;
|
|
46
|
-
// public totalDataChannelMessagesSent = 0;
|
|
47
|
-
// public totalDataChannelMessagesReceived = 0;
|
|
48
|
-
// public totalReceivedAudioBytes = 0;
|
|
49
|
-
// public totalReceivedVideoBytes = 0;
|
|
50
|
-
// public totalSentAudioBytes = 0;
|
|
51
|
-
// public totalSentVideoBytes = 0;
|
|
52
|
-
// public totalSentBytes = 0;
|
|
53
|
-
// public totalReceivedBytes = 0;
|
|
54
|
-
// public totalRttLt50Measurements = 0;
|
|
55
|
-
// public totalRttLt150Measurements = 0;
|
|
56
|
-
// public totalRttLt300Measurements = 0;
|
|
57
|
-
// public totalRttGtOrEq300Measurements = 0;
|
|
58
|
-
deltaReceivedAudioBytes = 0;
|
|
59
|
-
deltaReceivedVideoBytes = 0;
|
|
60
|
-
deltaSentAudioBytes = 0;
|
|
61
|
-
deltaSentVideoBytes = 0;
|
|
62
|
-
deltaDataChannelBytesSent = 0;
|
|
63
|
-
deltaDataChannelBytesReceived = 0;
|
|
64
|
-
deltaDataChannelMessagesSent = 0;
|
|
65
|
-
deltaDataChannelMessagesReceived = 0;
|
|
66
|
-
deltaInboundPacketsLost = 0;
|
|
67
|
-
deltaInboundPacketsReceived = 0;
|
|
68
|
-
deltaOutboundPacketsSent = 0;
|
|
69
|
-
deltaTransportSentBytes = 0;
|
|
70
|
-
deltaTransportReceivedBytes = 0;
|
|
71
|
-
deltaRttLt50Measurements = 0;
|
|
72
|
-
deltaRttLt150Measurements = 0;
|
|
73
|
-
deltaRttLt300Measurements = 0;
|
|
74
|
-
deltaRttGtOrEq300Measurements = 0;
|
|
75
|
-
currentMaxRttInMs;
|
|
76
|
-
currentMinRttInMs;
|
|
77
|
-
currentAvgRttInMs;
|
|
78
|
-
sendingAudioBitrate = 0;
|
|
79
|
-
sendingVideoBitrate = 0;
|
|
80
|
-
receivingAudioBitrate = 0;
|
|
81
|
-
receivingVideoBitrate = 0;
|
|
82
|
-
numberOfInboundRtpStreams = 0;
|
|
83
|
-
numberOfInbundTracks = 0;
|
|
84
|
-
numberOfOutboundRtpStreams = 0;
|
|
85
|
-
numberOfOutboundTracks = 0;
|
|
86
|
-
numberOfDataChannels = 0;
|
|
87
|
-
deltaNumberOfIssues = 0;
|
|
88
|
-
totalScoreSum = 0;
|
|
89
|
-
numberOfScoreMeasurements = 0;
|
|
90
|
-
// public totalNumberOfIssues = 0;
|
|
91
|
-
report;
|
|
92
|
-
mediaDevices = [];
|
|
93
|
-
issues = [];
|
|
94
|
-
_injections = {};
|
|
95
|
-
closeTimer;
|
|
96
|
-
constructor(settings, call) {
|
|
97
|
-
super();
|
|
98
|
-
this.call = call;
|
|
99
|
-
this.setMaxListeners(Infinity);
|
|
100
|
-
this.clientId = settings.clientId;
|
|
101
|
-
this.appData = settings.appData ?? {};
|
|
102
|
-
this.detectors = new Detectors_1.Detectors();
|
|
103
|
-
this.settings = {
|
|
104
|
-
closeClientIfIdleForMs: settings.closeClientIfIdleForMs,
|
|
105
|
-
};
|
|
106
|
-
this.report = {
|
|
107
|
-
callId: this.call.callId,
|
|
108
|
-
clientId: this.clientId,
|
|
109
|
-
rttDistribution: {
|
|
110
|
-
gtOrEq300ms: 0,
|
|
111
|
-
lt50ms: 0,
|
|
112
|
-
lt150ms: 0,
|
|
113
|
-
lt300ms: 0,
|
|
114
|
-
count: 0,
|
|
115
|
-
sum: 0,
|
|
116
|
-
},
|
|
117
|
-
scoreDistribution: {
|
|
118
|
-
'0': 0,
|
|
119
|
-
'1': 0,
|
|
120
|
-
'2': 0,
|
|
121
|
-
'3': 0,
|
|
122
|
-
'4': 0,
|
|
123
|
-
'5': 0,
|
|
124
|
-
count: 0,
|
|
125
|
-
sum: 0,
|
|
126
|
-
},
|
|
127
|
-
issues: {},
|
|
128
|
-
totalAudioBytesReceived: 0,
|
|
129
|
-
totalVideoBytesReceived: 0,
|
|
130
|
-
totalAudioBytesSent: 0,
|
|
131
|
-
totalVideoBytesSent: 0,
|
|
132
|
-
totalDataChannelBytesReceived: 0,
|
|
133
|
-
totalDataChannelBytesSent: 0,
|
|
134
|
-
totalDataChannelMessagesReceived: 0,
|
|
135
|
-
totalDataChannelMessagesSent: 0,
|
|
136
|
-
totalInboundRtpBytesReceived: 0,
|
|
137
|
-
totalInboundRtpPacketsLost: 0,
|
|
138
|
-
totalInboundRtpPacketsReceived: 0,
|
|
139
|
-
totalOutboundRtpBytesSent: 0,
|
|
140
|
-
totalOutboundRtpPacketsSent: 0,
|
|
141
|
-
totalNumberOfIssues: 0,
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
get numberOfPeerConnections() {
|
|
145
|
-
return this.observedPeerConnections.size;
|
|
146
|
-
}
|
|
147
|
-
get score() {
|
|
148
|
-
return this.calculatedScore.value;
|
|
149
|
-
}
|
|
150
|
-
close() {
|
|
151
|
-
if (this.closed)
|
|
152
|
-
return;
|
|
153
|
-
this.closed = true;
|
|
154
|
-
this._injections.clientEvents?.forEach((clientEvent) => this._processClientEvent(clientEvent));
|
|
155
|
-
this._injections.clientIssues?.forEach((clientIssue) => this.addIssue(clientIssue));
|
|
156
|
-
this._injections.extensionStats?.forEach((extensionStat) => this.addExtensionStats(extensionStat));
|
|
157
|
-
this._injections.clientMetaItems?.forEach((clientMetaItem) => this.addMetadata(clientMetaItem));
|
|
158
|
-
Array.from(this.observedPeerConnections.values()).forEach((peerConnection) => peerConnection.close());
|
|
159
|
-
if (!this.leftAt) {
|
|
160
|
-
this.leftAt = this.lastSampleTimestamp;
|
|
161
|
-
if (this.leftAt) {
|
|
162
|
-
this.emit('left');
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
this.closedAt = Date.now();
|
|
166
|
-
this.emit('close');
|
|
167
|
-
}
|
|
168
|
-
accept(sample) {
|
|
169
|
-
if (this.closed)
|
|
170
|
-
throw new Error(`Client ${this.clientId} is closed`);
|
|
171
|
-
if (this.closeTimer) {
|
|
172
|
-
clearTimeout(this.closeTimer);
|
|
173
|
-
this.closeTimer = undefined;
|
|
174
|
-
}
|
|
175
|
-
const now = Date.now();
|
|
176
|
-
const elapsedInMs = now - this.updated;
|
|
177
|
-
const elapsedInSeconds = elapsedInMs / 1000;
|
|
178
|
-
let sumOfRtts = 0;
|
|
179
|
-
let numberOfRttMeasurements = 0;
|
|
180
|
-
++this.acceptedSamples;
|
|
181
|
-
this.availableIncomingBitrate = 0;
|
|
182
|
-
this.availableOutgoingBitrate = 0;
|
|
183
|
-
this.deltaDataChannelBytesReceived = 0;
|
|
184
|
-
this.deltaDataChannelBytesSent = 0;
|
|
185
|
-
this.deltaDataChannelMessagesReceived = 0;
|
|
186
|
-
this.deltaDataChannelMessagesSent = 0;
|
|
187
|
-
this.deltaInboundPacketsLost = 0;
|
|
188
|
-
this.deltaInboundPacketsReceived = 0;
|
|
189
|
-
this.deltaOutboundPacketsSent = 0;
|
|
190
|
-
this.deltaReceivedAudioBytes = 0;
|
|
191
|
-
this.deltaReceivedVideoBytes = 0;
|
|
192
|
-
this.deltaSentAudioBytes = 0;
|
|
193
|
-
this.deltaSentVideoBytes = 0;
|
|
194
|
-
this.deltaTransportReceivedBytes = 0;
|
|
195
|
-
this.deltaTransportSentBytes = 0;
|
|
196
|
-
this.deltaRttLt50Measurements = 0;
|
|
197
|
-
this.deltaRttLt150Measurements = 0;
|
|
198
|
-
this.deltaRttLt300Measurements = 0;
|
|
199
|
-
this.deltaRttGtOrEq300Measurements = 0;
|
|
200
|
-
this.deltaNumberOfIssues = 0;
|
|
201
|
-
this.numberOfDataChannels = 0;
|
|
202
|
-
this.numberOfInboundRtpStreams = 0;
|
|
203
|
-
this.numberOfInbundTracks = 0;
|
|
204
|
-
this.numberOfOutboundRtpStreams = 0;
|
|
205
|
-
this.numberOfOutboundTracks = 0;
|
|
206
|
-
this.usingTURN = false;
|
|
207
|
-
this.usingTCP = false;
|
|
208
|
-
this.currentMinRttInMs = undefined;
|
|
209
|
-
this.currentMaxRttInMs = undefined;
|
|
210
|
-
this._mergeInjections(sample);
|
|
211
|
-
const clientEventsPostBuffer = [];
|
|
212
|
-
for (const clientEvent of sample.clientEvents ?? []) {
|
|
213
|
-
this._processClientEvent(clientEvent, clientEventsPostBuffer);
|
|
214
|
-
this.call.observer.emit('client-event', this, clientEvent);
|
|
215
|
-
}
|
|
216
|
-
for (const metaData of sample.clientMetaItems ?? []) {
|
|
217
|
-
this.addMetadata(metaData);
|
|
218
|
-
}
|
|
219
|
-
for (const issue of sample.clientIssues ?? []) {
|
|
220
|
-
this.addIssue(issue);
|
|
221
|
-
++this.deltaNumberOfIssues;
|
|
222
|
-
}
|
|
223
|
-
for (const extensionStat of sample.extensionStats ?? []) {
|
|
224
|
-
this.addExtensionStats(extensionStat);
|
|
225
|
-
}
|
|
226
|
-
for (const pcSample of sample.peerConnections ?? []) {
|
|
227
|
-
const observedPeerConnection = this._updatePeerConnection(pcSample);
|
|
228
|
-
if (!observedPeerConnection)
|
|
229
|
-
continue;
|
|
230
|
-
this.deltaDataChannelBytesReceived += observedPeerConnection.deltaDataChannelBytesReceived;
|
|
231
|
-
this.deltaDataChannelBytesSent += observedPeerConnection.deltaDataChannelBytesSent;
|
|
232
|
-
this.deltaDataChannelMessagesReceived += observedPeerConnection.deltaDataChannelMessagesReceived;
|
|
233
|
-
this.deltaDataChannelMessagesSent += observedPeerConnection.deltaDataChannelMessagesSent;
|
|
234
|
-
this.deltaInboundPacketsLost += observedPeerConnection.deltaInboundPacketsLost;
|
|
235
|
-
this.deltaInboundPacketsReceived += observedPeerConnection.deltaInboundPacketsReceived;
|
|
236
|
-
this.deltaOutboundPacketsSent += observedPeerConnection.deltaOutboundPacketsSent;
|
|
237
|
-
this.deltaReceivedAudioBytes += observedPeerConnection.deltaReceivedAudioBytes;
|
|
238
|
-
this.deltaReceivedVideoBytes += observedPeerConnection.deltaReceivedVideoBytes;
|
|
239
|
-
this.deltaSentAudioBytes += observedPeerConnection.deltaSentAudioBytes;
|
|
240
|
-
this.deltaSentVideoBytes += observedPeerConnection.deltaSentVideoBytes;
|
|
241
|
-
this.deltaTransportReceivedBytes += observedPeerConnection.deltaTransportReceivedBytes;
|
|
242
|
-
this.deltaTransportSentBytes += observedPeerConnection.deltaTransportSentBytes;
|
|
243
|
-
this.availableIncomingBitrate += observedPeerConnection.availableIncomingBitrate;
|
|
244
|
-
this.availableOutgoingBitrate += observedPeerConnection.availableOutgoingBitrate;
|
|
245
|
-
this.numberOfDataChannels += observedPeerConnection.observedDataChannels.size;
|
|
246
|
-
this.numberOfInbundTracks += observedPeerConnection.observedInboundTracks.size;
|
|
247
|
-
this.numberOfOutboundRtpStreams += observedPeerConnection.observedOutboundRtps.size;
|
|
248
|
-
this.numberOfOutboundTracks += observedPeerConnection.observedOutboundTracks.size;
|
|
249
|
-
this.numberOfInboundRtpStreams += observedPeerConnection.observedInboundRtps.size;
|
|
250
|
-
if (observedPeerConnection.usingTURN) {
|
|
251
|
-
this.usingTURN = true;
|
|
252
|
-
}
|
|
253
|
-
if (observedPeerConnection.usingTCP) {
|
|
254
|
-
this.usingTCP = true;
|
|
255
|
-
}
|
|
256
|
-
if (observedPeerConnection.currentRttInMs) {
|
|
257
|
-
if (this.currentMinRttInMs === undefined || observedPeerConnection.currentRttInMs < this.currentMinRttInMs) {
|
|
258
|
-
this.currentMinRttInMs = observedPeerConnection.currentRttInMs;
|
|
259
|
-
}
|
|
260
|
-
if (this.currentMaxRttInMs === undefined || observedPeerConnection.currentRttInMs > this.currentMaxRttInMs) {
|
|
261
|
-
this.currentMaxRttInMs = observedPeerConnection.currentRttInMs;
|
|
262
|
-
}
|
|
263
|
-
if (observedPeerConnection.currentRttInMs < 50) {
|
|
264
|
-
this.deltaRttLt50Measurements += 1;
|
|
265
|
-
this.report.rttDistribution.lt50ms += 1;
|
|
266
|
-
}
|
|
267
|
-
else if (observedPeerConnection.currentRttInMs < 150) {
|
|
268
|
-
this.deltaRttLt150Measurements += 1;
|
|
269
|
-
this.report.rttDistribution.lt150ms += 1;
|
|
270
|
-
}
|
|
271
|
-
else if (observedPeerConnection.currentRttInMs < 300) {
|
|
272
|
-
this.deltaRttLt300Measurements += 1;
|
|
273
|
-
this.report.rttDistribution.lt300ms += 1;
|
|
274
|
-
}
|
|
275
|
-
else if (300 <= observedPeerConnection.currentRttInMs) {
|
|
276
|
-
this.deltaRttGtOrEq300Measurements += 1;
|
|
277
|
-
this.report.rttDistribution.gtOrEq300ms += 1;
|
|
278
|
-
}
|
|
279
|
-
this.report.rttDistribution.count += 1;
|
|
280
|
-
this.report.rttDistribution.sum += observedPeerConnection.currentRttInMs;
|
|
281
|
-
sumOfRtts += observedPeerConnection.currentRttInMs;
|
|
282
|
-
++numberOfRttMeasurements;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
for (const clientEvent of clientEventsPostBuffer) {
|
|
286
|
-
this._processClientEvent(clientEvent);
|
|
287
|
-
}
|
|
288
|
-
// emit new attachments?
|
|
289
|
-
this.attachments = sample.attachments;
|
|
290
|
-
this.report.totalDataChannelBytesReceived += this.deltaDataChannelBytesReceived;
|
|
291
|
-
this.report.totalDataChannelBytesSent += this.deltaDataChannelBytesSent;
|
|
292
|
-
this.report.totalDataChannelMessagesReceived += this.deltaDataChannelMessagesReceived;
|
|
293
|
-
this.report.totalDataChannelMessagesSent += this.deltaDataChannelMessagesSent;
|
|
294
|
-
this.report.totalInboundRtpPacketsLost += this.deltaInboundPacketsLost;
|
|
295
|
-
this.report.totalInboundRtpPacketsReceived += this.deltaInboundPacketsReceived;
|
|
296
|
-
this.report.totalOutboundRtpPacketsSent += this.deltaOutboundPacketsSent;
|
|
297
|
-
this.report.totalAudioBytesReceived += this.deltaReceivedAudioBytes;
|
|
298
|
-
this.report.totalVideoBytesReceived += this.deltaReceivedVideoBytes;
|
|
299
|
-
this.report.totalAudioBytesSent += this.deltaSentAudioBytes;
|
|
300
|
-
this.report.totalVideoBytesSent += this.deltaSentVideoBytes;
|
|
301
|
-
this.report.totalInboundRtpBytesReceived += this.deltaTransportReceivedBytes;
|
|
302
|
-
this.report.totalOutboundRtpBytesSent += this.deltaTransportSentBytes;
|
|
303
|
-
this.report.totalNumberOfIssues += this.deltaNumberOfIssues;
|
|
304
|
-
this.receivingAudioBitrate = (this.deltaReceivedAudioBytes * 8) / (elapsedInSeconds);
|
|
305
|
-
this.receivingVideoBitrate = (this.deltaReceivedVideoBytes * 8) / (elapsedInSeconds);
|
|
306
|
-
this.sendingAudioBitrate = (this.deltaSentAudioBytes * 8) / (elapsedInSeconds);
|
|
307
|
-
this.sendingVideoBitrate = (this.deltaSentVideoBytes * 8) / (elapsedInSeconds);
|
|
308
|
-
this.currentAvgRttInMs = 0 < numberOfRttMeasurements ? sumOfRtts / numberOfRttMeasurements : undefined;
|
|
309
|
-
this.calculatedScore.value = sample.score;
|
|
310
|
-
if (sample.score !== undefined) {
|
|
311
|
-
const bucket = Math.floor(sample.score).toString();
|
|
312
|
-
this.report.scoreDistribution[bucket] = (this.report.scoreDistribution[bucket] ?? 0) + 1;
|
|
313
|
-
this.report.scoreDistribution.count += 1;
|
|
314
|
-
this.report.scoreDistribution.sum += sample.score;
|
|
315
|
-
}
|
|
316
|
-
this.detectors.update();
|
|
317
|
-
this.lastSampleTimestamp = sample.timestamp;
|
|
318
|
-
// emit update
|
|
319
|
-
this.emit('update', sample, now - this.updated);
|
|
320
|
-
this.updated = now;
|
|
321
|
-
// if result changed after update
|
|
322
|
-
if (this.calculatedScore.value) {
|
|
323
|
-
this.totalScoreSum += this.calculatedScore.value;
|
|
324
|
-
++this.numberOfScoreMeasurements;
|
|
325
|
-
}
|
|
326
|
-
if (this.settings.closeClientIfIdleForMs !== undefined) {
|
|
327
|
-
this.closeTimer = setTimeout(() => {
|
|
328
|
-
this.close();
|
|
329
|
-
}, this.settings.closeClientIfIdleForMs);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
_processClientEvent(event, postBuffer) {
|
|
333
|
-
// eslint-disable-next-line no-console
|
|
334
|
-
// console.warn('ClientEvent', event);
|
|
335
|
-
switch (event.type) {
|
|
336
|
-
case ClientEventTypes_1.ClientEventTypes.CLIENT_JOINED: {
|
|
337
|
-
if (event.timestamp) {
|
|
338
|
-
if (!this.joinedAt) {
|
|
339
|
-
this.joinedAt = event.timestamp;
|
|
340
|
-
this.emit('joined');
|
|
341
|
-
}
|
|
342
|
-
else if (this.joinedAt < event.timestamp) {
|
|
343
|
-
this.emit('rejoined', event.timestamp);
|
|
344
|
-
}
|
|
345
|
-
else {
|
|
346
|
-
this.joinedAt = event.timestamp;
|
|
347
|
-
logger.warn(`Client ${this.clientId} joinedAt timestamp was updated to ${event.timestamp}. the joined event will not be emitted.`);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
logger.debug('Client %s joined at %o', this.clientId, event);
|
|
351
|
-
break;
|
|
352
|
-
}
|
|
353
|
-
case ClientEventTypes_1.ClientEventTypes.CLIENT_LEFT: {
|
|
354
|
-
if (event.timestamp) {
|
|
355
|
-
if (!this.leftAt) {
|
|
356
|
-
this.leftAt = event.timestamp;
|
|
357
|
-
this.emit('left');
|
|
358
|
-
}
|
|
359
|
-
else {
|
|
360
|
-
logger.warn(`Client ${this.clientId} leftAt timestamp was already set`);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
logger.debug('Client %s left at %o', this.clientId, event);
|
|
364
|
-
break;
|
|
365
|
-
}
|
|
366
|
-
case ClientEventTypes_1.ClientEventTypes.PEER_CONNECTION_OPENED: {
|
|
367
|
-
const payload = (0, utils_1.parseJsonAs)(event.payload);
|
|
368
|
-
if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string') {
|
|
369
|
-
const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
|
|
370
|
-
if (observedPeerConnection) {
|
|
371
|
-
observedPeerConnection.openedAt = event.timestamp;
|
|
372
|
-
}
|
|
373
|
-
else if (postBuffer) {
|
|
374
|
-
postBuffer.push(event);
|
|
375
|
-
}
|
|
376
|
-
else {
|
|
377
|
-
logger.warn('Received PEER_CONNECTION_OPENED event without a corresponding observedPeerConnection: %o', event);
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
break;
|
|
381
|
-
}
|
|
382
|
-
case ClientEventTypes_1.ClientEventTypes.PEER_CONNECTION_CLOSED: {
|
|
383
|
-
const payload = (0, utils_1.parseJsonAs)(event.payload);
|
|
384
|
-
if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string') {
|
|
385
|
-
const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
|
|
386
|
-
if (observedPeerConnection) {
|
|
387
|
-
observedPeerConnection.closedAt = event.timestamp;
|
|
388
|
-
}
|
|
389
|
-
else if (postBuffer) {
|
|
390
|
-
postBuffer.push(event);
|
|
391
|
-
}
|
|
392
|
-
else {
|
|
393
|
-
logger.warn('Received PEER_CONNECTION_CLOSED event without a corresponding observedPeerConnection: %o', event);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
break;
|
|
397
|
-
}
|
|
398
|
-
case ClientEventTypes_1.ClientEventTypes.MEDIA_TRACK_ADDED: {
|
|
399
|
-
const payload = (0, utils_1.parseJsonAs)(event.payload);
|
|
400
|
-
if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string' && payload?.trackId && typeof payload.trackId === 'string') {
|
|
401
|
-
const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
|
|
402
|
-
const observedTrack = observedPeerConnection?.observedInboundTracks.get(payload.trackId) ?? observedPeerConnection?.observedOutboundTracks.get(payload.trackId);
|
|
403
|
-
if (observedTrack) {
|
|
404
|
-
observedTrack.addedAt = event.timestamp;
|
|
405
|
-
}
|
|
406
|
-
else if (postBuffer) {
|
|
407
|
-
postBuffer.push(event);
|
|
408
|
-
}
|
|
409
|
-
else {
|
|
410
|
-
logger.warn('Received MEDIA_TRACK_ADDED event without a corresponding observedPeerConnection or observedTrack: %o', event);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
break;
|
|
414
|
-
}
|
|
415
|
-
case ClientEventTypes_1.ClientEventTypes.MEDIA_TRACK_REMOVED: {
|
|
416
|
-
const payload = (0, utils_1.parseJsonAs)(event.payload);
|
|
417
|
-
if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string' && payload?.trackId && typeof payload.trackId === 'string') {
|
|
418
|
-
const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
|
|
419
|
-
const observedTrack = observedPeerConnection?.observedInboundTracks.get(payload.trackId) ?? observedPeerConnection?.observedOutboundTracks.get(payload.trackId);
|
|
420
|
-
if (observedTrack) {
|
|
421
|
-
observedTrack.removedAt = event.timestamp;
|
|
422
|
-
}
|
|
423
|
-
else if (postBuffer) {
|
|
424
|
-
postBuffer.push(event);
|
|
425
|
-
}
|
|
426
|
-
else {
|
|
427
|
-
logger.warn('Received MEDIA_TRACK_REMOVED event without a corresponding observedPeerConnection or observedTrack: %o', event);
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
break;
|
|
431
|
-
}
|
|
432
|
-
case ClientEventTypes_1.ClientEventTypes.DATA_CHANNEL_OPEN: {
|
|
433
|
-
const payload = (0, utils_1.parseJsonAs)(event.payload);
|
|
434
|
-
if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string' && payload?.dataChannelId && typeof payload.dataChannelId === 'string') {
|
|
435
|
-
const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
|
|
436
|
-
const observedDataChannel = observedPeerConnection?.observedDataChannels.get(payload.dataChannelId);
|
|
437
|
-
if (observedDataChannel) {
|
|
438
|
-
observedDataChannel.addedAt = event.timestamp;
|
|
439
|
-
}
|
|
440
|
-
else if (postBuffer) {
|
|
441
|
-
postBuffer.push(event);
|
|
442
|
-
}
|
|
443
|
-
else {
|
|
444
|
-
logger.warn('Received DATA_CHANNEL_OPENED event without a corresponding observedPeerConnection or observedDataChannel: %o', event);
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
break;
|
|
448
|
-
}
|
|
449
|
-
case ClientEventTypes_1.ClientEventTypes.DATA_CHANNEL_CLOSED: {
|
|
450
|
-
const payload = (0, utils_1.parseJsonAs)(event.payload);
|
|
451
|
-
if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string' && payload?.dataChannelId && typeof payload.dataChannelId === 'string') {
|
|
452
|
-
const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
|
|
453
|
-
const observedDataChannel = observedPeerConnection?.observedDataChannels.get(payload.dataChannelId);
|
|
454
|
-
if (observedDataChannel) {
|
|
455
|
-
observedDataChannel.removedAt = event.timestamp;
|
|
456
|
-
}
|
|
457
|
-
else if (postBuffer) {
|
|
458
|
-
postBuffer.push(event);
|
|
459
|
-
}
|
|
460
|
-
else {
|
|
461
|
-
logger.warn('Received DATA_CHANNEL_CLOSE event without a corresponding observedPeerConnection or observedDataChannel: %o', event);
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
break;
|
|
465
|
-
}
|
|
466
|
-
case ClientEventTypes_1.ClientEventTypes.MEDIA_TRACK_MUTED: {
|
|
467
|
-
const payload = (0, utils_1.parseJsonAs)(event.payload);
|
|
468
|
-
if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string' && payload?.trackId && typeof payload.trackId === 'string') {
|
|
469
|
-
const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
|
|
470
|
-
const observedInboundTrack = observedPeerConnection?.observedInboundTracks.get(payload.trackId);
|
|
471
|
-
const observedOutboundTrack = observedPeerConnection?.observedOutboundTracks.get(payload.trackId);
|
|
472
|
-
if (observedPeerConnection) {
|
|
473
|
-
if (observedInboundTrack) {
|
|
474
|
-
observedInboundTrack.muted = true;
|
|
475
|
-
observedPeerConnection?.emit('muted-inbound-track', observedInboundTrack);
|
|
476
|
-
}
|
|
477
|
-
else if (observedOutboundTrack) {
|
|
478
|
-
observedOutboundTrack.muted = true;
|
|
479
|
-
observedPeerConnection?.emit('muted-outbound-track', observedOutboundTrack);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
else if (postBuffer) {
|
|
483
|
-
postBuffer.push(event);
|
|
484
|
-
}
|
|
485
|
-
else {
|
|
486
|
-
logger.warn('Received MEDIA_TRACK_MUTED event without a corresponding observedPeerConnection or observedTrack: %o', event);
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
break;
|
|
490
|
-
}
|
|
491
|
-
case ClientEventTypes_1.ClientEventTypes.MEDIA_TRACK_UNMUTED: {
|
|
492
|
-
const payload = (0, utils_1.parseJsonAs)(event.payload);
|
|
493
|
-
if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string' && payload?.trackId && typeof payload.trackId === 'string') {
|
|
494
|
-
const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
|
|
495
|
-
const observedInboundTrack = observedPeerConnection?.observedInboundTracks.get(payload.trackId);
|
|
496
|
-
const observedOutboundTrack = observedPeerConnection?.observedOutboundTracks.get(payload.trackId);
|
|
497
|
-
if (observedPeerConnection) {
|
|
498
|
-
if (observedInboundTrack) {
|
|
499
|
-
observedInboundTrack.muted = false;
|
|
500
|
-
observedPeerConnection?.emit('unmuted-inbound-track', observedInboundTrack);
|
|
501
|
-
}
|
|
502
|
-
else if (observedOutboundTrack) {
|
|
503
|
-
observedOutboundTrack.muted = false;
|
|
504
|
-
observedPeerConnection?.emit('unmuted-outbound-track', observedOutboundTrack);
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
else if (postBuffer) {
|
|
508
|
-
postBuffer.push(event);
|
|
509
|
-
}
|
|
510
|
-
else {
|
|
511
|
-
logger.warn('Received MEDIA_TRACK_UNMUTED event without a corresponding observedPeerConnection or observedTrack: %o', event);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
break;
|
|
515
|
-
}
|
|
516
|
-
case ClientEventTypes_1.ClientEventTypes.ICE_CONNECTION_STATE_CHANGED: {
|
|
517
|
-
const payload = (0, utils_1.parseJsonAs)(event.payload);
|
|
518
|
-
if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string' && payload?.iceConnectionState && typeof payload.iceConnectionState === 'string') {
|
|
519
|
-
const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
|
|
520
|
-
if (observedPeerConnection) {
|
|
521
|
-
observedPeerConnection.iceConnectionState = payload.iceConnectionState;
|
|
522
|
-
observedPeerConnection.emit('iceconnectionstatechange', {
|
|
523
|
-
state: payload.iceConnectionState,
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
else if (postBuffer) {
|
|
527
|
-
postBuffer.push(event);
|
|
528
|
-
}
|
|
529
|
-
else {
|
|
530
|
-
logger.warn('Received ICE_CONNECTION_STATE_CHANGED event without a corresponding observedPeerConnection: %o', event);
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
break;
|
|
534
|
-
}
|
|
535
|
-
case ClientEventTypes_1.ClientEventTypes.ICE_GATHERING_STATE_CHANGED: {
|
|
536
|
-
const payload = (0, utils_1.parseJsonAs)(event.payload);
|
|
537
|
-
if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string' && payload?.iceGatheringState && typeof payload.iceGatheringState === 'string') {
|
|
538
|
-
const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
|
|
539
|
-
if (observedPeerConnection) {
|
|
540
|
-
observedPeerConnection.iceGatheringState = payload.iceGatheringState;
|
|
541
|
-
observedPeerConnection.emit('icegatheringstatechange', {
|
|
542
|
-
state: payload.iceGatheringState,
|
|
543
|
-
});
|
|
544
|
-
}
|
|
545
|
-
else if (postBuffer) {
|
|
546
|
-
postBuffer.push(event);
|
|
547
|
-
}
|
|
548
|
-
else {
|
|
549
|
-
logger.warn('Received ICE_GATHERING_STATE_CHANGED event without a corresponding observedPeerConnection: %o', event);
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
break;
|
|
553
|
-
}
|
|
554
|
-
case ClientEventTypes_1.ClientEventTypes.PEER_CONNECTION_STATE_CHANGED: {
|
|
555
|
-
const payload = (0, utils_1.parseJsonAs)(event.payload);
|
|
556
|
-
if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string' && payload?.peerConnectionState && typeof payload.peerConnectionState === 'string') {
|
|
557
|
-
const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
|
|
558
|
-
if (observedPeerConnection) {
|
|
559
|
-
observedPeerConnection.connectionState = payload.peerConnectionState;
|
|
560
|
-
observedPeerConnection.emit('connectionstatechange', {
|
|
561
|
-
state: payload.peerConnectionState,
|
|
562
|
-
});
|
|
563
|
-
}
|
|
564
|
-
else if (postBuffer) {
|
|
565
|
-
postBuffer.push(event);
|
|
566
|
-
}
|
|
567
|
-
else {
|
|
568
|
-
logger.warn('Received PEER_CONNECTION_STATE_CHANGED event without a corresponding observedPeerConnection: %o', event);
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
break;
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
this.emit('clientEvent', event);
|
|
575
|
-
}
|
|
576
|
-
injectMetaData(metaData) {
|
|
577
|
-
if (this.closed)
|
|
578
|
-
return;
|
|
579
|
-
if (!this._injections.clientMetaItems)
|
|
580
|
-
this._injections.clientMetaItems = [];
|
|
581
|
-
this._injections.clientMetaItems.push(metaData);
|
|
582
|
-
}
|
|
583
|
-
injectEvent(event) {
|
|
584
|
-
if (this.closed)
|
|
585
|
-
return;
|
|
586
|
-
if (!this._injections.clientEvents)
|
|
587
|
-
this._injections.clientEvents = [];
|
|
588
|
-
this._injections.clientEvents.push(event);
|
|
589
|
-
}
|
|
590
|
-
injectIssue(issue) {
|
|
591
|
-
if (this.closed)
|
|
592
|
-
return;
|
|
593
|
-
if (!this._injections.clientIssues)
|
|
594
|
-
this._injections.clientIssues = [];
|
|
595
|
-
this._injections.clientIssues.push(issue);
|
|
596
|
-
}
|
|
597
|
-
injectExtensionStat(stat) {
|
|
598
|
-
if (this.closed)
|
|
599
|
-
return;
|
|
600
|
-
if (!this._injections.extensionStats)
|
|
601
|
-
this._injections.extensionStats = [];
|
|
602
|
-
this._injections.extensionStats.push(stat);
|
|
603
|
-
}
|
|
604
|
-
injectAttachment(key, value) {
|
|
605
|
-
if (this.closed)
|
|
606
|
-
return;
|
|
607
|
-
if (!this._injections.attachments)
|
|
608
|
-
this._injections.attachments = {};
|
|
609
|
-
this._injections.attachments[key] = value;
|
|
610
|
-
}
|
|
611
|
-
addMetadata(metadata) {
|
|
612
|
-
if (this.closed)
|
|
613
|
-
return;
|
|
614
|
-
switch (metadata.type) {
|
|
615
|
-
case ClientMetaTypes_1.ClientMetaTypes.BROWSER: {
|
|
616
|
-
this.browser = (0, utils_1.parseJsonAs)(metadata.payload);
|
|
617
|
-
break;
|
|
618
|
-
}
|
|
619
|
-
case ClientMetaTypes_1.ClientMetaTypes.ENGINE: {
|
|
620
|
-
this.engine = (0, utils_1.parseJsonAs)(metadata.payload);
|
|
621
|
-
break;
|
|
622
|
-
}
|
|
623
|
-
case ClientMetaTypes_1.ClientMetaTypes.PLATFORM: {
|
|
624
|
-
this.platform = (0, utils_1.parseJsonAs)(metadata.payload);
|
|
625
|
-
break;
|
|
626
|
-
}
|
|
627
|
-
case ClientMetaTypes_1.ClientMetaTypes.OPERATION_SYSTEM: {
|
|
628
|
-
this.operationSystem = (0, utils_1.parseJsonAs)(metadata.payload);
|
|
629
|
-
break;
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
this.call.observer.emit('client-metadata', this, metadata);
|
|
633
|
-
}
|
|
634
|
-
addIssue(issue) {
|
|
635
|
-
if (this.closed)
|
|
636
|
-
return;
|
|
637
|
-
this.report.issues[issue.type] = (this.report.issues[issue.type] ?? 0) + 1;
|
|
638
|
-
this.emit('issue', issue);
|
|
639
|
-
this.call.observer.emit('client-issue', this, issue);
|
|
640
|
-
}
|
|
641
|
-
addExtensionStats(stats) {
|
|
642
|
-
this.call.observer.emit('client-extension-stats', this, stats);
|
|
643
|
-
this.emit('extensionStats', stats);
|
|
644
|
-
}
|
|
645
|
-
_updatePeerConnection(sample) {
|
|
646
|
-
let observedPeerConnection = this.observedPeerConnections.get(sample.peerConnectionId);
|
|
647
|
-
if (!observedPeerConnection) {
|
|
648
|
-
if (!sample.peerConnectionId) {
|
|
649
|
-
return (logger.warn(`ObservedClient received an invalid PeerConnectionSample (missing peerConnectionId field). ClientId: ${this.clientId}, CallId: ${this.call.callId}`, sample), void 0);
|
|
650
|
-
}
|
|
651
|
-
const newObservedPeerConnection = new ObservedPeerConnection_1.ObservedPeerConnection(sample.peerConnectionId, this);
|
|
652
|
-
const onInboundTrackRemoved = (track) => {
|
|
653
|
-
this.emit('trackreport', {
|
|
654
|
-
direction: 'inbound',
|
|
655
|
-
...track.report,
|
|
656
|
-
});
|
|
657
|
-
};
|
|
658
|
-
const onOutboundTrackRemoved = (track) => {
|
|
659
|
-
this.emit('trackreport', {
|
|
660
|
-
direction: 'outbound',
|
|
661
|
-
...track.report,
|
|
662
|
-
});
|
|
663
|
-
};
|
|
664
|
-
newObservedPeerConnection.once('close', () => {
|
|
665
|
-
newObservedPeerConnection?.off('removed-inbound-track', onInboundTrackRemoved);
|
|
666
|
-
newObservedPeerConnection?.off('removed-outbound-track', onOutboundTrackRemoved);
|
|
667
|
-
this.observedPeerConnections.delete(sample.peerConnectionId);
|
|
668
|
-
});
|
|
669
|
-
newObservedPeerConnection.on('removed-inbound-track', onInboundTrackRemoved);
|
|
670
|
-
newObservedPeerConnection.on('removed-outbound-track', onOutboundTrackRemoved);
|
|
671
|
-
this.observedPeerConnections.set(sample.peerConnectionId, newObservedPeerConnection);
|
|
672
|
-
this.emit('newpeerconnection', newObservedPeerConnection);
|
|
673
|
-
observedPeerConnection = newObservedPeerConnection;
|
|
674
|
-
}
|
|
675
|
-
observedPeerConnection.accept(sample);
|
|
676
|
-
return observedPeerConnection;
|
|
677
|
-
}
|
|
678
|
-
_mergeInjections(sample) {
|
|
679
|
-
if (this.closed)
|
|
680
|
-
return sample;
|
|
681
|
-
if (this._injections.clientEvents) {
|
|
682
|
-
if (!sample.clientEvents)
|
|
683
|
-
sample.clientEvents = [];
|
|
684
|
-
sample.clientEvents.push(...this._injections.clientEvents);
|
|
685
|
-
this._injections.clientEvents = undefined;
|
|
686
|
-
}
|
|
687
|
-
if (this._injections.clientIssues) {
|
|
688
|
-
if (!sample.clientIssues)
|
|
689
|
-
sample.clientIssues = [];
|
|
690
|
-
sample.clientIssues.push(...this._injections.clientIssues);
|
|
691
|
-
this._injections.clientIssues = undefined;
|
|
692
|
-
}
|
|
693
|
-
if (this._injections.extensionStats) {
|
|
694
|
-
if (!sample.extensionStats)
|
|
695
|
-
sample.extensionStats = [];
|
|
696
|
-
sample.extensionStats.push(...this._injections.extensionStats);
|
|
697
|
-
this._injections.extensionStats = undefined;
|
|
698
|
-
}
|
|
699
|
-
if (this._injections.attachments) {
|
|
700
|
-
if (!sample.attachments)
|
|
701
|
-
sample.attachments = {};
|
|
702
|
-
Object.assign(sample.attachments, this._injections.attachments);
|
|
703
|
-
this._injections.attachments = undefined;
|
|
704
|
-
}
|
|
705
|
-
if (this._injections.clientMetaItems) {
|
|
706
|
-
if (!sample.clientMetaItems)
|
|
707
|
-
sample.clientMetaItems = [];
|
|
708
|
-
sample.clientMetaItems.push(...this._injections.clientMetaItems);
|
|
709
|
-
this._injections.clientMetaItems = undefined;
|
|
710
|
-
}
|
|
711
|
-
return sample;
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
exports.ObservedClient = ObservedClient;
|