@observertc/observer-js 0.9.21-beta → 0.9.23-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 +1404 -38
  5. package/lib/Observer.d.ts.map +1 -1
  6. package/lib/Observer.js +479 -176
  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 +6 -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 +83 -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 +1 -1
  144. package/src/Evaluator.ts +17 -9
  145. package/src/Observer.ts +230 -170
  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 +9 -6
  206. package/src/sources/ObservedClientSource.ts +3 -2
  207. package/src/sources/ObservedSfuSource.ts +4 -8
  208. package/src/sources/Sources.ts +107 -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
package/src/Observer.ts CHANGED
@@ -1,15 +1,23 @@
1
1
  import { ObserverReportsEmitter, ObserverSinkProcess, SinkConfig, SinkImpl } from './sinks/ObserverSink';
2
2
  import { Sources, SourcesConfig } from './sources/Sources';
3
3
  import { createSimpleStorageProvider, StorageProvider } from './storages/StorageProvider';
4
- import * as Models from './models/Models';
5
4
  import { Evaluator, EvaluatorConfig, EvaluatorProcess } from './Evaluator';
6
5
  import { createSimpleSemaphoreProvider, SemaphoreProvider } from './common/Semaphore';
7
6
  import { ObservedCallSourceConfig, ObservedCallSource } from './sources/ObservedCallSource';
8
- import { ObservedClientSource, ObservedClientSourceConfig } from './sources/ObservedClientSource';
9
- import { PartialBy } from './common/utils';
7
+ import { PartialBy, asyncIteratorConverter } from './common/utils';
10
8
  import { createLogger, LogLevel } from './common/logger';
11
9
  import { ObservedSfuSource, ObservedSfuSourceConfig } from './sources/ObservedSfuSource';
12
10
  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';
13
21
 
14
22
  const logger = createLogger('Observer');
15
23
 
@@ -22,6 +30,7 @@ export type ObserverEvents = {
22
30
  }
23
31
 
