@observertc/observer-js 0.42.9 → 1.0.1-1b9b3c5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (295) hide show
  1. package/.prettierrc +6 -6
  2. package/README.md +0 -104
  3. package/lib/ObservedCall.d.ts +63 -43
  4. package/lib/ObservedCall.d.ts.map +1 -1
  5. package/lib/ObservedCall.js +176 -108
  6. package/lib/ObservedCallEventMonitor.d.ts +103 -0
  7. package/lib/ObservedCallEventMonitor.d.ts.map +1 -0
  8. package/lib/ObservedCallEventMonitor.js +312 -0
  9. package/lib/ObservedCallSummary.d.ts +18 -0
  10. package/lib/ObservedCallSummary.d.ts.map +1 -0
  11. package/lib/ObservedCertificate.d.ts +19 -0
  12. package/lib/ObservedCertificate.d.ts.map +1 -0
  13. package/lib/ObservedCertificate.js +38 -0
  14. package/lib/ObservedClient.d.ts +79 -130
  15. package/lib/ObservedClient.d.ts.map +1 -1
  16. package/lib/ObservedClient.js +463 -744
  17. package/lib/ObservedClientEventMonitor.d.ts +89 -0
  18. package/lib/ObservedClientEventMonitor.d.ts.map +1 -0
  19. package/lib/ObservedClientEventMonitor.js +247 -0
  20. package/lib/ObservedClientSummary.d.ts +23 -0
  21. package/lib/ObservedClientSummary.d.ts.map +1 -0
  22. package/lib/ObservedClientSummary.js +2 -0
  23. package/lib/ObservedCodec.d.ts +22 -0
  24. package/lib/ObservedCodec.d.ts.map +1 -0
  25. package/lib/ObservedCodec.js +45 -0
  26. package/lib/ObservedDataChannel.d.ts +25 -69
  27. package/lib/ObservedDataChannel.d.ts.map +1 -1
  28. package/lib/ObservedDataChannel.js +69 -109
  29. package/lib/ObservedIceCandidate.d.ts +29 -0
  30. package/lib/ObservedIceCandidate.d.ts.map +1 -0
  31. package/lib/ObservedIceCandidate.js +59 -0
  32. package/lib/ObservedIceCandidatePair.d.ts +44 -0
  33. package/lib/ObservedIceCandidatePair.d.ts.map +1 -0
  34. package/lib/ObservedIceCandidatePair.js +111 -0
  35. package/lib/ObservedIceTransport.d.ts +36 -0
  36. package/lib/ObservedIceTransport.d.ts.map +1 -0
  37. package/lib/ObservedIceTransport.js +93 -0
  38. package/lib/ObservedInboundRtp.d.ts +92 -0
  39. package/lib/ObservedInboundRtp.d.ts.map +1 -0
  40. package/lib/ObservedInboundRtp.js +193 -0
  41. package/lib/ObservedInboundTrack.d.ts +31 -0
  42. package/lib/ObservedInboundTrack.d.ts.map +1 -0
  43. package/lib/ObservedInboundTrack.js +59 -0
  44. package/lib/ObservedMediaPlayout.d.ts +22 -0
  45. package/lib/ObservedMediaPlayout.d.ts.map +1 -0
  46. package/lib/ObservedMediaPlayout.js +42 -0
  47. package/lib/ObservedMediaSource.d.ts +28 -0
  48. package/lib/ObservedMediaSource.d.ts.map +1 -0
  49. package/lib/ObservedMediaSource.js +55 -0
  50. package/lib/ObservedOutboundRtp.d.ts +62 -0
  51. package/lib/ObservedOutboundRtp.d.ts.map +1 -0
  52. package/lib/ObservedOutboundRtp.js +144 -0
  53. package/lib/ObservedOutboundTrack.d.ts +31 -0
  54. package/lib/ObservedOutboundTrack.d.ts.map +1 -0
  55. package/lib/ObservedOutboundTrack.js +59 -0
  56. package/lib/ObservedPeerConnection.d.ts +132 -80
  57. package/lib/ObservedPeerConnection.d.ts.map +1 -1
  58. package/lib/ObservedPeerConnection.js +646 -357
  59. package/lib/ObservedPeerConnectionTransport.d.ts +17 -0
  60. package/lib/ObservedPeerConnectionTransport.d.ts.map +1 -0
  61. package/lib/ObservedPeerConnectionTransport.js +34 -0
  62. package/lib/ObservedRemoteInboundRtp.d.ts +30 -0
  63. package/lib/ObservedRemoteInboundRtp.d.ts.map +1 -0
  64. package/lib/ObservedRemoteInboundRtp.js +60 -0
  65. package/lib/ObservedRemoteOutboundRtp.d.ts +30 -0
  66. package/lib/ObservedRemoteOutboundRtp.d.ts.map +1 -0
  67. package/lib/ObservedRemoteOutboundRtp.js +60 -0
  68. package/lib/ObservedTURN.d.ts +31 -0
  69. package/lib/ObservedTURN.d.ts.map +1 -0
  70. package/lib/ObservedTURN.js +58 -0
  71. package/lib/ObservedTurnServer.d.ts +25 -0
  72. package/lib/ObservedTurnServer.d.ts.map +1 -0
  73. package/lib/ObservedTurnServer.js +59 -0
  74. package/lib/Observer.d.ts +44 -51
  75. package/lib/Observer.d.ts.map +1 -1
  76. package/lib/Observer.js +135 -226
  77. package/lib/ObserverEventMonitor.d.ts +106 -0
  78. package/lib/ObserverEventMonitor.d.ts.map +1 -0
  79. package/lib/ObserverEventMonitor.js +320 -0
  80. package/lib/ObserverSummary.d.ts +13 -0
  81. package/lib/ObserverSummary.d.ts.map +1 -0
  82. package/lib/ObserverSummary.js +2 -0
  83. package/lib/common/Middleware.d.ts +10 -1
  84. package/lib/common/Middleware.d.ts.map +1 -1
  85. package/lib/common/Middleware.js +55 -36
  86. package/lib/common/logger.d.ts +8 -4
  87. package/lib/common/logger.d.ts.map +1 -1
  88. package/lib/common/logger.js +44 -68
  89. package/lib/common/types.d.ts +0 -21
  90. package/lib/common/types.d.ts.map +1 -1
  91. package/lib/common/types.js +1 -0
  92. package/lib/common/utils.d.ts +3 -1
  93. package/lib/common/utils.d.ts.map +1 -1
  94. package/lib/common/utils.js +23 -3
  95. package/lib/detectors/Detector.d.ts +5 -0
  96. package/lib/detectors/Detector.d.ts.map +1 -0
  97. package/lib/detectors/Detector.js +3 -0
  98. package/lib/detectors/Detectors.d.ts +11 -0
  99. package/lib/detectors/Detectors.d.ts.map +1 -0
  100. package/lib/detectors/Detectors.js +34 -0
  101. package/lib/index.d.ts +26 -25
  102. package/lib/index.d.ts.map +1 -1
  103. package/lib/index.js +45 -41
  104. package/lib/monitors/TurnUsageMonitor.d.ts +0 -52
  105. package/lib/monitors/TurnUsageMonitor.d.ts.map +1 -1
  106. package/lib/monitors/TurnUsageMonitor.js +145 -120
  107. package/lib/schema/ClientEventTypes.d.ts +160 -0
  108. package/lib/schema/ClientEventTypes.d.ts.map +1 -0
  109. package/lib/schema/ClientEventTypes.js +38 -0
  110. package/lib/schema/ClientMetaTypes.d.ts +34 -0
  111. package/lib/schema/ClientMetaTypes.d.ts.map +1 -0
  112. package/lib/schema/ClientMetaTypes.js +16 -0
  113. package/lib/schema/ClientSample.d.ts +1333 -0
  114. package/lib/schema/ClientSample.d.ts.map +1 -0
  115. package/lib/schema/ClientSample.js +4 -0
  116. package/lib/scores/CalculatedScore.d.ts +6 -0
  117. package/lib/scores/CalculatedScore.d.ts.map +1 -0
  118. package/lib/scores/CalculatedScore.js +2 -0
  119. package/lib/scores/DefaultCallScoreCalculator.d.ts +7 -0
  120. package/lib/scores/DefaultCallScoreCalculator.d.ts.map +1 -0
  121. package/lib/scores/DefaultCallScoreCalculator.js +21 -0
  122. package/lib/scores/ScoreCalculator.d.ts +4 -0
  123. package/lib/scores/ScoreCalculator.d.ts.map +1 -0
  124. package/lib/scores/ScoreCalculator.js +2 -0
  125. package/lib/updaters/CallUpdater.d.ts +5 -0
  126. package/lib/updaters/CallUpdater.d.ts.map +1 -0
  127. package/lib/updaters/CallUpdater.js +2 -0
  128. package/lib/updaters/ObserverUpdater.d.ts +5 -0
  129. package/lib/updaters/ObserverUpdater.d.ts.map +1 -0
  130. package/lib/updaters/ObserverUpdater.js +2 -0
  131. package/lib/updaters/OnAllCallObserverUpdater.d.ts +15 -0
  132. package/lib/updaters/OnAllCallObserverUpdater.d.ts.map +1 -0
  133. package/lib/updaters/OnAllCallObserverUpdater.js +50 -0
  134. package/lib/updaters/OnAllClientCallUpdater.d.ts +15 -0
  135. package/lib/updaters/OnAllClientCallUpdater.d.ts.map +1 -0
  136. package/lib/updaters/OnAllClientCallUpdater.js +53 -0
  137. package/lib/updaters/OnAnyCallObserverUpdater.d.ts +12 -0
  138. package/lib/updaters/OnAnyCallObserverUpdater.d.ts.map +1 -0
  139. package/lib/updaters/OnAnyCallObserverUpdater.js +37 -0
  140. package/lib/updaters/OnAnyClientCallUpdater.d.ts +12 -0
  141. package/lib/updaters/OnAnyClientCallUpdater.d.ts.map +1 -0
  142. package/lib/updaters/OnAnyClientCallUpdater.js +36 -0
  143. package/lib/updaters/OnIntervalUpdater.d.ts +10 -0
  144. package/lib/updaters/OnIntervalUpdater.d.ts.map +1 -0
  145. package/lib/updaters/OnIntervalUpdater.js +17 -0
  146. package/lib/updaters/Updater.d.ts +6 -0
  147. package/lib/updaters/Updater.d.ts.map +1 -0
  148. package/lib/updaters/Updater.js +2 -0
  149. package/lib/utils/MediasoupRemoteTrackResolver.d.ts +25 -0
  150. package/lib/utils/MediasoupRemoteTrackResolver.d.ts.map +1 -0
  151. package/lib/utils/MediasoupRemoteTrackResolver.js +110 -0
  152. package/lib/utils/RemoteTrackResolver.d.ts +7 -0
  153. package/lib/utils/RemoteTrackResolver.d.ts.map +1 -0
  154. package/lib/utils/RemoteTrackResolver.js +2 -0
  155. package/package.json +4 -4
  156. package/src/ObservedCall.ts +267 -166
  157. package/src/ObservedCallEventMonitor.ts +389 -0
  158. package/src/ObservedCallSummary.ts +22 -0
  159. package/src/ObservedCertificate.ts +43 -0
  160. package/src/ObservedClient.ts +519 -1020
  161. package/src/ObservedClientEventMonitor.ts +301 -0
  162. package/src/ObservedClientSummary.ts +24 -0
  163. package/src/ObservedCodec.ts +49 -0
  164. package/src/ObservedDataChannel.ts +71 -181
  165. package/src/ObservedIceCandidate.ts +64 -0
  166. package/src/ObservedIceCandidatePair.ts +118 -0
  167. package/src/ObservedIceTransport.ts +99 -0
  168. package/src/ObservedInboundRtp.ts +205 -0
  169. package/src/ObservedInboundTrack.ts +73 -0
  170. package/src/ObservedMediaPlayout.ts +49 -0
  171. package/src/ObservedMediaSource.ts +60 -0
  172. package/src/ObservedOutboundRtp.ts +156 -0
  173. package/src/ObservedOutboundTrack.ts +72 -0
  174. package/src/ObservedPeerConnection.ts +854 -408
  175. package/src/ObservedPeerConnectionTransport.ts +38 -0
  176. package/src/ObservedRemoteInboundRtp.ts +64 -0
  177. package/src/ObservedRemoteOutboundRtp.ts +65 -0
  178. package/src/ObservedTURN.ts +86 -0
  179. package/src/ObservedTurnServer.ts +72 -0
  180. package/src/Observer.ts +180 -295
  181. package/src/ObserverEventMonitor.ts +398 -0
  182. package/src/ObserverSummary.ts +15 -0
  183. package/src/common/Middleware.ts +70 -42
  184. package/src/common/logger.ts +60 -69
  185. package/src/common/types.ts +0 -42
  186. package/src/common/utils.ts +24 -2
  187. package/src/detectors/Detector.ts +6 -0
  188. package/src/detectors/Detectors.ts +38 -0
  189. package/src/index.ts +26 -90
  190. package/src/monitors/TurnUsageMonitor.ts +164 -164
  191. package/src/schema/ClientEventTypes.ts +176 -0
  192. package/src/schema/ClientMetaTypes.ts +41 -0
  193. package/src/schema/ClientSample.ts +1682 -0
  194. package/src/scores/CalculatedScore.ts +6 -0
  195. package/src/scores/DefaultCallScoreCalculator.ts +23 -0
  196. package/src/scores/ScoreCalculator.ts +3 -0
  197. package/src/updaters/CallUpdater.ts +5 -0
  198. package/src/updaters/ObserverUpdater.ts +5 -0
  199. package/src/updaters/OnAllCallObserverUpdater.ts +59 -0
  200. package/src/updaters/OnAllClientCallUpdater.ts +61 -0
  201. package/src/updaters/OnAnyCallObserverUpdater.ts +41 -0
  202. package/src/updaters/OnAnyClientCallUpdater.ts +39 -0
  203. package/src/updaters/OnIntervalUpdater.ts +19 -0
  204. package/src/updaters/Updater.ts +5 -0
  205. package/src/utils/MediasoupRemoteTrackResolver.ts +155 -0
  206. package/src/utils/RemoteTrackResolver.ts +12 -0
  207. package/tsconfig.json +3 -3
  208. package/lib/ObservedICE.d.ts +0 -64
  209. package/lib/ObservedICE.d.ts.map +0 -1
  210. package/lib/ObservedICE.js +0 -141
  211. package/lib/ObservedInboundAudioTrack.d.ts +0 -96
  212. package/lib/ObservedInboundAudioTrack.d.ts.map +0 -1
  213. package/lib/ObservedInboundAudioTrack.js +0 -217
  214. package/lib/ObservedInboundVideoTrack.d.ts +0 -101
  215. package/lib/ObservedInboundVideoTrack.d.ts.map +0 -1
  216. package/lib/ObservedInboundVideoTrack.js +0 -232
  217. package/lib/ObservedOutboundAudioTrack.d.ts +0 -87
  218. package/lib/ObservedOutboundAudioTrack.d.ts.map +0 -1
  219. package/lib/ObservedOutboundAudioTrack.js +0 -186
  220. package/lib/ObservedOutboundVideoTrack.d.ts +0 -91
  221. package/lib/ObservedOutboundVideoTrack.d.ts.map +0 -1
  222. package/lib/ObservedOutboundVideoTrack.js +0 -193
  223. package/lib/ObservedSfu.d.ts +0 -59
  224. package/lib/ObservedSfu.d.ts.map +0 -1
  225. package/lib/ObservedSfu.js +0 -157
  226. package/lib/ObservedSfuInboundRtpPad.d.ts +0 -42
  227. package/lib/ObservedSfuInboundRtpPad.d.ts.map +0 -1
  228. package/lib/ObservedSfuInboundRtpPad.js +0 -71
  229. package/lib/ObservedSfuOutboundRtpPad.d.ts +0 -42
  230. package/lib/ObservedSfuOutboundRtpPad.d.ts.map +0 -1
  231. package/lib/ObservedSfuOutboundRtpPad.js +0 -72
  232. package/lib/ObservedSfuSctpChannel.d.ts +0 -42
  233. package/lib/ObservedSfuSctpChannel.d.ts.map +0 -1
  234. package/lib/ObservedSfuSctpChannel.js +0 -57
  235. package/lib/ObservedSfuTransport.d.ts +0 -58
  236. package/lib/ObservedSfuTransport.d.ts.map +0 -1
  237. package/lib/ObservedSfuTransport.js +0 -120
  238. package/lib/RemoteTrackAssigner.d.ts +0 -14
  239. package/lib/RemoteTrackAssigner.d.ts.map +0 -1
  240. package/lib/RemoteTrackAssigner.js +0 -52
  241. package/lib/ReportsCollector.d.ts +0 -109
  242. package/lib/ReportsCollector.d.ts.map +0 -1
  243. package/lib/ReportsCollector.js +0 -207
  244. package/lib/common/CalculatedScore.d.ts +0 -80
  245. package/lib/common/CalculatedScore.d.ts.map +0 -1
  246. package/lib/common/CalculatedScore.js +0 -162
  247. package/lib/common/CallEventType.d.ts +0 -63
  248. package/lib/common/CallEventType.d.ts.map +0 -1
  249. package/lib/common/CallEventType.js +0 -39
  250. package/lib/common/CallMetaReports.d.ts +0 -42
  251. package/lib/common/CallMetaReports.d.ts.map +0 -1
  252. package/lib/common/CallMetaReports.js +0 -36
  253. package/lib/common/QualityScoreUtils.d.ts +0 -1
  254. package/lib/common/QualityScoreUtils.d.ts.map +0 -1
  255. package/lib/common/QualityScoreUtils.js +0 -1
  256. package/lib/common/TypedEventEmitter.d.ts +0 -22
  257. package/lib/common/TypedEventEmitter.d.ts.map +0 -1
  258. package/lib/common/TypedEventEmitter.js +0 -11
  259. package/lib/common/callEventReports.d.ts +0 -10
  260. package/lib/common/callEventReports.d.ts.map +0 -1
  261. package/lib/common/callEventReports.js +0 -112
  262. package/lib/monitors/CallSummary.d.ts +0 -37
  263. package/lib/monitors/CallSummary.d.ts.map +0 -1
  264. package/lib/monitors/CallSummaryMonitor.d.ts +0 -32
  265. package/lib/monitors/CallSummaryMonitor.d.ts.map +0 -1
  266. package/lib/monitors/CallSummaryMonitor.js +0 -152
  267. package/lib/monitors/ClientIssueMonitor.d.ts +0 -32
  268. package/lib/monitors/ClientIssueMonitor.d.ts.map +0 -1
  269. package/lib/monitors/ClientIssueMonitor.js +0 -49
  270. package/lib/monitors/SfuServerMonitor.d.ts +0 -79
  271. package/lib/monitors/SfuServerMonitor.d.ts.map +0 -1
  272. package/lib/monitors/SfuServerMonitor.js +0 -198
  273. package/src/ObservedICE.ts +0 -237
  274. package/src/ObservedInboundAudioTrack.ts +0 -344
  275. package/src/ObservedInboundVideoTrack.ts +0 -361
  276. package/src/ObservedOutboundAudioTrack.ts +0 -307
  277. package/src/ObservedOutboundVideoTrack.ts +0 -319
  278. package/src/ObservedSfu.ts +0 -231
  279. package/src/ObservedSfuInboundRtpPad.ts +0 -106
  280. package/src/ObservedSfuOutboundRtpPad.ts +0 -107
  281. package/src/ObservedSfuSctpChannel.ts +0 -103
  282. package/src/ObservedSfuTransport.ts +0 -185
  283. package/src/RemoteTrackAssigner.ts +0 -68
  284. package/src/ReportsCollector.ts +0 -336
  285. package/src/common/CalculatedScore.ts +0 -188
  286. package/src/common/CallEventType.ts +0 -69
  287. package/src/common/CallMetaReports.ts +0 -82
  288. package/src/common/QualityScoreUtils.ts +0 -0
  289. package/src/common/TypedEventEmitter.ts +0 -32
  290. package/src/common/callEventReports.ts +0 -178
  291. package/src/monitors/CallSummary.ts +0 -38
  292. package/src/monitors/CallSummaryMonitor.ts +0 -192
  293. package/src/monitors/ClientIssueMonitor.ts +0 -88
  294. package/src/monitors/SfuServerMonitor.ts +0 -285
  295. /package/lib/{monitors/CallSummary.js → ObservedCallSummary.js} +0 -0
