@observertc/observer-js 1.0.1-b52220e.0 → 1.0.1-c2558cc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/lib/ObservedCall.d.ts +2 -0
  2. package/lib/ObservedCall.d.ts.map +1 -1
  3. package/lib/ObservedCall.js +4 -0
  4. package/lib/ObservedCallEventMonitor.d.ts +104 -0
  5. package/lib/ObservedCallEventMonitor.d.ts.map +1 -0
  6. package/lib/ObservedCallEventMonitor.js +314 -0
  7. package/lib/ObservedClient.d.ts +2 -2
  8. package/lib/ObservedClient.d.ts.map +1 -1
  9. package/lib/ObservedClient.js +52 -4
  10. package/lib/ObservedIceCandidatePair.d.ts +2 -1
  11. package/lib/ObservedIceCandidatePair.d.ts.map +1 -1
  12. package/lib/ObservedIceCandidatePair.js +17 -1
  13. package/lib/ObservedInboundTrack.d.ts +1 -0
  14. package/lib/ObservedInboundTrack.d.ts.map +1 -1
  15. package/lib/ObservedInboundTrack.js +1 -0
  16. package/lib/ObservedOutboundTrack.d.ts +1 -0
  17. package/lib/ObservedOutboundTrack.d.ts.map +1 -1
  18. package/lib/ObservedOutboundTrack.js +1 -0
  19. package/lib/ObservedPeerConnection.d.ts +19 -0
  20. package/lib/ObservedPeerConnection.d.ts.map +1 -1
  21. package/lib/ObservedPeerConnection.js +75 -15
  22. package/lib/Observer.d.ts +8 -4
  23. package/lib/Observer.d.ts.map +1 -1
  24. package/lib/Observer.js +14 -2
  25. package/lib/ObserverEventMonitor.d.ts +138 -0
  26. package/lib/ObserverEventMonitor.d.ts.map +1 -0
  27. package/lib/ObserverEventMonitor.js +433 -0
  28. package/lib/index.d.ts +2 -1
  29. package/lib/index.d.ts.map +1 -1
  30. package/lib/index.js +3 -1
  31. package/lib/schema/ClientSample.d.ts +1 -1
  32. package/lib/schema/ClientSample.d.ts.map +1 -1
  33. package/lib/updaters/{OnAllCallObserverUpdater_.d.ts → OnAllCallObserverUpdater.d.ts} +3 -1
  34. package/lib/updaters/OnAllCallObserverUpdater.d.ts.map +1 -0
  35. package/lib/updaters/{OnAllCallObserverUpdater_.js → OnAllCallObserverUpdater.js} +13 -1
  36. package/lib/updaters/OnAllClientCallUpdater.d.ts +2 -0
  37. package/lib/updaters/OnAllClientCallUpdater.d.ts.map +1 -1
  38. package/lib/updaters/OnAllClientCallUpdater.js +16 -0
  39. package/lib/updaters/{OnAnyCallObserverUpdater_.d.ts → OnAnyCallObserverUpdater.d.ts} +2 -1
  40. package/lib/updaters/OnAnyCallObserverUpdater.d.ts.map +1 -0
  41. package/lib/updaters/{OnAnyCallObserverUpdater_.js → OnAnyCallObserverUpdater.js} +11 -1
  42. package/lib/updaters/OnAnyClientCallUpdater.d.ts +1 -0
  43. package/lib/updaters/OnAnyClientCallUpdater.d.ts.map +1 -1
  44. package/lib/updaters/OnAnyClientCallUpdater.js +11 -2
  45. package/lib/utils/MediasoupRemoteTrackResolver.d.ts +25 -0
  46. package/lib/utils/MediasoupRemoteTrackResolver.d.ts.map +1 -0
  47. package/lib/utils/MediasoupRemoteTrackResolver.js +110 -0
  48. package/package.json +1 -1
  49. package/src/ObservedCall.ts +5 -0
  50. package/src/ObservedCallEventMonitor.ts +392 -0
  51. package/src/ObservedClient.ts +53 -7
  52. package/src/ObservedIceCandidatePair.ts +18 -2
  53. package/src/ObservedInboundTrack.ts +2 -0
  54. package/src/ObservedOutboundTrack.ts +2 -0
  55. package/src/ObservedPeerConnection.ts +95 -30
  56. package/src/Observer.ts +21 -6
  57. package/src/ObserverEventMonitor.ts +551 -0
  58. package/src/index.ts +2 -2
  59. package/src/schema/ClientSample.ts +1 -1
  60. package/src/updaters/{OnAllCallObserverUpdater_.ts → OnAllCallObserverUpdater.ts} +14 -1
  61. package/src/updaters/OnAllClientCallUpdater.ts +15 -0
  62. package/src/updaters/{OnAnyCallObserverUpdater_.ts → OnAnyCallObserverUpdater.ts} +12 -3
  63. package/src/updaters/OnAnyClientCallUpdater.ts +9 -2
  64. package/src/utils/MediasoupRemoteTrackResolver.ts +155 -0
  65. package/lib/updaters/OnAllCallObserverUpdater_.d.ts.map +0 -1
  66. package/lib/updaters/OnAnyCallObserverUpdater_.d.ts.map +0 -1
