@observertc/observer-js 0.9.27-beta → 0.30.0-beta

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 (298) hide show
  1. package/lib/ObservedCall.d.ts +54 -0
  2. package/lib/ObservedCall.d.ts.map +1 -0
  3. package/lib/ObservedCall.js +166 -0
  4. package/lib/ObservedClient.d.ts +73 -0
  5. package/lib/ObservedClient.d.ts.map +1 -0
  6. package/lib/ObservedClient.js +487 -0
  7. package/lib/ObservedInboundTrack.d.ts +65 -0
  8. package/lib/ObservedInboundTrack.d.ts.map +1 -0
  9. package/lib/ObservedInboundTrack.js +192 -0
  10. package/lib/ObservedOutboundTrack.d.ts +55 -0
  11. package/lib/ObservedOutboundTrack.d.ts.map +1 -0
  12. package/lib/ObservedOutboundTrack.js +166 -0
  13. package/lib/ObservedPeerConnection.d.ts +57 -0
  14. package/lib/ObservedPeerConnection.d.ts.map +1 -0
  15. package/lib/ObservedPeerConnection.js +217 -0
  16. package/lib/Observer.d.ts +26 -1465
  17. package/lib/Observer.d.ts.map +1 -1
  18. package/lib/Observer.js +53 -605
  19. package/lib/{sinks/ObserverSink.d.ts → ReportsCollector.d.ts} +7 -23
  20. package/lib/ReportsCollector.d.ts.map +1 -0
  21. package/lib/{sinks/ObserverSink.js → ReportsCollector.js} +27 -85
  22. package/lib/common/ReportsCollector.d.ts +21 -24
  23. package/lib/common/ReportsCollector.d.ts.map +1 -1
  24. package/lib/common/ReportsCollector.js +24 -0
  25. package/lib/common/SingleExecutor.d.ts +3 -0
  26. package/lib/common/SingleExecutor.d.ts.map +1 -0
  27. package/lib/common/SingleExecutor.js +31 -0
  28. package/lib/common/TypedEventEmitter.d.ts +22 -0
  29. package/lib/common/TypedEventEmitter.d.ts.map +1 -0
  30. package/lib/common/TypedEventEmitter.js +11 -0
  31. package/lib/common/callEventReports.d.ts.map +1 -0
  32. package/lib/common/logger.d.ts +3 -9
  33. package/lib/common/logger.d.ts.map +1 -1
  34. package/lib/common/logger.js +58 -141
  35. package/lib/common/types.d.ts +2 -14
  36. package/lib/common/types.d.ts.map +1 -1
  37. package/lib/common/utils.d.ts +1 -0
  38. package/lib/common/utils.d.ts.map +1 -1
  39. package/lib/common/utils.js +6 -1
  40. package/lib/index.d.ts +8 -19
  41. package/lib/index.d.ts.map +1 -1
  42. package/lib/index.js +7 -2
  43. package/package.json +1 -1
  44. package/src/ObservedCall.ts +201 -0
  45. package/src/ObservedClient.ts +681 -0
  46. package/src/ObservedInboundTrack.ts +238 -0
  47. package/src/ObservedOutboundTrack.ts +205 -0
  48. package/src/ObservedPeerConnection.ts +249 -0
  49. package/src/Observer.ts +86 -442
  50. package/src/{sinks/ObserverSink.ts → ReportsCollector.ts} +29 -94
  51. package/src/common/ReportsCollector.ts +48 -23
  52. package/src/common/SingleExecutor.ts +36 -0
  53. package/src/common/TypedEventEmitter.ts +32 -0
  54. package/src/common/logger.ts +58 -161
  55. package/src/common/types.ts +4 -24
  56. package/src/common/utils.ts +6 -0
  57. package/src/index.ts +12 -23
  58. package/lib/Evaluator.d.ts +0 -43
  59. package/lib/Evaluator.d.ts.map +0 -1
  60. package/lib/Evaluator.js +0 -171
  61. package/lib/common/Semaphore.d.ts +0 -31
  62. package/lib/common/Semaphore.d.ts.map +0 -1
  63. package/lib/common/Semaphore.js +0 -16
  64. package/lib/entries/CallEntry.d.ts +0 -619
  65. package/lib/entries/CallEntry.d.ts.map +0 -1
  66. package/lib/entries/CallEntry.js +0 -75
  67. package/lib/entries/ClientEntry.d.ts +0 -478
  68. package/lib/entries/ClientEntry.d.ts.map +0 -1
  69. package/lib/entries/ClientEntry.js +0 -114
  70. package/lib/entries/InboundTrackEntry.d.ts +0 -682
  71. package/lib/entries/InboundTrackEntry.d.ts.map +0 -1
  72. package/lib/entries/InboundTrackEntry.js +0 -76
  73. package/lib/entries/OutboundTrackEntry.d.ts +0 -682
  74. package/lib/entries/OutboundTrackEntry.d.ts.map +0 -1
  75. package/lib/entries/OutboundTrackEntry.js +0 -73
  76. package/lib/entries/PeerConnectionEntry.d.ts +0 -505
  77. package/lib/entries/PeerConnectionEntry.d.ts.map +0 -1
  78. package/lib/entries/PeerConnectionEntry.js +0 -144
  79. package/lib/entries/SfuEntry.d.ts +0 -150
  80. package/lib/entries/SfuEntry.d.ts.map +0 -1
  81. package/lib/entries/SfuEntry.js +0 -77
  82. package/lib/entries/SfuInboundRtpPadEntry.d.ts +0 -14
  83. package/lib/entries/SfuInboundRtpPadEntry.d.ts.map +0 -1
  84. package/lib/entries/SfuInboundRtpPadEntry.js +0 -49
  85. package/lib/entries/SfuOutboundRtpPadEntry.d.ts +0 -14
  86. package/lib/entries/SfuOutboundRtpPadEntry.d.ts.map +0 -1
  87. package/lib/entries/SfuOutboundRtpPadEntry.js +0 -47
  88. package/lib/entries/SfuSctpChannelEntry.d.ts +0 -12
  89. package/lib/entries/SfuSctpChannelEntry.d.ts.map +0 -1
  90. package/lib/entries/SfuSctpChannelEntry.js +0 -43
  91. package/lib/entries/SfuTransportEntry.d.ts +0 -82
  92. package/lib/entries/SfuTransportEntry.d.ts.map +0 -1
  93. package/lib/entries/SfuTransportEntry.js +0 -122
  94. package/lib/evaluators/SetClientsCoordinateEvaluator.d.ts +0 -9
  95. package/lib/evaluators/SetClientsCoordinateEvaluator.d.ts.map +0 -1
  96. package/lib/evaluators/SetClientsCoordinateEvaluator.js +0 -95
  97. package/lib/middlewares/CallOperationsContext.d.ts +0 -18
  98. package/lib/middlewares/CallOperationsContext.d.ts.map +0 -1
  99. package/lib/middlewares/CallOperationsContext.js +0 -27
  100. package/lib/middlewares/CallProcessor.d.ts +0 -6
  101. package/lib/middlewares/CallProcessor.d.ts.map +0 -1
  102. package/lib/middlewares/CallProcessor.js +0 -36
  103. package/lib/middlewares/CommitTransactionMiddleware.d.ts +0 -6
  104. package/lib/middlewares/CommitTransactionMiddleware.d.ts.map +0 -1
  105. package/lib/middlewares/CommitTransactionMiddleware.js +0 -179
  106. package/lib/middlewares/DeleteOutdatedCallEntries.d.ts +0 -6
  107. package/lib/middlewares/DeleteOutdatedCallEntries.d.ts.map +0 -1
  108. package/lib/middlewares/DeleteOutdatedCallEntries.js +0 -121
  109. package/lib/middlewares/DeleteOutdatedSfuEntries.d.ts +0 -6
  110. package/lib/middlewares/DeleteOutdatedSfuEntries.d.ts.map +0 -1
  111. package/lib/middlewares/DeleteOutdatedSfuEntries.js +0 -127
  112. package/lib/middlewares/Middleware.d.ts +0 -3
  113. package/lib/middlewares/Middleware.d.ts.map +0 -1
  114. package/lib/middlewares/Middleware.js +0 -21
  115. package/lib/middlewares/Processor.d.ts +0 -9
  116. package/lib/middlewares/Processor.d.ts.map +0 -1
  117. package/lib/middlewares/Processor.js +0 -54
  118. package/lib/middlewares/TransactionContext.d.ts +0 -35
  119. package/lib/middlewares/TransactionContext.d.ts.map +0 -1
  120. package/lib/middlewares/TransactionContext.js +0 -90
  121. package/lib/middlewares/TransactoinProcessor.d.ts +0 -6
  122. package/lib/middlewares/TransactoinProcessor.d.ts.map +0 -1
  123. package/lib/middlewares/TransactoinProcessor.js +0 -17
  124. package/lib/middlewares/VisitObservedCallsMiddleware.d.ts +0 -7
  125. package/lib/middlewares/VisitObservedCallsMiddleware.d.ts.map +0 -1
  126. package/lib/middlewares/VisitObservedCallsMiddleware.js +0 -96
  127. package/lib/middlewares/VisitObservedSfusMiddleware.d.ts +0 -6
  128. package/lib/middlewares/VisitObservedSfusMiddleware.d.ts.map +0 -1
  129. package/lib/middlewares/VisitObservedSfusMiddleware.js +0 -151
  130. package/lib/middlewares/visitors/visitClient.d.ts +0 -5
  131. package/lib/middlewares/visitors/visitClient.d.ts.map +0 -1
  132. package/lib/middlewares/visitors/visitClient.js +0 -174
  133. package/lib/middlewares/visitors/visitInboundAudioTrack.d.ts +0 -5
  134. package/lib/middlewares/visitors/visitInboundAudioTrack.d.ts.map +0 -1
  135. package/lib/middlewares/visitors/visitInboundAudioTrack.js +0 -93
  136. package/lib/middlewares/visitors/visitInboundVideoTrack.d.ts +0 -5
  137. package/lib/middlewares/visitors/visitInboundVideoTrack.d.ts.map +0 -1
  138. package/lib/middlewares/visitors/visitInboundVideoTrack.js +0 -94
  139. package/lib/middlewares/visitors/visitOutboundAudioTrack.d.ts +0 -5
  140. package/lib/middlewares/visitors/visitOutboundAudioTrack.d.ts.map +0 -1
  141. package/lib/middlewares/visitors/visitOutboundAudioTrack.js +0 -90
  142. package/lib/middlewares/visitors/visitOutboundVideoTarck.d.ts +0 -5
  143. package/lib/middlewares/visitors/visitOutboundVideoTarck.d.ts.map +0 -1
  144. package/lib/middlewares/visitors/visitOutboundVideoTarck.js +0 -90
  145. package/lib/middlewares/visitors/visitPeerConnection.d.ts +0 -5
  146. package/lib/middlewares/visitors/visitPeerConnection.d.ts.map +0 -1
  147. package/lib/middlewares/visitors/visitPeerConnection.js +0 -111
  148. package/lib/middlewares/visitors/visitSfu.d.ts +0 -5
  149. package/lib/middlewares/visitors/visitSfu.d.ts.map +0 -1
  150. package/lib/middlewares/visitors/visitSfu.js +0 -78
  151. package/lib/middlewares/visitors/visitSfuInboundRtpPad.d.ts +0 -5
  152. package/lib/middlewares/visitors/visitSfuInboundRtpPad.d.ts.map +0 -1
  153. package/lib/middlewares/visitors/visitSfuInboundRtpPad.js +0 -56
  154. package/lib/middlewares/visitors/visitSfuOutboundRtpPad.d.ts +0 -5
  155. package/lib/middlewares/visitors/visitSfuOutboundRtpPad.d.ts.map +0 -1
  156. package/lib/middlewares/visitors/visitSfuOutboundRtpPad.js +0 -56
  157. package/lib/middlewares/visitors/visitSfuSctpChannel.d.ts +0 -5
  158. package/lib/middlewares/visitors/visitSfuSctpChannel.d.ts.map +0 -1
  159. package/lib/middlewares/visitors/visitSfuSctpChannel.js +0 -55
  160. package/lib/middlewares/visitors/visitSfuTransport.d.ts +0 -5
  161. package/lib/middlewares/visitors/visitSfuTransport.d.ts.map +0 -1
  162. package/lib/middlewares/visitors/visitSfuTransport.js +0 -56
  163. package/lib/processes/closePeerConnectionProcess.d.ts +0 -10
  164. package/lib/processes/closePeerConnectionProcess.d.ts.map +0 -1
  165. package/lib/processes/closePeerConnectionProcess.js +0 -51
  166. package/lib/processes/detachClientProcess.d.ts +0 -14
  167. package/lib/processes/detachClientProcess.d.ts.map +0 -1
  168. package/lib/processes/detachClientProcess.js +0 -106
  169. package/lib/processes/findRemoteMatches.d.ts +0 -9
  170. package/lib/processes/findRemoteMatches.d.ts.map +0 -1
  171. package/lib/processes/findRemoteMatches.js +0 -96
  172. package/lib/processes/inboundTrackRemoved.d.ts +0 -9
  173. package/lib/processes/inboundTrackRemoved.d.ts.map +0 -1
  174. package/lib/processes/inboundTrackRemoved.js +0 -22
  175. package/lib/processes/joinClientProcess.d.ts +0 -11
  176. package/lib/processes/joinClientProcess.d.ts.map +0 -1
  177. package/lib/processes/joinClientProcess.js +0 -120
  178. package/lib/processes/outboundTrackRemoved.d.ts +0 -9
  179. package/lib/processes/outboundTrackRemoved.d.ts.map +0 -1
  180. package/lib/processes/outboundTrackRemoved.js +0 -22
  181. package/lib/samples/ObservedCall.d.ts +0 -17
  182. package/lib/samples/ObservedCall.d.ts.map +0 -1
  183. package/lib/samples/ObservedCall.js +0 -29
  184. package/lib/samples/ObservedCalls.d.ts +0 -19
  185. package/lib/samples/ObservedCalls.d.ts.map +0 -1
  186. package/lib/samples/ObservedCalls.js +0 -113
  187. package/lib/samples/ObservedClient.d.ts +0 -28
  188. package/lib/samples/ObservedClient.d.ts.map +0 -1
  189. package/lib/samples/ObservedClient.js +0 -110
  190. package/lib/samples/ObservedInboundAudioTrack.d.ts +0 -17
  191. package/lib/samples/ObservedInboundAudioTrack.d.ts.map +0 -1
  192. package/lib/samples/ObservedInboundAudioTrack.js +0 -17
  193. package/lib/samples/ObservedInboundVideoTrack.d.ts +0 -17
  194. package/lib/samples/ObservedInboundVideoTrack.d.ts.map +0 -1
  195. package/lib/samples/ObservedInboundVideoTrack.js +0 -17
  196. package/lib/samples/ObservedOutboundAudioTrack.d.ts +0 -16
  197. package/lib/samples/ObservedOutboundAudioTrack.d.ts.map +0 -1
  198. package/lib/samples/ObservedOutboundAudioTrack.js +0 -17
  199. package/lib/samples/ObservedOutboundVideoTrack.d.ts +0 -16
  200. package/lib/samples/ObservedOutboundVideoTrack.d.ts.map +0 -1
  201. package/lib/samples/ObservedOutboundVideoTrack.js +0 -17
  202. package/lib/samples/ObservedPeerConnection.d.ts +0 -47
  203. package/lib/samples/ObservedPeerConnection.d.ts.map +0 -1
  204. package/lib/samples/ObservedPeerConnection.js +0 -130
  205. package/lib/samples/ObservedSfu.d.ts +0 -27
  206. package/lib/samples/ObservedSfu.d.ts.map +0 -1
  207. package/lib/samples/ObservedSfu.js +0 -65
  208. package/lib/samples/ObservedSfuInboundRtpPad.d.ts +0 -15
  209. package/lib/samples/ObservedSfuInboundRtpPad.d.ts.map +0 -1
  210. package/lib/samples/ObservedSfuInboundRtpPad.js +0 -17
  211. package/lib/samples/ObservedSfuOutboundRtpPad.d.ts +0 -15
  212. package/lib/samples/ObservedSfuOutboundRtpPad.d.ts.map +0 -1
  213. package/lib/samples/ObservedSfuOutboundRtpPad.js +0 -17
  214. package/lib/samples/ObservedSfuSctpChannel.d.ts +0 -15
  215. package/lib/samples/ObservedSfuSctpChannel.d.ts.map +0 -1
  216. package/lib/samples/ObservedSfuSctpChannel.js +0 -17
  217. package/lib/samples/ObservedSfuTransport.d.ts +0 -30
  218. package/lib/samples/ObservedSfuTransport.d.ts.map +0 -1
  219. package/lib/samples/ObservedSfuTransport.js +0 -86
  220. package/lib/samples/ObservedSfus.d.ts +0 -16
  221. package/lib/samples/ObservedSfus.d.ts.map +0 -1
  222. package/lib/samples/ObservedSfus.js +0 -72
  223. package/lib/sinks/ObserverSink.d.ts.map +0 -1
  224. package/lib/sinks/callEventReports.d.ts.map +0 -1
  225. package/lib/sources/ObservedCallSource.d.ts +0 -18
  226. package/lib/sources/ObservedCallSource.d.ts.map +0 -1
  227. package/lib/sources/ObservedCallSource.js +0 -2
  228. package/lib/sources/ObservedClientSource.d.ts +0 -19
  229. package/lib/sources/ObservedClientSource.d.ts.map +0 -1
  230. package/lib/sources/ObservedClientSource.js +0 -2
  231. package/lib/sources/ObservedSfuSource.d.ts +0 -15
  232. package/lib/sources/ObservedSfuSource.d.ts.map +0 -1
  233. package/lib/sources/ObservedSfuSource.js +0 -2
  234. package/lib/sources/Sources.d.ts +0 -49
  235. package/lib/sources/Sources.d.ts.map +0 -1
  236. package/lib/sources/Sources.js +0 -213
  237. package/src/Evaluator.ts +0 -229
  238. package/src/common/Semaphore.ts +0 -45
  239. package/src/entries/CallEntry.ts +0 -62
  240. package/src/entries/ClientEntry.ts +0 -106
  241. package/src/entries/InboundTrackEntry.ts +0 -74
  242. package/src/entries/OutboundTrackEntry.ts +0 -72
  243. package/src/entries/PeerConnectionEntry.ts +0 -133
  244. package/src/entries/SfuEntry.ts +0 -62
  245. package/src/entries/SfuInboundRtpPadEntry.ts +0 -46
  246. package/src/entries/SfuOutboundRtpPadEntry.ts +0 -44
  247. package/src/entries/SfuSctpChannelEntry.ts +0 -39
  248. package/src/entries/SfuTransportEntry.ts +0 -109
  249. package/src/evaluators/SetClientsCoordinateEvaluator.ts +0 -78
  250. package/src/middlewares/CallOperationsContext.ts +0 -56
  251. package/src/middlewares/CallProcessor.ts +0 -38
  252. package/src/middlewares/CommitTransactionMiddleware.ts +0 -328
  253. package/src/middlewares/DeleteOutdatedCallEntries.ts +0 -159
  254. package/src/middlewares/DeleteOutdatedSfuEntries.ts +0 -168
  255. package/src/middlewares/Middleware.ts +0 -10
  256. package/src/middlewares/Processor.ts +0 -59
  257. package/src/middlewares/TransactionContext.ts +0 -176
  258. package/src/middlewares/TransactoinProcessor.ts +0 -28
  259. package/src/middlewares/VisitObservedCallsMiddleware.ts +0 -172
  260. package/src/middlewares/VisitObservedSfusMiddleware.ts +0 -203
  261. package/src/middlewares/visitors/visitClient.ts +0 -239
  262. package/src/middlewares/visitors/visitInboundAudioTrack.ts +0 -113
  263. package/src/middlewares/visitors/visitInboundVideoTrack.ts +0 -117
  264. package/src/middlewares/visitors/visitOutboundAudioTrack.ts +0 -100
  265. package/src/middlewares/visitors/visitOutboundVideoTarck.ts +0 -102
  266. package/src/middlewares/visitors/visitPeerConnection.ts +0 -151
  267. package/src/middlewares/visitors/visitSfu.ts +0 -70
  268. package/src/middlewares/visitors/visitSfuInboundRtpPad.ts +0 -52
  269. package/src/middlewares/visitors/visitSfuOutboundRtpPad.ts +0 -53
  270. package/src/middlewares/visitors/visitSfuSctpChannel.ts +0 -50
  271. package/src/middlewares/visitors/visitSfuTransport.ts +0 -50
  272. package/src/processes/closePeerConnectionProcess.ts +0 -54
  273. package/src/processes/detachClientProcess.ts +0 -136
  274. package/src/processes/findRemoteMatches.ts +0 -104
  275. package/src/processes/inboundTrackRemoved.ts +0 -22
  276. package/src/processes/joinClientProcess.ts +0 -138
  277. package/src/processes/outboundTrackRemoved.ts +0 -22
  278. package/src/samples/ObservedCall.ts +0 -49
  279. package/src/samples/ObservedCalls.ts +0 -143
  280. package/src/samples/ObservedClient.ts +0 -172
  281. package/src/samples/ObservedInboundAudioTrack.ts +0 -35
  282. package/src/samples/ObservedInboundVideoTrack.ts +0 -36
  283. package/src/samples/ObservedOutboundAudioTrack.ts +0 -35
  284. package/src/samples/ObservedOutboundVideoTrack.ts +0 -35
  285. package/src/samples/ObservedPeerConnection.ts +0 -227
  286. package/src/samples/ObservedSfu.ts +0 -115
  287. package/src/samples/ObservedSfuInboundRtpPad.ts +0 -35
  288. package/src/samples/ObservedSfuOutboundRtpPad.ts +0 -35
  289. package/src/samples/ObservedSfuSctpChannel.ts +0 -35
  290. package/src/samples/ObservedSfuTransport.ts +0 -142
  291. package/src/samples/ObservedSfus.ts +0 -95
  292. package/src/sources/ObservedCallSource.ts +0 -26
  293. package/src/sources/ObservedClientSource.ts +0 -28
  294. package/src/sources/ObservedSfuSource.ts +0 -19
  295. package/src/sources/Sources.ts +0 -301
  296. /package/lib/{sinks → common}/callEventReports.d.ts +0 -0
  297. /package/lib/{sinks → common}/callEventReports.js +0 -0
  298. /package/src/{sinks → common}/callEventReports.ts +0 -0
