@observertc/observer-js 1.0.0-b276103.0 → 1.0.0-beta.10

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 (231) hide show
  1. package/README.md +972 -383
  2. package/dist/index.d.mts +2952 -0
  3. package/dist/index.d.ts +2952 -0
  4. package/dist/index.js +4040 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/index.mjs +3970 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/llms-full.txt +1536 -0
  9. package/package.json +32 -16
  10. package/.eslintrc.json +0 -143
  11. package/.prettierignore +0 -5
  12. package/.prettierrc +0 -7
  13. package/jest.config.js +0 -9
  14. package/lib/ObservedCall.d.ts +0 -70
  15. package/lib/ObservedCall.d.ts.map +0 -1
  16. package/lib/ObservedCall.js +0 -196
  17. package/lib/ObservedCallEventMonitor.d.ts +0 -107
  18. package/lib/ObservedCallEventMonitor.d.ts.map +0 -1
  19. package/lib/ObservedCallEventMonitor.js +0 -321
  20. package/lib/ObservedCallSummary.d.ts +0 -18
  21. package/lib/ObservedCallSummary.d.ts.map +0 -1
  22. package/lib/ObservedCallSummary.js +0 -2
  23. package/lib/ObservedCertificate.d.ts +0 -19
  24. package/lib/ObservedCertificate.d.ts.map +0 -1
  25. package/lib/ObservedCertificate.js +0 -38
  26. package/lib/ObservedClient.d.ts +0 -115
  27. package/lib/ObservedClient.d.ts.map +0 -1
  28. package/lib/ObservedClient.js +0 -714
  29. package/lib/ObservedClientEventMonitor.d.ts +0 -91
  30. package/lib/ObservedClientEventMonitor.d.ts.map +0 -1
  31. package/lib/ObservedClientEventMonitor.js +0 -254
  32. package/lib/ObservedClientSummary.d.ts +0 -23
  33. package/lib/ObservedClientSummary.d.ts.map +0 -1
  34. package/lib/ObservedClientSummary.js +0 -2
  35. package/lib/ObservedCodec.d.ts +0 -22
  36. package/lib/ObservedCodec.d.ts.map +0 -1
  37. package/lib/ObservedCodec.js +0 -45
  38. package/lib/ObservedDataChannel.d.ts +0 -30
  39. package/lib/ObservedDataChannel.d.ts.map +0 -1
  40. package/lib/ObservedDataChannel.js +0 -75
  41. package/lib/ObservedIceCandidate.d.ts +0 -29
  42. package/lib/ObservedIceCandidate.d.ts.map +0 -1
  43. package/lib/ObservedIceCandidate.js +0 -59
  44. package/lib/ObservedIceCandidatePair.d.ts +0 -45
  45. package/lib/ObservedIceCandidatePair.d.ts.map +0 -1
  46. package/lib/ObservedIceCandidatePair.js +0 -127
  47. package/lib/ObservedIceTransport.d.ts +0 -36
  48. package/lib/ObservedIceTransport.d.ts.map +0 -1
  49. package/lib/ObservedIceTransport.js +0 -93
  50. package/lib/ObservedInboundRtp.d.ts +0 -92
  51. package/lib/ObservedInboundRtp.d.ts.map +0 -1
  52. package/lib/ObservedInboundRtp.js +0 -193
  53. package/lib/ObservedInboundTrack.d.ts +0 -34
  54. package/lib/ObservedInboundTrack.d.ts.map +0 -1
  55. package/lib/ObservedInboundTrack.js +0 -92
  56. package/lib/ObservedMediaPlayout.d.ts +0 -22
  57. package/lib/ObservedMediaPlayout.d.ts.map +0 -1
  58. package/lib/ObservedMediaPlayout.js +0 -42
  59. package/lib/ObservedMediaSource.d.ts +0 -28
  60. package/lib/ObservedMediaSource.d.ts.map +0 -1
  61. package/lib/ObservedMediaSource.js +0 -55
  62. package/lib/ObservedOutboundRtp.d.ts +0 -62
  63. package/lib/ObservedOutboundRtp.d.ts.map +0 -1
  64. package/lib/ObservedOutboundRtp.js +0 -144
  65. package/lib/ObservedOutboundTrack.d.ts +0 -34
  66. package/lib/ObservedOutboundTrack.d.ts.map +0 -1
  67. package/lib/ObservedOutboundTrack.js +0 -65
  68. package/lib/ObservedPeerConnection.d.ts +0 -207
  69. package/lib/ObservedPeerConnection.d.ts.map +0 -1
  70. package/lib/ObservedPeerConnection.js +0 -788
  71. package/lib/ObservedPeerConnectionTransport.d.ts +0 -17
  72. package/lib/ObservedPeerConnectionTransport.d.ts.map +0 -1
  73. package/lib/ObservedPeerConnectionTransport.js +0 -34
  74. package/lib/ObservedRemoteInboundRtp.d.ts +0 -30
  75. package/lib/ObservedRemoteInboundRtp.d.ts.map +0 -1
  76. package/lib/ObservedRemoteInboundRtp.js +0 -60
  77. package/lib/ObservedRemoteOutboundRtp.d.ts +0 -30
  78. package/lib/ObservedRemoteOutboundRtp.d.ts.map +0 -1
  79. package/lib/ObservedRemoteOutboundRtp.js +0 -60
  80. package/lib/ObservedTURN.d.ts +0 -31
  81. package/lib/ObservedTURN.d.ts.map +0 -1
  82. package/lib/ObservedTURN.js +0 -58
  83. package/lib/ObservedTurnServer.d.ts +0 -25
  84. package/lib/ObservedTurnServer.d.ts.map +0 -1
  85. package/lib/ObservedTurnServer.js +0 -59
  86. package/lib/Observer.d.ts +0 -62
  87. package/lib/Observer.d.ts.map +0 -1
  88. package/lib/Observer.js +0 -160
  89. package/lib/ObserverEventMonitor.d.ts +0 -141
  90. package/lib/ObserverEventMonitor.d.ts.map +0 -1
  91. package/lib/ObserverEventMonitor.js +0 -440
  92. package/lib/ObserverSummary.d.ts +0 -13
  93. package/lib/ObserverSummary.d.ts.map +0 -1
  94. package/lib/ObserverSummary.js +0 -2
  95. package/lib/Reports.d.ts +0 -85
  96. package/lib/Reports.d.ts.map +0 -1
  97. package/lib/Reports.js +0 -2
  98. package/lib/common/Middleware.d.ts +0 -17
  99. package/lib/common/Middleware.d.ts.map +0 -1
  100. package/lib/common/Middleware.js +0 -60
  101. package/lib/common/SingleExecutor.d.ts +0 -3
  102. package/lib/common/SingleExecutor.d.ts.map +0 -1
  103. package/lib/common/SingleExecutor.js +0 -31
  104. package/lib/common/logger.d.ts +0 -17
  105. package/lib/common/logger.d.ts.map +0 -1
  106. package/lib/common/logger.js +0 -50
  107. package/lib/common/types.d.ts +0 -3
  108. package/lib/common/types.d.ts.map +0 -1
  109. package/lib/common/types.js +0 -3
  110. package/lib/common/utils.d.ts +0 -11
  111. package/lib/common/utils.d.ts.map +0 -1
  112. package/lib/common/utils.js +0 -63
  113. package/lib/detectors/Detector.d.ts +0 -5
  114. package/lib/detectors/Detector.d.ts.map +0 -1
  115. package/lib/detectors/Detector.js +0 -3
  116. package/lib/detectors/Detectors.d.ts +0 -11
  117. package/lib/detectors/Detectors.d.ts.map +0 -1
  118. package/lib/detectors/Detectors.js +0 -34
  119. package/lib/index.d.ts +0 -29
  120. package/lib/index.d.ts.map +0 -1
  121. package/lib/index.js +0 -49
  122. package/lib/mediasoup/ObservedMediaRouter.d.ts +0 -10
  123. package/lib/mediasoup/ObservedMediaRouter.d.ts.map +0 -1
  124. package/lib/mediasoup/ObservedMediaRouter.js +0 -6
  125. package/lib/monitors/TurnUsageMonitor.d.ts +0 -1
  126. package/lib/monitors/TurnUsageMonitor.d.ts.map +0 -1
  127. package/lib/monitors/TurnUsageMonitor.js +0 -146
  128. package/lib/schema/ClientEventTypes.d.ts +0 -228
  129. package/lib/schema/ClientEventTypes.d.ts.map +0 -1
  130. package/lib/schema/ClientEventTypes.js +0 -41
  131. package/lib/schema/ClientMetaTypes.d.ts +0 -34
  132. package/lib/schema/ClientMetaTypes.d.ts.map +0 -1
  133. package/lib/schema/ClientMetaTypes.js +0 -16
  134. package/lib/schema/ClientSample.d.ts +0 -1333
  135. package/lib/schema/ClientSample.d.ts.map +0 -1
  136. package/lib/schema/ClientSample.js +0 -4
  137. package/lib/scores/CalculatedScore.d.ts +0 -6
  138. package/lib/scores/CalculatedScore.d.ts.map +0 -1
  139. package/lib/scores/CalculatedScore.js +0 -2
  140. package/lib/scores/DefaultCallScoreCalculator.d.ts +0 -7
  141. package/lib/scores/DefaultCallScoreCalculator.d.ts.map +0 -1
  142. package/lib/scores/DefaultCallScoreCalculator.js +0 -21
  143. package/lib/scores/ScoreCalculator.d.ts +0 -4
  144. package/lib/scores/ScoreCalculator.d.ts.map +0 -1
  145. package/lib/scores/ScoreCalculator.js +0 -2
  146. package/lib/updaters/CallUpdater.d.ts +0 -5
  147. package/lib/updaters/CallUpdater.d.ts.map +0 -1
  148. package/lib/updaters/CallUpdater.js +0 -2
  149. package/lib/updaters/ObserverUpdater.d.ts +0 -5
  150. package/lib/updaters/ObserverUpdater.d.ts.map +0 -1
  151. package/lib/updaters/ObserverUpdater.js +0 -2
  152. package/lib/updaters/OnAllCallObserverUpdater.d.ts +0 -15
  153. package/lib/updaters/OnAllCallObserverUpdater.d.ts.map +0 -1
  154. package/lib/updaters/OnAllCallObserverUpdater.js +0 -50
  155. package/lib/updaters/OnAllClientCallUpdater.d.ts +0 -15
  156. package/lib/updaters/OnAllClientCallUpdater.d.ts.map +0 -1
  157. package/lib/updaters/OnAllClientCallUpdater.js +0 -53
  158. package/lib/updaters/OnAnyCallObserverUpdater.d.ts +0 -12
  159. package/lib/updaters/OnAnyCallObserverUpdater.d.ts.map +0 -1
  160. package/lib/updaters/OnAnyCallObserverUpdater.js +0 -37
  161. package/lib/updaters/OnAnyClientCallUpdater.d.ts +0 -12
  162. package/lib/updaters/OnAnyClientCallUpdater.d.ts.map +0 -1
  163. package/lib/updaters/OnAnyClientCallUpdater.js +0 -36
  164. package/lib/updaters/OnIntervalUpdater.d.ts +0 -10
  165. package/lib/updaters/OnIntervalUpdater.d.ts.map +0 -1
  166. package/lib/updaters/OnIntervalUpdater.js +0 -17
  167. package/lib/updaters/Updater.d.ts +0 -6
  168. package/lib/updaters/Updater.d.ts.map +0 -1
  169. package/lib/updaters/Updater.js +0 -2
  170. package/lib/utils/MediasoupRemoteTrackResolver.d.ts +0 -25
  171. package/lib/utils/MediasoupRemoteTrackResolver.d.ts.map +0 -1
  172. package/lib/utils/MediasoupRemoteTrackResolver.js +0 -110
  173. package/lib/utils/RemoteTrackResolver.d.ts +0 -7
  174. package/lib/utils/RemoteTrackResolver.d.ts.map +0 -1
  175. package/lib/utils/RemoteTrackResolver.js +0 -2
  176. package/src/ObservedCall.ts +0 -308
  177. package/src/ObservedCallEventMonitor.ts +0 -402
  178. package/src/ObservedCallSummary.ts +0 -22
  179. package/src/ObservedCertificate.ts +0 -43
  180. package/src/ObservedClient.ts +0 -883
  181. package/src/ObservedClientEventMonitor.ts +0 -309
  182. package/src/ObservedClientSummary.ts +0 -24
  183. package/src/ObservedCodec.ts +0 -49
  184. package/src/ObservedDataChannel.ts +0 -85
  185. package/src/ObservedIceCandidate.ts +0 -64
  186. package/src/ObservedIceCandidatePair.ts +0 -134
  187. package/src/ObservedIceTransport.ts +0 -99
  188. package/src/ObservedInboundRtp.ts +0 -205
  189. package/src/ObservedInboundTrack.ts +0 -105
  190. package/src/ObservedMediaPlayout.ts +0 -49
  191. package/src/ObservedMediaSource.ts +0 -60
  192. package/src/ObservedOutboundRtp.ts +0 -156
  193. package/src/ObservedOutboundTrack.ts +0 -82
  194. package/src/ObservedPeerConnection.ts +0 -1104
  195. package/src/ObservedPeerConnectionTransport.ts +0 -38
  196. package/src/ObservedRemoteInboundRtp.ts +0 -64
  197. package/src/ObservedRemoteOutboundRtp.ts +0 -65
  198. package/src/ObservedTURN.ts +0 -86
  199. package/src/ObservedTurnServer.ts +0 -72
  200. package/src/Observer.ts +0 -248
  201. package/src/ObserverEventMonitor.ts +0 -561
  202. package/src/ObserverSummary.ts +0 -15
  203. package/src/Reports.ts +0 -87
  204. package/src/common/Middleware.ts +0 -84
  205. package/src/common/SingleExecutor.ts +0 -36
  206. package/src/common/logger.ts +0 -82
  207. package/src/common/types.ts +0 -4
  208. package/src/common/utils.ts +0 -69
  209. package/src/detectors/Detector.ts +0 -6
  210. package/src/detectors/Detectors.ts +0 -38
  211. package/src/index.ts +0 -32
  212. package/src/mediasoup/ObservedMediaRouter.ts +0 -10
  213. package/src/monitors/TurnUsageMonitor.ts +0 -187
  214. package/src/schema/ClientEventTypes.ts +0 -280
  215. package/src/schema/ClientMetaTypes.ts +0 -41
  216. package/src/schema/ClientSample.ts +0 -1682
  217. package/src/scores/CalculatedScore.ts +0 -6
  218. package/src/scores/DefaultCallScoreCalculator.ts +0 -23
  219. package/src/scores/ScoreCalculator.ts +0 -3
  220. package/src/updaters/CallUpdater.ts +0 -5
  221. package/src/updaters/ObserverUpdater.ts +0 -5
  222. package/src/updaters/OnAllCallObserverUpdater.ts +0 -59
  223. package/src/updaters/OnAllClientCallUpdater.ts +0 -61
  224. package/src/updaters/OnAnyCallObserverUpdater.ts +0 -41
  225. package/src/updaters/OnAnyClientCallUpdater.ts +0 -39
  226. package/src/updaters/OnIntervalUpdater.ts +0 -19
  227. package/src/updaters/Updater.ts +0 -5
  228. package/src/utils/MediasoupRemoteTrackResolver.ts +0 -155
  229. package/src/utils/RemoteTrackResolver.ts +0 -12
  230. package/tsconfig.json +0 -19
  231. package/tslint.json +0 -6
