@observertc/observer-js 0.42.9 → 1.0.1-23e88d8.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 (239) hide show
  1. package/.prettierrc +6 -6
  2. package/README.md +0 -104
  3. package/lib/ObservedCall.d.ts +25 -41
  4. package/lib/ObservedCall.d.ts.map +1 -1
  5. package/lib/ObservedCall.js +61 -109
  6. package/lib/ObservedCertificate.d.ts +19 -0
  7. package/lib/ObservedCertificate.d.ts.map +1 -0
  8. package/lib/ObservedCertificate.js +38 -0
  9. package/lib/ObservedClient.d.ts +33 -143
  10. package/lib/ObservedClient.d.ts.map +1 -1
  11. package/lib/ObservedClient.js +156 -757
  12. package/lib/ObservedCodec.d.ts +22 -0
  13. package/lib/ObservedCodec.d.ts.map +1 -0
  14. package/lib/ObservedCodec.js +45 -0
  15. package/lib/ObservedDataChannel.d.ts +20 -70
  16. package/lib/ObservedDataChannel.d.ts.map +1 -1
  17. package/lib/ObservedDataChannel.js +39 -109
  18. package/lib/ObservedIceCandidate.d.ts +29 -0
  19. package/lib/ObservedIceCandidate.d.ts.map +1 -0
  20. package/lib/ObservedIceCandidate.js +59 -0
  21. package/lib/ObservedIceCandidatePair.d.ts +40 -0
  22. package/lib/ObservedIceCandidatePair.d.ts.map +1 -0
  23. package/lib/ObservedIceCandidatePair.js +83 -0
  24. package/lib/ObservedIceTransport.d.ts +32 -0
  25. package/lib/ObservedIceTransport.d.ts.map +1 -0
  26. package/lib/ObservedIceTransport.js +65 -0
  27. package/lib/ObservedInboundRtp.d.ts +92 -0
  28. package/lib/ObservedInboundRtp.d.ts.map +1 -0
  29. package/lib/ObservedInboundRtp.js +193 -0
  30. package/lib/ObservedInboundTrack.d.ts +29 -0
  31. package/lib/ObservedInboundTrack.d.ts.map +1 -0
  32. package/lib/ObservedInboundTrack.js +57 -0
  33. package/lib/ObservedMediaPlayout.d.ts +22 -0
  34. package/lib/ObservedMediaPlayout.d.ts.map +1 -0
  35. package/lib/ObservedMediaPlayout.js +42 -0
  36. package/lib/ObservedMediaSource.d.ts +28 -0
  37. package/lib/ObservedMediaSource.d.ts.map +1 -0
  38. package/lib/ObservedMediaSource.js +55 -0
  39. package/lib/ObservedOutboundRtp.d.ts +62 -0
  40. package/lib/ObservedOutboundRtp.d.ts.map +1 -0
  41. package/lib/ObservedOutboundRtp.js +144 -0
  42. package/lib/ObservedOutboundTrack.d.ts +29 -0
  43. package/lib/ObservedOutboundTrack.d.ts.map +1 -0
  44. package/lib/ObservedOutboundTrack.js +57 -0
  45. package/lib/ObservedPeerConnection.d.ts +118 -78
  46. package/lib/ObservedPeerConnection.d.ts.map +1 -1
  47. package/lib/ObservedPeerConnection.js +556 -359
  48. package/lib/ObservedPeerConnectionTransport.d.ts +17 -0
  49. package/lib/ObservedPeerConnectionTransport.d.ts.map +1 -0
  50. package/lib/ObservedPeerConnectionTransport.js +34 -0
  51. package/lib/ObservedRemoteInboundRtp.d.ts +30 -0
  52. package/lib/ObservedRemoteInboundRtp.d.ts.map +1 -0
  53. package/lib/ObservedRemoteInboundRtp.js +60 -0
  54. package/lib/ObservedRemoteOutboundRtp.d.ts +30 -0
  55. package/lib/ObservedRemoteOutboundRtp.d.ts.map +1 -0
  56. package/lib/ObservedRemoteOutboundRtp.js +60 -0
  57. package/lib/Observer.d.ts +30 -53
  58. package/lib/Observer.d.ts.map +1 -1
  59. package/lib/Observer.js +52 -225
  60. package/lib/common/Middleware.d.ts +10 -1
  61. package/lib/common/Middleware.d.ts.map +1 -1
  62. package/lib/common/Middleware.js +55 -36
  63. package/lib/common/logger.d.ts +8 -4
  64. package/lib/common/logger.d.ts.map +1 -1
  65. package/lib/common/logger.js +44 -68
  66. package/lib/common/types.d.ts +0 -21
  67. package/lib/common/types.d.ts.map +1 -1
  68. package/lib/common/types.js +1 -0
  69. package/lib/common/utils.d.ts +1 -0
  70. package/lib/common/utils.d.ts.map +1 -1
  71. package/lib/common/utils.js +13 -1
  72. package/lib/detectors/Detector.d.ts +5 -0
  73. package/lib/detectors/Detector.d.ts.map +1 -0
  74. package/lib/detectors/Detector.js +3 -0
  75. package/lib/detectors/Detectors.d.ts +11 -0
  76. package/lib/detectors/Detectors.d.ts.map +1 -0
  77. package/lib/detectors/Detectors.js +34 -0
  78. package/lib/index.d.ts +23 -25
  79. package/lib/index.d.ts.map +1 -1
  80. package/lib/index.js +41 -41
  81. package/lib/monitors/TurnUsageMonitor.d.ts +0 -52
  82. package/lib/monitors/TurnUsageMonitor.d.ts.map +1 -1
  83. package/lib/monitors/TurnUsageMonitor.js +145 -120
  84. package/lib/schema/ClientEventTypes.d.ts +33 -0
  85. package/lib/schema/ClientEventTypes.d.ts.map +1 -0
  86. package/lib/schema/ClientEventTypes.js +38 -0
  87. package/lib/schema/ClientMetaTypes.d.ts +34 -0
  88. package/lib/schema/ClientMetaTypes.d.ts.map +1 -0
  89. package/lib/schema/ClientMetaTypes.js +16 -0
  90. package/lib/schema/ClientSample.d.ts +1333 -0
  91. package/lib/schema/ClientSample.d.ts.map +1 -0
  92. package/lib/schema/ClientSample.js +4 -0
  93. package/lib/scores/CalculatedScore.d.ts +6 -0
  94. package/lib/scores/CalculatedScore.d.ts.map +1 -0
  95. package/lib/scores/DefaultCallScoreCalculator.d.ts +7 -0
  96. package/lib/scores/DefaultCallScoreCalculator.d.ts.map +1 -0
  97. package/lib/scores/DefaultCallScoreCalculator.js +21 -0
  98. package/lib/scores/ScoreCalculator.d.ts +4 -0
  99. package/lib/scores/ScoreCalculator.d.ts.map +1 -0
  100. package/lib/scores/ScoreCalculator.js +2 -0
  101. package/lib/utils/CallUpdater.d.ts +5 -0
  102. package/lib/utils/CallUpdater.d.ts.map +1 -0
  103. package/lib/utils/CallUpdater.js +2 -0
  104. package/lib/utils/OnAllClientCallUpdater.d.ts +16 -0
  105. package/lib/utils/OnAllClientCallUpdater.d.ts.map +1 -0
  106. package/lib/utils/OnAllClientCallUpdater.js +58 -0
  107. package/lib/utils/RemoteTrackResolver.d.ts +7 -0
  108. package/lib/utils/RemoteTrackResolver.d.ts.map +1 -0
  109. package/lib/utils/RemoteTrackResolver.js +2 -0
  110. package/lib/utils/onAnyClientCallUpdater.d.ts +14 -0
  111. package/lib/utils/onAnyClientCallUpdater.d.ts.map +1 -0
  112. package/lib/utils/onAnyClientCallUpdater.js +51 -0
  113. package/package.json +4 -4
  114. package/src/ObservedCall.ts +74 -167
  115. package/src/ObservedCertificate.ts +43 -0
  116. package/src/ObservedClient.ts +173 -1085
  117. package/src/ObservedCodec.ts +49 -0
  118. package/src/ObservedDataChannel.ts +36 -178
  119. package/src/ObservedIceCandidate.ts +64 -0
  120. package/src/ObservedIceCandidatePair.ts +92 -0
  121. package/src/ObservedIceTransport.ts +70 -0
  122. package/src/ObservedInboundRtp.ts +205 -0
  123. package/src/ObservedInboundTrack.ts +70 -0
  124. package/src/ObservedMediaPlayout.ts +49 -0
  125. package/src/ObservedMediaSource.ts +60 -0
  126. package/src/ObservedOutboundRtp.ts +156 -0
  127. package/src/ObservedOutboundTrack.ts +69 -0
  128. package/src/ObservedPeerConnection.ts +743 -401
  129. package/src/ObservedPeerConnectionTransport.ts +38 -0
  130. package/src/ObservedRemoteInboundRtp.ts +64 -0
  131. package/src/ObservedRemoteOutboundRtp.ts +65 -0
  132. package/src/Observer.ts +65 -285
  133. package/src/common/Middleware.ts +70 -42
  134. package/src/common/logger.ts +60 -69
  135. package/src/common/types.ts +0 -42
  136. package/src/common/utils.ts +12 -0
  137. package/src/detectors/Detector.ts +6 -0
  138. package/src/detectors/Detectors.ts +38 -0
  139. package/src/index.ts +23 -90
  140. package/src/monitors/TurnUsageMonitor.ts +164 -164
  141. package/src/schema/ClientEventTypes.ts +36 -0
  142. package/src/schema/ClientMetaTypes.ts +41 -0
  143. package/src/schema/ClientSample.ts +1682 -0
  144. package/src/scores/CalculatedScore.ts +6 -0
  145. package/src/scores/DefaultCallScoreCalculator.ts +23 -0
  146. package/src/scores/ScoreCalculator.ts +3 -0
  147. package/src/utils/CallUpdater.ts +5 -0
  148. package/src/utils/OnAllClientCallUpdater.ts +68 -0
  149. package/src/utils/RemoteTrackResolver.ts +12 -0
  150. package/src/utils/onAnyClientCallUpdater.ts +59 -0
  151. package/tsconfig.json +3 -3
  152. package/lib/ObservedICE.d.ts +0 -64
  153. package/lib/ObservedICE.d.ts.map +0 -1
  154. package/lib/ObservedICE.js +0 -141
  155. package/lib/ObservedInboundAudioTrack.d.ts +0 -96
  156. package/lib/ObservedInboundAudioTrack.d.ts.map +0 -1
  157. package/lib/ObservedInboundAudioTrack.js +0 -217
  158. package/lib/ObservedInboundVideoTrack.d.ts +0 -101
  159. package/lib/ObservedInboundVideoTrack.d.ts.map +0 -1
  160. package/lib/ObservedInboundVideoTrack.js +0 -232
  161. package/lib/ObservedOutboundAudioTrack.d.ts +0 -87
  162. package/lib/ObservedOutboundAudioTrack.d.ts.map +0 -1
  163. package/lib/ObservedOutboundAudioTrack.js +0 -186
  164. package/lib/ObservedOutboundVideoTrack.d.ts +0 -91
  165. package/lib/ObservedOutboundVideoTrack.d.ts.map +0 -1
  166. package/lib/ObservedOutboundVideoTrack.js +0 -193
  167. package/lib/ObservedSfu.d.ts +0 -59
  168. package/lib/ObservedSfu.d.ts.map +0 -1
  169. package/lib/ObservedSfu.js +0 -157
  170. package/lib/ObservedSfuInboundRtpPad.d.ts +0 -42
  171. package/lib/ObservedSfuInboundRtpPad.d.ts.map +0 -1
  172. package/lib/ObservedSfuInboundRtpPad.js +0 -71
  173. package/lib/ObservedSfuOutboundRtpPad.d.ts +0 -42
  174. package/lib/ObservedSfuOutboundRtpPad.d.ts.map +0 -1
  175. package/lib/ObservedSfuOutboundRtpPad.js +0 -72
  176. package/lib/ObservedSfuSctpChannel.d.ts +0 -42
  177. package/lib/ObservedSfuSctpChannel.d.ts.map +0 -1
  178. package/lib/ObservedSfuSctpChannel.js +0 -57
  179. package/lib/ObservedSfuTransport.d.ts +0 -58
  180. package/lib/ObservedSfuTransport.d.ts.map +0 -1
  181. package/lib/ObservedSfuTransport.js +0 -120
  182. package/lib/RemoteTrackAssigner.d.ts +0 -14
  183. package/lib/RemoteTrackAssigner.d.ts.map +0 -1
  184. package/lib/RemoteTrackAssigner.js +0 -52
  185. package/lib/ReportsCollector.d.ts +0 -109
  186. package/lib/ReportsCollector.d.ts.map +0 -1
  187. package/lib/ReportsCollector.js +0 -207
  188. package/lib/common/CalculatedScore.d.ts +0 -80
  189. package/lib/common/CalculatedScore.d.ts.map +0 -1
  190. package/lib/common/CalculatedScore.js +0 -162
  191. package/lib/common/CallEventType.d.ts +0 -63
  192. package/lib/common/CallEventType.d.ts.map +0 -1
  193. package/lib/common/CallEventType.js +0 -39
  194. package/lib/common/CallMetaReports.d.ts +0 -42
  195. package/lib/common/CallMetaReports.d.ts.map +0 -1
  196. package/lib/common/CallMetaReports.js +0 -36
  197. package/lib/common/QualityScoreUtils.d.ts +0 -1
  198. package/lib/common/QualityScoreUtils.d.ts.map +0 -1
  199. package/lib/common/QualityScoreUtils.js +0 -1
  200. package/lib/common/TypedEventEmitter.d.ts +0 -22
  201. package/lib/common/TypedEventEmitter.d.ts.map +0 -1
  202. package/lib/common/TypedEventEmitter.js +0 -11
  203. package/lib/common/callEventReports.d.ts +0 -10
  204. package/lib/common/callEventReports.d.ts.map +0 -1
  205. package/lib/common/callEventReports.js +0 -112
  206. package/lib/monitors/CallSummary.d.ts +0 -37
  207. package/lib/monitors/CallSummary.d.ts.map +0 -1
  208. package/lib/monitors/CallSummaryMonitor.d.ts +0 -32
  209. package/lib/monitors/CallSummaryMonitor.d.ts.map +0 -1
  210. package/lib/monitors/CallSummaryMonitor.js +0 -152
  211. package/lib/monitors/ClientIssueMonitor.d.ts +0 -32
  212. package/lib/monitors/ClientIssueMonitor.d.ts.map +0 -1
  213. package/lib/monitors/ClientIssueMonitor.js +0 -49
  214. package/lib/monitors/SfuServerMonitor.d.ts +0 -79
  215. package/lib/monitors/SfuServerMonitor.d.ts.map +0 -1
  216. package/lib/monitors/SfuServerMonitor.js +0 -198
  217. package/src/ObservedICE.ts +0 -237
  218. package/src/ObservedInboundAudioTrack.ts +0 -344
  219. package/src/ObservedInboundVideoTrack.ts +0 -361
  220. package/src/ObservedOutboundAudioTrack.ts +0 -307
  221. package/src/ObservedOutboundVideoTrack.ts +0 -319
  222. package/src/ObservedSfu.ts +0 -231
  223. package/src/ObservedSfuInboundRtpPad.ts +0 -106
  224. package/src/ObservedSfuOutboundRtpPad.ts +0 -107
  225. package/src/ObservedSfuSctpChannel.ts +0 -103
  226. package/src/ObservedSfuTransport.ts +0 -185
  227. package/src/RemoteTrackAssigner.ts +0 -68
  228. package/src/ReportsCollector.ts +0 -336
  229. package/src/common/CalculatedScore.ts +0 -188
  230. package/src/common/CallEventType.ts +0 -69
  231. package/src/common/CallMetaReports.ts +0 -82
  232. package/src/common/QualityScoreUtils.ts +0 -0
  233. package/src/common/TypedEventEmitter.ts +0 -32
  234. package/src/common/callEventReports.ts +0 -178
  235. package/src/monitors/CallSummary.ts +0 -38
  236. package/src/monitors/CallSummaryMonitor.ts +0 -192
  237. package/src/monitors/ClientIssueMonitor.ts +0 -88
  238. package/src/monitors/SfuServerMonitor.ts +0 -285
  239. /package/lib/{monitors/CallSummary.js → scores/CalculatedScore.js} +0 -0