24
32
  export type ObserverConfig = {
33
+
25
34
  /**
26
35
  *
27
36
  * Sets the default serviceId for samples.
@@ -71,8 +80,8 @@ export class Observer {
71
80
  );
72
81
 
73
82
  const semaphores = providedConfig.semaphores ?? createSimpleSemaphoreProvider();
74
-
75
83
  const storages = providedConfig.storages ?? createSimpleStorageProvider();
84
+
76
85
  return new Observer(config, storages, semaphores);
77
86
  }
78
87
 
@@ -88,7 +97,12 @@ export class Observer {
88
97
  ) {
89
98
  this._sources = new Sources(config.sources);
90
99
  this._sink = new SinkImpl(config.sink);
91
- this._evaluator = new Evaluator(this.config.evaluator, this._semaphores.callSemaphore, this._storages, this._sink);
100
+ this._evaluator = new Evaluator(
101
+ this.config.evaluator,
102
+ this._semaphores.callSemaphore,
103
+ this._storages,
104
+ this._sink
105
+ );
92
106
 
93
107
  this._sources.on('observed-samples', (event) => {
94
108
  this._emitter.emit('processing-started');
@@ -106,96 +120,70 @@ export class Observer {
106
120
  this._sink.emit();
107
121
  this._emitter.emit('processing-ended');
108
122
  });
109
- logger.debug(`Observer is created with config`, this.config);
123
+ logger.debug('Observer is created with config', this.config);
124
+ }
125
+
126
+ public get sources(): Sources {
127
+ return this._sources;
110
128
  }
111
129
 
112
130
  public on<K extends keyof ObserverEvents>(event: K, listener: (arg: ObserverEvents[K]) => void): this {
113
131
  this._emitter.on(event, listener);
132
+
114
133
  return this;
115
134
  }
116
135
 
117
136
  public once<K extends keyof ObserverEvents>(event: K, listener: (arg: ObserverEvents[K]) => void): this {
118
137
  this._emitter.once(event, listener);
138
+
119
139
  return this;
120
140
  }
121
141
 
122
142
  public off<K extends keyof ObserverEvents>(event: K, listener: (arg: ObserverEvents[K]) => void): this {
123
143
  this._emitter.off(event, listener);
144
+
124
145
  return this;
125
146
  }
126
147
 
127
- public createCallSource(
128
- config: PartialBy<ObservedCallSourceConfig, 'serviceId' | 'mediaUnitId'>
129
- ): ObservedCallSource {
148
+ public createCallSource<T extends Record<string, unknown> = Record<string, unknown>>(
149
+ config: PartialBy<ObservedCallSourceConfig<T>, 'serviceId' | 'mediaUnitId' | 'appData'>
150
+ ): ObservedCallSource<T> {
130
151
  if (this._closed) {
131
- throw new Error(`Attempted to create a call source on a closed observer`);
152
+ throw new Error('Attempted to create a call source on a closed observer');
132
153
  }
133
- let closed = false;
134
- const serviceId = config.serviceId ?? this.config.defaultServiceId;
135
- const mediaUnitId = config.mediaUnitId ?? this.config.defaultMediaUnitId;
136
- const clientSources = new Map<string, ObservedClientSource>();
137
- const callSource: ObservedCallSource = {
138
- ...config,
139
- serviceId,
140
- mediaUnitId,
141
- createClientSource: (context) => {
142
- const clientSource = this._sources.createClientSource({
143
- ...config,
144
- ...context,
145
- serviceId,
146
- mediaUnitId,
147
- });
148
- const closeClientSource = clientSource.close;
149
- clientSource.close = () => {
150
- closeClientSource();
151
- clientSources.delete(context.clientId);
152
- };
153
- clientSources.set(context.clientId, clientSource);
154
- return clientSource;
155
- },
156
- close: () => {
157
- if (closed) {
158
- return;
159
- }
160
- for (const clientSource of clientSources.values()) {
161
- clientSource.close();
162
- }
163
- clientSources.clear();
164
- closed = true;
165
- },
166
- closed,
167
- };
168
- return callSource;
169
- }
170
154
 
171
- public createClientSource(
172
- config: PartialBy<ObservedClientSourceConfig, 'serviceId' | 'mediaUnitId' | 'joined'>
173
- ): ObservedClientSource {
174
- if (this._closed) {
175
- throw new Error(`Attempted to create a client source on a closed observer`);
176
- }
177
- const serviceId = config.serviceId ?? this.config.defaultServiceId;
178
- const mediaUnitId = config.mediaUnitId ?? this.config.defaultMediaUnitId;
179
- const joined = config.joined ?? Date.now();
180
- return this._sources.createClientSource({
181
- ...config,
182
- serviceId,
155
+ const {
156
+ serviceId = this.config.defaultServiceId,
157
+ mediaUnitId = this.config.defaultMediaUnitId,
158
+ appData = {} as T,
159
+ ...callConfig
160
+ } = config;
161
+
162
+ return this._sources.createCallSource({
163
+ ...callConfig,
164
+ appData,
183
165
  mediaUnitId,
184
- joined,
166
+ serviceId,
185
167
  });
186
168
  }
187
169
 
188
- public createSfuSource(
189
- config: PartialBy<ObservedSfuSourceConfig, 'serviceId' | 'mediaUnitId' | 'joined'>
170
+ public createSfuSource<T extends Record<string, unknown> = Record<string, unknown>>(
171
+ config: PartialBy<ObservedSfuSourceConfig<T>, 'serviceId' | 'mediaUnitId' | 'joined' | 'appData'>
190
172
  ): ObservedSfuSource {
191
173
  if (this._closed) {
192
- throw new Error(`Attempted to create a sfu source on a closed observer`);
174
+ throw new Error('Attempted to create a sfu source on a closed observer');
193
175
  }
194
- const serviceId = config.serviceId ?? this.config.defaultServiceId;
195
- const mediaUnitId = config.mediaUnitId ?? this.config.defaultMediaUnitId;
196
- const joined = config.joined ?? Date.now();
197
- return this._sources.createSfuSource({
198
- ...config,
176
+ const {
177
+ appData = {} as T,
178
+ serviceId = this.config.defaultServiceId,
179
+ mediaUnitId = this.config.defaultMediaUnitId,
180
+ joined = Date.now(),
181
+ ...sfuConfig
182
+ } = config;
183
+
184
+ return this._sources.createSfuSource<T>({
185
+ ...sfuConfig,
186
+ appData,
199
187
  serviceId,
200
188
  mediaUnitId,
201
189
  joined,
@@ -204,7 +192,7 @@ export class Observer {
204
192
 
205
193
  public async evaluate() {
206
194
  return new Promise<void>((resolve, reject) => {
207
- this._evaluator.once('ready', err => {
195
+ this._evaluator.once('ready', (err) => {
208
196
  if (err) reject(err);
209
197
  else resolve();
210
198
  });
@@ -218,7 +206,7 @@ export class Observer {
218
206
 
219
207
  public addEvaluators(...processes: EvaluatorProcess[]) {
220
208
  if (this._closed) {
221
- throw new Error(`Attempted to add an evaluator to a closed observer`);
209
+ throw new Error('Attempted to add an evaluator to a closed observer');
222
210
  }
223
211
  for (const process of processes) {
224
212
  this._evaluator.addProcess(process);
@@ -227,7 +215,7 @@ export class Observer {
227
215
 
228
216
  public removeEvaluators(...processes: EvaluatorProcess[]) {
229
217
  if (this._closed) {
230
- throw new Error(`Attempted to remove an evaluator from a closed observer`);
218
+ throw new Error('Attempted to remove an evaluator from a closed observer');
231
219
  }
232
220
  for (const process of processes) {
233
221
  this._evaluator.removeProcess(process);
@@ -236,7 +224,7 @@ export class Observer {
236
224
 
237
225
  public addSinks(...processes: ObserverSinkProcess[]) {
238
226
  if (this._closed) {
239
- throw new Error(`Attempted to add an evaluator to a closed observer`);
227
+ throw new Error('Attempted to add an evaluator to a closed observer');
240
228
  }
241
229
  for (const process of processes) {
242
230
  this._sink.addProcess(process);
@@ -245,194 +233,267 @@ export class Observer {
245
233
 
246
234
  public removeSinks(...processes: ObserverSinkProcess[]) {
247
235
  if (this._closed) {
248
- throw new Error(`Attempted to remove an evaluator from a closed observer`);
236
+ throw new Error('Attempted to remove an evaluator from a closed observer');
249
237
  }
250
238
  for (const process of processes) {
251
239
  this._sink.removeProcess(process);
252
240
  }
253
241
  }
254
242
 
255
- public calls(): AsyncIterableIterator<[string, Models.Call]> {
256
- const { callStorage } = this._storages;
257
- return callStorage[Symbol.asyncIterator]();
243
+ public calls(): AsyncIterableIterator<CallEntry> {
244
+ const storageProvider = this._storages;
245
+
246
+ return asyncIteratorConverter((async function *() {
247
+ for await (const [ , callModel ] of storageProvider.callStorage[Symbol.asyncIterator]()) {
248
+ if (!callModel) continue;
249
+ yield createCallEntry(storageProvider, callModel);
250
+ }
251
+ })());
258
252
  }
259
253
 
260
- public sfus(): AsyncIterableIterator<[string, Models.Sfu]> {
261
- const { sfuStorage } = this._storages;
262
- return sfuStorage[Symbol.asyncIterator]();
254
+ public sfus(): AsyncIterableIterator<SfuEntry> {
255
+ const storageProvider = this._storages;
256
+
257
+ return asyncIteratorConverter((async function *() {
258
+ for await (const [ , sfuModel ] of storageProvider.sfuStorage[Symbol.asyncIterator]()) {
259
+ if (!sfuModel) continue;
260
+ yield createSfuEntry(storageProvider, sfuModel);
261
+ }
262
+ })());
263
263
  }
264
264
 
265
- public sfuTransports(): AsyncIterableIterator<[string, Models.SfuTransport]> {
266
- const { sfuTransportStorage } = this._storages;
267
- return sfuTransportStorage[Symbol.asyncIterator]();
265
+ public sfuTransports(): AsyncIterableIterator<SfuTransportEntry> {
266
+ const storageProvider = this._storages;
267
+
268
+ return asyncIteratorConverter((async function *() {
269
+ for await (const [ , sfuTransportModel ] of storageProvider.sfuTransportStorage[Symbol.asyncIterator]()) {
270
+ if (!sfuTransportModel) continue;
271
+ yield createSfuTransportEntry(storageProvider, sfuTransportModel);
272
+ }
273
+ })());
268
274
  }
269
275
 
270
- public sfuInboundRtpPads(): AsyncIterableIterator<[string, Models.SfuInboundRtpPad]> {
271
- const { sfuInboundRtpPadStorage } = this._storages;
272
- return sfuInboundRtpPadStorage[Symbol.asyncIterator]();
276
+ public sfuInboundRtpPads(): AsyncIterableIterator<SfuInboundRtpPadEntry> {
277
+ const storageProvider = this._storages;
278
+
279
+ return asyncIteratorConverter((async function *() {
280
+ for await (const [ , sfuInboundRtpPadModel ] of storageProvider.sfuInboundRtpPadStorage[Symbol.asyncIterator]()) {
281
+ if (!sfuInboundRtpPadModel) continue;
282
+ yield createSfuInboundRtpPadEntry(storageProvider, sfuInboundRtpPadModel);
283
+ }
284
+ })());
273
285
  }
274
286
 
275
- public sfuOutboundRtpPads(): AsyncIterableIterator<[string, Models.SfuOutboundRtpPad]> {
276
- const { sfuOutboundRtpPadStorage } = this._storages;
277
- return sfuOutboundRtpPadStorage[Symbol.asyncIterator]();
287
+ public sfuOutboundRtpPads(): AsyncIterableIterator<SfuOutboundRtpPadEntry> {
288
+ const storageProvider = this._storages;
289
+
290
+ return asyncIteratorConverter((async function *() {
291
+ for await (const [ , sfuOutboundRtpPadModel ] of storageProvider.sfuOutboundRtpPadStorage[Symbol.asyncIterator]()) {
292
+ if (!sfuOutboundRtpPadModel) continue;
293
+ yield createSfuOutboundRtpPadEntry(storageProvider, sfuOutboundRtpPadModel);
294
+ }
295
+ })());
278
296
  }
279
297
 
280
- public clients(): AsyncIterableIterator<[string, Models.Client]> {
281
- const { clientStorage } = this._storages;
282
- return clientStorage[Symbol.asyncIterator]();
298
+ public clients(): AsyncIterableIterator<ClientEntry> {
299
+ const storageProvider = this._storages;
300
+
301
+ return asyncIteratorConverter((async function *() {
302
+ for await (const [ , callModel ] of storageProvider.clientStorage[Symbol.asyncIterator]()) {
303
+ if (!callModel) continue;
304
+ yield createClientEntry(storageProvider, callModel);
305
+ }
306
+ })());
283
307
  }
284
308
 
285
- public peerConnections(): AsyncIterableIterator<[string, Models.PeerConnection]> {
286
- const { peerConnectionStorage } = this._storages;
287
- return peerConnectionStorage[Symbol.asyncIterator]();
309
+ public peerConnections(): AsyncIterableIterator<PeerConnectionEntry> {
310
+ const storageProvider = this._storages;
311
+
312
+ return asyncIteratorConverter((async function *() {
313
+ for await (const [ , peerConnectionModel ] of storageProvider.peerConnectionStorage[Symbol.asyncIterator]()) {
314
+ if (!peerConnectionModel) continue;
315
+ yield createPeerConnectionEntry(storageProvider, peerConnectionModel);
316
+ }
317
+ })());
288
318
  }
289
319
 
290
320
  public async getTrack(trackId: string) {
291
321
  const { inboundTrackStorage, outboundTrackStorage } = this._storages;
292
- const [inbTrack, outbTrack] = await Promise.all([
322
+ const [ inbTrackModel, outbTrackModel ] = await Promise.all([
293
323
  inboundTrackStorage.get(trackId),
294
324
  outboundTrackStorage.get(trackId),
295
325
  ]);
296
- if (inbTrack) return inbTrack;
297
- else if (outbTrack) return outbTrack;
326
+
327
+ if (inbTrackModel) return createInboundTrackEntry(this._storages, inbTrackModel);
328
+ else if (outbTrackModel) return createOutboundTrackEntry(this._storages, outbTrackModel);
298
329
  }
299
330
 
300
331
  public async getAllTracks(trackIds: Iterable<string>) {
332
+ const storageProvider = this._storages;
301
333
  const { inboundTrackStorage, outboundTrackStorage } = this._storages;
302
- const [inbTracks, outbTracks] = await Promise.all([
334
+
335
+ const [ inbTrackModels, outbTrackModels ] = await Promise.all([
303
336
  inboundTrackStorage.getAll(trackIds),
304
337
  outboundTrackStorage.getAll(trackIds),
305
338
  ]);
306
- return new Map([...inbTracks, ...outbTracks]);
339
+
340
+ const result = new Map<string, InboundTrackEntry | OutboundTrackEntry>();
341
+
342
+ for (const [ trackId, model ] of inbTrackModels) {
343
+ result.set(trackId, createInboundTrackEntry(storageProvider, model));
344
+ }
345
+ for (const [ trackId, model ] of outbTrackModels) {
346
+ result.set(trackId, createOutboundTrackEntry(storageProvider, model));
347
+ }
348
+
349
+ return result;
307
350
  }
308
351
 
309
- public inboundTracks(): AsyncIterableIterator<[string, Models.InboundTrack]> {
310
- const { inboundTrackStorage } = this._storages;
311
- return inboundTrackStorage[Symbol.asyncIterator]();
352
+ public inboundTracks(): AsyncIterableIterator<InboundTrackEntry> {
353
+ const storageProvider = this._storages;
354
+
355
+ return asyncIteratorConverter((async function *() {
356
+ for await (const [ , inboundTrackModel ] of storageProvider.inboundTrackStorage[Symbol.asyncIterator]()) {
357
+ if (!inboundTrackModel) continue;
358
+ yield createInboundTrackEntry(storageProvider, inboundTrackModel);
359
+ }
360
+ })());
312
361
  }
313
362
 
314
- public outboundTracks(): AsyncIterableIterator<[string, Models.OutboundTrack]> {
315
- const { outboundTrackStorage } = this._storages;
316
- return outboundTrackStorage[Symbol.asyncIterator]();
363
+ public outboundTracks(): AsyncIterableIterator<OutboundTrackEntry> {
364
+ const storageProvider = this._storages;
365
+
366
+ return asyncIteratorConverter((async function *() {
367
+ for await (const [ , outboundTrackModel ] of storageProvider.outboundTrackStorage[Symbol.asyncIterator]()) {
368
+ if (!outboundTrackModel) continue;
369
+ yield createOutboundTrackEntry(storageProvider, outboundTrackModel);
370
+ }
371
+ })());
317
372
  }
318
373
 
319
- public sfuSctpChannels(): AsyncIterableIterator<[string, Models.SfuSctpChannel]> {
320
- const { sfuSctpChannelStorage } = this._storages;
321
- return sfuSctpChannelStorage[Symbol.asyncIterator]();
374
+ public sfuSctpChannels(): AsyncIterableIterator<SfuSctpChannelEntry> {
375
+ const storageProvider = this._storages;
376
+
377
+ return asyncIteratorConverter((async function *() {
378
+ for await (const [ , sfuSctpChannelModel ] of storageProvider.sfuSctpChannelStorage[Symbol.asyncIterator]()) {
379
+ if (!sfuSctpChannelModel) continue;
380
+ yield createSfuSctpChannelEntry(storageProvider, sfuSctpChannelModel);
381
+ }
382
+ })());
322
383
  }
323
384
 
324
- public async getCall(callId: string): Promise<Models.Call | undefined> {
325
- const { callStorage } = this._storages;
326
- return callStorage.get(callId);
385
+ public async getCall(callId: string): Promise<CallEntry> {
386
+ return createCallEntry(this._storages, await this._storages.callStorage.get(callId));
327
387
  }
328
388
 
329
- public async getAllCalls(callIds: Iterable<string>): Promise<ReadonlyMap<string, Models.Call>> {
330
- const { callStorage } = this._storages;
331
- return callStorage.getAll(callIds);
389
+ public async getAllCalls(callIds: Iterable<string>): Promise<ReadonlyMap<string, CallEntry>> {
390
+ const models = await this._storages.callStorage.getAll(callIds);
391
+
392
+ return new Map(Array.from(models).map(([ callId, model ]) => [ callId, createCallEntry(this._storages, model) ]));
332
393
  }
333
394
 
334
- public async getSfu(sfuId: string): Promise<Models.Sfu | undefined> {
335
- const { sfuStorage } = this._storages;
336
- return sfuStorage.get(sfuId);
395
+ public async getSfu(sfuId: string): Promise<SfuEntry> {
396
+ return createSfuEntry(this._storages, await this._storages.sfuStorage.get(sfuId));
337
397
  }
338
398
 
339
- public async getAllSfus(sfuIds: Iterable<string>): Promise<ReadonlyMap<string, Models.Sfu>> {
340
- const { sfuStorage } = this._storages;
341
- return sfuStorage.getAll(sfuIds);
399
+ public async getAllSfus(sfuIds: Iterable<string>): Promise<ReadonlyMap<string, SfuEntry>> {
400
+ const models = await this._storages.sfuStorage.getAll(sfuIds);
401
+
402
+ return new Map(Array.from(models).map(([ sfuId, model ]) => [ sfuId, createSfuEntry(this._storages, model) ]));
342
403
  }
343
404
 
344
- public async getSfuTransport(sfuTransportId: string): Promise<Models.SfuTransport | undefined> {
345
- const { sfuTransportStorage } = this._storages;
346
- return sfuTransportStorage.get(sfuTransportId);
405
+ public async getSfuTransport(sfuTransportId: string): Promise<SfuTransportEntry | undefined> {
406
+ return createSfuTransportEntry(this._storages, await this._storages.sfuTransportStorage.get(sfuTransportId));
347
407
  }
348
408
 
349
409
  public async getAllSfuTransports(
350
410
  sfuTransportIds: Iterable<string>
351
- ): Promise<ReadonlyMap<string, Models.SfuTransport>> {
352
- const { sfuTransportStorage } = this._storages;
353
- return sfuTransportStorage.getAll(sfuTransportIds);
411
+ ): Promise<ReadonlyMap<string, SfuTransportEntry>> {
412
+ const models = await this._storages.sfuTransportStorage.getAll(sfuTransportIds);
413
+
414
+ return new Map(Array.from(models).map(([ sfuTransportId, model ]) => [ sfuTransportId, createSfuTransportEntry(this._storages, model) ]));
354
415
  }
355
416
 
356
- public async getSfuInboundRtpPad(sfuInboundRtpPadId: string): Promise<Models.SfuInboundRtpPad | undefined> {
357
- const { sfuInboundRtpPadStorage } = this._storages;
358
- return sfuInboundRtpPadStorage.get(sfuInboundRtpPadId);
417
+ public async getSfuInboundRtpPad(sfuInboundRtpPadId: string): Promise<SfuInboundRtpPadEntry | undefined> {
418
+ return createSfuInboundRtpPadEntry(this._storages, await this._storages.sfuInboundRtpPadStorage.get(sfuInboundRtpPadId));
359
419
  }
360
420
 
361
421
  public async getAllSfuInboundRtpPads(
362
422
  sfuInboundRtpPadIds: Iterable<string>
363
- ): Promise<ReadonlyMap<string, Models.SfuInboundRtpPad>> {
364
- const { sfuInboundRtpPadStorage } = this._storages;
365
- return sfuInboundRtpPadStorage.getAll(sfuInboundRtpPadIds);
423
+ ): Promise<ReadonlyMap<string, SfuInboundRtpPadEntry>> {
424
+ const models = await this._storages.sfuInboundRtpPadStorage.getAll(sfuInboundRtpPadIds);
425
+
426
+ return new Map(Array.from(models).map(([ sfuInboundRtpPadId, model ]) => [ sfuInboundRtpPadId, createSfuInboundRtpPadEntry(this._storages, model) ]));
366
427
  }
367
428
 
368
- public async getSfuOutboundRtpPad(sfuOutboundRtpPadId: string): Promise<Models.SfuOutboundRtpPad | undefined> {
369
- const { sfuOutboundRtpPadStorage } = this._storages;
370
- return sfuOutboundRtpPadStorage.get(sfuOutboundRtpPadId);
429
+ public async getSfuOutboundRtpPad(sfuOutboundRtpPadId: string): Promise<SfuOutboundRtpPadEntry | undefined> {
430
+ return createSfuOutboundRtpPadEntry(this._storages, await this._storages.sfuOutboundRtpPadStorage.get(sfuOutboundRtpPadId));
371
431
  }
372
432
 
373
433
  public async getAllSfuOutboundRtpPads(
374
434
  sfuOutboundRtpPadIds: Iterable<string>
375
- ): Promise<ReadonlyMap<string, Models.SfuOutboundRtpPad>> {
376
- const { sfuOutboundRtpPadStorage } = this._storages;
377
- return sfuOutboundRtpPadStorage.getAll(sfuOutboundRtpPadIds);
435
+ ): Promise<ReadonlyMap<string, SfuOutboundRtpPadEntry>> {
436
+ const models = await this._storages.sfuOutboundRtpPadStorage.getAll(sfuOutboundRtpPadIds);
437
+
438
+ return new Map(Array.from(models).map(([ sfuOutboundRtpPadId, model ]) => [ sfuOutboundRtpPadId, createSfuOutboundRtpPadEntry(this._storages, model) ]));
378
439
  }
379
440
 
380
- public async getClient(clientId: string): Promise<Models.Client | undefined> {
381
- const { clientStorage } = this._storages;
382
- return clientStorage.get(clientId);
441
+ public async getClient(clientId: string): Promise<ClientEntry> {
442
+ return createClientEntry(this._storages, await this._storages.clientStorage.get(clientId));
383
443
  }
384
444
 
385
- public async getAllClient(clientIds: Iterable<string>): Promise<ReadonlyMap<string, Models.Client>> {
386
- const { clientStorage } = this._storages;
387
- return clientStorage.getAll(clientIds);
445
+ public async getAllClient(clientIds: Iterable<string>): Promise<ReadonlyMap<string, ClientEntry>> {
446
+ const models = await this._storages.clientStorage.getAll(clientIds);
447
+
448
+ return new Map(Array.from(models).map(([ clientId, model ]) => [ clientId, createClientEntry(this._storages, model) ]));
388
449
  }
389
450
 
390
- public async getPeerConnection(peerConnectionId: string): Promise<Models.PeerConnection | undefined> {
391
- const { peerConnectionStorage } = this._storages;
392
- return peerConnectionStorage.get(peerConnectionId);
451
+ public async getPeerConnection(peerConnectionId: string): Promise<PeerConnectionEntry> {
452
+ return createPeerConnectionEntry(this._storages, await this._storages.peerConnectionStorage.get(peerConnectionId));
393
453
  }
394
454
 
395
455
  public async getAllPeerConnections(
396
456
  peerConnectionIds: Iterable<string>
397
- ): Promise<ReadonlyMap<string, Models.PeerConnection>> {
398
- const { peerConnectionStorage } = this._storages;
399
- return peerConnectionStorage.getAll(peerConnectionIds);
457
+ ): Promise<ReadonlyMap<string, PeerConnectionEntry>> {
458
+ const models = await this._storages.peerConnectionStorage.getAll(peerConnectionIds);
459
+
460
+ return new Map(Array.from(models).map(([ peerConnectionId, model ]) => [ peerConnectionId, createPeerConnectionEntry(this._storages, model) ]));
400
461
  }
401
462
 
402
- public async getInboundTrack(inboundTrackId: string): Promise<Models.InboundTrack | undefined> {
403
- const { inboundTrackStorage } = this._storages;
404
- return inboundTrackStorage.get(inboundTrackId);
463
+ public async getInboundTrack(inboundTrackId: string): Promise<InboundTrackEntry> {
464
+ return createInboundTrackEntry(this._storages, await this._storages.inboundTrackStorage.get(inboundTrackId));
405
465
  }
406
466
 
407
467
  public async getAllInboundTracks(
408
468
  inboundTrackIds: Iterable<string>
409
- ): Promise<ReadonlyMap<string, Models.InboundTrack>> {
410
- const { inboundTrackStorage } = this._storages;
411
- return inboundTrackStorage.getAll(inboundTrackIds);
469
+ ): Promise<ReadonlyMap<string, InboundTrackEntry>> {
470
+ const models = await this._storages.inboundTrackStorage.getAll(inboundTrackIds);
471
+
472
+ return new Map(Array.from(models).map(([ inboundTrackId, model ]) => [ inboundTrackId, createInboundTrackEntry(this._storages, model) ]));
412
473
  }
413
474
 
414
- public async getOutboundTrack(outboundTrackId: string): Promise<Models.OutboundTrack | undefined> {
415
- const { outboundTrackStorage } = this._storages;
416
- return outboundTrackStorage.get(outboundTrackId);
475
+ public async getOutboundTrack(outboundTrackId: string): Promise<OutboundTrackEntry> {
476
+ return createOutboundTrackEntry(this._storages, await this._storages.outboundTrackStorage.get(outboundTrackId));
417
477
  }
418
478
 
419
479
  public async getAllOutboundTracks(
420
480
  outboundTrackIds: Iterable<string>
421
- ): Promise<ReadonlyMap<string, Models.OutboundTrack>> {
422
- const { outboundTrackStorage } = this._storages;
423
- return outboundTrackStorage.getAll(outboundTrackIds);
481
+ ): Promise<ReadonlyMap<string, OutboundTrackEntry>> {
482
+ const models = await this._storages.outboundTrackStorage.getAll(outboundTrackIds);
483
+
484
+ return new Map(Array.from(models).map(([ outboundTrackId, model ]) => [ outboundTrackId, createOutboundTrackEntry(this._storages, model) ]));
424
485
  }
425
486
 
426
- public async getSfuSctpChannel(sctpChannelId: string): Promise<Models.SfuSctpChannel | undefined> {
427
- const { sfuSctpChannelStorage } = this._storages;
428
- return sfuSctpChannelStorage.get(sctpChannelId);
487
+ public async getSfuSctpChannel(sctpChannelId: string): Promise<SfuSctpChannelEntry | undefined> {
488
+ return createSfuSctpChannelEntry(this._storages, await this._storages.sfuSctpChannelStorage.get(sctpChannelId));
429
489
  }
430
490
 
431
491
  public async getAllSfuSctpChannel(
432
492
  sctpChannelIds: Iterable<string>
433
- ): Promise<ReadonlyMap<string, Models.SfuSctpChannel>> {
434
- const { sfuSctpChannelStorage } = this._storages;
435
- return sfuSctpChannelStorage.getAll(sctpChannelIds);
493
+ ): Promise<ReadonlyMap<string, SfuSctpChannelEntry>> {
494
+ const models = await this._storages.sfuSctpChannelStorage.getAll(sctpChannelIds);
495
+
496
+ return new Map(Array.from(models).map(([ sctpChannelId, model ]) => [ sctpChannelId, createSfuSctpChannelEntry(this._storages, model) ]));
436
497
  }
437
498
 
438
499
  public get closed() {
@@ -441,8 +502,7 @@ export class Observer {
441
502
 
442
503
  public close() {
443
504
  if (this._closed) {
444
- logger.debug(`Attempted to close twice`);
445
- return;
505
+ return logger.debug('Attempted to close twice');
446
506
  }
447
507
  this._closed = true;
448
508
  this._sources.close();
@@ -3,6 +3,7 @@
3
3
  * Semaphores are used to ensure that only one process can access the shared resource at a time.
4
4
  */
5
5
  export interface Semaphore {
6
+
6
7
  /**
7
8
  * Acquires the semaphore, blocking until the semaphore is available.
8
9
  * When the semaphore is acquired, it prevents other processes from acquiring it.
@@ -29,6 +30,7 @@ export function createDummySemaphore(): Semaphore {
29
30
  * SemaphoreProviders are used to manage access to shared resources across multiple processes.
30
31
  */
31
32
  export interface SemaphoreProvider {
33
+
32
34
  /**
33
35
  * A Semaphore instance that manages access to the 'call' shared resource.
34
36
  * This semaphore ensures that only one process can access the 'call' resource at a time.