@observertc/observer-js 1.0.0-beta.2 → 1.0.0-beta.4

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