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

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