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