@observertc/observer-js 1.0.1-c3edea3.0 → 1.0.1-ea70eab.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 (140) hide show
  1. package/lib/ObservedCall.d.ts +43 -7
  2. package/lib/ObservedCall.d.ts.map +1 -1
  3. package/lib/ObservedCall.js +129 -13
  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/ObservedCallSummary.d.ts +18 -0
  8. package/lib/ObservedCallSummary.d.ts.map +1 -0
  9. package/lib/ObservedClient.d.ts +70 -11
  10. package/lib/ObservedClient.d.ts.map +1 -1
  11. package/lib/ObservedClient.js +392 -72
  12. package/lib/ObservedClientEventMonitor.d.ts +89 -0
  13. package/lib/ObservedClientEventMonitor.d.ts.map +1 -0
  14. package/lib/ObservedClientEventMonitor.js +247 -0
  15. package/lib/ObservedClientSummary.d.ts +23 -0
  16. package/lib/ObservedClientSummary.d.ts.map +1 -0
  17. package/lib/ObservedClientSummary.js +2 -0
  18. package/lib/ObservedDataChannel.d.ts +6 -0
  19. package/lib/ObservedDataChannel.d.ts.map +1 -1
  20. package/lib/ObservedDataChannel.js +30 -0
  21. package/lib/ObservedIceCandidatePair.d.ts +6 -1
  22. package/lib/ObservedIceCandidatePair.d.ts.map +1 -1
  23. package/lib/ObservedIceCandidatePair.js +45 -1
  24. package/lib/ObservedIceTransport.d.ts +4 -0
  25. package/lib/ObservedIceTransport.d.ts.map +1 -1
  26. package/lib/ObservedIceTransport.js +28 -0
  27. package/lib/ObservedInboundTrack.d.ts +2 -0
  28. package/lib/ObservedInboundTrack.d.ts.map +1 -1
  29. package/lib/ObservedInboundTrack.js +2 -0
  30. package/lib/ObservedOutboundTrack.d.ts +2 -0
  31. package/lib/ObservedOutboundTrack.d.ts.map +1 -1
  32. package/lib/ObservedOutboundTrack.js +2 -0
  33. package/lib/ObservedPeerConnection.d.ts +29 -2
  34. package/lib/ObservedPeerConnection.d.ts.map +1 -1
  35. package/lib/ObservedPeerConnection.js +181 -29
  36. package/lib/ObservedTURN.d.ts +31 -0
  37. package/lib/ObservedTURN.d.ts.map +1 -0
  38. package/lib/ObservedTURN.js +58 -0
  39. package/lib/ObservedTurnServer.d.ts +25 -0
  40. package/lib/ObservedTurnServer.d.ts.map +1 -0
  41. package/lib/ObservedTurnServer.js +59 -0
  42. package/lib/Observer.d.ts +43 -22
  43. package/lib/Observer.d.ts.map +1 -1
  44. package/lib/Observer.js +126 -40
  45. package/lib/ObserverEventMonitor.d.ts +130 -0
  46. package/lib/ObserverEventMonitor.d.ts.map +1 -0
  47. package/lib/ObserverEventMonitor.js +404 -0
  48. package/lib/ObserverSummary.d.ts +13 -0
  49. package/lib/ObserverSummary.d.ts.map +1 -0
  50. package/lib/ObserverSummary.js +2 -0
  51. package/lib/common/utils.d.ts +2 -1
  52. package/lib/common/utils.d.ts.map +1 -1
  53. package/lib/common/utils.js +11 -3
  54. package/lib/index.d.ts +6 -0
  55. package/lib/index.d.ts.map +1 -1
  56. package/lib/index.js +9 -1
  57. package/lib/schema/ClientEventTypes.d.ts +160 -0
  58. package/lib/schema/ClientEventTypes.d.ts.map +1 -0
  59. package/lib/schema/ClientEventTypes.js +38 -0
  60. package/lib/schema/{metaTypes.d.ts → ClientMetaTypes.d.ts} +2 -2
  61. package/lib/schema/ClientMetaTypes.d.ts.map +1 -0
  62. package/lib/schema/ClientMetaTypes.js +16 -0
  63. package/lib/schema/ClientSample.d.ts +1 -1
  64. package/lib/schema/ClientSample.d.ts.map +1 -1
  65. package/lib/updaters/CallUpdater.d.ts.map +1 -0
  66. package/lib/updaters/CallUpdater.js +2 -0
  67. package/lib/updaters/ObserverUpdater.d.ts +5 -0
  68. package/lib/updaters/ObserverUpdater.d.ts.map +1 -0
  69. package/lib/updaters/ObserverUpdater.js +2 -0
  70. package/lib/updaters/OnAllCallObserverUpdater.d.ts +15 -0
  71. package/lib/updaters/OnAllCallObserverUpdater.d.ts.map +1 -0
  72. package/lib/updaters/OnAllCallObserverUpdater.js +50 -0
  73. package/lib/updaters/OnAllClientCallUpdater.d.ts +15 -0
  74. package/lib/updaters/OnAllClientCallUpdater.d.ts.map +1 -0
  75. package/lib/updaters/OnAllClientCallUpdater.js +53 -0
  76. package/lib/updaters/OnAnyCallObserverUpdater.d.ts +12 -0
  77. package/lib/updaters/OnAnyCallObserverUpdater.d.ts.map +1 -0
  78. package/lib/updaters/OnAnyCallObserverUpdater.js +37 -0
  79. package/lib/updaters/OnAnyClientCallUpdater.d.ts +12 -0
  80. package/lib/updaters/OnAnyClientCallUpdater.d.ts.map +1 -0
  81. package/lib/updaters/OnAnyClientCallUpdater.js +36 -0
  82. package/lib/updaters/OnIntervalUpdater.d.ts +10 -0
  83. package/lib/updaters/OnIntervalUpdater.d.ts.map +1 -0
  84. package/lib/updaters/OnIntervalUpdater.js +17 -0
  85. package/lib/updaters/Updater.d.ts +6 -0
  86. package/lib/updaters/Updater.d.ts.map +1 -0
  87. package/lib/updaters/Updater.js +2 -0
  88. package/lib/utils/MediasoupRemoteTrackResolver.d.ts +25 -0
  89. package/lib/utils/MediasoupRemoteTrackResolver.d.ts.map +1 -0
  90. package/lib/utils/MediasoupRemoteTrackResolver.js +110 -0
  91. package/package.json +1 -1
  92. package/src/ObservedCall.ts +210 -16
  93. package/src/ObservedCallEventMonitor.ts +392 -0
  94. package/src/ObservedCallSummary.ts +22 -0
  95. package/src/ObservedClient.ts +490 -79
  96. package/src/ObservedClientEventMonitor.ts +301 -0
  97. package/src/ObservedClientSummary.ts +24 -0
  98. package/src/ObservedDataChannel.ts +32 -0
  99. package/src/ObservedIceCandidatePair.ts +44 -2
  100. package/src/ObservedIceTransport.ts +29 -0
  101. package/src/ObservedInboundTrack.ts +3 -0
  102. package/src/ObservedOutboundTrack.ts +3 -0
  103. package/src/ObservedPeerConnection.ts +210 -46
  104. package/src/ObservedTURN.ts +86 -0
  105. package/src/ObservedTurnServer.ts +72 -0
  106. package/src/Observer.ts +179 -64
  107. package/src/ObserverEventMonitor.ts +518 -0
  108. package/src/ObserverSummary.ts +15 -0
  109. package/src/common/utils.ts +12 -2
  110. package/src/index.ts +6 -0
  111. package/src/schema/ClientEventTypes.ts +176 -0
  112. package/src/schema/{metaTypes.ts → ClientMetaTypes.ts} +1 -1
  113. package/src/schema/ClientSample.ts +1 -1
  114. package/src/updaters/ObserverUpdater.ts +5 -0
  115. package/src/updaters/OnAllCallObserverUpdater.ts +59 -0
  116. package/src/updaters/OnAllClientCallUpdater.ts +61 -0
  117. package/src/updaters/OnAnyCallObserverUpdater.ts +41 -0
  118. package/src/updaters/OnAnyClientCallUpdater.ts +39 -0
  119. package/src/updaters/OnIntervalUpdater.ts +19 -0
  120. package/src/updaters/Updater.ts +5 -0
  121. package/src/utils/MediasoupRemoteTrackResolver.ts +155 -0
  122. package/tsconfig.json +1 -1
  123. package/lib/schema/eventTypes.d.ts +0 -33
  124. package/lib/schema/eventTypes.d.ts.map +0 -1
  125. package/lib/schema/eventTypes.js +0 -38
  126. package/lib/schema/metaTypes.d.ts.map +0 -1
  127. package/lib/schema/metaTypes.js +0 -16
  128. package/lib/utils/CallUpdater.d.ts.map +0 -1
  129. package/lib/utils/OnAllClientCallUpdater.d.ts +0 -16
  130. package/lib/utils/OnAllClientCallUpdater.d.ts.map +0 -1
  131. package/lib/utils/OnAllClientCallUpdater.js +0 -58
  132. package/lib/utils/onAnyClientCallUpdater.d.ts +0 -14
  133. package/lib/utils/onAnyClientCallUpdater.d.ts.map +0 -1
  134. package/lib/utils/onAnyClientCallUpdater.js +0 -51
  135. package/src/schema/eventTypes.ts +0 -36
  136. package/src/utils/OnAllClientCallUpdater.ts +0 -68
  137. package/src/utils/onAnyClientCallUpdater.ts +0 -59
  138. /package/lib/{utils/CallUpdater.js → ObservedCallSummary.js} +0 -0
  139. /package/lib/{utils → updaters}/CallUpdater.d.ts +0 -0
  140. /package/src/{utils → updaters}/CallUpdater.ts +0 -0
