@observertc/observer-js 1.0.0-beta.2 → 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 (223) 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 -86
  11. package/lib/ObservedCall.d.ts.map +0 -1
  12. package/lib/ObservedCall.js +0 -225
  13. package/lib/ObservedCallEventMonitor.d.ts +0 -104
  14. package/lib/ObservedCallEventMonitor.d.ts.map +0 -1
  15. package/lib/ObservedCallEventMonitor.js +0 -314
  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 -130
  23. package/lib/ObservedClient.d.ts.map +0 -1
  24. package/lib/ObservedClient.js +0 -650
  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 -32
  50. package/lib/ObservedInboundTrack.d.ts.map +0 -1
  51. package/lib/ObservedInboundTrack.js +0 -60
  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 -32
  62. package/lib/ObservedOutboundTrack.d.ts.map +0 -1
  63. package/lib/ObservedOutboundTrack.js +0 -60
  64. package/lib/ObservedPeerConnection.d.ts +0 -207
  65. package/lib/ObservedPeerConnection.d.ts.map +0 -1
  66. package/lib/ObservedPeerConnection.js +0 -773
  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 -65
  83. package/lib/Observer.d.ts.map +0 -1
  84. package/lib/Observer.js +0 -166
  85. package/lib/ObserverEventMonitor.d.ts +0 -138
  86. package/lib/ObserverEventMonitor.d.ts.map +0 -1
  87. package/lib/ObserverEventMonitor.js +0 -433
  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/common/Middleware.d.ts +0 -17
  92. package/lib/common/Middleware.d.ts.map +0 -1
  93. package/lib/common/Middleware.js +0 -60
  94. package/lib/common/SingleExecutor.d.ts +0 -3
  95. package/lib/common/SingleExecutor.d.ts.map +0 -1
  96. package/lib/common/SingleExecutor.js +0 -31
  97. package/lib/common/logger.d.ts +0 -17
  98. package/lib/common/logger.d.ts.map +0 -1
  99. package/lib/common/logger.js +0 -50
  100. package/lib/common/types.d.ts +0 -3
  101. package/lib/common/types.d.ts.map +0 -1
  102. package/lib/common/types.js +0 -3
  103. package/lib/common/utils.d.ts +0 -11
  104. package/lib/common/utils.d.ts.map +0 -1
  105. package/lib/common/utils.js +0 -63
  106. package/lib/detectors/Detector.d.ts +0 -5
  107. package/lib/detectors/Detector.d.ts.map +0 -1
  108. package/lib/detectors/Detector.js +0 -3
  109. package/lib/detectors/Detectors.d.ts +0 -11
  110. package/lib/detectors/Detectors.d.ts.map +0 -1
  111. package/lib/detectors/Detectors.js +0 -34
  112. package/lib/index.d.ts +0 -28
  113. package/lib/index.d.ts.map +0 -1
  114. package/lib/index.js +0 -49
  115. package/lib/mediasoup/ObservedMediaRouter.d.ts +0 -10
  116. package/lib/mediasoup/ObservedMediaRouter.d.ts.map +0 -1
  117. package/lib/mediasoup/ObservedMediaRouter.js +0 -6
  118. package/lib/monitors/TurnUsageMonitor.d.ts +0 -1
  119. package/lib/monitors/TurnUsageMonitor.d.ts.map +0 -1
  120. package/lib/monitors/TurnUsageMonitor.js +0 -146
  121. package/lib/schema/ClientEventTypes.d.ts +0 -228
  122. package/lib/schema/ClientEventTypes.d.ts.map +0 -1
  123. package/lib/schema/ClientEventTypes.js +0 -41
  124. package/lib/schema/ClientMetaTypes.d.ts +0 -34
  125. package/lib/schema/ClientMetaTypes.d.ts.map +0 -1
  126. package/lib/schema/ClientMetaTypes.js +0 -16
  127. package/lib/schema/ClientSample.d.ts +0 -1333
  128. package/lib/schema/ClientSample.d.ts.map +0 -1
  129. package/lib/schema/ClientSample.js +0 -4
  130. package/lib/scores/CalculatedScore.d.ts +0 -6
  131. package/lib/scores/CalculatedScore.d.ts.map +0 -1
  132. package/lib/scores/CalculatedScore.js +0 -2
  133. package/lib/scores/DefaultCallScoreCalculator.d.ts +0 -7
  134. package/lib/scores/DefaultCallScoreCalculator.d.ts.map +0 -1
  135. package/lib/scores/DefaultCallScoreCalculator.js +0 -21
  136. package/lib/scores/ScoreCalculator.d.ts +0 -4
  137. package/lib/scores/ScoreCalculator.d.ts.map +0 -1
  138. package/lib/scores/ScoreCalculator.js +0 -2
  139. package/lib/updaters/CallUpdater.d.ts +0 -5
  140. package/lib/updaters/CallUpdater.d.ts.map +0 -1
  141. package/lib/updaters/CallUpdater.js +0 -2
  142. package/lib/updaters/ObserverUpdater.d.ts +0 -5
  143. package/lib/updaters/ObserverUpdater.d.ts.map +0 -1
  144. package/lib/updaters/ObserverUpdater.js +0 -2
  145. package/lib/updaters/OnAllCallObserverUpdater.d.ts +0 -15
  146. package/lib/updaters/OnAllCallObserverUpdater.d.ts.map +0 -1
  147. package/lib/updaters/OnAllCallObserverUpdater.js +0 -50
  148. package/lib/updaters/OnAllClientCallUpdater.d.ts +0 -15
  149. package/lib/updaters/OnAllClientCallUpdater.d.ts.map +0 -1
  150. package/lib/updaters/OnAllClientCallUpdater.js +0 -53
  151. package/lib/updaters/OnAnyCallObserverUpdater.d.ts +0 -12
  152. package/lib/updaters/OnAnyCallObserverUpdater.d.ts.map +0 -1
  153. package/lib/updaters/OnAnyCallObserverUpdater.js +0 -37
  154. package/lib/updaters/OnAnyClientCallUpdater.d.ts +0 -12
  155. package/lib/updaters/OnAnyClientCallUpdater.d.ts.map +0 -1
  156. package/lib/updaters/OnAnyClientCallUpdater.js +0 -36
  157. package/lib/updaters/OnIntervalUpdater.d.ts +0 -10
  158. package/lib/updaters/OnIntervalUpdater.d.ts.map +0 -1
  159. package/lib/updaters/OnIntervalUpdater.js +0 -17
  160. package/lib/updaters/Updater.d.ts +0 -6
  161. package/lib/updaters/Updater.d.ts.map +0 -1
  162. package/lib/updaters/Updater.js +0 -2
  163. package/lib/utils/MediasoupRemoteTrackResolver.d.ts +0 -25
  164. package/lib/utils/MediasoupRemoteTrackResolver.d.ts.map +0 -1
  165. package/lib/utils/MediasoupRemoteTrackResolver.js +0 -110
  166. package/lib/utils/RemoteTrackResolver.d.ts +0 -7
  167. package/lib/utils/RemoteTrackResolver.d.ts.map +0 -1
  168. package/lib/utils/RemoteTrackResolver.js +0 -2
  169. package/src/ObservedCall.ts +0 -342
  170. package/src/ObservedCallEventMonitor.ts +0 -392
  171. package/src/ObservedCallSummary.ts +0 -22
  172. package/src/ObservedCertificate.ts +0 -43
  173. package/src/ObservedClient.ts +0 -807
  174. package/src/ObservedClientEventMonitor.ts +0 -309
  175. package/src/ObservedClientSummary.ts +0 -24
  176. package/src/ObservedCodec.ts +0 -49
  177. package/src/ObservedDataChannel.ts +0 -85
  178. package/src/ObservedIceCandidate.ts +0 -64
  179. package/src/ObservedIceCandidatePair.ts +0 -134
  180. package/src/ObservedIceTransport.ts +0 -99
  181. package/src/ObservedInboundRtp.ts +0 -205
  182. package/src/ObservedInboundTrack.ts +0 -75
  183. package/src/ObservedMediaPlayout.ts +0 -49
  184. package/src/ObservedMediaSource.ts +0 -60
  185. package/src/ObservedOutboundRtp.ts +0 -156
  186. package/src/ObservedOutboundTrack.ts +0 -74
  187. package/src/ObservedPeerConnection.ts +0 -1088
  188. package/src/ObservedPeerConnectionTransport.ts +0 -38
  189. package/src/ObservedRemoteInboundRtp.ts +0 -64
  190. package/src/ObservedRemoteOutboundRtp.ts +0 -65
  191. package/src/ObservedTURN.ts +0 -86
  192. package/src/ObservedTurnServer.ts +0 -72
  193. package/src/Observer.ts +0 -251
  194. package/src/ObserverEventMonitor.ts +0 -551
  195. package/src/ObserverSummary.ts +0 -15
  196. package/src/common/Middleware.ts +0 -84
  197. package/src/common/SingleExecutor.ts +0 -36
  198. package/src/common/logger.ts +0 -82
  199. package/src/common/types.ts +0 -4
  200. package/src/common/utils.ts +0 -69
  201. package/src/detectors/Detector.ts +0 -6
  202. package/src/detectors/Detectors.ts +0 -38
  203. package/src/index.ts +0 -28
  204. package/src/mediasoup/ObservedMediaRouter.ts +0 -10
  205. package/src/monitors/TurnUsageMonitor.ts +0 -187
  206. package/src/schema/ClientEventTypes.ts +0 -280
  207. package/src/schema/ClientMetaTypes.ts +0 -41
  208. package/src/schema/ClientSample.ts +0 -1682
  209. package/src/scores/CalculatedScore.ts +0 -6
  210. package/src/scores/DefaultCallScoreCalculator.ts +0 -23
  211. package/src/scores/ScoreCalculator.ts +0 -3
  212. package/src/updaters/CallUpdater.ts +0 -5
  213. package/src/updaters/ObserverUpdater.ts +0 -5
  214. package/src/updaters/OnAllCallObserverUpdater.ts +0 -59
  215. package/src/updaters/OnAllClientCallUpdater.ts +0 -61
  216. package/src/updaters/OnAnyCallObserverUpdater.ts +0 -41
  217. package/src/updaters/OnAnyClientCallUpdater.ts +0 -39
  218. package/src/updaters/OnIntervalUpdater.ts +0 -19
  219. package/src/updaters/Updater.ts +0 -5
  220. package/src/utils/MediasoupRemoteTrackResolver.ts +0 -155
  221. package/src/utils/RemoteTrackResolver.ts +0 -12
  222. package/tsconfig.json +0 -19
  223. 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
- }