@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
@@ -0,0 +1,487 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __rest = (this && this.__rest) || function (s, e) {
35
+ var t = {};
36
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
37
+ t[p] = s[p];
38
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
39
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
40
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
41
+ t[p[i]] = s[p[i]];
42
+ }
43
+ return t;
44
+ };
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ exports.ObservedClient = void 0;
47
+ const Models = __importStar(require("./models/Models"));
48
+ const events_1 = require("events");
49
+ const SingleExecutor_1 = require("./common/SingleExecutor");
50
+ const ObservedPeerConnection_1 = require("./ObservedPeerConnection");
51
+ const logger_1 = require("./common/logger");
52
+ const callMetaReports_1 = require("./common/callMetaReports");
53
+ // eslint-disable-next-line camelcase
54
+ const samples_pb_1 = require("./models/samples_pb");
55
+ const utils_1 = require("./common/utils");
56
+ const logger = (0, logger_1.createLogger)('ObservedClient');
57
+ class ObservedClient extends events_1.EventEmitter {
58
+ static create(config, call, storageProvider) {
59
+ var _a, _b;
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ const { callId, clientId, mediaUnitId } = config;
62
+ const model = new Models.Client({
63
+ roomId: call.roomId,
64
+ serviceId: call.serviceId,
65
+ callId,
66
+ clientId,
67
+ mediaUnitId,
68
+ peerConnectionIds: [],
69
+ joined: BigInt((_a = config.joined) !== null && _a !== void 0 ? _a : Date.now()),
70
+ });
71
+ const result = new ObservedClient(model, call, storageProvider, config.appData);
72
+ const alreadyInserted = yield storageProvider.clientStorage.insert(clientId, model);
73
+ if (alreadyInserted)
74
+ throw new Error(`Client with id ${clientId} already exists`);
75
+ result._overflowingProcessingThreshold = (_b = config.overflowingProcessingThreshold) !== null && _b !== void 0 ? _b : 0;
76
+ return result;
77
+ });
78
+ }
79
+ constructor(_model, call, _storageProvider, appData) {
80
+ super();
81
+ this._model = _model;
82
+ this.call = call;
83
+ this._storageProvider = _storageProvider;
84
+ this.appData = appData;
85
+ this._peerConnections = new Map();
86
+ this._execute = (0, SingleExecutor_1.createSingleExecutor)();
87
+ this._overflowingProcessingThreshold = 0;
88
+ this._closed = false;
89
+ this._updated = Date.now();
90
+ this._acceptedSample = 0;
91
+ this._processingSample = 0;
92
+ this.mediaDevices = [];
93
+ this.codecs = [];
94
+ this.userMediaErrors = [];
95
+ }
96
+ get joined() {
97
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
98
+ return Number(this._model.joined);
99
+ }
100
+ get clientId() {
101
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
102
+ return this._model.clientId;
103
+ }
104
+ get roomId() {
105
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
106
+ return this._model.roomId;
107
+ }
108
+ get serviceId() {
109
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
110
+ return this._model.serviceId;
111
+ }
112
+ get callId() {
113
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
114
+ return this._model.callId;
115
+ }
116
+ get mediaUnitId() {
117
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
118
+ return this._model.mediaUnitId;
119
+ }
120
+ get reports() {
121
+ return this.call.reports;
122
+ }
123
+ get userId() {
124
+ return this._model.userId;
125
+ }
126
+ get iceLocalCandidate() {
127
+ return this._iceLocalCandidate;
128
+ }
129
+ get iceRemoteCandidate() {
130
+ return this._iceRemoteCandidate;
131
+ }
132
+ get marker() {
133
+ return this._model.marker;
134
+ }
135
+ get browser() {
136
+ return this._model.browser;
137
+ }
138
+ get engine() {
139
+ return this._model.engine;
140
+ }
141
+ get operationSystem() {
142
+ return this._model.operationSystem;
143
+ }
144
+ get platform() {
145
+ return this._model.platform;
146
+ }
147
+ get acceptedSample() {
148
+ return this._acceptedSample;
149
+ }
150
+ get updated() {
151
+ return this._updated;
152
+ }
153
+ get closed() {
154
+ return this._closed;
155
+ }
156
+ get peerConnections() {
157
+ return this._peerConnections;
158
+ }
159
+ close() {
160
+ if (this._closed)
161
+ return;
162
+ this._closed = true;
163
+ Array.from(this._peerConnections.values()).forEach((peerConnection) => peerConnection.close());
164
+ this._execute(() => this._storageProvider.clientStorage.remove(this.clientId))
165
+ .catch(() => void 0)
166
+ .finally(() => this.emit('close'));
167
+ }
168
+ accept(sample) {
169
+ return __awaiter(this, void 0, void 0, function* () {
170
+ if (this._closed)
171
+ throw new Error(`Client ${this.clientId} is closed`);
172
+ if (sample.clientId && sample.clientId !== 'NULL' && sample.clientId !== this.clientId) {
173
+ throw new Error(`Sample client id (${sample.clientId}) does not match the client id of the observed client (${this.clientId})`);
174
+ }
175
+ ++this._acceptedSample;
176
+ ++this._processingSample;
177
+ if (0 < this._overflowingProcessingThreshold && this._overflowingProcessingThreshold < this._processingSample) {
178
+ this.emit('processing-sample-overflow');
179
+ }
180
+ return this._execute(() => __awaiter(this, void 0, void 0, function* () {
181
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16;
182
+ let executeSave = false;
183
+ if (this.userId !== sample.userId) {
184
+ this._model.userId = sample.userId;
185
+ executeSave = true;
186
+ }
187
+ if (this._model.marker !== sample.marker) {
188
+ this._model.marker = sample.marker;
189
+ executeSave = true;
190
+ }
191
+ if (sample.os && (((_a = this._model.operationSystem) === null || _a === void 0 ? void 0 : _a.name) !== sample.os.name ||
192
+ ((_b = this._model.operationSystem) === null || _b === void 0 ? void 0 : _b.version) !== sample.os.version ||
193
+ ((_c = this._model.operationSystem) === null || _c === void 0 ? void 0 : _c.versionName) !== sample.os.versionName)) {
194
+ this._model.operationSystem = new samples_pb_1.Samples_ClientSample_OperationSystem(Object.assign({}, sample.os));
195
+ const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
196
+ type: callMetaReports_1.CallMetaType.OPERATION_SYSTEM,
197
+ payload: sample.os,
198
+ }, this.userId);
199
+ this.reports.addCallMetaReport(callMetaReport);
200
+ executeSave = true;
201
+ }
202
+ if (sample.engine && (((_d = this._model.engine) === null || _d === void 0 ? void 0 : _d.name) !== sample.engine.name ||
203
+ ((_e = this._model.engine) === null || _e === void 0 ? void 0 : _e.version) !== sample.engine.version)) {
204
+ this._model.engine = new samples_pb_1.Samples_ClientSample_Engine(Object.assign({}, sample.engine));
205
+ const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
206
+ type: callMetaReports_1.CallMetaType.ENGINE,
207
+ payload: sample.engine,
208
+ }, this.userId);
209
+ this.reports.addCallMetaReport(callMetaReport);
210
+ executeSave = true;
211
+ }
212
+ if (sample.platform && (((_f = this._model.platform) === null || _f === void 0 ? void 0 : _f.model) !== sample.platform.model ||
213
+ ((_g = this._model.platform) === null || _g === void 0 ? void 0 : _g.type) !== sample.platform.type ||
214
+ ((_h = this._model.platform) === null || _h === void 0 ? void 0 : _h.vendor) !== sample.platform.vendor)) {
215
+ this._model.platform = new samples_pb_1.Samples_ClientSample_Platform(Object.assign({}, sample.platform));
216
+ const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
217
+ type: callMetaReports_1.CallMetaType.PLATFORM,
218
+ payload: sample.platform,
219
+ }, this.userId);
220
+ this.reports.addCallMetaReport(callMetaReport);
221
+ executeSave = true;
222
+ }
223
+ if (sample.browser && (((_j = this._model.browser) === null || _j === void 0 ? void 0 : _j.name) !== sample.browser.name ||
224
+ ((_k = this._model.browser) === null || _k === void 0 ? void 0 : _k.version) !== sample.browser.version)) {
225
+ this._model.browser = new samples_pb_1.Samples_ClientSample_Browser(Object.assign({}, sample.browser));
226
+ const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
227
+ type: callMetaReports_1.CallMetaType.BROWSER,
228
+ payload: sample.browser,
229
+ }, this.userId);
230
+ this.reports.addCallMetaReport(callMetaReport);
231
+ executeSave = true;
232
+ }
233
+ for (const mediaConstraint of (_l = sample.mediaConstraints) !== null && _l !== void 0 ? _l : []) {
234
+ const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
235
+ type: callMetaReports_1.CallMetaType.MEDIA_CONSTRAINT,
236
+ payload: mediaConstraint,
237
+ }, this.userId);
238
+ this.reports.addCallMetaReport(callMetaReport);
239
+ }
240
+ for (const localSDP of (_m = sample.localSDPs) !== null && _m !== void 0 ? _m : []) {
241
+ const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
242
+ type: callMetaReports_1.CallMetaType.LOCAL_SDP,
243
+ payload: localSDP,
244
+ }, this.userId);
245
+ this.reports.addCallMetaReport(callMetaReport);
246
+ }
247
+ for (const extensionStats of (_o = sample.extensionStats) !== null && _o !== void 0 ? _o : []) {
248
+ this.reports.addClientExtensionReport({
249
+ serviceId: this.serviceId,
250
+ mediaUnitId: this.mediaUnitId,
251
+ roomId: this.roomId,
252
+ callId: this.callId,
253
+ clientId: this.clientId,
254
+ userId: this.userId,
255
+ timestamp: Date.now(),
256
+ payload: extensionStats.payload,
257
+ extensionType: extensionStats.type,
258
+ });
259
+ }
260
+ for (let _17 of (_p = sample.customCallEvents) !== null && _p !== void 0 ? _p : []) {
261
+ const { timestamp = Date.now() } = _17, callEvent = __rest(_17, ["timestamp"]);
262
+ this.reports.addCallEventReport(Object.assign({ serviceId: this.serviceId, mediaUnitId: this.mediaUnitId, roomId: this.roomId, callId: this.callId, clientId: this.clientId, userId: this.userId, timestamp }, callEvent));
263
+ }
264
+ for (const userMediaError of (_q = sample.userMediaErrors) !== null && _q !== void 0 ? _q : []) {
265
+ const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
266
+ type: callMetaReports_1.CallMetaType.USER_MEDIA_ERROR,
267
+ payload: userMediaError,
268
+ }, this.userId);
269
+ this.reports.addCallMetaReport(callMetaReport);
270
+ this.userMediaErrors.push(userMediaError);
271
+ }
272
+ for (const certificate of (_r = sample.certificates) !== null && _r !== void 0 ? _r : []) {
273
+ const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
274
+ type: callMetaReports_1.CallMetaType.CERTIFICATE,
275
+ payload: certificate,
276
+ }, this.userId);
277
+ this.reports.addCallMetaReport(callMetaReport);
278
+ }
279
+ for (const codec of (_s = sample.codecs) !== null && _s !== void 0 ? _s : []) {
280
+ const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
281
+ type: callMetaReports_1.CallMetaType.CODEC,
282
+ payload: codec,
283
+ }, this.userId);
284
+ this.reports.addCallMetaReport(callMetaReport);
285
+ codec.mimeType && this.codecs.push(codec.mimeType);
286
+ }
287
+ for (const iceServer of (_t = sample.iceServers) !== null && _t !== void 0 ? _t : []) {
288
+ const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
289
+ type: callMetaReports_1.CallMetaType.ICE_SERVER,
290
+ payload: iceServer,
291
+ }, this.userId);
292
+ this.reports.addCallMetaReport(callMetaReport);
293
+ }
294
+ for (const mediaDevice of (_u = sample.mediaDevices) !== null && _u !== void 0 ? _u : []) {
295
+ const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
296
+ type: callMetaReports_1.CallMetaType.MEDIA_DEVICE,
297
+ payload: mediaDevice,
298
+ }, this.userId);
299
+ this.reports.addCallMetaReport(callMetaReport);
300
+ mediaDevice.label && this.mediaDevices.push(mediaDevice.label);
301
+ }
302
+ for (const mediaSource of (_v = sample.mediaSources) !== null && _v !== void 0 ? _v : []) {
303
+ const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
304
+ type: callMetaReports_1.CallMetaType.MEDIA_SOURCE,
305
+ payload: mediaSource,
306
+ }, this.userId);
307
+ this.reports.addCallMetaReport(callMetaReport);
308
+ }
309
+ let selectedLocalCandidateId;
310
+ let selectedRemoteCandidateId;
311
+ for (const candidatePair of (_w = sample.iceCandidatePairs) !== null && _w !== void 0 ? _w : []) {
312
+ if (candidatePair.nominated) {
313
+ if (!selectedLocalCandidateId)
314
+ selectedLocalCandidateId = candidatePair.localCandidateId;
315
+ if (!selectedRemoteCandidateId)
316
+ selectedRemoteCandidateId = candidatePair.remoteCandidateId;
317
+ }
318
+ const report = Object.assign(Object.assign({ serviceId: this.serviceId, mediaUnitId: this.mediaUnitId, roomId: this.roomId, callId: this.callId, clientId: this.clientId, userId: this.userId, timestamp: sample.timestamp }, candidatePair), { sampleSeq: -1 });
319
+ this.reports.addIceCandidatePairReport(report);
320
+ }
321
+ let changeIceCandidatePair = false;
322
+ for (const iceLocalCandidate of (_x = sample.iceLocalCandidates) !== null && _x !== void 0 ? _x : []) {
323
+ if (iceLocalCandidate.id && selectedLocalCandidateId &&
324
+ iceLocalCandidate.id === selectedLocalCandidateId &&
325
+ ((_y = this._iceLocalCandidate) === null || _y === void 0 ? void 0 : _y.id) !== iceLocalCandidate.id) {
326
+ this._iceLocalCandidate = iceLocalCandidate;
327
+ changeIceCandidatePair = true;
328
+ }
329
+ const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
330
+ type: callMetaReports_1.CallMetaType.ICE_LOCAL_CANDIDATE,
331
+ payload: iceLocalCandidate,
332
+ }, this.userId);
333
+ this.reports.addCallMetaReport(callMetaReport);
334
+ }
335
+ for (const iceRemoteCandidate of (_z = sample.iceRemoteCandidates) !== null && _z !== void 0 ? _z : []) {
336
+ if (iceRemoteCandidate.id && selectedRemoteCandidateId &&
337
+ iceRemoteCandidate.id === selectedRemoteCandidateId &&
338
+ ((_0 = this._iceRemoteCandidate) === null || _0 === void 0 ? void 0 : _0.id) !== iceRemoteCandidate.id) {
339
+ this._iceRemoteCandidate = iceRemoteCandidate;
340
+ changeIceCandidatePair = true;
341
+ }
342
+ const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
343
+ type: callMetaReports_1.CallMetaType.ICE_REMOTE_CANDIDATE,
344
+ payload: iceRemoteCandidate,
345
+ }, this.userId);
346
+ this.reports.addCallMetaReport(callMetaReport);
347
+ }
348
+ for (const transport of (_1 = sample.pcTransports) !== null && _1 !== void 0 ? _1 : []) {
349
+ try {
350
+ const peerConnection = (_2 = this._peerConnections.get(transport.transportId)) !== null && _2 !== void 0 ? _2 : yield this._createPeerConnection(transport.peerConnectionId);
351
+ peerConnection.update(transport, sample.timestamp);
352
+ }
353
+ catch (err) {
354
+ logger.error(`Error creating peer connection: ${err === null || err === void 0 ? void 0 : err.message}`);
355
+ }
356
+ }
357
+ for (const track of (_3 = sample.inboundAudioTracks) !== null && _3 !== void 0 ? _3 : []) {
358
+ if (!track.peerConnectionId || !track.trackId) {
359
+ logger.warn(`InboundAudioTrack without peerConnectionId or trackId: ${JSON.stringify(track)}`);
360
+ continue;
361
+ }
362
+ try {
363
+ const peerConnection = (_4 = this._peerConnections.get(track.peerConnectionId)) !== null && _4 !== void 0 ? _4 : yield this._createPeerConnection(track.peerConnectionId);
364
+ if (!peerConnection)
365
+ continue;
366
+ const inboundAudioTrack = (_5 = peerConnection.inboundAudioTracks.get(track.trackId)) !== null && _5 !== void 0 ? _5 : yield peerConnection.createInboundAudioTrack({
367
+ trackId: track.trackId,
368
+ sfuStreamId: track.sfuStreamId,
369
+ sfuSinkId: track.sfuSinkId,
370
+ });
371
+ yield inboundAudioTrack.update(track, sample.timestamp);
372
+ const remoteOutboundTrack = this.call.sfuStreamIdToOutboundAudioTrack.get((_6 = track.sfuStreamId) !== null && _6 !== void 0 ? _6 : '');
373
+ if (remoteOutboundTrack && inboundAudioTrack.sfuStreamId && !remoteOutboundTrack.remoteInboundTracks.has(inboundAudioTrack.sfuStreamId)) {
374
+ remoteOutboundTrack.connectInboundTrack(inboundAudioTrack);
375
+ }
376
+ }
377
+ catch (err) {
378
+ logger.error(`Error creating inbound audio track: ${err === null || err === void 0 ? void 0 : err.message}`);
379
+ }
380
+ }
381
+ for (const track of (_7 = sample.inboundVideoTracks) !== null && _7 !== void 0 ? _7 : []) {
382
+ if (!track.peerConnectionId || !track.trackId) {
383
+ logger.warn(`InboundVideoTrack without peerConnectionId or trackId: ${JSON.stringify(track)}`);
384
+ continue;
385
+ }
386
+ if ((0, utils_1.isValidUuid)(track.trackId) === false) {
387
+ // mediasoup-probator trackId is not a valid UUID, no need to warn about it
388
+ if (track.trackId === 'probator')
389
+ continue;
390
+ logger.warn(`InboundVideoTrack with invalid trackId: ${track.trackId}`);
391
+ continue;
392
+ }
393
+ try {
394
+ const peerConnection = (_8 = this._peerConnections.get(track.peerConnectionId)) !== null && _8 !== void 0 ? _8 : yield this._createPeerConnection(track.peerConnectionId);
395
+ if (!peerConnection)
396
+ continue;
397
+ const inboundVideoTrack = (_9 = peerConnection.inboundVideoTracks.get(track.trackId)) !== null && _9 !== void 0 ? _9 : yield peerConnection.createInboundVideoTrack({
398
+ trackId: track.trackId,
399
+ sfuStreamId: track.sfuStreamId,
400
+ sfuSinkId: track.sfuSinkId,
401
+ });
402
+ yield inboundVideoTrack.update(track, sample.timestamp);
403
+ const remoteOutboundTrack = this.call.sfuStreamIdToOutboundVideoTrack.get((_10 = inboundVideoTrack.sfuStreamId) !== null && _10 !== void 0 ? _10 : '');
404
+ if (remoteOutboundTrack && inboundVideoTrack.sfuStreamId && !remoteOutboundTrack.remoteInboundTracks.has(inboundVideoTrack.sfuStreamId)) {
405
+ remoteOutboundTrack.connectInboundTrack(inboundVideoTrack);
406
+ }
407
+ }
408
+ catch (err) {
409
+ logger.error(`Error creating inbound video track: ${err === null || err === void 0 ? void 0 : err.message}`);
410
+ }
411
+ }
412
+ for (const track of (_11 = sample.outboundAudioTracks) !== null && _11 !== void 0 ? _11 : []) {
413
+ if (!track.peerConnectionId || !track.trackId) {
414
+ logger.warn(`OutboundAudioTrack without peerConnectionId or trackId: ${JSON.stringify(track)}`);
415
+ continue;
416
+ }
417
+ try {
418
+ const peerConnection = (_12 = this._peerConnections.get(track.peerConnectionId)) !== null && _12 !== void 0 ? _12 : yield this._createPeerConnection(track.peerConnectionId);
419
+ if (!peerConnection)
420
+ continue;
421
+ const outboundAudioTrack = (_13 = peerConnection.outboundAudioTracks.get(track.trackId)) !== null && _13 !== void 0 ? _13 : yield peerConnection.createOutboundAudioTrack({
422
+ trackId: track.trackId,
423
+ sfuStreamId: track.sfuStreamId,
424
+ });
425
+ yield outboundAudioTrack.update(track, sample.timestamp);
426
+ }
427
+ catch (err) {
428
+ logger.error(`Error creating outbound audio track: ${err === null || err === void 0 ? void 0 : err.message}`);
429
+ }
430
+ }
431
+ for (const track of (_14 = sample.outboundVideoTracks) !== null && _14 !== void 0 ? _14 : []) {
432
+ if (!track.peerConnectionId || !track.trackId) {
433
+ logger.warn(`OutboundVideoTrack without peerConnectionId or trackId: ${JSON.stringify(track)}`);
434
+ continue;
435
+ }
436
+ try {
437
+ const peerConnection = (_15 = this._peerConnections.get(track.peerConnectionId)) !== null && _15 !== void 0 ? _15 : yield this._createPeerConnection(track.peerConnectionId);
438
+ if (!peerConnection)
439
+ continue;
440
+ const outboundVideoTrack = (_16 = peerConnection.outboundVideoTracks.get(track.trackId)) !== null && _16 !== void 0 ? _16 : yield peerConnection.createOutboundVideoTrack({
441
+ trackId: track.trackId,
442
+ sfuStreamId: track.sfuStreamId,
443
+ });
444
+ yield outboundVideoTrack.update(track, sample.timestamp);
445
+ }
446
+ catch (err) {
447
+ logger.error(`Error creating outbound video track: ${err === null || err === void 0 ? void 0 : err.message}`);
448
+ }
449
+ }
450
+ if (changeIceCandidatePair) {
451
+ this.emit('candidate-pair-change');
452
+ }
453
+ if (executeSave)
454
+ yield this._save();
455
+ this._updated = sample.timestamp;
456
+ this.emit('update');
457
+ })).finally(() => {
458
+ --this._processingSample;
459
+ });
460
+ });
461
+ }
462
+ _createPeerConnection(peerConnectionId) {
463
+ return __awaiter(this, void 0, void 0, function* () {
464
+ const result = yield ObservedPeerConnection_1.ObservedPeerConnection.create({
465
+ peerConnectionId,
466
+ }, this, this._storageProvider);
467
+ result.once('close', () => {
468
+ this._peerConnections.delete(peerConnectionId);
469
+ this._model.peerConnectionIds = this._model.peerConnectionIds.filter((id) => id !== peerConnectionId);
470
+ this._save().catch(() => void 0);
471
+ });
472
+ this._peerConnections.set(peerConnectionId, result);
473
+ this._model.peerConnectionIds.push(peerConnectionId);
474
+ yield this._save();
475
+ this.emit('newpeerconnection', result);
476
+ return result;
477
+ });
478
+ }
479
+ _save() {
480
+ return __awaiter(this, void 0, void 0, function* () {
481
+ if (this._closed)
482
+ throw new Error(`Client ${this.clientId} is closed`);
483
+ return this._storageProvider.clientStorage.set(this.clientId, this._model);
484
+ });
485
+ }
486
+ }
487
+ exports.ObservedClient = ObservedClient;
@@ -0,0 +1,65 @@
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from 'events';
3
+ import { StorageProvider } from './storages/StorageProvider';
4
+ import { ObservedPeerConnection } from './ObservedPeerConnection';
5
+ import { InboundAudioTrack, InboundVideoTrack } from '@observertc/sample-schemas-js';
6
+ import { ObservedOutboundTrack } from './ObservedOutboundTrack';
7
+ import { MediaKind } from './common/types';
8
+ export type ObservedInboundTrackConfig<K extends MediaKind> = {
9
+ trackId: string;
10
+ kind: K;
11
+ sfuStreamId?: string;
12
+ sfuSinkId?: string;
13
+ };
14
+ export type ObservedInboundTrackEvents<K extends MediaKind> = {
15
+ update: [];
16
+ close: [];
17
+ remoteoutboundtrack: [ObservedOutboundTrack<K>];
18
+ };
19
+ export type ObservedInboundTrackStatsUpdate<K extends MediaKind> = K extends 'audio' ? InboundAudioTrack : InboundVideoTrack;
20
+ export type ObservedInboundTrackStats<K extends MediaKind> = ObservedInboundTrackStatsUpdate<K> & {
21
+ ssrc: number;
22
+ bitrate: number;
23
+ fractionLost: number;
24
+ rttInMs?: number;
25
+ };
26
+ export declare interface ObservedInboundTrack<Kind extends MediaKind> {
27
+ on<U extends keyof ObservedInboundTrackEvents<Kind>>(event: U, listener: (...args: ObservedInboundTrackEvents<Kind>[U]) => void): this;
28
+ off<U extends keyof ObservedInboundTrackEvents<Kind>>(event: U, listener: (...args: ObservedInboundTrackEvents<Kind>[U]) => void): this;
29
+ once<U extends keyof ObservedInboundTrackEvents<Kind>>(event: U, listener: (...args: ObservedInboundTrackEvents<Kind>[U]) => void): this;
30
+ emit<U extends keyof ObservedInboundTrackEvents<Kind>>(event: U, ...args: ObservedInboundTrackEvents<Kind>[U]): boolean;
31
+ update(sample: ObservedInboundTrackStatsUpdate<Kind>, timestamp: number): void;
32
+ }
33
+ export declare class ObservedInboundTrack<Kind extends MediaKind> extends EventEmitter {
34
+ private readonly _model;
35
+ readonly peerConnection: ObservedPeerConnection;
36
+ private readonly _storageProvider;
37
+ static create<K extends MediaKind>(config: ObservedInboundTrackConfig<K>, peerConnection: ObservedPeerConnection, storageProvider: StorageProvider): Promise<ObservedInboundTrack<K>>;
38
+ private readonly _stats;
39
+ private readonly _execute;
40
+ private _closed;
41
+ private _updated;
42
+ private _remoteOutboundTrack?;
43
+ bitrate: number;
44
+ rttInMs: number;
45
+ private constructor();
46
+ get serviceId(): string;
47
+ get roomId(): string;
48
+ get callId(): string;
49
+ get clientId(): string;
50
+ get mediaUnitId(): string;
51
+ get peerConnectionId(): string;
52
+ get trackId(): string;
53
+ get kind(): Kind;
54
+ get sfuStreamId(): string | undefined;
55
+ get sfuSinkId(): string | undefined;
56
+ get updated(): number;
57
+ get stats(): ReadonlyMap<number, ObservedInboundTrackStats<Kind>>;
58
+ get reports(): import("./ReportsCollector").ReportsCollector;
59
+ set remoteOutboundTrack(track: ObservedOutboundTrack<Kind> | undefined);
60
+ get remoteOutboundTrack(): ObservedOutboundTrack<Kind> | undefined;
61
+ get closed(): boolean;
62
+ close(): void;
63
+ private _save;
64
+ }
65
+ //# sourceMappingURL=ObservedInboundTrack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ObservedInboundTrack.d.ts","sourceRoot":"","sources":["../src/ObservedInboundTrack.ts"],"names":[],"mappings":"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"}