@@ -1,6 +0,0 @@
1
-
2
- export type CalculatedScore = {
3
- weight: number;
4
- value?: number;
5
- appData?: Record<string, unknown>;
6
- };
@@ -1,23 +0,0 @@
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
- }
@@ -1,3 +0,0 @@
1
- export interface ScoreCalculator {
2
- update(): void;
3
- }
@@ -1,5 +0,0 @@
1
- import { ObservedClient } from '../ObservedClient';
2
-
3
- export interface CallUpdater {
4
- onClientUpdate(observedClient: ObservedClient): void;
5
- }
@@ -1,5 +0,0 @@
1
- import { ObservedCall } from '../ObservedCall';
2
-
3
- export interface ObserverUpdater {
4
- onCallUpdate(observedCall: ObservedCall): void;
5
- }
@@ -1,59 +0,0 @@
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
- }
@@ -1,61 +0,0 @@
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
- }
@@ -1,41 +0,0 @@
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
- public 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
- }
@@ -1,39 +0,0 @@
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
- }
@@ -1,19 +0,0 @@
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
- }
@@ -1,5 +0,0 @@
1
- export interface Updater {
2
- readonly name: string;
3
- readonly description?: string;
4
- close(): void;
5
- }
@@ -1,155 +0,0 @@
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
- }
@@ -1,12 +0,0 @@
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 DELETED
@@ -1,19 +0,0 @@
1
- {
2
- "compileOnSave": true,
3
- "compilerOptions":
4
- {
5
- "lib": [ "ES2020", "dom" ],
6
- "target": "ESNext",
7
- "module": "CommonJS",
8
- "moduleResolution": "node",
9
- "esModuleInterop": true,
10
- "strict": true,
11
- "outDir": "lib",
12
- "declaration": true,
13
- "declarationMap": true,
14
- "experimentalDecorators": true,
15
- "emitDecoratorMetadata": true
16
- },
17
- "include": [ "src" ]
18
- }
19
-
package/tslint.json DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "rules": {
3
- "prefer-for-of": false
4
- },
5
- "extends": ["tslint:recommended", "tslint-config-prettier"]
6
- }