@observertc/observer-js 1.0.1-797e5af.0 → 1.0.1-7be4daa.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 (60) 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 +2 -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/ObservedPeerConnection.d.ts.map +1 -1
  14. package/lib/ObservedPeerConnection.js +60 -15
  15. package/lib/Observer.d.ts +8 -4
  16. package/lib/Observer.d.ts.map +1 -1
  17. package/lib/Observer.js +14 -2
  18. package/lib/ObserverEventMonitor.d.ts +106 -0
  19. package/lib/ObserverEventMonitor.d.ts.map +1 -0
  20. package/lib/ObserverEventMonitor.js +320 -0
  21. package/lib/index.d.ts +1 -0
  22. package/lib/index.d.ts.map +1 -1
  23. package/lib/index.js +3 -1
  24. package/lib/schema/ClientEventTypes.d.ts +17 -0
  25. package/lib/schema/ClientEventTypes.d.ts.map +1 -1
  26. package/lib/schema/ClientSample.d.ts +1 -1
  27. package/lib/schema/ClientSample.d.ts.map +1 -1
  28. package/lib/updaters/{OnAllCallObserverUpdater_.d.ts → OnAllCallObserverUpdater.d.ts} +3 -1
  29. package/lib/updaters/OnAllCallObserverUpdater.d.ts.map +1 -0
  30. package/lib/updaters/{OnAllCallObserverUpdater_.js → OnAllCallObserverUpdater.js} +13 -1
  31. package/lib/updaters/OnAllClientCallUpdater.d.ts +2 -0
  32. package/lib/updaters/OnAllClientCallUpdater.d.ts.map +1 -1
  33. package/lib/updaters/OnAllClientCallUpdater.js +16 -0
  34. package/lib/updaters/{OnAnyCallObserverUpdater_.d.ts → OnAnyCallObserverUpdater.d.ts} +2 -1
  35. package/lib/updaters/OnAnyCallObserverUpdater.d.ts.map +1 -0
  36. package/lib/updaters/{OnAnyCallObserverUpdater_.js → OnAnyCallObserverUpdater.js} +11 -1
  37. package/lib/updaters/OnAnyClientCallUpdater.d.ts +1 -0
  38. package/lib/updaters/OnAnyClientCallUpdater.d.ts.map +1 -1
  39. package/lib/updaters/OnAnyClientCallUpdater.js +11 -2
  40. package/lib/utils/MediasoupRemoteTrackResolver.d.ts +25 -0
  41. package/lib/utils/MediasoupRemoteTrackResolver.d.ts.map +1 -0
  42. package/lib/utils/MediasoupRemoteTrackResolver.js +110 -0
  43. package/package.json +1 -1
  44. package/src/ObservedCall.ts +5 -0
  45. package/src/ObservedCallEventMonitor.ts +392 -0
  46. package/src/ObservedClient.ts +4 -7
  47. package/src/ObservedIceCandidatePair.ts +18 -2
  48. package/src/ObservedPeerConnection.ts +60 -30
  49. package/src/Observer.ts +21 -6
  50. package/src/ObserverEventMonitor.ts +398 -0
  51. package/src/index.ts +1 -0
  52. package/src/schema/ClientEventTypes.ts +18 -0
  53. package/src/schema/ClientSample.ts +1 -1
  54. package/src/updaters/{OnAllCallObserverUpdater_.ts → OnAllCallObserverUpdater.ts} +14 -1
  55. package/src/updaters/OnAllClientCallUpdater.ts +15 -0
  56. package/src/updaters/{OnAnyCallObserverUpdater_.ts → OnAnyCallObserverUpdater.ts} +12 -3
  57. package/src/updaters/OnAnyClientCallUpdater.ts +9 -2
  58. package/src/utils/MediasoupRemoteTrackResolver.ts +155 -0
  59. package/lib/updaters/OnAllCallObserverUpdater_.d.ts.map +0 -1
  60. package/lib/updaters/OnAnyCallObserverUpdater_.d.ts.map +0 -1
