@observertc/observer-js 1.0.0-beta.3 → 1.0.0-beta.4

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