@observertc/observer-js 1.0.1-f31d7a4.0 → 1.1.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 (174) hide show
  1. package/README.md +2184 -1
  2. package/dist/index.d.mts +6842 -0
  3. package/dist/index.d.ts +6842 -0
  4. package/dist/index.js +7736 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/index.mjs +7608 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/package.json +44 -18
  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 -62
  14. package/lib/ObservedCall.d.ts.map +0 -1
  15. package/lib/ObservedCall.js +0 -127
  16. package/lib/ObservedCertificate.d.ts +0 -19
  17. package/lib/ObservedCertificate.d.ts.map +0 -1
  18. package/lib/ObservedCertificate.js +0 -38
  19. package/lib/ObservedClient.d.ts +0 -104
  20. package/lib/ObservedClient.d.ts.map +0 -1
  21. package/lib/ObservedClient.js +0 -250
  22. package/lib/ObservedCodec.d.ts +0 -22
  23. package/lib/ObservedCodec.d.ts.map +0 -1
  24. package/lib/ObservedCodec.js +0 -45
  25. package/lib/ObservedDataChannel.d.ts +0 -28
  26. package/lib/ObservedDataChannel.d.ts.map +0 -1
  27. package/lib/ObservedDataChannel.js +0 -73
  28. package/lib/ObservedIceCandidate.d.ts +0 -29
  29. package/lib/ObservedIceCandidate.d.ts.map +0 -1
  30. package/lib/ObservedIceCandidate.js +0 -59
  31. package/lib/ObservedIceCandidatePair.d.ts +0 -44
  32. package/lib/ObservedIceCandidatePair.d.ts.map +0 -1
  33. package/lib/ObservedIceCandidatePair.js +0 -111
  34. package/lib/ObservedIceTransport.d.ts +0 -32
  35. package/lib/ObservedIceTransport.d.ts.map +0 -1
  36. package/lib/ObservedIceTransport.js +0 -65
  37. package/lib/ObservedInboundRtp.d.ts +0 -92
  38. package/lib/ObservedInboundRtp.d.ts.map +0 -1
  39. package/lib/ObservedInboundRtp.js +0 -193
  40. package/lib/ObservedInboundTrack.d.ts +0 -29
  41. package/lib/ObservedInboundTrack.d.ts.map +0 -1
  42. package/lib/ObservedInboundTrack.js +0 -57
  43. package/lib/ObservedMediaPlayout.d.ts +0 -22
  44. package/lib/ObservedMediaPlayout.d.ts.map +0 -1
  45. package/lib/ObservedMediaPlayout.js +0 -42
  46. package/lib/ObservedMediaSource.d.ts +0 -28
  47. package/lib/ObservedMediaSource.d.ts.map +0 -1
  48. package/lib/ObservedMediaSource.js +0 -55
  49. package/lib/ObservedOutboundRtp.d.ts +0 -62
  50. package/lib/ObservedOutboundRtp.d.ts.map +0 -1
  51. package/lib/ObservedOutboundRtp.js +0 -144
  52. package/lib/ObservedOutboundTrack.d.ts +0 -29
  53. package/lib/ObservedOutboundTrack.d.ts.map +0 -1
  54. package/lib/ObservedOutboundTrack.js +0 -57
  55. package/lib/ObservedPeerConnection.d.ts +0 -183
  56. package/lib/ObservedPeerConnection.d.ts.map +0 -1
  57. package/lib/ObservedPeerConnection.js +0 -688
  58. package/lib/ObservedPeerConnectionTransport.d.ts +0 -17
  59. package/lib/ObservedPeerConnectionTransport.d.ts.map +0 -1
  60. package/lib/ObservedPeerConnectionTransport.js +0 -34
  61. package/lib/ObservedRemoteInboundRtp.d.ts +0 -30
  62. package/lib/ObservedRemoteInboundRtp.d.ts.map +0 -1
  63. package/lib/ObservedRemoteInboundRtp.js +0 -60
  64. package/lib/ObservedRemoteOutboundRtp.d.ts +0 -30
  65. package/lib/ObservedRemoteOutboundRtp.d.ts.map +0 -1
  66. package/lib/ObservedRemoteOutboundRtp.js +0 -60
  67. package/lib/ObservedTURN.d.ts +0 -30
  68. package/lib/ObservedTURN.d.ts.map +0 -1
  69. package/lib/ObservedTURN.js +0 -54
  70. package/lib/ObservedTurnServer.d.ts +0 -25
  71. package/lib/ObservedTurnServer.d.ts.map +0 -1
  72. package/lib/ObservedTurnServer.js +0 -59
  73. package/lib/Observer.d.ts +0 -50
  74. package/lib/Observer.d.ts.map +0 -1
  75. package/lib/Observer.js +0 -101
  76. package/lib/common/Middleware.d.ts +0 -17
  77. package/lib/common/Middleware.d.ts.map +0 -1
  78. package/lib/common/Middleware.js +0 -60
  79. package/lib/common/SingleExecutor.d.ts +0 -3
  80. package/lib/common/SingleExecutor.d.ts.map +0 -1
  81. package/lib/common/SingleExecutor.js +0 -31
  82. package/lib/common/logger.d.ts +0 -17
  83. package/lib/common/logger.d.ts.map +0 -1
  84. package/lib/common/logger.js +0 -50
  85. package/lib/common/types.d.ts +0 -3
  86. package/lib/common/types.d.ts.map +0 -1
  87. package/lib/common/types.js +0 -3
  88. package/lib/common/utils.d.ts +0 -10
  89. package/lib/common/utils.d.ts.map +0 -1
  90. package/lib/common/utils.js +0 -55
  91. package/lib/detectors/Detector.d.ts +0 -5
  92. package/lib/detectors/Detector.d.ts.map +0 -1
  93. package/lib/detectors/Detector.js +0 -3
  94. package/lib/detectors/Detectors.d.ts +0 -11
  95. package/lib/detectors/Detectors.d.ts.map +0 -1
  96. package/lib/detectors/Detectors.js +0 -34
  97. package/lib/index.d.ts +0 -26
  98. package/lib/index.d.ts.map +0 -1
  99. package/lib/index.js +0 -41
  100. package/lib/monitors/TurnUsageMonitor.d.ts +0 -1
  101. package/lib/monitors/TurnUsageMonitor.d.ts.map +0 -1
  102. package/lib/monitors/TurnUsageMonitor.js +0 -146
  103. package/lib/schema/ClientEventTypes.d.ts +0 -33
  104. package/lib/schema/ClientEventTypes.d.ts.map +0 -1
  105. package/lib/schema/ClientEventTypes.js +0 -38
  106. package/lib/schema/ClientMetaTypes.d.ts +0 -34
  107. package/lib/schema/ClientMetaTypes.d.ts.map +0 -1
  108. package/lib/schema/ClientMetaTypes.js +0 -16
  109. package/lib/schema/ClientSample.d.ts +0 -1333
  110. package/lib/schema/ClientSample.d.ts.map +0 -1
  111. package/lib/schema/ClientSample.js +0 -4
  112. package/lib/scores/CalculatedScore.d.ts +0 -6
  113. package/lib/scores/CalculatedScore.d.ts.map +0 -1
  114. package/lib/scores/CalculatedScore.js +0 -2
  115. package/lib/scores/DefaultCallScoreCalculator.d.ts +0 -7
  116. package/lib/scores/DefaultCallScoreCalculator.d.ts.map +0 -1
  117. package/lib/scores/DefaultCallScoreCalculator.js +0 -21
  118. package/lib/scores/ScoreCalculator.d.ts +0 -4
  119. package/lib/scores/ScoreCalculator.d.ts.map +0 -1
  120. package/lib/scores/ScoreCalculator.js +0 -2
  121. package/lib/utils/CallUpdater.d.ts +0 -5
  122. package/lib/utils/CallUpdater.d.ts.map +0 -1
  123. package/lib/utils/CallUpdater.js +0 -2
  124. package/lib/utils/OnAllClientCallUpdater.d.ts +0 -16
  125. package/lib/utils/OnAllClientCallUpdater.d.ts.map +0 -1
  126. package/lib/utils/OnAllClientCallUpdater.js +0 -58
  127. package/lib/utils/RemoteTrackResolver.d.ts +0 -7
  128. package/lib/utils/RemoteTrackResolver.d.ts.map +0 -1
  129. package/lib/utils/RemoteTrackResolver.js +0 -2
  130. package/lib/utils/onAnyClientCallUpdater.d.ts +0 -14
  131. package/lib/utils/onAnyClientCallUpdater.d.ts.map +0 -1
  132. package/lib/utils/onAnyClientCallUpdater.js +0 -51
  133. package/src/ObservedCall.ts +0 -176
  134. package/src/ObservedCertificate.ts +0 -43
  135. package/src/ObservedClient.ts +0 -324
  136. package/src/ObservedCodec.ts +0 -49
  137. package/src/ObservedDataChannel.ts +0 -82
  138. package/src/ObservedIceCandidate.ts +0 -64
  139. package/src/ObservedIceCandidatePair.ts +0 -118
  140. package/src/ObservedIceTransport.ts +0 -70
  141. package/src/ObservedInboundRtp.ts +0 -205
  142. package/src/ObservedInboundTrack.ts +0 -70
  143. package/src/ObservedMediaPlayout.ts +0 -49
  144. package/src/ObservedMediaSource.ts +0 -60
  145. package/src/ObservedOutboundRtp.ts +0 -156
  146. package/src/ObservedOutboundTrack.ts +0 -69
  147. package/src/ObservedPeerConnection.ts +0 -995
  148. package/src/ObservedPeerConnectionTransport.ts +0 -38
  149. package/src/ObservedRemoteInboundRtp.ts +0 -64
  150. package/src/ObservedRemoteOutboundRtp.ts +0 -65
  151. package/src/ObservedTURN.ts +0 -80
  152. package/src/ObservedTurnServer.ts +0 -72
  153. package/src/Observer.ts +0 -152
  154. package/src/common/Middleware.ts +0 -84
  155. package/src/common/SingleExecutor.ts +0 -36
  156. package/src/common/logger.ts +0 -82
  157. package/src/common/types.ts +0 -4
  158. package/src/common/utils.ts +0 -59
  159. package/src/detectors/Detector.ts +0 -6
  160. package/src/detectors/Detectors.ts +0 -38
  161. package/src/index.ts +0 -27
  162. package/src/monitors/TurnUsageMonitor.ts +0 -187
  163. package/src/schema/ClientEventTypes.ts +0 -36
  164. package/src/schema/ClientMetaTypes.ts +0 -41
  165. package/src/schema/ClientSample.ts +0 -1682
  166. package/src/scores/CalculatedScore.ts +0 -6
  167. package/src/scores/DefaultCallScoreCalculator.ts +0 -23
  168. package/src/scores/ScoreCalculator.ts +0 -3
  169. package/src/utils/CallUpdater.ts +0 -5
  170. package/src/utils/OnAllClientCallUpdater.ts +0 -68
  171. package/src/utils/RemoteTrackResolver.ts +0 -12
  172. package/src/utils/onAnyClientCallUpdater.ts +0 -59
  173. package/tsconfig.json +0 -19
  174. package/tslint.json +0 -6
