@observertc/observer-js 0.42.9 → 1.0.1-24e14e5.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 (287) hide show
  1. package/.prettierrc +6 -6
  2. package/README.md +0 -104
  3. package/lib/ObservedCall.d.ts +61 -43
  4. package/lib/ObservedCall.d.ts.map +1 -1
  5. package/lib/ObservedCall.js +172 -108
  6. package/lib/ObservedCallSummary.d.ts +18 -0
  7. package/lib/ObservedCallSummary.d.ts.map +1 -0
  8. package/lib/ObservedCertificate.d.ts +19 -0
  9. package/lib/ObservedCertificate.d.ts.map +1 -0
  10. package/lib/ObservedCertificate.js +38 -0
  11. package/lib/ObservedClient.d.ts +79 -130
  12. package/lib/ObservedClient.d.ts.map +1 -1
  13. package/lib/ObservedClient.js +463 -744
  14. package/lib/ObservedClientEventMonitor.d.ts +89 -0
  15. package/lib/ObservedClientEventMonitor.d.ts.map +1 -0
  16. package/lib/ObservedClientEventMonitor.js +247 -0
  17. package/lib/ObservedClientSummary.d.ts +23 -0
  18. package/lib/ObservedClientSummary.d.ts.map +1 -0
  19. package/lib/ObservedClientSummary.js +2 -0
  20. package/lib/ObservedCodec.d.ts +22 -0
  21. package/lib/ObservedCodec.d.ts.map +1 -0
  22. package/lib/ObservedCodec.js +45 -0
  23. package/lib/ObservedDataChannel.d.ts +25 -69
  24. package/lib/ObservedDataChannel.d.ts.map +1 -1
  25. package/lib/ObservedDataChannel.js +69 -109
  26. package/lib/ObservedIceCandidate.d.ts +29 -0
  27. package/lib/ObservedIceCandidate.d.ts.map +1 -0
  28. package/lib/ObservedIceCandidate.js +59 -0
  29. package/lib/ObservedIceCandidatePair.d.ts +44 -0
  30. package/lib/ObservedIceCandidatePair.d.ts.map +1 -0
  31. package/lib/ObservedIceCandidatePair.js +111 -0
  32. package/lib/ObservedIceTransport.d.ts +36 -0
  33. package/lib/ObservedIceTransport.d.ts.map +1 -0
  34. package/lib/ObservedIceTransport.js +93 -0
  35. package/lib/ObservedInboundRtp.d.ts +92 -0
  36. package/lib/ObservedInboundRtp.d.ts.map +1 -0
  37. package/lib/ObservedInboundRtp.js +193 -0
  38. package/lib/ObservedInboundTrack.d.ts +31 -0
  39. package/lib/ObservedInboundTrack.d.ts.map +1 -0
  40. package/lib/ObservedInboundTrack.js +59 -0
  41. package/lib/ObservedMediaPlayout.d.ts +22 -0
  42. package/lib/ObservedMediaPlayout.d.ts.map +1 -0
  43. package/lib/ObservedMediaPlayout.js +42 -0
  44. package/lib/ObservedMediaSource.d.ts +28 -0
  45. package/lib/ObservedMediaSource.d.ts.map +1 -0
  46. package/lib/ObservedMediaSource.js +55 -0
  47. package/lib/ObservedOutboundRtp.d.ts +62 -0
  48. package/lib/ObservedOutboundRtp.d.ts.map +1 -0
  49. package/lib/ObservedOutboundRtp.js +144 -0
  50. package/lib/ObservedOutboundTrack.d.ts +31 -0
  51. package/lib/ObservedOutboundTrack.d.ts.map +1 -0
  52. package/lib/ObservedOutboundTrack.js +59 -0
  53. package/lib/ObservedPeerConnection.d.ts +132 -80
  54. package/lib/ObservedPeerConnection.d.ts.map +1 -1
  55. package/lib/ObservedPeerConnection.js +646 -357
  56. package/lib/ObservedPeerConnectionTransport.d.ts +17 -0
  57. package/lib/ObservedPeerConnectionTransport.d.ts.map +1 -0
  58. package/lib/ObservedPeerConnectionTransport.js +34 -0
  59. package/lib/ObservedRemoteInboundRtp.d.ts +30 -0
  60. package/lib/ObservedRemoteInboundRtp.d.ts.map +1 -0
  61. package/lib/ObservedRemoteInboundRtp.js +60 -0
  62. package/lib/ObservedRemoteOutboundRtp.d.ts +30 -0
  63. package/lib/ObservedRemoteOutboundRtp.d.ts.map +1 -0
  64. package/lib/ObservedRemoteOutboundRtp.js +60 -0
  65. package/lib/ObservedTURN.d.ts +31 -0
  66. package/lib/ObservedTURN.d.ts.map +1 -0
  67. package/lib/ObservedTURN.js +58 -0
  68. package/lib/ObservedTurnServer.d.ts +25 -0
  69. package/lib/ObservedTurnServer.d.ts.map +1 -0
  70. package/lib/ObservedTurnServer.js +59 -0
  71. package/lib/Observer.d.ts +44 -51
  72. package/lib/Observer.d.ts.map +1 -1
  73. package/lib/Observer.js +131 -226
  74. package/lib/ObserverEventMonitor.d.ts +104 -0
  75. package/lib/ObserverEventMonitor.d.ts.map +1 -0
  76. package/lib/ObserverEventMonitor.js +307 -0
  77. package/lib/ObserverSummary.d.ts +13 -0
  78. package/lib/ObserverSummary.d.ts.map +1 -0
  79. package/lib/ObserverSummary.js +2 -0
  80. package/lib/common/Middleware.d.ts +10 -1
  81. package/lib/common/Middleware.d.ts.map +1 -1
  82. package/lib/common/Middleware.js +55 -36
  83. package/lib/common/logger.d.ts +8 -4
  84. package/lib/common/logger.d.ts.map +1 -1
  85. package/lib/common/logger.js +44 -68
  86. package/lib/common/types.d.ts +0 -21
  87. package/lib/common/types.d.ts.map +1 -1
  88. package/lib/common/types.js +1 -0
  89. package/lib/common/utils.d.ts +3 -1
  90. package/lib/common/utils.d.ts.map +1 -1
  91. package/lib/common/utils.js +23 -3
  92. package/lib/detectors/Detector.d.ts +5 -0
  93. package/lib/detectors/Detector.d.ts.map +1 -0
  94. package/lib/detectors/Detector.js +3 -0
  95. package/lib/detectors/Detectors.d.ts +11 -0
  96. package/lib/detectors/Detectors.d.ts.map +1 -0
  97. package/lib/detectors/Detectors.js +34 -0
  98. package/lib/index.d.ts +25 -25
  99. package/lib/index.d.ts.map +1 -1
  100. package/lib/index.js +43 -41
  101. package/lib/monitors/TurnUsageMonitor.d.ts +0 -52
  102. package/lib/monitors/TurnUsageMonitor.d.ts.map +1 -1
  103. package/lib/monitors/TurnUsageMonitor.js +145 -120
  104. package/lib/schema/ClientEventTypes.d.ts +160 -0
  105. package/lib/schema/ClientEventTypes.d.ts.map +1 -0
  106. package/lib/schema/ClientEventTypes.js +38 -0
  107. package/lib/schema/ClientMetaTypes.d.ts +34 -0
  108. package/lib/schema/ClientMetaTypes.d.ts.map +1 -0
  109. package/lib/schema/ClientMetaTypes.js +16 -0
  110. package/lib/schema/ClientSample.d.ts +1333 -0
  111. package/lib/schema/ClientSample.d.ts.map +1 -0
  112. package/lib/schema/ClientSample.js +4 -0
  113. package/lib/scores/CalculatedScore.d.ts +6 -0
  114. package/lib/scores/CalculatedScore.d.ts.map +1 -0
  115. package/lib/scores/CalculatedScore.js +2 -0
  116. package/lib/scores/DefaultCallScoreCalculator.d.ts +7 -0
  117. package/lib/scores/DefaultCallScoreCalculator.d.ts.map +1 -0
  118. package/lib/scores/DefaultCallScoreCalculator.js +21 -0
  119. package/lib/scores/ScoreCalculator.d.ts +4 -0
  120. package/lib/scores/ScoreCalculator.d.ts.map +1 -0
  121. package/lib/scores/ScoreCalculator.js +2 -0
  122. package/lib/updaters/CallUpdater.d.ts +5 -0
  123. package/lib/updaters/CallUpdater.d.ts.map +1 -0
  124. package/lib/updaters/CallUpdater.js +2 -0
  125. package/lib/updaters/ObserverUpdater.d.ts +5 -0
  126. package/lib/updaters/ObserverUpdater.d.ts.map +1 -0
  127. package/lib/updaters/ObserverUpdater.js +2 -0
  128. package/lib/updaters/OnAllCallObserverUpdater_.d.ts +13 -0
  129. package/lib/updaters/OnAllCallObserverUpdater_.d.ts.map +1 -0
  130. package/lib/updaters/OnAllCallObserverUpdater_.js +38 -0
  131. package/lib/updaters/OnAllClientCallUpdater.d.ts +13 -0
  132. package/lib/updaters/OnAllClientCallUpdater.d.ts.map +1 -0
  133. package/lib/updaters/OnAllClientCallUpdater.js +37 -0
  134. package/lib/updaters/OnAnyCallObserverUpdater_.d.ts +11 -0
  135. package/lib/updaters/OnAnyCallObserverUpdater_.d.ts.map +1 -0
  136. package/lib/updaters/OnAnyCallObserverUpdater_.js +27 -0
  137. package/lib/updaters/OnAnyClientCallUpdater.d.ts +11 -0
  138. package/lib/updaters/OnAnyClientCallUpdater.d.ts.map +1 -0
  139. package/lib/updaters/OnAnyClientCallUpdater.js +27 -0
  140. package/lib/updaters/OnIntervalUpdater.d.ts +10 -0
  141. package/lib/updaters/OnIntervalUpdater.d.ts.map +1 -0
  142. package/lib/updaters/OnIntervalUpdater.js +17 -0
  143. package/lib/updaters/Updater.d.ts +6 -0
  144. package/lib/updaters/Updater.d.ts.map +1 -0
  145. package/lib/updaters/Updater.js +2 -0
  146. package/lib/utils/RemoteTrackResolver.d.ts +7 -0
  147. package/lib/utils/RemoteTrackResolver.d.ts.map +1 -0
  148. package/lib/utils/RemoteTrackResolver.js +2 -0
  149. package/package.json +4 -4
  150. package/src/ObservedCall.ts +262 -166
  151. package/src/ObservedCallSummary.ts +22 -0
  152. package/src/ObservedCertificate.ts +43 -0
  153. package/src/ObservedClient.ts +519 -1020
  154. package/src/ObservedClientEventMonitor.ts +301 -0
  155. package/src/ObservedClientSummary.ts +24 -0
  156. package/src/ObservedCodec.ts +49 -0
  157. package/src/ObservedDataChannel.ts +71 -181
  158. package/src/ObservedIceCandidate.ts +64 -0
  159. package/src/ObservedIceCandidatePair.ts +118 -0
  160. package/src/ObservedIceTransport.ts +99 -0
  161. package/src/ObservedInboundRtp.ts +205 -0
  162. package/src/ObservedInboundTrack.ts +73 -0
  163. package/src/ObservedMediaPlayout.ts +49 -0
  164. package/src/ObservedMediaSource.ts +60 -0
  165. package/src/ObservedOutboundRtp.ts +156 -0
  166. package/src/ObservedOutboundTrack.ts +72 -0
  167. package/src/ObservedPeerConnection.ts +854 -408
  168. package/src/ObservedPeerConnectionTransport.ts +38 -0
  169. package/src/ObservedRemoteInboundRtp.ts +64 -0
  170. package/src/ObservedRemoteOutboundRtp.ts +65 -0
  171. package/src/ObservedTURN.ts +86 -0
  172. package/src/ObservedTurnServer.ts +72 -0
  173. package/src/Observer.ts +176 -295
  174. package/src/ObserverEventMonitor.ts +385 -0
  175. package/src/ObserverSummary.ts +15 -0
  176. package/src/common/Middleware.ts +70 -42
  177. package/src/common/logger.ts +60 -69
  178. package/src/common/types.ts +0 -42
  179. package/src/common/utils.ts +24 -2
  180. package/src/detectors/Detector.ts +6 -0
  181. package/src/detectors/Detectors.ts +38 -0
  182. package/src/index.ts +25 -90
  183. package/src/monitors/TurnUsageMonitor.ts +164 -164
  184. package/src/schema/ClientEventTypes.ts +176 -0
  185. package/src/schema/ClientMetaTypes.ts +41 -0
  186. package/src/schema/ClientSample.ts +1682 -0
  187. package/src/scores/CalculatedScore.ts +6 -0
  188. package/src/scores/DefaultCallScoreCalculator.ts +23 -0
  189. package/src/scores/ScoreCalculator.ts +3 -0
  190. package/src/updaters/CallUpdater.ts +5 -0
  191. package/src/updaters/ObserverUpdater.ts +5 -0
  192. package/src/updaters/OnAllCallObserverUpdater_.ts +46 -0
  193. package/src/updaters/OnAllClientCallUpdater.ts +46 -0
  194. package/src/updaters/OnAnyCallObserverUpdater_.ts +32 -0
  195. package/src/updaters/OnAnyClientCallUpdater.ts +32 -0
  196. package/src/updaters/OnIntervalUpdater.ts +19 -0
  197. package/src/updaters/Updater.ts +5 -0
  198. package/src/utils/RemoteTrackResolver.ts +12 -0
  199. package/tsconfig.json +3 -3
  200. package/lib/ObservedICE.d.ts +0 -64
  201. package/lib/ObservedICE.d.ts.map +0 -1
  202. package/lib/ObservedICE.js +0 -141
  203. package/lib/ObservedInboundAudioTrack.d.ts +0 -96
  204. package/lib/ObservedInboundAudioTrack.d.ts.map +0 -1
  205. package/lib/ObservedInboundAudioTrack.js +0 -217
  206. package/lib/ObservedInboundVideoTrack.d.ts +0 -101
  207. package/lib/ObservedInboundVideoTrack.d.ts.map +0 -1
  208. package/lib/ObservedInboundVideoTrack.js +0 -232
  209. package/lib/ObservedOutboundAudioTrack.d.ts +0 -87
  210. package/lib/ObservedOutboundAudioTrack.d.ts.map +0 -1
  211. package/lib/ObservedOutboundAudioTrack.js +0 -186
  212. package/lib/ObservedOutboundVideoTrack.d.ts +0 -91
  213. package/lib/ObservedOutboundVideoTrack.d.ts.map +0 -1
  214. package/lib/ObservedOutboundVideoTrack.js +0 -193
  215. package/lib/ObservedSfu.d.ts +0 -59
  216. package/lib/ObservedSfu.d.ts.map +0 -1
  217. package/lib/ObservedSfu.js +0 -157
  218. package/lib/ObservedSfuInboundRtpPad.d.ts +0 -42
  219. package/lib/ObservedSfuInboundRtpPad.d.ts.map +0 -1
  220. package/lib/ObservedSfuInboundRtpPad.js +0 -71
  221. package/lib/ObservedSfuOutboundRtpPad.d.ts +0 -42
  222. package/lib/ObservedSfuOutboundRtpPad.d.ts.map +0 -1
  223. package/lib/ObservedSfuOutboundRtpPad.js +0 -72
  224. package/lib/ObservedSfuSctpChannel.d.ts +0 -42
  225. package/lib/ObservedSfuSctpChannel.d.ts.map +0 -1
  226. package/lib/ObservedSfuSctpChannel.js +0 -57
  227. package/lib/ObservedSfuTransport.d.ts +0 -58
  228. package/lib/ObservedSfuTransport.d.ts.map +0 -1
  229. package/lib/ObservedSfuTransport.js +0 -120
  230. package/lib/RemoteTrackAssigner.d.ts +0 -14
  231. package/lib/RemoteTrackAssigner.d.ts.map +0 -1
  232. package/lib/RemoteTrackAssigner.js +0 -52
  233. package/lib/ReportsCollector.d.ts +0 -109
  234. package/lib/ReportsCollector.d.ts.map +0 -1
  235. package/lib/ReportsCollector.js +0 -207
  236. package/lib/common/CalculatedScore.d.ts +0 -80
  237. package/lib/common/CalculatedScore.d.ts.map +0 -1
  238. package/lib/common/CalculatedScore.js +0 -162
  239. package/lib/common/CallEventType.d.ts +0 -63
  240. package/lib/common/CallEventType.d.ts.map +0 -1
  241. package/lib/common/CallEventType.js +0 -39
  242. package/lib/common/CallMetaReports.d.ts +0 -42
  243. package/lib/common/CallMetaReports.d.ts.map +0 -1
  244. package/lib/common/CallMetaReports.js +0 -36
  245. package/lib/common/QualityScoreUtils.d.ts +0 -1
  246. package/lib/common/QualityScoreUtils.d.ts.map +0 -1
  247. package/lib/common/QualityScoreUtils.js +0 -1
  248. package/lib/common/TypedEventEmitter.d.ts +0 -22
  249. package/lib/common/TypedEventEmitter.d.ts.map +0 -1
  250. package/lib/common/TypedEventEmitter.js +0 -11
  251. package/lib/common/callEventReports.d.ts +0 -10
  252. package/lib/common/callEventReports.d.ts.map +0 -1
  253. package/lib/common/callEventReports.js +0 -112
  254. package/lib/monitors/CallSummary.d.ts +0 -37
  255. package/lib/monitors/CallSummary.d.ts.map +0 -1
  256. package/lib/monitors/CallSummaryMonitor.d.ts +0 -32
  257. package/lib/monitors/CallSummaryMonitor.d.ts.map +0 -1
  258. package/lib/monitors/CallSummaryMonitor.js +0 -152
  259. package/lib/monitors/ClientIssueMonitor.d.ts +0 -32
  260. package/lib/monitors/ClientIssueMonitor.d.ts.map +0 -1
  261. package/lib/monitors/ClientIssueMonitor.js +0 -49
  262. package/lib/monitors/SfuServerMonitor.d.ts +0 -79
  263. package/lib/monitors/SfuServerMonitor.d.ts.map +0 -1
  264. package/lib/monitors/SfuServerMonitor.js +0 -198
  265. package/src/ObservedICE.ts +0 -237
  266. package/src/ObservedInboundAudioTrack.ts +0 -344
  267. package/src/ObservedInboundVideoTrack.ts +0 -361
  268. package/src/ObservedOutboundAudioTrack.ts +0 -307
  269. package/src/ObservedOutboundVideoTrack.ts +0 -319
  270. package/src/ObservedSfu.ts +0 -231
  271. package/src/ObservedSfuInboundRtpPad.ts +0 -106
  272. package/src/ObservedSfuOutboundRtpPad.ts +0 -107
  273. package/src/ObservedSfuSctpChannel.ts +0 -103
  274. package/src/ObservedSfuTransport.ts +0 -185
  275. package/src/RemoteTrackAssigner.ts +0 -68
  276. package/src/ReportsCollector.ts +0 -336
  277. package/src/common/CalculatedScore.ts +0 -188
  278. package/src/common/CallEventType.ts +0 -69
  279. package/src/common/CallMetaReports.ts +0 -82
  280. package/src/common/QualityScoreUtils.ts +0 -0
  281. package/src/common/TypedEventEmitter.ts +0 -32
  282. package/src/common/callEventReports.ts +0 -178
  283. package/src/monitors/CallSummary.ts +0 -38
  284. package/src/monitors/CallSummaryMonitor.ts +0 -192
  285. package/src/monitors/ClientIssueMonitor.ts +0 -88
  286. package/src/monitors/SfuServerMonitor.ts +0 -285
  287. /package/lib/{monitors/CallSummary.js → ObservedCallSummary.js} +0 -0
