@observertc/observer-js 0.42.8 → 1.0.0-beta.1

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 (299) hide show
  1. package/.prettierrc +6 -6
  2. package/README.md +493 -63
  3. package/lib/ObservedCall.d.ts +63 -43
  4. package/lib/ObservedCall.d.ts.map +1 -1
  5. package/lib/ObservedCall.js +188 -108
  6. package/lib/ObservedCallEventMonitor.d.ts +104 -0
  7. package/lib/ObservedCallEventMonitor.d.ts.map +1 -0
  8. package/lib/ObservedCallEventMonitor.js +314 -0
  9. package/lib/ObservedCallSummary.d.ts +18 -0
  10. package/lib/ObservedCallSummary.d.ts.map +1 -0
  11. package/lib/ObservedCertificate.d.ts +19 -0
  12. package/lib/ObservedCertificate.d.ts.map +1 -0
  13. package/lib/ObservedCertificate.js +38 -0
  14. package/lib/ObservedClient.d.ts +81 -136
  15. package/lib/ObservedClient.d.ts.map +1 -1
  16. package/lib/ObservedClient.js +581 -744
  17. package/lib/ObservedClientEventMonitor.d.ts +91 -0
  18. package/lib/ObservedClientEventMonitor.d.ts.map +1 -0
  19. package/lib/ObservedClientEventMonitor.js +254 -0
  20. package/lib/ObservedClientSummary.d.ts +23 -0
  21. package/lib/ObservedClientSummary.d.ts.map +1 -0
  22. package/lib/ObservedClientSummary.js +2 -0
  23. package/lib/ObservedCodec.d.ts +22 -0
  24. package/lib/ObservedCodec.d.ts.map +1 -0
  25. package/lib/ObservedCodec.js +45 -0
  26. package/lib/ObservedDataChannel.d.ts +25 -69
  27. package/lib/ObservedDataChannel.d.ts.map +1 -1
  28. package/lib/ObservedDataChannel.js +69 -109
  29. package/lib/ObservedIceCandidate.d.ts +29 -0
  30. package/lib/ObservedIceCandidate.d.ts.map +1 -0
  31. package/lib/ObservedIceCandidate.js +59 -0
  32. package/lib/ObservedIceCandidatePair.d.ts +45 -0
  33. package/lib/ObservedIceCandidatePair.d.ts.map +1 -0
  34. package/lib/ObservedIceCandidatePair.js +127 -0
  35. package/lib/ObservedIceTransport.d.ts +36 -0
  36. package/lib/ObservedIceTransport.d.ts.map +1 -0
  37. package/lib/ObservedIceTransport.js +93 -0
  38. package/lib/ObservedInboundRtp.d.ts +92 -0
  39. package/lib/ObservedInboundRtp.d.ts.map +1 -0
  40. package/lib/ObservedInboundRtp.js +193 -0
  41. package/lib/ObservedInboundTrack.d.ts +32 -0
  42. package/lib/ObservedInboundTrack.d.ts.map +1 -0
  43. package/lib/ObservedInboundTrack.js +60 -0
  44. package/lib/ObservedMediaPlayout.d.ts +22 -0
  45. package/lib/ObservedMediaPlayout.d.ts.map +1 -0
  46. package/lib/ObservedMediaPlayout.js +42 -0
  47. package/lib/ObservedMediaSource.d.ts +28 -0
  48. package/lib/ObservedMediaSource.d.ts.map +1 -0
  49. package/lib/ObservedMediaSource.js +55 -0
  50. package/lib/ObservedOutboundRtp.d.ts +62 -0
  51. package/lib/ObservedOutboundRtp.d.ts.map +1 -0
  52. package/lib/ObservedOutboundRtp.js +144 -0
  53. package/lib/ObservedOutboundTrack.d.ts +32 -0
  54. package/lib/ObservedOutboundTrack.d.ts.map +1 -0
  55. package/lib/ObservedOutboundTrack.js +60 -0
  56. package/lib/ObservedPeerConnection.d.ts +154 -80
  57. package/lib/ObservedPeerConnection.d.ts.map +1 -1
  58. package/lib/ObservedPeerConnection.js +709 -357
  59. package/lib/ObservedPeerConnectionTransport.d.ts +17 -0
  60. package/lib/ObservedPeerConnectionTransport.d.ts.map +1 -0
  61. package/lib/ObservedPeerConnectionTransport.js +34 -0
  62. package/lib/ObservedRemoteInboundRtp.d.ts +30 -0
  63. package/lib/ObservedRemoteInboundRtp.d.ts.map +1 -0
  64. package/lib/ObservedRemoteInboundRtp.js +60 -0
  65. package/lib/ObservedRemoteOutboundRtp.d.ts +30 -0
  66. package/lib/ObservedRemoteOutboundRtp.d.ts.map +1 -0
  67. package/lib/ObservedRemoteOutboundRtp.js +60 -0
  68. package/lib/ObservedTURN.d.ts +31 -0
  69. package/lib/ObservedTURN.d.ts.map +1 -0
  70. package/lib/ObservedTURN.js +58 -0
  71. package/lib/ObservedTurnServer.d.ts +25 -0
  72. package/lib/ObservedTurnServer.d.ts.map +1 -0
  73. package/lib/ObservedTurnServer.js +59 -0
  74. package/lib/Observer.d.ts +49 -54
  75. package/lib/Observer.d.ts.map +1 -1
  76. package/lib/Observer.js +131 -226
  77. package/lib/ObserverEventMonitor.d.ts +138 -0
  78. package/lib/ObserverEventMonitor.d.ts.map +1 -0
  79. package/lib/ObserverEventMonitor.js +433 -0
  80. package/lib/ObserverSummary.d.ts +13 -0
  81. package/lib/ObserverSummary.d.ts.map +1 -0
  82. package/lib/ObserverSummary.js +2 -0
  83. package/lib/common/Middleware.d.ts +10 -1
  84. package/lib/common/Middleware.d.ts.map +1 -1
  85. package/lib/common/Middleware.js +55 -36
  86. package/lib/common/logger.d.ts +8 -4
  87. package/lib/common/logger.d.ts.map +1 -1
  88. package/lib/common/logger.js +44 -68
  89. package/lib/common/types.d.ts +0 -21
  90. package/lib/common/types.d.ts.map +1 -1
  91. package/lib/common/types.js +1 -0
  92. package/lib/common/utils.d.ts +3 -1
  93. package/lib/common/utils.d.ts.map +1 -1
  94. package/lib/common/utils.js +23 -3
  95. package/lib/detectors/Detector.d.ts +5 -0
  96. package/lib/detectors/Detector.d.ts.map +1 -0
  97. package/lib/detectors/Detector.js +3 -0
  98. package/lib/detectors/Detectors.d.ts +11 -0
  99. package/lib/detectors/Detectors.d.ts.map +1 -0
  100. package/lib/detectors/Detectors.js +34 -0
  101. package/lib/index.d.ts +26 -24
  102. package/lib/index.d.ts.map +1 -1
  103. package/lib/index.js +45 -41
  104. package/lib/mediasoup/ObservedMediaRouter.d.ts +10 -0
  105. package/lib/mediasoup/ObservedMediaRouter.d.ts.map +1 -0
  106. package/lib/mediasoup/ObservedMediaRouter.js +6 -0
  107. package/lib/monitors/TurnUsageMonitor.d.ts +0 -52
  108. package/lib/monitors/TurnUsageMonitor.d.ts.map +1 -1
  109. package/lib/monitors/TurnUsageMonitor.js +145 -120
  110. package/lib/schema/ClientEventTypes.d.ts +228 -0
  111. package/lib/schema/ClientEventTypes.d.ts.map +1 -0
  112. package/lib/schema/ClientEventTypes.js +41 -0
  113. package/lib/schema/ClientMetaTypes.d.ts +34 -0
  114. package/lib/schema/ClientMetaTypes.d.ts.map +1 -0
  115. package/lib/schema/ClientMetaTypes.js +16 -0
  116. package/lib/schema/ClientSample.d.ts +1333 -0
  117. package/lib/schema/ClientSample.d.ts.map +1 -0
  118. package/lib/schema/ClientSample.js +4 -0
  119. package/lib/scores/CalculatedScore.d.ts +6 -0
  120. package/lib/scores/CalculatedScore.d.ts.map +1 -0
  121. package/lib/scores/CalculatedScore.js +2 -0
  122. package/lib/scores/DefaultCallScoreCalculator.d.ts +7 -0
  123. package/lib/scores/DefaultCallScoreCalculator.d.ts.map +1 -0
  124. package/lib/scores/DefaultCallScoreCalculator.js +21 -0
  125. package/lib/scores/ScoreCalculator.d.ts +4 -0
  126. package/lib/scores/ScoreCalculator.d.ts.map +1 -0
  127. package/lib/scores/ScoreCalculator.js +2 -0
  128. package/lib/updaters/CallUpdater.d.ts +5 -0
  129. package/lib/updaters/CallUpdater.d.ts.map +1 -0
  130. package/lib/updaters/CallUpdater.js +2 -0
  131. package/lib/updaters/ObserverUpdater.d.ts +5 -0
  132. package/lib/updaters/ObserverUpdater.d.ts.map +1 -0
  133. package/lib/updaters/ObserverUpdater.js +2 -0
  134. package/lib/updaters/OnAllCallObserverUpdater.d.ts +15 -0
  135. package/lib/updaters/OnAllCallObserverUpdater.d.ts.map +1 -0
  136. package/lib/updaters/OnAllCallObserverUpdater.js +50 -0
  137. package/lib/updaters/OnAllClientCallUpdater.d.ts +15 -0
  138. package/lib/updaters/OnAllClientCallUpdater.d.ts.map +1 -0
  139. package/lib/updaters/OnAllClientCallUpdater.js +53 -0
  140. package/lib/updaters/OnAnyCallObserverUpdater.d.ts +12 -0
  141. package/lib/updaters/OnAnyCallObserverUpdater.d.ts.map +1 -0
  142. package/lib/updaters/OnAnyCallObserverUpdater.js +37 -0
  143. package/lib/updaters/OnAnyClientCallUpdater.d.ts +12 -0
  144. package/lib/updaters/OnAnyClientCallUpdater.d.ts.map +1 -0
  145. package/lib/updaters/OnAnyClientCallUpdater.js +36 -0
  146. package/lib/updaters/OnIntervalUpdater.d.ts +10 -0
  147. package/lib/updaters/OnIntervalUpdater.d.ts.map +1 -0
  148. package/lib/updaters/OnIntervalUpdater.js +17 -0
  149. package/lib/updaters/Updater.d.ts +6 -0
  150. package/lib/updaters/Updater.d.ts.map +1 -0
  151. package/lib/updaters/Updater.js +2 -0
  152. package/lib/utils/MediasoupRemoteTrackResolver.d.ts +25 -0
  153. package/lib/utils/MediasoupRemoteTrackResolver.d.ts.map +1 -0
  154. package/lib/utils/MediasoupRemoteTrackResolver.js +110 -0
  155. package/lib/utils/RemoteTrackResolver.d.ts +7 -0
  156. package/lib/utils/RemoteTrackResolver.d.ts.map +1 -0
  157. package/lib/utils/RemoteTrackResolver.js +2 -0
  158. package/package.json +4 -4
  159. package/src/ObservedCall.ts +276 -164
  160. package/src/ObservedCallEventMonitor.ts +392 -0
  161. package/src/ObservedCallSummary.ts +22 -0
  162. package/src/ObservedCertificate.ts +43 -0
  163. package/src/ObservedClient.ts +625 -1006
  164. package/src/ObservedClientEventMonitor.ts +309 -0
  165. package/src/ObservedClientSummary.ts +24 -0
  166. package/src/ObservedCodec.ts +49 -0
  167. package/src/ObservedDataChannel.ts +71 -181
  168. package/src/ObservedIceCandidate.ts +64 -0
  169. package/src/ObservedIceCandidatePair.ts +134 -0
  170. package/src/ObservedIceTransport.ts +99 -0
  171. package/src/ObservedInboundRtp.ts +205 -0
  172. package/src/ObservedInboundTrack.ts +75 -0
  173. package/src/ObservedMediaPlayout.ts +49 -0
  174. package/src/ObservedMediaSource.ts +60 -0
  175. package/src/ObservedOutboundRtp.ts +156 -0
  176. package/src/ObservedOutboundTrack.ts +74 -0
  177. package/src/ObservedPeerConnection.ts +917 -402
  178. package/src/ObservedPeerConnectionTransport.ts +38 -0
  179. package/src/ObservedRemoteInboundRtp.ts +64 -0
  180. package/src/ObservedRemoteOutboundRtp.ts +65 -0
  181. package/src/ObservedTURN.ts +86 -0
  182. package/src/ObservedTurnServer.ts +72 -0
  183. package/src/Observer.ts +182 -298
  184. package/src/ObserverEventMonitor.ts +551 -0
  185. package/src/ObserverSummary.ts +15 -0
  186. package/src/common/Middleware.ts +70 -42
  187. package/src/common/logger.ts +60 -69
  188. package/src/common/types.ts +0 -42
  189. package/src/common/utils.ts +24 -2
  190. package/src/detectors/Detector.ts +6 -0
  191. package/src/detectors/Detectors.ts +38 -0
  192. package/src/index.ts +26 -88
  193. package/src/mediasoup/ObservedMediaRouter.ts +10 -0
  194. package/src/monitors/TurnUsageMonitor.ts +164 -164
  195. package/src/schema/ClientEventTypes.ts +280 -0
  196. package/src/schema/ClientMetaTypes.ts +41 -0
  197. package/src/schema/ClientSample.ts +1682 -0
  198. package/src/scores/CalculatedScore.ts +6 -0
  199. package/src/scores/DefaultCallScoreCalculator.ts +23 -0
  200. package/src/scores/ScoreCalculator.ts +3 -0
  201. package/src/updaters/CallUpdater.ts +5 -0
  202. package/src/updaters/ObserverUpdater.ts +5 -0
  203. package/src/updaters/OnAllCallObserverUpdater.ts +59 -0
  204. package/src/updaters/OnAllClientCallUpdater.ts +61 -0
  205. package/src/updaters/OnAnyCallObserverUpdater.ts +41 -0
  206. package/src/updaters/OnAnyClientCallUpdater.ts +39 -0
  207. package/src/updaters/OnIntervalUpdater.ts +19 -0
  208. package/src/updaters/Updater.ts +5 -0
  209. package/src/utils/MediasoupRemoteTrackResolver.ts +155 -0
  210. package/src/utils/RemoteTrackResolver.ts +12 -0
  211. package/tsconfig.json +3 -3
  212. package/lib/ObservedICE.d.ts +0 -64
  213. package/lib/ObservedICE.d.ts.map +0 -1
  214. package/lib/ObservedICE.js +0 -141
  215. package/lib/ObservedInboundAudioTrack.d.ts +0 -96
  216. package/lib/ObservedInboundAudioTrack.d.ts.map +0 -1
  217. package/lib/ObservedInboundAudioTrack.js +0 -217
  218. package/lib/ObservedInboundVideoTrack.d.ts +0 -101
  219. package/lib/ObservedInboundVideoTrack.d.ts.map +0 -1
  220. package/lib/ObservedInboundVideoTrack.js +0 -232
  221. package/lib/ObservedOutboundAudioTrack.d.ts +0 -87
  222. package/lib/ObservedOutboundAudioTrack.d.ts.map +0 -1
  223. package/lib/ObservedOutboundAudioTrack.js +0 -186
  224. package/lib/ObservedOutboundVideoTrack.d.ts +0 -91
  225. package/lib/ObservedOutboundVideoTrack.d.ts.map +0 -1
  226. package/lib/ObservedOutboundVideoTrack.js +0 -193
  227. package/lib/ObservedSfu.d.ts +0 -59
  228. package/lib/ObservedSfu.d.ts.map +0 -1
  229. package/lib/ObservedSfu.js +0 -157
  230. package/lib/ObservedSfuInboundRtpPad.d.ts +0 -42
  231. package/lib/ObservedSfuInboundRtpPad.d.ts.map +0 -1
  232. package/lib/ObservedSfuInboundRtpPad.js +0 -71
  233. package/lib/ObservedSfuOutboundRtpPad.d.ts +0 -42
  234. package/lib/ObservedSfuOutboundRtpPad.d.ts.map +0 -1
  235. package/lib/ObservedSfuOutboundRtpPad.js +0 -72
  236. package/lib/ObservedSfuSctpChannel.d.ts +0 -42
  237. package/lib/ObservedSfuSctpChannel.d.ts.map +0 -1
  238. package/lib/ObservedSfuSctpChannel.js +0 -57
  239. package/lib/ObservedSfuTransport.d.ts +0 -58
  240. package/lib/ObservedSfuTransport.d.ts.map +0 -1
  241. package/lib/ObservedSfuTransport.js +0 -120
  242. package/lib/RemoteTrackAssigner.d.ts +0 -14
  243. package/lib/RemoteTrackAssigner.d.ts.map +0 -1
  244. package/lib/RemoteTrackAssigner.js +0 -52
  245. package/lib/ReportsCollector.d.ts +0 -109
  246. package/lib/ReportsCollector.d.ts.map +0 -1
  247. package/lib/ReportsCollector.js +0 -207
  248. package/lib/common/CalculatedScore.d.ts +0 -80
  249. package/lib/common/CalculatedScore.d.ts.map +0 -1
  250. package/lib/common/CalculatedScore.js +0 -162
  251. package/lib/common/CallEventType.d.ts +0 -63
  252. package/lib/common/CallEventType.d.ts.map +0 -1
  253. package/lib/common/CallEventType.js +0 -39
  254. package/lib/common/CallMetaReports.d.ts +0 -42
  255. package/lib/common/CallMetaReports.d.ts.map +0 -1
  256. package/lib/common/CallMetaReports.js +0 -36
  257. package/lib/common/QualityScoreUtils.d.ts +0 -1
  258. package/lib/common/QualityScoreUtils.d.ts.map +0 -1
  259. package/lib/common/QualityScoreUtils.js +0 -1
  260. package/lib/common/TypedEventEmitter.d.ts +0 -22
  261. package/lib/common/TypedEventEmitter.d.ts.map +0 -1
  262. package/lib/common/TypedEventEmitter.js +0 -11
  263. package/lib/common/callEventReports.d.ts +0 -10
  264. package/lib/common/callEventReports.d.ts.map +0 -1
  265. package/lib/common/callEventReports.js +0 -112
  266. package/lib/monitors/CallSummary.d.ts +0 -37
  267. package/lib/monitors/CallSummary.d.ts.map +0 -1
  268. package/lib/monitors/CallSummaryMonitor.d.ts +0 -32
  269. package/lib/monitors/CallSummaryMonitor.d.ts.map +0 -1
  270. package/lib/monitors/CallSummaryMonitor.js +0 -152
  271. package/lib/monitors/ClientIssueMonitor.d.ts +0 -32
  272. package/lib/monitors/ClientIssueMonitor.d.ts.map +0 -1
  273. package/lib/monitors/ClientIssueMonitor.js +0 -49
  274. package/lib/monitors/SfuServerMonitor.d.ts +0 -79
  275. package/lib/monitors/SfuServerMonitor.d.ts.map +0 -1
  276. package/lib/monitors/SfuServerMonitor.js +0 -198
  277. package/src/ObservedICE.ts +0 -237
  278. package/src/ObservedInboundAudioTrack.ts +0 -344
  279. package/src/ObservedInboundVideoTrack.ts +0 -361
  280. package/src/ObservedOutboundAudioTrack.ts +0 -307
  281. package/src/ObservedOutboundVideoTrack.ts +0 -319
  282. package/src/ObservedSfu.ts +0 -231
  283. package/src/ObservedSfuInboundRtpPad.ts +0 -106
  284. package/src/ObservedSfuOutboundRtpPad.ts +0 -107
  285. package/src/ObservedSfuSctpChannel.ts +0 -103
  286. package/src/ObservedSfuTransport.ts +0 -185
  287. package/src/RemoteTrackAssigner.ts +0 -68
  288. package/src/ReportsCollector.ts +0 -336
  289. package/src/common/CalculatedScore.ts +0 -188
  290. package/src/common/CallEventType.ts +0 -69
  291. package/src/common/CallMetaReports.ts +0 -82
  292. package/src/common/QualityScoreUtils.ts +0 -0
  293. package/src/common/TypedEventEmitter.ts +0 -32
  294. package/src/common/callEventReports.ts +0 -178
  295. package/src/monitors/CallSummary.ts +0 -38
  296. package/src/monitors/CallSummaryMonitor.ts +0 -192
  297. package/src/monitors/ClientIssueMonitor.ts +0 -88
  298. package/src/monitors/SfuServerMonitor.ts +0 -285
  299. /package/lib/{monitors/CallSummary.js → ObservedCallSummary.js} +0 -0