@@ -0,0 +1,6 @@
1
+
2
+ export type CalculatedScore = {
3
+ weight: number;
4
+ value?: number;
5
+ appData?: Record<string, unknown>;
6
+ };
@@ -0,0 +1,23 @@
1
+ import { ObservedCall } from '../ObservedCall';
2
+
3
+ export class DefaultCallScoreCalculator {
4
+
5
+ public constructor(
6
+ public readonly observedCall: ObservedCall,
7
+ ) {
8
+ }
9
+
10
+ public update() {
11
+ let totalScore = 0;
12
+ let totalWeight = 0;
13
+
14
+ for (const client of this.observedCall.observedClients.values()) {
15
+ if (client.score === undefined) continue;
16
+
17
+ totalScore += client.score * client.calculatedScore.weight;
18
+ totalWeight += client.calculatedScore.weight;
19
+ }
20
+
21
+ this.observedCall.calculatedScore.value = totalWeight ? totalScore / totalWeight : undefined;
22
+ }
23
+ }
@@ -0,0 +1,3 @@
1
+ export interface ScoreCalculator {
2
+ update(): void;
3
+ }
@@ -0,0 +1,5 @@
1
+ import { ObservedClient } from '../ObservedClient';
2
+
3
+ export interface CallUpdater {
4
+ onClientUpdate(observedClient: ObservedClient): void;
5
+ }
@@ -0,0 +1,5 @@
1
+ import { ObservedCall } from '../ObservedCall';
2
+
3
+ export interface ObserverUpdater {
4
+ onCallUpdate(observedCall: ObservedCall): void;
5
+ }
@@ -0,0 +1,59 @@
1
+ import { ObservedCall } from '../ObservedCall';
2
+ import { Observer } from '../Observer';
3
+ import { Updater } from './Updater';
4
+
5
+ export class OnAllCallObserverUpdater implements Updater {
6
+ public readonly name = 'OnAllCallObserverUpdater';
7
+ public readonly description = 'Call Observer\'s update() method when all of the ObservedCalls are updated';
8
+
9
+ private readonly _updatedCalls = new Set<string>();
10
+ public closed = false;
11
+
12
+ public constructor(
13
+ private observer: Observer
14
+ ) {
15
+ this._onNewObservedCall = this._onNewObservedCall.bind(this);
16
+
17
+ this.observer.once('close', () => {
18
+ this.observer.off('newcall', this._onNewObservedCall);
19
+ });
20
+ this.observer.on('newcall', this._onNewObservedCall);
21
+ }
22
+
23
+ close(): void {
24
+ if (this.closed) return;
25
+ this.closed = true;
26
+
27
+ this._updatedCalls.clear();
28
+ }
29
+
30
+ private _onNewObservedCall(observedCall: ObservedCall) {
31
+ if (this.closed) return;
32
+
33
+ const onUpdate = () => this._onObservedCallUpdated(observedCall);
34
+
35
+ observedCall.once('close', () => {
36
+ observedCall.off('update', onUpdate);
37
+ this._updatedCalls.delete(observedCall.callId);
38
+
39
+ this._updateIfEveryCallUpdated();
40
+ });
41
+ observedCall.on('update', onUpdate);
42
+ }
43
+
44
+ private _onObservedCallUpdated(observedCall: ObservedCall) {
45
+ if (observedCall.closed) return;
46
+
47
+ this._updatedCalls.add(observedCall.callId);
48
+
49
+ this._updateIfEveryCallUpdated();
50
+ }
51
+
52
+ private _updateIfEveryCallUpdated() {
53
+ if (this._updatedCalls.size < this.observer.observedCalls.size) return;
54
+ else if (this.closed) return;
55
+
56
+ this._updatedCalls.clear();
57
+ this.observer.update();
58
+ }
59
+ }
@@ -0,0 +1,61 @@
1
+ import { ObservedCall } from '../ObservedCall';
2
+ import { ObservedClient } from '../ObservedClient';
3
+ import { Updater } from './Updater';
4
+
5
+ export class OnAllClientCallUpdater implements Updater {
6
+ readonly name = 'OnAllClientCallUpdater';
7
+ readonly description = 'Call the update() method of the ObservedCall once all client has been updated';
8
+
9
+ private readonly _updatedClients = new Set<string>();
10
+ public closed = false;
11
+
12
+ public constructor(
13
+ private _observedCall: ObservedCall
14
+ ) {
15
+ this._onNewObservedClient = this._onNewObservedClient.bind(this);
16
+
17
+ this._observedCall.once('close', () => {
18
+ this._observedCall.off('newclient', this._onNewObservedClient);
19
+ });
20
+ this._observedCall.on('newclient', this._onNewObservedClient);
21
+ }
22
+
23
+ public close(): void {
24
+ if (this.closed) return;
25
+ this.closed = true;
26
+ // do nothing, as close once emitted unsubscription happened
27
+ this._updatedClients.clear();
28
+ }
29
+
30
+ private _onNewObservedClient(observedClient: ObservedClient) {
31
+ if (this.closed) return;
32
+
33
+ const onUpdate = () => this._onClientUpdate(observedClient);
34
+
35
+ observedClient.once('close', () => {
36
+ observedClient.off('update', onUpdate);
37
+ this._updatedClients.delete(observedClient.clientId);
38
+ this._updateIfEveryClientUpdated();
39
+ });
40
+ observedClient.on('update', onUpdate);
41
+ }
42
+
43
+ private _onClientUpdate(observedClient: ObservedClient) {
44
+ if (observedClient.closed) return;
45
+
46
+ this._updatedClients.add(observedClient.clientId);
47
+ this._updateIfEveryClientUpdated();
48
+ }
49
+
50
+ private _updateIfEveryClientUpdated() {
51
+ if (this._updatedClients.size < this._observedCall.observedClients.size) {
52
+ return;
53
+ } else if (this.closed) {
54
+ return;
55
+ }
56
+
57
+ this._updatedClients.clear();
58
+ this._observedCall.update();
59
+ }
60
+
61
+ }
@@ -0,0 +1,41 @@
1
+ import { ObservedCall } from '../ObservedCall';
2
+ import { Observer } from '../Observer';
3
+ import { Updater } from './Updater';
4
+
5
+ export class OnAnyCallObserverUpdater implements Updater {
6
+ public readonly name = 'OnAnyCallObserverUpdater';
7
+ public readonly description = 'Call Observer\'s update() method on any of the ObservedCall is updated';
8
+ public closed = false;
9
+
10
+ public constructor(
11
+ private observver: Observer
12
+ ) {
13
+ this._onNewObservedCall = this._onNewObservedCall.bind(this);
14
+
15
+ this.observver.once('close', () => {
16
+ this.observver.off('newcall', this._onNewObservedCall);
17
+ });
18
+ this.observver.on('newcall', this._onNewObservedCall);
19
+ }
20
+
21
+ close(): void {
22
+ if (this.closed) return;
23
+ this.closed = true;
24
+ // do nothing, because we unsubscribe once close is emitted from observer
25
+ }
26
+
27
+ private _onNewObservedCall(observedCall: ObservedCall) {
28
+ if (this.closed) return;
29
+
30
+ const onUpdate = () => {
31
+ if (this.closed) return;
32
+
33
+ this.observver.update();
34
+ };
35
+
36
+ observedCall.once('close', () => {
37
+ observedCall.off('update', onUpdate);
38
+ });
39
+ observedCall.on('update', onUpdate);
40
+ }
41
+ }
@@ -0,0 +1,39 @@
1
+ import { ObservedCall } from '../ObservedCall';
2
+ import { ObservedClient } from '../ObservedClient';
3
+ import { Updater } from './Updater';
4
+
5
+ export class OnAnyClientCallUpdater implements Updater {
6
+ readonly name = 'OnAnyClientCallUpdater';
7
+ readonly description = 'Call the update() method of the ObservedCall when any of the client has been updated';
8
+ public closed = false;
9
+
10
+ public constructor(
11
+ private _observedCall: ObservedCall
12
+ ) {
13
+ this._onNewObservedClient = this._onNewObservedClient.bind(this);
14
+
15
+ this._observedCall.once('close', () => {
16
+ this._observedCall.off('newclient', this._onNewObservedClient);
17
+ });
18
+ this._observedCall.on('newclient', this._onNewObservedClient);
19
+ }
20
+
21
+ public close(): void {
22
+ if (this.closed) return;
23
+ this.closed = true;
24
+ }
25
+
26
+ private _onNewObservedClient(observedClient: ObservedClient) {
27
+ if (this.closed) return;
28
+
29
+ const onUpdate = () => {
30
+ if (this.closed) return;
31
+ this._observedCall.update();
32
+ };
33
+
34
+ observedClient.once('close', () => {
35
+ observedClient.off('update', onUpdate);
36
+ });
37
+ observedClient.on('update', onUpdate);
38
+ }
39
+ }
@@ -0,0 +1,19 @@
1
+ import { Updater } from './Updater';
2
+
3
+ export class OnIntervalUpdater implements Updater {
4
+ readonly name = 'OnIntervalUpdater';
5
+ readonly description = 'Call the update() method given in the constructor once the interval elapsed';
6
+
7
+ public timer: ReturnType<typeof setInterval>;
8
+
9
+ public constructor(
10
+ intervalInMs: number,
11
+ private readonly _update: () => void,
12
+ ) {
13
+ this.timer = setInterval(() => this._update(), intervalInMs);
14
+ }
15
+
16
+ public close(): void {
17
+ clearInterval(this.timer);
18
+ }
19
+ }
@@ -0,0 +1,5 @@
1
+ export interface Updater {
2
+ readonly name: string;
3
+ readonly description?: string;
4
+ close(): void;
5
+ }
@@ -0,0 +1,155 @@
1
+ import { ObservedCall } from '../ObservedCall';
2
+ import { ObservedCallEventMonitor } from '../ObservedCallEventMonitor';
3
+ import { ObservedInboundTrack } from '../ObservedInboundTrack';
4
+ import { ObservedOutboundTrack } from '../ObservedOutboundTrack';
5
+ import { RemoteTrackResolver } from './RemoteTrackResolver';
6
+
7
+ export class MediasoupRemoteTrackResolver implements RemoteTrackResolver {
8
+ public readonly eventMonitor: ObservedCallEventMonitor<{
9
+ // empty
10
+ }>;
11
+
12
+ private _consumerIdToProducerId = new Map<string, string>();
13
+ private _producerIdToOutboundTrack = new Map<string, ObservedOutboundTrack>();
14
+ private _consumerIdToInboundTrack = new Map<string, ObservedInboundTrack>();
15
+ // private _producerIdToOutboundTrack = new Map<string, ObservedOutboundTrack>();
16
+
17
+ private _inboundTrackToConsumerId = new Map<string, string>();
18
+ private _producerIdToConsumerIds = new Map<string, string[]>();
19
+ private _outboundTrackToProducerId = new Map<string, string>();
20
+
21
+ public constructor(
22
+ public readonly observedCall: ObservedCall
23
+ ) {
24
+ this.eventMonitor = this.observedCall.createEventMonitor({});
25
+
26
+ this.eventMonitor.onInboundTrackAdded = this._addInboundTrack.bind(this);
27
+ this.eventMonitor.onInboundTrackRemoved = this._removeInboundTrack.bind(this);
28
+ this.eventMonitor.onOutboundTrackAdded = this._addOutboundTrack.bind(this);
29
+ this.eventMonitor.onOutboundTrackRemoved = this._removeOutboundTrack.bind(this);
30
+
31
+ // this.eventMonitor.onClientEvent = (client, event) => {
32
+
33
+ // };
34
+ }
35
+
36
+ public resolveRemoteOutboundTrack(inboundTrack: ObservedInboundTrack): ObservedOutboundTrack | undefined {
37
+ const consumerId = this._inboundTrackToConsumerId.get(inboundTrack.id);
38
+
39
+ if (!consumerId) return;
40
+
41
+ const producerId = this._consumerIdToProducerId.get(consumerId);
42
+
43
+ if (!producerId) return;
44
+
45
+ return this._producerIdToOutboundTrack.get(producerId);
46
+ }
47
+
48
+ public resolveRemoteInboundTracks(outboundTrack: ObservedOutboundTrack): ObservedInboundTrack[] | undefined {
49
+ const producerId = this._outboundTrackToProducerId.get(outboundTrack.id);
50
+
51
+ if (!producerId) return;
52
+
53
+ const consumerIds = this._producerIdToConsumerIds.get(producerId);
54
+
55
+ if (!consumerIds) return;
56
+
57
+ return consumerIds
58
+ .map((consumerId) => this._consumerIdToInboundTrack.get(consumerId))
59
+ .filter((inboundTrack) => Boolean(inboundTrack)) as ObservedInboundTrack[]
60
+ ;
61
+ }
62
+
63
+ private _addInboundTrack(inboundTrack: ObservedInboundTrack) {
64
+ const attachments = this._getInboundTrackAttachments(inboundTrack);
65
+
66
+ if (!attachments) return;
67
+
68
+ const {
69
+ producerId,
70
+ consumerId
71
+ } = attachments;
72
+
73
+ this._inboundTrackToConsumerId.set(inboundTrack.id, consumerId);
74
+ this._consumerIdToProducerId.set(consumerId, producerId);
75
+ this._consumerIdToInboundTrack.set(consumerId, inboundTrack);
76
+
77
+ let producerConsumers = this._producerIdToConsumerIds.get(producerId);
78
+
79
+ if (!producerConsumers) {
80
+ producerConsumers = [];
81
+ this._producerIdToConsumerIds.set(producerId, producerConsumers);
82
+ }
83
+ producerConsumers.push(consumerId);
84
+ }
85
+
86
+ private _removeInboundTrack(inboundTrack: ObservedInboundTrack) {
87
+ const consumerId = this._inboundTrackToConsumerId.get(inboundTrack.id);
88
+
89
+ if (!consumerId) return;
90
+
91
+ this._inboundTrackToConsumerId.delete(inboundTrack.id);
92
+ this._consumerIdToProducerId.delete(consumerId);
93
+ this._consumerIdToInboundTrack.delete(consumerId);
94
+
95
+ const producerConsumers = this._producerIdToConsumerIds.get(consumerId);
96
+
97
+ if (!producerConsumers) return;
98
+
99
+ const filteredProducerConsumers = producerConsumers.filter((id) => id !== consumerId);
100
+
101
+ if (filteredProducerConsumers.length === 0) {
102
+ this._producerIdToConsumerIds.delete(consumerId);
103
+ } else {
104
+ this._producerIdToConsumerIds.set(consumerId, filteredProducerConsumers);
105
+ }
106
+ }
107
+
108
+ private _addOutboundTrack(outboundTrack: ObservedOutboundTrack) {
109
+ const attachments = this._getOutboundTrackAttachments(outboundTrack);
110
+
111
+ if (!attachments) return;
112
+
113
+ const {
114
+ producerId,
115
+ } = attachments;
116
+
117
+ this._producerIdToOutboundTrack.set(producerId, outboundTrack);
118
+ this._outboundTrackToProducerId.set(outboundTrack.id, producerId);
119
+ }
120
+
121
+ private _removeOutboundTrack(outboundTrack: ObservedOutboundTrack) {
122
+ const producerId = this._outboundTrackToProducerId.get(outboundTrack.id);
123
+
124
+ if (!producerId) return;
125
+
126
+ this._producerIdToOutboundTrack.delete(producerId);
127
+ this._outboundTrackToProducerId.delete(outboundTrack.id);
128
+ }
129
+
130
+ private _getInboundTrackAttachments(inboundTrack: ObservedInboundTrack) {
131
+ const {
132
+ producerId,
133
+ consumerId
134
+ } = inboundTrack.attachments ?? {};
135
+
136
+ if (!producerId || !consumerId || typeof producerId !== 'string' || typeof consumerId !== 'string') return;
137
+
138
+ return {
139
+ producerId,
140
+ consumerId
141
+ };
142
+ }
143
+
144
+ private _getOutboundTrackAttachments(outboundTrack: ObservedOutboundTrack) {
145
+ const {
146
+ producerId,
147
+ } = outboundTrack.attachments ?? {};
148
+
149
+ if (!producerId || typeof producerId !== 'string') return;
150
+
151
+ return {
152
+ producerId,
153
+ };
154
+ }
155
+ }
@@ -0,0 +1,12 @@
1
+ import { ObservedInboundTrack } from '../ObservedInboundTrack';
2
+ import { ObservedOutboundTrack } from '../ObservedOutboundTrack';
3
+
4
+ export interface RemoteTrackResolver {
5
+ resolveRemoteOutboundTrack(
6
+ inboundTrack: ObservedInboundTrack,
7
+ ): ObservedOutboundTrack | undefined;
8
+
9
+ resolveRemoteInboundTracks(
10
+ outboundTrack: ObservedOutboundTrack,
11
+ ): ObservedInboundTrack[] | undefined;
12
+ }
package/tsconfig.json CHANGED
@@ -2,9 +2,9 @@
2
2
  "compileOnSave": true,