package/.prettierrc CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
- "tabWidth": 2,
3
- "useTabs": true,
4
- "trailingComma": "es5",
5
- "singleQuote": true,
6
- "printWidth": 120
7
- }
2
+ "tabWidth": 2,
3
+ "useTabs": true,
4
+ "trailingComma": "es5",
5
+ "singleQuote": true,
6
+ "printWidth": 120
7
+ }
package/README.md CHANGED
@@ -1,106 +1,2 @@
1
1
  Server side component for monitoring WebRTC applications and services
2
2
  ---
3
-
4
- Table of Contents:
5
-
6
- * [Quick Start](#quick-start)
7
- * [Configurations](#configurations)
8
- * [NPM package](#npm-package)
9
- * [Schemas](#schemas)
10
- * [License](#license)
11
-
12
- ## Qucik Start
13
-
14
- Install it from [npm](https://www.npmjs.com/package/@observertc/observer-js) package repository.
15
-
16
- ```
17
- npm i @observertc/observer-js
18
- ```
19
-
20
- Use it in your server side NodeJS app.
21
-
22
- ```javascript
23
- import { createObserver, ClientSample } from "@observertc/observer-js";
24
-
25
- const observer = createObserver({
26
- defaultServiceId: 'my-service-name',
27
- defaultMediaUnitId: 'my-reporting-component',
28
- });
29
-
30
- const observedCall = observer.createObservedCall({
31
- roomId: 'roomId',
32
- callId: 'room-session-id',
33
- });
34
-
35
- const observedClient = observedCall.createObservedClient({
36
- clientId: 'client-id',
37
- mediaUnitId: 'media-unit-id',
38
- });
39
-
40
- const clientSample: ClientSample; // Receive your samples, for example, from a WebSocket
41
-
42
- observedClient.accept(clientSample);
43
- ```
44
-
45
- The above example do as follows:
46
- 1. create an observer to evaluate samples from clients and sfus
47
- 2. create a client source object to accept client samples
48
- 3. add an evaluator process to evaluate ended calls
49
-
50
- ### Get a Summary of a call when it ends
51
-
52
- ```javascript
53
-
54
- const monitor = observer.createCallSummaryMonitor('summary', (summary) => {
55
- console.log('Call Summary', summary);
56
- });
57
- ```
58
-
59
- ### How Many Clients are using TURN?
60
-
61
- ```javascript
62
- const monitor = observer.createTurnUsageMonitor('turn', (turn) => {
63
- console.log('TURN', turn);
64
- });
65
-
66
- // at any point of time you can get the current state of the turn usage
67
-
68
- console.log('Currently ', monitor.clients.size, 'clients are using TURN');
69
-
70
- // you can get the incoming and outgoing bytes of the TURN server
71
- console.log(`${YOUR_TURN_SERVER_ADDRESS} usage:`, monitor.getUsage(YOUR_TURN_SERVER_ADDRESS));
72
-
73
- ```
74
-
75
- ### Monitor Calls and Clients as they updated
76
-
77
- ```javascript
78
- observer.on('newcall', (call) => {
79
- call.on('update', () => {
80
- console.log('Call Updated', call.callId);
81
- });
82
-
83
- call.on('newclient', (client) => {
84
-
85
- client.on('update', () => {
86
- console.log('Client Updated', client.clientId);
87
-
88
- console.log(`The avaialble incoming bitrate for the client ${client.clientId} is: ${client.availableIncomingBitrate}`)
89
- });
90
- })
91
- });
92
- ```
93
-
94
- ## NPM package
95
-
96
- https://www.npmjs.com/package/@observertc/observer-js
97
-
98
-
99
- ## Schemas
100
-
101
- https://github.com/observertc/schemas
102
-
103
-
104
- ## License
105
-
106
- Apache-2.0
@@ -1,23 +1,24 @@
1
1
  /// <reference types="node" />
2
2
  import { EventEmitter } from 'events';
3
- import { ObservedClient, ObservedClientModel } from './ObservedClient';
3
+ import { ObservedClient, ObservedClientSettings } from './ObservedClient';
4
4
  import { Observer } from './Observer';
5
- import { PartialBy } from './common/utils';
6
- import { CallEventReport } from '@observertc/report-schemas-js';
7
- import { ClientSample } from '@observertc/sample-schemas-js';
8
- import { ObservedOutboundAudioTrack } from './ObservedOutboundAudioTrack';
9
- import { ObservedOutboundVideoTrack } from './ObservedOutboundVideoTrack';
10
- import { CalculatedScore } from './common/CalculatedScore';
11
- export type ObservedCallModel = {
12
- serviceId: string;
13
- roomId: string;
5
+ import { ScoreCalculator } from './scores/ScoreCalculator';
6
+ import { CalculatedScore } from './scores/CalculatedScore';
7
+ import { Detectors } from './detectors/Detectors';
8
+ import { RemoteTrackResolver } from './utils/RemoteTrackResolver';
9
+ import { Updater } from './updaters/Updater';
10
+ export type ObservedCallSettings<AppData extends Record<string, unknown> = Record<string, unknown>> = {
14
11
  callId: string;
12
+ appData?: AppData;
13
+ remoteTrackResolvePolicy?: 'p2p' | 'mediasoup-sfu';
14
+ updatePolicy?: 'update-on-any-client-updated' | 'update-when-all-client-updated' | 'update-on-interval';
15
+ updateIntervalInMs?: number;
15
16
  };
16
17
  export type ObservedCallEvents = {
17
18
  update: [];
18
19
  newclient: [ObservedClient];
19
- callevent: [Omit<CallEventReport, 'callId' | 'serviceId' | 'roomId'>];
20
20
  empty: [];
21
+ 'not-empty': [];
21
22
  close: [];
22
23
  };
23
24
  export declare interface ObservedCall {
@@ -27,39 +28,56 @@ export declare interface ObservedCall {
27
28
  emit<U extends keyof ObservedCallEvents>(event: U, ...args: ObservedCallEvents[U]): boolean;
28
29
  }
29
30
  export declare class ObservedCall<AppData extends Record<string, unknown> = Record<string, unknown>> extends EventEmitter {
30
- private readonly _model;
31
31
  readonly observer: Observer;
32
- readonly appData: AppData;
33
- readonly created: number;
34
- readonly processor: import("./common/Middleware").Processor<ClientSample>;
35
- private readonly _clients;
36
- _scoreData?: {
37
- score: CalculatedScore;
38
- calculated: number;
39
- };
40
- readonly sfuStreamIdToOutboundAudioTrack: Map<string | number, ObservedOutboundAudioTrack>;
41
- readonly sfuStreamIdToOutboundVideoTrack: Map<string | number, ObservedOutboundVideoTrack>;
42
- private _closed;
43
- started?: number;
44
- ended?: number;
45
- observationUpdated: number;
46
- observationEnded?: number;
47
- readonly observationStarted: number;
48
- constructor(_model: ObservedCallModel, observer: Observer, appData: AppData);
49
- get serviceId(): string;
50
- get reports(): import("./ReportsCollector").ReportsCollector;
51
- get roomId(): string;
52
- get callId(): string;
53
- get clients(): ReadonlyMap<string, ObservedClient>;
54
- get score(): CalculatedScore | undefined;
55
- get closed(): boolean;
32
+ readonly detectors: Detectors;
33
+ updater?: Updater;
34
+ scoreCalculator: ScoreCalculator;
35
+ readonly callId: string;
36
+ readonly observedClients: Map<string, ObservedClient<Record<string, unknown>>>;
37
+ readonly clientsUsedTurn: Set<string>;
38
+ readonly calculatedScore: CalculatedScore;
39
+ remoteTrackResolver?: RemoteTrackResolver;
40
+ totalAddedClients: number;
41
+ totalRemovedClients: number;
42
+ totalClientsReceivedAudioBytes: number;
43
+ totalClientsReceivedVideoBytes: number;
44
+ totalClientsReceivedDataChannelBytes: number;
45
+ totalClientsReceivedBytes: number;
46
+ totalClientsSentAudioBytes: number;
47
+ totalClientsSentDataChannelBytes: number;
48
+ totalClientsSentVideoBytes: number;
49
+ totalClientsSentBytes: number;
50
+ totalRttLt50Measurements: number;
51
+ totalRttLt150Measurements: number;
52
+ totalRttLt300Measurements: number;
53
+ totalRttGtOrEq300Measurements: number;
54
+ numberOfIssues: number;
55
+ numberOfPeerConnections: number;
56
+ numberOfInboundRtpStreams: number;
57
+ numberOfOutboundRtpStreams: number;
58
+ numberOfDataChannels: number;
59
+ maxNumberOfClients: number;
60
+ deltaNumberOfIssues: number;
61
+ deltaRttLt50Measurements: number;
62
+ deltaRttLt150Measurements: number;
63
+ deltaRttLt300Measurements: number;
64
+ deltaRttGtOrEq300Measurements: number;
65
+ appData: AppData;
66
+ closed: boolean;
67
+ startedAt?: number;
68
+ endedAt?: number;
69
+ closedAt?: number;
70
+ private _callStartedEvent;
71
+ private _callEndedEvent;
72
+ constructor(settings: ObservedCallSettings<AppData>, observer: Observer);
73
+ get numberOfClients(): number;
74
+ get score(): number | undefined;
56
75
  close(): void;
57
- addEventReport(params: PartialBy<Omit<CallEventReport, 'serviceId' | 'roomId' | 'callId'>, 'timestamp'>): void;
58
- createClient<ClientAppData extends Record<string, unknown> = Record<string, unknown>>(config: ObservedClientModel & {
59
- appData: ClientAppData;
60
- joinedTimestamp?: number;
61
- createClientJoinedReport?: boolean;
62
- createClientLeftReport?: boolean;
63
- }): ObservedClient<ClientAppData>;
76
+ getObservedClient<ClientAppData extends Record<string, unknown> = Record<string, unknown>>(clientId: string): ObservedClient<ClientAppData> | undefined;
77
+ createObservedClient<ClientAppData extends Record<string, unknown> = Record<string, unknown>>(settings: ObservedClientSettings<ClientAppData>): ObservedClient<ClientAppData>;
78
+ update(): void;
79
+ private _onClientUpdate;
80
+ private _clientJoined;
81
+ private _clientLeft;
64
82
  }
65
83
  //# sourceMappingURL=ObservedCall.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ObservedCall.d.ts","sourceRoot":"","sources":["../src/ObservedCall.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAa,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,MAAM,MAAM,iBAAiB,GAAG;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAChC,MAAM,EAAE,EAAE,CAAC;IACX,SAAS,EAAE,CAAC,cAAc,CAAC,CAAC;IAC5B,SAAS,EAAE,CAAC,IAAI,CAAC,eAAe,EAAE,QAAQ,GAAG,WAAW,GAAG,QAAQ,CAAC,CAAC,CAAC;IACtE,KAAK,EAAE,EAAE,CAAC;IACV,KAAK,EAAE,EAAE,CAAC;CACV,CAAA;AAED,MAAM,CAAC,OAAO,WAAW,YAAY;IACpC,EAAE,CAAC,CAAC,SAAS,MAAM,kBAAkB,EAAE,K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zB,OAAO,CAAC,iBAAiB,CAGvB;IACF,OAAO,CAAC,eAAe,CAErB;gBAGD,QAAQ,EAAE,oBAAoB,CAAC,OAAO,CAAC,EACvB,QAAQ,EAAE,QAAQ;IA8CnC,IAAW,eAAe,WAEzB;IAED,IAAW,KAAK,uBAEf;IAEM,KAAK;IAaL,iBAAiB,CAAC,aAAa,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,cAAc,CAAC,aAAa,CAAC,GAAG,SAAS;IAMvJ,oBAAoB,CAAC,aAAa,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,sBAAsB,CAAC,aAAa,CAAC,GAAG,cAAc,CAAC,aAAa,CAAC;IAsC7K,MAAM;IA2Bb,OAAO,CAAC,eAAe;IA4BvB,OAAO,CAAC,aAAa;IAMrB,OAAO,CAAC,WAAW;CAoDnB"}
@@ -1,139 +1,203 @@
1
1
  "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  exports.ObservedCall = void 0;
15
4
  const events_1 = require("events");
16
5
  const ObservedClient_1 = require("./ObservedClient");
17
- const callEventReports_1 = require("./common/callEventReports");
18
- const utils_1 = require("./common/utils");
19
- const Middleware_1 = require("./common/Middleware");
6
+ const DefaultCallScoreCalculator_1 = require("./scores/DefaultCallScoreCalculator");
7
+ const Detectors_1 = require("./detectors/Detectors");
8
+ const OnAllClientCallUpdater_1 = require("./updaters/OnAllClientCallUpdater");
9
+ const OnIntervalUpdater_1 = require("./updaters/OnIntervalUpdater");
10
+ const OnAnyClientCallUpdater_1 = require("./updaters/OnAnyClientCallUpdater");
20
11
  class ObservedCall extends events_1.EventEmitter {
21
- constructor(_model, observer, appData) {
12
+ observer;
13
+ detectors;
14
+ updater;
15
+ scoreCalculator;
16
+ callId;
17
+ observedClients = new Map();
18
+ clientsUsedTurn = new Set();
19
+ calculatedScore = {
20
+ weight: 1,
21
+ value: undefined,
22
+ };
23
+ remoteTrackResolver;
24
+ totalAddedClients = 0;
25
+ totalRemovedClients = 0;
26
+ totalClientsReceivedAudioBytes = 0;
27
+ totalClientsReceivedVideoBytes = 0;
28
+ totalClientsReceivedDataChannelBytes = 0;
29
+ totalClientsReceivedBytes = 0;
30
+ totalClientsSentAudioBytes = 0;
31
+ totalClientsSentDataChannelBytes = 0;
32
+ totalClientsSentVideoBytes = 0;
33
+ totalClientsSentBytes = 0;
34
+ totalRttLt50Measurements = 0;
35
+ totalRttLt150Measurements = 0;
36
+ totalRttLt300Measurements = 0;
37
+ totalRttGtOrEq300Measurements = 0;
38
+ numberOfIssues = 0;
39
+ numberOfPeerConnections = 0;
40
+ numberOfInboundRtpStreams = 0;
41
+ numberOfOutboundRtpStreams = 0;
42
+ numberOfDataChannels = 0;
43
+ maxNumberOfClients = 0;
44
+ deltaNumberOfIssues = 0;
45
+ deltaRttLt50Measurements = 0;
46
+ deltaRttLt150Measurements = 0;
47
+ deltaRttLt300Measurements = 0;
48
+ deltaRttGtOrEq300Measurements = 0;
49
+ appData;
50
+ closed = false;
51
+ startedAt;
52
+ endedAt;
53
+ closedAt;
54
+ _callStartedEvent;
55
+ _callEndedEvent;
56
+ constructor(settings, observer) {
22
57
  super();
23
- this._model = _model;
24
58
  this.observer = observer;
25
- this.appData = appData;
26
- this.created = Date.now();
27
- this.processor = (0, Middleware_1.createProcessor)();
28
- this._clients = new Map();
29
- this.sfuStreamIdToOutboundAudioTrack = new Map();
30
- this.sfuStreamIdToOutboundVideoTrack = new Map();
31
- this._closed = false;
32
- this.observationUpdated = Date.now();
33
- this.observationStarted = Date.now();
34
59
  this.setMaxListeners(Infinity);
35
- }
36
- get serviceId() {
37
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
38
- return this._model.serviceId;
39
- }
40
- get reports() {
41
- return this.observer.reports;
42
- }
43
- get roomId() {
44
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
45
- return this._model.roomId;
46
- }
47
- get callId() {
48
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
49
- return this._model.callId;
50
- }
51
- get clients() {
52
- return this._clients;
53
- }
54
- get score() {
55
- var _a, _b, _c;
56
- const now = Date.now();
57
- if (now - 15000 < ((_b = (_a = this._scoreData) === null || _a === void 0 ? void 0 : _a.calculated) !== null && _b !== void 0 ? _b : 0)) {
58
- return (_c = this._scoreData) === null || _c === void 0 ? void 0 : _c.score;
60
+ this.callId = settings.callId;
61
+ this.appData = settings.appData ?? {};
62
+ this.scoreCalculator = new DefaultCallScoreCalculator_1.DefaultCallScoreCalculator(this);
63
+ this.detectors = new Detectors_1.Detectors();
64
+ if (settings.updateIntervalInMs) {
65
+ if (settings.updatePolicy !== 'update-on-interval') {
66
+ throw new Error('updatePolicy must be update-on-interval if updateIntervalInMs is set in config');
67
+ }
59
68
  }
60
- else if (this.clients.size < 1) {
61
- return {
62
- remarks: [{
63
- severity: 'none',
64
- text: 'No clients',
65
- }],
66
- score: 5.0,
67
- timestamp: now,
68
- };
69
+ switch (settings.updatePolicy) {
70
+ case 'update-on-any-client-updated':
71
+ this.updater = new OnAllClientCallUpdater_1.OnAllClientCallUpdater(this);
72
+ break;
73
+ case 'update-when-all-client-updated':
74
+ this.updater = new OnAnyClientCallUpdater_1.OnAnyClientCallUpdater(this);
75
+ break;
76
+ case 'update-on-interval':
77
+ if (!settings.updateIntervalInMs) {
78
+ throw new Error('updateIntervalInMs setting in config must be set if updatePolicy is update-on-interval');
79
+ }
80
+ this.updater = new OnIntervalUpdater_1.OnIntervalUpdater(settings.updateIntervalInMs, this.update.bind(this));
81
+ break;
82
+ }
83
+ switch (settings.remoteTrackResolvePolicy) {
84
+ case 'mediasoup-sfu':
85
+ break;
69
86
  }
70
- const scores = [...this.clients.values()].map((client) => { var _a, _b; return (_b = (_a = client.score) === null || _a === void 0 ? void 0 : _a.score) !== null && _b !== void 0 ? _b : 5.0; });
71
- this._scoreData = {
72
- score: {
73
- remarks: [],
74
- score: (0, utils_1.getMedian)(scores),
75
- timestamp: now,
76
- },
77
- calculated: now,
87
+ this._callStartedEvent = {
88
+ emitted: false,
78
89
  };
79
- return this._scoreData.score;
90
+ this._callEndedEvent = {
91
+ emitted: false,
92
+ };
93
+ }
94
+ get numberOfClients() {
95
+ return this.observedClients.size;
80
96
  }
81
- get closed() {
82
- return this._closed;
97
+ get score() {
98
+ return this.calculatedScore.value;
83
99
  }
84
100
  close() {
85
- if (this._closed)
101
+ if (this.closed)
86
102
  return;
87
- this._closed = true;
88
- Array.from(this._clients.values()).forEach((client) => client.close());
89
- this.observationEnded = Date.now();
103
+ this.update(); // last update before closing
104
+ this.closed = true;
105
+ this.updater?.close();
106
+ [...this.observedClients.values()].forEach((client) => client.close());
107
+ this.closedAt = Date.now();
90
108
  this.emit('close');
91
109
  }
92
- addEventReport(params) {
93
- var _a;
94
- this.reports.addCallEventReport(Object.assign(Object.assign({}, params), { serviceId: this.serviceId, roomId: this.roomId, callId: this.callId, timestamp: (_a = params.timestamp) !== null && _a !== void 0 ? _a : Date.now() }));
110
+ getObservedClient(clientId) {
111
+ if (this.closed || !this.observedClients.has(clientId))
112
+ return;
113
+ return this.observedClients.get(clientId);
95
114
  }
96
- createClient(config) {
97
- var _a;
98
- if (this._closed)
115
+ createObservedClient(settings) {
116
+ if (this.closed)
99
117
  throw new Error(`Call ${this.callId} is closed`);
100
- const { appData, createClientJoinedReport, createClientLeftReport, joinedTimestamp = Date.now() } = config, model = __rest(config, ["appData", "createClientJoinedReport", "createClientLeftReport", "joinedTimestamp"]);
101
- const result = new ObservedClient_1.ObservedClient(model, this, appData);
102
- const onUpdate = ({ sample }) => {
103
- this.observationUpdated = Date.now();
104
- if (result.joined) {
105
- if (this.started === undefined || result.joined < this.started) {
106
- this.started = result.joined;
107
- }
108
- }
109
- if (result.left) {
110
- if (this.ended === undefined || result.left > this.ended) {
111
- this.ended = result.left;
112
- }
113
- }
114
- this.emit('update');
115
- this.processor.process(sample);
116
- };
118
+ if (this.observedClients.has(settings.clientId))
119
+ throw new Error(`Client with id ${settings.clientId} already exists`);
120
+ const result = new ObservedClient_1.ObservedClient(settings, this);
121
+ const wasEmpty = this.observedClients.size === 0;
122
+ const onUpdate = () => this._onClientUpdate(result);
123
+ const joined = () => this._clientJoined(result);
124
+ const left = () => this._clientLeft(result);
117
125
  result.once('close', () => {
118
126
  result.off('update', onUpdate);
119
- this._clients.delete(result.clientId);
120
- if (this._clients.size === 0) {
127
+ result.off('joined', joined);
128
+ result.off('left', left);
129
+ this.observedClients.delete(settings.clientId);
130
+ if (this.observedClients.size === 0) {
121
131
  this.emit('empty');
122
132
  }
133
+ ++this.totalRemovedClients;
123
134
  });
124
135
  result.on('update', onUpdate);
125
- this._clients.set(result.clientId, result);
126
- if (createClientJoinedReport) {
127
- this.reports.addCallEventReport((0, callEventReports_1.createClientJoinedEventReport)(this.serviceId, result.mediaUnitId, this.roomId, this.callId, result.clientId, (_a = result.joined) !== null && _a !== void 0 ? _a : joinedTimestamp, result.userId, result.marker));
128
- }
129
- result.once('close', () => {
130
- var _a;
131
- if (createClientLeftReport) {
132
- this.reports.addCallEventReport((0, callEventReports_1.createClientLeftEventReport)(this.serviceId, result.mediaUnitId, this.roomId, this.callId, result.clientId, (_a = result.left) !== null && _a !== void 0 ? _a : Date.now(), result.userId, result.marker));
133
- }
134
- });
136
+ result.on('joined', joined);
137
+ result.on('left', left);
138
+ ++this.totalAddedClients;
139
+ this.observedClients.set(settings.clientId, result);
140
+ this.maxNumberOfClients = Math.max(this.maxNumberOfClients, this.observedClients.size);
135
141
  this.emit('newclient', result);
142
+ if (wasEmpty) {
143
+ this.emit('not-empty');
144
+ }
136
145
  return result;
137
146
  }
147
+ update() {
148
+ if (this.closed)
149
+ return;
150
+ this.numberOfInboundRtpStreams = 0;
151
+ this.numberOfOutboundRtpStreams = 0;
152
+ this.numberOfPeerConnections = 0;
153
+ this.numberOfDataChannels = 0;
154
+ for (const client of this.observedClients.values()) {
155
+ this.numberOfInboundRtpStreams += client.numberOfInboundRtpStreams;
156
+ this.numberOfOutboundRtpStreams += client.numberOfOutboundRtpStreams;
157
+ this.numberOfPeerConnections += client.numberOfPeerConnections;
158
+ this.numberOfDataChannels += client.numberOfDataChannels;
159
+ }
160
+ this.detectors.update();
161
+ this.scoreCalculator.update();
162
+ this.emit('update');
163
+ this.deltaNumberOfIssues = 0;
164
+ this.deltaRttLt50Measurements = 0;
165
+ this.deltaRttLt150Measurements = 0;
166
+ this.deltaRttLt300Measurements = 0;
167
+ this.deltaRttGtOrEq300Measurements = 0;
168
+ }
169
+ _onClientUpdate(client) {
170
+ this.totalClientsReceivedAudioBytes += client.deltaReceivedAudioBytes;
171
+ this.totalClientsReceivedVideoBytes += client.deltaReceivedVideoBytes;
172
+ this.totalClientsReceivedDataChannelBytes += client.deltaDataChannelBytesReceived;
173
+ this.totalClientsReceivedBytes += client.deltaTransportReceivedBytes;
174
+ this.totalClientsSentAudioBytes += client.deltaSentAudioBytes;
175
+ this.totalClientsSentVideoBytes += client.deltaSentVideoBytes;
176
+ this.totalClientsSentDataChannelBytes += client.deltaDataChannelBytesSent;
177
+ this.totalClientsSentBytes += client.deltaTransportSentBytes;
178
+ this.deltaRttLt50Measurements += client.deltaRttLt50Measurements;
179
+ this.deltaRttLt150Measurements += client.deltaRttLt150Measurements;
180
+ this.deltaRttLt300Measurements += client.deltaRttLt300Measurements;
181
+ this.deltaRttGtOrEq300Measurements += client.deltaRttGtOrEq300Measurements;
182
+ this.totalRttLt50Measurements += client.deltaRttLt50Measurements;
183
+ this.totalRttLt150Measurements += client.deltaRttLt150Measurements;
184
+ this.totalRttLt300Measurements += client.deltaRttLt300Measurements;
185
+ this.totalRttGtOrEq300Measurements += client.deltaRttGtOrEq300Measurements;
186
+ this.deltaNumberOfIssues += client.deltaNumberOfIssues;
187
+ this.numberOfIssues += client.deltaNumberOfIssues;
188
+ if (client.usingTURN) {
189
+ this.clientsUsedTurn.add(client.clientId);
190
+ }
191
+ }
192
+ _clientJoined(client) {
193
+ if (!client.joinedAt)
194
+ return;
195
+ this.startedAt = Math.min(this.startedAt ?? client.joinedAt, client.joinedAt);
196
+ }
197
+ _clientLeft(client) {
198
+ if (!client.leftAt)
199
+ return;
200
+ this.endedAt = Math.max(this.endedAt ?? client.leftAt, client.leftAt);
201
+ }
138
202
  }
139
203
  exports.ObservedCall = ObservedCall;
@@ -0,0 +1,18 @@
1
+ export type ObservedCallSummary = {
2
+ currentActiveClients: number;
3
+ totalAddedClients: number;
4
+ totalRemovedClients: number;
5
+ totalClientsSentBytes: number;
6
+ totalClientsReceivedBytes: number;
7
+ totalClientsReceivedAudioBytes: number;
8
+ totalClientsReceivedVideoBytes: number;
9
+ totalClientsSentAudioBytes: number;
10
+ totalClientsSentVideoBytes: number;
11
+ totalRttLt50Measurements: number;
12
+ totalRttLt150Measurements: number;
13
+ totalRttLt300Measurements: number;
14
+ totalRttGtOrEq300Measurements: number;
15
+ numberOfIssues: number;
16
+ numberOfClientsUsedTurn: number;
17
+ };
18
+ //# sourceMappingURL=ObservedCallSummary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ObservedCallSummary.d.ts","sourceRoot":"","sources":["../src/ObservedCallSummary.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG;IACjC,oBAAoB,EAAE,MAAM,CAAC;IAE7B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,mBAAmB,EAAE,MAAM,CAAC;IAE5B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,yBAAyB,EAAE,MAAM,CAAC;IAClC,8BAA8B,EAAE,MAAM,CAAC;IACvC,8BAA8B,EAAE,MAAM,CAAC;IACvC,0BAA0B,EAAE,MAAM,CAAC;IACnC,0BAA0B,EAAE,MAAM,CAAC;IAEnC,wBAAwB,EAAE,MAAM,CAAC;IACjC,yBAAyB,EAAE,MAAM,CAAC;IAClC,yBAAyB,EAAE,MAAM,CAAC;IAClC,6BAA6B,EAAE,MAAM,CAAC;IAEtC,cAAc,EAAE,MAAM,CAAC;IAEvB,uBAAuB,EAAE,MAAM,CAAC;CAChC,CAAA"}
@@ -0,0 +1,19 @@
1
+ import { ObservedPeerConnection } from './ObservedPeerConnection';
2
+ import { CertificateStats } from './schema/ClientSample';
3
+ export declare class ObservedCertificate implements CertificateStats {
4
+ timestamp: number;
5
+ id: string;
6
+ private readonly _peerConnection;
7
+ appData?: Record<string, unknown>;
8
+ private _visited;
9
+ fingerprint?: string;
10
+ fingerprintAlgorithm?: string;
11
+ base64Certificate?: string;
12
+ issuerCertificateId?: string;
13
+ attachments?: Record<string, unknown>;
14
+ constructor(timestamp: number, id: string, _peerConnection: ObservedPeerConnection);
15
+ get visited(): boolean;
16
+ getPeerConnection(): ObservedPeerConnection;
17
+ update(stats: CertificateStats): void;
18
+ }
19
+ //# sourceMappingURL=ObservedCertificate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ObservedCertificate.d.ts","sourceRoot":"","sources":["../src/ObservedCertificate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,qBAAa,mBAAoB,YAAW,gBAAgB;IAYnD,SAAS,EAAE,MAAM;IACjB,EAAE,EAAE,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAb1B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEzC,OAAO,CAAC,QAAQ,CAAS;IAEzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAG9B,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,EACA,eAAe,EAAE,sBAAsB;IAGzD,IAAW,OAAO,YAMjB;IAEM,iBAAiB;IAIjB,MAAM,CAAC,KAAK,EAAE,gBAAgB;CAUrC"}