@@ -1,361 +0,0 @@
1
- import { EventEmitter } from 'events';
2
- import { ObservedPeerConnection } from './ObservedPeerConnection';
3
- import { InboundVideoTrack } from '@observertc/sample-schemas-js';
4
- import { InboundAudioTrackReport, InboundVideoTrackReport } from '@observertc/report-schemas-js';
5
- import { CalculatedScore, calculateBaseVideoScore } from './common/CalculatedScore';
6
- import { ClientIssue } from './monitors/CallSummary';
7
- import { ObservedOutboundVideoTrack } from './ObservedOutboundVideoTrack';
8
- import { SupportedVideoCodecType } from './common/types';
9
-
10
- export type ObservedInboundVideoTrackModel = {
11
- trackId: string;
12
- sfuStreamId?: string;
13
- sfuSinkId?: string;
14
- }
15
-
16
- export type ObservedInboundVideoTrackEvents = {
17
- update: [{
18
- elapsedTimeInMs: number;
19
- }],
20
- score: [CalculatedScore],
21
- close: [],
22
- remoteoutboundtrack: [ObservedOutboundVideoTrack | undefined],
23
- };
24
-
25
- export type ObservedInboundVideoTrackStatsUpdate = InboundVideoTrack;
26
-
27
- export type ObservedInboundVideoTrackStats = InboundVideoTrack & {
28
- ssrc: number;
29
- bitrate: number;
30
- fractionLost: number;
31
- rttInMs?: number;
32
- deltaReceivedBytes?: number;
33
- deltaLostPackets?: number;
34
- deltaReceivedPackets?: number;
35
- deltaReceivedFrames?: number;
36
- deltaDecodedFrames?: number;
37
- deltaDroppedFrames?: number;
38
- fractionLoss?: number;
39
- statsTimestamp: number;
40
- };
41
-
42
- // {
43
- // [Property in keyof ObservedInboundTrackStats<K>]: ObservedInboundTrackStats<K>[Property];
44
- // }
45
-
46
- export declare interface ObservedInboundVideoTrack {
47
- on<U extends keyof ObservedInboundVideoTrackEvents>(event: U, listener: (...args: ObservedInboundVideoTrackEvents[U]) => void): this;
48
- off<U extends keyof ObservedInboundVideoTrackEvents>(event: U, listener: (...args: ObservedInboundVideoTrackEvents[U]) => void): this;
49
- once<U extends keyof ObservedInboundVideoTrackEvents>(event: U, listener: (...args: ObservedInboundVideoTrackEvents[U]) => void): this;
50
- emit<U extends keyof ObservedInboundVideoTrackEvents>(event: U, ...args: ObservedInboundVideoTrackEvents[U]): boolean;
51
- update(sample: InboundVideoTrack, timestamp: number): void;
52
- }
53
-
54
- export class ObservedInboundVideoTrack extends EventEmitter {
55
- public readonly created = Date.now();
56
- public visited = false;
57
-
58
- // timestamp of the MEDIA_TRACK_ADDED event
59
- public added?: number;
60
- // timestamp of the MEDIA_TRACK_REMOVED event
61
- public removed?: number;
62
-
63
- public contentType: 'lowmotion' | 'standard' | 'highmotion' = 'standard';
64
- public codec?: SupportedVideoCodecType;
65
-
66
- private readonly _stats = new Map<number, ObservedInboundVideoTrackStats>();
67
-
68
- private _closed = false;
69
- private _updated = Date.now();
70
- private _remoteOutboundTrack?: ObservedOutboundVideoTrack;
71
- private _lastMaxStatsTimestamp = 0;
72
-
73
- public bitrate = 0;
74
- public rttInMs?: number;
75
- public jitter?: number;
76
- public fractionLoss = 0;
77
- public marker?: string;
78
-
79
- public totalLostPackets = 0;
80
- public totalReceivedPackets = 0;
81
- public totalBytesReceived = 0;
82
- public totalReceivedFrames = 0;
83
- public totalDecodedFrames = 0;
84
- public totalDroppedFrames = 0;
85
-
86
- public deltaLostPackets = 0;
87
- public deltaReceivedPackets = 0;
88
- public deltaBytesReceived = 0;
89
- public deltaReceivedFrames = 0;
90
- public deltaDecodedFrames = 0;
91
- public deltaDroppedFrames = 0;
92
- public highestLayer?: ObservedInboundVideoTrackStats;
93
- public score?: CalculatedScore;
94
-
95
- public ωpendingIssuesForScores: ClientIssue[] = [];
96
-
97
- public constructor(
98
- private readonly _model: ObservedInboundVideoTrackModel,
99
- public readonly peerConnection: ObservedPeerConnection,
100
- ) {
101
- super();
102
- this.setMaxListeners(Infinity);
103
- }
104
-
105
- public get serviceId() {
106
- return this.peerConnection.serviceId;
107
- }
108
-
109
- public get roomId() {
110
- return this.peerConnection.roomId;
111
- }
112
-
113
- public get callId() {
114
- return this.peerConnection.callId;
115
- }
116
-
117
- public get clientId() {
118
- return this.peerConnection.clientId;
119
- }
120
-
121
- public get mediaUnitId() {
122
- return this.peerConnection.mediaUnitId;
123
- }
124
-
125
- public get peerConnectionId() {
126
- return this.peerConnection.peerConnectionId;
127
- }
128
-
129
- public get trackId() {
130
- return this._model.trackId;
131
- }
132
-
133
- public get sfuStreamId() {
134
- return this._model.sfuStreamId;
135
- }
136
-
137
- public get sfuSinkId() {
138
- return this._model.sfuSinkId;
139
- }
140
-
141
- public get updated() {
142
- return this._updated;
143
- }
144
-
145
- public get statsTimestamp() {
146
- return this._lastMaxStatsTimestamp;
147
- }
148
-
149
- public get stats(): ReadonlyMap<number, ObservedInboundVideoTrackStats> {
150
- return this._stats;
151
- }
152
-
153
- public get reports() {
154
- return this.peerConnection.reports;
155
- }
156
-
157
- public set remoteOutboundTrack(track: ObservedOutboundVideoTrack | undefined) {
158
- if (this._closed) return;
159
- if (this._remoteOutboundTrack) return;
160
- if (!track) return;
161
-
162
- track.once('close', () => {
163
- this._remoteOutboundTrack = undefined;
164
- this.emit('remoteoutboundtrack', undefined);
165
- });
166
- this._remoteOutboundTrack = track;
167
- this.emit('remoteoutboundtrack', track);
168
- }
169
-
170
- public get remoteOutboundTrack() {
171
- return this._remoteOutboundTrack;
172
- }
173
-
174
- public get closed() {
175
- return this._closed;
176
- }
177
-
178
- public close() {
179
- if (this._closed) return;
180
-
181
- this._closed = true;
182
-
183
- this.emit('close');
184
- }
185
-
186
- public update(sample: ObservedInboundVideoTrackStatsUpdate, statsTimestamp: number) {
187
- if (this._closed) return;
188
-
189
- const now = Date.now();
190
- const report: InboundAudioTrackReport | InboundVideoTrackReport = {
191
- serviceId: this.peerConnection.client.call.serviceId,
192
- roomId: this.peerConnection.client.call.roomId,
193
- callId: this.peerConnection.client.call.callId,
194
- clientId: this.peerConnection.client.clientId,
195
- userId: this.peerConnection.client.userId,
196
- mediaUnitId: this.peerConnection.client.mediaUnitId,
197
- peerConnectionId: this.peerConnection.peerConnectionId,
198
- ...sample,
199
- timestamp: statsTimestamp,
200
- sampleSeq: -1,
201
-
202
- remoteClientId: sample.remoteClientId ?? this.remoteOutboundTrack?.peerConnection.client.clientId,
203
- remoteUserId: this.remoteOutboundTrack?.peerConnection.client.userId,
204
- remoteTrackId: this.remoteOutboundTrack?.trackId,
205
- remotePeerConnectionId: this.remoteOutboundTrack?.peerConnection.peerConnectionId,
206
- marker: this.marker,
207
- };
208
-
209
- this.reports.addInboundVideoTrackReport(report);
210
-
211
- if (!this._model.sfuStreamId && sample.sfuStreamId) {
212
- this._model.sfuStreamId = sample.sfuStreamId;
213
- }
214
-
215
- if (!this._model.sfuSinkId && sample.sfuSinkId) {
216
- this._model.sfuSinkId = sample.sfuSinkId;
217
- }
218
-
219
- const elapsedTimeInMs = Math.max(1, now - this._updated);
220
- const lastStat = this._stats.get(sample.ssrc);
221
- const rttInMs = sample.roundTripTime ? sample.roundTripTime * 1000 : undefined;
222
- let bitrate = 0;
223
- let deltaReceivedBytes = 0;
224
- let fractionLost = 0;
225
- let deltaLostPackets = 0;
226
- let deltaReceivedPackets = 0;
227
-
228
- if (lastStat?.bytesReceived && sample.bytesReceived && lastStat.bytesReceived < sample.bytesReceived) {
229
- deltaReceivedBytes = sample.bytesReceived - lastStat.bytesReceived;
230
- bitrate = deltaReceivedBytes / (elapsedTimeInMs / 1000);
231
- }
232
- if (lastStat?.packetsReceived && sample?.packetsReceived && lastStat.packetsReceived < sample.packetsReceived) {
233
- deltaReceivedPackets = sample.packetsReceived - lastStat.packetsReceived;
234
- }
235
- if (lastStat?.packetsLost && sample.packetsLost && lastStat.packetsLost < sample.packetsLost) {
236
- deltaLostPackets = sample.packetsLost - lastStat.packetsLost;
237
- if (0 < deltaReceivedPackets) {
238
- fractionLost = deltaLostPackets / (deltaReceivedPackets + deltaLostPackets);
239
- }
240
- }
241
-
242
- let deltaDecodedFrames: number | undefined;
243
- let deltaDroppedFrames: number | undefined;
244
- let deltaReceivedFrames: number | undefined;
245
- const videoSample = sample as InboundVideoTrack;
246
- const lastVideoStat = lastStat as InboundVideoTrack | undefined;
247
-
248
- if (videoSample.framesDecoded && lastVideoStat?.framesDecoded && lastVideoStat.framesDecoded < videoSample.framesDecoded) {
249
- deltaDecodedFrames = videoSample.framesDecoded - lastVideoStat.framesDecoded;
250
- }
251
- if (videoSample.framesDropped && lastVideoStat?.framesDropped && lastVideoStat.framesDropped < videoSample.framesDropped) {
252
- deltaDroppedFrames = videoSample.framesDropped - lastVideoStat.framesDropped;
253
- }
254
- if (videoSample.framesReceived && lastVideoStat?.framesReceived && lastVideoStat.framesReceived < videoSample.framesReceived) {
255
- deltaReceivedFrames = videoSample.framesReceived - lastVideoStat.framesReceived;
256
- }
257
-
258
- const stats: ObservedInboundVideoTrackStats = {
259
- ...sample,
260
- fractionLost,
261
- rttInMs,
262
- bitrate,
263
- ssrc: sample.ssrc,
264
- deltaReceivedBytes,
265
- deltaLostPackets,
266
- deltaReceivedPackets,
267
- deltaReceivedFrames,
268
- deltaDecodedFrames,
269
- deltaDroppedFrames,
270
- statsTimestamp,
271
- };
272
-
273
- this._stats.set(sample.ssrc, stats);
274
-
275
- this.visited = true;
276
- // a peer connection is active if it has at least one active track
277
- this.peerConnection.visited = true;
278
-
279
- this._updated = now;
280
- this.emit('update', {
281
- elapsedTimeInMs,
282
- });
283
- }
284
-
285
- public updateMetrics() {
286
- let maxStatsTimestamp = 0;
287
- let rttInMsSum = 0;
288
- let jitterSum = 0;
289
- let size = 0;
290
-
291
- this.bitrate = 0;
292
- this.rttInMs = undefined;
293
- this.deltaBytesReceived = 0;
294
- this.deltaLostPackets = 0;
295
- this.deltaReceivedFrames = 0;
296
- this.deltaDecodedFrames = 0;
297
- this.deltaDroppedFrames = 0;
298
- this.fractionLoss = 0;
299
-
300
- const highestLayer = { ssrc: -1, bitrate: -1 };
301
-
302
- for (const [ ssrc, stats ] of this._stats) {
303
- if (stats.statsTimestamp <= this._lastMaxStatsTimestamp) continue;
304
-
305
- this.deltaBytesReceived += stats.deltaReceivedBytes ?? 0;
306
- this.deltaLostPackets += stats.deltaLostPackets ?? 0;
307
- this.deltaReceivedPackets += stats.deltaReceivedFrames ?? 0;
308
- this.deltaReceivedFrames += stats.deltaReceivedFrames ?? 0;
309
- this.deltaDecodedFrames += stats.deltaDecodedFrames ?? 0;
310
- this.deltaDroppedFrames += stats.deltaDroppedFrames ?? 0;
311
- this.bitrate += stats.bitrate;
312
-
313
- maxStatsTimestamp = Math.max(maxStatsTimestamp, stats.statsTimestamp);
314
-
315
- if (highestLayer.bitrate < stats.bitrate) {
316
- highestLayer.ssrc = ssrc;
317
- }
318
- rttInMsSum += stats.rttInMs ?? 0;
319
- jitterSum += stats.jitter ?? 0;
320
- ++size;
321
- }
322
- this.highestLayer = this.stats.get(highestLayer.ssrc);
323
- this.totalBytesReceived += this.deltaBytesReceived;
324
- this.totalLostPackets += this.deltaLostPackets;
325
- this.totalReceivedPackets += this.deltaReceivedPackets;
326
- this.totalReceivedFrames += this.deltaReceivedFrames;
327
- this.totalDecodedFrames += this.deltaDecodedFrames;
328
- this.totalDroppedFrames += this.deltaDroppedFrames;
329
-
330
- this.rttInMs = rttInMsSum / Math.max(size, 1);
331
- this.jitter = jitterSum / Math.max(size, 1);
332
- this.fractionLoss = 0 < this.deltaReceivedPackets && 0 < this.deltaLostPackets ? (this.deltaLostPackets / (this.deltaReceivedPackets + this.deltaLostPackets)) : 0;
333
-
334
- this._lastMaxStatsTimestamp = maxStatsTimestamp;
335
- this._updateQualityScore(maxStatsTimestamp);
336
- }
337
-
338
- private _updateQualityScore(timestamp: number) {
339
- const newIssues = this.ωpendingIssuesForScores;
340
- const score = calculateBaseVideoScore(this, newIssues);
341
-
342
- if (0 < this.ωpendingIssuesForScores.length) {
343
- this.ωpendingIssuesForScores = [];
344
- }
345
-
346
- if (!score) return (this.score = undefined);
347
-
348
- if (0.05 < this.fractionLoss) {
349
- score.score *= 0.5;
350
- score.remarks.push({
351
- severity: 'major',
352
- text: 'Fraction loss is too high',
353
- });
354
- }
355
-
356
- score.timestamp = timestamp;
357
- this.score = score;
358
-
359
- this.emit('score', this.score);
360
- }
361
- }
@@ -1,307 +0,0 @@
1
- import { EventEmitter } from 'events';
2
- import { ObservedPeerConnection } from './ObservedPeerConnection';
3
- import { OutboundAudioTrack, OutboundVideoTrack } from '@observertc/sample-schemas-js';
4
- import { OutboundAudioTrackReport, OutboundVideoTrackReport } from '@observertc/report-schemas-js';
5
- import { ObservedInboundAudioTrack } from './ObservedInboundAudioTrack';
6
- import { calculateBaseAudioScore, CalculatedScore } from './common/CalculatedScore';
7
- import { ClientIssue } from './monitors/CallSummary';
8
-
9
- export type ObservedOutboundAudioTrackModel = {
10
- trackId: string;
11
- sfuStreamId?: string;
12
- }
13
-
14
- export type ObservedOutboundAudioTrackEvents = {
15
- qualitylimitationchanged: [string];
16
- update: [{
17
- elapsedTimeInMs: number;
18
- }],
19
- score: [CalculatedScore],
20
- close: [],
21
- };
22
-
23
- export type ObservedOutboundAudioTrackStats = OutboundAudioTrack & {
24
- ssrc: number;
25
- bitrate: number;
26
- rttInMs?: number;
27
-
28
- deltaLostPackets: number;
29
- deltaSentPackets: number;
30
- deltaSentBytes: number;
31
- deltaSentFrames?: number;
32
- deltaEncodedFrames?: number;
33
-
34
- statsTimestamp: number;
35
- };
36
-
37
- // export type ObservedOutboundTrackStatsUpdate = {
38
- // [Property in keyof ObservedOutboundTrackStats<K>]: ObservedOutboundTrackStats<K>[Property];
39
- // }
40
-
41
- export declare interface ObservedOutboundAudioTrack {
42
- on<U extends keyof ObservedOutboundAudioTrackEvents>(event: U, listener: (...args: ObservedOutboundAudioTrackEvents[U]) => void): this;
43
- off<U extends keyof ObservedOutboundAudioTrackEvents>(event: U, listener: (...args: ObservedOutboundAudioTrackEvents[U]) => void): this;
44
- once<U extends keyof ObservedOutboundAudioTrackEvents>(event: U, listener: (...args: ObservedOutboundAudioTrackEvents[U]) => void): this;
45
- emit<U extends keyof ObservedOutboundAudioTrackEvents>(event: U, ...args: ObservedOutboundAudioTrackEvents[U]): boolean;
46
- update(sample: OutboundAudioTrack, timestamp: number): void;
47
- }
48
-
49
- export class ObservedOutboundAudioTrack extends EventEmitter {
50
- public readonly created = Date.now();
51
- public visited = false;
52
-
53
- // timestamp of the MEDIA_TRACK_ADDED event
54
- public added?: number;
55
- // timestamp of the MEDIA_TRACK_REMOVED event
56
- public removed?: number;
57
-
58
- public bitrate = 0;
59
- public rttInMs?: number;
60
- public jitter?: number;
61
- public marker?: string;
62
-
63
- public totalLostPackets = 0;
64
- public totalSentPackets = 0;
65
- public totalSentBytes = 0;
66
- public totalSentFrames = 0;
67
-
68
- public deltaLostPackets = 0;
69
- public deltaSentPackets = 0;
70
- public deltaSentBytes = 0;
71
- public deltaSentFrames = 0;
72
- public deltaEncodedFrames = 0;
73
-
74
- public sendingBitrate = 0;
75
-
76
- private readonly _stats = new Map<number, ObservedOutboundAudioTrackStats>();
77
- private _lastMaxStatsTimestamp = 0;
78
-
79
- private _closed = false;
80
- private _updated = Date.now();
81
- private _lastUpdateMetrics?: number;
82
-
83
- public score?: CalculatedScore;
84
- public ωpendingIssuesForScores: ClientIssue[] = [];
85
-
86
- public readonly remoteInboundTracks = new Map<string, ObservedInboundAudioTrack>();
87
-
88
- public constructor(
89
- private readonly _model: ObservedOutboundAudioTrackModel,
90
- public readonly peerConnection: ObservedPeerConnection,
91
- ) {
92
- super();
93
- this.setMaxListeners(Infinity);
94
- }
95
-
96
- public get serviceId() {
97
- return this.peerConnection.serviceId;
98
- }
99
-
100
- public get roomId() {
101
- return this.peerConnection.roomId;
102
- }
103
-
104
- public get callId() {
105
- return this.peerConnection.callId;
106
- }
107
-
108
- public get clientId() {
109
- return this.peerConnection.clientId;
110
- }
111
-
112
- public get mediaUnitId() {
113
- return this.peerConnection.mediaUnitId;
114
- }
115
-
116
- public get peerConnectionId() {
117
- return this.peerConnection.peerConnectionId;
118
- }
119
-
120
- public get trackId() {
121
- return this._model.trackId;
122
- }
123
-
124
- public get sfuStreamId() {
125
- return this._model.sfuStreamId;
126
- }
127
-
128
- public get reports() {
129
- return this.peerConnection.reports;
130
- }
131
-
132
- public get statsTimestamp() {
133
- return this._lastMaxStatsTimestamp;
134
- }
135
-
136
- public get updated() {
137
- return this._updated;
138
- }
139
-
140
- public get stats(): ReadonlyMap<number, ObservedOutboundAudioTrackStats> {
141
- return this._stats;
142
- }
143
-
144
- public get closed() {
145
- return this._closed;
146
- }
147
-
148
- public close() {
149
- if (this._closed) return;
150
- this._closed = true;
151
-
152
- this.emit('close');
153
- }
154
-
155
- public update(sample: OutboundAudioTrack, statsTimestamp: number): void {
156
- if (this._closed) return;
157
-
158
- const now = Date.now();
159
- const report: OutboundAudioTrackReport | OutboundVideoTrackReport = {
160
- serviceId: this.peerConnection.client.serviceId,
161
- roomId: this.peerConnection.client.call.roomId,
162
- callId: this.peerConnection.client.call.callId,
163
- clientId: this.peerConnection.client.clientId,
164
- userId: this.peerConnection.client.userId,
165
- mediaUnitId: this.peerConnection.client.mediaUnitId,
166
- peerConnectionId: this.peerConnection.peerConnectionId,
167
- ...sample,
168
- timestamp: statsTimestamp,
169
- sampleSeq: -1,
170
- marker: this.marker,
171
- };
172
-
173
- this.reports.addOutboundAudioTrackReport(report);
174
-
175
- const elapsedTimeInMs = Math.max(1, now - this._updated);
176
- const lastStat = this._stats.get(sample.ssrc);
177
- const rttInMs = sample.roundTripTime ? sample.roundTripTime * 1000 : undefined;
178
- let bitrate = 0;
179
- let deltaLostPackets = 0;
180
- let deltaSentPackets = 0;
181
- let deltaSentBytes = 0;
182
-
183
- if (sample.bytesSent && lastStat?.bytesSent && lastStat.bytesSent < sample.bytesSent) {
184
- bitrate = (sample.bytesSent - lastStat.bytesSent) * 8 / (elapsedTimeInMs / 1000);
185
- }
186
- if (sample.packetsLost && lastStat?.packetsLost && lastStat.packetsLost < sample.packetsLost) {
187
- deltaLostPackets = sample.packetsLost - lastStat.packetsLost;
188
- }
189
- if (sample.packetsSent && lastStat?.packetsSent && lastStat.packetsSent < sample.packetsSent) {
190
- deltaSentPackets = sample.packetsSent - lastStat.packetsSent;
191
- }
192
- if (sample.bytesSent && lastStat?.bytesSent && lastStat.bytesSent < sample.bytesSent) {
193
- deltaSentBytes = sample.bytesSent - lastStat.bytesSent;
194
- }
195
-
196
- let deltaEncodedFrames: number | undefined;
197
- let deltaSentFrames: number | undefined;
198
-
199
- const videoSample = sample as OutboundVideoTrack;
200
- const lastVideoStats = lastStat as OutboundVideoTrack | undefined;
201
-
202
- if (videoSample?.framesEncoded && lastVideoStats?.framesEncoded && lastVideoStats.framesEncoded < videoSample.framesEncoded) {
203
- deltaEncodedFrames = videoSample.framesEncoded - lastVideoStats.framesEncoded;
204
- }
205
- if (videoSample?.framesSent && lastVideoStats?.framesSent && lastVideoStats.framesSent < videoSample.framesSent) {
206
- deltaSentFrames = videoSample.framesSent - lastVideoStats.framesSent;
207
- }
208
-
209
- if (videoSample.qualityLimitationReason && lastVideoStats?.qualityLimitationReason !== videoSample.qualityLimitationReason) {
210
- this.emit('qualitylimitationchanged', videoSample.qualityLimitationReason);
211
- }
212
-
213
- const stats: ObservedOutboundAudioTrackStats = {
214
- ...sample,
215
- rttInMs,
216
- bitrate,
217
- ssrc: sample.ssrc,
218
-
219
- deltaLostPackets,
220
- deltaSentPackets,
221
- deltaSentBytes,
222
- deltaEncodedFrames,
223
- deltaSentFrames,
224
-
225
- statsTimestamp,
226
- };
227
-
228
- this._stats.set(sample.ssrc, stats);
229
-
230
- this.visited = true;
231
- // a peer connection is active if it has at least one active track
232
- this.peerConnection.visited = true;
233
-
234
- this._updated = now;
235
- this.emit('update', {
236
- elapsedTimeInMs,
237
- });
238
- }
239
-
240
- public updateMetrics() {
241
- let maxStatsTimestamp = 0;
242
- let rttInMsSum = 0;
243
- let jitterSum = 0;
244
- let size = 0;
245
-
246
- this.bitrate = 0;
247
- this.rttInMs = undefined;
248
-
249
- this.sendingBitrate = 0;
250
- this.deltaLostPackets = 0;
251
- this.deltaSentPackets = 0;
252
- this.deltaSentBytes = 0;
253
- this.deltaSentFrames = 0;
254
- this.deltaEncodedFrames = 0;
255
-
256
- for (const [ , stats ] of this._stats) {
257
- if (stats.statsTimestamp <= this._lastMaxStatsTimestamp) continue;
258
-
259
- this.deltaLostPackets += stats.deltaLostPackets ?? 0;
260
- this.deltaSentPackets += stats.deltaSentPackets ?? 0;
261
- this.deltaSentBytes += stats.deltaSentBytes ?? 0;
262
- this.deltaSentFrames += stats.deltaSentFrames ?? 0;
263
- this.deltaEncodedFrames += stats.deltaEncodedFrames ?? 0;
264
- this.bitrate += stats.bitrate;
265
-
266
- maxStatsTimestamp = Math.max(maxStatsTimestamp, stats.statsTimestamp);
267
-
268
- rttInMsSum += stats.rttInMs ?? 0;
269
- jitterSum += stats.jitter ?? 0;
270
- ++size;
271
- }
272
-
273
- const now = Date.now();
274
-
275
- if (this._lastUpdateMetrics) {
276
- this.sendingBitrate = (this.deltaSentBytes * 8) / ((now - this._lastUpdateMetrics) / 1000);
277
- }
278
- this._lastUpdateMetrics = now;
279
-
280
- this.totalLostPackets += this.deltaLostPackets;
281
- this.totalSentPackets += this.deltaSentPackets;
282
- this.totalSentBytes += this.deltaSentBytes;
283
- this.totalSentFrames += this.deltaSentFrames;
284
-
285
- this.rttInMs = rttInMsSum / Math.max(size, 1);
286
- this.jitter = jitterSum / Math.max(size, 1);
287
-
288
- this._lastMaxStatsTimestamp = maxStatsTimestamp;
289
- this._updateQualityScore(maxStatsTimestamp);
290
- }
291
-
292
- private _updateQualityScore(timestamp: number) {
293
- const newIssues = this.ωpendingIssuesForScores;
294
- const score = calculateBaseAudioScore(this, newIssues);
295
-
296
- if (0 < newIssues.length) {
297
- this.ωpendingIssuesForScores = [];
298
- }
299
-
300
- if (!score) return (this.score = undefined);
301
-
302
- score.timestamp = timestamp;
303
- this.score = score;
304
-
305
- this.emit('score', this.score);
306
- }
307
- }