@observertc/observer-js 1.0.0-beta.3 → 1.0.0-beta.5

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 (230) hide show
  1. package/README.md +790 -386
  2. package/dist/index.d.mts +2795 -0
  3. package/dist/index.d.ts +2795 -0
  4. package/dist/index.js +3765 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/index.mjs +3699 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/package.json +28 -15
  9. package/.eslintrc.json +0 -143
  10. package/.prettierignore +0 -5
  11. package/.prettierrc +0 -7
  12. package/jest.config.js +0 -9
  13. package/lib/ObservedCall.d.ts +0 -70
  14. package/lib/ObservedCall.d.ts.map +0 -1
  15. package/lib/ObservedCall.js +0 -196
  16. package/lib/ObservedCallEventMonitor.d.ts +0 -107
  17. package/lib/ObservedCallEventMonitor.d.ts.map +0 -1
  18. package/lib/ObservedCallEventMonitor.js +0 -321
  19. package/lib/ObservedCallSummary.d.ts +0 -18
  20. package/lib/ObservedCallSummary.d.ts.map +0 -1
  21. package/lib/ObservedCallSummary.js +0 -2
  22. package/lib/ObservedCertificate.d.ts +0 -19
  23. package/lib/ObservedCertificate.d.ts.map +0 -1
  24. package/lib/ObservedCertificate.js +0 -38
  25. package/lib/ObservedClient.d.ts +0 -115
  26. package/lib/ObservedClient.d.ts.map +0 -1
  27. package/lib/ObservedClient.js +0 -714
  28. package/lib/ObservedClientEventMonitor.d.ts +0 -91
  29. package/lib/ObservedClientEventMonitor.d.ts.map +0 -1
  30. package/lib/ObservedClientEventMonitor.js +0 -254
  31. package/lib/ObservedClientSummary.d.ts +0 -23
  32. package/lib/ObservedClientSummary.d.ts.map +0 -1
  33. package/lib/ObservedClientSummary.js +0 -2
  34. package/lib/ObservedCodec.d.ts +0 -22
  35. package/lib/ObservedCodec.d.ts.map +0 -1
  36. package/lib/ObservedCodec.js +0 -45
  37. package/lib/ObservedDataChannel.d.ts +0 -30
  38. package/lib/ObservedDataChannel.d.ts.map +0 -1
  39. package/lib/ObservedDataChannel.js +0 -75
  40. package/lib/ObservedIceCandidate.d.ts +0 -29
  41. package/lib/ObservedIceCandidate.d.ts.map +0 -1
  42. package/lib/ObservedIceCandidate.js +0 -59
  43. package/lib/ObservedIceCandidatePair.d.ts +0 -45
  44. package/lib/ObservedIceCandidatePair.d.ts.map +0 -1
  45. package/lib/ObservedIceCandidatePair.js +0 -127
  46. package/lib/ObservedIceTransport.d.ts +0 -36
  47. package/lib/ObservedIceTransport.d.ts.map +0 -1
  48. package/lib/ObservedIceTransport.js +0 -93
  49. package/lib/ObservedInboundRtp.d.ts +0 -92
  50. package/lib/ObservedInboundRtp.d.ts.map +0 -1
  51. package/lib/ObservedInboundRtp.js +0 -193
  52. package/lib/ObservedInboundTrack.d.ts +0 -34
  53. package/lib/ObservedInboundTrack.d.ts.map +0 -1
  54. package/lib/ObservedInboundTrack.js +0 -92
  55. package/lib/ObservedMediaPlayout.d.ts +0 -22
  56. package/lib/ObservedMediaPlayout.d.ts.map +0 -1
  57. package/lib/ObservedMediaPlayout.js +0 -42
  58. package/lib/ObservedMediaSource.d.ts +0 -28
  59. package/lib/ObservedMediaSource.d.ts.map +0 -1
  60. package/lib/ObservedMediaSource.js +0 -55
  61. package/lib/ObservedOutboundRtp.d.ts +0 -62
  62. package/lib/ObservedOutboundRtp.d.ts.map +0 -1
  63. package/lib/ObservedOutboundRtp.js +0 -144
  64. package/lib/ObservedOutboundTrack.d.ts +0 -34
  65. package/lib/ObservedOutboundTrack.d.ts.map +0 -1
  66. package/lib/ObservedOutboundTrack.js +0 -65
  67. package/lib/ObservedPeerConnection.d.ts +0 -207
  68. package/lib/ObservedPeerConnection.d.ts.map +0 -1
  69. package/lib/ObservedPeerConnection.js +0 -788
  70. package/lib/ObservedPeerConnectionTransport.d.ts +0 -17
  71. package/lib/ObservedPeerConnectionTransport.d.ts.map +0 -1
  72. package/lib/ObservedPeerConnectionTransport.js +0 -34
  73. package/lib/ObservedRemoteInboundRtp.d.ts +0 -30
  74. package/lib/ObservedRemoteInboundRtp.d.ts.map +0 -1
  75. package/lib/ObservedRemoteInboundRtp.js +0 -60
  76. package/lib/ObservedRemoteOutboundRtp.d.ts +0 -30
  77. package/lib/ObservedRemoteOutboundRtp.d.ts.map +0 -1
  78. package/lib/ObservedRemoteOutboundRtp.js +0 -60
  79. package/lib/ObservedTURN.d.ts +0 -31
  80. package/lib/ObservedTURN.d.ts.map +0 -1
  81. package/lib/ObservedTURN.js +0 -58
  82. package/lib/ObservedTurnServer.d.ts +0 -25
  83. package/lib/ObservedTurnServer.d.ts.map +0 -1
  84. package/lib/ObservedTurnServer.js +0 -59
  85. package/lib/Observer.d.ts +0 -62
  86. package/lib/Observer.d.ts.map +0 -1
  87. package/lib/Observer.js +0 -160
  88. package/lib/ObserverEventMonitor.d.ts +0 -141
  89. package/lib/ObserverEventMonitor.d.ts.map +0 -1
  90. package/lib/ObserverEventMonitor.js +0 -440
  91. package/lib/ObserverSummary.d.ts +0 -13
  92. package/lib/ObserverSummary.d.ts.map +0 -1
  93. package/lib/ObserverSummary.js +0 -2
  94. package/lib/Reports.d.ts +0 -85
  95. package/lib/Reports.d.ts.map +0 -1
  96. package/lib/Reports.js +0 -2
  97. package/lib/common/Middleware.d.ts +0 -17
  98. package/lib/common/Middleware.d.ts.map +0 -1
  99. package/lib/common/Middleware.js +0 -60
  100. package/lib/common/SingleExecutor.d.ts +0 -3
  101. package/lib/common/SingleExecutor.d.ts.map +0 -1
  102. package/lib/common/SingleExecutor.js +0 -31
  103. package/lib/common/logger.d.ts +0 -17
  104. package/lib/common/logger.d.ts.map +0 -1
  105. package/lib/common/logger.js +0 -50
  106. package/lib/common/types.d.ts +0 -3
  107. package/lib/common/types.d.ts.map +0 -1
  108. package/lib/common/types.js +0 -3
  109. package/lib/common/utils.d.ts +0 -11
  110. package/lib/common/utils.d.ts.map +0 -1
  111. package/lib/common/utils.js +0 -63
  112. package/lib/detectors/Detector.d.ts +0 -5
  113. package/lib/detectors/Detector.d.ts.map +0 -1
  114. package/lib/detectors/Detector.js +0 -3
  115. package/lib/detectors/Detectors.d.ts +0 -11
  116. package/lib/detectors/Detectors.d.ts.map +0 -1
  117. package/lib/detectors/Detectors.js +0 -34
  118. package/lib/index.d.ts +0 -29
  119. package/lib/index.d.ts.map +0 -1
  120. package/lib/index.js +0 -49
  121. package/lib/mediasoup/ObservedMediaRouter.d.ts +0 -10
  122. package/lib/mediasoup/ObservedMediaRouter.d.ts.map +0 -1
  123. package/lib/mediasoup/ObservedMediaRouter.js +0 -6
  124. package/lib/monitors/TurnUsageMonitor.d.ts +0 -1
  125. package/lib/monitors/TurnUsageMonitor.d.ts.map +0 -1
  126. package/lib/monitors/TurnUsageMonitor.js +0 -146
  127. package/lib/schema/ClientEventTypes.d.ts +0 -228
  128. package/lib/schema/ClientEventTypes.d.ts.map +0 -1
  129. package/lib/schema/ClientEventTypes.js +0 -41
  130. package/lib/schema/ClientMetaTypes.d.ts +0 -34
  131. package/lib/schema/ClientMetaTypes.d.ts.map +0 -1
  132. package/lib/schema/ClientMetaTypes.js +0 -16
  133. package/lib/schema/ClientSample.d.ts +0 -1333
  134. package/lib/schema/ClientSample.d.ts.map +0 -1
  135. package/lib/schema/ClientSample.js +0 -4
  136. package/lib/scores/CalculatedScore.d.ts +0 -6
  137. package/lib/scores/CalculatedScore.d.ts.map +0 -1
  138. package/lib/scores/CalculatedScore.js +0 -2
  139. package/lib/scores/DefaultCallScoreCalculator.d.ts +0 -7
  140. package/lib/scores/DefaultCallScoreCalculator.d.ts.map +0 -1
  141. package/lib/scores/DefaultCallScoreCalculator.js +0 -21
  142. package/lib/scores/ScoreCalculator.d.ts +0 -4
  143. package/lib/scores/ScoreCalculator.d.ts.map +0 -1
  144. package/lib/scores/ScoreCalculator.js +0 -2
  145. package/lib/updaters/CallUpdater.d.ts +0 -5
  146. package/lib/updaters/CallUpdater.d.ts.map +0 -1
  147. package/lib/updaters/CallUpdater.js +0 -2
  148. package/lib/updaters/ObserverUpdater.d.ts +0 -5
  149. package/lib/updaters/ObserverUpdater.d.ts.map +0 -1
  150. package/lib/updaters/ObserverUpdater.js +0 -2
  151. package/lib/updaters/OnAllCallObserverUpdater.d.ts +0 -15
  152. package/lib/updaters/OnAllCallObserverUpdater.d.ts.map +0 -1
  153. package/lib/updaters/OnAllCallObserverUpdater.js +0 -50
  154. package/lib/updaters/OnAllClientCallUpdater.d.ts +0 -15
  155. package/lib/updaters/OnAllClientCallUpdater.d.ts.map +0 -1
  156. package/lib/updaters/OnAllClientCallUpdater.js +0 -53
  157. package/lib/updaters/OnAnyCallObserverUpdater.d.ts +0 -12
  158. package/lib/updaters/OnAnyCallObserverUpdater.d.ts.map +0 -1
  159. package/lib/updaters/OnAnyCallObserverUpdater.js +0 -37
  160. package/lib/updaters/OnAnyClientCallUpdater.d.ts +0 -12
  161. package/lib/updaters/OnAnyClientCallUpdater.d.ts.map +0 -1
  162. package/lib/updaters/OnAnyClientCallUpdater.js +0 -36
  163. package/lib/updaters/OnIntervalUpdater.d.ts +0 -10
  164. package/lib/updaters/OnIntervalUpdater.d.ts.map +0 -1
  165. package/lib/updaters/OnIntervalUpdater.js +0 -17
  166. package/lib/updaters/Updater.d.ts +0 -6
  167. package/lib/updaters/Updater.d.ts.map +0 -1
  168. package/lib/updaters/Updater.js +0 -2
  169. package/lib/utils/MediasoupRemoteTrackResolver.d.ts +0 -25
  170. package/lib/utils/MediasoupRemoteTrackResolver.d.ts.map +0 -1
  171. package/lib/utils/MediasoupRemoteTrackResolver.js +0 -110
  172. package/lib/utils/RemoteTrackResolver.d.ts +0 -7
  173. package/lib/utils/RemoteTrackResolver.d.ts.map +0 -1
  174. package/lib/utils/RemoteTrackResolver.js +0 -2
  175. package/src/ObservedCall.ts +0 -308
  176. package/src/ObservedCallEventMonitor.ts +0 -402
  177. package/src/ObservedCallSummary.ts +0 -22
  178. package/src/ObservedCertificate.ts +0 -43
  179. package/src/ObservedClient.ts +0 -883
  180. package/src/ObservedClientEventMonitor.ts +0 -309
  181. package/src/ObservedClientSummary.ts +0 -24
  182. package/src/ObservedCodec.ts +0 -49
  183. package/src/ObservedDataChannel.ts +0 -85
  184. package/src/ObservedIceCandidate.ts +0 -64
  185. package/src/ObservedIceCandidatePair.ts +0 -134
  186. package/src/ObservedIceTransport.ts +0 -99
  187. package/src/ObservedInboundRtp.ts +0 -205
  188. package/src/ObservedInboundTrack.ts +0 -105
  189. package/src/ObservedMediaPlayout.ts +0 -49
  190. package/src/ObservedMediaSource.ts +0 -60
  191. package/src/ObservedOutboundRtp.ts +0 -156
  192. package/src/ObservedOutboundTrack.ts +0 -82
  193. package/src/ObservedPeerConnection.ts +0 -1104
  194. package/src/ObservedPeerConnectionTransport.ts +0 -38
  195. package/src/ObservedRemoteInboundRtp.ts +0 -64
  196. package/src/ObservedRemoteOutboundRtp.ts +0 -65
  197. package/src/ObservedTURN.ts +0 -86
  198. package/src/ObservedTurnServer.ts +0 -72
  199. package/src/Observer.ts +0 -248
  200. package/src/ObserverEventMonitor.ts +0 -561
  201. package/src/ObserverSummary.ts +0 -15
  202. package/src/Reports.ts +0 -87
  203. package/src/common/Middleware.ts +0 -84
  204. package/src/common/SingleExecutor.ts +0 -36
  205. package/src/common/logger.ts +0 -82
  206. package/src/common/types.ts +0 -4
  207. package/src/common/utils.ts +0 -69
  208. package/src/detectors/Detector.ts +0 -6
  209. package/src/detectors/Detectors.ts +0 -38
  210. package/src/index.ts +0 -32
  211. package/src/mediasoup/ObservedMediaRouter.ts +0 -10
  212. package/src/monitors/TurnUsageMonitor.ts +0 -187
  213. package/src/schema/ClientEventTypes.ts +0 -280
  214. package/src/schema/ClientMetaTypes.ts +0 -41
  215. package/src/schema/ClientSample.ts +0 -1682
  216. package/src/scores/CalculatedScore.ts +0 -6
  217. package/src/scores/DefaultCallScoreCalculator.ts +0 -23
  218. package/src/scores/ScoreCalculator.ts +0 -3
  219. package/src/updaters/CallUpdater.ts +0 -5
  220. package/src/updaters/ObserverUpdater.ts +0 -5
  221. package/src/updaters/OnAllCallObserverUpdater.ts +0 -59
  222. package/src/updaters/OnAllClientCallUpdater.ts +0 -61
  223. package/src/updaters/OnAnyCallObserverUpdater.ts +0 -41
  224. package/src/updaters/OnAnyClientCallUpdater.ts +0 -39
  225. package/src/updaters/OnIntervalUpdater.ts +0 -19
  226. package/src/updaters/Updater.ts +0 -5
  227. package/src/utils/MediasoupRemoteTrackResolver.ts +0 -155
  228. package/src/utils/RemoteTrackResolver.ts +0 -12
  229. package/tsconfig.json +0 -19
  230. package/tslint.json +0 -6
