@observertc/observer-js 1.0.1-4daea92.0 → 1.0.1-5a1b94b.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 (144) hide show
  1. package/README.md +535 -1
  2. package/lib/ObservedCall.d.ts +18 -2
  3. package/lib/ObservedCall.d.ts.map +1 -1
  4. package/lib/ObservedCall.js +65 -11
  5. package/lib/ObservedCallEventMonitor.d.ts +14 -13
  6. package/lib/ObservedCallEventMonitor.d.ts.map +1 -1
  7. package/lib/ObservedCallEventMonitor.js +3 -1
  8. package/lib/ObservedClient.d.ts +9 -9
  9. package/lib/ObservedClient.d.ts.map +1 -1
  10. package/lib/ObservedClient.js +181 -15
  11. package/lib/ObservedClientEventMonitor.d.ts +54 -52
  12. package/lib/ObservedClientEventMonitor.d.ts.map +1 -1
  13. package/lib/ObservedClientEventMonitor.js +7 -0
  14. package/lib/ObservedTURN.d.ts +1 -1
  15. package/lib/ObservedTURN.d.ts.map +1 -1
  16. package/lib/ObservedTURN.js +1 -0
  17. package/lib/ObservedTurnServer.d.ts +2 -2
  18. package/lib/ObservedTurnServer.d.ts.map +1 -1
  19. package/lib/Observer.d.ts +6 -5
  20. package/lib/Observer.d.ts.map +1 -1
  21. package/lib/Observer.js +13 -20
  22. package/lib/ObserverEventMonitor.d.ts +45 -13
  23. package/lib/ObserverEventMonitor.d.ts.map +1 -1
  24. package/lib/ObserverEventMonitor.js +114 -1
  25. package/lib/common/ObserverSummary.d.ts.map +1 -0
  26. package/lib/common/types.d.ts +20 -0
  27. package/lib/common/types.d.ts.map +1 -1
  28. package/lib/index.d.ts +17 -17
  29. package/lib/index.d.ts.map +1 -1
  30. package/lib/index.js +16 -16
  31. package/lib/mediasoup/ObservedMediasoupRouter.d.ts +7 -0
  32. package/lib/mediasoup/ObservedMediasoupRouter.d.ts.map +1 -0
  33. package/lib/mediasoup/ObservedMediasoupRouter.js +12 -0
  34. package/lib/schema/ClientEventTypes.d.ts +147 -79
  35. package/lib/schema/ClientEventTypes.d.ts.map +1 -1
  36. package/lib/schema/ClientEventTypes.js +5 -2
  37. package/lib/schema/ClientSample.d.ts +1 -1
  38. package/lib/schema/ClientSample.d.ts.map +1 -1
  39. package/lib/updaters/OnAnyCallObserverUpdater.d.ts.map +1 -1
  40. package/lib/utils/MediasoupRemoteTrackResolver.d.ts +2 -2
  41. package/lib/utils/MediasoupRemoteTrackResolver.d.ts.map +1 -1
  42. package/lib/utils/RemoteTrackResolver.d.ts +2 -2
  43. package/lib/utils/RemoteTrackResolver.d.ts.map +1 -1
  44. package/lib/{ObservedCertificate.d.ts → webrtc/ObservedCertificate.d.ts} +1 -1
  45. package/lib/webrtc/ObservedCertificate.d.ts.map +1 -0
  46. package/lib/{ObservedCodec.d.ts → webrtc/ObservedCodec.d.ts} +1 -1
  47. package/lib/webrtc/ObservedCodec.d.ts.map +1 -0
  48. package/lib/{ObservedDataChannel.d.ts → webrtc/ObservedDataChannel.d.ts} +1 -1
  49. package/lib/webrtc/ObservedDataChannel.d.ts.map +1 -0
  50. package/lib/{ObservedIceCandidate.d.ts → webrtc/ObservedIceCandidate.d.ts} +1 -1
  51. package/lib/webrtc/ObservedIceCandidate.d.ts.map +1 -0
  52. package/lib/{ObservedIceCandidatePair.d.ts → webrtc/ObservedIceCandidatePair.d.ts} +3 -2
  53. package/lib/webrtc/ObservedIceCandidatePair.d.ts.map +1 -0
  54. package/lib/{ObservedIceCandidatePair.js → webrtc/ObservedIceCandidatePair.js} +17 -1
  55. package/lib/{ObservedIceTransport.d.ts → webrtc/ObservedIceTransport.d.ts} +1 -1
  56. package/lib/webrtc/ObservedIceTransport.d.ts.map +1 -0
  57. package/lib/{ObservedInboundRtp.d.ts → webrtc/ObservedInboundRtp.d.ts} +2 -2
  58. package/lib/webrtc/ObservedInboundRtp.d.ts.map +1 -0
  59. package/lib/{ObservedInboundTrack.d.ts → webrtc/ObservedInboundTrack.d.ts} +5 -4
  60. package/lib/webrtc/ObservedInboundTrack.d.ts.map +1 -0
  61. package/lib/{ObservedInboundTrack.js → webrtc/ObservedInboundTrack.js} +2 -1
  62. package/lib/{ObservedMediaPlayout.d.ts → webrtc/ObservedMediaPlayout.d.ts} +2 -2
  63. package/lib/webrtc/ObservedMediaPlayout.d.ts.map +1 -0
  64. package/lib/{ObservedMediaSource.d.ts → webrtc/ObservedMediaSource.d.ts} +2 -2
  65. package/lib/webrtc/ObservedMediaSource.d.ts.map +1 -0
  66. package/lib/{ObservedOutboundRtp.d.ts → webrtc/ObservedOutboundRtp.d.ts} +2 -2
  67. package/lib/webrtc/ObservedOutboundRtp.d.ts.map +1 -0
  68. package/lib/{ObservedOutboundTrack.d.ts → webrtc/ObservedOutboundTrack.d.ts} +5 -4
  69. package/lib/webrtc/ObservedOutboundTrack.d.ts.map +1 -0
  70. package/lib/{ObservedOutboundTrack.js → webrtc/ObservedOutboundTrack.js} +2 -1
  71. package/lib/{ObservedPeerConnection.d.ts → webrtc/ObservedPeerConnection.d.ts} +26 -4
  72. package/lib/webrtc/ObservedPeerConnection.d.ts.map +1 -0
  73. package/lib/{ObservedPeerConnection.js → webrtc/ObservedPeerConnection.js} +80 -17
  74. package/lib/{ObservedPeerConnectionTransport.d.ts → webrtc/ObservedPeerConnectionTransport.d.ts} +1 -1
  75. package/lib/webrtc/ObservedPeerConnectionTransport.d.ts.map +1 -0
  76. package/lib/{ObservedRemoteInboundRtp.d.ts → webrtc/ObservedRemoteInboundRtp.d.ts} +2 -2
  77. package/lib/webrtc/ObservedRemoteInboundRtp.d.ts.map +1 -0
  78. package/lib/{ObservedRemoteOutboundRtp.d.ts → webrtc/ObservedRemoteOutboundRtp.d.ts} +2 -2
  79. package/lib/webrtc/ObservedRemoteOutboundRtp.d.ts.map +1 -0
  80. package/package.json +1 -1
  81. package/src/ObservedCall.ts +70 -17
  82. package/src/ObservedCallEventMonitor.ts +17 -14
  83. package/src/ObservedClient.ts +195 -22
  84. package/src/ObservedClientEventMonitor.ts +59 -51
  85. package/src/ObservedTURN.ts +2 -1
  86. package/src/ObservedTurnServer.ts +2 -2
  87. package/src/Observer.ts +22 -27
  88. package/src/ObserverEventMonitor.ts +167 -14
  89. package/src/common/types.ts +20 -1
  90. package/src/index.ts +18 -19
  91. package/src/mediasoup/ObservedMediasoupRouter.ts +12 -0
  92. package/src/schema/ClientEventTypes.ts +187 -83
  93. package/src/schema/ClientSample.ts +1 -1
  94. package/src/updaters/OnAnyCallObserverUpdater.ts +1 -1
  95. package/src/utils/MediasoupRemoteTrackResolver.ts +2 -2
  96. package/src/utils/RemoteTrackResolver.ts +2 -2
  97. package/src/{ObservedCertificate.ts → webrtc/ObservedCertificate.ts} +1 -1
  98. package/src/{ObservedCodec.ts → webrtc/ObservedCodec.ts} +1 -1
  99. package/src/{ObservedDataChannel.ts → webrtc/ObservedDataChannel.ts} +1 -1
  100. package/src/{ObservedIceCandidate.ts → webrtc/ObservedIceCandidate.ts} +1 -1
  101. package/src/{ObservedIceCandidatePair.ts → webrtc/ObservedIceCandidatePair.ts} +19 -3
  102. package/src/{ObservedIceTransport.ts → webrtc/ObservedIceTransport.ts} +1 -1
  103. package/src/{ObservedInboundRtp.ts → webrtc/ObservedInboundRtp.ts} +2 -2
  104. package/src/{ObservedInboundTrack.ts → webrtc/ObservedInboundTrack.ts} +6 -4
  105. package/src/{ObservedMediaPlayout.ts → webrtc/ObservedMediaPlayout.ts} +2 -2
  106. package/src/{ObservedMediaSource.ts → webrtc/ObservedMediaSource.ts} +2 -2
  107. package/src/{ObservedOutboundRtp.ts → webrtc/ObservedOutboundRtp.ts} +2 -2
  108. package/src/{ObservedOutboundTrack.ts → webrtc/ObservedOutboundTrack.ts} +6 -4
  109. package/src/{ObservedPeerConnection.ts → webrtc/ObservedPeerConnection.ts} +122 -37
  110. package/src/{ObservedPeerConnectionTransport.ts → webrtc/ObservedPeerConnectionTransport.ts} +1 -1
  111. package/src/{ObservedRemoteInboundRtp.ts → webrtc/ObservedRemoteInboundRtp.ts} +2 -2
  112. package/src/{ObservedRemoteOutboundRtp.ts → webrtc/ObservedRemoteOutboundRtp.ts} +2 -2
  113. package/lib/ObservedCertificate.d.ts.map +0 -1
  114. package/lib/ObservedCodec.d.ts.map +0 -1
  115. package/lib/ObservedDataChannel.d.ts.map +0 -1
  116. package/lib/ObservedIceCandidate.d.ts.map +0 -1
  117. package/lib/ObservedIceCandidatePair.d.ts.map +0 -1
  118. package/lib/ObservedIceTransport.d.ts.map +0 -1
  119. package/lib/ObservedInboundRtp.d.ts.map +0 -1
  120. package/lib/ObservedInboundTrack.d.ts.map +0 -1
  121. package/lib/ObservedMediaPlayout.d.ts.map +0 -1
  122. package/lib/ObservedMediaSource.d.ts.map +0 -1
  123. package/lib/ObservedOutboundRtp.d.ts.map +0 -1
  124. package/lib/ObservedOutboundTrack.d.ts.map +0 -1
  125. package/lib/ObservedPeerConnection.d.ts.map +0 -1
  126. package/lib/ObservedPeerConnectionTransport.d.ts.map +0 -1
  127. package/lib/ObservedRemoteInboundRtp.d.ts.map +0 -1
  128. package/lib/ObservedRemoteOutboundRtp.d.ts.map +0 -1
  129. package/lib/ObserverSummary.d.ts.map +0 -1
  130. /package/lib/{ObserverSummary.d.ts → common/ObserverSummary.d.ts} +0 -0
  131. /package/lib/{ObserverSummary.js → common/ObserverSummary.js} +0 -0
  132. /package/lib/{ObservedCertificate.js → webrtc/ObservedCertificate.js} +0 -0
  133. /package/lib/{ObservedCodec.js → webrtc/ObservedCodec.js} +0 -0
  134. /package/lib/{ObservedDataChannel.js → webrtc/ObservedDataChannel.js} +0 -0
  135. /package/lib/{ObservedIceCandidate.js → webrtc/ObservedIceCandidate.js} +0 -0
  136. /package/lib/{ObservedIceTransport.js → webrtc/ObservedIceTransport.js} +0 -0
  137. /package/lib/{ObservedInboundRtp.js → webrtc/ObservedInboundRtp.js} +0 -0
  138. /package/lib/{ObservedMediaPlayout.js → webrtc/ObservedMediaPlayout.js} +0 -0
  139. /package/lib/{ObservedMediaSource.js → webrtc/ObservedMediaSource.js} +0 -0
  140. /package/lib/{ObservedOutboundRtp.js → webrtc/ObservedOutboundRtp.js} +0 -0
  141. /package/lib/{ObservedPeerConnectionTransport.js → webrtc/ObservedPeerConnectionTransport.js} +0 -0
  142. /package/lib/{ObservedRemoteInboundRtp.js → webrtc/ObservedRemoteInboundRtp.js} +0 -0
  143. /package/lib/{ObservedRemoteOutboundRtp.js → webrtc/ObservedRemoteOutboundRtp.js} +0 -0
  144. /package/src/{ObserverSummary.ts → common/ObserverSummary.ts} +0 -0