@@ -0,0 +1,518 @@
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 { Observer } from './Observer';
17
+ import { ClientEvent, ClientIssue, ClientMetaData, ClientSample, ExtensionStat } from './schema/ClientSample';
18
+
19
+ export class ObserverEventMonitor<Context> {
20
+ public constructor(
21
+ public readonly observer: Observer,
22
+ public readonly context: Context,
23
+ ) {
24
+ this._onPeerConnconnectionAdded = this._onPeerConnconnectionAdded.bind(this);
25
+ this._onPeerConnectionRemoved = this._onPeerConnectionRemoved.bind(this);
26
+ this._onCertificateAdded = this._onCertificateAdded.bind(this);
27
+ this._onCertificateRemoved = this._onCertificateRemoved.bind(this);
28
+ this._onInboundTrackAdded = this._onInboundTrackAdded.bind(this);
29
+ this._onInboundTrackRemoved = this._onInboundTrackRemoved.bind(this);
30
+ this._onOutboundTrackAdded = this._onOutboundTrackAdded.bind(this);
31
+ this._onOutboundTrackRemoved = this._onOutboundTrackRemoved.bind(this);
32
+ this._onInboundRtpAdded = this._onInboundRtpAdded.bind(this);
33
+ this._onInboundRtpRemoved = this._onInboundRtpRemoved.bind(this);
34
+ this._onOutboundRtpAdded = this._onOutboundRtpAdded.bind(this);
35
+ this._onOutboundRtpRemoved = this._onOutboundRtpRemoved.bind(this);
36
+ this._onDataChannelAdded = this._onDataChannelAdded.bind(this);
37
+ this._onDataChannelRemoved = this._onDataChannelRemoved.bind(this);
38
+ this._onAddedIceTransport = this._onAddedIceTransport.bind(this);
39
+ this._onRemovedIceTransport = this._onRemovedIceTransport.bind(this);
40
+ this._onIceCandidateAdded = this._onIceCandidateAdded.bind(this);
41
+ this._onIceCandidateRemoved = this._onIceCandidateRemoved.bind(this);
42
+ this._onAddedIceCandidatePair = this._onAddedIceCandidatePair.bind(this);
43
+ this._onRemovedIceCandidatePair = this._onRemovedIceCandidatePair.bind(this);
44
+ this._onAddedMediaCodec = this._onAddedMediaCodec.bind(this);
45
+ this._onRemovedMediaCodec = this._onRemovedMediaCodec.bind(this);
46
+ this._onAddedMediaPlayout = this._onAddedMediaPlayout.bind(this);
47
+ this._onRemovedMediaPlayout = this._onRemovedMediaPlayout.bind(this);
48
+ this._onMediaSourceAdded = this._onMediaSourceAdded.bind(this);
49
+ this._onMediaSourceRemoved = this._onMediaSourceRemoved.bind(this);
50
+ this._onClientIssue = this._onClientIssue.bind(this);
51
+ this._onClientMetadata = this._onClientMetadata.bind(this);
52
+ this._onClientJoined = this._onClientJoined.bind(this);
53
+ this._onClientLeft = this._onClientLeft.bind(this);
54
+ this._onUserMediaError = this._onUserMediaError.bind(this);
55
+ this._onUsingTurn = this._onUsingTurn.bind(this);
56
+ this._onClientAdded = this._onClientAdded.bind(this);
57
+ this._onCallAdded = this._onCallAdded.bind(this);
58
+ this._onClientRejoined = this._onClientRejoined.bind(this);
59
+ this._onClientExtensionStats = this._onClientExtensionStats.bind(this);
60
+ this._onCertificateUpdated = this._onCertificateUpdated.bind(this);
61
+ this._onInboundRtpUpdated = this._onInboundRtpUpdated.bind(this);
62
+ this._onOutboundRtpUpdated = this._onOutboundRtpUpdated.bind(this);
63
+ this._onInboundTrackUpdated = this._onInboundTrackUpdated.bind(this);
64
+ this._onOutboundTrackUpdated = this._onOutboundTrackUpdated.bind(this);
65
+ this._onDataChannelUpdated = this._onDataChannelUpdated.bind(this);
66
+ this._onIceTransportUpdated = this._onIceTransportUpdated.bind(this);
67
+ this._onIceCandidatePairUpdated = this._onIceCandidatePairUpdated.bind(this);
68
+ this._onMediaCodecUpdated = this._onMediaCodecUpdated.bind(this);
69
+ this._onMediaPlayoutUpdated = this._onMediaPlayoutUpdated.bind(this);
70
+ this._onMediaSourceUpdated = this._onMediaSourceUpdated.bind(this);
71
+ this._onIceCandidateUpdated = this._onIceCandidateUpdated.bind(this);
72
+
73
+ this.observer.once('close', () => {
74
+ this.observer.off('newcall', this._onCallAdded);
75
+ });
76
+ this.observer.on('newcall', this._onCallAdded);
77
+ }
78
+
79
+ // Public event handlers
80
+ public onCallAdded?: (call: ObservedCall, ctx: Context) => void;
81
+ public onCallRemoved?: (call: ObservedCall, ctx: Context) => void;
82
+ public onCallEmpty?: (call: ObservedCall, ctx: Context) => void;
83
+ public onCallNotEmpty?: (call: ObservedCall, ctx: Context) => void;
84
+ public onCallUpdated?: (call: ObservedCall, ctx: Context) => void;
85
+
86
+ public onClientAdded?: (client: ObservedClient, ctx: Context) => void;
87
+ public onClientClosed?: (client: ObservedClient, ctx: Context) => void;
88
+ public onClientRejoined?: (client: ObservedClient, ctx: Context) => void;
89
+ public onClientIssue?: (observedClent: ObservedClient, issue: ClientIssue, ctx: Context) => void;
90
+ public onClientMetadata?: (observedClient: ObservedClient, metadata: ClientMetaData, ctx: Context) => void;
91
+ public onClientExtensionStats?: (observedClient: ObservedClient, extensionStats: ExtensionStat, ctx: Context) => void;
92
+ public onClientJoined?: (client: ObservedClient, ctx: Context) => void;
93
+ public onClientLeft?: (client: ObservedClient, ctx: Context) => void;
94
+ public onClientUserMediaError?: (observedClient: ObservedClient, error: string, ctx: Context) => void;
95
+ public onClientUsingTurn?: (client: ObservedClient, usingTurn: boolean, ctx: Context) => void;
96
+ public onClientUpdated?: (client: ObservedClient, sample: ClientSample, ctx: Context) => void;
97
+ public onClientEvent?: (client: ObservedClient, event: ClientEvent, ctx: Context) => void;
98
+
99
+ public onPeerConnectionAdded?: (peerConnection: ObservedPeerConnection, ctx: Context) => void;
100
+ public onPeerConnectionRemoved?: (peerConnection: ObservedPeerConnection, ctx: Context) => void;
101
+ public onSelectedCandidatePairChanged?: (peerConnection: ObservedPeerConnection, ctx: Context) => void;
102
+ public onIceGatheringStateChange?: (peerConnection: ObservedPeerConnection, ctx: Context) => void;
103
+ public onIceConnectionStateChange?: (peerConnection: ObservedPeerConnection, ctx: Context) => void;
104
+ public onConnectionStateChange?: (peerConnection: ObservedPeerConnection, ctx: Context) => void;
105
+
106
+ public onCertificateAdded?: (certificate: ObservedCertificate, ctx: Context) => void;
107
+ public onCertificateRemoved?: (certificate: ObservedCertificate, ctx: Context) => void;
108
+ public onCertificateUpdated?: (certificate: ObservedCertificate, ctx: Context) => void;
109
+
110
+ public onInboundTrackAdded?: (inboundTrack: ObservedInboundTrack, ctx: Context) => void;
111
+ public onInboundTrackRemoved?: (inboundTrack: ObservedInboundTrack, ctx: Context) => void;
112
+ public onInboundTrackUpdated?: (inboundTrack: ObservedInboundTrack, ctx: Context) => void;
113
+
114
+ public onOutboundTrackAdded?: (outboundTrack: ObservedOutboundTrack, ctx: Context) => void;
115
+ public onOutboundTrackRemoved?: (outboundTrack: ObservedOutboundTrack, ctx: Context) => void;
116
+ public onOutboundTrackUpdated?: (outboundTrack: ObservedOutboundTrack, ctx: Context) => void;
117
+
118
+ public onInboundRtpAdded?: (inboundRtp: ObservedInboundRtp, ctx: Context) => void;
119
+ public onInboundRtpRemoved?: (inboundRtp: ObservedInboundRtp, ctx: Context) => void;
120
+ public onInboundRtpUpdated?: (inboundRtp: ObservedInboundRtp, ctx: Context) => void;
121
+
122
+ public onOutboundRtpAdded?: (outboundRtp: ObservedOutboundRtp, ctx: Context) => void;
123
+ public onOutboundRtpRemoved?: (outboundRtp: ObservedOutboundRtp, ctx: Context) => void;
124
+ public onOutboundRtpUpdated?: (outboundRtp: ObservedOutboundRtp, ctx: Context) => void;
125
+
126
+ public onDataChannelAdded?: (dataChannel: ObservedDataChannel, ctx: Context) => void;
127
+ public onDataChannelRemoved?: (dataChannel: ObservedDataChannel, ctx: Context) => void;
128
+ public onDataChannelUpdated?: (dataChannel: ObservedDataChannel, ctx: Context) => void;
129
+
130
+ public onAddedIceTransport?: (iceTransport: ObservedIceTransport, ctx: Context) => void;
131
+ public onRemovedIceTransport?: (iceTransport: ObservedIceTransport, ctx: Context) => void;
132
+ public onIceTransportUpdated?: (iceTransport: ObservedIceTransport, ctx: Context) => void;
133
+
134
+ public onIceCandidateAdded?: (iceCandidate: ObservedIceCandidate, ctx: Context) => void;
135
+ public onIceCandidateRemoved?: (iceCandidate: ObservedIceCandidate, ctx: Context) => void;
136
+ public onIceCandidateUpdated?: (iceCandidate: ObservedIceCandidate, ctx: Context) => void;
137
+
138
+ public onAddedIceCandidatePair?: (candidatePair: ObservedIceCandidatePair, ctx: Context) => void;
139
+ public onRemovedIceCandidatePair?: (candidatePair: ObservedIceCandidatePair, ctx: Context) => void;
140
+ public onIceCandidatePairUpdated?: (candidatePair: ObservedIceCandidatePair, ctx: Context) => void;
141
+
142
+ public onAddedMediaCodec?: (codec: ObservedCodec, ctx: Context) => void;
143
+ public onRemovedMediaCodec?: (codec: ObservedCodec, ctx: Context) => void;
144
+ public onMediaCodecUpdated?: (codec: ObservedCodec, ctx: Context) => void;
145
+
146
+ public onAddedMediaPlayout?: (mediaPlayout: ObservedMediaPlayout, ctx: Context) => void;
147
+ public onRemovedMediaPlayout?: (mediaPlayout: ObservedMediaPlayout, ctx: Context) => void;
148
+ public onMediaPlayoutUpdated?: (mediaPlayout: ObservedMediaPlayout, ctx: Context) => void;
149
+
150
+ public onMediaSourceAdded?: (mediaSource: ObservedMediaSource, ctx: Context) => void;
151
+ public onMediaSourceRemoved?: (mediaSource: ObservedMediaSource, ctx: Context) => void;
152
+ public onMediaSourceUpdated?: (mediaSource: ObservedMediaSource, ctx: Context) => void;
153
+
154
+ private _onCallAdded(call: ObservedCall) {
155
+ const onCallEmpty = () => this.onCallEmpty?.(call, this.context);
156
+ const onCallNotEmpty = () => this.onCallNotEmpty?.(call, this.context);
157
+ const onCallUpdated = () => this.onCallUpdated?.(call, this.context);
158
+
159
+ call.once('close', () => {
160
+ call.off('newclient', this._onClientAdded);
161
+ call.off('empty', onCallEmpty);
162
+ call.off('not-empty', onCallNotEmpty);
163
+ call.off('update', onCallUpdated);
164
+
165
+ this.onCallRemoved?.(call, this.context);
166
+ });
167
+ call.on('newclient', this._onClientAdded);
168
+ call.on('empty', onCallEmpty);
169
+ call.on('not-empty', onCallNotEmpty);
170
+ call.on('update', onCallUpdated);
171
+
172
+ this.onCallAdded?.(call, this.context);
173
+ }
174
+
175
+ private _onClientAdded(observedClient: ObservedClient) {
176
+ const onClientIssue = (issue: ClientIssue) => this._onClientIssue(observedClient, issue);
177
+ const onClientMetadata = (metaData: ClientMetaData) => this._onClientMetadata(observedClient, metaData);
178
+ const onClientJoined = () => this._onClientJoined(observedClient);
179
+ const onClientLeft = () => this._onClientLeft(observedClient);
180
+ const onClientRejoined = () => this._onClientRejoined(observedClient);
181
+ const onClientExtensionStats = (extensionStats: ExtensionStat) => this._onClientExtensionStats(observedClient, extensionStats);
182
+ const onUsingTurn = (usingTurn: boolean) => this._onUsingTurn(observedClient, usingTurn);
183
+ const onUserMediaError = (error: string) => this._onUserMediaError(observedClient, error);
184
+ const onClientUpdated = (...args: ObservedClientEvents['update']) => this.onClientUpdated?.(observedClient, args[0].sample, this.context);
185
+ const onClientEvent = (event: ClientEvent) => this.onClientEvent?.(observedClient, event, this.context);
186
+
187
+ observedClient.once('close', () => {
188
+ observedClient.off('newpeerconnection', this._onPeerConnconnectionAdded);
189
+ observedClient.off('issue', onClientIssue);
190
+ observedClient.off('metaData', onClientMetadata);
191
+ observedClient.off('joined', onClientJoined);
192
+ observedClient.off('left', onClientLeft);
193
+ observedClient.off('rejoined', onClientJoined);
194
+ observedClient.off('usermediaerror', onUserMediaError);
195
+ observedClient.off('usingturn', onUsingTurn);
196
+ observedClient.off('extensionStats', onClientExtensionStats);
197
+ observedClient.off('update', onClientUpdated);
198
+ observedClient.off('clientEvent', onClientEvent);
199
+
200
+ this.onClientClosed?.(observedClient, this.context);
201
+ });
202
+
203
+ observedClient.on('newpeerconnection', this._onPeerConnconnectionAdded);
204
+ observedClient.on('issue', onClientIssue);
205
+ observedClient.on('metaData', onClientMetadata);
206
+ observedClient.on('joined', onClientJoined);
207
+ observedClient.on('left', onClientLeft);
208
+ observedClient.on('rejoined', onClientRejoined);
209
+ observedClient.on('usermediaerror', onUserMediaError);
210
+ observedClient.on('usingturn', onUsingTurn);
211
+ observedClient.on('extensionStats', onClientExtensionStats);
212
+ observedClient.on('update', onClientUpdated);
213
+ observedClient.on('clientEvent', onClientEvent);
214
+
215
+ this.onClientAdded?.(observedClient, this.context);
216
+ }
217
+
218
+ private _onClientRejoined(observedClient: ObservedClient) {
219
+ this.onClientRejoined?.(observedClient, this.context);
220
+ }
221
+
222
+ private _onPeerConnconnectionAdded(peerConnection: ObservedPeerConnection) {
223
+ const onSelectedCandidatePairChanged = () => this.onSelectedCandidatePairChanged?.(peerConnection, this.context);
224
+ const onIceGatheringStateChange = () => this.onIceGatheringStateChange?.(peerConnection, this.context);
225
+ const onIceConnectionStateChange = () => this.onIceConnectionStateChange?.(peerConnection, this.context);
226
+ const onConnectionStateChange = () => this.onConnectionStateChange?.(peerConnection, this.context);
227
+
228
+ peerConnection.once('close', () => {
229
+ peerConnection.off('added-certificate', this._onCertificateAdded);
230
+ peerConnection.off('removed-certificate', this._onCertificateRemoved);
231
+ peerConnection.off('updated-certificate', this._onCertificateUpdated);
232
+
233
+ peerConnection.off('added-inbound-track', this._onInboundTrackAdded);
234
+ peerConnection.off('removed-inbound-track', this._onInboundTrackRemoved);
235
+ peerConnection.off('updated-inbound-track', this._onInboundTrackUpdated);
236
+
237
+ peerConnection.off('added-outbound-track', this._onOutboundTrackAdded);
238
+ peerConnection.off('removed-outbound-track', this._onOutboundTrackRemoved);
239
+ peerConnection.off('updated-outbound-track', this._onOutboundTrackUpdated);
240
+
241
+ peerConnection.off('added-inbound-rtp', this._onInboundRtpAdded);
242
+ peerConnection.off('removed-inbound-rtp', this._onInboundRtpRemoved);
243
+ peerConnection.off('updated-inbound-rtp', this._onInboundRtpUpdated);
244
+
245
+ peerConnection.off('added-outbound-rtp', this._onOutboundRtpAdded);
246
+ peerConnection.off('removed-outbound-rtp', this._onOutboundRtpRemoved);
247
+ peerConnection.off('updated-outbound-rtp', this._onOutboundRtpUpdated);
248
+
249
+ peerConnection.off('added-data-channel', this._onDataChannelAdded);
250
+ peerConnection.off('removed-data-channel', this._onDataChannelRemoved);
251
+ peerConnection.off('updated-data-channel', this._onDataChannelUpdated);
252
+
253
+ peerConnection.off('added-ice-transport', this._onAddedIceTransport);
254
+ peerConnection.off('removed-ice-transport', this._onRemovedIceTransport);
255
+ peerConnection.off('updated-ice-transport', this._onIceTransportUpdated);
256
+
257
+ peerConnection.off('added-ice-candidate', this._onIceCandidateAdded);
258
+ peerConnection.off('removed-ice-candidate', this._onIceCandidateRemoved);
259
+ peerConnection.off('updated-ice-candidate', this._onIceCandidateUpdated);
260
+
261
+ peerConnection.off('added-ice-candidate-pair', this._onAddedIceCandidatePair);
262
+ peerConnection.off('removed-ice-candidate-pair', this._onRemovedIceCandidatePair);
263
+ peerConnection.off('updated-ice-candidate-pair', this._onIceCandidatePairUpdated);
264
+
265
+ peerConnection.off('added-codec', this._onAddedMediaCodec);
266
+ peerConnection.off('removed-codec', this._onRemovedMediaCodec);
267
+ peerConnection.off('updated-codec', this._onMediaCodecUpdated);
268
+
269
+ peerConnection.off('added-media-playout', this._onAddedMediaPlayout);
270
+ peerConnection.off('removed-media-playout', this._onRemovedMediaPlayout);
271
+ peerConnection.off('updated-media-playout', this._onMediaPlayoutUpdated);
272
+
273
+ peerConnection.off('added-media-source', this._onMediaSourceAdded);
274
+ peerConnection.off('removed-media-source', this._onMediaSourceRemoved);
275
+ peerConnection.off('updated-media-source', this._onMediaSourceUpdated);
276
+
277
+ peerConnection.off('selectedcandidatepair', onSelectedCandidatePairChanged);
278
+ peerConnection.off('icegatheringstatechange', onIceGatheringStateChange);
279
+ peerConnection.off('iceconnectionstatechange', onIceConnectionStateChange);
280
+ peerConnection.off('connectionstatechange', onConnectionStateChange);
281
+
282
+ this.onPeerConnectionRemoved?.(peerConnection, this.context);
283
+ });
284
+
285
+ peerConnection.on('added-certificate', this._onCertificateAdded);
286
+ peerConnection.on('removed-certificate', this._onCertificateRemoved);
287
+ peerConnection.on('updated-certificate', this._onCertificateUpdated);
288
+
289
+ peerConnection.on('added-inbound-track', this._onInboundTrackAdded);
290
+ peerConnection.on('removed-inbound-track', this._onInboundTrackRemoved);
291
+ peerConnection.on('updated-inbound-track', this._onInboundTrackUpdated);
292
+
293
+ peerConnection.on('added-outbound-track', this._onOutboundTrackAdded);
294
+ peerConnection.on('removed-outbound-track', this._onOutboundTrackRemoved);
295
+ peerConnection.on('updated-outbound-track', this._onOutboundTrackUpdated);
296
+
297
+ peerConnection.on('added-inbound-rtp', this._onInboundRtpAdded);
298
+ peerConnection.on('removed-inbound-rtp', this._onInboundRtpRemoved);
299
+ peerConnection.on('updated-inbound-rtp', this._onInboundRtpUpdated);
300
+
301
+ peerConnection.on('added-outbound-rtp', this._onOutboundRtpAdded);
302
+ peerConnection.on('removed-outbound-rtp', this._onOutboundRtpRemoved);
303
+ peerConnection.on('updated-outbound-rtp', this._onOutboundRtpUpdated);
304
+
305
+ peerConnection.on('added-data-channel', this._onDataChannelAdded);
306
+ peerConnection.on('removed-data-channel', this._onDataChannelRemoved);
307
+ peerConnection.on('updated-data-channel', this._onDataChannelUpdated);
308
+
309
+ peerConnection.on('added-ice-transport', this._onAddedIceTransport);
310
+ peerConnection.on('removed-ice-transport', this._onRemovedIceTransport);
311
+ peerConnection.on('updated-ice-transport', this._onIceTransportUpdated);
312
+
313
+ peerConnection.on('added-ice-candidate', this._onIceCandidateAdded);
314
+ peerConnection.on('removed-ice-candidate', this._onIceCandidateRemoved);
315
+ peerConnection.on('updated-ice-candidate', this._onIceCandidateUpdated);
316
+
317
+ peerConnection.on('added-ice-candidate-pair', this._onAddedIceCandidatePair);
318
+ peerConnection.on('removed-ice-candidate-pair', this._onRemovedIceCandidatePair);
319
+ peerConnection.on('updated-ice-candidate-pair', this._onIceCandidatePairUpdated);
320
+
321
+ peerConnection.on('added-codec', this._onAddedMediaCodec);
322
+ peerConnection.on('removed-codec', this._onRemovedMediaCodec);
323
+ peerConnection.on('updated-codec', this._onMediaCodecUpdated);
324
+
325
+ peerConnection.on('added-media-playout', this._onAddedMediaPlayout);
326
+ peerConnection.on('removed-media-playout', this._onRemovedMediaPlayout);
327
+ peerConnection.on('updated-media-playout', this._onMediaPlayoutUpdated);
328
+
329
+ peerConnection.on('added-media-source', this._onMediaSourceAdded);
330
+ peerConnection.on('removed-media-source', this._onMediaSourceRemoved);
331
+ peerConnection.on('updated-media-source', this._onMediaSourceUpdated);
332
+
333
+ peerConnection.on('selectedcandidatepair', onSelectedCandidatePairChanged);
334
+ peerConnection.on('icegatheringstatechange', onIceGatheringStateChange);
335
+ peerConnection.on('iceconnectionstatechange', onIceConnectionStateChange);
336
+ peerConnection.on('connectionstatechange', onConnectionStateChange);
337
+
338
+ this.onPeerConnectionAdded?.(peerConnection, this.context);
339
+
340
+ }
341
+
342
+ private _onPeerConnectionRemoved(peerConnection: ObservedPeerConnection) {
343
+ this.onPeerConnectionRemoved?.(peerConnection, this.context);
344
+
345
+ }
346
+
347
+ private _onCertificateAdded(certificate: ObservedCertificate) {
348
+ this.onCertificateAdded?.(certificate, this.context);
349
+ }
350
+
351
+ private _onCertificateRemoved(certificate: ObservedCertificate) {
352
+ this.onCertificateRemoved?.(certificate, this.context);
353
+ }
354
+
355
+ private _onCertificateUpdated(certificate: ObservedCertificate) {
356
+ this.onCertificateUpdated?.(certificate, this.context);
357
+ }
358
+
359
+ private _onInboundTrackAdded(inboundTrack: ObservedInboundTrack) {
360
+ this.onInboundTrackAdded?.(inboundTrack, this.context);
361
+ }
362
+
363
+ private _onInboundTrackRemoved(inboundTrack: ObservedInboundTrack) {
364
+ this.onInboundTrackRemoved?.(inboundTrack, this.context);
365
+ }
366
+
367
+ private _onInboundTrackUpdated(inboundTrack: ObservedInboundTrack) {
368
+ this.onInboundTrackUpdated?.(inboundTrack, this.context);
369
+ }
370
+
371
+ private _onOutboundTrackAdded(outboundTrack: ObservedOutboundTrack) {
372
+ this.onOutboundTrackAdded?.(outboundTrack, this.context);
373
+ }
374
+
375
+ private _onOutboundTrackRemoved(outboundTrack: ObservedOutboundTrack) {
376
+ this.onOutboundTrackRemoved?.(outboundTrack, this.context);
377
+ }
378
+
379
+ private _onOutboundTrackUpdated(outboundTrack: ObservedOutboundTrack) {
380
+ this.onOutboundTrackUpdated?.(outboundTrack, this.context);
381
+ }
382
+
383
+ private _onInboundRtpAdded(inboundRtp: ObservedInboundRtp) {
384
+ this.onInboundRtpAdded?.(inboundRtp, this.context);
385
+ }
386
+
387
+ private _onInboundRtpRemoved(inboundRtp: ObservedInboundRtp) {
388
+ this.onInboundRtpRemoved?.(inboundRtp, this.context);
389
+ }
390
+
391
+ private _onInboundRtpUpdated(inboundRtp: ObservedInboundRtp) {
392
+ this.onInboundRtpUpdated?.(inboundRtp, this.context);
393
+ }
394
+
395
+ private _onOutboundRtpAdded(outboundRtp: ObservedOutboundRtp) {
396
+ this.onOutboundRtpAdded?.(outboundRtp, this.context);
397
+ }
398
+
399
+ private _onOutboundRtpRemoved(outboundRtp: ObservedOutboundRtp) {
400
+ this.onOutboundRtpRemoved?.(outboundRtp, this.context);
401
+ }
402
+
403
+ private _onOutboundRtpUpdated(outboundRtp: ObservedOutboundRtp) {
404
+ this.onOutboundRtpUpdated?.(outboundRtp, this.context);
405
+ }
406
+
407
+ private _onDataChannelAdded(dataChannel: ObservedDataChannel) {
408
+ this.onDataChannelAdded?.(dataChannel, this.context);
409
+ }
410
+
411
+ private _onDataChannelRemoved(dataChannel: ObservedDataChannel) {
412
+ this.onDataChannelRemoved?.(dataChannel, this.context);
413
+ }
414
+
415
+ private _onDataChannelUpdated(dataChannel: ObservedDataChannel) {
416
+ this.onDataChannelUpdated?.(dataChannel, this.context);
417
+ }
418
+
419
+ private _onAddedIceTransport(iceTransport: ObservedIceTransport) {
420
+ this.onAddedIceTransport?.(iceTransport, this.context);
421
+ }
422
+
423
+ private _onRemovedIceTransport(iceTransport: ObservedIceTransport) {
424
+ this.onRemovedIceTransport?.(iceTransport, this.context);
425
+ }
426
+
427
+ private _onIceTransportUpdated(iceTransport: ObservedIceTransport) {
428
+ this.onIceTransportUpdated?.(iceTransport, this.context);
429
+ }
430
+
431
+ private _onIceCandidateAdded(iceCandidate: ObservedIceCandidate) {
432
+ this.onIceCandidateAdded?.(iceCandidate, this.context);
433
+ }
434
+
435
+ private _onIceCandidateRemoved(iceCandidate: ObservedIceCandidate) {
436
+ this.onIceCandidateRemoved?.(iceCandidate, this.context);
437
+ }
438
+
439
+ private _onIceCandidateUpdated(iceCandidate: ObservedIceCandidate) {
440
+ this.onIceCandidateUpdated?.(iceCandidate, this.context);
441
+ }
442
+
443
+ private _onAddedIceCandidatePair(candidatePair: ObservedIceCandidatePair) {
444
+ this.onAddedIceCandidatePair?.(candidatePair, this.context);
445
+ }
446
+
447
+ private _onRemovedIceCandidatePair(candidatePair: ObservedIceCandidatePair) {
448
+ this.onRemovedIceCandidatePair?.(candidatePair, this.context);
449
+ }
450
+
451
+ private _onIceCandidatePairUpdated(candidatePair: ObservedIceCandidatePair) {
452
+ this.onIceCandidatePairUpdated?.(candidatePair, this.context);
453
+ }
454
+
455
+ private _onAddedMediaCodec(codec: ObservedCodec) {
456
+ this.onAddedMediaCodec?.(codec, this.context);
457
+ }
458
+
459
+ private _onRemovedMediaCodec(codec: ObservedCodec) {
460
+ this.onRemovedMediaCodec?.(codec, this.context);
461
+ }
462
+
463
+ private _onMediaCodecUpdated(codec: ObservedCodec) {
464
+ this.onMediaCodecUpdated?.(codec, this.context);
465
+ }
466
+
467
+ private _onAddedMediaPlayout(mediaPlayout: ObservedMediaPlayout) {
468
+ this.onAddedMediaPlayout?.(mediaPlayout, this.context);
469
+ }
470
+
471
+ private _onRemovedMediaPlayout(mediaPlayout: ObservedMediaPlayout) {
472
+ this.onRemovedMediaPlayout?.(mediaPlayout, this.context);
473
+ }
474
+
475
+ private _onMediaPlayoutUpdated(mediaPlayout: ObservedMediaPlayout) {
476
+ this.onMediaPlayoutUpdated?.(mediaPlayout, this.context);
477
+ }
478
+
479
+ private _onMediaSourceAdded(mediaSource: ObservedMediaSource) {
480
+ this.onMediaSourceAdded?.(mediaSource, this.context);
481
+ }
482
+
483
+ private _onMediaSourceRemoved(mediaSource: ObservedMediaSource) {
484
+ this.onMediaSourceRemoved?.(mediaSource, this.context);
485
+ }
486
+
487
+ private _onMediaSourceUpdated(mediaSource: ObservedMediaSource) {
488
+ this.onMediaSourceUpdated?.(mediaSource, this.context);
489
+ }
490
+
491
+ private _onClientIssue(observedClent: ObservedClient, issue: ClientIssue) {
492
+ this.onClientIssue?.(observedClent, issue, this.context);
493
+ }
494
+
495
+ private _onClientMetadata(observedClient: ObservedClient, metadata: ClientMetaData) {
496
+ this.onClientMetadata?.(observedClient, metadata, this.context);
497
+ }
498
+
499
+ private _onClientExtensionStats(observedClient: ObservedClient, extensionStats: ExtensionStat) {
500
+ this.onClientExtensionStats?.(observedClient, extensionStats, this.context);
501
+ }
502
+
503
+ private _onClientJoined(observedClient: ObservedClient) {
504
+ this.onClientJoined?.(observedClient, this.context);
505
+ }
506
+
507
+ private _onClientLeft(observedClient: ObservedClient) {
508
+ this.onClientLeft?.(observedClient, this.context);
509
+ }
510
+
511
+ private _onUserMediaError(observedClient: ObservedClient, error: string) {
512
+ this.onClientUserMediaError?.(observedClient, error, this.context);
513
+ }
514
+
515
+ private _onUsingTurn(observedClient: ObservedClient, usingTurn: boolean) {
516
+ this.onClientUsingTurn?.(observedClient, usingTurn, this.context);
517
+ }
518
+ }
@@ -0,0 +1,15 @@
1
+ export type ObserverSummary = {
2
+ currentActiveCalls: number;
3
+ currentNumberOfClientsUsingTURN: number;
4
+ currentNumberOfClients: number;
5
+
6
+ totalAddedCall: number;
7
+ totalRemovedCall: number;
8
+
9
+ totalRttLt50Measurements: number,
10
+ totalRttLt150Measurements: number,
11
+ totalRttLt300Measurements: number,
12
+ totalRttGtOrEq300Measurements: number,
13
+
14
+ totalClientIssues: number,
15
+ }
@@ -30,9 +30,19 @@ export function isValidUuid(str: string): boolean {
30
30
  return regexp.test(str);
31
31
  }