@@ -1,995 +0,0 @@
1
- import { EventEmitter } from 'events';
2
- import { ObservedClient } from './ObservedClient';
3
- import { CertificateStats, CodecStats, DataChannelStats, IceCandidateStats, InboundRtpStats, InboundTrackSample, MediaPlayoutStats, MediaSourceStats, OutboundRtpStats, OutboundTrackSample, PeerConnectionSample, PeerConnectionTransportStats, RemoteInboundRtpStats, RemoteOutboundRtpStats } from './schema/ClientSample';
4
- import { ObservedInboundRtp } from './ObservedInboundRtp';
5
- import { createLogger } from './common/logger';
6
- import { MediaKind } from './common/types';
7
- import { ObservedOutboundRtp } from './ObservedOutboundRtp';
8
- import { ObservedCertificate } from './ObservedCertificate';
9
- import { ObservedCodec } from './ObservedCodec';
10
- import { ObservedDataChannel } from './ObservedDataChannel';
11
- import { ObservedIceCandidate } from './ObservedIceCandidate';
12
- import { ObservedIceCandidatePair } from './ObservedIceCandidatePair';
13
- import { ObservedIceTransport } from './ObservedIceTransport';
14
- import { ObservedMediaSource } from './ObservedMediaSource';
15
- import { ObservedPeerConnectionTransport } from './ObservedPeerConnectionTransport';
16
- import { ObservedMediaPlayout } from './ObservedMediaPlayout';
17
- import { ObservedRemoteInboundRtp } from './ObservedRemoteInboundRtp';
18
- import { ObservedRemoteOutboundRtp } from './ObservedRemoteOutboundRtp';
19
- import { ObservedInboundTrack } from './ObservedInboundTrack';
20
- import { ObservedOutboundTrack } from './ObservedOutboundTrack';
21
- import { CalculatedScore } from './scores/CalculatedScore';
22
- import { ObservedTurnServer } from './ObservedTurnServer';
23
-
24
- const logger = createLogger('ObservedPeerConnection');
25
-
26
- export type ObservedPeerConnectionEvents = {
27
- iceconnectionstatechange: [
28
- {
29
- state: string;
30
- }
31
- ];
32
- icegatheringstatechange: [
33
- {
34
- state: string;
35
- }
36
- ];
37
- connectionstatechange: [
38
- {
39
- state: string;
40
- }
41
- ];
42
- selectedcandidatepair: [];
43
-
44
- 'added-certificate': [ObservedCertificate];
45
- 'added-codec': [ObservedCodec];
46
- 'added-data-channel': [ObservedDataChannel];
47
- 'added-ice-candidate': [ObservedIceCandidate];
48
- 'added-ice-candidate-pair': [ObservedIceCandidatePair];
49
- 'added-ice-transport': [ObservedIceTransport];
50
- 'added-inbound-rtp': [ObservedInboundRtp];
51
- 'added-inbound-track': [ObservedInboundTrack];
52
- 'added-media-playout': [ObservedMediaPlayout];
53
- 'added-media-source': [ObservedMediaSource];
54
- 'added-outbound-rtp': [ObservedOutboundRtp];
55
- 'added-outbound-track': [ObservedOutboundTrack];
56
- 'added-peer-connection-transport': [ObservedPeerConnectionTransport];
57
- 'added-remote-inbound-rtp': [ObservedRemoteInboundRtp];
58
- 'added-remote-outbound-rtp': [ObservedRemoteOutboundRtp];
59
- 'removed-certificate': [ObservedCertificate];
60
- 'removed-codec': [ObservedCodec];
61
- 'removed-data-channel': [ObservedDataChannel];
62
- 'removed-ice-candidate': [ObservedIceCandidate];
63
- 'removed-ice-candidate-pair': [ObservedIceCandidatePair];
64
- 'removed-ice-transport': [ObservedIceTransport];
65
- 'removed-inbound-rtp': [ObservedInboundRtp];
66
- 'removed-inbound-track': [ObservedInboundTrack];
67
- 'removed-media-playout': [ObservedMediaPlayout];
68
- 'removed-media-source': [ObservedMediaSource];
69
- 'removed-outbound-rtp': [ObservedOutboundRtp];
70
- 'removed-outbound-track': [ObservedOutboundTrack];
71
- 'removed-peer-connection-transport': [ObservedPeerConnectionTransport];
72
- 'removed-remote-inbound-rtp': [ObservedRemoteInboundRtp];
73
- 'removed-remote-outbound-rtp': [ObservedRemoteOutboundRtp];
74
- 'update': [],
75
- close: [];
76
- };
77
-
78
- export declare interface ObservedPeerConnection {
79
- on<U extends keyof ObservedPeerConnectionEvents>(
80
- event: U,
81
- listener: (...args: ObservedPeerConnectionEvents[U]) => void
82
- ): this;
83
- off<U extends keyof ObservedPeerConnectionEvents>(
84
- event: U,
85
- listener: (...args: ObservedPeerConnectionEvents[U]) => void
86
- ): this;
87
- once<U extends keyof ObservedPeerConnectionEvents>(
88
- event: U,
89
- listener: (...args: ObservedPeerConnectionEvents[U]) => void
90
- ): this;
91
- emit<U extends keyof ObservedPeerConnectionEvents>(event: U, ...args: ObservedPeerConnectionEvents[U]): boolean;
92
- }
93
-
94
- export class ObservedPeerConnection extends EventEmitter {
95
- private _visited = true;
96
-
97
- public appData?: Record<string, unknown>;
98
- public readonly calculatedScore: CalculatedScore = {
99
- weight: 1,
100
- value: undefined,
101
- };
102
-
103
- public closed = false;
104
- // timestamp of the PEER_CONNECTION_OPENED event
105
- public openedAt?: number;
106
- // timestamp of the PEER_CONNECTION_CLOSED event
107
- public closedAt?: number;
108
- public updated = Date.now();
109
-
110
- public availableIncomingBitrate = 0;
111
- public availableOutgoingBitrate = 0;
112
- public totalInboundPacketsLost = 0;
113
- public totalInboundPacketsReceived = 0;
114
- public totalOutboundPacketsSent = 0;
115
- public totalDataChannelBytesSent = 0;
116
- public totalDataChannelBytesReceived = 0;
117
- public totalDataChannelMessagesSent = 0;
118
- public totalDataChannelMessagesReceived = 0;
119
-
120
- public totalSentAudioBytes = 0;
121
- public totalSentVideoBytes = 0;
122
- public totalSentAudioPackets = 0;
123
- public totalSentVideoPackets = 0;
124
- public totalReceivedAudioPacktes = 0;
125
- public totalReceivedVideoPackets = 0;
126
- public totalReceivedAudioBytes = 0;
127
- public totalReceivedVideoBytes = 0;
128
-
129
- public deltaInboundPacketsLost = 0;
130
- public deltaInboundPacketsReceived = 0;
131
- public deltaOutboundPacketsSent = 0;
132
- public deltaDataChannelBytesSent = 0;
133
- public deltaDataChannelBytesReceived = 0;
134
- public deltaDataChannelMessagesSent = 0;
135
- public deltaDataChannelMessagesReceived = 0;
136
- public deltaInboundReceivedBytes = 0;
137
- public deltaOutboundSentBytes = 0;
138
-
139
- public deltaReceivedAudioBytes = 0;
140
- public deltaReceivedVideoBytes = 0;
141
- public deltaReceivedAudioPackets = 0;
142
- public deltaReceivedVideoPackets = 0;
143
- public deltaSentAudioBytes = 0;
144
- public deltaSentVideoBytes = 0;
145
-
146
- public receivingPacketsPerSecond = 0;
147
- public sendingPacketsPerSecond = 0;
148
- public sendingAudioBitrate = 0;
149
- public sendingVideoBitrate = 0;
150
- public receivingAudioBitrate = 0;
151
- public receivingVideoBitrate = 0;
152
-
153
- public avgRttInMs?: number;
154
- public avgJitter?: number;
155
-
156
- public usingTCP = false;
157
- public usingTURN = false;
158
-
159
- public observedTurnServer?: ObservedTurnServer;
160
- public readonly observedCertificates = new Map<string, ObservedCertificate>();
161
- public readonly observedCodecs = new Map<string, ObservedCodec>();
162
- public readonly observedDataChannels = new Map<string, ObservedDataChannel>();
163
- public readonly observedIceCandidates = new Map<string, ObservedIceCandidate>();
164
- public readonly observedIceCandidatesPair = new Map<string, ObservedIceCandidatePair>();
165
- public readonly observedIceTransports = new Map<string, ObservedIceTransport>();
166
- public readonly observedInboundRtps = new Map<number, ObservedInboundRtp>();
167
- public readonly observedInboundTracks = new Map<string, ObservedInboundTrack>();
168
- public readonly observedMediaPlayouts = new Map<string, ObservedMediaPlayout>();
169
- public readonly observedMediaSources = new Map<string, ObservedMediaSource>();
170
- public readonly observedOutboundRtps = new Map<number, ObservedOutboundRtp>();
171
- public readonly observedOutboundTracks = new Map<string, ObservedOutboundTrack>();
172
- public readonly observedPeerConnectionTransports = new Map<string, ObservedPeerConnectionTransport>();
173
- public readonly observedRemoteInboundRtps = new Map<number, ObservedRemoteInboundRtp>();
174
- public readonly observedRemoteOutboundRtps = new Map<number, ObservedRemoteOutboundRtp>();
175
-
176
- public constructor(public readonly peerConnectionId: string, public readonly client: ObservedClient) {
177
- super();
178
- this.setMaxListeners(Infinity);
179
- }
180
-
181
- public get score() {
182
- return this.calculatedScore.value;
183
- }
184
-
185
- public get visited() {
186
- const visited = this._visited;
187
-
188
- this._visited = false;
189
-
190
- return visited;
191
- }
192
-
193
- public get codecs() {
194
- return [ ...this.observedCodecs.values() ];
195
- }
196
-
197
- public get inboundRtps() {
198
- return [ ...this.observedInboundRtps.values() ];
199
- }
200
-
201
- public get remoteOutboundRtps() {
202
- return [ ...this.observedRemoteOutboundRtps.values() ];
203
- }
204
-
205
- public get outboundRtps() {
206
- return [ ...this.observedOutboundRtps.values() ];
207
- }
208
-
209
- public get remoteInboundRtps() {
210
- return [ ...this.observedRemoteInboundRtps.values() ];
211
- }
212
-
213
- public get mediaSources() {
214
- return [ ...this.observedMediaSources.values() ];
215
- }
216
-
217
- public get mediaPlayouts() {
218
- return [ ...this.observedMediaPlayouts.values() ];
219
- }
220
-
221
- public get dataChannels() {
222
- return [ ...this.observedDataChannels.values() ];
223
- }
224
-
225
- public get peerConnectionTransports() {
226
- return [ ...this.observedPeerConnectionTransports.values() ];
227
- }
228
-
229
- public get iceTransports() {
230
- return [ ...this.observedIceTransports.values() ];
231
- }
232
-
233
- public get iceCandidates() {
234
- return [ ...this.observedIceCandidates.values() ];
235
- }
236
-
237
- public get iceCandidatePairs() {
238
- return [ ...this.observedIceCandidatesPair.values() ];
239
- }
240
-
241
- public get certificates() {
242
- return [ ...this.observedCertificates.values() ];
243
- }
244
-
245
- public get selectedIceCandidatePairs() {
246
- return this.iceTransports.map((iceTransport) => iceTransport.getSelectedCandidatePair())
247
- .filter((pair) => pair !== undefined) as ObservedIceCandidatePair[];
248
- }
249
-
250
- public get selectedIceCandiadtePairForTurn() {
251
- return this.selectedIceCandidatePairs
252
- .filter((pair) =>
253
- pair.getLocalCandidate()?.candidateType === 'relay' &&
254
- pair.getRemoteCandidate()?.url?.startsWith('turn:')
255
- );
256
- }
257
-
258
- public close() {
259
- if (this.closed) return;
260
- this.closed = true;
261
-
262
- this.observedCertificates.clear();
263
- this.observedCodecs.clear();
264
- this.observedDataChannels.clear();
265
- this.observedIceCandidates.clear();
266
- this.observedIceCandidatesPair.clear();
267
- this.observedIceTransports.clear();
268
- this.observedInboundRtps.clear();
269
- this.observedInboundTracks.clear();
270
- this.observedMediaPlayouts.clear();
271
- this.observedMediaSources.clear();
272
- this.observedOutboundRtps.clear();
273
- this.observedOutboundTracks.clear();
274
- this.observedPeerConnectionTransports.clear();
275
- this.observedRemoteInboundRtps.clear();
276
- this.observedRemoteOutboundRtps.clear();
277
-
278
- this.client.call.observer.observedTURN.removePeerConnection(this);
279
-
280
- this.emit('close');
281
- }
282
-
283
- public accept(sample: PeerConnectionSample) {
284
- if (this.closed) return;
285
- this._visited = true;
286
-
287
- this.availableIncomingBitrate = 0;
288
- this.availableOutgoingBitrate = 0;
289
- this.deltaInboundPacketsLost = 0;
290
- this.deltaInboundPacketsReceived = 0;
291
- this.deltaOutboundPacketsSent = 0;
292
- this.deltaDataChannelBytesSent = 0;
293
- this.deltaDataChannelBytesReceived = 0;
294
- this.deltaInboundReceivedBytes = 0;
295
- this.deltaOutboundSentBytes = 0;
296
- this.deltaReceivedAudioBytes = 0;
297
- this.deltaReceivedVideoBytes = 0;
298
- this.deltaReceivedAudioPackets = 0;
299
- this.deltaReceivedVideoPackets = 0;
300
- this.deltaSentAudioBytes = 0;
301
- this.deltaSentVideoBytes = 0;
302
- this.sendingAudioBitrate = 0;
303
- this.sendingVideoBitrate = 0;
304
- this.receivingAudioBitrate = 0;
305
- this.receivingVideoBitrate = 0;
306
-
307
- const now = Date.now();
308
- const elapsedTimeInMs = now - this.updated;
309
- const elapsedTimeInSec = elapsedTimeInMs / 1000;
310
- const rttMeasurementsInSec: number[] = [];
311
- const jitterMeasurements: number[] = [];
312
-
313
- if (sample.certificates) {
314
- for (const certificate of sample.certificates) {
315
- this._updateCertificateStats(certificate);
316
- }
317
- }
318
- if (sample.codecs) {
319
- for (const codec of sample.codecs) {
320
- this._updateCodecStats(codec);
321
- }
322
- }
323
- if (sample.dataChannels) {
324
- for (const dataChannel of sample.dataChannels) {
325
- const observedDataChannel = this._updateDataChannelStats(dataChannel);
326
-
327
- if (!observedDataChannel) continue;
328
-
329
- this.deltaDataChannelBytesSent += observedDataChannel.deltaBytesSent;
330
- this.deltaDataChannelBytesReceived += observedDataChannel.deltaBytesReceived;
331
- this.deltaDataChannelMessagesSent += observedDataChannel.deltaMessagesSent;
332
- this.deltaDataChannelMessagesReceived += observedDataChannel.deltaMessagesReceived;
333
- }
334
- }
335
- if (sample.iceCandidates) {
336
- for (const iceCandidate of sample.iceCandidates) {
337
- this._updateIceCandidateStats(iceCandidate);
338
- }
339
- }
340
- if (sample.iceCandidatePairs) {
341
- for (const iceCandidatePair of sample.iceCandidatePairs) {
342
- const observedCandidatePair = this._updateIceCandidatePairStats(iceCandidatePair);
343
-
344
- if (!observedCandidatePair) continue;
345
-
346
- if (observedCandidatePair.currentRoundTripTime) {
347
- rttMeasurementsInSec.push(observedCandidatePair.currentRoundTripTime);
348
- }
349
- if (observedCandidatePair.availableIncomingBitrate) {
350
- this.availableIncomingBitrate += observedCandidatePair.availableIncomingBitrate;
351
- }
352
- if (observedCandidatePair.availableOutgoingBitrate) {
353
- this.availableOutgoingBitrate += observedCandidatePair.availableOutgoingBitrate;
354
- }
355
- }
356
- }
357
- if (sample.iceTransports) {
358
- for (const iceTransport of sample.iceTransports) {
359
- this._updateIceTransportStats(iceTransport);
360
- }
361
- }
362
- if (sample.inboundRtps) {
363
- for (const inboundRtp of sample.inboundRtps) {
364
- const observedInboundRtp = this._updateInboundRtpStats(inboundRtp);
365
-
366
- if (!observedInboundRtp) continue;
367
-
368
- this.deltaInboundPacketsLost += observedInboundRtp.deltaLostPackets;
369
- this.deltaInboundPacketsReceived += observedInboundRtp.deltaReceivedPackets;
370
- this.deltaInboundReceivedBytes += observedInboundRtp.deltaBytesReceived;
371
-
372
- switch (inboundRtp.kind) {
373
- case 'audio':
374
- this.deltaReceivedAudioBytes += observedInboundRtp.deltaBytesReceived;
375
- this.deltaReceivedAudioPackets += observedInboundRtp.deltaReceivedPackets;
376
- break;
377
- case 'video':
378
- this.deltaReceivedVideoBytes += observedInboundRtp.deltaBytesReceived;
379
- this.deltaReceivedVideoPackets += observedInboundRtp.deltaReceivedPackets;
380
- break;
381
- }
382
-
383
- if (observedInboundRtp.jitter) {
384
- jitterMeasurements.push(observedInboundRtp.jitter);
385
- }
386
- }
387
- }
388
- if (sample.mediaPlayouts) {
389
- for (const mediaPlayout of sample.mediaPlayouts) {
390
- this._updateMediaPlayoutStats(mediaPlayout);
391
- }
392
- }
393
- if (sample.mediaSources) {
394
- for (const mediaSource of sample.mediaSources) {
395
- this._updateMediaSourceStats(mediaSource);
396
- }
397
- }
398
- if (sample.outboundRtps) {
399
- for (const outboundRtp of sample.outboundRtps) {
400
- const observedOutboundRtp = this._updateOutboundRtpStats(outboundRtp);
401
-
402
- if (!observedOutboundRtp) continue;
403
-
404
- this.deltaOutboundPacketsSent += observedOutboundRtp.deltaPacketsSent ?? 0;
405
- this.deltaOutboundSentBytes += observedOutboundRtp.deltaBytesSent ?? 0;
406
-
407
- switch (outboundRtp.kind) {
408
- case 'audio':
409
- this.deltaSentAudioBytes += observedOutboundRtp.deltaBytesSent;
410
- this.deltaSentAudioBytes += observedOutboundRtp.deltaPacketsSent;
411
- break;
412
- case 'video':
413
- this.deltaSentVideoBytes += observedOutboundRtp.deltaBytesSent;
414
- this.deltaSentVideoBytes += observedOutboundRtp.deltaPacketsSent;
415
- break;
416
- }
417
-
418
- }
419
- }
420
- if (sample.peerConnectionTransports) {
421
- for (const peerConnectionTransport of sample.peerConnectionTransports) {
422
- this._updatePeerConnectionTransportStats(peerConnectionTransport);
423
- }
424
- }
425
- if (sample.remoteInboundRtps) {
426
- for (const remoteInboundRtp of sample.remoteInboundRtps) {
427
- const observedRemoteInboundRtp = this._updateRemoteInboundRtpStats(remoteInboundRtp);
428
-
429
- if (!observedRemoteInboundRtp) continue;
430
-
431
- if (observedRemoteInboundRtp.roundTripTime) {
432
- rttMeasurementsInSec.push(observedRemoteInboundRtp.roundTripTime);
433
- }
434
- }
435
- }
436
- if (sample.remoteOutboundRtps) {
437
- for (const remoteOutboundRtp of sample.remoteOutboundRtps) {
438
- const observedRemoteOutboundRtp = this._updateRemoteOutboundRtpStats(remoteOutboundRtp);
439
-
440
- if (!observedRemoteOutboundRtp) continue;
441
- }
442
- }
443
-
444
- // tracks should be updated last as they are derived stats
445
- // and depends on base stats but they all received in the sample sample
446
- if (sample.inboundTracks) {
447
- for (const inboundTrack of sample.inboundTracks) {
448
- this._updateInboundTrackSample(inboundTrack);
449
- }
450
- }
451
- if (sample.outboundTracks) {
452
- for (const outboundTrack of sample.outboundTracks) {
453
- this._updateOutboundTrackSample(outboundTrack);
454
- }
455
- }
456
-
457
- this.totalInboundPacketsLost += this.deltaInboundPacketsLost;
458
- this.totalInboundPacketsReceived += this.deltaInboundPacketsReceived;
459
- this.totalOutboundPacketsSent += this.deltaOutboundPacketsSent;
460
- this.totalDataChannelBytesSent += this.deltaDataChannelBytesSent;
461
- this.totalDataChannelBytesReceived += this.deltaDataChannelBytesReceived;
462
- this.totalDataChannelMessagesSent += this.deltaDataChannelMessagesSent;
463
- this.totalDataChannelMessagesReceived += this.deltaDataChannelMessagesReceived;
464
- this.totalReceivedAudioBytes += this.deltaReceivedAudioBytes;
465
- this.totalReceivedVideoBytes += this.deltaReceivedVideoBytes;
466
- this.totalSentAudioBytes += this.deltaSentAudioBytes;
467
- this.totalSentVideoBytes += this.deltaSentVideoBytes;
468
- this.totalReceivedAudioPacktes += this.deltaReceivedAudioPackets;
469
- this.totalReceivedVideoPackets += this.deltaReceivedVideoPackets;
470
- this.totalSentAudioPackets += this.deltaSentAudioBytes;
471
- this.totalSentVideoPackets += this.deltaSentVideoBytes;
472
-
473
- this.receivingPacketsPerSecond = this.deltaInboundPacketsReceived / elapsedTimeInSec;
474
- this.sendingPacketsPerSecond = this.deltaOutboundPacketsSent / elapsedTimeInSec;
475
- this.sendingAudioBitrate = (this.deltaSentAudioBytes * 8) / elapsedTimeInSec;
476
- this.sendingVideoBitrate = (this.deltaSentVideoBytes * 8) / elapsedTimeInSec;
477
- this.receivingAudioBitrate = (this.deltaReceivedAudioBytes * 8) / elapsedTimeInSec;
478
- this.receivingVideoBitrate = (this.deltaReceivedVideoBytes * 8) / elapsedTimeInSec;
479
-
480
- if (rttMeasurementsInSec.length > 0) {
481
- this.avgRttInMs = rttMeasurementsInSec.reduce((acc, val) => acc + val, 0) / rttMeasurementsInSec.length;
482
- } else {
483
- this.avgRttInMs = undefined;
484
- }
485
- if (jitterMeasurements.length > 0) {
486
- this.avgJitter = jitterMeasurements.reduce((acc, val) => acc + val, 0) / jitterMeasurements.length;
487
- } else {
488
- this.avgJitter = undefined;
489
- }
490
-
491
- const selectedIceCandidatePairs = this.selectedIceCandidatePairs;
492
- const selectedCandidatePairForTurn = selectedIceCandidatePairs.filter((pair) =>
493
- pair.getLocalCandidate()?.candidateType === 'relay' &&
494
- pair.getRemoteCandidate()?.url?.startsWith('turn:')
495
- );
496
- const wasUsingTURN = this.usingTURN;
497
-
498
- this.usingTCP = selectedIceCandidatePairs.some((pair) => pair.getLocalCandidate()?.protocol === 'tcp');
499
- this.usingTURN = 0 < selectedCandidatePairForTurn.length;
500
-
501
- if (this.usingTURN) {
502
- if (!this.observedTurnServer) {
503
- this.observedTurnServer = this.client.call.observer.observedTURN.addPeerConnection(this);
504
- }
505
- this.observedTurnServer?.updateTurnUsage(...selectedCandidatePairForTurn);
506
- } else if (wasUsingTURN) {
507
- if (!this.usingTURN) {
508
- this.client.call.observer.observedTURN.removePeerConnection(this);
509
- }
510
- }
511
- this.calculatedScore.value = sample.score;
512
- this.updated = now;
513
- this._checkVisited();
514
-
515
- this.emit('update');
516
- }
517
-
518
- private _checkVisited() {
519
- for (const certificate of [ ...this.observedCertificates.values() ]) {
520
- if (certificate.visited) continue;
521
-
522
- this.observedCertificates.delete(certificate.id);
523
- }
524
- for (const codec of [ ...this.observedCodecs.values() ]) {
525
- if (codec.visited) continue;
526
-
527
- this.observedCodecs.delete(codec.id);
528
- this.emit('removed-codec', codec);
529
- }
530
- for (const dataChannel of [ ...this.observedDataChannels.values() ]) {
531
- if (dataChannel.visited) continue;
532
-
533
- this.observedDataChannels.delete(dataChannel.id);
534
- this.emit('removed-data-channel', dataChannel);
535
- }
536
- for (const iceCandidate of [ ...this.observedIceCandidates.values() ]) {
537
- if (iceCandidate.visited) continue;
538
-
539
- this.observedIceCandidates.delete(iceCandidate.id);
540
- this.emit('removed-ice-candidate', iceCandidate);
541
- }
542
- for (const iceCandidatePair of [ ...this.observedIceCandidatesPair.values() ]) {
543
- if (iceCandidatePair.visited) continue;
544
-
545
- this.observedIceCandidatesPair.delete(iceCandidatePair.id);
546
- this.emit('removed-ice-candidate-pair', iceCandidatePair);
547
- }
548
- for (const iceTransport of [ ...this.observedIceTransports.values() ]) {
549
- if (iceTransport.visited) continue;
550
-
551
- this.observedIceTransports.delete(iceTransport.id);
552
- this.emit('removed-ice-transport', iceTransport);
553
- }
554
- for (const inboundRtp of [ ...this.observedInboundRtps.values() ]) {
555
- if (inboundRtp.visited) continue;
556
-
557
- this.observedInboundRtps.delete(inboundRtp.ssrc);
558
- this.emit('removed-inbound-rtp', inboundRtp);
559
- }
560
- for (const inboundTrack of [ ...this.observedInboundTracks.values() ]) {
561
- if (inboundTrack.visited) continue;
562
-
563
- this.observedInboundTracks.delete(inboundTrack.id);
564
- this.emit('removed-inbound-track', inboundTrack);
565
- }
566
- for (const mediaPlayout of [ ...this.observedMediaPlayouts.values() ]) {
567
- if (mediaPlayout.visited) continue;
568
-
569
- this.observedMediaPlayouts.delete(mediaPlayout.id);
570
- this.emit('removed-media-playout', mediaPlayout);
571
- }
572
- for (const mediaSource of [ ...this.observedMediaSources.values() ]) {
573
- if (mediaSource.visited) continue;
574
-
575
- this.observedMediaSources.delete(mediaSource.id);
576
- this.emit('removed-media-source', mediaSource);
577
- }
578
- for (const outboundRtp of [ ...this.observedOutboundRtps.values() ]) {
579
- if (outboundRtp.visited) continue;
580
-
581
- this.observedOutboundRtps.delete(outboundRtp.ssrc);
582
- this.emit('removed-outbound-rtp', outboundRtp);
583
- }
584
- for (const outboundTrack of [ ...this.observedOutboundTracks.values() ]) {
585
- if (outboundTrack.visited) continue;
586
-
587
- this.observedOutboundTracks.delete(outboundTrack.id);
588
- this.emit('removed-outbound-track', outboundTrack);
589
- }
590
- for (const peerConnectionTransport of [ ...this.observedPeerConnectionTransports.values() ]) {
591
- if (peerConnectionTransport.visited) continue;
592
-
593
- this.observedPeerConnectionTransports.delete(peerConnectionTransport.id);
594
- this.emit('removed-peer-connection-transport', peerConnectionTransport);
595
- }
596
- for (const remoteInboundRtp of [ ...this.observedRemoteInboundRtps.values() ]) {
597
- if (remoteInboundRtp.visited) continue;
598
-
599
- this.observedRemoteInboundRtps.delete(remoteInboundRtp.ssrc);
600
- this.emit('removed-remote-inbound-rtp', remoteInboundRtp);
601
- }
602
- for (const remoteOutboundRtp of [ ...this.observedRemoteOutboundRtps.values() ]) {
603
- if (remoteOutboundRtp.visited) continue;
604
-
605
- this.observedRemoteOutboundRtps.delete(remoteOutboundRtp.ssrc);
606
- this.emit('removed-remote-outbound-rtp', remoteOutboundRtp);
607
- }
608
- }
609
-
610
- private _updateCertificateStats(stats: CertificateStats) {
611
- let observedCertificate = this.observedCertificates.get(stats.id);
612
-
613
- if (!observedCertificate) {
614
- if (!stats.timestamp || !stats.id || !stats.fingerprint) {
615
- return logger.warn(
616
- `ObservedPeerConnection received an invalid CertificateStats (missing timestamp OR id OR fingerprint field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`,
617
- stats
618
- );
619
- }
620
-
621
- observedCertificate = new ObservedCertificate(stats.timestamp, stats.id, this);
622
-
623
- this.observedCertificates.set(stats.id, observedCertificate);
624
- this.emit('added-certificate', observedCertificate);
625
- }
626
-
627
- observedCertificate.update(stats);
628
-
629
- return observedCertificate;
630
- }
631
-
632
- private _updateCodecStats(stats: CodecStats) {
633
- let observedCodec = this.observedCodecs.get(stats.id);
634
-
635
- if (!observedCodec) {
636
- if (!stats.timestamp || !stats.id || !stats.mimeType) {
637
- return logger.warn(
638
- `ObservedPeerConnection received an invalid CodecStats (missing timestamp OR id OR mimeType field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`,
639
- stats
640
- );
641
- }
642
-
643
- observedCodec = new ObservedCodec(stats.timestamp, stats.id, stats.mimeType, this);
644
-
645
- this.observedCodecs.set(stats.id, observedCodec);
646
- this.emit('added-codec', observedCodec);
647
- }
648
-
649
- observedCodec.update(stats);
650
-
651
- return observedCodec;
652
- }
653
-
654
- private _updateDataChannelStats(stats: DataChannelStats) {
655
- let observedDataChannel = this.observedDataChannels.get(stats.id);
656
-
657
- if (!observedDataChannel) {
658
- if (!stats.timestamp || !stats.id) {
659
- return logger.warn(
660
- `ObservedPeerConnection received an invalid DataChannelStats (missing timestamp OR id field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`,
661
- stats
662
- );
663
- }
664
-
665
- observedDataChannel = new ObservedDataChannel(stats.timestamp, stats.id, this);
666
-
667
- this.observedDataChannels.set(stats.id, observedDataChannel);
668
- this.emit('added-data-channel', observedDataChannel);
669
- }
670
-
671
- observedDataChannel.update(stats);
672
-
673
- return observedDataChannel;
674
- }
675
-
676
- private _updateIceCandidateStats(stats: IceCandidateStats) {
677
- let observedIceCandidate = this.observedIceCandidates.get(stats.id);
678
-
679
- if (!observedIceCandidate) {
680
- if (!stats.timestamp || !stats.id) {
681
- return logger.warn(
682
- `ObservedPeerConnection received an invalid IceCandidateStats (missing timestamp OR id field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`,
683
- stats
684
- );
685
- }
686
-
687
- observedIceCandidate = new ObservedIceCandidate(stats.timestamp, stats.id, this);
688
-
689
- this.observedIceCandidates.set(stats.id, observedIceCandidate);
690
- this.emit('added-ice-candidate', observedIceCandidate);
691
- }
692
-
693
- observedIceCandidate.update(stats);
694
-
695
- return observedIceCandidate;
696
- }
697
-
698
- private _updateIceCandidatePairStats(stats: IceCandidateStats) {
699
- let observedIceCandidatePair = this.observedIceCandidatesPair.get(stats.id);
700
-
701
- if (!observedIceCandidatePair) {
702
- if (!stats.timestamp || !stats.id) {
703
- return logger.warn(
704
- `ObservedPeerConnection received an invalid IceCandidateStats (missing timestamp OR id field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`,
705
- stats
706
- );
707
- }
708
-
709
- observedIceCandidatePair = new ObservedIceCandidatePair(stats.timestamp, stats.id, this);
710
-
711
- this.observedIceCandidatesPair.set(stats.id, observedIceCandidatePair);
712
- this.emit('added-ice-candidate-pair', observedIceCandidatePair);
713
- }
714
-
715
- observedIceCandidatePair.update(stats);
716
-
717
- return observedIceCandidatePair;
718
- }
719
-
720
- private _updateIceTransportStats(stats: IceCandidateStats) {
721
- let observedIceTransport = this.observedIceTransports.get(stats.id);
722
-
723
- if (!observedIceTransport) {
724
- if (!stats.timestamp || !stats.id) {
725
- return logger.warn(
726
- `ObservedPeerConnection received an invalid IceCandidateStats (missing timestamp OR id field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`,
727
- stats
728
- );
729
- }
730
-
731
- observedIceTransport = new ObservedIceTransport(stats.timestamp, stats.id, this);
732
-
733
- this.observedIceTransports.set(stats.id, observedIceTransport);
734
- this.emit('added-ice-transport', observedIceTransport);
735
- }
736
-
737
- observedIceTransport.update(stats);
738
-
739
- return observedIceTransport;
740
- }
741
-
742
- private _updateInboundRtpStats(stats: InboundRtpStats) {
743
- let observedInboundRtp = this.observedInboundRtps.get(stats.ssrc);
744
-
745
- if (!observedInboundRtp) {
746
- if (!stats.timestamp || !stats.id || !stats.ssrc || !stats.kind || !stats.trackIdentifier) {
747
- return logger.warn(
748
- `ObservedPeerConnection received an invalid InboundRtpStats (missing timestamp OR id OR ssrc OR kind OR trackIdentifier field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`,
749
- stats
750
- );
751
- }
752
-
753
- observedInboundRtp = new ObservedInboundRtp(
754
- stats.timestamp,
755
- stats.id,
756
- stats.ssrc,
757
- stats.kind as MediaKind,
758
- stats.trackIdentifier,
759
- this
760
- );
761
-
762
- this.observedInboundRtps.set(stats.ssrc, observedInboundRtp);
763
- this.emit('added-inbound-rtp', observedInboundRtp);
764
- }
765
-
766
- observedInboundRtp.update(stats);
767
-
768
- return observedInboundRtp;
769
- }
770
-
771
- private _updateInboundTrackSample(stats: InboundTrackSample) {
772
- let observedInboundTrack = this.observedInboundTracks.get(stats.id);
773
-
774
- if (!observedInboundTrack) {
775
- if (!stats.timestamp || !stats.id || !stats.kind) {
776
- return logger.warn(
777
- `ObservedPeerConnection received an invalid InboundTrackSample (missing timestamp OR id OR kind field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`,
778
- stats
779
- );
780
- }
781
-
782
- const inboundRtp = [ ...this.observedInboundRtps.values() ].find((inbRtp) => inbRtp.trackIdentifier === stats.id);
783
- const mediaPlayout = inboundRtp ?
784
- [ ...this.observedMediaPlayouts.values() ].find((mp) => mp.id === inboundRtp.playoutId) : undefined;
785
-
786
- observedInboundTrack = new ObservedInboundTrack(
787
- stats.timestamp,
788
- stats.id,
789
- stats.kind as MediaKind,
790
- this,
791
- inboundRtp,
792
- mediaPlayout,
793
- );
794
-
795
- this.observedInboundTracks.set(stats.id, observedInboundTrack);
796
- this.emit('added-inbound-track', observedInboundTrack);
797
- }
798
-
799
- observedInboundTrack.update(stats);
800
-
801
- return observedInboundTrack;
802
- }
803
-
804
- private _updateMediaPlayoutStats(stats: MediaPlayoutStats) {
805
- let observedMediaPlayout = this.observedMediaPlayouts.get(stats.id);
806
-
807
- if (!observedMediaPlayout) {
808
- if (!stats.timestamp || !stats.id || !stats.kind) {
809
- return logger.warn(
810
- `ObservedPeerConnection received an invalid InboundRtpStats (missing timestamp OR id OR kind OR trackIdentifier field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`,
811
- stats
812
- );
813
- }
814
-
815
- observedMediaPlayout = new ObservedMediaPlayout(
816
- stats.timestamp,
817
- stats.id,
818
- stats.kind as MediaKind,
819
- this
820
- );
821
-
822
- this.observedMediaPlayouts.set(stats.id, observedMediaPlayout);
823
- this.emit('added-media-playout', observedMediaPlayout);
824
- }
825
-
826
- observedMediaPlayout.update(stats);
827
-
828
- return observedMediaPlayout;
829
- }
830
-
831
- private _updateMediaSourceStats(stats: MediaSourceStats) {
832
- let observedMediaSource = this.observedMediaSources.get(stats.id);
833
-
834
- if (!observedMediaSource) {
835
- if (!stats.timestamp || !stats.id || !stats.kind) {
836
- return logger.warn(
837
- `ObservedPeerConnection received an invalid InboundRtpStats (missing timestamp OR id OR kind field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`,
838
- stats
839
- );
840
- }
841
-
842
- observedMediaSource = new ObservedMediaSource(
843
- stats.timestamp,
844
- stats.id,
845
- stats.kind as MediaKind,
846
- this
847
- );
848
-
849
- this.observedMediaSources.set(stats.id, observedMediaSource);
850
- this.emit('added-media-source', observedMediaSource);
851
- }
852
-
853
- observedMediaSource.update(stats);
854
-
855
- return observedMediaSource;
856
- }
857
-
858
- private _updateOutboundRtpStats(stats: OutboundRtpStats) {
859
- let observedOutboundRtp = this.observedOutboundRtps.get(stats.ssrc);
860
-
861
- if (!observedOutboundRtp) {
862
- if (!stats.timestamp || !stats.id || !stats.ssrc || !stats.kind) {
863
- return logger.warn(
864
- `ObservedPeerConnection received an invalid OutboundRtpStats (missing timestamp OR id OR ssrc OR kind field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`,
865
- stats
866
- );
867
- }
868
-
869
- observedOutboundRtp = new ObservedOutboundRtp(
870
- stats.timestamp,
871
- stats.id,
872
- stats.ssrc,
873
- stats.kind as MediaKind,
874
- this
875
- );
876
-
877
- this.observedOutboundRtps.set(stats.ssrc, observedOutboundRtp);
878
- this.emit('added-outbound-rtp', observedOutboundRtp);
879
- }
880
-
881
- observedOutboundRtp.update(stats);
882
-
883
- return observedOutboundRtp;
884
- }
885
-
886
- public _updateOutboundTrackSample(stats: OutboundTrackSample) {
887
- let observedOutboundTrack = this.observedOutboundTracks.get(stats.id);
888
-
889
- if (!observedOutboundTrack) {
890
- if (!stats.timestamp || !stats.id || !stats.kind) {
891
- return logger.warn(
892
- `ObservedPeerConnection received an invalid OutboundTrackSample (missing timestamp OR id OR kind field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`,
893
- stats
894
- );
895
- }
896
- const observedMediaSource = [ ...this.observedMediaSources.values() ].find((mediaSource) => mediaSource.trackIdentifier === stats.id);
897
- const outboundRtps = observedMediaSource
898
- ? [ ...this.observedOutboundRtps.values() ].filter((outboundRtp) => outboundRtp.mediaSourceId === observedMediaSource?.id) : undefined;
899
-
900
- observedOutboundTrack = new ObservedOutboundTrack(
901
- stats.timestamp,
902
- stats.id,
903
- stats.kind as MediaKind,
904
- this,
905
- outboundRtps,
906
- observedMediaSource,
907
- );
908
-
909
- this.observedOutboundTracks.set(stats.id, observedOutboundTrack);
910
- this.emit('added-outbound-track', observedOutboundTrack);
911
- }
912
-
913
- observedOutboundTrack.update(stats);
914
-
915
- return observedOutboundTrack;
916
- }
917
-
918
- private _updatePeerConnectionTransportStats(stats: PeerConnectionTransportStats) {
919
- let observedPeerConnectionTransport = this.observedPeerConnectionTransports.get(stats.id);
920
-
921
- if (!observedPeerConnectionTransport) {
922
- if (!stats.timestamp || !stats.id) {
923
- return logger.warn(
924
- `ObservedPeerConnection received an invalid PeerConnectionTransportStats (missing timestamp OR id field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`,
925
- stats
926
- );
927
- }
928
-
929
- observedPeerConnectionTransport = new ObservedPeerConnectionTransport(stats.timestamp, stats.id, this);
930
-
931
- this.observedPeerConnectionTransports.set(stats.id, observedPeerConnectionTransport);
932
- this.emit('added-peer-connection-transport', observedPeerConnectionTransport);
933
- }
934
-
935
- observedPeerConnectionTransport.update(stats);
936
-
937
- return observedPeerConnectionTransport;
938
- }
939
-
940
- private _updateRemoteInboundRtpStats(stats: RemoteInboundRtpStats) {
941
- let observedRemoteInboundRtp = this.observedRemoteInboundRtps.get(stats.ssrc);
942
-
943
- if (!observedRemoteInboundRtp) {
944
- if (!stats.timestamp || !stats.id || !stats.ssrc || !stats.kind) {
945
- return logger.warn(
946
- `ObservedPeerConnection received an invalid RemoteInboundRtpStats (missing timestamp OR id OR ssrc OR kind field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`,
947
- stats
948
- );
949
- }
950
-
951
- observedRemoteInboundRtp = new ObservedRemoteInboundRtp(
952
- stats.timestamp,
953
- stats.id,
954
- stats.ssrc,
955
- stats.kind as MediaKind,
956
- this
957
- );
958
-
959
- this.observedRemoteInboundRtps.set(stats.ssrc, observedRemoteInboundRtp);
960
- this.emit('added-remote-inbound-rtp', observedRemoteInboundRtp);
961
- }
962
-
963
- observedRemoteInboundRtp.update(stats);
964
-
965
- return observedRemoteInboundRtp;
966
- }
967
-
968
- private _updateRemoteOutboundRtpStats(stats: RemoteOutboundRtpStats) {
969
- let observedRemoteOutboundRtp = this.observedRemoteOutboundRtps.get(stats.ssrc);
970
-
971
- if (!observedRemoteOutboundRtp) {
972
- if (!stats.timestamp || !stats.id || !stats.ssrc || !stats.kind) {
973
- return logger.warn(
974
- `ObservedPeerConnection received an invalid RemoteOutboundRtpStats (missing timestamp OR id OR ssrc OR kind field). PeerConnectionId: ${this.peerConnectionId} ClientId: ${this.client.clientId}, CallId: ${this.client.call.callId}`,
975
- stats
976
- );
977
- }
978
-
979
- observedRemoteOutboundRtp = new ObservedRemoteOutboundRtp(
980
- stats.timestamp,
981
- stats.id,
982
- stats.ssrc,
983
- stats.kind as MediaKind,
984
- this
985
- );
986
-
987
- this.observedRemoteOutboundRtps.set(stats.ssrc, observedRemoteOutboundRtp);
988
- this.emit('added-remote-outbound-rtp', observedRemoteOutboundRtp);
989
- }
990
-
991
- observedRemoteOutboundRtp.update(stats);
992
-
993
- return observedRemoteOutboundRtp;
994
- }
995
- }