package/src/Observer.ts CHANGED
@@ -1,33 +1,17 @@
1
- import { ObserverReportsEmitter, ObserverSinkProcess, SinkConfig, SinkImpl } from './sinks/ObserverSink';
2
- import { Sources, SourcesConfig } from './sources/Sources';
3
- import { createSimpleStorageProvider, StorageProvider } from './storages/StorageProvider';
4
- import { Evaluator, EvaluatorConfig, EvaluatorProcess } from './Evaluator';
5
- import { createSimpleSemaphoreProvider, SemaphoreProvider } from './common/Semaphore';
6
- import { ObservedCallSourceConfig, ObservedCallSource } from './sources/ObservedCallSource';
7
- import { PartialBy, asyncIteratorConverter } from './common/utils';
8
- import { createLogger, LogLevel } from './common/logger';
9
- import { ObservedSfuSource, ObservedSfuSourceConfig } from './sources/ObservedSfuSource';
1
+ import { createLogger } from './common/logger';
2
+ import { StorageProvider, createSimpleStorageProvider } from './storages/StorageProvider';
3
+ import { ObservedCall, ObservedCallConfig } from './ObservedCall';
4
+ import { ReportsCollector } from './ReportsCollector';
10
5
  import { EventEmitter } from 'events';
11
- import { CallEntry, createCallEntry } from './entries/CallEntry';
12
- import { ClientEntry, createClientEntry } from './entries/ClientEntry';
13
- import { PeerConnectionEntry, createPeerConnectionEntry } from './entries/PeerConnectionEntry';
14
- import { InboundTrackEntry, createInboundTrackEntry } from './entries/InboundTrackEntry';
15
- import { OutboundTrackEntry, createOutboundTrackEntry } from './entries/OutboundTrackEntry';
16
- import { SfuEntry, createSfuEntry } from './entries/SfuEntry';
17
- import { SfuTransportEntry, createSfuTransportEntry } from './entries/SfuTransportEntry';
18
- import { SfuInboundRtpPadEntry, createSfuInboundRtpPadEntry } from './entries/SfuInboundRtpPadEntry';
19
- import { SfuOutboundRtpPadEntry, createSfuOutboundRtpPadEntry } from './entries/SfuOutboundRtpPadEntry';
20
- import { SfuSctpChannelEntry, createSfuSctpChannelEntry } from './entries/SfuSctpChannelEntry';
21
- import { GetClientCoordinate, createSetClientsCoordinateEvaluator } from './evaluators/SetClientsCoordinateEvaluator';
6
+ import { PartialBy } from './common/utils';
7
+ import { createCallStartedEventReport } from './common/callEventReports';
22
8
 