@@ -1,23 +1,23 @@
1
- import { ObservedCertificate } from './ObservedCertificate';
2
- import { ObservedClient } from './ObservedClient';
3
- import { ObservedCodec } from './ObservedCodec';
4
- import { ObservedDataChannel } from './ObservedDataChannel';
5
- import { ObservedIceCandidate } from './ObservedIceCandidate';
6
- import { ObservedIceCandidatePair } from './ObservedIceCandidatePair';
7
- import { ObservedIceTransport } from './ObservedIceTransport';
8
- import { ObservedInboundRtp } from './ObservedInboundRtp';
9
- import { ObservedInboundTrack } from './ObservedInboundTrack';
10
- import { ObservedMediaPlayout } from './ObservedMediaPlayout';
11
- import { ObservedMediaSource } from './ObservedMediaSource';
12
- import { ObservedOutboundRtp } from './ObservedOutboundRtp';
13
- import { ObservedOutboundTrack } from './ObservedOutboundTrack';
14
- import { ObservedPeerConnection } from './ObservedPeerConnection';
1
+ import { ObservedCertificate } from './webrtc/ObservedCertificate';
2
+ import { ObservedClient, ObservedClientEvents } from './ObservedClient';
3
+ import { ObservedCodec } from './webrtc/ObservedCodec';
4
+ import { ObservedDataChannel } from './webrtc/ObservedDataChannel';
5
+ import { ObservedIceCandidate } from './webrtc/ObservedIceCandidate';
6
+ import { ObservedIceCandidatePair } from './webrtc/ObservedIceCandidatePair';
7
+ import { ObservedIceTransport } from './webrtc/ObservedIceTransport';
8
+ import { ObservedInboundRtp } from './webrtc/ObservedInboundRtp';
9
+ import { ObservedInboundTrack } from './webrtc/ObservedInboundTrack';
10
+ import { ObservedMediaPlayout } from './webrtc/ObservedMediaPlayout';
11
+ import { ObservedMediaSource } from './webrtc/ObservedMediaSource';
12
+ import { ObservedOutboundRtp } from './webrtc/ObservedOutboundRtp';
13
+ import { ObservedOutboundTrack } from './webrtc/ObservedOutboundTrack';
14
+ import { ObservedPeerConnection } from './webrtc/ObservedPeerConnection';
15
15
  import { ClientIssue, ClientMetaData, ExtensionStat } from './schema/ClientSample';
