@observertc/observer-js 0.42.9 → 1.0.1-1b9b3c5.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.
Files changed (295) hide show
  1. package/.prettierrc +6 -6
  2. package/README.md +0 -104
  3. package/lib/ObservedCall.d.ts +63 -43
  4. package/lib/ObservedCall.d.ts.map +1 -1
  5. package/lib/ObservedCall.js +176 -108
  6. package/lib/ObservedCallEventMonitor.d.ts +103 -0
  7. package/lib/ObservedCallEventMonitor.d.ts.map +1 -0
  8. package/lib/ObservedCallEventMonitor.js +312 -0
  9. package/lib/ObservedCallSummary.d.ts +18 -0
  10. package/lib/ObservedCallSummary.d.ts.map +1 -0
  11. package/lib/ObservedCertificate.d.ts +19 -0
  12. package/lib/ObservedCertificate.d.ts.map +1 -0
  13. package/lib/ObservedCertificate.js +38 -0
  14. package/lib/ObservedClient.d.ts +79 -130
  15. package/lib/ObservedClient.d.ts.map +1 -1
  16. package/lib/ObservedClient.js +463 -744
  17. package/lib/ObservedClientEventMonitor.d.ts +89 -0
  18. package/lib/ObservedClientEventMonitor.d.ts.map +1 -0
  19. package/lib/ObservedClientEventMonitor.js +247 -0
  20. package/lib/ObservedClientSummary.d.ts +23 -0
  21. package/lib/ObservedClientSummary.d.ts.map +1 -0
  22. package/lib/ObservedClientSummary.js +2 -0
  23. package/lib/ObservedCodec.d.ts +22 -0
  24. package/lib/ObservedCodec.d.ts.map +1 -0
  25. package/lib/ObservedCodec.js +45 -0
  26. package/lib/ObservedDataChannel.d.ts +25 -69
  27. package/lib/ObservedDataChannel.d.ts.map +1 -1
  28. package/lib/ObservedDataChannel.js +69 -109
  29. package/lib/ObservedIceCandidate.d.ts +29 -0
  30. package/lib/ObservedIceCandidate.d.ts.map +1 -0
  31. package/lib/ObservedIceCandidate.js +59 -0
  32. package/lib/ObservedIceCandidatePair.d.ts +44 -0
  33. package/lib/ObservedIceCandidatePair.d.ts.map +1 -0
  34. package/lib/ObservedIceCandidatePair.js +111 -0
  35. package/lib/ObservedIceTransport.d.ts +36 -0
  36. package/lib/ObservedIceTransport.d.ts.map +1 -0
  37. package/lib/ObservedIceTransport.js +93 -0
  38. package/lib/ObservedInboundRtp.d.ts +92 -0
  39. package/lib/ObservedInboundRtp.d.ts.map +1 -0
  40. package/lib/ObservedInboundRtp.js +193 -0
  41. package/lib/ObservedInboundTrack.d.ts +31 -0
  42. package/lib/ObservedInboundTrack.d.ts.map +1 -0
  43. package/lib/ObservedInboundTrack.js +59 -0
  44. package/lib/ObservedMediaPlayout.d.ts +22 -0
  45. package/lib/ObservedMediaPlayout.d.ts.map +1 -0
  46. package/lib/ObservedMediaPlayout.js +42 -0
  47. package/lib/ObservedMediaSource.d.ts +28 -0
  48. package/lib/ObservedMediaSource.d.ts.map +1 -0
  49. package/lib/ObservedMediaSource.js +55 -0
  50. package/lib/ObservedOutboundRtp.d.ts +62 -0
  51. package/lib/ObservedOutboundRtp.d.ts.map +1 -0
  52. package/lib/ObservedOutboundRtp.js +144 -0
  53. package/lib/ObservedOutboundTrack.d.ts +31 -0
  54. package/lib/ObservedOutboundTrack.d.ts.map +1 -0
  55. package/lib/ObservedOutboundTrack.js +59 -0
  56. package/lib/ObservedPeerConnection.d.ts +132 -80
  57. package/lib/ObservedPeerConnection.d.ts.map +1 -1
  58. package/lib/ObservedPeerConnection.js +646 -357
  59. package/lib/ObservedPeerConnectionTransport.d.ts +17 -0
  60. package/lib/ObservedPeerConnectionTransport.d.ts.map +1 -0
  61. package/lib/ObservedPeerConnectionTransport.js +34 -0
  62. package/lib/ObservedRemoteInboundRtp.d.ts +30 -0
  63. package/lib/ObservedRemoteInboundRtp.d.ts.map +1 -0
  64. package/lib/ObservedRemoteInboundRtp.js +60 -0
  65. package/lib/ObservedRemoteOutboundRtp.d.ts +30 -0
  66. package/lib/ObservedRemoteOutboundRtp.d.ts.map +1 -0
  67. package/lib/ObservedRemoteOutboundRtp.js +60 -0
  68. package/lib/ObservedTURN.d.ts +31 -0
  69. package/lib/ObservedTURN.d.ts.map +1 -0
  70. package/lib/ObservedTURN.js +58 -0
  71. package/lib/ObservedTurnServer.d.ts +25 -0
  72. package/lib/ObservedTurnServer.d.ts.map +1 -0
  73. package/lib/ObservedTurnServer.js +59 -0
  74. package/lib/Observer.d.ts +44 -51
  75. package/lib/Observer.d.ts.map +1 -1
  76. package/lib/Observer.js +135 -226
  77. package/lib/ObserverEventMonitor.d.ts +106 -0
  78. package/lib/ObserverEventMonitor.d.ts.map +1 -0
  79. package/lib/ObserverEventMonitor.js +320 -0
  80. package/lib/ObserverSummary.d.ts +13 -0
  81. package/lib/ObserverSummary.d.ts.map +1 -0
  82. package/lib/ObserverSummary.js +2 -0
  83. package/lib/common/Middleware.d.ts +10 -1
  84. package/lib/common/Middleware.d.ts.map +1 -1
  85. package/lib/common/Middleware.js +55 -36
  86. package/lib/common/logger.d.ts +8 -4
  87. package/lib/common/logger.d.ts.map +1 -1
  88. package/lib/common/logger.js +44 -68
  89. package/lib/common/types.d.ts +0 -21
  90. package/lib/common/types.d.ts.map +1 -1
  91. package/lib/common/types.js +1 -0
  92. package/lib/common/utils.d.ts +3 -1
  93. package/lib/common/utils.d.ts.map +1 -1
  94. package/lib/common/utils.js +23 -3
  95. package/lib/detectors/Detector.d.ts +5 -0
  96. package/lib/detectors/Detector.d.ts.map +1 -0
  97. package/lib/detectors/Detector.js +3 -0
  98. package/lib/detectors/Detectors.d.ts +11 -0
  99. package/lib/detectors/Detectors.d.ts.map +1 -0
  100. package/lib/detectors/Detectors.js +34 -0
  101. package/lib/index.d.ts +26 -25
  102. package/lib/index.d.ts.map +1 -1
  103. package/lib/index.js +45 -41
  104. package/lib/monitors/TurnUsageMonitor.d.ts +0 -52
  105. package/lib/monitors/TurnUsageMonitor.d.ts.map +1 -1
  106. package/lib/monitors/TurnUsageMonitor.js +145 -120
  107. package/lib/schema/ClientEventTypes.d.ts +160 -0
  108. package/lib/schema/ClientEventTypes.d.ts.map +1 -0
  109. package/lib/schema/ClientEventTypes.js +38 -0
  110. package/lib/schema/ClientMetaTypes.d.ts +34 -0
  111. package/lib/schema/ClientMetaTypes.d.ts.map +1 -0
  112. package/lib/schema/ClientMetaTypes.js +16 -0
  113. package/lib/schema/ClientSample.d.ts +1333 -0
  114. package/lib/schema/ClientSample.d.ts.map +1 -0
  115. package/lib/schema/ClientSample.js +4 -0
  116. package/lib/scores/CalculatedScore.d.ts +6 -0
  117. package/lib/scores/CalculatedScore.d.ts.map +1 -0
  118. package/lib/scores/CalculatedScore.js +2 -0
  119. package/lib/scores/DefaultCallScoreCalculator.d.ts +7 -0
  120. package/lib/scores/DefaultCallScoreCalculator.d.ts.map +1 -0
  121. package/lib/scores/DefaultCallScoreCalculator.js +21 -0
  122. package/lib/scores/ScoreCalculator.d.ts +4 -0
  123. package/lib/scores/ScoreCalculator.d.ts.map +1 -0
  124. package/lib/scores/ScoreCalculator.js +2 -0
  125. package/lib/updaters/CallUpdater.d.ts +5 -0
  126. package/lib/updaters/CallUpdater.d.ts.map +1 -0
  127. package/lib/updaters/CallUpdater.js +2 -0
  128. package/lib/updaters/ObserverUpdater.d.ts +5 -0
  129. package/lib/updaters/ObserverUpdater.d.ts.map +1 -0
  130. package/lib/updaters/ObserverUpdater.js +2 -0
  131. package/lib/updaters/OnAllCallObserverUpdater.d.ts +15 -0
  132. package/lib/updaters/OnAllCallObserverUpdater.d.ts.map +1 -0
  133. package/lib/updaters/OnAllCallObserverUpdater.js +50 -0
  134. package/lib/updaters/OnAllClientCallUpdater.d.ts +15 -0
  135. package/lib/updaters/OnAllClientCallUpdater.d.ts.map +1 -0
  136. package/lib/updaters/OnAllClientCallUpdater.js +53 -0
  137. package/lib/updaters/OnAnyCallObserverUpdater.d.ts +12 -0
  138. package/lib/updaters/OnAnyCallObserverUpdater.d.ts.map +1 -0
  139. package/lib/updaters/OnAnyCallObserverUpdater.js +37 -0
  140. package/lib/updaters/OnAnyClientCallUpdater.d.ts +12 -0
  141. package/lib/updaters/OnAnyClientCallUpdater.d.ts.map +1 -0
  142. package/lib/updaters/OnAnyClientCallUpdater.js +36 -0
  143. package/lib/updaters/OnIntervalUpdater.d.ts +10 -0
  144. package/lib/updaters/OnIntervalUpdater.d.ts.map +1 -0
  145. package/lib/updaters/OnIntervalUpdater.js +17 -0
  146. package/lib/updaters/Updater.d.ts +6 -0
  147. package/lib/updaters/Updater.d.ts.map +1 -0
  148. package/lib/updaters/Updater.js +2 -0
  149. package/lib/utils/MediasoupRemoteTrackResolver.d.ts +25 -0
  150. package/lib/utils/MediasoupRemoteTrackResolver.d.ts.map +1 -0
  151. package/lib/utils/MediasoupRemoteTrackResolver.js +110 -0
  152. package/lib/utils/RemoteTrackResolver.d.ts +7 -0
  153. package/lib/utils/RemoteTrackResolver.d.ts.map +1 -0
  154. package/lib/utils/RemoteTrackResolver.js +2 -0
  155. package/package.json +4 -4
  156. package/src/ObservedCall.ts +267 -166
  157. package/src/ObservedCallEventMonitor.ts +389 -0
  158. package/src/ObservedCallSummary.ts +22 -0
  159. package/src/ObservedCertificate.ts +43 -0
  160. package/src/ObservedClient.ts +519 -1020
  161. package/src/ObservedClientEventMonitor.ts +301 -0
  162. package/src/ObservedClientSummary.ts +24 -0
  163. package/src/ObservedCodec.ts +49 -0
  164. package/src/ObservedDataChannel.ts +71 -181
  165. package/src/ObservedIceCandidate.ts +64 -0
  166. package/src/ObservedIceCandidatePair.ts +118 -0
  167. package/src/ObservedIceTransport.ts +99 -0
  168. package/src/ObservedInboundRtp.ts +205 -0
  169. package/src/ObservedInboundTrack.ts +73 -0
  170. package/src/ObservedMediaPlayout.ts +49 -0
  171. package/src/ObservedMediaSource.ts +60 -0
  172. package/src/ObservedOutboundRtp.ts +156 -0
  173. package/src/ObservedOutboundTrack.ts +72 -0
  174. package/src/ObservedPeerConnection.ts +854 -408
  175. package/src/ObservedPeerConnectionTransport.ts +38 -0
  176. package/src/ObservedRemoteInboundRtp.ts +64 -0
  177. package/src/ObservedRemoteOutboundRtp.ts +65 -0
  178. package/src/ObservedTURN.ts +86 -0
  179. package/src/ObservedTurnServer.ts +72 -0
  180. package/src/Observer.ts +180 -295
  181. package/src/ObserverEventMonitor.ts +398 -0
  182. package/src/ObserverSummary.ts +15 -0
  183. package/src/common/Middleware.ts +70 -42
  184. package/src/common/logger.ts +60 -69
  185. package/src/common/types.ts +0 -42
  186. package/src/common/utils.ts +24 -2
  187. package/src/detectors/Detector.ts +6 -0
  188. package/src/detectors/Detectors.ts +38 -0
  189. package/src/index.ts +26 -90
  190. package/src/monitors/TurnUsageMonitor.ts +164 -164
  191. package/src/schema/ClientEventTypes.ts +176 -0
  192. package/src/schema/ClientMetaTypes.ts +41 -0
  193. package/src/schema/ClientSample.ts +1682 -0
  194. package/src/scores/CalculatedScore.ts +6 -0
  195. package/src/scores/DefaultCallScoreCalculator.ts +23 -0
  196. package/src/scores/ScoreCalculator.ts +3 -0
  197. package/src/updaters/CallUpdater.ts +5 -0
  198. package/src/updaters/ObserverUpdater.ts +5 -0
  199. package/src/updaters/OnAllCallObserverUpdater.ts +59 -0
  200. package/src/updaters/OnAllClientCallUpdater.ts +61 -0
  201. package/src/updaters/OnAnyCallObserverUpdater.ts +41 -0
  202. package/src/updaters/OnAnyClientCallUpdater.ts +39 -0
  203. package/src/updaters/OnIntervalUpdater.ts +19 -0
  204. package/src/updaters/Updater.ts +5 -0
  205. package/src/utils/MediasoupRemoteTrackResolver.ts +155 -0
  206. package/src/utils/RemoteTrackResolver.ts +12 -0
  207. package/tsconfig.json +3 -3
  208. package/lib/ObservedICE.d.ts +0 -64
  209. package/lib/ObservedICE.d.ts.map +0 -1
  210. package/lib/ObservedICE.js +0 -141
  211. package/lib/ObservedInboundAudioTrack.d.ts +0 -96
  212. package/lib/ObservedInboundAudioTrack.d.ts.map +0 -1
  213. package/lib/ObservedInboundAudioTrack.js +0 -217
  214. package/lib/ObservedInboundVideoTrack.d.ts +0 -101
  215. package/lib/ObservedInboundVideoTrack.d.ts.map +0 -1
  216. package/lib/ObservedInboundVideoTrack.js +0 -232
  217. package/lib/ObservedOutboundAudioTrack.d.ts +0 -87
  218. package/lib/ObservedOutboundAudioTrack.d.ts.map +0 -1
  219. package/lib/ObservedOutboundAudioTrack.js +0 -186
  220. package/lib/ObservedOutboundVideoTrack.d.ts +0 -91
  221. package/lib/ObservedOutboundVideoTrack.d.ts.map +0 -1
  222. package/lib/ObservedOutboundVideoTrack.js +0 -193
  223. package/lib/ObservedSfu.d.ts +0 -59
  224. package/lib/ObservedSfu.d.ts.map +0 -1
  225. package/lib/ObservedSfu.js +0 -157
  226. package/lib/ObservedSfuInboundRtpPad.d.ts +0 -42
  227. package/lib/ObservedSfuInboundRtpPad.d.ts.map +0 -1
  228. package/lib/ObservedSfuInboundRtpPad.js +0 -71
  229. package/lib/ObservedSfuOutboundRtpPad.d.ts +0 -42
  230. package/lib/ObservedSfuOutboundRtpPad.d.ts.map +0 -1
  231. package/lib/ObservedSfuOutboundRtpPad.js +0 -72
  232. package/lib/ObservedSfuSctpChannel.d.ts +0 -42
  233. package/lib/ObservedSfuSctpChannel.d.ts.map +0 -1
  234. package/lib/ObservedSfuSctpChannel.js +0 -57
  235. package/lib/ObservedSfuTransport.d.ts +0 -58
  236. package/lib/ObservedSfuTransport.d.ts.map +0 -1
  237. package/lib/ObservedSfuTransport.js +0 -120
  238. package/lib/RemoteTrackAssigner.d.ts +0 -14
  239. package/lib/RemoteTrackAssigner.d.ts.map +0 -1
  240. package/lib/RemoteTrackAssigner.js +0 -52
  241. package/lib/ReportsCollector.d.ts +0 -109
  242. package/lib/ReportsCollector.d.ts.map +0 -1
  243. package/lib/ReportsCollector.js +0 -207
  244. package/lib/common/CalculatedScore.d.ts +0 -80
  245. package/lib/common/CalculatedScore.d.ts.map +0 -1
  246. package/lib/common/CalculatedScore.js +0 -162
  247. package/lib/common/CallEventType.d.ts +0 -63
  248. package/lib/common/CallEventType.d.ts.map +0 -1
  249. package/lib/common/CallEventType.js +0 -39
  250. package/lib/common/CallMetaReports.d.ts +0 -42
  251. package/lib/common/CallMetaReports.d.ts.map +0 -1
  252. package/lib/common/CallMetaReports.js +0 -36
  253. package/lib/common/QualityScoreUtils.d.ts +0 -1
  254. package/lib/common/QualityScoreUtils.d.ts.map +0 -1
  255. package/lib/common/QualityScoreUtils.js +0 -1
  256. package/lib/common/TypedEventEmitter.d.ts +0 -22
  257. package/lib/common/TypedEventEmitter.d.ts.map +0 -1
  258. package/lib/common/TypedEventEmitter.js +0 -11
  259. package/lib/common/callEventReports.d.ts +0 -10
  260. package/lib/common/callEventReports.d.ts.map +0 -1
  261. package/lib/common/callEventReports.js +0 -112
  262. package/lib/monitors/CallSummary.d.ts +0 -37
  263. package/lib/monitors/CallSummary.d.ts.map +0 -1
  264. package/lib/monitors/CallSummaryMonitor.d.ts +0 -32
  265. package/lib/monitors/CallSummaryMonitor.d.ts.map +0 -1
  266. package/lib/monitors/CallSummaryMonitor.js +0 -152
  267. package/lib/monitors/ClientIssueMonitor.d.ts +0 -32
  268. package/lib/monitors/ClientIssueMonitor.d.ts.map +0 -1
  269. package/lib/monitors/ClientIssueMonitor.js +0 -49
  270. package/lib/monitors/SfuServerMonitor.d.ts +0 -79
  271. package/lib/monitors/SfuServerMonitor.d.ts.map +0 -1
  272. package/lib/monitors/SfuServerMonitor.js +0 -198
  273. package/src/ObservedICE.ts +0 -237
  274. package/src/ObservedInboundAudioTrack.ts +0 -344
  275. package/src/ObservedInboundVideoTrack.ts +0 -361
  276. package/src/ObservedOutboundAudioTrack.ts +0 -307
  277. package/src/ObservedOutboundVideoTrack.ts +0 -319
  278. package/src/ObservedSfu.ts +0 -231
  279. package/src/ObservedSfuInboundRtpPad.ts +0 -106
  280. package/src/ObservedSfuOutboundRtpPad.ts +0 -107
  281. package/src/ObservedSfuSctpChannel.ts +0 -103
  282. package/src/ObservedSfuTransport.ts +0 -185
  283. package/src/RemoteTrackAssigner.ts +0 -68
  284. package/src/ReportsCollector.ts +0 -336
  285. package/src/common/CalculatedScore.ts +0 -188
  286. package/src/common/CallEventType.ts +0 -69
  287. package/src/common/CallMetaReports.ts +0 -82
  288. package/src/common/QualityScoreUtils.ts +0 -0
  289. package/src/common/TypedEventEmitter.ts +0 -32
  290. package/src/common/callEventReports.ts +0 -178
  291. package/src/monitors/CallSummary.ts +0 -38
  292. package/src/monitors/CallSummaryMonitor.ts +0 -192
  293. package/src/monitors/ClientIssueMonitor.ts +0 -88
  294. package/src/monitors/SfuServerMonitor.ts +0 -285
  295. /package/lib/{monitors/CallSummary.js → ObservedCallSummary.js} +0 -0