@@ -5,7 +5,8 @@ import { Updater } from './Updater';
5
5
  export class OnAnyCallObserverUpdater implements Updater {
6
6
  public readonly name = 'OnAnyCallObserverUpdater';
7
7
  public readonly description = 'Call Observer\'s update() method on any of the ObservedCall is updated';
8
-
8
+ public closed = false;
9
+
9
10
  public constructor(
10
11
  private observver: Observer
11
12
  ) {
@@ -17,12 +18,20 @@ export class OnAnyCallObserverUpdater implements Updater {
17
18
  this.observver.on('newcall', this._onNewObservedCall);
18
19
  }
19
20
 
20
- close(): void {
21
+ public close(): void {
22
+ if (this.closed) return;
23
+ this.closed = true;
21
24
  // do nothing, because we unsubscribe once close is emitted from observer
22
25
  }
23
26
 
24
27
  private _onNewObservedCall(observedCall: ObservedCall) {
25
- const onUpdate = () => this.observver.update();
28
+ if (this.closed) return;
29
+
30
+ const onUpdate = () => {
31
+ if (this.closed) return;
32
+
33
+ this.observver.update();
34
+ };
26
35
 
27
36
  observedCall.once('close', () => {
28
37
  observedCall.off('update', onUpdate);
@@ -5,6 +5,7 @@ import { Updater } from './Updater';
5
5
  export class OnAnyClientCallUpdater implements Updater {
6
6
  readonly name = 'OnAnyClientCallUpdater';
7
7
  readonly description = 'Call the update() method of the ObservedCall when any of the client has been updated';
8
+ public closed = false;
8
9
 
9
10
  public constructor(
10
11
  private _observedCall: ObservedCall
@@ -18,11 +19,17 @@ export class OnAnyClientCallUpdater implements Updater {
18
19
  }
19
20
 
20
21
  public close(): void {
21
- // do nothing, as close once emitted unsubscription happened
22
+ if (this.closed) return;
23
+ this.closed = true;
22
24
  }
23
25
 
24
26
  private _onNewObservedClient(observedClient: ObservedClient) {
25
- const onUpdate = () => this._observedCall.update();
27
+ if (this.closed) return;
28
+
29
+ const onUpdate = () => {
30
+ if (this.closed) return;
31
+ this._observedCall.update();
32
+ };
26
33
 
27
34
  observedClient.once('close', () => {
28
35
  observedClient.off('update', onUpdate);
@@ -0,0 +1,155 @@
1
+ import { ObservedCall } from '../ObservedCall';
2
+ import { ObservedCallEventMonitor } from '../ObservedCallEventMonitor';
3
+ import { ObservedInboundTrack } from '../ObservedInboundTrack';
4
+ import { ObservedOutboundTrack } from '../ObservedOutboundTrack';
5
+ import { RemoteTrackResolver } from './RemoteTrackResolver';
6
+
7
+ export class MediasoupRemoteTrackResolver implements RemoteTrackResolver {
8
+ public readonly eventMonitor: ObservedCallEventMonitor<{
9
+ // empty
10
+ }>;
11
+
12
+ private _consumerIdToProducerId = new Map<string, string>();
13
+ private _producerIdToOutboundTrack = new Map<string, ObservedOutboundTrack>();
14
+ private _consumerIdToInboundTrack = new Map<string, ObservedInboundTrack>();
15
+ // private _producerIdToOutboundTrack = new Map<string, ObservedOutboundTrack>();
16
+
17
+ private _inboundTrackToConsumerId = new Map<string, string>();
18
+ private _producerIdToConsumerIds = new Map<string, string[]>();
19
+ private _outboundTrackToProducerId = new Map<string, string>();
20
+
21
+ public constructor(
22
+ public readonly observedCall: ObservedCall
23
+ ) {
24
+ this.eventMonitor = this.observedCall.createEventMonitor({});
25
+
26
+ this.eventMonitor.onInboundTrackAdded = this._addInboundTrack.bind(this);
27
+ this.eventMonitor.onInboundTrackRemoved = this._removeInboundTrack.bind(this);
28
+ this.eventMonitor.onOutboundTrackAdded = this._addOutboundTrack.bind(this);
29
+ this.eventMonitor.onOutboundTrackRemoved = this._removeOutboundTrack.bind(this);
30
+
31
+ // this.eventMonitor.onClientEvent = (client, event) => {
32
+
33
+ // };
34
+ }
35
+
36
+ public resolveRemoteOutboundTrack(inboundTrack: ObservedInboundTrack): ObservedOutboundTrack | undefined {
37
+ const consumerId = this._inboundTrackToConsumerId.get(inboundTrack.id);
38
+
39
+ if (!consumerId) return;
40
+
41
+ const producerId = this._consumerIdToProducerId.get(consumerId);
42
+
43
+ if (!producerId) return;
44
+
45
+ return this._producerIdToOutboundTrack.get(producerId);
46
+ }
47
+
48
+ public resolveRemoteInboundTracks(outboundTrack: ObservedOutboundTrack): ObservedInboundTrack[] | undefined {
49
+ const producerId = this._outboundTrackToProducerId.get(outboundTrack.id);
50
+
51
+ if (!producerId) return;
52
+
53
+ const consumerIds = this._producerIdToConsumerIds.get(producerId);
54
+
55
+ if (!consumerIds) return;
56
+
57
+ return consumerIds
58
+ .map((consumerId) => this._consumerIdToInboundTrack.get(consumerId))
59
+ .filter((inboundTrack) => Boolean(inboundTrack)) as ObservedInboundTrack[]
60
+ ;
61
+ }
62
+
63
+ private _addInboundTrack(inboundTrack: ObservedInboundTrack) {
64
+ const attachments = this._getInboundTrackAttachments(inboundTrack);
65
+
66
+ if (!attachments) return;
67
+
68
+ const {
69
+ producerId,
70
+ consumerId
71
+ } = attachments;
72
+
73
+ this._inboundTrackToConsumerId.set(inboundTrack.id, consumerId);
74
+ this._consumerIdToProducerId.set(consumerId, producerId);
75
+ this._consumerIdToInboundTrack.set(consumerId, inboundTrack);
76
+
77
+ let producerConsumers = this._producerIdToConsumerIds.get(producerId);
78
+
79
+ if (!producerConsumers) {
80
+ producerConsumers = [];
81
+ this._producerIdToConsumerIds.set(producerId, producerConsumers);
82
+ }
83
+ producerConsumers.push(consumerId);
84
+ }
85
+
86
+ private _removeInboundTrack(inboundTrack: ObservedInboundTrack) {
87
+ const consumerId = this._inboundTrackToConsumerId.get(inboundTrack.id);
88
+
89
+ if (!consumerId) return;
90
+
91
+ this._inboundTrackToConsumerId.delete(inboundTrack.id);
92
+ this._consumerIdToProducerId.delete(consumerId);
93
+ this._consumerIdToInboundTrack.delete(consumerId);
94
+
95
+ const producerConsumers = this._producerIdToConsumerIds.get(consumerId);
96
+
97
+ if (!producerConsumers) return;
98
+
99
+ const filteredProducerConsumers = producerConsumers.filter((id) => id !== consumerId);
100
+
101
+ if (filteredProducerConsumers.length === 0) {
102
+ this._producerIdToConsumerIds.delete(consumerId);
103
+ } else {
104
+ this._producerIdToConsumerIds.set(consumerId, filteredProducerConsumers);
105
+ }
106
+ }
107
+
108
+ private _addOutboundTrack(outboundTrack: ObservedOutboundTrack) {
109
+ const attachments = this._getOutboundTrackAttachments(outboundTrack);
110
+
111
+ if (!attachments) return;
112
+
113
+ const {
114
+ producerId,
115
+ } = attachments;
116
+
117
+ this._producerIdToOutboundTrack.set(producerId, outboundTrack);
118
+ this._outboundTrackToProducerId.set(outboundTrack.id, producerId);
119
+ }
120
+
121
+ private _removeOutboundTrack(outboundTrack: ObservedOutboundTrack) {
122
+ const producerId = this._outboundTrackToProducerId.get(outboundTrack.id);
123
+
124
+ if (!producerId) return;
125
+
126
+ this._producerIdToOutboundTrack.delete(producerId);
127
+ this._outboundTrackToProducerId.delete(outboundTrack.id);
128
+ }
129
+
130
+ private _getInboundTrackAttachments(inboundTrack: ObservedInboundTrack) {
131
+ const {
132
+ producerId,
133
+ consumerId
134
+ } = inboundTrack.attachments ?? {};
135
+
136
+ if (!producerId || !consumerId || typeof producerId !== 'string' || typeof consumerId !== 'string') return;
137
+
138
+ return {
139
+ producerId,
140
+ consumerId
141
+ };
142
+ }
143
+
144
+ private _getOutboundTrackAttachments(outboundTrack: ObservedOutboundTrack) {
145
+ const {
146
+ producerId,
147
+ } = outboundTrack.attachments ?? {};
148
+
149
+ if (!producerId || typeof producerId !== 'string') return;
150
+
151
+ return {
152
+ producerId,
153
+ };
154
+ }
155
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"OnAllCallObserverUpdater_.d.ts","sourceRoot":"","sources":["../../src/updaters/OnAllCallObserverUpdater_.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,qBAAa,wBAAyB,YAAW,OAAO;IAOtD,OAAO,CAAC,QAAQ;IANjB,SAAgB,IAAI,8BAA8B;IAClD,SAAgB,WAAW,+EAAgF;IAE3G,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAqB;gBAG1C,QAAQ,EAAE,QAAQ;IAU3B,KAAK,IAAI,IAAI;IAIb,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,sBAAsB;CAU9B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"OnAnyCallObserverUpdater_.d.ts","sourceRoot":"","sources":["../../src/updaters/OnAnyCallObserverUpdater_.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,qBAAa,wBAAyB,YAAW,OAAO;IAKtD,OAAO,CAAC,SAAS;IAJlB,SAAgB,IAAI,8BAA8B;IAClD,SAAgB,WAAW,2EAA4E;gBAG9F,SAAS,EAAE,QAAQ;IAU5B,KAAK,IAAI,IAAI;IAIb,OAAO,CAAC,kBAAkB;CAQ1B"}