@observertc/observer-js 0.9.20-beta → 0.9.22-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 (212) hide show
  1. package/.eslintrc.json +143 -0
  2. package/lib/Evaluator.d.ts.map +1 -1
  3. package/lib/Evaluator.js +54 -47
  4. package/lib/Observer.d.ts +1408 -38
  5. package/lib/Observer.d.ts.map +1 -1
  6. package/lib/Observer.js +484 -180
  7. package/lib/common/Semaphore.d.ts.map +1 -1
  8. package/lib/common/callMetaReports.d.ts.map +1 -1
  9. package/lib/common/callMetaReports.js +1 -0
  10. package/lib/common/logger.d.ts.map +1 -1
  11. package/lib/common/logger.js +15 -15
  12. package/lib/common/utils.d.ts +1 -0
  13. package/lib/common/utils.d.ts.map +1 -1
  14. package/lib/common/utils.js +12 -1
  15. package/lib/entries/CallEntry.d.ts +611 -0
  16. package/lib/entries/CallEntry.d.ts.map +1 -0
  17. package/lib/entries/CallEntry.js +75 -0
  18. package/lib/entries/ClientEntry.d.ts +474 -0
  19. package/lib/entries/ClientEntry.d.ts.map +1 -0
  20. package/lib/entries/ClientEntry.js +101 -0
  21. package/lib/entries/InboundTrackEntry.d.ts +670 -0
  22. package/lib/entries/InboundTrackEntry.d.ts.map +1 -0
  23. package/lib/entries/InboundTrackEntry.js +76 -0
  24. package/lib/entries/OutboundTrackEntry.d.ts +670 -0
  25. package/lib/entries/OutboundTrackEntry.d.ts.map +1 -0
  26. package/lib/entries/OutboundTrackEntry.js +73 -0
  27. package/lib/entries/PeerConnectionEntry.d.ts +469 -0
  28. package/lib/entries/PeerConnectionEntry.d.ts.map +1 -0
  29. package/lib/entries/PeerConnectionEntry.js +144 -0
  30. package/lib/entries/SfuEntry.d.ts +150 -0
  31. package/lib/entries/SfuEntry.d.ts.map +1 -0
  32. package/lib/entries/SfuEntry.js +77 -0
  33. package/lib/entries/SfuInboundRtpPadEntry.d.ts +14 -0
  34. package/lib/entries/SfuInboundRtpPadEntry.d.ts.map +1 -0
  35. package/lib/entries/SfuInboundRtpPadEntry.js +49 -0
  36. package/lib/entries/SfuOutboundRtpPadEntry.d.ts +14 -0
  37. package/lib/entries/SfuOutboundRtpPadEntry.d.ts.map +1 -0
  38. package/lib/entries/SfuOutboundRtpPadEntry.js +47 -0
  39. package/lib/entries/SfuSctpChannelEntry.d.ts +12 -0
  40. package/lib/entries/SfuSctpChannelEntry.d.ts.map +1 -0
  41. package/lib/entries/SfuSctpChannelEntry.js +43 -0
  42. package/lib/entries/SfuTransportEntry.d.ts +82 -0
  43. package/lib/entries/SfuTransportEntry.d.ts.map +1 -0
  44. package/lib/entries/SfuTransportEntry.js +122 -0
  45. package/lib/index.d.ts +10 -0
  46. package/lib/index.d.ts.map +1 -1
  47. package/lib/middlewares/CallOperationsContext.d.ts.map +1 -1
  48. package/lib/middlewares/CallOperationsContext.js +2 -6
  49. package/lib/middlewares/CallProcessor.d.ts.map +1 -1
  50. package/lib/middlewares/CallProcessor.js +15 -6
  51. package/lib/middlewares/CommitTransactionMiddleware.d.ts.map +1 -1
  52. package/lib/middlewares/CommitTransactionMiddleware.js +22 -26
  53. package/lib/middlewares/DeleteOutdatedCallEntries.d.ts.map +1 -1
  54. package/lib/middlewares/DeleteOutdatedCallEntries.js +29 -20
  55. package/lib/middlewares/DeleteOutdatedSfuEntries.d.ts.map +1 -1
  56. package/lib/middlewares/DeleteOutdatedSfuEntries.js +27 -18
  57. package/lib/middlewares/Middleware.d.ts.map +1 -1
  58. package/lib/middlewares/Middleware.js +13 -4
  59. package/lib/middlewares/Processor.d.ts.map +1 -1
  60. package/lib/middlewares/Processor.js +18 -9
  61. package/lib/middlewares/TransactionContext.d.ts.map +1 -1
  62. package/lib/middlewares/TransactionContext.js +84 -73
  63. package/lib/middlewares/VisitObservedCallsMiddleware.d.ts.map +1 -1
  64. package/lib/middlewares/VisitObservedCallsMiddleware.js +16 -7
  65. package/lib/middlewares/VisitObservedSfusMiddleware.d.ts.map +1 -1
  66. package/lib/middlewares/VisitObservedSfusMiddleware.js +15 -6
  67. package/lib/middlewares/visitors/visitClient.d.ts.map +1 -1
  68. package/lib/middlewares/visitors/visitClient.js +6 -18
  69. package/lib/middlewares/visitors/visitInboundAudioTrack.d.ts.map +1 -1
  70. package/lib/middlewares/visitors/visitInboundAudioTrack.js +17 -20
  71. package/lib/middlewares/visitors/visitInboundVideoTrack.d.ts.map +1 -1
  72. package/lib/middlewares/visitors/visitInboundVideoTrack.js +16 -21
  73. package/lib/middlewares/visitors/visitOutboundAudioTrack.d.ts.map +1 -1
  74. package/lib/middlewares/visitors/visitOutboundAudioTrack.js +16 -16
  75. package/lib/middlewares/visitors/visitOutboundVideoTarck.d.ts.map +1 -1
  76. package/lib/middlewares/visitors/visitOutboundVideoTarck.js +16 -17
  77. package/lib/middlewares/visitors/visitPeerConnection.d.ts.map +1 -1
  78. package/lib/middlewares/visitors/visitPeerConnection.js +24 -40
  79. package/lib/middlewares/visitors/visitSfu.d.ts.map +1 -1
  80. package/lib/middlewares/visitors/visitSfu.js +6 -7
  81. package/lib/middlewares/visitors/visitSfuInboundRtpPad.d.ts.map +1 -1
  82. package/lib/middlewares/visitors/visitSfuInboundRtpPad.js +3 -7
  83. package/lib/middlewares/visitors/visitSfuOutboundRtpPad.d.ts.map +1 -1
  84. package/lib/middlewares/visitors/visitSfuOutboundRtpPad.js +3 -8
  85. package/lib/middlewares/visitors/visitSfuSctpChannel.d.ts.map +1 -1
  86. package/lib/middlewares/visitors/visitSfuSctpChannel.js +3 -6
  87. package/lib/middlewares/visitors/visitSfuTransport.d.ts.map +1 -1
  88. package/lib/middlewares/visitors/visitSfuTransport.js +3 -6
  89. package/lib/processes/closePeerConnectionProcess.d.ts.map +1 -1
  90. package/lib/processes/closePeerConnectionProcess.js +14 -5
  91. package/lib/processes/detachClientProcess.d.ts.map +1 -1
  92. package/lib/processes/detachClientProcess.js +20 -17
  93. package/lib/processes/findRemoteMatches.d.ts +2 -2
  94. package/lib/processes/findRemoteMatches.d.ts.map +1 -1
  95. package/lib/processes/findRemoteMatches.js +70 -56
  96. package/lib/processes/inboundTrackRemoved.d.ts.map +1 -1
  97. package/lib/processes/inboundTrackRemoved.js +12 -3
  98. package/lib/processes/joinClientProcess.d.ts.map +1 -1
  99. package/lib/processes/joinClientProcess.js +15 -6
  100. package/lib/processes/outboundTrackRemoved.d.ts.map +1 -1
  101. package/lib/processes/outboundTrackRemoved.js +12 -3
  102. package/lib/samples/ObservedCall.d.ts.map +1 -1
  103. package/lib/samples/ObservedCall.js +1 -5
  104. package/lib/samples/ObservedCalls.d.ts.map +1 -1
  105. package/lib/samples/ObservedClient.d.ts.map +1 -1
  106. package/lib/samples/ObservedClient.js +1 -9
  107. package/lib/samples/ObservedInboundAudioTrack.d.ts.map +1 -1
  108. package/lib/samples/ObservedInboundAudioTrack.js +1 -5
  109. package/lib/samples/ObservedInboundVideoTrack.d.ts.map +1 -1
  110. package/lib/samples/ObservedInboundVideoTrack.js +1 -5
  111. package/lib/samples/ObservedOutboundAudioTrack.d.ts.map +1 -1
  112. package/lib/samples/ObservedOutboundAudioTrack.js +1 -5
  113. package/lib/samples/ObservedOutboundVideoTrack.d.ts.map +1 -1
  114. package/lib/samples/ObservedOutboundVideoTrack.js +1 -5
  115. package/lib/samples/ObservedPeerConnection.d.ts.map +1 -1
  116. package/lib/samples/ObservedPeerConnection.js +1 -12
  117. package/lib/samples/ObservedSfu.d.ts.map +1 -1
  118. package/lib/samples/ObservedSfu.js +1 -8
  119. package/lib/samples/ObservedSfuInboundRtpPad.d.ts.map +1 -1
  120. package/lib/samples/ObservedSfuInboundRtpPad.js +1 -5
  121. package/lib/samples/ObservedSfuOutboundRtpPad.d.ts.map +1 -1
  122. package/lib/samples/ObservedSfuOutboundRtpPad.js +1 -5
  123. package/lib/samples/ObservedSfuSctpChannel.d.ts.map +1 -1
  124. package/lib/samples/ObservedSfuSctpChannel.js +1 -5
  125. package/lib/samples/ObservedSfuTransport.d.ts.map +1 -1
  126. package/lib/samples/ObservedSfuTransport.js +1 -8
  127. package/lib/samples/ObservedSfus.d.ts.map +1 -1
  128. package/lib/sinks/ObserverSink.d.ts.map +1 -1
  129. package/lib/sinks/ObserverSink.js +42 -31
  130. package/lib/sinks/callEventReports.js +1 -0
  131. package/lib/sources/ObservedCallSource.d.ts +5 -3
  132. package/lib/sources/ObservedCallSource.d.ts.map +1 -1
  133. package/lib/sources/ObservedClientSource.d.ts +3 -2
  134. package/lib/sources/ObservedClientSource.d.ts.map +1 -1
  135. package/lib/sources/ObservedSfuSource.d.ts +3 -2
  136. package/lib/sources/ObservedSfuSource.d.ts.map +1 -1
  137. package/lib/sources/Sources.d.ts +8 -4
  138. package/lib/sources/Sources.d.ts.map +1 -1
  139. package/lib/sources/Sources.js +71 -46
  140. package/lib/storages/ObserverStorage.d.ts.map +1 -1
  141. package/lib/storages/SimpleStorage.d.ts.map +1 -1
  142. package/lib/storages/SimpleStorage.js +40 -23
  143. package/package.json +2 -1
  144. package/src/Evaluator.ts +17 -9
  145. package/src/Observer.ts +239 -171
  146. package/src/common/Semaphore.ts +2 -0
  147. package/src/common/callMetaReports.ts +30 -28
  148. package/src/common/logger.ts +140 -132
  149. package/src/common/types.ts +1 -1
  150. package/src/common/utils.ts +12 -1
  151. package/src/entries/CallEntry.ts +62 -0
  152. package/src/entries/ClientEntry.ts +90 -0
  153. package/src/entries/InboundTrackEntry.ts +74 -0
  154. package/src/entries/OutboundTrackEntry.ts +72 -0
  155. package/src/entries/PeerConnectionEntry.ts +133 -0
  156. package/src/entries/SfuEntry.ts +62 -0
  157. package/src/entries/SfuInboundRtpPadEntry.ts +46 -0
  158. package/src/entries/SfuOutboundRtpPadEntry.ts +44 -0
  159. package/src/entries/SfuSctpChannelEntry.ts +39 -0
  160. package/src/entries/SfuTransportEntry.ts +109 -0
  161. package/src/index.ts +11 -0
  162. package/src/middlewares/CallOperationsContext.ts +9 -5
  163. package/src/middlewares/CallProcessor.ts +4 -2
  164. package/src/middlewares/CommitTransactionMiddleware.ts +8 -5
  165. package/src/middlewares/DeleteOutdatedCallEntries.ts +24 -16
  166. package/src/middlewares/DeleteOutdatedSfuEntries.ts +24 -15
  167. package/src/middlewares/Middleware.ts +1 -0
  168. package/src/middlewares/Processor.ts +10 -5
  169. package/src/middlewares/TransactionContext.ts +1 -2
  170. package/src/middlewares/VisitObservedCallsMiddleware.ts +5 -2
  171. package/src/middlewares/VisitObservedSfusMiddleware.ts +8 -7
  172. package/src/middlewares/visitors/visitClient.ts +15 -1
  173. package/src/middlewares/visitors/visitInboundAudioTrack.ts +4 -1
  174. package/src/middlewares/visitors/visitInboundVideoTrack.ts +5 -1
  175. package/src/middlewares/visitors/visitOutboundAudioTrack.ts +5 -1
  176. package/src/middlewares/visitors/visitOutboundVideoTarck.ts +5 -1
  177. package/src/middlewares/visitors/visitPeerConnection.ts +15 -2
  178. package/src/middlewares/visitors/visitSfu.ts +7 -1
  179. package/src/middlewares/visitors/visitSfuInboundRtpPad.ts +4 -2
  180. package/src/middlewares/visitors/visitSfuOutboundRtpPad.ts +3 -1
  181. package/src/middlewares/visitors/visitSfuSctpChannel.ts +23 -21
  182. package/src/middlewares/visitors/visitSfuTransport.ts +3 -1
  183. package/src/processes/closePeerConnectionProcess.ts +3 -0
  184. package/src/processes/detachClientProcess.ts +13 -4
  185. package/src/processes/findRemoteMatches.ts +32 -21
  186. package/src/processes/inboundTrackRemoved.ts +2 -0
  187. package/src/processes/joinClientProcess.ts +8 -2
  188. package/src/processes/outboundTrackRemoved.ts +2 -0
  189. package/src/samples/ObservedCall.ts +6 -0
  190. package/src/samples/ObservedCalls.ts +13 -7
  191. package/src/samples/ObservedClient.ts +24 -8
  192. package/src/samples/ObservedInboundAudioTrack.ts +3 -2
  193. package/src/samples/ObservedInboundVideoTrack.ts +3 -2
  194. package/src/samples/ObservedOutboundAudioTrack.ts +3 -2
  195. package/src/samples/ObservedOutboundVideoTrack.ts +3 -2
  196. package/src/samples/ObservedPeerConnection.ts +27 -11
  197. package/src/samples/ObservedSfu.ts +17 -10
  198. package/src/samples/ObservedSfuInboundRtpPad.ts +5 -4
  199. package/src/samples/ObservedSfuOutboundRtpPad.ts +5 -4
  200. package/src/samples/ObservedSfuSctpChannel.ts +13 -13
  201. package/src/samples/ObservedSfuTransport.ts +19 -7
  202. package/src/samples/ObservedSfus.ts +10 -5
  203. package/src/sinks/ObserverSink.ts +51 -44
  204. package/src/sinks/callEventReports.ts +1 -1
  205. package/src/sources/ObservedCallSource.ts +6 -5
  206. package/src/sources/ObservedClientSource.ts +3 -2
  207. package/src/sources/ObservedSfuSource.ts +4 -8
  208. package/src/sources/Sources.ts +96 -22
  209. package/src/storages/ObserverStorage.ts +1 -0
  210. package/src/storages/SimpleStorage.ts +44 -21
  211. package/tsconfig.json +7 -5
  212. package/.eslintrc.js +0 -27