@@ -1,237 +0,0 @@
1
- import { IceCandidatePair, IceLocalCandidate, IceRemoteCandidate } from '@observertc/sample-schemas-js';
2
- import { EventEmitter } from 'events';
3
- import { ObservedPeerConnection } from './ObservedPeerConnection';
4
- import { IceCandidatePairReport } from '@observertc/report-schemas-js';
5
- import { CallMetaType, createCallMetaReport } from './common/CallMetaReports';
6
-
7
- export type ObservedICEEvents = {
8
- update: [{
9
- elapsedTimeInMs: number;
10
- }],
11
- 'new-local-candidate': [IceLocalCandidate],
12
- 'new-remote-candidate': [IceRemoteCandidate],
13
- 'new-selected-candidate-pair': [{
14
- localCandidate: IceLocalCandidate,
15
- remoteCandidate: IceRemoteCandidate,
16
- }],
17
- usingturnchanged: [boolean],
18
- close: [],
19
- };
20
-
21
- export declare interface ObservedICE {
22
- on<U extends keyof ObservedICEEvents>(event: U, listener: (...args: ObservedICEEvents[U]) => void): this;
23
- off<U extends keyof ObservedICEEvents>(event: U, listener: (...args: ObservedICEEvents[U]) => void): this;
24
- once<U extends keyof ObservedICEEvents>(event: U, listener: (...args: ObservedICEEvents[U]) => void): this;
25
- emit<U extends keyof ObservedICEEvents>(event: U, ...args: ObservedICEEvents[U]): boolean;
26
- }
27
-
28
- export class ObservedICE extends EventEmitter {
29
- public static create(peerConnection: ObservedPeerConnection,) {
30
- return new ObservedICE(peerConnection);
31
- }
32
-
33
- public marker?: string;
34
-
35
- private readonly _localCandidates = new Map<string, IceLocalCandidate>();
36
- private readonly _remoteCandidates = new Map<string, IceLocalCandidate>();
37
-
38
- public usingTURN = false;
39
-
40
- public deltaBytesReceived = 0;
41
- public deltaBytesSent = 0;
42
- public deltaPacketsReceived = 0;
43
- public deltaPacketsSent = 0;
44
-
45
- public totalBytesReceived = 0;
46
- public totalBytesSent = 0;
47
- public totalPacketsReceived = 0;
48
- public totalPacketsSent = 0;
49
-
50
- public currentRttInMs?: number;
51
-
52
- private _selectedLocalCandidateId?: string;
53
- private _selectedRemoteCandidateId?: string;
54
- private _updated = Date.now();
55
- private _stats?: IceCandidatePair;
56
- private _closed = false;
57
-
58
- private constructor(
59
- public readonly peerConnection: ObservedPeerConnection,
60
- ) {
61
- super();
62
- this.setMaxListeners(Infinity);
63
- }
64
-
65
- public get reports() {
66
- return this.peerConnection.reports;
67
- }
68
-
69
- public get localCandidates(): ReadonlyMap<string, IceLocalCandidate> {
70
- return this._localCandidates;
71
- }
72
-
73
- public get remoteCandidates(): ReadonlyMap<string, IceRemoteCandidate> {
74
- return this._remoteCandidates;
75
- }
76
-
77
- public get selectedLocalCandidate() {
78
- return this._localCandidates.get(this._selectedLocalCandidateId ?? '');
79
- }
80
-
81
- public get selectedRemoteCandidate() {
82
- return this._remoteCandidates.get(this._selectedRemoteCandidateId ?? '');
83
- }
84
-
85
- public get stats() {
86
- return this._stats;
87
- }
88
-
89
- public get updated() {
90
- return this._updated;
91
- }
92
-
93
- public get closed() {
94
- return this._closed;
95
- }
96
-
97
- public close() {
98
- if (this._closed) return;
99
- this._closed = true;
100
- this.emit('close');
101
- }
102
-
103
- public addLocalCandidate(candidate: IceLocalCandidate, sampleTimestamp?: number) {
104
- if (!candidate.id) return;
105
-
106
- const newCandidate = !this._localCandidates.has(candidate.id);
107
-
108
- this._localCandidates.set(candidate.id, candidate);
109
-
110
- if (newCandidate) {
111
- const callMetaReport = createCallMetaReport(
112
- this.peerConnection.client.serviceId,
113
- this.peerConnection.client.mediaUnitId,
114
- this.peerConnection.client.roomId,
115
- this.peerConnection.client.callId,
116
- this.peerConnection.client.clientId, {
117
- type: CallMetaType.ICE_LOCAL_CANDIDATE,
118
- payload: candidate,
119
- },
120
- this.peerConnection.client.userId,
121
- this.peerConnection.peerConnectionId,
122
- sampleTimestamp,
123
- );
124
-
125
- this.reports.addCallMetaReport(callMetaReport);
126
-
127
- this.emit('new-local-candidate', candidate);
128
- }
129
- }
130
-
131
- public addRemoteCandidate(candidate: IceRemoteCandidate, sampleTimestamp?: number) {
132
- if (!candidate.id) return;
133
-
134
- const newCandidate = !this._remoteCandidates.has(candidate.id);
135
-
136
- this._remoteCandidates.set(candidate.id, candidate);
137
-
138
- if (newCandidate) {
139
- const callMetaReport = createCallMetaReport(
140
- this.peerConnection.client.serviceId,
141
- this.peerConnection.client.mediaUnitId,
142
- this.peerConnection.client.roomId,
143
- this.peerConnection.client.callId,
144
- this.peerConnection.client.clientId, {
145
- type: CallMetaType.ICE_REMOTE_CANDIDATE,
146
- payload: candidate,
147
- },
148
- this.peerConnection.client.userId,
149
- this.peerConnection.peerConnectionId,
150
- sampleTimestamp
151
- );
152
-
153
- this.reports.addCallMetaReport(callMetaReport);
154
-
155
- this.emit('new-remote-candidate', candidate);
156
- }
157
- }
158
-
159
- public resetMetrics() {
160
- this.deltaBytesReceived = 0;
161
- this.deltaBytesSent = 0;
162
- this.deltaPacketsReceived = 0;
163
- this.deltaPacketsSent = 0;
164
-
165
- this.currentRttInMs = undefined;
166
- }
167
-
168
- public update(candidatePair: IceCandidatePair, timestamp: number) {
169
- const now = Date.now();
170
- const elapsedTimeInMs = now - this._updated;
171
- const report: IceCandidatePairReport = {
172
- serviceId: this.peerConnection.client.serviceId,
173
- mediaUnitId: this.peerConnection.client.mediaUnitId,
174
- roomId: this.peerConnection.client.roomId,
175
- callId: this.peerConnection.client.callId,
176
- clientId: this.peerConnection.client.clientId,
177
- userId: this.peerConnection.client.userId,
178
- timestamp,
179
- ...candidatePair,
180
- sampleSeq: -1, // deprecated
181
- marker: this.marker,
182
- };
183
-
184
- this.reports.addIceCandidatePairReport(report);
185
-
186
- if (!candidatePair.nominated) return;
187
-
188
- this.deltaBytesReceived = (candidatePair.bytesReceived ?? 0) - (this._stats?.bytesReceived ?? 0);
189
- this.deltaBytesSent = (candidatePair.bytesSent ?? 0) - (this._stats?.bytesSent ?? 0);
190
- this.deltaPacketsReceived = (candidatePair.packetsReceived ?? 0) - (this._stats?.packetsReceived ?? 0);
191
- this.deltaPacketsSent = (candidatePair.packetsSent ?? 0) - (this._stats?.packetsSent ?? 0);
192
-
193
- this.totalBytesReceived += this.deltaBytesReceived;
194
- this.totalBytesSent += this.deltaBytesSent;
195
- this.totalPacketsReceived += this.deltaPacketsReceived;
196
- this.totalPacketsSent += this.deltaPacketsSent;
197
-
198
- this.currentRttInMs = candidatePair.currentRoundTripTime ? candidatePair.currentRoundTripTime * 1000 : undefined;
199
-
200
- this._stats = candidatePair;
201
-
202
- if (
203
- candidatePair.localCandidateId &&
204
- candidatePair.localCandidateId !== this._selectedLocalCandidateId &&
205
- this._localCandidates.has(candidatePair.localCandidateId) &&
206
- candidatePair.remoteCandidateId &&
207
- candidatePair.remoteCandidateId !== this._selectedRemoteCandidateId &&
208
- this._remoteCandidates.has(candidatePair.remoteCandidateId)
209
- ) {
210
- this._selectedLocalCandidateId = candidatePair.localCandidateId;
211
- this._selectedRemoteCandidateId = candidatePair.remoteCandidateId;
212
-
213
- const localCandidate = this._localCandidates.get(candidatePair.localCandidateId);
214
- const remoteCandidate = this._remoteCandidates.get(candidatePair.remoteCandidateId);
215
-
216
- if (localCandidate && remoteCandidate) {
217
- const wasUsingTURN = this.usingTURN;
218
-
219
- this.usingTURN = (localCandidate.candidateType?.toLocaleLowerCase() === 'relay' ?? false) && (localCandidate.url?.startsWith('turn:') ?? false);
220
-
221
- this.emit('new-selected-candidate-pair', {
222
- localCandidate,
223
- remoteCandidate,
224
- });
225
-
226
- if (wasUsingTURN !== this.usingTURN) {
227
- this.emit('usingturnchanged', this.usingTURN);
228
- }
229
- }
230
- }
231
-
232
- this._updated = now;
233
- this.emit('update', {
234
- elapsedTimeInMs,
235
- });
236
- }
237
- }
@@ -1,344 +0,0 @@
1
- import { EventEmitter } from 'events';
2
- import { ObservedPeerConnection } from './ObservedPeerConnection';
3
- import { InboundAudioTrack } from '@observertc/sample-schemas-js';
4
- import { InboundAudioTrackReport, InboundVideoTrackReport } from '@observertc/report-schemas-js';
5
- import { calculateBaseAudioScore, CalculatedScore } from './common/CalculatedScore';
6
- import { ClientIssue } from './monitors/CallSummary';
7
- import { ObservedOutboundAudioTrack } from './ObservedOutboundAudioTrack';
8
-
9
- export type ObservedInboundAudioTrackModel = {
10
- trackId: string;
11
- sfuStreamId?: string;
12
- sfuSinkId?: string;
13
- }
14
-
15
- export type ObservedInboundAudioTrackEvents = {
16
- update: [{
17
- elapsedTimeInMs: number;
18
- }],
19
- score: [CalculatedScore],
20
- close: [],
21
- remoteoutboundtrack: [ObservedOutboundAudioTrack | undefined],
22
- };
23
-
24
- export type ObservedInboundAudioTrackStats = InboundAudioTrack & {
25
- ssrc: number;
26
- bitrate: number;
27
- fractionLost: number;
28
- rttInMs?: number;
29
- deltaReceivedBytes?: number;
30
- deltaLostPackets?: number;
31
- deltaReceivedPackets?: number;
32
- deltaReceivedFrames?: number;
33
- deltaDecodedFrames?: number;
34
- deltaDroppedFrames?: number;
35
- deltaReceivedSamples?: number;
36
- deltaSilentConcealedSamples?: number;
37
- fractionLoss?: number;
38
- statsTimestamp: number;
39
- };
40
-
41
- // {
42
- // [Property in keyof ObservedInboundAudioTrackStats<K>]: ObservedInboundAudioTrackStats<K>[Property];
43
- // }
44
-
45
- export declare interface ObservedInboundAudioTrack {
46
- on<U extends keyof ObservedInboundAudioTrackEvents>(event: U, listener: (...args: ObservedInboundAudioTrackEvents[U]) => void): this;
47
- off<U extends keyof ObservedInboundAudioTrackEvents>(event: U, listener: (...args: ObservedInboundAudioTrackEvents[U]) => void): this;
48
- once<U extends keyof ObservedInboundAudioTrackEvents>(event: U, listener: (...args: ObservedInboundAudioTrackEvents[U]) => void): this;
49
- emit<U extends keyof ObservedInboundAudioTrackEvents>(event: U, ...args: ObservedInboundAudioTrackEvents[U]): boolean;
50
- update(sample: InboundAudioTrack, timestamp: number): void;
51
- }
52
-
53
- export class ObservedInboundAudioTrack extends EventEmitter {
54
- public readonly created = Date.now();
55
- public visited = false;
56
-
57
- // timestamp of the MEDIA_TRACK_ADDED event
58
- public added?: number;
59
- // timestamp of the MEDIA_TRACK_REMOVED event
60
- public removed?: number;
61
-
62
- private readonly _stats = new Map<number, ObservedInboundAudioTrackStats>();
63
-
64
- private _closed = false;
65
- private _updated = Date.now();
66
- private _remoteOutboundTrack?: ObservedOutboundAudioTrack;
67
- private _lastMaxStatsTimestamp = 0;
68
-
69
- public bitrate = 0;
70
- public rttInMs?: number;
71
- public jitter?: number;
72
- public fractionLoss = 0;
73
- public marker?: string;
74
-
75
- public totalLostPackets = 0;
76
- public totalReceivedPackets = 0;
77
- public totalBytesReceived = 0;
78
- public totalReceivedSamples = 0;
79
- public totalSilentConcealedSamples = 0;
80
-
81
- public deltaLostPackets = 0;
82
- public deltaReceivedPackets = 0;
83
- public deltaBytesReceived = 0;
84
- public deltaReceivedSamples = 0;
85
- public deltaSilentConcealedSamples = 0;
86
-
87
- public score?: CalculatedScore;
88
- public ωpendingIssuesForScores: ClientIssue[] = [];
89
-
90
- public constructor(
91
- private readonly _model: ObservedInboundAudioTrackModel,
92
- public readonly peerConnection: ObservedPeerConnection,
93
- ) {
94
- super();
95
- this.setMaxListeners(Infinity);
96
- }
97
-
98
- public get serviceId() {
99
- return this.peerConnection.serviceId;
100
- }
101
-
102
- public get roomId() {
103
- return this.peerConnection.roomId;
104
- }
105
-
106
- public get callId() {
107
- return this.peerConnection.callId;
108
- }
109
-
110
- public get clientId() {
111
- return this.peerConnection.clientId;
112
- }
113
-
114
- public get mediaUnitId() {
115
- return this.peerConnection.mediaUnitId;
116
- }
117
-
118
- public get peerConnectionId() {
119
- return this.peerConnection.peerConnectionId;
120
- }
121
-
122
- public get trackId() {
123
- return this._model.trackId;
124
- }
125
-
126
- public get sfuStreamId() {
127
- return this._model.sfuStreamId;
128
- }
129
-
130
- public get sfuSinkId() {
131
- return this._model.sfuSinkId;
132
- }
133
-
134
- public get updated() {
135
- return this._updated;
136
- }
137
-
138
- public get statsTimestamp() {
139
- return this._lastMaxStatsTimestamp;
140
- }
141
-
142
- public get stats(): ReadonlyMap<number, ObservedInboundAudioTrackStats> {
143
- return this._stats;
144
- }
145
-
146
- public get reports() {
147
- return this.peerConnection.reports;
148
- }
149
-
150
- public set remoteOutboundTrack(track: ObservedOutboundAudioTrack | undefined) {
151
- if (this._closed) return;
152
- if (this._remoteOutboundTrack) return;
153
- if (!track) return;
154
-
155
- track.once('close', () => {
156
- this._remoteOutboundTrack = undefined;
157
- this.emit('remoteoutboundtrack', undefined);
158
- });
159
- this._remoteOutboundTrack = track;
160
- this.emit('remoteoutboundtrack', track);
161
- }
162
-
163
- public get remoteOutboundTrack() {
164
- return this._remoteOutboundTrack;
165
- }
166
-
167
- public get closed() {
168
- return this._closed;
169
- }
170
-
171
- public close() {
172
- if (this._closed) return;
173
-
174
- this._closed = true;
175
-
176
- this.emit('close');
177
- }
178
-
179
- public update(sample: InboundAudioTrack, statsTimestamp: number) {
180
- if (this._closed) return;
181
-
182
- const now = Date.now();
183
- const report: InboundAudioTrackReport | InboundVideoTrackReport = {
184
- serviceId: this.peerConnection.client.call.serviceId,
185
- roomId: this.peerConnection.client.call.roomId,
186
- callId: this.peerConnection.client.call.callId,
187
- clientId: this.peerConnection.client.clientId,
188
- userId: this.peerConnection.client.userId,
189
- mediaUnitId: this.peerConnection.client.mediaUnitId,
190
- peerConnectionId: this.peerConnection.peerConnectionId,
191
- ...sample,
192
- timestamp: statsTimestamp,
193
- sampleSeq: -1,
194
-
195
- remoteClientId: sample.remoteClientId ?? this.remoteOutboundTrack?.peerConnection.client.clientId,
196
- remoteUserId: this.remoteOutboundTrack?.peerConnection.client.userId,
197
- remoteTrackId: this.remoteOutboundTrack?.trackId,
198
- remotePeerConnectionId: this.remoteOutboundTrack?.peerConnection.peerConnectionId,
199
- marker: this.marker,
200
- };
201
-
202
- this.reports.addInboundAudioTrackReport(report);
203
-
204
- if (!this._model.sfuStreamId && sample.sfuStreamId) {
205
- this._model.sfuStreamId = sample.sfuStreamId;
206
- }
207
-
208
- if (!this._model.sfuSinkId && sample.sfuSinkId) {
209
- this._model.sfuSinkId = sample.sfuSinkId;
210
- }
211
-
212
- const elapsedTimeInMs = Math.max(1, now - this._updated);
213
- const lastStat = this._stats.get(sample.ssrc);
214
- const rttInMs = sample.roundTripTime ? sample.roundTripTime * 1000 : undefined;
215
- let bitrate = 0;
216
- let deltaReceivedBytes = 0;
217
- let fractionLost = 0;
218
- let deltaLostPackets = 0;
219
- let deltaReceivedPackets = 0;
220
-
221
- if (lastStat?.bytesReceived && sample.bytesReceived && lastStat.bytesReceived < sample.bytesReceived) {
222
- deltaReceivedBytes = sample.bytesReceived - lastStat.bytesReceived;
223
- bitrate = deltaReceivedBytes / (elapsedTimeInMs / 1000);
224
- }
225
- if (lastStat?.packetsReceived && sample?.packetsReceived && lastStat.packetsReceived < sample.packetsReceived) {
226
- deltaReceivedPackets = sample.packetsReceived - lastStat.packetsReceived;
227
- }
228
- if (lastStat?.packetsLost && sample.packetsLost && lastStat.packetsLost < sample.packetsLost) {
229
- deltaLostPackets = sample.packetsLost - lastStat.packetsLost;
230
- if (0 < deltaReceivedPackets) {
231
- fractionLost = deltaLostPackets / (deltaReceivedPackets + deltaLostPackets);
232
- }
233
- }
234
-
235
- let deltaDecodedFrames: number | undefined;
236
- let deltaDroppedFrames: number | undefined;
237
- let deltaReceivedFrames: number | undefined;
238
- let deltaSilentConcealedSamples: number | undefined;
239
- const audioSample = sample as InboundAudioTrack;
240
- const lastAudioStat = lastStat as InboundAudioTrack | undefined;
241
-
242
- if (audioSample.silentConcealedSamples && lastAudioStat?.silentConcealedSamples && lastAudioStat.silentConcealedSamples < audioSample.silentConcealedSamples) {
243
- deltaSilentConcealedSamples = audioSample.silentConcealedSamples - lastAudioStat.silentConcealedSamples;
244
- }
245
-
246
- const stats: ObservedInboundAudioTrackStats = {
247
- ...sample,
248
- fractionLost,
249
- rttInMs,
250
- bitrate,
251
- ssrc: sample.ssrc,
252
- deltaReceivedBytes,
253
- deltaLostPackets,
254
- deltaReceivedPackets,
255
- deltaReceivedFrames,
256
- deltaDecodedFrames,
257
- deltaDroppedFrames,
258
- deltaSilentConcealedSamples,
259
- statsTimestamp,
260
- };
261
-
262
- this._stats.set(sample.ssrc, stats);
263
-
264
- this.visited = true;
265
- // a peer connection is active if it has at least one active track
266
- this.peerConnection.visited = true;
267
-
268
- this._updated = now;
269
-
270
- this.emit('update', {
271
- elapsedTimeInMs,
272
- });
273
- }
274
-
275
- public updateMetrics() {
276
- let maxStatsTimestamp = 0;
277
- let rttInMsSum = 0;
278
- let jitterSum = 0;
279
- let size = 0;
280
-
281
- this.bitrate = 0;
282
- this.rttInMs = undefined;
283
- this.deltaBytesReceived = 0;
284
- this.deltaLostPackets = 0;
285
- this.deltaReceivedSamples = 0;
286
- this.deltaSilentConcealedSamples = 0;
287
- this.fractionLoss = 0;
288
-
289
- for (const [ , stats ] of this._stats) {
290
- if (stats.statsTimestamp <= this._lastMaxStatsTimestamp) continue;
291
-
292
- this.deltaBytesReceived += stats.deltaReceivedBytes ?? 0;
293
- this.deltaLostPackets += stats.deltaLostPackets ?? 0;
294
- this.deltaReceivedPackets += stats.deltaReceivedFrames ?? 0;
295
- this.deltaReceivedSamples += stats.deltaReceivedSamples ?? 0;
296
- this.deltaSilentConcealedSamples += stats.deltaSilentConcealedSamples ?? 0;
297
- this.bitrate += stats.bitrate;
298
-
299
- maxStatsTimestamp = Math.max(maxStatsTimestamp, stats.statsTimestamp);
300
-
301
- rttInMsSum += stats.rttInMs ?? 0;
302
- jitterSum += stats.jitter ?? 0;
303
- ++size;
304
- }
305
-
306
- this.totalBytesReceived += this.deltaBytesReceived;
307
- this.totalLostPackets += this.deltaLostPackets;
308
- this.totalReceivedPackets += this.deltaReceivedPackets;
309
- this.totalReceivedSamples += this.deltaReceivedSamples;
310
- this.totalSilentConcealedSamples += this.deltaSilentConcealedSamples;
311
-
312
- this.rttInMs = rttInMsSum / Math.max(size, 1);
313
- this.jitter = jitterSum / Math.max(size, 1);
314
- this.fractionLoss = 0 < this.deltaReceivedPackets && 0 < this.deltaLostPackets ? (this.deltaLostPackets / (this.deltaReceivedPackets + this.deltaLostPackets)) : 0;
315
-
316
- this._lastMaxStatsTimestamp = maxStatsTimestamp;
317
-
318
- this._updateQualityScore(maxStatsTimestamp);
319
- }
320
-
321
- private _updateQualityScore(timestamp: number) {
322
- const newIssues = this.ωpendingIssuesForScores;
323
- const score = calculateBaseAudioScore(this, newIssues);
324
-
325
- if (0 < newIssues.length) {
326
- this.ωpendingIssuesForScores = [];
327
- }
328
-
329
- if (!score) return (this.score = undefined);
330
-
331
- if (0.05 < this.fractionLoss) {
332
- score.score *= 0.5;
333
- score.remarks.push({
334
- severity: 'major',
335
- text: 'Fraction loss is too high',
336
- });
337
- }
338
-
339
- score.timestamp = timestamp;
340
- this.score = score;
341
-
342
- this.emit('score', this.score);
343
- }
344
- }