@@ -1,883 +0,0 @@
1
- import { EventEmitter } from 'events';
2
- import { ObservedPeerConnection } from './ObservedPeerConnection';
3
- import { createLogger } from './common/logger';
4
- // eslint-disable-next-line camelcase
5
- import { ClientEvent, ClientMetaData, ClientSample, PeerConnectionSample, ClientIssue, ExtensionStat } from './schema/ClientSample';
6
- import * as MetaData from './schema/ClientMetaTypes';
7
- import { ClientEventTypes } from './schema/ClientEventTypes';
8
- import { ObservedCall } from './ObservedCall';
9
- import { ClientMetaTypes } from './schema/ClientMetaTypes';
10
- import { parseJsonAs } from './common/utils';
11
- import { CalculatedScore } from './scores/CalculatedScore';
12
- import { Detectors } from './detectors/Detectors';
13
- import { ClientReport, TrackReport } from './Reports';
14
- import { ObservedInboundTrack } from './ObservedInboundTrack';
15
- import { ObservedOutboundTrack } from './ObservedOutboundTrack';
16
-
17
- const logger = createLogger('ObservedClient');
18
-
19
- export type ObservedClientSettings<AppData extends Record<string, unknown> = Record<string, unknown>> = {
20
- clientId: string;
21
- appData?: AppData;
22
- closeClientIfIdleForMs?: number;
23
- };
24
-
25
- export type ObservedClientEvents = {
26
- update: [sample: ClientSample, elapsedTimeInMs: number];
27
- close: [];
28
- joined: [];
29
- issue: [ClientIssue];
30
- metaData: [ClientMetaData];
31
- rejoined: [timestamp: number];
32
- left: [];
33
- usingturn: [boolean];
34
- usermediaerror: [string];
35
- extensionStats: [ExtensionStat];
36
- clientEvent: [ClientEvent];
37
-
38
- newpeerconnection: [ObservedPeerConnection];
39
-
40
- trackreport: [TrackReport];
41
- };
42
-
43
- export declare interface ObservedClient {
44
- on<U extends keyof ObservedClientEvents>(event: U, listener: (...args: ObservedClientEvents[U]) => void): this;
45
- off<U extends keyof ObservedClientEvents>(event: U, listener: (...args: ObservedClientEvents[U]) => void): this;
46
- once<U extends keyof ObservedClientEvents>(event: U, listener: (...args: ObservedClientEvents[U]) => void): this;
47
- emit<U extends keyof ObservedClientEvents>(event: U, ...args: ObservedClientEvents[U]): boolean;
48
- }
49
-
50
- export class ObservedClient<AppData extends Record<string, unknown> = Record<string, unknown>> extends EventEmitter {
51
- public readonly detectors: Detectors;
52
-
53
- public readonly clientId: string;
54
- public readonly observedPeerConnections = new Map<string, ObservedPeerConnection>();
55
- public readonly calculatedScore: CalculatedScore = {
56
- weight: 1,
57
- value: undefined,
58
- };
59
-
60
- public readonly settings: Pick<ObservedClientSettings, 'closeClientIfIdleForMs'>;
61
-
62
- public appData: AppData;
63
- public attachments?: Record<string, unknown>;
64
-
65
- public updated = Date.now();
66
- public acceptedSamples = 0;
67
- public closed = false;
68
-
69
- public joinedAt?: number;
70
- public leftAt?: number;
71
- public closedAt?: number;
72
- public lastSampleTimestamp?: number;
73
- // the timestamp of the CLIENT_JOINED event
74
- public operationSystem?: MetaData.OperationSystem;
75
- public engine?: MetaData.Engine;
76
- public platform?: MetaData.Platform;
77
- public browser?: MetaData.Browser;
78
- public mediaConstraints: string[] = [];
79
-
80
- public usingTURN = false;
81
- public usingTCP = false;
82
- public availableOutgoingBitrate = 0;
83
- public availableIncomingBitrate = 0;
84
-
85
- // public totalInboundPacketsLost = 0;
86
- // public totalInboundPacketsReceived = 0;
87
- // public totalOutboundPacketsSent = 0;
88
- // public totalDataChannelBytesSent = 0;
89
- // public totalDataChannelBytesReceived = 0;
90
- // public totalDataChannelMessagesSent = 0;
91
- // public totalDataChannelMessagesReceived = 0;
92
- // public totalReceivedAudioBytes = 0;
93
- // public totalReceivedVideoBytes = 0;
94
- // public totalSentAudioBytes = 0;
95
- // public totalSentVideoBytes = 0;
96
- // public totalSentBytes = 0;
97
- // public totalReceivedBytes = 0;
98
- // public totalRttLt50Measurements = 0;
99
- // public totalRttLt150Measurements = 0;
100
- // public totalRttLt300Measurements = 0;
101
- // public totalRttGtOrEq300Measurements = 0;
102
-
103
- public deltaReceivedAudioBytes = 0;
104
- public deltaReceivedVideoBytes = 0;
105
- public deltaSentAudioBytes = 0;
106
- public deltaSentVideoBytes = 0;
107
- public deltaDataChannelBytesSent = 0;
108
- public deltaDataChannelBytesReceived = 0;
109
- public deltaDataChannelMessagesSent = 0;
110
- public deltaDataChannelMessagesReceived = 0;
111
- public deltaInboundPacketsLost = 0;
112
- public deltaInboundPacketsReceived = 0;
113
- public deltaOutboundPacketsSent = 0;
114
- public deltaTransportSentBytes = 0;
115
- public deltaTransportReceivedBytes = 0;
116
- public deltaRttLt50Measurements = 0;
117
- public deltaRttLt150Measurements = 0;
118
- public deltaRttLt300Measurements = 0;
119
- public deltaRttGtOrEq300Measurements = 0;
120
-
121
- public currentMaxRttInMs?: number;
122
- public currentMinRttInMs?: number;
123
- public currentAvgRttInMs?: number;
124
-
125
- public sendingAudioBitrate = 0;
126
- public sendingVideoBitrate = 0;
127
- public receivingAudioBitrate = 0;
128
- public receivingVideoBitrate = 0;
129
-
130
- public numberOfInboundRtpStreams = 0;
131
- public numberOfInbundTracks = 0;
132
- public numberOfOutboundRtpStreams = 0;
133
- public numberOfOutboundTracks = 0;
134
- public numberOfDataChannels = 0;
135
-
136
- public deltaNumberOfIssues = 0;
137
-
138
- public totalScoreSum = 0;
139
- public numberOfScoreMeasurements = 0;
140
- // public totalNumberOfIssues = 0;
141
-
142
- public readonly report: ClientReport;
143
-
144
- public readonly mediaDevices: MetaData.MediaDeviceInfo[] = [];
145
- public issues: ClientIssue[] = [];
146
-
147
- private _injections: Pick<ClientSample, 'clientEvents' | 'clientIssues' | 'extensionStats' | 'attachments' | 'clientMetaItems'> = {};
148
-
149
- private closeTimer?: ReturnType<typeof setTimeout>;
150
-
151
- public constructor(settings: ObservedClientSettings<AppData>, public readonly call: ObservedCall) {
152
- super();
153
- this.setMaxListeners(Infinity);
154
-
155
- this.clientId = settings.clientId;
156
- this.appData = settings.appData ?? {} as AppData;
157
-
158
- this.detectors = new Detectors();
159
- this.settings = {
160
- closeClientIfIdleForMs: settings.closeClientIfIdleForMs,
161
- };
162
-
163
- this.report = {
164
- callId: this.call.callId,
165
- clientId: this.clientId,
166
- rttDistribution: {
167
- gtOrEq300ms: 0,
168
- lt50ms: 0,
169
- lt150ms: 0,
170
- lt300ms: 0,
171
- count: 0,
172
- sum: 0,
173
- },
174
- scoreDistribution: {
175
- '0': 0,
176
- '1': 0,
177
- '2': 0,
178
- '3': 0,
179
- '4': 0,
180
- '5': 0,
181
- count: 0,
182
- sum: 0,
183
- },
184
- issues: {},
185
- totalAudioBytesReceived: 0,
186
- totalVideoBytesReceived: 0,
187
- totalAudioBytesSent: 0,
188
- totalVideoBytesSent: 0,
189
- totalDataChannelBytesReceived: 0,
190
- totalDataChannelBytesSent: 0,
191
- totalDataChannelMessagesReceived: 0,
192
- totalDataChannelMessagesSent: 0,
193
- totalInboundRtpBytesReceived: 0,
194
- totalInboundRtpPacketsLost: 0,
195
- totalInboundRtpPacketsReceived: 0,
196
- totalOutboundRtpBytesSent: 0,
197
- totalOutboundRtpPacketsSent: 0,
198
- totalNumberOfIssues: 0,
199
- };
200
- }
201
-
202
- public get numberOfPeerConnections() {
203
- return this.observedPeerConnections.size;
204
- }
205
-
206
- public get score() {
207
- return this.calculatedScore.value;
208
- }
209
-
210
- public close() {
211
- if (this.closed) return;
212
- this.closed = true;
213
-
214
- this._injections.clientEvents?.forEach((clientEvent) => this._processClientEvent(clientEvent));
215
- this._injections.clientIssues?.forEach((clientIssue) => this.addIssue(clientIssue));
216
- this._injections.extensionStats?.forEach((extensionStat) => this.addExtensionStats(extensionStat));
217
- this._injections.clientMetaItems?.forEach((clientMetaItem) => this.addMetadata(clientMetaItem));
218
-
219
- Array.from(this.observedPeerConnections.values()).forEach((peerConnection) => peerConnection.close());
220
- if (!this.leftAt) {
221
- this.leftAt = this.lastSampleTimestamp;
222
-
223
- if (this.leftAt) {
224
- this.emit('left');
225
- }
226
- }
227
- this.closedAt = Date.now();
228
-
229
- this.emit('close');
230
- }
231
-
232
- public accept(sample: ClientSample): void {
233
- if (this.closed) throw new Error(`Client ${this.clientId} is closed`);
234
-
235
- if (this.closeTimer) {
236
- clearTimeout(this.closeTimer);
237
- this.closeTimer = undefined;
238
- }
239
-
240
- const now = Date.now();
241
- const elapsedInMs = now - this.updated;
242
- const elapsedInSeconds = elapsedInMs / 1000;
243
- let sumOfRtts = 0;
244
- let numberOfRttMeasurements = 0;
245
-
246
- ++this.acceptedSamples;
247
-
248
- this.availableIncomingBitrate = 0;
249
- this.availableOutgoingBitrate = 0;
250
- this.deltaDataChannelBytesReceived = 0;
251
- this.deltaDataChannelBytesSent = 0;
252
- this.deltaDataChannelMessagesReceived = 0;
253
- this.deltaDataChannelMessagesSent = 0;
254
- this.deltaInboundPacketsLost = 0;
255
- this.deltaInboundPacketsReceived = 0;
256
- this.deltaOutboundPacketsSent = 0;
257
- this.deltaReceivedAudioBytes = 0;
258
- this.deltaReceivedVideoBytes = 0;
259
- this.deltaSentAudioBytes = 0;
260
- this.deltaSentVideoBytes = 0;
261
- this.deltaTransportReceivedBytes = 0;
262
- this.deltaTransportSentBytes = 0;
263
- this.deltaRttLt50Measurements = 0;
264
- this.deltaRttLt150Measurements = 0;
265
- this.deltaRttLt300Measurements = 0;
266
- this.deltaRttGtOrEq300Measurements = 0;
267
- this.deltaNumberOfIssues = 0;
268
-
269
- this.numberOfDataChannels = 0;
270
- this.numberOfInboundRtpStreams = 0;
271
- this.numberOfInbundTracks = 0;
272
- this.numberOfOutboundRtpStreams = 0;
273
- this.numberOfOutboundTracks = 0;
274
- this.usingTURN = false;
275
- this.usingTCP = false;
276
- this.currentMinRttInMs = undefined;
277
- this.currentMaxRttInMs = undefined;
278
-
279
- this._mergeInjections(sample);
280
-
281
- const clientEventsPostBuffer: ClientEvent[] = [];
282
-
283
- for (const clientEvent of sample.clientEvents ?? []) {
284
- this._processClientEvent(clientEvent, clientEventsPostBuffer);
285
-
286
- this.call.observer.emit('client-event', this, clientEvent);
287
- }
288
-
289
- for (const metaData of sample.clientMetaItems ?? []) {
290
- this.addMetadata(metaData);
291
- }
292
-
293
- for (const issue of sample.clientIssues ?? []) {
294
- this.addIssue(issue);
295
-
296
- ++this.deltaNumberOfIssues;
297
- }
298
-
299
- for (const extensionStat of sample.extensionStats ?? []) {
300
- this.addExtensionStats(extensionStat);
301
- }
302
-
303
- for (const pcSample of sample.peerConnections ?? []) {
304
- const observedPeerConnection = this._updatePeerConnection(pcSample);
305
-
306
- if (!observedPeerConnection) continue;
307
-
308
- this.deltaDataChannelBytesReceived += observedPeerConnection.deltaDataChannelBytesReceived;
309
- this.deltaDataChannelBytesSent += observedPeerConnection.deltaDataChannelBytesSent;
310
- this.deltaDataChannelMessagesReceived += observedPeerConnection.deltaDataChannelMessagesReceived;
311
- this.deltaDataChannelMessagesSent += observedPeerConnection.deltaDataChannelMessagesSent;
312
- this.deltaInboundPacketsLost += observedPeerConnection.deltaInboundPacketsLost;
313
- this.deltaInboundPacketsReceived += observedPeerConnection.deltaInboundPacketsReceived;
314
- this.deltaOutboundPacketsSent += observedPeerConnection.deltaOutboundPacketsSent;
315
- this.deltaReceivedAudioBytes += observedPeerConnection.deltaReceivedAudioBytes;
316
- this.deltaReceivedVideoBytes += observedPeerConnection.deltaReceivedVideoBytes;
317
- this.deltaSentAudioBytes += observedPeerConnection.deltaSentAudioBytes;
318
- this.deltaSentVideoBytes += observedPeerConnection.deltaSentVideoBytes;
319
- this.deltaTransportReceivedBytes += observedPeerConnection.deltaTransportReceivedBytes;
320
- this.deltaTransportSentBytes += observedPeerConnection.deltaTransportSentBytes;
321
-
322
- this.availableIncomingBitrate += observedPeerConnection.availableIncomingBitrate;
323
- this.availableOutgoingBitrate += observedPeerConnection.availableOutgoingBitrate;
324
-
325
- this.numberOfDataChannels += observedPeerConnection.observedDataChannels.size;
326
- this.numberOfInbundTracks += observedPeerConnection.observedInboundTracks.size;
327
- this.numberOfOutboundRtpStreams += observedPeerConnection.observedOutboundRtps.size;
328
- this.numberOfOutboundTracks += observedPeerConnection.observedOutboundTracks.size;
329
- this.numberOfInboundRtpStreams += observedPeerConnection.observedInboundRtps.size;
330
-
331
- if (observedPeerConnection.usingTURN) {
332
- this.usingTURN = true;
333
- }
334
- if (observedPeerConnection.usingTCP) {
335
- this.usingTCP = true;
336
- }
337
-
338
- if (observedPeerConnection.currentRttInMs) {
339
- if (this.currentMinRttInMs === undefined || observedPeerConnection.currentRttInMs < this.currentMinRttInMs) {
340
- this.currentMinRttInMs = observedPeerConnection.currentRttInMs;
341
- }
342
- if (this.currentMaxRttInMs === undefined || observedPeerConnection.currentRttInMs > this.currentMaxRttInMs) {
343
- this.currentMaxRttInMs = observedPeerConnection.currentRttInMs;
344
- }
345
- if (observedPeerConnection.currentRttInMs < 50) {
346
- this.deltaRttLt50Measurements += 1;
347
- this.report.rttDistribution.lt50ms += 1;
348
- } else if (observedPeerConnection.currentRttInMs < 150) {
349
- this.deltaRttLt150Measurements += 1;
350
- this.report.rttDistribution.lt150ms += 1;
351
- } else if (observedPeerConnection.currentRttInMs < 300) {
352
- this.deltaRttLt300Measurements += 1;
353
- this.report.rttDistribution.lt300ms += 1;
354
- } else if (300 <= observedPeerConnection.currentRttInMs) {
355
- this.deltaRttGtOrEq300Measurements += 1;
356
- this.report.rttDistribution.gtOrEq300ms += 1;
357
- }
358
- this.report.rttDistribution.count += 1;
359
- this.report.rttDistribution.sum += observedPeerConnection.currentRttInMs;
360
-
361
- sumOfRtts += observedPeerConnection.currentRttInMs;
362
- ++numberOfRttMeasurements;
363
- }
364
- }
365
-
366
- for (const clientEvent of clientEventsPostBuffer) {
367
- this._processClientEvent(clientEvent);
368
- }
369
-
370
- // emit new attachments?
371
- this.attachments = sample.attachments;
372
-
373
- this.report.totalDataChannelBytesReceived += this.deltaDataChannelBytesReceived;
374
- this.report.totalDataChannelBytesSent += this.deltaDataChannelBytesSent;
375
- this.report.totalDataChannelMessagesReceived += this.deltaDataChannelMessagesReceived;
376
- this.report.totalDataChannelMessagesSent += this.deltaDataChannelMessagesSent;
377
- this.report.totalInboundRtpPacketsLost += this.deltaInboundPacketsLost;
378
- this.report.totalInboundRtpPacketsReceived += this.deltaInboundPacketsReceived;
379
- this.report.totalOutboundRtpPacketsSent += this.deltaOutboundPacketsSent;
380
- this.report.totalAudioBytesReceived += this.deltaReceivedAudioBytes;
381
- this.report.totalVideoBytesReceived += this.deltaReceivedVideoBytes;
382
- this.report.totalAudioBytesSent += this.deltaSentAudioBytes;
383
- this.report.totalVideoBytesSent += this.deltaSentVideoBytes;
384
- this.report.totalInboundRtpBytesReceived += this.deltaTransportReceivedBytes;
385
- this.report.totalOutboundRtpBytesSent += this.deltaTransportSentBytes;
386
- this.report.totalNumberOfIssues += this.deltaNumberOfIssues;
387
-
388
- this.receivingAudioBitrate = (this.deltaReceivedAudioBytes * 8) / (elapsedInSeconds);
389
- this.receivingVideoBitrate = (this.deltaReceivedVideoBytes * 8) / (elapsedInSeconds);
390
- this.sendingAudioBitrate = (this.deltaSentAudioBytes * 8) / (elapsedInSeconds);
391
- this.sendingVideoBitrate = (this.deltaSentVideoBytes * 8) / (elapsedInSeconds);
392
- this.currentAvgRttInMs = 0 < numberOfRttMeasurements ? sumOfRtts / numberOfRttMeasurements : undefined;
393
-
394
- this.calculatedScore.value = sample.score;
395
-
396
- if (sample.score !== undefined) {
397
- const bucket = Math.floor(sample.score).toString() as '0' | '1' | '2' | '3' | '4' | '5';
398
-
399
- this.report.scoreDistribution[bucket] = (this.report.scoreDistribution[bucket] ?? 0) + 1;
400
- this.report.scoreDistribution.count += 1;
401
- this.report.scoreDistribution.sum += sample.score;
402
- }
403
-
404
- this.detectors.update();
405
-
406
- this.lastSampleTimestamp = sample.timestamp;
407
- // emit update
408
- this.emit('update',
409
- sample,
410
- now - this.updated,
411
- );
412
- this.updated = now;
413
-
414
- // if result changed after update
415
- if (this.calculatedScore.value) {
416
- this.totalScoreSum += this.calculatedScore.value;
417
- ++this.numberOfScoreMeasurements;
418
- }
419
-
420
- if (this.settings.closeClientIfIdleForMs !== undefined) {
421
- this.closeTimer = setTimeout(() => {
422
- this.close();
423
- }, this.settings.closeClientIfIdleForMs);
424
- }
425
- }
426
-
427
- private _processClientEvent(event: ClientEvent, postBuffer?: ClientEvent[]) {
428
- // eslint-disable-next-line no-console
429
- // console.warn('ClientEvent', event);
430
- switch (event.type) {
431
- case ClientEventTypes.CLIENT_JOINED: {
432
- if (event.timestamp) {
433
- if (!this.joinedAt) {
434
- this.joinedAt = event.timestamp;
435
- this.emit('joined');
436
- } else if (this.joinedAt < event.timestamp) {
437
- this.emit('rejoined', event.timestamp);
438
- } else {
439
- this.joinedAt = event.timestamp;
440
- logger.warn(`Client ${this.clientId} joinedAt timestamp was updated to ${event.timestamp}. the joined event will not be emitted.`);
441
- }
442
- }
443
- logger.debug('Client %s joined at %o', this.clientId, event);
444
- break;
445
- }
446
- case ClientEventTypes.CLIENT_LEFT: {
447
- if (event.timestamp) {
448
- if (!this.leftAt) {
449
- this.leftAt = event.timestamp;
450
- this.emit('left');
451
- } else {
452
- logger.warn(`Client ${this.clientId} leftAt timestamp was already set`);
453
- }
454
-
455
- }
456
- logger.debug('Client %s left at %o', this.clientId, event);
457
- break;
458
- }
459
- case ClientEventTypes.PEER_CONNECTION_OPENED: {
460
- const payload = parseJsonAs<Record<string, unknown>>(event.payload);
461
-
462
- if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string') {
463
- const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
464
-
465
- if (observedPeerConnection) {
466
- observedPeerConnection.openedAt = event.timestamp;
467
- } else if (postBuffer) {
468
- postBuffer.push(event);
469
- } else {
470
- logger.warn('Received PEER_CONNECTION_OPENED event without a corresponding observedPeerConnection: %o', event);
471
- }
472
-
473
- }
474
- break;
475
- }
476
- case ClientEventTypes.PEER_CONNECTION_CLOSED: {
477
- const payload = parseJsonAs<Record<string, unknown>>(event.payload);
478
-
479
- if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string') {
480
- const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
481
-
482
- if (observedPeerConnection) {
483
- observedPeerConnection.closedAt = event.timestamp;
484
- } else if (postBuffer) {
485
- postBuffer.push(event);
486
- } else {
487
- logger.warn('Received PEER_CONNECTION_CLOSED event without a corresponding observedPeerConnection: %o', event);
488
- }
489
- }
490
- break;
491
- }
492
- case ClientEventTypes.MEDIA_TRACK_ADDED: {
493
- const payload = parseJsonAs<Record<string, unknown>>(event.payload);
494
-
495
- if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string' && payload?.trackId && typeof payload.trackId === 'string') {
496
- const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
497
- const observedTrack = observedPeerConnection?.observedInboundTracks.get(payload.trackId) ?? observedPeerConnection?.observedOutboundTracks.get(payload.trackId);
498
-
499
- if (observedTrack) {
500
- observedTrack.addedAt = event.timestamp;
501
- } else if (postBuffer) {
502
- postBuffer.push(event);
503
- } else {
504
- logger.warn('Received MEDIA_TRACK_ADDED event without a corresponding observedPeerConnection or observedTrack: %o', event);
505
- }
506
- }
507
- break;
508
- }
509
- case ClientEventTypes.MEDIA_TRACK_REMOVED: {
510
- const payload = parseJsonAs<Record<string, unknown>>(event.payload);
511
-
512
- if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string' && payload?.trackId && typeof payload.trackId === 'string') {
513
- const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
514
- const observedTrack = observedPeerConnection?.observedInboundTracks.get(payload.trackId) ?? observedPeerConnection?.observedOutboundTracks.get(payload.trackId);
515
-
516
- if (observedTrack) {
517
- observedTrack.removedAt = event.timestamp;
518
- } else if (postBuffer) {
519
- postBuffer.push(event);
520
- } else {
521
- logger.warn('Received MEDIA_TRACK_REMOVED event without a corresponding observedPeerConnection or observedTrack: %o', event);
522
- }
523
- }
524
- break;
525
- }
526
- case ClientEventTypes.DATA_CHANNEL_OPEN: {
527
- const payload = parseJsonAs<Record<string, unknown>>(event.payload);
528
-
529
- if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string' && payload?.dataChannelId && typeof payload.dataChannelId === 'string') {
530
- const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
531
- const observedDataChannel = observedPeerConnection?.observedDataChannels.get(payload.dataChannelId);
532
-
533
- if (observedDataChannel) {
534
- observedDataChannel.addedAt = event.timestamp;
535
- } else if (postBuffer) {
536
- postBuffer.push(event);
537
- } else {
538
- logger.warn('Received DATA_CHANNEL_OPENED event without a corresponding observedPeerConnection or observedDataChannel: %o', event);
539
- }
540
- }
541
- break;
542
- }
543
- case ClientEventTypes.DATA_CHANNEL_CLOSED: {
544
- const payload = parseJsonAs<Record<string, unknown>>(event.payload);
545
-
546
- if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string' && payload?.dataChannelId && typeof payload.dataChannelId === 'string') {
547
- const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
548
- const observedDataChannel = observedPeerConnection?.observedDataChannels.get(payload.dataChannelId);
549
-
550
- if (observedDataChannel) {
551
- observedDataChannel.removedAt = event.timestamp;
552
- } else if (postBuffer) {
553
- postBuffer.push(event);
554
- } else {
555
- logger.warn('Received DATA_CHANNEL_CLOSE event without a corresponding observedPeerConnection or observedDataChannel: %o', event);
556
- }
557
- }
558
- break;
559
- }
560
- case ClientEventTypes.MEDIA_TRACK_MUTED: {
561
- const payload = parseJsonAs<Record<string, unknown>>(event.payload);
562
-
563
- if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string' && payload?.trackId && typeof payload.trackId === 'string') {
564
- const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
565
- const observedInboundTrack = observedPeerConnection?.observedInboundTracks.get(payload.trackId);
566
- const observedOutboundTrack = observedPeerConnection?.observedOutboundTracks.get(payload.trackId);
567
-
568
- if (observedPeerConnection) {
569
- if (observedInboundTrack) {
570
- observedInboundTrack.muted = true;
571
- observedPeerConnection?.emit('muted-inbound-track', observedInboundTrack);
572
- } else if (observedOutboundTrack) {
573
- observedOutboundTrack.muted = true;
574
- observedPeerConnection?.emit('muted-outbound-track', observedOutboundTrack);
575
- }
576
- } else if (postBuffer) {
577
- postBuffer.push(event);
578
- } else {
579
- logger.warn('Received MEDIA_TRACK_MUTED event without a corresponding observedPeerConnection or observedTrack: %o', event);
580
- }
581
- }
582
-
583
- break;
584
- }
585
- case ClientEventTypes.MEDIA_TRACK_UNMUTED: {
586
- const payload = parseJsonAs<Record<string, unknown>>(event.payload);
587
-
588
- if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string' && payload?.trackId && typeof payload.trackId === 'string') {
589
- const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
590
- const observedInboundTrack = observedPeerConnection?.observedInboundTracks.get(payload.trackId);
591
- const observedOutboundTrack = observedPeerConnection?.observedOutboundTracks.get(payload.trackId);
592
-
593
- if (observedPeerConnection) {
594
- if (observedInboundTrack) {
595
- observedInboundTrack.muted = false;
596
- observedPeerConnection?.emit('unmuted-inbound-track', observedInboundTrack);
597
- } else if (observedOutboundTrack) {
598
- observedOutboundTrack.muted = false;
599
- observedPeerConnection?.emit('unmuted-outbound-track', observedOutboundTrack);
600
- }
601
- } else if (postBuffer) {
602
- postBuffer.push(event);
603
- } else {
604
- logger.warn('Received MEDIA_TRACK_UNMUTED event without a corresponding observedPeerConnection or observedTrack: %o', event);
605
- }
606
- }
607
- break;
608
- }
609
- case ClientEventTypes.ICE_CONNECTION_STATE_CHANGED: {
610
- const payload = parseJsonAs<Record<string, unknown>>(event.payload);
611
-
612
- if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string' && payload?.iceConnectionState && typeof payload.iceConnectionState === 'string') {
613
- const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
614
-
615
- if (observedPeerConnection) {
616
- observedPeerConnection.iceConnectionState = payload.iceConnectionState as 'new' | 'checking' | 'connected' | 'completed' | 'failed' | 'disconnected' | 'closed';
617
- observedPeerConnection.emit('iceconnectionstatechange', {
618
- state: payload.iceConnectionState,
619
- });
620
- } else if (postBuffer) {
621
- postBuffer.push(event);
622
- } else {
623
- logger.warn('Received ICE_CONNECTION_STATE_CHANGED event without a corresponding observedPeerConnection: %o', event);
624
- }
625
- }
626
- break;
627
- }
628
- case ClientEventTypes.ICE_GATHERING_STATE_CHANGED: {
629
- const payload = parseJsonAs<Record<string, unknown>>(event.payload);
630
-
631
- if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string' && payload?.iceGatheringState && typeof payload.iceGatheringState === 'string') {
632
- const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
633
-
634
- if (observedPeerConnection) {
635
- observedPeerConnection.iceGatheringState = payload.iceGatheringState as 'new' | 'gathering' | 'complete';
636
- observedPeerConnection.emit('icegatheringstatechange', {
637
- state: payload.iceGatheringState,
638
- });
639
- } else if (postBuffer) {
640
- postBuffer.push(event);
641
- } else {
642
- logger.warn('Received ICE_GATHERING_STATE_CHANGED event without a corresponding observedPeerConnection: %o', event);
643
- }
644
- }
645
- break;
646
- }
647
- case ClientEventTypes.PEER_CONNECTION_STATE_CHANGED: {
648
- const payload = parseJsonAs<Record<string, unknown>>(event.payload);
649
-
650
- if (payload?.peerConnectionId && typeof payload.peerConnectionId === 'string' && payload?.peerConnectionState && typeof payload.peerConnectionState === 'string') {
651
- const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
652
-
653
- if (observedPeerConnection) {
654
- observedPeerConnection.connectionState = payload.peerConnectionState as 'new' | 'connecting' | 'connected' | 'disconnected' | 'failed' | 'closed';
655
- observedPeerConnection.emit('connectionstatechange', {
656
- state: payload.peerConnectionState,
657
- });
658
- } else if (postBuffer) {
659
- postBuffer.push(event);
660
- } else {
661
- logger.warn('Received PEER_CONNECTION_STATE_CHANGED event without a corresponding observedPeerConnection: %o', event);
662
- }
663
- }
664
- break;
665
- }
666
- }
667
-
668
- this.emit('clientEvent', event);
669
- }
670
-
671
- public injectMetaData(metaData: ClientMetaData) {
672
- if (this.closed) return;
673
-
674
- if (!this._injections.clientMetaItems) this._injections.clientMetaItems = [];
675
-
676
- this._injections.clientMetaItems.push(metaData);
677
- }
678
-
679
- public injectEvent(event: ClientEvent) {
680
- if (this.closed) return;
681
-
682
- if (!this._injections.clientEvents) this._injections.clientEvents = [];
683
-
684
- this._injections.clientEvents.push(event);
685
- }
686
-
687
- public injectIssue(issue: ClientIssue) {
688
- if (this.closed) return;
689
-
690
- if (!this._injections.clientIssues) this._injections.clientIssues = [];
691
-
692
- this._injections.clientIssues.push(issue);
693
- }
694
-
695
- public injectExtensionStat(stat: ExtensionStat) {
696
- if (this.closed) return;
697
-
698
- if (!this._injections.extensionStats) this._injections.extensionStats = [];
699
-
700
- this._injections.extensionStats.push(stat);
701
- }
702
-
703
- public injectAttachment(key: string, value: unknown) {
704
- if (this.closed) return;
705
-
706
- if (!this._injections.attachments) this._injections.attachments = {};
707
-
708
- this._injections.attachments[key] = value;
709
-
710
- }
711
-
712
- public addMetadata(metadata: ClientMetaData) {
713
- if (this.closed) return;
714
-
715
- switch (metadata.type) {
716
- case ClientMetaTypes.BROWSER: {
717
- this.browser = parseJsonAs(metadata.payload);
718
- break;
719
- }
720
- case ClientMetaTypes.ENGINE: {
721
- this.engine = parseJsonAs(metadata.payload);
722
- break;
723
- }
724
- case ClientMetaTypes.PLATFORM: {
725
- this.platform = parseJsonAs(metadata.payload);
726
- break;
727
- }
728
- case ClientMetaTypes.OPERATION_SYSTEM: {
729
- this.operationSystem = parseJsonAs(metadata.payload);
730
- break;
731
- }
732
- }
733
-
734
- this.call.observer.emit('client-metadata', this, metadata);
735
- }
736
-
737
- public addIssue(issue: ClientIssue) {
738
- if (this.closed) return;
739
-
740
- this.report.issues[issue.type] = (this.report.issues[issue.type] ?? 0) + 1;
741
-
742
- this.emit('issue', issue);
743
- this.call.observer.emit('client-issue', this, issue);
744
- }
745
-
746
- public addExtensionStats(stats: ExtensionStat) {
747
- this.call.observer.emit('client-extension-stats', this, stats);
748
- this.emit('extensionStats', stats);
749
- }
750
-
751
- private _updatePeerConnection(sample: PeerConnectionSample): ObservedPeerConnection | undefined {
752
- let observedPeerConnection = this.observedPeerConnections.get(sample.peerConnectionId);
753
-
754
- if (!observedPeerConnection) {
755
- if (!sample.peerConnectionId) {
756
- return (logger.warn(
757
- `ObservedClient received an invalid PeerConnectionSample (missing peerConnectionId field). ClientId: ${this.clientId}, CallId: ${this.call.callId}`,
758
- sample
759
- ), void 0);
760
- }
761
-
762
- const newObservedPeerConnection = new ObservedPeerConnection(sample.peerConnectionId, this);
763
- const onInboundTrackRemoved = (track: ObservedInboundTrack) => {
764
- this.emit('trackreport', {
765
- direction: 'inbound',
766
- ...track.report,
767
- });
768
- };
769
- const onOutboundTrackRemoved = (track: ObservedOutboundTrack) => {
770
- this.emit('trackreport', {
771
- direction: 'outbound',
772
- ...track.report,
773
- });
774
- };
775
-
776
- newObservedPeerConnection.once('close', () => {
777
- newObservedPeerConnection?.off('removed-inbound-track', onInboundTrackRemoved);
778
- newObservedPeerConnection?.off('removed-outbound-track', onOutboundTrackRemoved);
779
- this.observedPeerConnections.delete(sample.peerConnectionId);
780
- });
781
- newObservedPeerConnection.on('removed-inbound-track', onInboundTrackRemoved);
782
- newObservedPeerConnection.on('removed-outbound-track', onOutboundTrackRemoved);
783
- this.observedPeerConnections.set(sample.peerConnectionId, newObservedPeerConnection);
784
-
785
- this.emit('newpeerconnection', newObservedPeerConnection);
786
-
787
- observedPeerConnection = newObservedPeerConnection;
788
- }
789
-
790
- observedPeerConnection.accept(sample);
791
-
792
- return observedPeerConnection;
793
- }
794
-
795
- private _mergeInjections(sample: ClientSample): ClientSample {
796
- if (this.closed) return sample;
797
-
798
- if (this._injections.clientEvents) {
799
- if (!sample.clientEvents) sample.clientEvents = [];
800
- sample.clientEvents.push(...this._injections.clientEvents);
801
-
802
- this._injections.clientEvents = undefined;
803
- }
804
-
805
- if (this._injections.clientIssues) {
806
- if (!sample.clientIssues) sample.clientIssues = [];
807
- sample.clientIssues.push(...this._injections.clientIssues);
808
-
809
- this._injections.clientIssues = undefined;
810
- }
811
-
812
- if (this._injections.extensionStats) {
813
- if (!sample.extensionStats) sample.extensionStats = [];
814
- sample.extensionStats.push(...this._injections.extensionStats);
815
-
816
- this._injections.extensionStats = undefined;
817
- }
818
-
819
- if (this._injections.attachments) {
820
- if (!sample.attachments) sample.attachments = {};
821
- Object.assign(sample.attachments, this._injections.attachments);
822
-
823
- this._injections.attachments = undefined;
824
- }
825
-
826
- if (this._injections.clientMetaItems) {
827
- if (!sample.clientMetaItems) sample.clientMetaItems = [];
828
- sample.clientMetaItems.push(...this._injections.clientMetaItems);
829
-
830
- this._injections.clientMetaItems = undefined;
831
- }
832
-
833
- return sample;
834
- }
835
-
836
- // public resetSummaryMetrics() {
837
- // this.totalDataChannelBytesReceived = 0;
838
- // this.totalDataChannelBytesSent = 0;
839
- // this.totalDataChannelMessagesReceived = 0;
840
- // this.totalDataChannelMessagesSent = 0;
841
- // this.totalInboundPacketsLost = 0;
842
- // this.totalInboundPacketsReceived = 0;
843
- // this.totalOutboundPacketsSent = 0;
844
- // this.totalReceivedAudioBytes = 0;
845
- // this.totalReceivedVideoBytes = 0;
846
- // this.totalSentAudioBytes = 0;
847
- // this.totalSentVideoBytes = 0;
848
- // this.totalSentBytes = 0;
849
- // this.totalReceivedBytes = 0;
850
-
851
- // this.totalNumberOfIssues = 0;
852
-
853
- // this.totalScoreSum = 0;
854
- // this.numberOfScoreMeasurements = 0;
855
- // }
856
-
857
- // public createSummary(): ObservedClientSummary {
858
- // return {
859
- // totalRttLt50Measurements: this.totalRttLt50Measurements,
860
- // totalRttLt150Measurements: this.totalRttLt150Measurements,
861
- // totalRttLt300Measurements: this.totalRttLt300Measurements,
862
- // totalRttGtOrEq300Measurements: this.totalRttGtOrEq300Measurements,
863
- // totalDataChannelBytesReceived: this.totalDataChannelBytesReceived,
864
- // totalDataChannelBytesSent: this.totalDataChannelBytesSent,
865
- // totalDataChannelMessagesReceived: this.totalDataChannelMessagesReceived,
866
- // totalDataChannelMessagesSent: this.totalDataChannelMessagesSent,
867
- // totalInboundPacketsLost: this.totalInboundPacketsLost,
868
- // totalInboundPacketsReceived: this.totalInboundPacketsReceived,
869
- // totalOutboundPacketsSent: this.totalOutboundPacketsSent,
870
- // totalReceivedAudioBytes: this.totalReceivedAudioBytes,
871
- // totalReceivedVideoBytes: this.totalReceivedVideoBytes,
872
- // totalSentAudioBytes: this.totalSentAudioBytes,
873
- // totalSentVideoBytes: this.totalSentVideoBytes,
874
- // totalSentBytes: this.totalSentBytes,
875
- // totalReceivedBytes: this.totalReceivedBytes,
876
-
877
- // numberOfIssues: this.totalNumberOfIssues,
878
-
879
- // totalScoreSum: this.totalScoreSum,
880
- // numberOfScoreMeasurements: this.numberOfScoreMeasurements,
881
- // };
882
- // }
883
- }