23
9
  const logger = createLogger('Observer');
24
10
 
25
11
  export type ObserverEvents = {
26
- 'processing-started': undefined,
27
- 'client-added': string,
28
- 'client-removed': string,
29
- 'processing-ended': undefined,
30
- 'close': undefined,
12
+ 'newcall': [ObservedCall],
13
+ // 'newsfu': [ObservedSfu],
14
+ 'close': [],
31
15
  }
32
16
 
33
17
  export type ObserverConfig = {
@@ -48,28 +32,30 @@ export type ObserverConfig = {
48
32
  */
49
33
  defaultMediaUnitId: string;
50
34
 
51
- /**
52
- * Setup the sources
53
- */
54
- sources: SourcesConfig;
55
- evaluator: EvaluatorConfig;
56
- sink: SinkConfig;
35
+ maxReports?: number | undefined;
36
+ maxCollectingTimeInMs?: number | undefined;
37
+
57
38
  storages?: StorageProvider;
58
- semaphores?: SemaphoreProvider;
59
39
 
60
- logLevel: LogLevel;
40
+ /**
41
+ * before client-monitor-js 3.4.0 the client joined event was generated by the observer, this flag is to keep the compatibility with the old behavior
42
+ */
43
+ addJoinAndDetachClientEvent?: boolean;
61
44
  };
62
45
 
63
- export class Observer {
46
+ export declare interface Observer {
47
+ on<U extends keyof ObserverEvents>(event: U, listener: (...args: ObserverEvents[U]) => void): this;
48
+ off<U extends keyof ObserverEvents>(event: U, listener: (...args: ObserverEvents[U]) => void): this;
49
+ once<U extends keyof ObserverEvents>(event: U, listener: (...args: ObserverEvents[U]) => void): this;
50
+ emit<U extends keyof ObserverEvents>(event: U, ...args: ObserverEvents[U]): boolean;
51
+ }
52
+
53
+ export class Observer extends EventEmitter {
64
54
  public static create(providedConfig: Partial<ObserverConfig>): Observer {
65
55
  const config: ObserverConfig = Object.assign(
66
56
  {
67
57
  defaultServiceId: 'default-service-id',
68
58
  defaultMediaUnitId: 'default-media-unit-id',
69
- sources: {
70
- maxSamples: 1000,
71
- maxTimeInMs: 10000,
72
- },
73
59
  evaluator: {
74
60
  fetchSamples: true,
75
61
  maxIdleTimeInMs: 300 * 1000,
@@ -80,430 +66,73 @@ export class Observer {
80
66
  providedConfig
81
67
  );
82
68
 
83
- const semaphores = providedConfig.semaphores ?? createSimpleSemaphoreProvider();
84
69
  const storages = providedConfig.storages ?? createSimpleStorageProvider();
85
70
 
86
- return new Observer(config, storages, semaphores);
71
+ return new Observer(config, storages);
87
72
  }
88
73
 
89
- private readonly _emitter = new EventEmitter();
90
- private _sources: Sources;
91
- private _sink: SinkImpl;
92
- private _evaluator: Evaluator;
74
+ public readonly reports = new ReportsCollector();
75
+ private readonly _observedCalls = new Map<string, ObservedCall>();
76
+ private _reportTimer?: ReturnType<typeof setTimeout>;
93
77
  private _closed = false;
94
78
  public constructor(
95
79
  public readonly config: ObserverConfig,
96
- private readonly _storages: StorageProvider,
97
- private readonly _semaphores: SemaphoreProvider
80
+ public readonly storage: StorageProvider,
98
81
  ) {
99
- this._sources = new Sources(config.sources);
100
- this._sink = new SinkImpl(config.sink);
101
- this._evaluator = new Evaluator(
102
- this.config.evaluator,
103
- this._semaphores.callSemaphore,
104
- this._storages,
105
- this._sink
106
- );
107
-
108
- this._sources.on('observed-samples', (event) => {
109
- this._emitter.emit('processing-started');
110
- this._evaluator.addObservedSamples(event);
111
- });
112
- this._sources.on('added-client-source', (event) => {
113
- this._evaluator.addCreatedClientSource(event);
114
- this._emitter.emit('client-added', event.clientId);
115
- });
116
- this._sources.on('removed-client-source', (event) => {
117
- this._evaluator.addClosedClientSource(event);
118
- this._emitter.emit('client-added', event.clientId);
119
- });
120
- this._evaluator.on('ready', () => {
121
- this._sink.emit();
122
- this._emitter.emit('processing-ended');
123
- });
82
+ super();
124
83
  logger.debug('Observer is created with config', this.config);
125
- }
126
-
127
- public get sources(): Sources {
128
- return this._sources;
129
- }
130
-
131
- public on<K extends keyof ObserverEvents>(event: K, listener: (arg: ObserverEvents[K]) => void): this {
132
- this._emitter.on(event, listener);
133
-
134
- return this;
135
- }
136
-
137
- public once<K extends keyof ObserverEvents>(event: K, listener: (arg: ObserverEvents[K]) => void): this {
138
- this._emitter.once(event, listener);
139
-
140
- return this;
141
- }
84
+ const onNewReport = (collectedReports: number) => {
85
+ if (!this.config.maxReports || this._closed) return;
86
+ if (this.config.maxReports < collectedReports) {
87
+ this._emitReports();
88
+ }
89
+ };
142
90
 
143
- public off<K extends keyof ObserverEvents>(event: K, listener: (arg: ObserverEvents[K]) => void): this {
144
- this._emitter.off(event, listener);
145
-
146
- return this;
91
+ this.once('close', () => this.reports.off('newreport', onNewReport));
92
+ this.reports.on('newreport', onNewReport);
147
93
  }
148
94
 
149
- public createCallSource<T extends Record<string, unknown> = Record<string, unknown>>(
150
- config: PartialBy<ObservedCallSourceConfig<T>, 'serviceId' | 'mediaUnitId' | 'appData'>
151
- ): ObservedCallSource<T> {
95
+ public async createObservedCall<T extends Record<string, unknown> = Record<string, unknown>>(
96
+ config: PartialBy<ObservedCallConfig<T>, 'serviceId' | 'started'>
97
+ ): Promise<ObservedCall<T>> {
152
98
  if (this._closed) {
153
99
  throw new Error('Attempted to create a call source on a closed observer');
154
100
  }
155
101
 
156
- const {
157
- serviceId = this.config.defaultServiceId,
158
- mediaUnitId = this.config.defaultMediaUnitId,
159
- appData = {} as T,
160
- ...callConfig
161
- } = config;
162
-
163
- return this._sources.createCallSource({
164
- ...callConfig,
165
- appData,
166
- mediaUnitId,
167
- serviceId,
168
- });
169
- }
170
-
171
- public createSfuSource<T extends Record<string, unknown> = Record<string, unknown>>(
172
- config: PartialBy<ObservedSfuSourceConfig<T>, 'serviceId' | 'mediaUnitId' | 'joined' | 'appData'>
173
- ): ObservedSfuSource {
174
- if (this._closed) {
175
- throw new Error('Attempted to create a sfu source on a closed observer');
176
- }
177
- const {
178
- appData = {} as T,
179
- serviceId = this.config.defaultServiceId,
180
- mediaUnitId = this.config.defaultMediaUnitId,
181
- joined = Date.now(),
182
- ...sfuConfig
183
- } = config;
184
-
185
- return this._sources.createSfuSource<T>({
186
- ...sfuConfig,
187
- appData,
188
- serviceId,
189
- mediaUnitId,
190
- joined,
191
- });
192
- }
193
-
194
- public async evaluate() {
195
- return new Promise<void>((resolve, reject) => {
196
- this._evaluator.once('ready', (err) => {
197
- if (err) reject(err);
198
- else resolve();
199
- });
200
- this._sources.emitSamples();
102
+ const call = await ObservedCall.create({
103
+ serviceId: this.config.defaultServiceId,
104
+ started: Date.now(),
105
+ ...config,
106
+ }, this);
107
+
108
+ if (this._closed) throw new Error('Cannot create an observed call on a closed observer');
109
+ if (this._observedCalls.has(call.callId)) throw new Error(`Observed Call with id ${call.callId} already exists`);
110
+
111
+ call.once('close', () => {
112
+ this._observedCalls.delete(call.callId);
113
+ this.reports.addCallEventReport(createCallStartedEventReport(
114
+ call.serviceId,
115
+ call.roomId,
116
+ call.callId,
117
+ Date.now(),
118
+ ));
201
119
  });
202
- }
203
-
204
- public get reports(): ObserverReportsEmitter {
205
- return this._sink;
206
- }
207
-
208
- public addEvaluators(...processes: EvaluatorProcess[]) {
209
- if (this._closed) {
210
- throw new Error('Attempted to add an evaluator to a closed observer');
211
- }
212
- for (const process of processes) {
213
- this._evaluator.addProcess(process);
214
- }
215
- }
216
-
217
- public removeEvaluators(...processes: EvaluatorProcess[]) {
218
- if (this._closed) {
219
- throw new Error('Attempted to remove an evaluator from a closed observer');
220
- }
221
- for (const process of processes) {
222
- this._evaluator.removeProcess(process);
223
- }
224
- }
225
-
226
- public addCoordinateEvaluator(getClientCoordinate: GetClientCoordinate) {
227
- if (this._closed) {
228
- throw new Error('Attempted to add an evaluator to a closed observer');
229
- }
230
- const process = createSetClientsCoordinateEvaluator(getClientCoordinate);
231
-
232
- this._evaluator.addProcess(async (context) => process(context));
233
- }
234
-
235
- public addSinks(...processes: ObserverSinkProcess[]) {
236
- if (this._closed) {
237
- throw new Error('Attempted to add an evaluator to a closed observer');
238
- }
239
- for (const process of processes) {
240
- this._sink.addProcess(process);
241
- }
242
- }
243
-
244
- public removeSinks(...processes: ObserverSinkProcess[]) {
245
- if (this._closed) {
246
- throw new Error('Attempted to remove an evaluator from a closed observer');
247
- }
248
- for (const process of processes) {
249
- this._sink.removeProcess(process);
250
- }
251
- }
252
-
253
- public calls(): AsyncIterableIterator<CallEntry> {
254
- const storageProvider = this._storages;
255
-
256
- return asyncIteratorConverter((async function *() {
257
- for await (const [ , callModel ] of storageProvider.callStorage[Symbol.asyncIterator]()) {
258
- if (!callModel) continue;
259
- yield createCallEntry(storageProvider, callModel);
260
- }
261
- })());
262
- }
263
-
264
- public sfus(): AsyncIterableIterator<SfuEntry> {
265
- const storageProvider = this._storages;
266
-
267
- return asyncIteratorConverter((async function *() {
268
- for await (const [ , sfuModel ] of storageProvider.sfuStorage[Symbol.asyncIterator]()) {
269
- if (!sfuModel) continue;
270
- yield createSfuEntry(storageProvider, sfuModel);
271
- }
272
- })());
273
- }
274
-
275
- public sfuTransports(): AsyncIterableIterator<SfuTransportEntry> {
276
- const storageProvider = this._storages;
277
-
278
- return asyncIteratorConverter((async function *() {
279
- for await (const [ , sfuTransportModel ] of storageProvider.sfuTransportStorage[Symbol.asyncIterator]()) {
280
- if (!sfuTransportModel) continue;
281
- yield createSfuTransportEntry(storageProvider, sfuTransportModel);
282
- }
283
- })());
284
- }
285
-
286
- public sfuInboundRtpPads(): AsyncIterableIterator<SfuInboundRtpPadEntry> {
287
- const storageProvider = this._storages;
288
-
289
- return asyncIteratorConverter((async function *() {
290
- for await (const [ , sfuInboundRtpPadModel ] of storageProvider.sfuInboundRtpPadStorage[Symbol.asyncIterator]()) {
291
- if (!sfuInboundRtpPadModel) continue;
292
- yield createSfuInboundRtpPadEntry(storageProvider, sfuInboundRtpPadModel);
293
- }
294
- })());
295
- }
296
-
297
- public sfuOutboundRtpPads(): AsyncIterableIterator<SfuOutboundRtpPadEntry> {
298
- const storageProvider = this._storages;
299
-
300
- return asyncIteratorConverter((async function *() {
301
- for await (const [ , sfuOutboundRtpPadModel ] of storageProvider.sfuOutboundRtpPadStorage[Symbol.asyncIterator]()) {
302
- if (!sfuOutboundRtpPadModel) continue;
303
- yield createSfuOutboundRtpPadEntry(storageProvider, sfuOutboundRtpPadModel);
304
- }
305
- })());
306
- }
307
-
308
- public clients(): AsyncIterableIterator<ClientEntry> {
309
- const storageProvider = this._storages;
310
-
311
- return asyncIteratorConverter((async function *() {
312
- for await (const [ , callModel ] of storageProvider.clientStorage[Symbol.asyncIterator]()) {
313
- if (!callModel) continue;
314
- yield createClientEntry(storageProvider, callModel);
315
- }
316
- })());
317
- }
318
-
319
- public peerConnections(): AsyncIterableIterator<PeerConnectionEntry> {
320
- const storageProvider = this._storages;
321
120
 
322
- return asyncIteratorConverter((async function *() {
323
- for await (const [ , peerConnectionModel ] of storageProvider.peerConnectionStorage[Symbol.asyncIterator]()) {
324
- if (!peerConnectionModel) continue;
325
- yield createPeerConnectionEntry(storageProvider, peerConnectionModel);
326
- }
327
- })());
328
- }
329
-
330
- public async getTrack(trackId: string) {
331
- const { inboundTrackStorage, outboundTrackStorage } = this._storages;
332
- const [ inbTrackModel, outbTrackModel ] = await Promise.all([
333
- inboundTrackStorage.get(trackId),
334
- outboundTrackStorage.get(trackId),
335
- ]);
336
-
337
- if (inbTrackModel) return createInboundTrackEntry(this._storages, inbTrackModel);
338
- else if (outbTrackModel) return createOutboundTrackEntry(this._storages, outbTrackModel);
339
- }
121
+ this._observedCalls.set(call.callId, call);
122
+ this.reports.addCallEventReport(createCallStartedEventReport(
123
+ call.serviceId,
124
+ call.roomId,
125
+ call.callId,
126
+ call.started,
127
+ ));
340
128
 
341
- public async getAllTracks(trackIds: Iterable<string>) {
342
- const storageProvider = this._storages;
343
- const { inboundTrackStorage, outboundTrackStorage } = this._storages;
129
+ this.emit('newcall', call);
344
130
 
345
- const [ inbTrackModels, outbTrackModels ] = await Promise.all([
346
- inboundTrackStorage.getAll(trackIds),
347
- outboundTrackStorage.getAll(trackIds),
348
- ]);
349
-
350
- const result = new Map<string, InboundTrackEntry | OutboundTrackEntry>();
351
-
352
- for (const [ trackId, model ] of inbTrackModels) {
353
- result.set(trackId, createInboundTrackEntry(storageProvider, model));
354
- }
355
- for (const [ trackId, model ] of outbTrackModels) {
356
- result.set(trackId, createOutboundTrackEntry(storageProvider, model));
357
- }
358
-
359
- return result;
360
- }
361
-
362
- public inboundTracks(): AsyncIterableIterator<InboundTrackEntry> {
363
- const storageProvider = this._storages;
364
-
365
- return asyncIteratorConverter((async function *() {
366
- for await (const [ , inboundTrackModel ] of storageProvider.inboundTrackStorage[Symbol.asyncIterator]()) {
367
- if (!inboundTrackModel) continue;
368
- yield createInboundTrackEntry(storageProvider, inboundTrackModel);
369
- }
370
- })());
371
- }
372
-
373
- public outboundTracks(): AsyncIterableIterator<OutboundTrackEntry> {
374
- const storageProvider = this._storages;
375
-
376
- return asyncIteratorConverter((async function *() {
377
- for await (const [ , outboundTrackModel ] of storageProvider.outboundTrackStorage[Symbol.asyncIterator]()) {
378
- if (!outboundTrackModel) continue;
379
- yield createOutboundTrackEntry(storageProvider, outboundTrackModel);
380
- }
381
- })());
382
- }
383
-
384
- public sfuSctpChannels(): AsyncIterableIterator<SfuSctpChannelEntry> {
385
- const storageProvider = this._storages;
386
-
387
- return asyncIteratorConverter((async function *() {
388
- for await (const [ , sfuSctpChannelModel ] of storageProvider.sfuSctpChannelStorage[Symbol.asyncIterator]()) {
389
- if (!sfuSctpChannelModel) continue;
390
- yield createSfuSctpChannelEntry(storageProvider, sfuSctpChannelModel);
391
- }
392
- })());
393
- }
394
-
395
- public async getCall(callId: string): Promise<CallEntry> {
396
- return createCallEntry(this._storages, await this._storages.callStorage.get(callId));
397
- }
398
-
399
- public async getAllCalls(callIds: Iterable<string>): Promise<ReadonlyMap<string, CallEntry>> {
400
- const models = await this._storages.callStorage.getAll(callIds);
401
-
402
- return new Map(Array.from(models).map(([ callId, model ]) => [ callId, createCallEntry(this._storages, model) ]));
403
- }
404
-
405
- public async getSfu(sfuId: string): Promise<SfuEntry> {
406
- return createSfuEntry(this._storages, await this._storages.sfuStorage.get(sfuId));
407
- }
408
-
409
- public async getAllSfus(sfuIds: Iterable<string>): Promise<ReadonlyMap<string, SfuEntry>> {
410
- const models = await this._storages.sfuStorage.getAll(sfuIds);
411
-
412
- return new Map(Array.from(models).map(([ sfuId, model ]) => [ sfuId, createSfuEntry(this._storages, model) ]));
413
- }
414
-
415
- public async getSfuTransport(sfuTransportId: string): Promise<SfuTransportEntry | undefined> {
416
- return createSfuTransportEntry(this._storages, await this._storages.sfuTransportStorage.get(sfuTransportId));
417
- }
418
-
419
- public async getAllSfuTransports(
420
- sfuTransportIds: Iterable<string>
421
- ): Promise<ReadonlyMap<string, SfuTransportEntry>> {
422
- const models = await this._storages.sfuTransportStorage.getAll(sfuTransportIds);
423
-
424
- return new Map(Array.from(models).map(([ sfuTransportId, model ]) => [ sfuTransportId, createSfuTransportEntry(this._storages, model) ]));
425
- }
426
-
427
- public async getSfuInboundRtpPad(sfuInboundRtpPadId: string): Promise<SfuInboundRtpPadEntry | undefined> {
428
- return createSfuInboundRtpPadEntry(this._storages, await this._storages.sfuInboundRtpPadStorage.get(sfuInboundRtpPadId));
131
+ return call;
429
132
  }
430
133
 
431
- public async getAllSfuInboundRtpPads(
432
- sfuInboundRtpPadIds: Iterable<string>
433
- ): Promise<ReadonlyMap<string, SfuInboundRtpPadEntry>> {
434
- const models = await this._storages.sfuInboundRtpPadStorage.getAll(sfuInboundRtpPadIds);
435
-
436
- return new Map(Array.from(models).map(([ sfuInboundRtpPadId, model ]) => [ sfuInboundRtpPadId, createSfuInboundRtpPadEntry(this._storages, model) ]));
437
- }
438
-
439
- public async getSfuOutboundRtpPad(sfuOutboundRtpPadId: string): Promise<SfuOutboundRtpPadEntry | undefined> {
440
- return createSfuOutboundRtpPadEntry(this._storages, await this._storages.sfuOutboundRtpPadStorage.get(sfuOutboundRtpPadId));
441
- }
442
-
443
- public async getAllSfuOutboundRtpPads(
444
- sfuOutboundRtpPadIds: Iterable<string>
445
- ): Promise<ReadonlyMap<string, SfuOutboundRtpPadEntry>> {
446
- const models = await this._storages.sfuOutboundRtpPadStorage.getAll(sfuOutboundRtpPadIds);
447
-
448
- return new Map(Array.from(models).map(([ sfuOutboundRtpPadId, model ]) => [ sfuOutboundRtpPadId, createSfuOutboundRtpPadEntry(this._storages, model) ]));
449
- }
450
-
451
- public async getClient(clientId: string): Promise<ClientEntry> {
452
- return createClientEntry(this._storages, await this._storages.clientStorage.get(clientId));
453
- }
454
-
455
- public async getAllClient(clientIds: Iterable<string>): Promise<ReadonlyMap<string, ClientEntry>> {
456
- const models = await this._storages.clientStorage.getAll(clientIds);
457
-
458
- return new Map(Array.from(models).map(([ clientId, model ]) => [ clientId, createClientEntry(this._storages, model) ]));
459
- }
460
-
461
- public async getPeerConnection(peerConnectionId: string): Promise<PeerConnectionEntry> {
462
- return createPeerConnectionEntry(this._storages, await this._storages.peerConnectionStorage.get(peerConnectionId));
463
- }
464
-
465
- public async getAllPeerConnections(
466
- peerConnectionIds: Iterable<string>
467
- ): Promise<ReadonlyMap<string, PeerConnectionEntry>> {
468
- const models = await this._storages.peerConnectionStorage.getAll(peerConnectionIds);
469
-
470
- return new Map(Array.from(models).map(([ peerConnectionId, model ]) => [ peerConnectionId, createPeerConnectionEntry(this._storages, model) ]));
471
- }
472
-
473
- public async getInboundTrack(inboundTrackId: string): Promise<InboundTrackEntry> {
474
- return createInboundTrackEntry(this._storages, await this._storages.inboundTrackStorage.get(inboundTrackId));
475
- }
476
-
477
- public async getAllInboundTracks(
478
- inboundTrackIds: Iterable<string>
479
- ): Promise<ReadonlyMap<string, InboundTrackEntry>> {
480
- const models = await this._storages.inboundTrackStorage.getAll(inboundTrackIds);
481
-
482
- return new Map(Array.from(models).map(([ inboundTrackId, model ]) => [ inboundTrackId, createInboundTrackEntry(this._storages, model) ]));
483
- }
484
-
485
- public async getOutboundTrack(outboundTrackId: string): Promise<OutboundTrackEntry> {
486
- return createOutboundTrackEntry(this._storages, await this._storages.outboundTrackStorage.get(outboundTrackId));
487
- }
488
-
489
- public async getAllOutboundTracks(
490
- outboundTrackIds: Iterable<string>
491
- ): Promise<ReadonlyMap<string, OutboundTrackEntry>> {
492
- const models = await this._storages.outboundTrackStorage.getAll(outboundTrackIds);
493
-
494
- return new Map(Array.from(models).map(([ outboundTrackId, model ]) => [ outboundTrackId, createOutboundTrackEntry(this._storages, model) ]));
495
- }
496
-
497
- public async getSfuSctpChannel(sctpChannelId: string): Promise<SfuSctpChannelEntry | undefined> {
498
- return createSfuSctpChannelEntry(this._storages, await this._storages.sfuSctpChannelStorage.get(sctpChannelId));
499
- }
500
-
501
- public async getAllSfuSctpChannel(
502
- sctpChannelIds: Iterable<string>
503
- ): Promise<ReadonlyMap<string, SfuSctpChannelEntry>> {
504
- const models = await this._storages.sfuSctpChannelStorage.getAll(sctpChannelIds);
505
-
506
- return new Map(Array.from(models).map(([ sctpChannelId, model ]) => [ sctpChannelId, createSfuSctpChannelEntry(this._storages, model) ]));
134
+ public get observedCalls(): ReadonlyMap<string, ObservedCall> {
135
+ return this._observedCalls;
507
136
  }
508
137
 
509
138
  public get closed() {
@@ -515,8 +144,23 @@ export class Observer {
515
144
  return logger.debug('Attempted to close twice');
516
145
  }
517
146
  this._closed = true;
518
- this._sources.close();
519
147
 
520
- this._emitter.emit('close');
148
+ this.emit('close');
149
+ }
150
+
151
+ private _emitReports() {
152
+ if (this._reportTimer) {
153
+ clearTimeout(this._reportTimer);
154
+ this._reportTimer = undefined;
155
+ }
156
+
157
+ this.reports.emit();
158
+
159
+ if (this.config.maxCollectingTimeInMs) {
160
+ this._reportTimer = setTimeout(() => {
161
+ this._reportTimer = undefined;
162
+ this._emitReports();
163
+ }, this.config.maxCollectingTimeInMs);
164
+ }
521
165
  }
522
166
  }