@@ -1,5 +1,4 @@
1
1
  import { iteratorConverter } from '../common/utils';
2
- import { ObservedCall, ObservedCallBuilder } from './ObservedCall';
3
2
  import { ObservedSfu, ObservedSfuBuilder } from './ObservedSfu';
4
3
 
5
4
  export interface ObservedSfus {
@@ -23,25 +22,28 @@ export class ObservedSfusBuilder {
23
22
  configSupplier: () => ConstructorParameters<typeof ObservedSfuBuilder>[0]
24
23
  ) {
25
24
  let result = this._builders.get(sfuId);
25
+
26
26
  if (!result) {
27
27
  const config = configSupplier();
28
+
28
29
  result = new ObservedSfuBuilder(config);
29
30
  this._builders.set(sfuId, result);
30
31
  }
32
+
31
33
  return result;
32
34
  }
33
35
 
34
36
  public build(): ObservedSfus {
35
37
  const observedSfus = new Map<string, ObservedSfu>();
36
38
 
37
- const sfuIdsGenerator = function* () {
39
+ const sfuIdsGenerator = function *() {
38
40
  for (const observedSfu of observedSfus.values()) {
39
41
  yield observedSfu.sfuId;
40
42
  }
41
43
  };
42
44
  const sfuIds = () => iteratorConverter<string>(sfuIdsGenerator());
43
45
 
44
- const sfuTransportIdsGenerator = function* () {
46
+ const sfuTransportIdsGenerator = function *() {
45
47
  for (const observedSfu of observedSfus.values()) {
46
48
  for (const observedTransport of observedSfu.observedSfuTransports()) {
47
49
  yield observedTransport.transportId;
@@ -50,7 +52,7 @@ export class ObservedSfusBuilder {
50
52
  };
51
53
  const sfuTransportIds = () => iteratorConverter<string>(sfuTransportIdsGenerator());
52
54
 
53
- const sfuInboundRtpPadIdsGenerator = function* () {
55
+ const sfuInboundRtpPadIdsGenerator = function *() {
54
56
  for (const observedSfu of observedSfus.values()) {
55
57
  for (const observedTransport of observedSfu.observedSfuTransports()) {
56
58
  for (const sfuInboundRtpPad of observedTransport.inboundRtpPads()) {
@@ -61,7 +63,7 @@ export class ObservedSfusBuilder {
61
63
  };
62
64
  const sfuInboundRtpPadIds = () => iteratorConverter<string>(sfuInboundRtpPadIdsGenerator());
63
65
 
64
- const sfuOutboundRtpPadIdsGenerator = function* () {
66
+ const sfuOutboundRtpPadIdsGenerator = function *() {
65
67
  for (const observedSfu of observedSfus.values()) {
66
68
  for (const observedTransport of observedSfu.observedSfuTransports()) {
67
69
  for (const sfuOutboundRtpPad of observedTransport.outboundRtpPads()) {
@@ -80,11 +82,14 @@ export class ObservedSfusBuilder {
80
82
  observedSfus: () => observedSfus.values(),
81
83
  getObservedSfu: (sfuId) => observedSfus.get(sfuId),
82
84
  };
85
+
83
86
  for (const builder of this._builders.values()) {
84
87
  const observedSfu = builder.build();
88
+
85
89
  observedSfus.set(observedSfu.sfuId, observedSfu);
86
90
  }
87
91
  this._builders.clear();
92
+
88
93
  return result;
89
94
  }
90
95
  }
@@ -121,19 +121,21 @@ export class SinkImpl implements ReportsCollector, ObserverReportsEmitter {
121
121
  this._processor = createProcessor();
122
122
  }
123
123
 
124
-
125
124
  public on<K extends keyof SinkEventsMap>(event: K, listener: (reports: SinkEventsMap[K]) => void): this {
126
125
  this._emitter.addListener(event, listener);
126
+
127
127
  return this;
128
128
  }
129
129
 
130
130
  public off<K extends keyof SinkEventsMap>(event: K, listener: (reports: SinkEventsMap[K]) => void): this {
131
131
  this._emitter.removeListener(event, listener);
132
+
132
133
  return this;
133
134
  }
134
135
 
135
136
  public once<K extends keyof SinkEventsMap>(event: K, listener: (reports: SinkEventsMap[K]) => void): this {
136
137
  this._emitter.once(event, listener);
138
+
137
139
  return this;
138
140
  }
139
141
 
@@ -230,12 +232,14 @@ export class SinkImpl implements ReportsCollector, ObserverReportsEmitter {
230
232
  await process(context);
231
233
  if (next) await next(context);
232
234
  };
235
+
233
236
  this._customProcesses.set(process, middleware);
234
237
  this._processor.addMiddleware(middleware);
235
238
  }
236
239
 
237
240
  public removeProcess(process: ObserverSinkProcess) {
238
241
  const middleware = this._customProcesses.get(process);
242
+
239
243
  if (!middleware) {
240
244
  return;
241
245
  }
@@ -249,7 +253,7 @@ export class SinkImpl implements ReportsCollector, ObserverReportsEmitter {
249
253
  return;
250
254
  }
251
255
  if (this._processes.has(this._index)) {
252
- logger.warn(`The sink process has been called while the previous process has not yet completed. This may indicate that the observer is attempting to process more reports than it can handle.`);
256
+ logger.warn('The sink process has been called while the previous process has not yet completed. This may indicate that the observer is attempting to process more reports than it can handle.');
253
257
  }
254
258
 
255
259
  const actualBlockingPoint = this._processes.get(this._index) ?? Promise.resolve();
@@ -270,7 +274,9 @@ export class SinkImpl implements ReportsCollector, ObserverReportsEmitter {
270
274
  resolve();
271
275
  });
272
276
  });
277
+
273
278
  this._processes.set(index, nextBlockingPoint);
279
+
274
280
  return result;
275
281
  }
276
282
 
@@ -284,9 +290,10 @@ export class SinkImpl implements ReportsCollector, ObserverReportsEmitter {
284
290
  };
285
291
 
286
292
  const context = this._createObserverSinkContext();
287
- this._process(context).catch(err => {
288
- logger.error(`Error occurred while processing reports`, err);
289
- })
293
+
294
+ this._process(context).catch((err) => {
295
+ logger.error('Error occurred while processing reports', err);
296
+ });
290
297
 
291
298
  checkAndEmit('call-event', this._callEventReports);
292
299
  this._callEventReports = [];
@@ -349,45 +356,45 @@ export class SinkImpl implements ReportsCollector, ObserverReportsEmitter {
349
356
  return this._emitter.emit(event, reports);
350
357
  }
351
358
 
352
- private _createObserverSinkContext(): ObserverSinkContext {
353
- const callEventReports = [...this._callEventReports];
354
- const callMetaReports = [...this._callMetaReports];
355
- const clientDataChannelReports = [...this._clientDataChannelReports];
356
- const clientExtensionReports = [...this._clientExtensionReports];
357
- const iceCandidatePairReports = [...this._iceCandidatePairReports];
358
- const inboundAudioTrackReports = [...this._inboundAudioTrackReports];
359
- const inboundVideoTrackReports = [...this._inboundVideoTrackReports];
360
- const peerConnectionTransportReports = [...this._peerConnectionTransportReports];
361
- const observerEventReports = [...this._observerEventReports];
362
- const outboundAudioTrackReports = [...this._outboundAudioTrackReports];
363
- const outboundVideoTrackReports = [...this._outboundVideoTrackReports];
364
- const sfuEventReports = [...this._sfuEventReports];
365
- const sfuExtensionReports = [...this._sfuExtensionReports];
366
- const sfuInboundRtpPadReports = [...this._sfuInboundRtpPadReports];
367
- const sfuOutboundRtpPadReports = [...this._sfuOutboundRtpPadReports];
368
- const sfuSctpStreamReports = [...this._sfuSctpStreamReports];
369
- const sfuTransportReports = [...this._sfuTransportReports];
370
- const sfuMetaReports = [...this._sfuMetaReports];
371
-
359
+ private _createObserverSinkContext(): ObserverSinkContext {
360
+ const callEventReports = [ ...this._callEventReports ];
361
+ const callMetaReports = [ ...this._callMetaReports ];
362
+ const clientDataChannelReports = [ ...this._clientDataChannelReports ];
363
+ const clientExtensionReports = [ ...this._clientExtensionReports ];
364
+ const iceCandidatePairReports = [ ...this._iceCandidatePairReports ];
365
+ const inboundAudioTrackReports = [ ...this._inboundAudioTrackReports ];
366
+ const inboundVideoTrackReports = [ ...this._inboundVideoTrackReports ];
367
+ const peerConnectionTransportReports = [ ...this._peerConnectionTransportReports ];
368
+ const observerEventReports = [ ...this._observerEventReports ];
369
+ const outboundAudioTrackReports = [ ...this._outboundAudioTrackReports ];
370
+ const outboundVideoTrackReports = [ ...this._outboundVideoTrackReports ];
371
+ const sfuEventReports = [ ...this._sfuEventReports ];
372
+ const sfuExtensionReports = [ ...this._sfuExtensionReports ];
373
+ const sfuInboundRtpPadReports = [ ...this._sfuInboundRtpPadReports ];
374
+ const sfuOutboundRtpPadReports = [ ...this._sfuOutboundRtpPadReports ];
375
+ const sfuSctpStreamReports = [ ...this._sfuSctpStreamReports ];
376
+ const sfuTransportReports = [ ...this._sfuTransportReports ];
377
+ const sfuMetaReports = [ ...this._sfuMetaReports ];
378
+
372
379
  return {
373
- callEventReports,
374
- callMetaReports,
375
- clientDataChannelReports,
376
- clientExtensionReports,
377
- iceCandidatePairReports,
378
- inboundAudioTrackReports,
379
- inboundVideoTrackReports,
380
- peerConnectionTransportReports,
381
- observerEventReports,
382
- outboundAudioTrackReports,
383
- outboundVideoTrackReports,
384
- sfuEventReports,
385
- sfuExtensionReports,
386
- sfuInboundRtpPadReports,
387
- sfuOutboundRtpPadReports,
388
- sfuSctpStreamReports,
389
- sfuTransportReports,
390
- sfuMetaReports,
380
+ callEventReports,
381
+ callMetaReports,
382
+ clientDataChannelReports,
383
+ clientExtensionReports,
384
+ iceCandidatePairReports,
385
+ inboundAudioTrackReports,
386
+ inboundVideoTrackReports,
387
+ peerConnectionTransportReports,
388
+ observerEventReports,
389
+ outboundAudioTrackReports,
390
+ outboundVideoTrackReports,
391
+ sfuEventReports,
392
+ sfuExtensionReports,
393
+ sfuInboundRtpPadReports,
394
+ sfuOutboundRtpPadReports,
395
+ sfuSctpStreamReports,
396
+ sfuTransportReports,
397
+ sfuMetaReports,
391
398
  };
392
- }
399
+ }
393
400
  }
@@ -1,6 +1,6 @@
1
1
  import { CallEventReport } from '@observertc/report-schemas-js';
2
- import { stringify } from 'uuid';
3
2
 
3
+ // eslint-disable-next-line no-shadow
4
4
  export enum CallEventType {
5
5
  CALL_STARTED = 'CALL_STARTED',
6
6
  CALL_ENDED = 'CALL_ENDED',
@@ -1,19 +1,20 @@
1
- import { ClientSample } from '@observertc/sample-schemas-js';
2
1
  import { PartialBy } from '../common/utils';
3
2
  import { ObservedClientSource, ObservedClientSourceConfig } from './ObservedClientSource';
4
3
 
5
- export type ObservedCallSourceConfig = {
4
+ export type ObservedCallSourceConfig<T extends Record<string, unknown>> = {
5
+ readonly appData: T
6
6
  readonly serviceId: string;
7
7
  readonly mediaUnitId: string;
8
8
  readonly roomId: string;
9
9
  readonly callId: string;
10
10
  };
11
11
 
12
- export interface ObservedCallSource extends ObservedCallSourceConfig {
12
+ export interface ObservedCallSource<T extends Record<string, unknown> = Record<string, unknown>> extends ObservedCallSourceConfig<T> {
13
13
  readonly closed: boolean;
14
+ readonly clients: ReadonlyMap<string, ObservedClientSource>;
14
15
 
15
- createClientSource(
16
- context: PartialBy<ObservedClientSourceConfig, 'joined' | 'mediaUnitId' | 'serviceId' | 'callId' | 'roomId'>
16
+ createClientSource<U extends Record<string, unknown> = Record<string, unknown>>(
17
+ context: PartialBy<ObservedClientSourceConfig<U>, 'joined' | 'mediaUnitId' | 'serviceId' | 'callId' | 'roomId'>
17
18
  ): ObservedClientSource;
18
19
 
19
20
  // automatically close every
@@ -1,6 +1,7 @@
1
1
  import { ClientSample } from '@observertc/sample-schemas-js';
2
2
 
3
- export type ObservedClientSourceConfig = {
3
+ export type ObservedClientSourceConfig<T extends Record<string, unknown> = Record<string, unknown>> = {
4
+ readonly appData: T;
4
5
  readonly serviceId: string;
5
6
  readonly mediaUnitId: string;
6
7
  readonly roomId: string;
@@ -13,7 +14,7 @@ export type ObservedClientSourceConfig = {
13
14
  timeZoneId?: string;
14
15
  };
15
16
 
16
- export interface ObservedClientSource extends ObservedClientSourceConfig {
17
+ export interface ObservedClientSource<T extends Record<string, unknown> = Record<string, unknown>> extends ObservedClientSourceConfig<T> {
17
18
  readonly closed: boolean;
18
19
 
19
20
  accept(...samples: ClientSample[]): void;
@@ -1,6 +1,7 @@
1
- import { ClientSample, SfuSample } from '@observertc/sample-schemas-js';
1
+ import { SfuSample } from '@observertc/sample-schemas-js';
2
2
 
3
- export type ObservedSfuSourceConfig = {
3
+ export type ObservedSfuSourceConfig<T extends Record<string, unknown> = Record<string, unknown>> = {
4
+ readonly appData: T;
4
5
  readonly serviceId: string;
5
6
  readonly mediaUnitId: string;
6
7
  readonly sfuId: string;
@@ -9,15 +10,10 @@ export type ObservedSfuSourceConfig = {
9
10
  timeZoneId?: string;
10
11
  };
11
12
 
12
- export interface ObservedSfuSource extends ObservedSfuSourceConfig {
13
+ export interface ObservedSfuSource<T extends Record<string, unknown> = Record<string, unknown>> extends ObservedSfuSourceConfig<T> {
13
14
  readonly closed: boolean;
14
15
 
15
16
  accept(...samples: SfuSample[]): void;
16
17
 
17
- // when you close this, client is disposed. so this triggers the client to dispose
18
- // therefore this triggers the call to be disposed
19
- // peer connections, and tracks the creation is evented by the client,
20
- // the close of those object is evented by the observer or closing this
21
- // call the close of this is mandatory, as only this closes the client inside the observer
22
18
  close(): void;
23
19
  }
@@ -4,9 +4,9 @@ import { ObservedClientSource, ObservedClientSourceConfig } from './ObservedClie
4
4
  import { EventEmitter } from 'events';
5
5
  import { createLogger } from '../common/logger';
6
6
  import { PartialBy } from '../common/utils';
7
- import { ObservedCallSource, ObservedCallSourceConfig } from './ObservedCallSource';
8
7
  import { ObservedSfuSourceConfig, ObservedSfuSource } from './ObservedSfuSource';
9
8
  import { ObservedSfus, ObservedSfusBuilder } from '../samples/ObservedSfus';
9
+ import { ObservedCallSource, ObservedCallSourceConfig } from './ObservedCallSource';
10
10
 
11
11
  const logger = createLogger('Sources');
12
12
 
@@ -30,7 +30,8 @@ export type SourcesEvents = {
30
30
  export class Sources {
31
31
 
32
32
  private readonly _warnFlags = { autoEmitButEmitSamplesInvoked: false };
33
- private readonly _clientSources = new Map<string, ObservedClientSource>();
33
+ private readonly _callSources = new Map<string, ObservedCallSource>();
34
+ // private readonly _clientSources = new Map<string, ObservedClientSource>();
34
35
  private readonly _sfuSources = new Map<string, ObservedSfuSource>();
35
36
  private readonly _emitter = new EventEmitter();
36
37
 
@@ -41,13 +42,23 @@ export class Sources {
41
42
 
42
43
  public constructor(public readonly config: SourcesConfig) {}
43
44
 
45
+ public getCallSource(callId: string) {
46
+ return this._callSources.get(callId);
47
+ }
48
+
49
+ public getSfuSource(sfuId: string) {
50
+ return this._sfuSources.get(sfuId);
51
+ }
52
+
44
53
  public on<K extends keyof SourcesEvents>(event: K, listener: (data: SourcesEvents[K]) => void): this {
45
54
  this._emitter.addListener(event, listener);
55
+
46
56
  return this;
47
57
  }
48
58
 
49
59
  public off<K extends keyof SourcesEvents>(event: K, listener: (data: SourcesEvents[K]) => void): this {
50
60
  this._emitter.removeListener(event, listener);
61
+
51
62
  return this;
52
63
  }
53
64
 
@@ -55,16 +66,79 @@ export class Sources {
55
66
  return this._emitter.emit(event, data);
56
67
  }
57
68
 
58
- public createClientSource(config: PartialBy<ObservedClientSourceConfig, 'joined'>): ObservedClientSource {
59
- const existingClientSource = this._clientSources.get(config.clientId);
60
- if (existingClientSource) {
61
- logger.warn(`Attempted to add a ClientSource for client ${config.clientId} twice`);
62
- return existingClientSource;
69
+ public createCallSource<T extends Record<string, unknown> = Record<string, unknown>>(
70
+ config: ObservedCallSourceConfig<T>
71
+ ): ObservedCallSource<T> {
72
+ let closed = false;
73
+ const {
74
+ serviceId,
75
+ mediaUnitId,
76
+ appData,
77
+ ...callConfig
78
+ } = config;
79
+ const clientSources = new Map<string, ObservedClientSource>();
80
+ const callSource: ObservedCallSource<T> = {
81
+ ...callConfig,
82
+ appData,
83
+ serviceId,
84
+ mediaUnitId,
85
+ clients: clientSources,
86
+
87
+ createClientSource: <U extends Record<string, unknown> = Record<string, unknown>>(context: ObservedClientSourceConfig<U>) => {
88
+ const existingClientSource = clientSources.get(context.clientId);
89
+
90
+ if (existingClientSource) return existingClientSource;
91
+
92
+ const { appData: clientAppData, ...clientConfig } = context;
93
+ const clientSource = this._createClientSource<U>({
94
+ ...callConfig,
95
+ ...clientConfig,
96
+ appData: clientAppData,
97
+ serviceId,
98
+ mediaUnitId,
99
+ });
100
+ const closeClientSource = clientSource.close;
101
+
102
+ clientSource.close = () => {
103
+ closeClientSource();
104
+ clientSources.delete(context.clientId);
105
+ };
106
+ clientSources.set(context.clientId, clientSource);
107
+
108
+ return clientSource;
109
+ },
110
+ close: () => {
111
+ if (closed) {
112
+ return;
113
+ }
114
+ for (const clientSource of clientSources.values()) {
115
+ clientSource.close();
116
+ }
117
+ clientSources.clear();
118
+ this._callSources.delete(config.callId);
119
+ closed = true;
120
+ },
121
+ closed,
122
+ };
123
+
124
+ if (this._callSources.size < 1) {
125
+ this._resetTimer();
63
126
  }
127
+ this._callSources.set(config.callId, callSource);
128
+
129
+ return callSource;
130
+ }
131
+
132
+ private _createClientSource<T extends Record<string, unknown> = Record<string, unknown>>(config: PartialBy<ObservedClientSourceConfig<T>, 'joined'>): ObservedClientSource<T> {
64
133
  let closed = false;
65
- // config.joined = config.joined ?? Date.now();
66
- const source: ObservedClientSource = {
67
- ...config,
134
+ const {
135
+ appData,
136
+ ...clientConfig
137
+ } = config;
138
+
139
+ const source: ObservedClientSource<T> = {
140
+ ...clientConfig,
141
+ appData,
68
142
  joined: config.joined ?? Date.now(),
69
143
 
70
144
  accept: (...samples: ClientSample[]) => {
@@ -92,23 +166,20 @@ export class Sources {
92
166
  return;
93
167
  }
94
168
  closed = true;
95
- this._clientSources.delete(config.clientId);
96
169
  this._emit('removed-client-source', source);
97
170
  },
98
171
  closed,
99
172
  };
100
- if (this._clientSources.size < 1) {
101
- this._resetTimer();
102
- }
103
- this._clientSources.set(config.clientId, source);
173
+
104
174
  this._emit('added-client-source', source);
175
+
105
176
  return source;
106
177
  }
107
178
 
108
- public createSfuSource(config: PartialBy<ObservedSfuSourceConfig, 'joined'>): ObservedSfuSource {
179
+ public createSfuSource<T extends Record<string, unknown> = Record<string, unknown>>(config: PartialBy<ObservedSfuSourceConfig<T>, 'joined'>): ObservedSfuSource {
109
180
  const existingSfuSource = this._sfuSources.get(config.sfuId);
181
+
110
182
  if (existingSfuSource) {
111
- logger.warn(`Attempted to add a SfuSource for sfu ${config.sfuId} twice`);
112
183
  return existingSfuSource;
113
184
  }
114
185
  let closed = false;
@@ -142,11 +213,13 @@ export class Sources {
142
213
  },
143
214
  closed,
144
215
  };
216
+
145
217
  if (this._sfuSources.size < 1) {
146
218
  this._resetTimer();
147
219
  }
148
220
  this._sfuSources.set(config.sfuId, source);
149
221
  this._emit('added-sfu-source', source);
222
+
150
223
  return source;
151
224
  }
152
225
 
@@ -174,8 +247,10 @@ export class Sources {
174
247
  private _emitSamples() {
175
248
  this._resetTimer();
176
249
  const observedCalls = this._observedCallsBuilder.build();
250
+
177
251
  this._observedCallsBuilder = new ObservedCallsBuilder();
178
252
  const observedSfus = this._observedSfusBuilder.build();
253
+
179
254
  this._observedSfusBuilder = new ObservedSfusBuilder();
180
255
  this._emit('observed-samples', {
181
256
  observedCalls,
@@ -199,11 +274,10 @@ export class Sources {
199
274
  }
200
275
 
201
276
  public close() {
202
- for (const clientSource of this._clientSources.values()) {
203
- if (!clientSource.closed) {
204
- clientSource.close();
205
- }
206
- }
277
+ [ ...this._callSources.values() ].forEach((callSource) => callSource.close());
278
+ [ ...this._sfuSources.values() ].forEach((sfuSource) => sfuSource.close());
279
+ this._callSources.clear();
280
+ this._sfuSources.clear();
207
281
  this._emitSamples();
208
282
  }
209
283
  }
@@ -2,6 +2,7 @@
2
2
  * The `ObserverStorage` interface defines the methods used for managing storage of key-value pairs.
3
3
  */
4
4
  export interface ObserverStorage<K, V> {
5
+
5
6
  /**
6
7
  * The identifier of the storage
7
8
  */
@@ -5,87 +5,110 @@ export class SimpleStorage<K, V> implements ObserverStorage<K, V> {
5
5
 
6
6
  public constructor(public readonly id: string) {}
7
7
 
8
- public async size(): Promise<number> {
9
- return this._map.size;
8
+ public size(): Promise<number> {
9
+ return Promise.resolve(this._map.size);
10
10
  }
11
11
 
12
- public async clear(): Promise<void> {
12
+ public clear(): Promise<void> {
13
13
  this._map.clear();
14
+
15
+ return Promise.resolve();
14
16
  }
15
17
 
16
- public async get(key: K): Promise<V | undefined> {
17
- return this._map.get(key);
18
+ public get(key: K): Promise<V | undefined> {
19
+ return Promise.resolve(this._map.get(key));
18
20
  }
19
21
 
20
- public async getAll(keys: Iterable<K>): Promise<ReadonlyMap<K, V>> {
22
+ public getAll(keys: Iterable<K>): Promise<ReadonlyMap<K, V>> {
21
23
  const result = new Map<K, V>();
24
+
22
25
  for (const key of keys) {
23
26
  const value = this._map.get(key);
27
+
24
28
  if (value) {
25
29
  result.set(key, value);
26
30
  }
27
31
  }
28
- return result;
32
+
33
+ return Promise.resolve(result);
29
34
  }
30
35
 
31
- public async set(key: K, value: V): Promise<V | undefined> {
36
+ public set(key: K, value: V): Promise<V | undefined> {
32
37
  const result = this._map.get(key);
38
+
33
39
  this._map.set(key, value);
34
- return result;
40
+
41
+ return Promise.resolve(result);
35
42
  }
36
43
 
37
- public async setAll(entries: ReadonlyMap<K, V>): Promise<ReadonlyMap<K, V>> {
44
+ public setAll(entries: ReadonlyMap<K, V>): Promise<ReadonlyMap<K, V>> {
38
45
  const result = new Map<K, V>();
39
- for (const [key, value] of entries) {
46
+
47
+ for (const [ key, value ] of entries) {
40
48
  const oldValue = this._map.get(key);
49
+
41
50
  if (oldValue) {
42
51
  result.set(key, oldValue);
43
52
  }
44
53
  this._map.set(key, value);
45
54
  }
46
- return result;
55
+
56
+ return Promise.resolve(result);
47
57
  }
48
58
 
49
- public async insert(key: K, value: V): Promise<V | undefined> {
59
+ public insert(key: K, value: V): Promise<V | undefined> {
50
60
  const result = this._map.get(key);
61
+
51
62
  if (result) {
52
- return result;
63
+ return Promise.resolve(result);
53
64
  }
54
65
  this._map.set(key, value);
66
+
67
+ return Promise.resolve(undefined);
55
68
  }
56
69
 
57
- public async insertAll(entries: ReadonlyMap<K, V>): Promise<ReadonlyMap<K, V>> {
70
+ public insertAll(entries: ReadonlyMap<K, V>): Promise<ReadonlyMap<K, V>> {
58
71
  const result = new Map<K, V>();
59
- for (const [key, value] of entries) {
72
+
73
+ for (const [ key, value ] of entries) {
60
74
  const oldValue = this._map.get(key);
75
+
61
76
  if (oldValue) {
62
77
  result.set(key, oldValue);
63
78
  } else {
64
79
  this._map.set(key, value);
65
80
  }
66
81
  }
67
- return result;
82
+
83
+ return Promise.resolve(result);
68
84
  }
69
85
 
70
- public async remove(key: K): Promise<V | undefined> {
86
+ public remove(key: K): Promise<V | undefined> {
71
87
  const result = this._map.get(key);
88
+
72
89
  this._map.delete(key);
73
- return result;
90
+
91
+ return Promise.resolve(result);
74
92
  }
75
93
 
76
- public async removeAll(keys: Iterable<K>): Promise<ReadonlyMap<K, V>> {
94
+ public removeAll(keys: Iterable<K>): Promise<ReadonlyMap<K, V>> {
77
95
  const result = new Map<K, V>();
96
+
78
97
  for (const key of keys) {
79
98
  const value = this._map.get(key);
99
+
80
100
  this._map.delete(key);
81
101
  if (value) {
82
102
  result.set(key, value);
83
103
  }
84
104
  }
85
- return result;
105
+
106
+ return Promise.resolve(result);
86
107
  }
87
108
 
88
109
  public async *[Symbol.asyncIterator](): AsyncIterableIterator<[K, V]> {
110
+ await Promise.resolve();
111
+
89
112
  for (const entry of this._map.entries()) {
90
113
  yield entry;
91
114
  }
package/tsconfig.json CHANGED
@@ -3,15 +3,17 @@
3
3
  "compilerOptions":
4
4
  {
5
5
  "lib": [ "es2020" ],
6
- "target": "es2018",
6
+ "target": "es6",
7
7
  "module": "commonjs",
8
8
  "moduleResolution": "node",
9
9
  "esModuleInterop": true,
10
- "isolatedModules": true,
11
10
  "strict": true,
12
11
  "outDir": "lib",
13
12
  "declaration": true,
14
- "declarationMap": true
13
+ "declarationMap": true,
14
+ "experimentalDecorators": true,
15
+ "emitDecoratorMetadata": true
15
16
  },
16
- "include": [ "src" ],
17
- }
17
+ "include": [ "src" ]
18
+ }
19
+