@@ -5,6 +5,7 @@ class OnAnyCallObserverUpdater {
5
5
  observver;
6
6
  name = 'OnAnyCallObserverUpdater';
7
7
  description = 'Call Observer\'s update() method on any of the ObservedCall is updated';
8
+ closed = false;
8
9
  constructor(observver) {
9
10
  this.observver = observver;
10
11
  this._onNewObservedCall = this._onNewObservedCall.bind(this);
@@ -14,10 +15,19 @@ class OnAnyCallObserverUpdater {
14
15
  this.observver.on('newcall', this._onNewObservedCall);
15
16
  }
16
17
  close() {
18
+ if (this.closed)
19
+ return;
20
+ this.closed = true;
17
21
  // do nothing, because we unsubscribe once close is emitted from observer
18
22
  }
19
23
  _onNewObservedCall(observedCall) {
20
- const onUpdate = () => this.observver.update();
24
+ if (this.closed)
25
+ return;
26
+ const onUpdate = () => {
27
+ if (this.closed)
28
+ return;
29
+ this.observver.update();
30
+ };
21
31
  observedCall.once('close', () => {
22
32
  observedCall.off('update', onUpdate);
23
33
  });
@@ -4,6 +4,7 @@ export declare class OnAnyClientCallUpdater implements Updater {
4
4
  private _observedCall;
5
5
  readonly name = "OnAnyClientCallUpdater";
6
6
  readonly description = "Call the update() method of the ObservedCall when any of the client has been updated";
7
+ closed: boolean;
7
8
  constructor(_observedCall: ObservedCall);
8
9
  close(): void;
9
10
  private _onNewObservedClient;
@@ -1 +1 @@
1
- {"version":3,"file":"OnAnyClientCallUpdater.d.ts","sourceRoot":"","sources":["../../src/updaters/OnAnyClientCallUpdater.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,qBAAa,sBAAuB,YAAW,OAAO;IAKpD,OAAO,CAAC,aAAa;IAJtB,QAAQ,CAAC,IAAI,4BAA4B;IACzC,QAAQ,CAAC,WAAW,0FAA0F;gBAGrG,aAAa,EAAE,YAAY;IAU7B,KAAK,IAAI,IAAI;IAIpB,OAAO,CAAC,oBAAoB;CAQ5B"}
1
+ {"version":3,"file":"OnAnyClientCallUpdater.d.ts","sourceRoot":"","sources":["../../src/updaters/OnAnyClientCallUpdater.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,qBAAa,sBAAuB,YAAW,OAAO;IAMpD,OAAO,CAAC,aAAa;IALtB,QAAQ,CAAC,IAAI,4BAA4B;IACzC,QAAQ,CAAC,WAAW,0FAA0F;IACvG,MAAM,UAAS;gBAGb,aAAa,EAAE,YAAY;IAU7B,KAAK,IAAI,IAAI;IAKpB,OAAO,CAAC,oBAAoB;CAa5B"}
@@ -5,6 +5,7 @@ class OnAnyClientCallUpdater {
5
5
  _observedCall;
6
6
  name = 'OnAnyClientCallUpdater';
7
7
  description = 'Call the update() method of the ObservedCall when any of the client has been updated';
8
+ closed = false;
8
9
  constructor(_observedCall) {
9
10
  this._observedCall = _observedCall;
10
11
  this._onNewObservedClient = this._onNewObservedClient.bind(this);
@@ -14,10 +15,18 @@ class OnAnyClientCallUpdater {
14
15
  this._observedCall.on('newclient', this._onNewObservedClient);
15
16
  }
16
17
  close() {
17
- // do nothing, as close once emitted unsubscription happened
18
+ if (this.closed)
19
+ return;
20
+ this.closed = true;
18
21
  }
19
22
  _onNewObservedClient(observedClient) {
20
- const onUpdate = () => this._observedCall.update();
23
+ if (this.closed)
24
+ return;
25
+ const onUpdate = () => {
26
+ if (this.closed)
27
+ return;
28
+ this._observedCall.update();
29
+ };
21
30
  observedClient.once('close', () => {
22
31
  observedClient.off('update', onUpdate);
23
32
  });
@@ -0,0 +1,25 @@
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
+ export declare class MediasoupRemoteTrackResolver implements RemoteTrackResolver {
7
+ readonly observedCall: ObservedCall;
8
+ readonly eventMonitor: ObservedCallEventMonitor<{}>;
9
+ private _consumerIdToProducerId;
10
+ private _producerIdToOutboundTrack;
11
+ private _consumerIdToInboundTrack;
12
+ private _inboundTrackToConsumerId;
13
+ private _producerIdToConsumerIds;
14
+ private _outboundTrackToProducerId;
15
+ constructor(observedCall: ObservedCall);
16
+ resolveRemoteOutboundTrack(inboundTrack: ObservedInboundTrack): ObservedOutboundTrack | undefined;
17
+ resolveRemoteInboundTracks(outboundTrack: ObservedOutboundTrack): ObservedInboundTrack[] | undefined;
18
+ private _addInboundTrack;
19
+ private _removeInboundTrack;
20
+ private _addOutboundTrack;
21
+ private _removeOutboundTrack;
22
+ private _getInboundTrackAttachments;
23
+ private _getOutboundTrackAttachments;
24
+ }
25
+ //# sourceMappingURL=MediasoupRemoteTrackResolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MediasoupRemoteTrackResolver.d.ts","sourceRoot":"","sources":["../../src/utils/MediasoupRemoteTrackResolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,qBAAa,4BAA6B,YAAW,mBAAmB;aAetD,YAAY,EAAE,YAAY;IAd3C,SAAgB,YAAY,EAAE,wBAAwB,CAAC,EAEtD,CAAC,CAAC;IAEH,OAAO,CAAC,uBAAuB,CAA6B;IAC5D,OAAO,CAAC,0BAA0B,CAA4C;IAC9E,OAAO,CAAC,yBAAyB,CAA2C;IAG5E,OAAO,CAAC,yBAAyB,CAA6B;IAC9D,OAAO,CAAC,wBAAwB,CAA+B;IAC/D,OAAO,CAAC,0BAA0B,CAA6B;gBAG9C,YAAY,EAAE,YAAY;IAcpC,0BAA0B,CAAC,YAAY,EAAE,oBAAoB,GAAG,qBAAqB,GAAG,SAAS;IAYjG,0BAA0B,CAAC,aAAa,EAAE,qBAAqB,GAAG,oBAAoB,EAAE,GAAG,SAAS;IAe3G,OAAO,CAAC,gBAAgB;IAuBxB,OAAO,CAAC,mBAAmB;IAsB3B,OAAO,CAAC,iBAAiB;IAazB,OAAO,CAAC,oBAAoB;IAS5B,OAAO,CAAC,2BAA2B;IAcnC,OAAO,CAAC,4BAA4B;CAWpC"}
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MediasoupRemoteTrackResolver = void 0;
4
+ class MediasoupRemoteTrackResolver {
5
+ observedCall;
6
+ eventMonitor;
7
+ _consumerIdToProducerId = new Map();
8
+ _producerIdToOutboundTrack = new Map();
9
+ _consumerIdToInboundTrack = new Map();
10
+ // private _producerIdToOutboundTrack = new Map<string, ObservedOutboundTrack>();
11
+ _inboundTrackToConsumerId = new Map();
12
+ _producerIdToConsumerIds = new Map();
13
+ _outboundTrackToProducerId = new Map();
14
+ constructor(observedCall) {
15
+ this.observedCall = observedCall;
16
+ this.eventMonitor = this.observedCall.createEventMonitor({});
17
+ this.eventMonitor.onInboundTrackAdded = this._addInboundTrack.bind(this);
18
+ this.eventMonitor.onInboundTrackRemoved = this._removeInboundTrack.bind(this);
19
+ this.eventMonitor.onOutboundTrackAdded = this._addOutboundTrack.bind(this);
20
+ this.eventMonitor.onOutboundTrackRemoved = this._removeOutboundTrack.bind(this);
21
+ // this.eventMonitor.onClientEvent = (client, event) => {
22
+ // };
23
+ }
24
+ resolveRemoteOutboundTrack(inboundTrack) {
25
+ const consumerId = this._inboundTrackToConsumerId.get(inboundTrack.id);
26
+ if (!consumerId)
27
+ return;
28
+ const producerId = this._consumerIdToProducerId.get(consumerId);
29
+ if (!producerId)
30
+ return;
31
+ return this._producerIdToOutboundTrack.get(producerId);
32
+ }
33
+ resolveRemoteInboundTracks(outboundTrack) {
34
+ const producerId = this._outboundTrackToProducerId.get(outboundTrack.id);
35
+ if (!producerId)
36
+ return;
37
+ const consumerIds = this._producerIdToConsumerIds.get(producerId);
38
+ if (!consumerIds)
39
+ return;
40
+ return consumerIds
41
+ .map((consumerId) => this._consumerIdToInboundTrack.get(consumerId))
42
+ .filter((inboundTrack) => Boolean(inboundTrack));
43
+ }
44
+ _addInboundTrack(inboundTrack) {
45
+ const attachments = this._getInboundTrackAttachments(inboundTrack);
46
+ if (!attachments)
47
+ return;
48
+ const { producerId, consumerId } = attachments;
49
+ this._inboundTrackToConsumerId.set(inboundTrack.id, consumerId);
50
+ this._consumerIdToProducerId.set(consumerId, producerId);
51
+ this._consumerIdToInboundTrack.set(consumerId, inboundTrack);
52
+ let producerConsumers = this._producerIdToConsumerIds.get(producerId);
53
+ if (!producerConsumers) {
54
+ producerConsumers = [];
55
+ this._producerIdToConsumerIds.set(producerId, producerConsumers);
56
+ }
57
+ producerConsumers.push(consumerId);
58
+ }
59
+ _removeInboundTrack(inboundTrack) {
60
+ const consumerId = this._inboundTrackToConsumerId.get(inboundTrack.id);
61
+ if (!consumerId)
62
+ return;
63
+ this._inboundTrackToConsumerId.delete(inboundTrack.id);
64
+ this._consumerIdToProducerId.delete(consumerId);
65
+ this._consumerIdToInboundTrack.delete(consumerId);
66
+ const producerConsumers = this._producerIdToConsumerIds.get(consumerId);
67
+ if (!producerConsumers)
68
+ return;
69
+ const filteredProducerConsumers = producerConsumers.filter((id) => id !== consumerId);
70
+ if (filteredProducerConsumers.length === 0) {
71
+ this._producerIdToConsumerIds.delete(consumerId);
72
+ }
73
+ else {
74
+ this._producerIdToConsumerIds.set(consumerId, filteredProducerConsumers);
75
+ }
76
+ }
77
+ _addOutboundTrack(outboundTrack) {
78
+ const attachments = this._getOutboundTrackAttachments(outboundTrack);
79
+ if (!attachments)
80
+ return;
81
+ const { producerId, } = attachments;
82
+ this._producerIdToOutboundTrack.set(producerId, outboundTrack);
83
+ this._outboundTrackToProducerId.set(outboundTrack.id, producerId);
84
+ }
85
+ _removeOutboundTrack(outboundTrack) {
86
+ const producerId = this._outboundTrackToProducerId.get(outboundTrack.id);
87
+ if (!producerId)
88
+ return;
89
+ this._producerIdToOutboundTrack.delete(producerId);
90
+ this._outboundTrackToProducerId.delete(outboundTrack.id);
91
+ }
92
+ _getInboundTrackAttachments(inboundTrack) {
93
+ const { producerId, consumerId } = inboundTrack.attachments ?? {};
94
+ if (!producerId || !consumerId || typeof producerId !== 'string' || typeof consumerId !== 'string')
95
+ return;
96
+ return {
97
+ producerId,
98
+ consumerId
99
+ };
100
+ }
101
+ _getOutboundTrackAttachments(outboundTrack) {
102
+ const { producerId, } = outboundTrack.attachments ?? {};
103
+ if (!producerId || typeof producerId !== 'string')
104
+ return;
105
+ return {
106
+ producerId,
107
+ };
108
+ }
109
+ }
110
+ exports.MediasoupRemoteTrackResolver = MediasoupRemoteTrackResolver;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@observertc/observer-js",
3
- "version": "1.0.1-797e5af.0",
3
+ "version": "1.0.1-7be4daa.0",
4
4
  "description": "Server Side NodeJS Library for processing ObserveRTC Samples",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -10,6 +10,7 @@ import { OnAllClientCallUpdater } from './updaters/OnAllClientCallUpdater';
10
10
  import { Updater } from './updaters/Updater';
11
11
  import { OnIntervalUpdater } from './updaters/OnIntervalUpdater';
12
12
  import { OnAnyClientCallUpdater } from './updaters/OnAnyClientCallUpdater';
13
+ import { ObservedCallEventMonitor } from './ObservedCallEventMonitor';
13
14
 
14
15
  export type ObservedCallSettings<AppData extends Record<string, unknown> = Record<string, unknown>> = {
15
16
  callId: string;
@@ -206,6 +207,10 @@ export class ObservedCall<AppData extends Record<string, unknown> = Record<strin
206
207
  return result;
207
208
  }
208
209
 
210
+ public createEventMonitor<CTX>(context: CTX): ObservedCallEventMonitor<CTX> {
211
+ return new ObservedCallEventMonitor(this, context);
212
+ }
213
+
209
214
  public update() {
210
215
  if (this.closed) return;
211
216
 
@@ -0,0 +1,392 @@
1
+ import { ObservedCall } from './ObservedCall';
2
+ import { ObservedCertificate } from './ObservedCertificate';
3
+ import { ObservedClient, ObservedClientEvents } from './ObservedClient';
4
+ import { ObservedCodec } from './ObservedCodec';
5
+ import { ObservedDataChannel } from './ObservedDataChannel';
6
+ import { ObservedIceCandidate } from './ObservedIceCandidate';
7
+ import { ObservedIceCandidatePair } from './ObservedIceCandidatePair';
8
+ import { ObservedIceTransport } from './ObservedIceTransport';
9
+ import { ObservedInboundRtp } from './ObservedInboundRtp';
10
+ import { ObservedInboundTrack } from './ObservedInboundTrack';
11
+ import { ObservedMediaPlayout } from './ObservedMediaPlayout';
12
+ import { ObservedMediaSource } from './ObservedMediaSource';
13
+ import { ObservedOutboundRtp } from './ObservedOutboundRtp';
14
+ import { ObservedOutboundTrack } from './ObservedOutboundTrack';
15
+ import { ObservedPeerConnection } from './ObservedPeerConnection';
16
+ import { ClientEvent, ClientIssue, ClientMetaData, ClientSample, ExtensionStat } from './schema/ClientSample';
17
+
18
+ export class ObservedCallEventMonitor<Context> {
19
+ public constructor(
20
+ public readonly call: ObservedCall,
21
+ public readonly context: Context,
22
+ ) {
23
+ this._onPeerConnconnectionAdded = this._onPeerConnconnectionAdded.bind(this);
24
+ this._onPeerConnectionRemoved = this._onPeerConnectionRemoved.bind(this);
25
+ this._onCertificateAdded = this._onCertificateAdded.bind(this);
26
+ this._onCertificateRemoved = this._onCertificateRemoved.bind(this);
27
+ this._onInboundTrackAdded = this._onInboundTrackAdded.bind(this);
28
+ this._onInboundTrackRemoved = this._onInboundTrackRemoved.bind(this);
29
+ this._onOutboundTrackAdded = this._onOutboundTrackAdded.bind(this);
30
+ this._onOutboundTrackRemoved = this._onOutboundTrackRemoved.bind(this);
31
+ this._onInboundRtpAdded = this._onInboundRtpAdded.bind(this);
32
+ this._onInboundRtpRemoved = this._onInboundRtpRemoved.bind(this);
33
+ this._onOutboundRtpAdded = this._onOutboundRtpAdded.bind(this);
34
+ this._onOutboundRtpRemoved = this._onOutboundRtpRemoved.bind(this);
35
+ this._onDataChannelAdded = this._onDataChannelAdded.bind(this);
36
+ this._onDataChannelRemoved = this._onDataChannelRemoved.bind(this);
37
+ this._onAddedIceTransport = this._onAddedIceTransport.bind(this);
38
+ this._onRemovedIceTransport = this._onRemovedIceTransport.bind(this);
39
+ this._onIceCandidateAdded = this._onIceCandidateAdded.bind(this);
40
+ this._onIceCandidateRemoved = this._onIceCandidateRemoved.bind(this);
41
+ this._onAddedIceCandidatePair = this._onAddedIceCandidatePair.bind(this);
42
+ this._onRemovedIceCandidatePair = this._onRemovedIceCandidatePair.bind(this);
43
+ this._onAddedMediaCodec = this._onAddedMediaCodec.bind(this);
44
+ this._onRemovedMediaCodec = this._onRemovedMediaCodec.bind(this);
45
+ this._onAddedMediaPlayout = this._onAddedMediaPlayout.bind(this);
46
+ this._onRemovedMediaPlayout = this._onRemovedMediaPlayout.bind(this);
47
+ this._onMediaSourceAdded = this._onMediaSourceAdded.bind(this);
48
+ this._onMediaSourceRemoved = this._onMediaSourceRemoved.bind(this);
49
+ this._onClientIssue = this._onClientIssue.bind(this);
50
+ this._onClientMetadata = this._onClientMetadata.bind(this);
51
+ this._onClientJoined = this._onClientJoined.bind(this);
52
+ this._onClientLeft = this._onClientLeft.bind(this);
53
+ this._onUserMediaError = this._onUserMediaError.bind(this);
54
+ this._onUsingTurn = this._onUsingTurn.bind(this);
55
+ this._onClientAdded = this._onClientAdded.bind(this);
56
+ this._onCallAdded = this._onCallAdded.bind(this);
57
+ this._onClientRejoined = this._onClientRejoined.bind(this);
58
+ this._onClientExtensionStats = this._onClientExtensionStats.bind(this);
59
+
60
+ this._onCallAdded(call);
61
+ }
62
+
63
+ // Public event handlers
64
+ public onCallClosed?: (call: ObservedCall, ctx: Context) => void;
65
+ public onCallEmpty?: (call: ObservedCall, ctx: Context) => void;
66
+ public onCallNotEmpty?: (call: ObservedCall, ctx: Context) => void;
67
+ public onCallUpdated?: (call: ObservedCall, ctx: Context) => void;
68
+
69
+ public onClientAdded?: (client: ObservedClient, ctx: Context) => void;
70
+ public onClientClosed?: (client: ObservedClient, ctx: Context) => void;
71
+ public onClientRejoined?: (client: ObservedClient, ctx: Context) => void;
72
+ public onClientIssue?: (observedClent: ObservedClient, issue: ClientIssue, ctx: Context) => void;
73
+ public onClientMetadata?: (observedClient: ObservedClient, metadata: ClientMetaData, ctx: Context) => void;
74
+ public onClientExtensionStats?: (observedClient: ObservedClient, extensionStats: ExtensionStat, ctx: Context) => void;
75
+ public onClientJoined?: (client: ObservedClient, ctx: Context) => void;
76
+ public onClientLeft?: (client: ObservedClient, ctx: Context) => void;
77
+ public onClientUserMediaError?: (observedClient: ObservedClient, error: string, ctx: Context) => void;
78
+ public onClientUsingTurn?: (client: ObservedClient, usingTurn: boolean, ctx: Context) => void;
79
+ public onClientUpdated?: (client: ObservedClient, sample: ClientSample, ctx: Context) => void;
80
+ public onClientEvent?: (client: ObservedClient, event: ClientEvent, ctx: Context) => void;
81
+
82
+ public onPeerConnectionAdded?: (peerConnection: ObservedPeerConnection, ctx: Context) => void;
83
+ public onPeerConnectionRemoved?: (peerConnection: ObservedPeerConnection, ctx: Context) => void;
84
+ public onSelectedCandidatePairChanged?: (peerConnection: ObservedPeerConnection, ctx: Context) => void;
85
+ public onIceGatheringStateChange?: (peerConnection: ObservedPeerConnection, ctx: Context) => void;
86
+ public onIceConnectionStateChange?: (peerConnection: ObservedPeerConnection, ctx: Context) => void;
87
+ public onConnectionStateChange?: (peerConnection: ObservedPeerConnection, ctx: Context) => void;
88
+
89
+ public onCertificateAdded?: (certificate: ObservedCertificate, ctx: Context) => void;
90
+ public onCertificateRemoved?: (certificate: ObservedCertificate, ctx: Context) => void;
91
+
92
+ public onInboundTrackAdded?: (inboundTrack: ObservedInboundTrack, ctx: Context) => void;
93
+ public onInboundTrackRemoved?: (inboundTrack: ObservedInboundTrack, ctx: Context) => void;
94
+
95
+ public onOutboundTrackAdded?: (outboundTrack: ObservedOutboundTrack, ctx: Context) => void;
96
+ public onOutboundTrackRemoved?: (outboundTrack: ObservedOutboundTrack, ctx: Context) => void;
97
+
98
+ public onInboundRtpAdded?: (inboundRtp: ObservedInboundRtp, ctx: Context) => void;
99
+ public onInboundRtpRemoved?: (inboundRtp: ObservedInboundRtp, ctx: Context) => void;
100
+
101
+ public onOutboundRtpAdded?: (outboundRtp: ObservedOutboundRtp, ctx: Context) => void;
102
+ public onOutboundRtpRemoved?: (outboundRtp: ObservedOutboundRtp, ctx: Context) => void;
103
+
104
+ public onDataChannelAdded?: (dataChannel: ObservedDataChannel, ctx: Context) => void;
105
+ public onDataChannelRemoved?: (dataChannel: ObservedDataChannel, ctx: Context) => void;
106
+
107
+ public onAddedIceTransport?: (iceTransport: ObservedIceTransport, ctx: Context) => void;
108
+ public onRemovedIceTransport?: (iceTransport: ObservedIceTransport, ctx: Context) => void;
109
+
110
+ public onIceCandidateAdded?: (iceCandidate: ObservedIceCandidate, ctx: Context) => void;
111
+ public onIceCandidateRemoved?: (iceCandidate: ObservedIceCandidate, ctx: Context) => void;
112
+
113
+ public onAddedIceCandidatePair?: (candidatePair: ObservedIceCandidatePair, ctx: Context) => void;
114
+ public onRemovedIceCandidatePair?: (candidatePair: ObservedIceCandidatePair, ctx: Context) => void;
115
+
116
+ public onAddedMediaCodec?: (codec: ObservedCodec, ctx: Context) => void;
117
+ public onRemovedMediaCodec?: (codec: ObservedCodec, ctx: Context) => void;
118
+
119
+ public onAddedMediaPlayout?: (mediaPlayout: ObservedMediaPlayout, ctx: Context) => void;
120
+ public onRemovedMediaPlayout?: (mediaPlayout: ObservedMediaPlayout, ctx: Context) => void;
121
+
122
+ public onMediaSourceAdded?: (mediaSource: ObservedMediaSource, ctx: Context) => void;
123
+ public onMediaSourceRemoved?: (mediaSource: ObservedMediaSource, ctx: Context) => void;
124
+
125
+ private _onCallAdded(call: ObservedCall) {
126
+ const onCallEmpty = () => this.onCallEmpty?.(call, this.context);
127
+ const onCallNotEmpty = () => this.onCallNotEmpty?.(call, this.context);
128
+ const onCallUpdated = () => this.onCallUpdated?.(call, this.context);
129
+
130
+ call.once('close', () => {
131
+ call.off('newclient', this._onClientAdded);
132
+ call.off('empty', onCallEmpty);
133
+ call.off('not-empty', onCallNotEmpty);
134
+ call.off('update', onCallUpdated);
135
+
136
+ this.onCallClosed?.(call, this.context);
137
+
138
+ });
139
+ call.on('newclient', this._onClientAdded);
140
+ call.on('empty', onCallEmpty);
141
+ call.on('not-empty', onCallNotEmpty);
142
+ call.on('update', onCallUpdated);
143
+
144
+ }
145
+
146
+ private _onClientAdded(observedClient: ObservedClient) {
147
+ const onClientIssue = (issue: ClientIssue) => this._onClientIssue(observedClient, issue);
148
+ const onClientMetadata = (metaData: ClientMetaData) => this._onClientMetadata(observedClient, metaData);
149
+ const onClientJoined = () => this._onClientJoined(observedClient);
150
+ const onClientLeft = () => this._onClientLeft(observedClient);
151
+ const onClientRejoined = () => this._onClientRejoined(observedClient);
152
+ const onClientExtensionStats = (extensionStats: ExtensionStat) => this._onClientExtensionStats(observedClient, extensionStats);
153
+ const onUsingTurn = (usingTurn: boolean) => this._onUsingTurn(observedClient, usingTurn);
154
+ const onUserMediaError = (error: string) => this._onUserMediaError(observedClient, error);
155
+ const onClientUpdated = (...args: ObservedClientEvents['update']) => this.onClientUpdated?.(observedClient, args[0].sample, this.context);
156
+ const onClientEvent = (event: ClientEvent) => this.onClientEvent?.(observedClient, event, this.context);
157
+
158
+ observedClient.once('close', () => {
159
+ observedClient.off('newpeerconnection', this._onPeerConnconnectionAdded);
160
+ observedClient.off('issue', onClientIssue);
161
+ observedClient.off('metaData', onClientMetadata);
162
+ observedClient.off('joined', onClientJoined);
163
+ observedClient.off('left', onClientLeft);
164
+ observedClient.off('rejoined', onClientJoined);
165
+ observedClient.off('usermediaerror', onUserMediaError);
166
+ observedClient.off('usingturn', onUsingTurn);
167
+ observedClient.off('update', onClientUpdated);
168
+ observedClient.off('clientEvent', onClientEvent);
169
+
170
+ this.onClientClosed?.(observedClient, this.context);
171
+ });
172
+
173
+ observedClient.on('newpeerconnection', this._onPeerConnconnectionAdded);
174
+ observedClient.on('issue', onClientIssue);
175
+ observedClient.on('metaData', onClientMetadata);
176
+ observedClient.on('joined', onClientJoined);
177
+ observedClient.on('left', onClientLeft);
178
+ observedClient.on('rejoined', onClientRejoined);
179
+ observedClient.on('usermediaerror', onUserMediaError);
180
+ observedClient.on('usingturn', onUsingTurn);
181
+ observedClient.on('extensionStats', onClientExtensionStats);
182
+ observedClient.on('update', onClientUpdated);
183
+ observedClient.on('clientEvent', onClientEvent);
184
+
185
+ this.onClientAdded?.(observedClient, this.context);
186
+ }
187
+
188
+ private _onClientRejoined(observedClient: ObservedClient) {
189
+ this.onClientRejoined?.(observedClient, this.context);
190
+ }
191
+
192
+ private _onPeerConnconnectionAdded(peerConnection: ObservedPeerConnection) {
193
+ const onSelectedCandidatePairChanged = () => this.onSelectedCandidatePairChanged?.(peerConnection, this.context);
194
+ const onIceGatheringStateChange = () => this.onIceGatheringStateChange?.(peerConnection, this.context);
195
+ const onIceConnectionStateChange = () => this.onIceConnectionStateChange?.(peerConnection, this.context);
196
+ const onConnectionStateChange = () => this.onConnectionStateChange?.(peerConnection, this.context);
197
+
198
+ peerConnection.once('close', () => {
199
+ peerConnection.off('added-certificate', this._onCertificateAdded);
200
+ peerConnection.off('removed-certificate', this._onCertificateRemoved);
201
+ peerConnection.off('added-inbound-track', this._onInboundTrackAdded);
202
+ peerConnection.off('removed-inbound-track', this._onInboundTrackRemoved);
203
+ peerConnection.off('added-outbound-track', this._onOutboundTrackAdded);
204
+ peerConnection.off('removed-outbound-track', this._onOutboundTrackRemoved);
205
+ peerConnection.off('added-inbound-rtp', this._onInboundRtpAdded);
206
+ peerConnection.off('removed-inbound-rtp', this._onInboundRtpRemoved);
207
+ peerConnection.off('added-outbound-rtp', this._onOutboundRtpAdded);
208
+ peerConnection.off('removed-outbound-rtp', this._onOutboundRtpRemoved);
209
+ peerConnection.off('added-data-channel', this._onDataChannelAdded);
210
+ peerConnection.off('removed-data-channel', this._onDataChannelRemoved);
211
+ peerConnection.off('added-ice-transport', this._onAddedIceTransport);
212
+ peerConnection.off('removed-ice-transport', this._onRemovedIceTransport);
213
+ peerConnection.off('added-ice-candidate', this._onIceCandidateAdded);
214
+ peerConnection.off('removed-ice-candidate', this._onIceCandidateRemoved);
215
+ peerConnection.off('added-ice-candidate-pair', this._onAddedIceCandidatePair);
216
+ peerConnection.off('removed-ice-candidate-pair', this._onRemovedIceCandidatePair);
217
+ peerConnection.off('added-codec', this._onAddedMediaCodec);
218
+ peerConnection.off('removed-codec', this._onRemovedMediaCodec);
219
+ peerConnection.off('added-media-playout', this._onAddedMediaPlayout);
220
+ peerConnection.off('removed-media-playout', this._onRemovedMediaPlayout);
221
+ peerConnection.off('added-media-source', this._onMediaSourceAdded);
222
+ peerConnection.off('removed-media-source', this._onMediaSourceRemoved);
223
+ peerConnection.off('selectedcandidatepair', onSelectedCandidatePairChanged);
224
+ peerConnection.off('icegatheringstatechange', onIceGatheringStateChange);
225
+ peerConnection.off('iceconnectionstatechange', onIceConnectionStateChange);
226
+ peerConnection.off('connectionstatechange', onConnectionStateChange);
227
+
228
+ this.onPeerConnectionRemoved?.(peerConnection, this.context);
229
+ });
230
+
231
+ peerConnection.on('added-certificate', this._onCertificateAdded);
232
+ peerConnection.on('removed-certificate', this._onCertificateRemoved);
233
+ peerConnection.on('added-inbound-track', this._onInboundTrackAdded);
234
+ peerConnection.on('removed-inbound-track', this._onInboundTrackRemoved);
235
+ peerConnection.on('added-outbound-track', this._onOutboundTrackAdded);
236
+ peerConnection.on('removed-outbound-track', this._onOutboundTrackRemoved);
237
+ peerConnection.on('added-inbound-rtp', this._onInboundRtpAdded);
238
+ peerConnection.on('removed-inbound-rtp', this._onInboundRtpRemoved);
239
+ peerConnection.on('added-outbound-rtp', this._onOutboundRtpAdded);
240
+ peerConnection.on('removed-outbound-rtp', this._onOutboundRtpRemoved);
241
+ peerConnection.on('added-data-channel', this._onDataChannelAdded);
242
+ peerConnection.on('removed-data-channel', this._onDataChannelRemoved);
243
+ peerConnection.on('added-ice-transport', this._onAddedIceTransport);
244
+ peerConnection.on('removed-ice-transport', this._onRemovedIceTransport);
245
+ peerConnection.on('added-ice-candidate', this._onIceCandidateAdded);
246
+ peerConnection.on('removed-ice-candidate', this._onIceCandidateRemoved);
247
+ peerConnection.on('added-ice-candidate-pair', this._onAddedIceCandidatePair);
248
+ peerConnection.on('removed-ice-candidate-pair', this._onRemovedIceCandidatePair);
249
+ peerConnection.on('added-codec', this._onAddedMediaCodec);
250
+ peerConnection.on('removed-codec', this._onRemovedMediaCodec);
251
+ peerConnection.on('added-media-playout', this._onAddedMediaPlayout);
252
+ peerConnection.on('removed-media-playout', this._onRemovedMediaPlayout);
253
+ peerConnection.on('added-media-source', this._onMediaSourceAdded);
254
+ peerConnection.on('removed-media-source', this._onMediaSourceRemoved);
255
+ peerConnection.on('selectedcandidatepair', onSelectedCandidatePairChanged);
256
+ peerConnection.on('icegatheringstatechange', onIceGatheringStateChange);
257
+ peerConnection.on('iceconnectionstatechange', onIceConnectionStateChange);
258
+ peerConnection.on('connectionstatechange', onConnectionStateChange);
259
+
260
+ this.onPeerConnectionAdded?.(peerConnection, this.context);
261
+
262
+ }
263
+
264
+ private _onPeerConnectionRemoved(peerConnection: ObservedPeerConnection) {
265
+ this.onPeerConnectionRemoved?.(peerConnection, this.context);
266
+
267
+ }
268
+
269
+ private _onCertificateAdded(certificate: ObservedCertificate) {
270
+ this.onCertificateAdded?.(certificate, this.context);
271
+ }
272
+
273
+ private _onCertificateRemoved(certificate: ObservedCertificate) {
274
+ this.onCertificateRemoved?.(certificate, this.context);
275
+ }
276
+
277
+ private _onInboundTrackAdded(inboundTrack: ObservedInboundTrack) {
278
+ this.onInboundTrackAdded?.(inboundTrack, this.context);
279
+ }
280
+
281
+ private _onInboundTrackRemoved(inboundTrack: ObservedInboundTrack) {
282
+ this.onInboundTrackRemoved?.(inboundTrack, this.context);
283
+ }
284
+
285
+ private _onOutboundTrackAdded(outboundTrack: ObservedOutboundTrack) {
286
+ this.onOutboundTrackAdded?.(outboundTrack, this.context);
287
+ }
288
+
289
+ private _onOutboundTrackRemoved(outboundTrack: ObservedOutboundTrack) {
290
+ this.onOutboundTrackRemoved?.(outboundTrack, this.context);
291
+ }
292
+
293
+ private _onInboundRtpAdded(inboundRtp: ObservedInboundRtp) {
294
+ this.onInboundRtpAdded?.(inboundRtp, this.context);
295
+ }
296
+
297
+ private _onInboundRtpRemoved(inboundRtp: ObservedInboundRtp) {
298
+ this.onInboundRtpRemoved?.(inboundRtp, this.context);
299
+ }
300
+
301
+ private _onOutboundRtpAdded(outboundRtp: ObservedOutboundRtp) {
302
+ this.onOutboundRtpAdded?.(outboundRtp, this.context);
303
+ }
304
+
305
+ private _onOutboundRtpRemoved(outboundRtp: ObservedOutboundRtp) {
306
+ this.onOutboundRtpRemoved?.(outboundRtp, this.context);
307
+ }
308
+
309
+ private _onDataChannelAdded(dataChannel: ObservedDataChannel) {
310
+ this.onDataChannelAdded?.(dataChannel, this.context);
311
+ }
312
+
313
+ private _onDataChannelRemoved(dataChannel: ObservedDataChannel) {
314
+ this.onDataChannelRemoved?.(dataChannel, this.context);
315
+ }
316
+
317
+ private _onAddedIceTransport(iceTransport: ObservedIceTransport) {
318
+ this.onAddedIceTransport?.(iceTransport, this.context);
319
+ }
320
+
321
+ private _onRemovedIceTransport(iceTransport: ObservedIceTransport) {
322
+ this.onRemovedIceTransport?.(iceTransport, this.context);
323
+ }
324
+
325
+ private _onIceCandidateAdded(iceCandidate: ObservedIceCandidate) {
326
+ this.onIceCandidateAdded?.(iceCandidate, this.context);
327
+ }
328
+
329
+ private _onIceCandidateRemoved(iceCandidate: ObservedIceCandidate) {
330
+ this.onIceCandidateRemoved?.(iceCandidate, this.context);
331
+ }
332
+
333
+ private _onAddedIceCandidatePair(candidatePair: ObservedIceCandidatePair) {
334
+ this.onAddedIceCandidatePair?.(candidatePair, this.context);
335
+ }
336
+
337
+ private _onRemovedIceCandidatePair(candidatePair: ObservedIceCandidatePair) {
338
+ this.onRemovedIceCandidatePair?.(candidatePair, this.context);
339
+ }
340
+
341
+ private _onAddedMediaCodec(codec: ObservedCodec) {
342
+ this.onAddedMediaCodec?.(codec, this.context);
343
+ }
344
+
345
+ private _onRemovedMediaCodec(codec: ObservedCodec) {
346
+ this.onRemovedMediaCodec?.(codec, this.context);
347
+ }
348
+
349
+ private _onAddedMediaPlayout(mediaPlayout: ObservedMediaPlayout) {
350
+ this.onAddedMediaPlayout?.(mediaPlayout, this.context);
351
+ }
352
+
353
+ private _onRemovedMediaPlayout(mediaPlayout: ObservedMediaPlayout) {
354
+ this.onRemovedMediaPlayout?.(mediaPlayout, this.context);
355
+ }
356
+
357
+ private _onMediaSourceAdded(mediaSource: ObservedMediaSource) {
358
+ this.onMediaSourceAdded?.(mediaSource, this.context);
359
+ }
360
+
361
+ private _onMediaSourceRemoved(mediaSource: ObservedMediaSource) {
362
+ this.onMediaSourceRemoved?.(mediaSource, this.context);
363
+ }
364
+
365
+ private _onClientIssue(observedClent: ObservedClient, issue: ClientIssue) {
366
+ this.onClientIssue?.(observedClent, issue, this.context);
367
+ }
368
+
369
+ private _onClientMetadata(observedClient: ObservedClient, metadata: ClientMetaData) {
370
+ this.onClientMetadata?.(observedClient, metadata, this.context);
371
+ }
372
+
373
+ private _onClientExtensionStats(observedClient: ObservedClient, extensionStats: ExtensionStat) {
374
+ this.onClientExtensionStats?.(observedClient, extensionStats, this.context);
375
+ }
376
+
377
+ private _onClientJoined(observedClient: ObservedClient) {
378
+ this.onClientJoined?.(observedClient, this.context);
379
+ }
380
+
381
+ private _onClientLeft(observedClient: ObservedClient) {
382
+ this.onClientLeft?.(observedClient, this.context);
383
+ }
384
+
385
+ private _onUserMediaError(observedClient: ObservedClient, error: string) {
386
+ this.onClientUserMediaError?.(observedClient, error, this.context);
387
+ }
388
+
389
+ private _onUsingTurn(observedClient: ObservedClient, usingTurn: boolean) {
390
+ this.onClientUsingTurn?.(observedClient, usingTurn, this.context);
391
+ }
392
+ }