@@ -2,169 +2,191 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ObservedPeerConnection = void 0;
4
4
  const events_1 = require("events");
5
- const ObservedICE_1 = require("./ObservedICE");
5
+ const ObservedInboundRtp_1 = require("./ObservedInboundRtp");
6
+ const logger_1 = require("./common/logger");
7
+ const ObservedOutboundRtp_1 = require("./ObservedOutboundRtp");
8
+ const ObservedCertificate_1 = require("./ObservedCertificate");
9
+ const ObservedCodec_1 = require("./ObservedCodec");
6
10
  const ObservedDataChannel_1 = require("./ObservedDataChannel");
7
- const ObservedInboundAudioTrack_1 = require("./ObservedInboundAudioTrack");
8
- const ObservedInboundVideoTrack_1 = require("./ObservedInboundVideoTrack");
9
- const ObservedOutboundAudioTrack_1 = require("./ObservedOutboundAudioTrack");
10
- const ObservedOutboundVideoTrack_1 = require("./ObservedOutboundVideoTrack");
11
- const CalculatedScore_1 = require("./common/CalculatedScore");
11
+ const ObservedIceCandidate_1 = require("./ObservedIceCandidate");
12
+ const ObservedIceCandidatePair_1 = require("./ObservedIceCandidatePair");
13
+ const ObservedIceTransport_1 = require("./ObservedIceTransport");
14
+ const ObservedMediaSource_1 = require("./ObservedMediaSource");
15
+ const ObservedPeerConnectionTransport_1 = require("./ObservedPeerConnectionTransport");
16
+ const ObservedMediaPlayout_1 = require("./ObservedMediaPlayout");
17
+ const ObservedRemoteInboundRtp_1 = require("./ObservedRemoteInboundRtp");
18
+ const ObservedRemoteOutboundRtp_1 = require("./ObservedRemoteOutboundRtp");
19
+ const ObservedInboundTrack_1 = require("./ObservedInboundTrack");
20
+ const ObservedOutboundTrack_1 = require("./ObservedOutboundTrack");
21
+ const utils_1 = require("./common/utils");
22
+ const logger = (0, logger_1.createLogger)('ObservedPeerConnection');
12
23
  class ObservedPeerConnection extends events_1.EventEmitter {
13
- constructor(_model, client) {
24
+ peerConnectionId;
25
+ client;
26
+ _visited = true;
27
+ appData;
28
+ calculatedScore = {
29
+ weight: 1,
30
+ value: undefined,
31
+ };
32
+ closed = false;
33
+ // timestamp of the PEER_CONNECTION_OPENED event
34
+ openedAt;
35
+ // timestamp of the PEER_CONNECTION_CLOSED event
36
+ closedAt;
37
+ updated = Date.now();
38
+ availableIncomingBitrate = 0;
39
+ availableOutgoingBitrate = 0;
40
+ totalInboundPacketsLost = 0;
41
+ totalInboundPacketsReceived = 0;
42
+ totalOutboundPacketsSent = 0;
43
+ totalDataChannelBytesSent = 0;
44
+ totalDataChannelBytesReceived = 0;
45
+ totalDataChannelMessagesSent = 0;
46
+ totalDataChannelMessagesReceived = 0;
47
+ totalSentAudioBytes = 0;
48
+ totalSentVideoBytes = 0;
49
+ totalSentAudioPackets = 0;
50
+ totalSentVideoPackets = 0;
51
+ totalReceivedAudioPacktes = 0;
52
+ totalReceivedVideoPackets = 0;
53
+ totalReceivedAudioBytes = 0;
54
+ totalReceivedVideoBytes = 0;
55
+ deltaInboundPacketsLost = 0;
56
+ deltaInboundPacketsReceived = 0;
57
+ deltaOutboundPacketsSent = 0;
58
+ deltaDataChannelBytesSent = 0;
59
+ deltaDataChannelBytesReceived = 0;
60
+ deltaDataChannelMessagesSent = 0;
61
+ deltaDataChannelMessagesReceived = 0;
62
+ deltaInboundReceivedBytes = 0;
63
+ deltaOutboundSentBytes = 0;
64
+ deltaReceivedAudioBytes = 0;
65
+ deltaReceivedVideoBytes = 0;
66
+ deltaReceivedAudioPackets = 0;
67
+ deltaReceivedVideoPackets = 0;
68
+ deltaSentAudioBytes = 0;
69
+ deltaSentVideoBytes = 0;
70
+ deltaTransportSentBytes = 0;
71
+ deltaTransportReceivedBytes = 0;
72
+ receivingPacketsPerSecond = 0;
73
+ sendingPacketsPerSecond = 0;
74
+ sendingAudioBitrate = 0;
75
+ sendingVideoBitrate = 0;
76
+ receivingAudioBitrate = 0;
77
+ receivingVideoBitrate = 0;
78
+ currentRttInMs;
79
+ currentJitter;
80
+ usingTCP = false;
81
+ usingTURN = false;
82
+ observedTurnServer;
83
+ observedCertificates = new Map();
84
+ observedCodecs = new Map();
85
+ observedDataChannels = new Map();
86
+ observedIceCandidates = new Map();
87
+ observedIceCandidatesPair = new Map();
88
+ observedIceTransports = new Map();
89
+ observedInboundRtps = new Map();
90
+ observedInboundTracks = new Map();
91
+ observedMediaPlayouts = new Map();
92
+ observedMediaSources = new Map();
93
+ observedOutboundRtps = new Map();
94
+ observedOutboundTracks = new Map();
95
+ observedPeerConnectionTransports = new Map();
96
+ observedRemoteInboundRtps = new Map();
97
+ observedRemoteOutboundRtps = new Map();
98
+ constructor(peerConnectionId, client) {
14
99
  super();
15
- this._model = _model;
100
+ this.peerConnectionId = peerConnectionId;
16
101
  this.client = client;
17
- this.created = Date.now();
18
- this.visited = true;
19
- this._stabilityScores = [];
20
- this.ωpendingIssuesForScores = [];
21
- this.totalInboundPacketsLost = 0;
22
- this.totalInboundPacketsReceived = 0;
23
- this.totalOutboundPacketsSent = 0;
24
- this.totalDataChannelBytesSent = 0;
25
- this.totalDataChannelBytesReceived = 0;
26
- this.totalSentAudioBytes = 0;
27
- this.totalSentVideoBytes = 0;
28
- this.totalSentAudioPackets = 0;
29
- this.totalSentVideoPackets = 0;
30
- this.totalReceivedAudioPacktes = 0;
31
- this.totalReceivedVideoPackets = 0;
32
- this.totalReceivedAudioBytes = 0;
33
- this.totalReceivedVideoBytes = 0;
34
- this.deltaInboundPacketsLost = 0;
35
- this.deltaInboundPacketsReceived = 0;
36
- this.deltaOutboundPacketsSent = 0;
37
- this.deltaDataChannelBytesSent = 0;
38
- this.deltaDataChannelBytesReceived = 0;
39
- this.deltaInboundReceivedBytes = 0;
40
- this.deltaOutboundSentBytes = 0;
41
- this.deltaReceivedAudioBytes = 0;
42
- this.deltaReceivedVideoBytes = 0;
43
- this.deltaReceivedAudioPackets = 0;
44
- this.deltaReceivedVideoPackets = 0;
45
- this.deltaSentAudioBytes = 0;
46
- this.deltaSentVideoBytes = 0;
47
- this.receivingPacketsPerSecond = 0;
48
- this.sendingPacketsPerSecond = 0;
49
- this.sendingAudioBitrate = 0;
50
- this.sendingVideoBitrate = 0;
51
- this.receivingAudioBitrate = 0;
52
- this.receivingVideoBitrate = 0;
53
- this._closed = false;
54
- this._updated = Date.now();
55
- this.ICE = ObservedICE_1.ObservedICE.create(this);
56
- this._inboundAudioTracks = new Map();
57
- this._inboundVideoTracks = new Map();
58
- this._outboundAudioTracks = new Map();
59
- this._outboundVideoTracks = new Map();
60
- this._dataChannels = new Map();
61
102
  this.setMaxListeners(Infinity);
62
103
  }
63
- get serviceId() {
64
- return this.client.serviceId;
65
- }
66
- get roomId() {
67
- return this.client.roomId;
68
- }
69
- get callId() {
70
- return this.client.callId;
71
- }
72
- get clientId() {
73
- return this.client.clientId;
74
- }
75
- get mediaUnitId() {
76
- return this.client.mediaUnitId;
77
- }
78
- get label() {
79
- return this._model.label;
80
- }
81
- set label(value) {
82
- this._model.label = value;
83
- }
84
- get usingTURN() {
85
- return this.ICE.usingTURN;
104
+ get score() {
105
+ return this.calculatedScore.value;
86
106
  }
87
- get availableOutgoingBitrate() {
88
- var _a;
89
- return (_a = this.ICE.stats) === null || _a === void 0 ? void 0 : _a.availableOutgoingBitrate;
107
+ get visited() {
108
+ const visited = this._visited;
109
+ this._visited = false;
110
+ return visited;
90
111
  }
91
- get availableIncomingBitrate() {
92
- var _a;
93
- return (_a = this.ICE.stats) === null || _a === void 0 ? void 0 : _a.availableIncomingBitrate;
112
+ get codecs() {
113
+ return [...this.observedCodecs.values()];
94
114
  }
95
- get peerConnectionId() {
96
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
97
- return this._model.peerConnectionId;
115
+ get inboundRtps() {
116
+ return [...this.observedInboundRtps.values()];
98
117
  }
99
- get reports() {
100
- return this.client.reports;
118
+ get remoteOutboundRtps() {
119
+ return [...this.observedRemoteOutboundRtps.values()];
101
120
  }
102
- get stats() {
103
- return this._sample;
121
+ get outboundRtps() {
122
+ return [...this.observedOutboundRtps.values()];
104
123
  }
105
- get updated() {
106
- return this._updated;
124
+ get remoteInboundRtps() {
125
+ return [...this.observedRemoteInboundRtps.values()];
107
126
  }
108
- get inboundAudioTracks() {
109
- return this._inboundAudioTracks;
127
+ get mediaSources() {
128
+ return [...this.observedMediaSources.values()];
110
129
  }
111
- get inboundVideoTracks() {
112
- return this._inboundVideoTracks;
130
+ get mediaPlayouts() {
131
+ return [...this.observedMediaPlayouts.values()];
113
132
  }
114
- get outboundAudioTracks() {
115
- return this._outboundAudioTracks;
133
+ get dataChannels() {
134
+ return [...this.observedDataChannels.values()];
116
135
  }
117
- get outboundVideoTracks() {
118
- return this._outboundVideoTracks;
136
+ get peerConnectionTransports() {
137
+ return [...this.observedPeerConnectionTransports.values()];
119
138
  }
120
- get dataChannels() {
121
- return this._dataChannels;
139
+ get iceTransports() {
140
+ return [...this.observedIceTransports.values()];
122
141
  }
123
- get uptimeInMs() {
124
- return this._updated - this.created;
142
+ get iceCandidates() {
143
+ return [...this.observedIceCandidates.values()];
125
144
  }
126
- get marker() {
127
- return this._marker;
145
+ get iceCandidatePairs() {
146
+ return [...this.observedIceCandidatesPair.values()];
128
147
  }
129
- set marker(value) {
130
- this._marker = value;
131
- this._inboundAudioTracks.forEach((track) => (track.marker = value));
132
- this._inboundVideoTracks.forEach((track) => (track.marker = value));
133
- this._outboundAudioTracks.forEach((track) => (track.marker = value));
134
- this._outboundVideoTracks.forEach((track) => (track.marker = value));
135
- this._dataChannels.forEach((channel) => (channel.marker = value));
136
- this.ICE.marker = value;
148
+ get certificates() {
149
+ return [...this.observedCertificates.values()];
137
150
  }
138
- addEventReport(params) {
139
- var _a;
140
- this.reports.addCallEventReport(Object.assign(Object.assign({}, params), { serviceId: this.serviceId, mediaUnitId: this.mediaUnitId, roomId: this.roomId, callId: this.callId, clientId: this.clientId, userId: this.client.userId, peerConnectionId: this.peerConnectionId, marker: this.client.marker, timestamp: (_a = params.timestamp) !== null && _a !== void 0 ? _a : Date.now() }));
151
+ get selectedIceCandidatePairs() {
152
+ return this.iceTransports.map((iceTransport) => iceTransport.getSelectedCandidatePair())
153
+ .filter((pair) => pair !== undefined);
141
154
  }
142
- get closed() {
143
- return this._closed;
155
+ get selectedIceCandiadtePairForTurn() {
156
+ return this.selectedIceCandidatePairs
157
+ .filter((pair) => pair.getLocalCandidate()?.candidateType === 'relay' &&
158
+ pair.getRemoteCandidate()?.url?.startsWith('turn:'));
144
159
  }
145
160
  close() {
146
- if (this._closed)
161
+ if (this.closed)
147
162
  return;
148
- this._closed = true;
149
- Array.from(this._inboundAudioTracks.values()).forEach((track) => track.close());
150
- Array.from(this._inboundVideoTracks.values()).forEach((track) => track.close());
151
- Array.from(this._outboundAudioTracks.values()).forEach((track) => {
152
- var _a;
153
- this.client.call.sfuStreamIdToOutboundAudioTrack.delete((_a = track.sfuStreamId) !== null && _a !== void 0 ? _a : '');
154
- track.close();
155
- });
156
- Array.from(this._outboundVideoTracks.values()).forEach((track) => {
157
- var _a;
158
- this.client.call.sfuStreamIdToOutboundVideoTrack.delete((_a = track.sfuStreamId) !== null && _a !== void 0 ? _a : '');
159
- track.close();
160
- });
163
+ this.closed = true;
164
+ this.observedCertificates.clear();
165
+ this.observedCodecs.clear();
166
+ this.observedDataChannels.clear();
167
+ this.observedIceCandidates.clear();
168
+ this.observedIceCandidatesPair.clear();
169
+ this.observedIceTransports.clear();
170
+ this.observedInboundRtps.clear();
171
+ this.observedInboundTracks.clear();
172
+ this.observedMediaPlayouts.clear();
173
+ this.observedMediaSources.clear();
174
+ this.observedOutboundRtps.clear();
175
+ this.observedOutboundTracks.clear();
176
+ this.observedPeerConnectionTransports.clear();
177
+ this.observedRemoteInboundRtps.clear();
178
+ this.observedRemoteOutboundRtps.clear();
179
+ this.client.call.observer.observedTURN.removePeerConnection(this);
180
+ if (!this.closedAt)
181
+ this.closedAt = Date.now();
161
182
  this.emit('close');
162
183
  }
163
- getTrack(trackId) {
164
- var _a, _b, _c;
165
- return (_c = (_b = (_a = this._inboundAudioTracks.get(trackId)) !== null && _a !== void 0 ? _a : this._inboundVideoTracks.get(trackId)) !== null && _b !== void 0 ? _b : this._outboundAudioTracks.get(trackId)) !== null && _c !== void 0 ? _c : this._outboundVideoTracks.get(trackId);
166
- }
167
- resetMetrics() {
184
+ accept(sample) {
185
+ if (this.closed)
186
+ return;
187
+ this._visited = true;
188
+ this.availableIncomingBitrate = 0;
189
+ this.availableOutgoingBitrate = 0;
168
190
  this.deltaInboundPacketsLost = 0;
169
191
  this.deltaInboundPacketsReceived = 0;
170
192
  this.deltaOutboundPacketsSent = 0;
@@ -178,244 +200,511 @@ class ObservedPeerConnection extends events_1.EventEmitter {
178
200
  this.deltaReceivedVideoPackets = 0;
179
201
  this.deltaSentAudioBytes = 0;
180
202
  this.deltaSentVideoBytes = 0;
203
+ this.deltaTransportReceivedBytes = 0;
204
+ this.deltaTransportSentBytes = 0;
181
205
  this.sendingAudioBitrate = 0;
182
206
  this.sendingVideoBitrate = 0;
183
207
  this.receivingAudioBitrate = 0;
184
208
  this.receivingVideoBitrate = 0;
185
- this.ICE.resetMetrics();
186
- }
187
- update(sample, timestamp) {
188
- if (this._closed)
189
- return;
190
- if (sample.peerConnectionId !== this._model.peerConnectionId)
191
- throw new Error(`TransportId mismatch. PeerConnectionId: ${this._model.peerConnectionId} TransportId: ${sample.transportId}`);
192
- this._sample = sample;
193
- if (this._model.label !== sample.label) {
194
- this._model.label = sample.label;
195
- }
196
209
  const now = Date.now();
197
- const report = Object.assign(Object.assign({ serviceId: this.client.call.serviceId, roomId: this.client.call.roomId, callId: this.client.call.callId, clientId: this.client.clientId, userId: this.client.userId, mediaUnitId: this.client.mediaUnitId }, sample), { timestamp, sampleSeq: -1, marker: this.marker });
198
- this.reports.addPeerConnectionTransportReports(report);
199
- this._elapsedTimeSinceLastUpdate = now - this._updated;
200
- this.visited = true;
201
- this._updated = now;
202
- this._statsTimestamp = timestamp;
203
- this.emit('update', {
204
- elapsedTimeInMs: this._elapsedTimeSinceLastUpdate,
205
- });
206
- }
207
- createInboundAudioTrack(config) {
208
- if (this._closed)
209
- throw new Error(`PeerConnection ${this.peerConnectionId} is closed`);
210
- const result = new ObservedInboundAudioTrack_1.ObservedInboundAudioTrack(config, this);
211
- result.on('close', () => {
212
- this._inboundAudioTracks.delete(result.trackId);
213
- });
214
- this._inboundAudioTracks.set(result.trackId, result);
215
- this.emit('newinboudaudiotrack', result);
216
- return result;
217
- }
218
- createInboundVideoTrack(config) {
219
- if (this._closed)
220
- throw new Error(`PeerConnection ${this.peerConnectionId} is closed`);
221
- const result = new ObservedInboundVideoTrack_1.ObservedInboundVideoTrack(config, this);
222
- result.on('close', () => {
223
- this._inboundVideoTracks.delete(result.trackId);
224
- });
225
- this._inboundVideoTracks.set(result.trackId, result);
226
- this.emit('newinboudvideotrack', result);
227
- return result;
228
- }
229
- createOutboundAudioTrack(config) {
230
- if (this._closed)
231
- throw new Error(`PeerConnection ${this.peerConnectionId} is closed`);
232
- const result = new ObservedOutboundAudioTrack_1.ObservedOutboundAudioTrack(config, this);
233
- result.on('close', () => {
234
- this._outboundAudioTracks.delete(result.trackId);
235
- });
236
- this._outboundAudioTracks.set(result.trackId, result);
237
- this.emit('newoutboundaudiotrack', result);
238
- return result;
239
- }
240
- createOutboundVideoTrack(config) {
241
- if (this._closed)
242
- throw new Error(`PeerConnection ${this.peerConnectionId} is closed`);
243
- const result = new ObservedOutboundVideoTrack_1.ObservedOutboundVideoTrack(config, this);
244
- result.on('close', () => {
245
- this._outboundVideoTracks.delete(result.trackId);
246
- });
247
- this._outboundVideoTracks.set(result.trackId, result);
248
- this.emit('newoutboundvideotrack', result);
249
- return result;
250
- }
251
- createDataChannel(channelId) {
252
- if (this._closed)
253
- throw new Error(`PeerConnection ${this.peerConnectionId} is closed`);
254
- const result = new ObservedDataChannel_1.ObservedDataChannel({
255
- channelId,
256
- }, this);
257
- result.on('close', () => {
258
- this._dataChannels.delete(result.channelId);
259
- });
260
- this._dataChannels.set(result.channelId, result);
261
- this.emit('newdatachannel', result);
262
- return result;
263
- }
264
- updateMetrics() {
265
- var _a;
266
- let sumRttInMs = 0;
267
- let sumJitter = 0;
268
- const trackScores = [];
269
- this._inboundAudioTracks.forEach((track) => {
270
- var _a, _b;
271
- track.updateMetrics();
272
- this.deltaInboundPacketsLost += track.deltaLostPackets;
273
- this.deltaInboundPacketsReceived += track.deltaReceivedPackets;
274
- this.deltaInboundReceivedBytes += track.deltaBytesReceived;
275
- this.deltaReceivedAudioBytes += track.deltaBytesReceived;
276
- this.deltaReceivedAudioPackets += track.deltaReceivedPackets;
277
- this.receivingAudioBitrate += track.bitrate;
278
- sumRttInMs += ((_a = track.rttInMs) !== null && _a !== void 0 ? _a : 0);
279
- sumJitter += ((_b = track.jitter) !== null && _b !== void 0 ? _b : 0);
280
- track.score && trackScores.push(track.score);
281
- });
282
- this._inboundVideoTracks.forEach((track) => {
283
- var _a, _b;
284
- track.updateMetrics();
285
- this.deltaInboundPacketsLost += track.deltaLostPackets;
286
- this.deltaInboundPacketsReceived += track.deltaReceivedPackets;
287
- this.deltaInboundReceivedBytes += track.deltaBytesReceived;
288
- this.deltaReceivedVideoBytes += track.deltaBytesReceived;
289
- this.deltaReceivedVideoPackets += track.deltaReceivedPackets;
290
- this.receivingVideoBitrate += track.bitrate;
291
- sumRttInMs += ((_a = track.rttInMs) !== null && _a !== void 0 ? _a : 0);
292
- sumJitter += ((_b = track.jitter) !== null && _b !== void 0 ? _b : 0);
293
- track.score && trackScores.push(track.score);
294
- });
295
- this._outboundAudioTracks.forEach((track) => {
296
- var _a, _b;
297
- track.updateMetrics();
298
- this.deltaOutboundPacketsSent += track.deltaSentPackets;
299
- this.deltaOutboundSentBytes += track.deltaSentBytes;
300
- this.deltaSentAudioBytes += track.deltaSentBytes;
301
- this.deltaSentAudioBytes += track.deltaSentPackets;
302
- this.sendingAudioBitrate += track.bitrate;
303
- sumRttInMs += ((_a = track.rttInMs) !== null && _a !== void 0 ? _a : 0);
304
- sumJitter += ((_b = track.jitter) !== null && _b !== void 0 ? _b : 0);
305
- track.score && trackScores.push(track.score);
306
- });
307
- this._outboundVideoTracks.forEach((track) => {
308
- var _a, _b;
309
- track.updateMetrics();
310
- this.deltaOutboundPacketsSent += track.deltaSentPackets;
311
- this.deltaOutboundSentBytes += track.deltaSentBytes;
312
- this.deltaSentVideoBytes += track.deltaSentBytes;
313
- this.deltaSentVideoBytes += track.deltaSentPackets;
314
- this.sendingVideoBitrate += track.bitrate;
315
- sumRttInMs += ((_a = track.rttInMs) !== null && _a !== void 0 ? _a : 0);
316
- sumJitter += ((_b = track.jitter) !== null && _b !== void 0 ? _b : 0);
317
- track.score && trackScores.push(track.score);
318
- });
319
- this._dataChannels.forEach((channel) => {
320
- this.deltaDataChannelBytesSent += channel.deltaBytesSent;
321
- this.deltaDataChannelBytesReceived += channel.deltaBytesReceived;
322
- });
323
- const iceRttInMs = (_a = this.ICE.stats) === null || _a === void 0 ? void 0 : _a.currentRoundTripTime;
324
- let nrOfBelongings = this._inboundAudioTracks.size + this._inboundVideoTracks.size + this._outboundAudioTracks.size + this._outboundVideoTracks.size;
325
- this.avgJitter = 0 < nrOfBelongings ? sumJitter / nrOfBelongings : undefined;
326
- if (iceRttInMs) {
327
- sumRttInMs += iceRttInMs;
328
- nrOfBelongings += 1;
329
- }
330
- this.avgRttInMs = 0 < nrOfBelongings ? sumRttInMs / nrOfBelongings : undefined;
331
- this.totalDataChannelBytesReceived += this.deltaDataChannelBytesReceived;
332
- this.totalDataChannelBytesSent += this.deltaDataChannelBytesSent;
210
+ const elapsedTimeInMs = now - this.updated;
211
+ const elapsedTimeInSec = elapsedTimeInMs / 1000;
212
+ const rttMeasurementsInSec = [];
213
+ const jitterMeasurements = [];
214
+ if (sample.certificates) {
215
+ for (const certificate of sample.certificates) {
216
+ this._updateCertificateStats(certificate);
217
+ }
218
+ }
219
+ if (sample.codecs) {
220
+ for (const codec of sample.codecs) {
221
+ this._updateCodecStats(codec);
222
+ }
223
+ }
224
+ if (sample.dataChannels) {
225
+ for (const dataChannel of sample.dataChannels) {
226
+ const observedDataChannel = this._updateDataChannelStats(dataChannel);
227
+ if (!observedDataChannel)
228
+ continue;
229
+ this.deltaDataChannelBytesSent += observedDataChannel.deltaBytesSent;
230
+ this.deltaDataChannelBytesReceived += observedDataChannel.deltaBytesReceived;
231
+ this.deltaDataChannelMessagesSent += observedDataChannel.deltaMessagesSent;
232
+ this.deltaDataChannelMessagesReceived += observedDataChannel.deltaMessagesReceived;
233
+ }
234
+ }
235
+ if (sample.iceCandidates) {
236
+ for (const iceCandidate of sample.iceCandidates) {
237
+ this._updateIceCandidateStats(iceCandidate);
238
+ }
239
+ }
240
+ if (sample.iceCandidatePairs) {
241
+ for (const iceCandidatePair of sample.iceCandidatePairs) {
242
+ const observedCandidatePair = this._updateIceCandidatePairStats(iceCandidatePair);
243
+ if (!observedCandidatePair)
244
+ continue;
245
+ if (observedCandidatePair.currentRoundTripTime) {
246
+ rttMeasurementsInSec.push(observedCandidatePair.currentRoundTripTime);
247
+ }
248
+ if (observedCandidatePair.availableIncomingBitrate) {
249
+ this.availableIncomingBitrate += observedCandidatePair.availableIncomingBitrate;
250
+ }
251
+ if (observedCandidatePair.availableOutgoingBitrate) {
252
+ this.availableOutgoingBitrate += observedCandidatePair.availableOutgoingBitrate;
253
+ }
254
+ }
255
+ }
256
+ if (sample.iceTransports) {
257
+ for (const iceTransport of sample.iceTransports) {
258
+ const observedIceTransport = this._updateIceTransportStats(iceTransport);
259
+ if (!observedIceTransport)
260
+ return;
261
+ observedIceTransport.bytesReceived;
262
+ }
263
+ }
264
+ if (sample.inboundRtps) {
265
+ for (const inboundRtp of sample.inboundRtps) {
266
+ const observedInboundRtp = this._updateInboundRtpStats(inboundRtp);
267
+ if (!observedInboundRtp)
268
+ continue;
269
+ this.deltaInboundPacketsLost += observedInboundRtp.deltaLostPackets;
270
+ this.deltaInboundPacketsReceived += observedInboundRtp.deltaReceivedPackets;
271
+ this.deltaInboundReceivedBytes += observedInboundRtp.deltaBytesReceived;
272
+ switch (inboundRtp.kind) {
273
+ case 'audio':
274
+ this.deltaReceivedAudioBytes += observedInboundRtp.deltaBytesReceived;
275
+ this.deltaReceivedAudioPackets += observedInboundRtp.deltaReceivedPackets;
276
+ break;
277
+ case 'video':
278
+ this.deltaReceivedVideoBytes += observedInboundRtp.deltaBytesReceived;
279
+ this.deltaReceivedVideoPackets += observedInboundRtp.deltaReceivedPackets;
280
+ break;
281
+ }
282
+ if (observedInboundRtp.jitter) {
283
+ jitterMeasurements.push(observedInboundRtp.jitter);
284
+ }
285
+ }
286
+ }
287
+ if (sample.mediaPlayouts) {
288
+ for (const mediaPlayout of sample.mediaPlayouts) {
289
+ this._updateMediaPlayoutStats(mediaPlayout);
290
+ }
291
+ }
292
+ if (sample.mediaSources) {
293
+ for (const mediaSource of sample.mediaSources) {
294
+ this._updateMediaSourceStats(mediaSource);
295
+ }
296
+ }
297
+ if (sample.outboundRtps) {
298
+ for (const outboundRtp of sample.outboundRtps) {
299
+ const observedOutboundRtp = this._updateOutboundRtpStats(outboundRtp);
300
+ if (!observedOutboundRtp)
301
+ continue;
302
+ this.deltaOutboundPacketsSent += observedOutboundRtp.deltaPacketsSent ?? 0;
303
+ this.deltaOutboundSentBytes += observedOutboundRtp.deltaBytesSent ?? 0;
304
+ switch (outboundRtp.kind) {
305
+ case 'audio':
306
+ this.deltaSentAudioBytes += observedOutboundRtp.deltaBytesSent;
307
+ this.deltaSentAudioBytes += observedOutboundRtp.deltaPacketsSent;
308
+ break;
309
+ case 'video':
310
+ this.deltaSentVideoBytes += observedOutboundRtp.deltaBytesSent;
311
+ this.deltaSentVideoBytes += observedOutboundRtp.deltaPacketsSent;
312
+ break;
313
+ }
314
+ }
315
+ }
316
+ if (sample.peerConnectionTransports) {
317
+ for (const peerConnectionTransport of sample.peerConnectionTransports) {
318
+ const observedTransport = this._updatePeerConnectionTransportStats(peerConnectionTransport);
319
+ if (!observedTransport)
320
+ continue;
321
+ }
322
+ }
323
+ if (sample.remoteInboundRtps) {
324
+ for (const remoteInboundRtp of sample.remoteInboundRtps) {
325
+ const observedRemoteInboundRtp = this._updateRemoteInboundRtpStats(remoteInboundRtp);
326
+ if (!observedRemoteInboundRtp)
327
+ continue;
328
+ if (observedRemoteInboundRtp.roundTripTime) {
329
+ rttMeasurementsInSec.push(observedRemoteInboundRtp.roundTripTime);
330
+ }
331
+ }
332
+ }
333
+ if (sample.remoteOutboundRtps) {
334
+ for (const remoteOutboundRtp of sample.remoteOutboundRtps) {
335
+ const observedRemoteOutboundRtp = this._updateRemoteOutboundRtpStats(remoteOutboundRtp);
336
+ if (!observedRemoteOutboundRtp)
337
+ continue;
338
+ }
339
+ }
340
+ // tracks should be updated last as they are derived stats
341
+ // and depends on base stats but they all received in the sample sample
342
+ if (sample.inboundTracks) {
343
+ for (const inboundTrack of sample.inboundTracks) {
344
+ this._updateInboundTrackSample(inboundTrack);
345
+ }
346
+ }
347
+ if (sample.outboundTracks) {
348
+ for (const outboundTrack of sample.outboundTracks) {
349
+ this._updateOutboundTrackSample(outboundTrack);
350
+ }
351
+ }
333
352
  this.totalInboundPacketsLost += this.deltaInboundPacketsLost;
334
353
  this.totalInboundPacketsReceived += this.deltaInboundPacketsReceived;
335
354
  this.totalOutboundPacketsSent += this.deltaOutboundPacketsSent;
336
- this.totalSentAudioBytes += this.deltaSentAudioBytes;
337
- this.totalSentVideoBytes += this.deltaSentVideoBytes;
355
+ this.totalDataChannelBytesSent += this.deltaDataChannelBytesSent;
356
+ this.totalDataChannelBytesReceived += this.deltaDataChannelBytesReceived;
357
+ this.totalDataChannelMessagesSent += this.deltaDataChannelMessagesSent;
358
+ this.totalDataChannelMessagesReceived += this.deltaDataChannelMessagesReceived;
338
359
  this.totalReceivedAudioBytes += this.deltaReceivedAudioBytes;
339
360
  this.totalReceivedVideoBytes += this.deltaReceivedVideoBytes;
361
+ this.totalSentAudioBytes += this.deltaSentAudioBytes;
362
+ this.totalSentVideoBytes += this.deltaSentVideoBytes;
340
363
  this.totalReceivedAudioPacktes += this.deltaReceivedAudioPackets;
341
364
  this.totalReceivedVideoPackets += this.deltaReceivedVideoPackets;
342
365
  this.totalSentAudioPackets += this.deltaSentAudioBytes;
343
366
  this.totalSentVideoPackets += this.deltaSentVideoBytes;
344
- if (this._elapsedTimeSinceLastUpdate && 0 < this._elapsedTimeSinceLastUpdate) {
345
- this.sendingPacketsPerSecond = this.deltaOutboundPacketsSent / (this._elapsedTimeSinceLastUpdate / 1000);
346
- this.receivingPacketsPerSecond = this.deltaInboundPacketsReceived / (this._elapsedTimeSinceLastUpdate / 1000);
367
+ this.receivingPacketsPerSecond = this.deltaInboundPacketsReceived / elapsedTimeInSec;
368
+ this.sendingPacketsPerSecond = this.deltaOutboundPacketsSent / elapsedTimeInSec;
369
+ this.sendingAudioBitrate = (this.deltaSentAudioBytes * 8) / elapsedTimeInSec;
370
+ this.sendingVideoBitrate = (this.deltaSentVideoBytes * 8) / elapsedTimeInSec;
371
+ this.receivingAudioBitrate = (this.deltaReceivedAudioBytes * 8) / elapsedTimeInSec;
372
+ this.receivingVideoBitrate = (this.deltaReceivedVideoBytes * 8) / elapsedTimeInSec;
373
+ if (rttMeasurementsInSec.length > 0) {
374
+ this.currentRttInMs = (0, utils_1.getMedian)(rttMeasurementsInSec, false) * 1000;
347
375
  }
348
376
  else {
349
- this.sendingPacketsPerSecond = 0;
350
- this.receivingPacketsPerSecond = 0;
351
- }
352
- // calculate quality score
353
- this._updateQualityScore(trackScores);
354
- }
355
- _updateQualityScore(trackScores) {
356
- var _a, _b, _c, _d, _e, _f, _g;
357
- // Packet Jitter measured in seconds
358
- // we use RTT and lost packets to calculate the base score for the connection
359
- const rttInMs = (_a = this.avgRttInMs) !== null && _a !== void 0 ? _a : 0;
360
- const latencyFactor = rttInMs < 150 ? 1.0 : (0, CalculatedScore_1.getRttScore)(rttInMs);
361
- const totalPackets = Math.max(1, ((_b = this.totalInboundPacketsReceived) !== null && _b !== void 0 ? _b : 0) + ((_c = this.totalOutboundPacketsSent) !== null && _c !== void 0 ? _c : 0));
362
- const lostPackets = ((_d = this.totalInboundPacketsLost) !== null && _d !== void 0 ? _d : 0) + ((_e = this.deltaOutboundPacketsSent) !== null && _e !== void 0 ? _e : 0);
363
- const deliveryFactor = 1.0 - ((lostPackets) / (lostPackets + totalPackets));
364
- // let's push the actual stability score
365
- const stabilityScore = Math.pow(((latencyFactor * 0.5) + (deliveryFactor * 0.5)), 2);
366
- this._stabilityScores.push(stabilityScore);
367
- if (10 < this._stabilityScores.length) {
368
- this._stabilityScores.shift();
369
- }
370
- else if (this._stabilityScores.length < 5) {
371
- return;
377
+ this.currentRttInMs = undefined;
378
+ }
379
+ if (jitterMeasurements.length > 0) {
380
+ this.currentJitter = (0, utils_1.getMedian)(jitterMeasurements, false);
381
+ }
382
+ else {
383
+ this.currentJitter = undefined;
384
+ }
385
+ const wasUsingTURN = this.usingTURN;
386
+ const selectedIceCandidatePairs = this.selectedIceCandidatePairs;
387
+ const selectedCandidatePairForTurn = [];
388
+ this.usingTCP = false;
389
+ this.usingTURN = false;
390
+ for (const selectedCandidatePair of selectedIceCandidatePairs) {
391
+ if (selectedCandidatePair.getLocalCandidate()?.protocol === 'tcp') {
392
+ this.usingTCP = true;
393
+ }
394
+ if (selectedCandidatePair.getLocalCandidate()?.candidateType === 'relay' && selectedCandidatePair.getRemoteCandidate()?.url?.startsWith('turn:')) {
395
+ selectedCandidatePairForTurn.push(selectedCandidatePair);
396
+ this.usingTURN = true;
397
+ }
398
+ this.deltaTransportReceivedBytes += selectedCandidatePair.deltaBytesReceived;
399
+ this.deltaTransportSentBytes += selectedCandidatePair.deltaBytesSent;
400
+ }
401
+ if (this.usingTURN) {
402
+ if (!this.observedTurnServer) {
403
+ this.observedTurnServer = this.client.call.observer.observedTURN.addPeerConnection(this);
404
+ }
405
+ this.observedTurnServer?.updateTurnUsage(...selectedCandidatePairForTurn);
406
+ }
407
+ else if (wasUsingTURN) {
408
+ if (!this.usingTURN) {
409
+ this.client.call.observer.observedTURN.removePeerConnection(this);
410
+ }
411
+ }
412
+ this.calculatedScore.value = sample.score;
413
+ this.updated = now;
414
+ this._checkVisited();
415
+ this.emit('update');
416
+ }
417
+ _checkVisited() {
418
+ for (const certificate of [...this.observedCertificates.values()]) {
419
+ if (certificate.visited)
420
+ continue;
421
+ this.observedCertificates.delete(certificate.id);
422
+ }
423
+ for (const codec of [...this.observedCodecs.values()]) {
424
+ if (codec.visited)
425
+ continue;
426
+ this.observedCodecs.delete(codec.id);
427
+ this.emit('removed-codec', codec);
428
+ }
429
+ for (const dataChannel of [...this.observedDataChannels.values()]) {
430
+ if (dataChannel.visited)
431
+ continue;
432
+ this.observedDataChannels.delete(dataChannel.id);
433
+ this.emit('removed-data-channel', dataChannel);
434
+ }
435
+ for (const iceCandidate of [...this.observedIceCandidates.values()]) {
436
+ if (iceCandidate.visited)
437
+ continue;
438
+ this.observedIceCandidates.delete(iceCandidate.id);
439
+ this.emit('removed-ice-candidate', iceCandidate);
440
+ }
441
+ for (const iceCandidatePair of [...this.observedIceCandidatesPair.values()]) {
442
+ if (iceCandidatePair.visited)
443
+ continue;
444
+ this.observedIceCandidatesPair.delete(iceCandidatePair.id);
445
+ this.emit('removed-ice-candidate-pair', iceCandidatePair);
446
+ }
447
+ for (const iceTransport of [...this.observedIceTransports.values()]) {
448
+ if (iceTransport.visited)
449
+ continue;
450
+ this.observedIceTransports.delete(iceTransport.id);
451
+ this.emit('removed-ice-transport', iceTransport);
452
+ }
453
+ for (const inboundRtp of [...this.observedInboundRtps.values()]) {
454
+ if (inboundRtp.visited)
455
+ continue;
456
+ this.observedInboundRtps.delete(inboundRtp.ssrc);
457
+ this.emit('removed-inbound-rtp', inboundRtp);
458
+ }
459
+ for (const inboundTrack of [...this.observedInboundTracks.values()]) {
460
+ if (inboundTrack.visited)
461
+ continue;
462
+ this.observedInboundTracks.delete(inboundTrack.id);
463
+ this.emit('removed-inbound-track', inboundTrack);
464
+ }
465
+ for (const mediaPlayout of [...this.observedMediaPlayouts.values()]) {
466
+ if (mediaPlayout.visited)
467
+ continue;
468
+ this.observedMediaPlayouts.delete(mediaPlayout.id);
469
+ this.emit('removed-media-playout', mediaPlayout);
470
+ }
471
+ for (const mediaSource of [...this.observedMediaSources.values()]) {
472
+ if (mediaSource.visited)
473
+ continue;
474
+ this.observedMediaSources.delete(mediaSource.id);
475
+ this.emit('removed-media-source', mediaSource);
476
+ }
477
+ for (const outboundRtp of [...this.observedOutboundRtps.values()]) {
478
+ if (outboundRtp.visited)
479
+ continue;
480
+ this.observedOutboundRtps.delete(outboundRtp.ssrc);
481
+ this.emit('removed-outbound-rtp', outboundRtp);
482
+ }
483
+ for (const outboundTrack of [...this.observedOutboundTracks.values()]) {
484
+ if (outboundTrack.visited)
485
+ continue;
486
+ this.observedOutboundTracks.delete(outboundTrack.id);
487
+ this.emit('removed-outbound-track', outboundTrack);
488
+ }
489
+ for (const peerConnectionTransport of [...this.observedPeerConnectionTransports.values()]) {
490
+ if (peerConnectionTransport.visited)
491
+ continue;
492
+ this.observedPeerConnectionTransports.delete(peerConnectionTransport.id);
493
+ this.emit('removed-peer-connection-transport', peerConnectionTransport);
494
+ }
495
+ for (const remoteInboundRtp of [...this.observedRemoteInboundRtps.values()]) {
496
+ if (remoteInboundRtp.visited)
497
+ continue;
498
+ this.observedRemoteInboundRtps.delete(remoteInboundRtp.ssrc);
499
+ this.emit('removed-remote-inbound-rtp', remoteInboundRtp);
500
+ }
501
+ for (const remoteOutboundRtp of [...this.observedRemoteOutboundRtps.values()]) {
502
+ if (remoteOutboundRtp.visited)
503
+ continue;
504
+ this.observedRemoteOutboundRtps.delete(remoteOutboundRtp.ssrc);
505
+ this.emit('removed-remote-outbound-rtp', remoteOutboundRtp);
506
+ }
507
+ }
508
+ _updateCertificateStats(stats) {
509
+ let observedCertificate = this.observedCertificates.get(stats.id);
510
+ if (!observedCertificate) {
511
+ if (!stats.timestamp || !stats.id || !stats.fingerprint) {
512
+ return logger.warn(`ObservedPeerConnection received an invalid CertificateStats (missing timestamp OR id OR fingerprint field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`, stats);
513
+ }
514
+ observedCertificate = new ObservedCertificate_1.ObservedCertificate(stats.timestamp, stats.id, this);
515
+ this.observedCertificates.set(stats.id, observedCertificate);
516
+ this.emit('added-certificate', observedCertificate);
517
+ }
518
+ observedCertificate.update(stats);
519
+ return observedCertificate;
520
+ }
521
+ _updateCodecStats(stats) {
522
+ let observedCodec = this.observedCodecs.get(stats.id);
523
+ if (!observedCodec) {
524
+ if (!stats.timestamp || !stats.id || !stats.mimeType) {
525
+ return logger.warn(`ObservedPeerConnection received an invalid CodecStats (missing timestamp OR id OR mimeType field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`, stats);
526
+ }
527
+ observedCodec = new ObservedCodec_1.ObservedCodec(stats.timestamp, stats.id, stats.mimeType, this);
528
+ this.observedCodecs.set(stats.id, observedCodec);
529
+ this.emit('added-codec', observedCodec);
530
+ }
531
+ observedCodec.update(stats);
532
+ return observedCodec;
533
+ }
534
+ _updateDataChannelStats(stats) {
535
+ let observedDataChannel = this.observedDataChannels.get(stats.id);
536
+ if (!observedDataChannel) {
537
+ if (!stats.timestamp || !stats.id) {
538
+ return logger.warn(`ObservedPeerConnection received an invalid DataChannelStats (missing timestamp OR id field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`, stats);
539
+ }
540
+ observedDataChannel = new ObservedDataChannel_1.ObservedDataChannel(stats.timestamp, stats.id, this);
541
+ this.observedDataChannels.set(stats.id, observedDataChannel);
542
+ this.emit('added-data-channel', observedDataChannel);
543
+ }
544
+ observedDataChannel.update(stats);
545
+ return observedDataChannel;
546
+ }
547
+ _updateIceCandidateStats(stats) {
548
+ let observedIceCandidate = this.observedIceCandidates.get(stats.id);
549
+ if (!observedIceCandidate) {
550
+ if (!stats.timestamp || !stats.id) {
551
+ return logger.warn(`ObservedPeerConnection received an invalid IceCandidateStats (missing timestamp OR id field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`, stats);
552
+ }
553
+ observedIceCandidate = new ObservedIceCandidate_1.ObservedIceCandidate(stats.timestamp, stats.id, this);
554
+ this.observedIceCandidates.set(stats.id, observedIceCandidate);
555
+ this.emit('added-ice-candidate', observedIceCandidate);
556
+ }
557
+ observedIceCandidate.update(stats);
558
+ return observedIceCandidate;
559
+ }
560
+ _updateIceCandidatePairStats(stats) {
561
+ let observedIceCandidatePair = this.observedIceCandidatesPair.get(stats.id);
562
+ if (!observedIceCandidatePair) {
563
+ if (!stats.timestamp || !stats.id) {
564
+ return logger.warn(`ObservedPeerConnection received an invalid IceCandidateStats (missing timestamp OR id field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`, stats);
565
+ }
566
+ observedIceCandidatePair = new ObservedIceCandidatePair_1.ObservedIceCandidatePair(stats.timestamp, stats.id, this);
567
+ this.observedIceCandidatesPair.set(stats.id, observedIceCandidatePair);
568
+ this.emit('added-ice-candidate-pair', observedIceCandidatePair);
569
+ }
570
+ observedIceCandidatePair.update(stats);
571
+ return observedIceCandidatePair;
572
+ }
573
+ _updateIceTransportStats(stats) {
574
+ let observedIceTransport = this.observedIceTransports.get(stats.id);
575
+ if (!observedIceTransport) {
576
+ if (!stats.timestamp || !stats.id) {
577
+ return logger.warn(`ObservedPeerConnection received an invalid IceCandidateStats (missing timestamp OR id field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`, stats);
578
+ }
579
+ observedIceTransport = new ObservedIceTransport_1.ObservedIceTransport(stats.timestamp, stats.id, this);
580
+ this.observedIceTransports.set(stats.id, observedIceTransport);
581
+ this.emit('added-ice-transport', observedIceTransport);
582
+ }
583
+ observedIceTransport.update(stats);
584
+ return observedIceTransport;
585
+ }
586
+ _updateInboundRtpStats(stats) {
587
+ let observedInboundRtp = this.observedInboundRtps.get(stats.ssrc);
588
+ if (!observedInboundRtp) {
589
+ if (!stats.timestamp || !stats.id || !stats.ssrc || !stats.kind || !stats.trackIdentifier) {
590
+ return logger.warn(`ObservedPeerConnection received an invalid InboundRtpStats (missing timestamp OR id OR ssrc OR kind OR trackIdentifier field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`, stats);
591
+ }
592
+ observedInboundRtp = new ObservedInboundRtp_1.ObservedInboundRtp(stats.timestamp, stats.id, stats.ssrc, stats.kind, stats.trackIdentifier, this);
593
+ this.observedInboundRtps.set(stats.ssrc, observedInboundRtp);
594
+ this.emit('added-inbound-rtp', observedInboundRtp);
595
+ }
596
+ observedInboundRtp.update(stats);
597
+ return observedInboundRtp;
598
+ }
599
+ _updateInboundTrackSample(stats) {
600
+ let observedInboundTrack = this.observedInboundTracks.get(stats.id);
601
+ if (!observedInboundTrack) {
602
+ if (!stats.timestamp || !stats.id || !stats.kind) {
603
+ return logger.warn(`ObservedPeerConnection received an invalid InboundTrackSample (missing timestamp OR id OR kind field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`, stats);
604
+ }
605
+ const inboundRtp = [...this.observedInboundRtps.values()].find((inbRtp) => inbRtp.trackIdentifier === stats.id);
606
+ const mediaPlayout = inboundRtp ?
607
+ [...this.observedMediaPlayouts.values()].find((mp) => mp.id === inboundRtp.playoutId) : undefined;
608
+ observedInboundTrack = new ObservedInboundTrack_1.ObservedInboundTrack(stats.timestamp, stats.id, stats.kind, this, inboundRtp, mediaPlayout);
609
+ this.observedInboundTracks.set(stats.id, observedInboundTrack);
610
+ this.emit('added-inbound-track', observedInboundTrack);
611
+ }
612
+ observedInboundTrack.update(stats);
613
+ return observedInboundTrack;
614
+ }
615
+ _updateMediaPlayoutStats(stats) {
616
+ let observedMediaPlayout = this.observedMediaPlayouts.get(stats.id);
617
+ if (!observedMediaPlayout) {
618
+ if (!stats.timestamp || !stats.id || !stats.kind) {
619
+ return logger.warn(`ObservedPeerConnection received an invalid InboundRtpStats (missing timestamp OR id OR kind OR trackIdentifier field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`, stats);
620
+ }
621
+ observedMediaPlayout = new ObservedMediaPlayout_1.ObservedMediaPlayout(stats.timestamp, stats.id, stats.kind, this);
622
+ this.observedMediaPlayouts.set(stats.id, observedMediaPlayout);
623
+ this.emit('added-media-playout', observedMediaPlayout);
624
+ }
625
+ observedMediaPlayout.update(stats);
626
+ return observedMediaPlayout;
627
+ }
628
+ _updateMediaSourceStats(stats) {
629
+ let observedMediaSource = this.observedMediaSources.get(stats.id);
630
+ if (!observedMediaSource) {
631
+ if (!stats.timestamp || !stats.id || !stats.kind) {
632
+ return logger.warn(`ObservedPeerConnection received an invalid InboundRtpStats (missing timestamp OR id OR kind field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`, stats);
633
+ }
634
+ observedMediaSource = new ObservedMediaSource_1.ObservedMediaSource(stats.timestamp, stats.id, stats.kind, this);
635
+ this.observedMediaSources.set(stats.id, observedMediaSource);
636
+ this.emit('added-media-source', observedMediaSource);
637
+ }
638
+ observedMediaSource.update(stats);
639
+ return observedMediaSource;
640
+ }
641
+ _updateOutboundRtpStats(stats) {
642
+ let observedOutboundRtp = this.observedOutboundRtps.get(stats.ssrc);
643
+ if (!observedOutboundRtp) {
644
+ if (!stats.timestamp || !stats.id || !stats.ssrc || !stats.kind) {
645
+ return logger.warn(`ObservedPeerConnection received an invalid OutboundRtpStats (missing timestamp OR id OR ssrc OR kind field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`, stats);
646
+ }
647
+ observedOutboundRtp = new ObservedOutboundRtp_1.ObservedOutboundRtp(stats.timestamp, stats.id, stats.ssrc, stats.kind, this);
648
+ this.observedOutboundRtps.set(stats.ssrc, observedOutboundRtp);
649
+ this.emit('added-outbound-rtp', observedOutboundRtp);
650
+ }
651
+ observedOutboundRtp.update(stats);
652
+ return observedOutboundRtp;
653
+ }
654
+ _updateOutboundTrackSample(stats) {
655
+ let observedOutboundTrack = this.observedOutboundTracks.get(stats.id);
656
+ if (!observedOutboundTrack) {
657
+ if (!stats.timestamp || !stats.id || !stats.kind) {
658
+ return logger.warn(`ObservedPeerConnection received an invalid OutboundTrackSample (missing timestamp OR id OR kind field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`, stats);
659
+ }
660
+ const observedMediaSource = [...this.observedMediaSources.values()].find((mediaSource) => mediaSource.trackIdentifier === stats.id);
661
+ const outboundRtps = observedMediaSource
662
+ ? [...this.observedOutboundRtps.values()].filter((outboundRtp) => outboundRtp.mediaSourceId === observedMediaSource?.id) : undefined;
663
+ observedOutboundTrack = new ObservedOutboundTrack_1.ObservedOutboundTrack(stats.timestamp, stats.id, stats.kind, this, outboundRtps, observedMediaSource);
664
+ this.observedOutboundTracks.set(stats.id, observedOutboundTrack);
665
+ this.emit('added-outbound-track', observedOutboundTrack);
666
+ }
667
+ observedOutboundTrack.update(stats);
668
+ return observedOutboundTrack;
669
+ }
670
+ _updatePeerConnectionTransportStats(stats) {
671
+ let observedPeerConnectionTransport = this.observedPeerConnectionTransports.get(stats.id);
672
+ if (!observedPeerConnectionTransport) {
673
+ if (!stats.timestamp || !stats.id) {
674
+ return logger.warn(`ObservedPeerConnection received an invalid PeerConnectionTransportStats (missing timestamp OR id field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`, stats);
675
+ }
676
+ observedPeerConnectionTransport = new ObservedPeerConnectionTransport_1.ObservedPeerConnectionTransport(stats.timestamp, stats.id, this);
677
+ this.observedPeerConnectionTransports.set(stats.id, observedPeerConnectionTransport);
678
+ this.emit('added-peer-connection-transport', observedPeerConnectionTransport);
679
+ }
680
+ observedPeerConnectionTransport.update(stats);
681
+ return observedPeerConnectionTransport;
682
+ }
683
+ _updateRemoteInboundRtpStats(stats) {
684
+ let observedRemoteInboundRtp = this.observedRemoteInboundRtps.get(stats.ssrc);
685
+ if (!observedRemoteInboundRtp) {
686
+ if (!stats.timestamp || !stats.id || !stats.ssrc || !stats.kind) {
687
+ return logger.warn(`ObservedPeerConnection received an invalid RemoteInboundRtpStats (missing timestamp OR id OR ssrc OR kind field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`, stats);
688
+ }
689
+ observedRemoteInboundRtp = new ObservedRemoteInboundRtp_1.ObservedRemoteInboundRtp(stats.timestamp, stats.id, stats.ssrc, stats.kind, this);
690
+ this.observedRemoteInboundRtps.set(stats.ssrc, observedRemoteInboundRtp);
691
+ this.emit('added-remote-inbound-rtp', observedRemoteInboundRtp);
692
+ }
693
+ observedRemoteInboundRtp.update(stats);
694
+ return observedRemoteInboundRtp;
695
+ }
696
+ _updateRemoteOutboundRtpStats(stats) {
697
+ let observedRemoteOutboundRtp = this.observedRemoteOutboundRtps.get(stats.ssrc);
698
+ if (!observedRemoteOutboundRtp) {
699
+ if (!stats.timestamp || !stats.id || !stats.ssrc || !stats.kind) {
700
+ return logger.warn(`ObservedPeerConnection received an invalid RemoteOutboundRtpStats (missing timestamp OR id OR ssrc OR kind field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`, stats);
701
+ }
702
+ observedRemoteOutboundRtp = new ObservedRemoteOutboundRtp_1.ObservedRemoteOutboundRtp(stats.timestamp, stats.id, stats.ssrc, stats.kind, this);
703
+ this.observedRemoteOutboundRtps.set(stats.ssrc, observedRemoteOutboundRtp);
704
+ this.emit('added-remote-outbound-rtp', observedRemoteOutboundRtp);
372
705
  }
373
- let counter = 0;
374
- let weight = 0;
375
- let totalScore = 0;
376
- for (const score of this._stabilityScores) {
377
- weight += 1;
378
- counter += weight;
379
- totalScore += weight * score;
380
- }
381
- const weightedStabilityScore = totalScore / counter;
382
- let sumTrackScores = 0;
383
- for (const trackScore of trackScores) {
384
- sumTrackScores += trackScore.score;
385
- }
386
- const avgTrackScores = sumTrackScores / trackScores.length;
387
- const score = {
388
- remarks: [{
389
- severity: 'none',
390
- text: `Peer Connection stability score: ${weightedStabilityScore}`,
391
- },
392
- {
393
- severity: 'none',
394
- text: `Avg. Track score: ${avgTrackScores}`,
395
- }],
396
- score: Math.round(((weightedStabilityScore + avgTrackScores) * 5 * 100)) / 100.0,
397
- timestamp: (_f = this._statsTimestamp) !== null && _f !== void 0 ? _f : Date.now(),
398
- };
399
- for (const pendingIssue of this.ωpendingIssuesForScores) {
400
- switch (pendingIssue.severity) {
401
- case 'critical':
402
- score.score = 0.0;
403
- break;
404
- case 'major':
405
- score.score *= 0.5;
406
- break;
407
- case 'minor':
408
- score.score *= 0.8;
409
- break;
410
- }
411
- score.remarks.push({
412
- severity: pendingIssue.severity,
413
- text: (_g = pendingIssue.description) !== null && _g !== void 0 ? _g : 'Issue occurred',
414
- });
415
- }
416
- this.ωpendingIssuesForScores = [];
417
- this.score = score;
418
- this.emit('score', score);
706
+ observedRemoteOutboundRtp.update(stats);
707
+ return observedRemoteOutboundRtp;
419
708
  }
420
709
  }
421
710
  exports.ObservedPeerConnection = ObservedPeerConnection;