16
16
 
17
- export class ObservedClientEventMonitor<Context> {
17
+ export class ObservedClientEventMonitor<AppContext, ClientAppData extends Record<string, unknown> = Record<string, unknown>> {
18
18
  public constructor(
19
- public readonly observedClient: ObservedClient,
20
- public readonly context: Context,
19
+ public readonly observedClient: ObservedClient<ClientAppData>,
20
+ public readonly context: AppContext,
21
21
  ) {
22
22
  this._onPeerConnconnectionAdded = this._onPeerConnconnectionAdded.bind(this);
23
23
  this._onPeerConnectionRemoved = this._onPeerConnectionRemoved.bind(this);
@@ -52,6 +52,8 @@ export class ObservedClientEventMonitor<Context> {
52
52
  this._onClientLeft = this._onClientLeft.bind(this);
53
53
  this._onUserMediaError = this._onUserMediaError.bind(this);
54
54
  this._onUsingTurn = this._onUsingTurn.bind(this);
55
+ this._onClientUpdated = this._onClientUpdated.bind(this);
56
+ this._onClientExtensionStats = this._onClientExtensionStats.bind(this);
55
57
 
56
58
  this.observedClient.on('newpeerconnection', this._onPeerConnconnectionAdded);
57
59
  this.observedClient.on('issue', this._onClientIssue);
@@ -61,11 +63,17 @@ export class ObservedClientEventMonitor<Context> {
61
63
  this.observedClient.on('rejoined', this._onClientJoined);
62
64
  this.observedClient.on('usermediaerror', this._onUserMediaError);
63
65
  this.observedClient.on('usingturn', this._onUsingTurn);
66
+ this.observedClient.on('update', this._onClientUpdated);
64
67
 
65
68
  this.observedClient.once('close', this._onClientClosed);
66
69
  }
67
70
 
68
- public onClientClosed?: (client: ObservedClient, ctx: Context) => void;
71
+ public onClientUpdated?: (client: ObservedClient, event: ObservedClientEvents['update'][0], ctx: AppContext) => void;
72
+ private _onClientUpdated(...args: ObservedClientEvents['update']) {
73
+ this.onClientUpdated?.(this.observedClient, args[0], this.context);
74
+ }
75
+
76
+ public onClientClosed?: (client: ObservedClient, ctx: AppContext) => void;
69
77
  private _onClientClosed() {
70
78
  this.onClientClosed?.(this.observedClient, this.context);
71
79
 
@@ -80,7 +88,7 @@ export class ObservedClientEventMonitor<Context> {
80
88
 
81
89
  }
82
90
 
83
- public onPeerConnectionAdded?: (peerConnection: ObservedPeerConnection, ctx: Context) => void;
91
+ public onPeerConnectionAdded?: (peerConnection: ObservedPeerConnection, ctx: AppContext) => void;
84
92
  private _onPeerConnconnectionAdded(peerConnection: ObservedPeerConnection) {
85
93
  this.onPeerConnectionAdded?.(peerConnection, this.context);
86
94
 
@@ -113,7 +121,7 @@ export class ObservedClientEventMonitor<Context> {
113
121
 
114
122
  }
115
123
 
116
- public onPeerConnectionRemoved?: (peerConnection: ObservedPeerConnection, ctx: Context) => void;
124
+ public onPeerConnectionRemoved?: (peerConnection: ObservedPeerConnection, ctx: AppContext) => void;
117
125
  private _onPeerConnectionRemoved(peerConnection: ObservedPeerConnection) {
118
126
  this.onPeerConnectionRemoved?.(peerConnection, this.context);
119
127
 
@@ -144,157 +152,157 @@ export class ObservedClientEventMonitor<Context> {
144
152
 
145
153
  }
146
154
 
147
- public onCertificateAdded?: (certificate: ObservedCertificate, ctx: Context) => void;
155
+ public onCertificateAdded?: (certificate: ObservedCertificate, ctx: AppContext) => void;
148
156
  private _onCertificateAdded(certificate: ObservedCertificate) {
149
157
  this.onCertificateAdded?.(certificate, this.context);
150
158
  }
151
159
 
152
- public onCertificateRemoved?: (certificate: ObservedCertificate, ctx: Context) => void;
160
+ public onCertificateRemoved?: (certificate: ObservedCertificate, ctx: AppContext) => void;
153
161
  private _onCertificateRemoved(certificate: ObservedCertificate) {
154
162
  this.onCertificateRemoved?.(certificate, this.context);
155
163
  }
156
164
 
157
- public onInboundTrackAdded?: (inboundTrack: ObservedInboundTrack, ctx: Context) => void;
165
+ public onInboundTrackAdded?: (inboundTrack: ObservedInboundTrack, ctx: AppContext) => void;
158
166
  private _onInboundTrackAdded(inboundTrack: ObservedInboundTrack) {
159
167
  this.onInboundTrackAdded?.(inboundTrack, this.context);
160
168
  }
161
169
 
162
- public onInboundTrackRemoved?: (inboundTrack: ObservedInboundTrack, ctx: Context) => void;
170
+ public onInboundTrackRemoved?: (inboundTrack: ObservedInboundTrack, ctx: AppContext) => void;
163
171
  private _onInboundTrackRemoved(inboundTrack: ObservedInboundTrack) {
164
172
  this.onInboundTrackRemoved?.(inboundTrack, this.context);
165
173
  }
166
174
 
167
- public onOutboundTrackAdded?: (outboundTrack: ObservedOutboundTrack, ctx: Context) => void;
175
+ public onOutboundTrackAdded?: (outboundTrack: ObservedOutboundTrack, ctx: AppContext) => void;
168
176
  private _onOutboundTrackAdded(outboundTrack: ObservedOutboundTrack) {
169
177
  this.onOutboundTrackAdded?.(outboundTrack, this.context);
170
178
  }
171
179
 
172
- public onOutboundTrackRemoved?: (outboundTrack: ObservedOutboundTrack, ctx: Context) => void;
180
+ public onOutboundTrackRemoved?: (outboundTrack: ObservedOutboundTrack, ctx: AppContext) => void;
173
181
  private _onOutboundTrackRemoved(outboundTrack: ObservedOutboundTrack) {
174
182
  this.onOutboundTrackRemoved?.(outboundTrack, this.context);
175
183
  }
176
184
 
177
- public onInboundRtpAdded?: (inboundRtp: ObservedInboundRtp, ctx: Context) => void;
185
+ public onInboundRtpAdded?: (inboundRtp: ObservedInboundRtp, ctx: AppContext) => void;
178
186
  private _onInboundRtpAdded(inboundRtp: ObservedInboundRtp) {
179
187
  this.onInboundRtpAdded?.(inboundRtp, this.context);
180
188
  }
181
189
 
182
- public onInboundRtpRemoved?: (inboundRtp: ObservedInboundRtp, ctx: Context) => void;
190
+ public onInboundRtpRemoved?: (inboundRtp: ObservedInboundRtp, ctx: AppContext) => void;
183
191
  private _onInboundRtpRemoved(inboundRtp: ObservedInboundRtp) {
184
192
  this.onInboundRtpRemoved?.(inboundRtp, this.context);
185
193
  }
186
194
 
187
- public onOutboundRtpAdded?: (outboundRtp: ObservedOutboundRtp, ctx: Context) => void;
195
+ public onOutboundRtpAdded?: (outboundRtp: ObservedOutboundRtp, ctx: AppContext) => void;
188
196
  private _onOutboundRtpAdded(outboundRtp: ObservedOutboundRtp) {
189
197
  this.onOutboundRtpAdded?.(outboundRtp, this.context);
190
198
  }
191
199
 
192
- public onOutboundRtpRemoved?: (outboundRtp: ObservedOutboundRtp, ctx: Context) => void;
200
+ public onOutboundRtpRemoved?: (outboundRtp: ObservedOutboundRtp, ctx: AppContext) => void;
193
201
  private _onOutboundRtpRemoved(outboundRtp: ObservedOutboundRtp) {
194
202
  this.onOutboundRtpRemoved?.(outboundRtp, this.context);
195
203
  }
196
204
 
197
- public onDataChannelAdded?: (dataChannel: ObservedDataChannel, ctx: Context) => void;
205
+ public onDataChannelAdded?: (dataChannel: ObservedDataChannel, ctx: AppContext) => void;
198
206
  private _onDataChannelAdded(dataChannel: ObservedDataChannel) {
199
207
  this.onDataChannelAdded?.(dataChannel, this.context);
200
208
  }
201
209
 
202
- public onDataChannelRemoved?: (dataChannel: ObservedDataChannel, ctx: Context) => void;
210
+ public onDataChannelRemoved?: (dataChannel: ObservedDataChannel, ctx: AppContext) => void;
203
211
  private _onDataChannelRemoved(dataChannel: ObservedDataChannel) {
204
212
  this.onDataChannelRemoved?.(dataChannel, this.context);
205
213
  }
206
214
 
207
- public onAddedIceTransport?: (iceTransport: ObservedIceTransport, ctx: Context) => void;
215
+ public onAddedIceTransport?: (iceTransport: ObservedIceTransport, ctx: AppContext) => void;
208
216
  private _onAddedIceTransport(iceTransport: ObservedIceTransport) {
209
217
  this.onAddedIceTransport?.(iceTransport, this.context);
210
218
  }
211
219
 
212
- public onRemovedIceTransport?: (iceTransport: ObservedIceTransport, ctx: Context) => void;
220
+ public onRemovedIceTransport?: (iceTransport: ObservedIceTransport, ctx: AppContext) => void;
213
221
  private _onRemovedIceTransport(iceTransport: ObservedIceTransport) {
214
222
  this.onRemovedIceTransport?.(iceTransport, this.context);
215
223
  }
216
224
 
217
- public onIceCandidateAdded?: (iceCandidate: ObservedIceCandidate, ctx: Context) => void;
225
+ public onIceCandidateAdded?: (iceCandidate: ObservedIceCandidate, ctx: AppContext) => void;
218
226
  private _onIceCandidateAdded(iceCandidate: ObservedIceCandidate) {
219
227
  this.onIceCandidateAdded?.(iceCandidate, this.context);
220
228
  }
221
229
 
222
- public onIceCandidateRemoved?: (iceCandidate: ObservedIceCandidate, ctx: Context) => void;
230
+ public onIceCandidateRemoved?: (iceCandidate: ObservedIceCandidate, ctx: AppContext) => void;
223
231
  private _onIceCandidateRemoved(iceCandidate: ObservedIceCandidate) {
224
232
  this.onIceCandidateRemoved?.(iceCandidate, this.context);
225
233
  }
226
234
 
227
- public onAddedIceCandidatePair?: (candidatePair: ObservedIceCandidatePair, ctx: Context) => void;
235
+ public onAddedIceCandidatePair?: (candidatePair: ObservedIceCandidatePair, ctx: AppContext) => void;
228
236
  private _onAddedIceCandidatePair(candidatePair: ObservedIceCandidatePair) {
229
237
  this.onAddedIceCandidatePair?.(candidatePair, this.context);
230
238
  }
231
239
 
232
- public onRemovedIceCandidatePair?: (candidatePair: ObservedIceCandidatePair, ctx: Context) => void;
240
+ public onRemovedIceCandidatePair?: (candidatePair: ObservedIceCandidatePair, ctx: AppContext) => void;
233
241
  private _onRemovedIceCandidatePair(candidatePair: ObservedIceCandidatePair) {
234
242
  this.onRemovedIceCandidatePair?.(candidatePair, this.context);
235
243
  }
236
244
 
237
- public onAddedMediaCodec?: (codec: ObservedCodec, ctx: Context) => void;
245
+ public onAddedMediaCodec?: (codec: ObservedCodec, ctx: AppContext) => void;
238
246
  private _onAddedMediaCodec(codec: ObservedCodec) {
239
247
  this.onAddedMediaCodec?.(codec, this.context);
240
248
  }
241
249
 
242
- public onRemovedMediaCodec?: (codec: ObservedCodec, ctx: Context) => void;
250
+ public onRemovedMediaCodec?: (codec: ObservedCodec, ctx: AppContext) => void;
243
251
  private _onRemovedMediaCodec(codec: ObservedCodec) {
244
252
  this.onRemovedMediaCodec?.(codec, this.context);
245
253
  }
246
254
 
247
- public onAddedMediaPlayout?: (mediaPlayout: ObservedMediaPlayout, ctx: Context) => void;
255
+ public onAddedMediaPlayout?: (mediaPlayout: ObservedMediaPlayout, ctx: AppContext) => void;
248
256
  private _onAddedMediaPlayout(mediaPlayout: ObservedMediaPlayout) {
249
257
  this.onAddedMediaPlayout?.(mediaPlayout, this.context);
250
258
  }
251
259
 
252
- public onRemovedMediaPlayout?: (mediaPlayout: ObservedMediaPlayout, ctx: Context) => void;
260
+ public onRemovedMediaPlayout?: (mediaPlayout: ObservedMediaPlayout, ctx: AppContext) => void;
253
261
  private _onRemovedMediaPlayout(mediaPlayout: ObservedMediaPlayout) {
254
262
  this.onRemovedMediaPlayout?.(mediaPlayout, this.context);
255
263
  }
256
264
 
257
- public onMediaSourceAdded?: (mediaSource: ObservedMediaSource, ctx: Context) => void;
265
+ public onMediaSourceAdded?: (mediaSource: ObservedMediaSource, ctx: AppContext) => void;
258
266
  private _onMediaSourceAdded(mediaSource: ObservedMediaSource) {
259
267
  this.onMediaSourceAdded?.(mediaSource, this.context);
260
268
  }
261
269
 
262
- public onMediaSourceRemoved?: (mediaSource: ObservedMediaSource, ctx: Context) => void;
270
+ public onMediaSourceRemoved?: (mediaSource: ObservedMediaSource, ctx: AppContext) => void;
263
271
  private _onMediaSourceRemoved(mediaSource: ObservedMediaSource) {
264
272
  this.onMediaSourceRemoved?.(mediaSource, this.context);
265
273
  }
266
274
 
267
- public onClientIssue?: (issue: ClientIssue, ctx: Context) => void;
275
+ public onClientIssue?: (issue: ClientIssue, ctx: AppContext) => void;
268
276
  private _onClientIssue(issue: ClientIssue) {
269
277
  this.onClientIssue?.(issue, this.context);
270
278
  }
271
279
 
272
- public onClientMetadata?: (metadata: ClientMetaData, ctx: Context) => void;
280
+ public onClientMetadata?: (metadata: ClientMetaData, ctx: AppContext) => void;
273
281
  private _onClientMetadata(metadata: ClientMetaData) {
274
282
  this.onClientMetadata?.(metadata, this.context);
275
283
  }
276
284
 
277
- public onClientExtensionStats?: (extensionStats: ExtensionStat, ctx: Context) => void;
285
+ public onClientExtensionStats?: (extensionStats: ExtensionStat, ctx: AppContext) => void;
278
286
  private _onClientExtensionStats(extensionStats: ExtensionStat) {
279
287
  this.onClientExtensionStats?.(extensionStats, this.context);
280
288
  }
281
289
 
282
- public onClientJoined?: (client: ObservedClient, ctx: Context) => void;
290
+ public onClientJoined?: (client: ObservedClient, ctx: AppContext) => void;
283
291
  private _onClientJoined() {
284
292
  this.onClientJoined?.(this.observedClient, this.context);
285
293
  }
286
294
 
287
- public onClientLeft?: (client: ObservedClient, ctx: Context) => void;
295
+ public onClientLeft?: (client: ObservedClient, ctx: AppContext) => void;
288
296
  private _onClientLeft() {
289
297
  this.onClientLeft?.(this.observedClient, this.context);
290
298
  }
291
299
 
292
- public onUserMediaError?: (error: string, observedClient: ObservedClient, ctx: Context) => void;
300
+ public onUserMediaError?: (error: string, observedClient: ObservedClient, ctx: AppContext) => void;
293
301
  private _onUserMediaError(error: string) {
294
302
  this.onUserMediaError?.(error, this.observedClient, this.context);
295
303
  }
296
304
 
297
- public onUsingTurn?: (client: ObservedClient, ctx: Context) => void;
305
+ public onUsingTurn?: (client: ObservedClient, ctx: AppContext) => void;
298
306
  private _onUsingTurn() {
299
307
  this.onUsingTurn?.(this.observedClient, this.context);
300
308
  }
@@ -1,5 +1,5 @@
1
1
  import { EventEmitter } from 'stream';
2
- import { ObservedPeerConnection } from './ObservedPeerConnection';
2
+ import { ObservedPeerConnection } from './webrtc/ObservedPeerConnection';
3
3
  import { ObservedTurnServer } from './ObservedTurnServer';
4
4
  import { createLogger } from './common/logger';
5
5
 
@@ -34,6 +34,7 @@ export class ObservedTURN extends EventEmitter {
34
34
  public constructor(
35
35
  ) {
36
36
  super();
37
+ this.setMaxListeners(Infinity);
37
38
  }
38
39
 
39
40
  public update() {
@@ -1,5 +1,5 @@
1
- import { ObservedIceCandidatePair } from './ObservedIceCandidatePair';
2
- import { ObservedPeerConnection } from './ObservedPeerConnection';
1
+ import { ObservedIceCandidatePair } from './webrtc/ObservedIceCandidatePair';
2
+ import { ObservedPeerConnection } from './webrtc/ObservedPeerConnection';
3
3
  import { ObservedTURN } from './ObservedTURN';
4
4
 
5
5
  export class ObservedTurnServer {
package/src/Observer.ts CHANGED
@@ -17,19 +17,20 @@ const logger = createLogger('Observer');
17
17
  export type ObserverEvents = {
18
18
  'client-event': [ObservedClient, ClientEvent];
19
19
  'call-updated': [ObservedCall],
20
- 'client-issue': [ObservedClient, ClientIssue],
21
- 'client-metadata': [ObservedClient, ClientMetaData],
22
- 'client-extension-stats': [ObservedClient, ExtensionStat],
20
+ 'client-issue': [ObservedClient, ClientIssue];
21
+ 'client-metadata': [ObservedClient, ClientMetaData];
22
+ 'client-extension-stats': [ObservedClient, ExtensionStat];
23
23
  'newcall': [ObservedCall],
24
24
  'update': [],
25
25
  'close': [],
26
26
  }
27
27
 
28
- export type ObserverConfig = {
28
+ export type ObserverConfig<AppData extends Record<string, unknown> = Record<string, unknown>> = {
29
29
  updatePolicy?: 'update-on-any-call-updated' | 'update-when-all-call-updated' | 'update-on-interval',
30
30
  updateIntervalInMs?: number,
31
31
  defaultCallUpdatePolicy?: ObservedCallSettings['updatePolicy'],
32
32
  defaultCallUpdateIntervalInMs?: number,
33
+ appData?: AppData,
33
34
  }
34
35
 
35
36
  export declare interface Observer {
@@ -39,7 +40,7 @@ export declare interface Observer {
39
40
  emit<U extends keyof ObserverEvents>(event: U, ...args: ObserverEvents[U]): boolean;
40
41
  }
41
42
 
42
- export class Observer extends EventEmitter {
43
+ export class Observer<AppData extends Record<string, unknown> = Record<string, unknown>> extends EventEmitter {
43
44
  public readonly detectors: Detectors;
44
45
 
45
46
  public readonly observedTURN = new ObservedTURN();
@@ -67,49 +68,45 @@ export class Observer extends EventEmitter {
67
68
  return this.observedCalls.size;
68
69
  }
69
70
 
70
- private _timer?: ReturnType<typeof setInterval>;
71
-
72
- public constructor(public readonly config: ObserverConfig = {
71
+ public constructor(public readonly config: ObserverConfig<AppData> = {
73
72
  updatePolicy: 'update-when-all-call-updated',
74
73
  updateIntervalInMs: undefined,
74
+ appData: {} as AppData,
75
75
  }) {
76
76
  super();
77
77
  this.setMaxListeners(Infinity);
78
78
  this.update = this.update.bind(this);
79
79
 
80
- if (this.config.updateIntervalInMs) {
81
- if (this.config.updatePolicy && this.config.updatePolicy !== 'update-on-interval') {
82
- throw new Error('update policy must be update-on-interval if updateIntervalInMs is set in config');
83
- }
84
- this._timer = setInterval(this.update.bind(this), this.config.updateIntervalInMs);
85
- }
80
+ const currentUpdatePolicy = (config?.updatePolicy) ?? 'update-when-all-call-updated';
86
81
 
87
- if (this.config.updateIntervalInMs) {
88
- if (this.config.updatePolicy !== 'update-on-interval') {
89
- throw new Error('updatePolicy must be update-on-interval if updateIntervalInMs is set in config');
90
- }
91
- }
92
- switch (this.config.updatePolicy) {
82
+ switch (currentUpdatePolicy) {
93
83
  case 'update-on-any-call-updated':
94
- this.updater = new OnAllCallObserverUpdater(this);
84
+ this.updater = new OnAnyCallObserverUpdater(this);
95
85
  break;
96
86
  case 'update-when-all-call-updated':
97
- this.updater = new OnAnyCallObserverUpdater(this);
87
+ this.updater = new OnAllCallObserverUpdater(this);
98
88
  break;
99
- case 'update-on-interval':
100
- if (!this.config.updateIntervalInMs) {
89
+ case 'update-on-interval': {
90
+ const interval = config?.updateIntervalInMs;
91
+
92
+ if (!interval) {
101
93
  throw new Error('updateIntervalInMs setting in config must be set if updatePolicy is update-on-interval');
102
94
  }
103
95
  this.updater = new OnIntervalUpdater(
104
- this.config.updateIntervalInMs,
96
+ interval,
105
97
  this.update.bind(this),
106
98
  );
107
99
  break;
100
+ }
108
101
  }
109
102
 
110
103
  this.detectors = new Detectors();
111
104
  }
112
105
 
106
+ public get appData() {
107
+ return this.config.appData;
108
+ }
109
+
113
110
  public getObservedCall<T extends Record<string, unknown> = Record<string, unknown>>(callId: string): ObservedCall<T> | undefined {
114
111
  if (this.closed || !this.observedCalls.has(callId)) return;
115
112
 
@@ -155,8 +152,6 @@ export class Observer extends EventEmitter {
155
152
  return logger.debug('Attempted to close twice');
156
153
  }
157
154
  this.closed = true;
158
- clearInterval(this._timer);
159
- this._timer = undefined;
160
155
 
161
156
  this.observedCalls.forEach((call) => call.close());
162
157