32
32
 
33
- export function getMedian(arr: number[]): number {
33
+ export function getAverage(arr: number[], defaultAvgIfArrLengthIs0 = 0): number {
34
+ if (arr.length === 0) return defaultAvgIfArrLengthIs0;
35
+
36
+ return arr.reduce((a, b) => a + b, 0) / arr.length;
37
+ }
38
+
39
+ export function getMedian(arr: number[], copyArrayForSorting = true): number {
34
40
  // Sort the array in ascending order
35
- const sortedArr = arr.slice().sort((a, b) => a - b);
41
+ const sortedArr = copyArrayForSorting
42
+ ? arr.slice().sort((a, b) => a - b)
43
+ : arr.sort((a, b) => a-b)
44
+
45
+ ;
36
46
 
37
47
  // Calculate the middle index
38
48
  const mid = Math.floor(sortedArr.length / 2);
package/src/index.ts CHANGED
@@ -19,5 +19,11 @@ export { ObservedIceCandidatePair } from './ObservedIceCandidatePair';
19
19
  export { ObservedIceCandidate } from './ObservedIceCandidate';
20
20
  export { ObservedIceTransport } from './ObservedIceTransport';
21
21
  export { ObservedPeerConnectionTransport } from './ObservedPeerConnectionTransport';
22
+ export { ClientEventTypes } from './schema/ClientEventTypes';
23
+ export { ClientMetaTypes } from './schema/ClientMetaTypes';
24
+ export { ClientSample } from './schema/ClientSample';
25
+ export { ScoreCalculator } from './scores/ScoreCalculator';
26
+ export { ObservedClientEventMonitor } from './ObservedClientEventMonitor';
27
+ export { ObserverEventMonitor } from './ObserverEventMonitor';
22
28
 
23
29
  export { Middleware } from './common/Middleware';