3
3
  "compilerOptions":
4
4
  {
5
- "lib": [ "es2020" ],
6
- "target": "es6",
7
- "module": "commonjs",
5
+ "lib": [ "ES2020", "dom" ],
6
+ "target": "ESNext",
7
+ "module": "CommonJS",
8
8
  "moduleResolution": "node",
9
9
  "esModuleInterop": true,
10
10
  "strict": true,
@@ -1,64 +0,0 @@
1
- /// <reference types="node" />
2
- import { IceCandidatePair, IceLocalCandidate, IceRemoteCandidate } from '@observertc/sample-schemas-js';
3
- import { EventEmitter } from 'events';
4
- import { ObservedPeerConnection } from './ObservedPeerConnection';
5
- export type ObservedICEEvents = {
6
- update: [
7
- {
8
- elapsedTimeInMs: number;
9
- }
10
- ];
11
- 'new-local-candidate': [IceLocalCandidate];
12
- 'new-remote-candidate': [IceRemoteCandidate];
13
- 'new-selected-candidate-pair': [
14
- {
15
- localCandidate: IceLocalCandidate;
16
- remoteCandidate: IceRemoteCandidate;
17
- }
18
- ];
19
- usingturnchanged: [boolean];
20
- close: [];
21
- };
22
- export declare interface ObservedICE {
23
- on<U extends keyof ObservedICEEvents>(event: U, listener: (...args: ObservedICEEvents[U]) => void): this;
24
- off<U extends keyof ObservedICEEvents>(event: U, listener: (...args: ObservedICEEvents[U]) => void): this;
25
- once<U extends keyof ObservedICEEvents>(event: U, listener: (...args: ObservedICEEvents[U]) => void): this;
26
- emit<U extends keyof ObservedICEEvents>(event: U, ...args: ObservedICEEvents[U]): boolean;
27
- }
28
- export declare class ObservedICE extends EventEmitter {
29
- readonly peerConnection: ObservedPeerConnection;
30
- static create(peerConnection: ObservedPeerConnection): ObservedICE;
31
- marker?: string;
32
- private readonly _localCandidates;
33
- private readonly _remoteCandidates;
34
- usingTURN: boolean;
35
- deltaBytesReceived: number;
36
- deltaBytesSent: number;
37
- deltaPacketsReceived: number;
38
- deltaPacketsSent: number;
39
- totalBytesReceived: number;
40
- totalBytesSent: number;
41
- totalPacketsReceived: number;
42
- totalPacketsSent: number;
43
- currentRttInMs?: number;
44
- private _selectedLocalCandidateId?;
45
- private _selectedRemoteCandidateId?;
46
- private _updated;
47
- private _stats?;
48
- private _closed;
49
- private constructor();
50
- get reports(): import("./ReportsCollector").ReportsCollector;
51
- get localCandidates(): ReadonlyMap<string, IceLocalCandidate>;
52
- get remoteCandidates(): ReadonlyMap<string, IceRemoteCandidate>;
53
- get selectedLocalCandidate(): IceLocalCandidate | undefined;
54
- get selectedRemoteCandidate(): IceLocalCandidate | undefined;
55
- get stats(): IceCandidatePair | undefined;
56
- get updated(): number;
57
- get closed(): boolean;
58
- close(): void;
59
- addLocalCandidate(candidate: IceLocalCandidate, sampleTimestamp?: number): void;
60
- addRemoteCandidate(candidate: IceRemoteCandidate, sampleTimestamp?: number): void;
61
- resetMetrics(): void;
62
- update(candidatePair: IceCandidatePair, timestamp: number): void;
63
- }
64
- //# sourceMappingURL=ObservedICE.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ObservedICE.d.ts","sourceRoot":"","sources":["../src/ObservedICE.ts"],"names":[],"mappings":"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"}
@@ -1,141 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ObservedICE = void 0;
4
- const events_1 = require("events");
5
- const CallMetaReports_1 = require("./common/CallMetaReports");
6
- class ObservedICE extends events_1.EventEmitter {
7
- static create(peerConnection) {
8
- return new ObservedICE(peerConnection);
9
- }
10
- constructor(peerConnection) {
11
- super();
12
- this.peerConnection = peerConnection;
13
- this._localCandidates = new Map();
14
- this._remoteCandidates = new Map();
15
- this.usingTURN = false;
16
- this.deltaBytesReceived = 0;
17
- this.deltaBytesSent = 0;
18
- this.deltaPacketsReceived = 0;
19
- this.deltaPacketsSent = 0;
20
- this.totalBytesReceived = 0;
21
- this.totalBytesSent = 0;
22
- this.totalPacketsReceived = 0;
23
- this.totalPacketsSent = 0;
24
- this._updated = Date.now();
25
- this._closed = false;
26
- this.setMaxListeners(Infinity);
27
- }
28
- get reports() {
29
- return this.peerConnection.reports;
30
- }
31
- get localCandidates() {
32
- return this._localCandidates;
33
- }
34
- get remoteCandidates() {
35
- return this._remoteCandidates;
36
- }
37
- get selectedLocalCandidate() {
38
- var _a;
39
- return this._localCandidates.get((_a = this._selectedLocalCandidateId) !== null && _a !== void 0 ? _a : '');
40
- }
41
- get selectedRemoteCandidate() {
42
- var _a;
43
- return this._remoteCandidates.get((_a = this._selectedRemoteCandidateId) !== null && _a !== void 0 ? _a : '');
44
- }
45
- get stats() {
46
- return this._stats;
47
- }
48
- get updated() {
49
- return this._updated;
50
- }
51
- get closed() {
52
- return this._closed;
53
- }
54
- close() {
55
- if (this._closed)
56
- return;
57
- this._closed = true;
58
- this.emit('close');
59
- }
60
- addLocalCandidate(candidate, sampleTimestamp) {
61
- if (!candidate.id)
62
- return;
63
- const newCandidate = !this._localCandidates.has(candidate.id);
64
- this._localCandidates.set(candidate.id, candidate);
65
- if (newCandidate) {
66
- const callMetaReport = (0, CallMetaReports_1.createCallMetaReport)(this.peerConnection.client.serviceId, this.peerConnection.client.mediaUnitId, this.peerConnection.client.roomId, this.peerConnection.client.callId, this.peerConnection.client.clientId, {
67
- type: CallMetaReports_1.CallMetaType.ICE_LOCAL_CANDIDATE,
68
- payload: candidate,
69
- }, this.peerConnection.client.userId, this.peerConnection.peerConnectionId, sampleTimestamp);
70
- this.reports.addCallMetaReport(callMetaReport);
71
- this.emit('new-local-candidate', candidate);
72
- }
73
- }
74
- addRemoteCandidate(candidate, sampleTimestamp) {
75
- if (!candidate.id)
76
- return;
77
- const newCandidate = !this._remoteCandidates.has(candidate.id);
78
- this._remoteCandidates.set(candidate.id, candidate);
79
- if (newCandidate) {
80
- const callMetaReport = (0, CallMetaReports_1.createCallMetaReport)(this.peerConnection.client.serviceId, this.peerConnection.client.mediaUnitId, this.peerConnection.client.roomId, this.peerConnection.client.callId, this.peerConnection.client.clientId, {
81
- type: CallMetaReports_1.CallMetaType.ICE_REMOTE_CANDIDATE,
82
- payload: candidate,
83
- }, this.peerConnection.client.userId, this.peerConnection.peerConnectionId, sampleTimestamp);
84
- this.reports.addCallMetaReport(callMetaReport);
85
- this.emit('new-remote-candidate', candidate);
86
- }
87
- }
88
- resetMetrics() {
89
- this.deltaBytesReceived = 0;
90
- this.deltaBytesSent = 0;
91
- this.deltaPacketsReceived = 0;
92
- this.deltaPacketsSent = 0;
93
- this.currentRttInMs = undefined;
94
- }
95
- update(candidatePair, timestamp) {
96
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
97
- const now = Date.now();
98
- const elapsedTimeInMs = now - this._updated;
99
- const report = Object.assign(Object.assign({ serviceId: this.peerConnection.client.serviceId, mediaUnitId: this.peerConnection.client.mediaUnitId, roomId: this.peerConnection.client.roomId, callId: this.peerConnection.client.callId, clientId: this.peerConnection.client.clientId, userId: this.peerConnection.client.userId, timestamp }, candidatePair), { sampleSeq: -1, marker: this.marker });
100
- this.reports.addIceCandidatePairReport(report);
101
- if (!candidatePair.nominated)
102
- return;
103
- this.deltaBytesReceived = ((_a = candidatePair.bytesReceived) !== null && _a !== void 0 ? _a : 0) - ((_c = (_b = this._stats) === null || _b === void 0 ? void 0 : _b.bytesReceived) !== null && _c !== void 0 ? _c : 0);
104
- this.deltaBytesSent = ((_d = candidatePair.bytesSent) !== null && _d !== void 0 ? _d : 0) - ((_f = (_e = this._stats) === null || _e === void 0 ? void 0 : _e.bytesSent) !== null && _f !== void 0 ? _f : 0);
105
- this.deltaPacketsReceived = ((_g = candidatePair.packetsReceived) !== null && _g !== void 0 ? _g : 0) - ((_j = (_h = this._stats) === null || _h === void 0 ? void 0 : _h.packetsReceived) !== null && _j !== void 0 ? _j : 0);
106
- this.deltaPacketsSent = ((_k = candidatePair.packetsSent) !== null && _k !== void 0 ? _k : 0) - ((_m = (_l = this._stats) === null || _l === void 0 ? void 0 : _l.packetsSent) !== null && _m !== void 0 ? _m : 0);
107
- this.totalBytesReceived += this.deltaBytesReceived;
108
- this.totalBytesSent += this.deltaBytesSent;
109
- this.totalPacketsReceived += this.deltaPacketsReceived;
110
- this.totalPacketsSent += this.deltaPacketsSent;
111
- this.currentRttInMs = candidatePair.currentRoundTripTime ? candidatePair.currentRoundTripTime * 1000 : undefined;
112
- this._stats = candidatePair;
113
- if (candidatePair.localCandidateId &&
114
- candidatePair.localCandidateId !== this._selectedLocalCandidateId &&
115
- this._localCandidates.has(candidatePair.localCandidateId) &&
116
- candidatePair.remoteCandidateId &&
117
- candidatePair.remoteCandidateId !== this._selectedRemoteCandidateId &&
118
- this._remoteCandidates.has(candidatePair.remoteCandidateId)) {
119
- this._selectedLocalCandidateId = candidatePair.localCandidateId;
120
- this._selectedRemoteCandidateId = candidatePair.remoteCandidateId;
121
- const localCandidate = this._localCandidates.get(candidatePair.localCandidateId);
122
- const remoteCandidate = this._remoteCandidates.get(candidatePair.remoteCandidateId);
123
- if (localCandidate && remoteCandidate) {
124
- const wasUsingTURN = this.usingTURN;
125
- this.usingTURN = ((_p = ((_o = localCandidate.candidateType) === null || _o === void 0 ? void 0 : _o.toLocaleLowerCase()) === 'relay') !== null && _p !== void 0 ? _p : false) && ((_r = (_q = localCandidate.url) === null || _q === void 0 ? void 0 : _q.startsWith('turn:')) !== null && _r !== void 0 ? _r : false);
126
- this.emit('new-selected-candidate-pair', {
127
- localCandidate,
128
- remoteCandidate,
129
- });
130
- if (wasUsingTURN !== this.usingTURN) {
131
- this.emit('usingturnchanged', this.usingTURN);
132
- }
133
- }
134
- }
135
- this._updated = now;
136
- this.emit('update', {
137
- elapsedTimeInMs,
138
- });
139
- }
140
- }
141
- exports.ObservedICE = ObservedICE;