@observertc/observer-js 0.42.9 → 1.0.0-5f150eb.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 (303) hide show
  1. package/.prettierrc +6 -6
  2. package/README.md +493 -63
  3. package/lib/ObservedCall.d.ts +48 -43
  4. package/lib/ObservedCall.d.ts.map +1 -1
  5. package/lib/ObservedCall.js +164 -107
  6. package/lib/ObservedCallEventMonitor.d.ts +107 -0
  7. package/lib/ObservedCallEventMonitor.d.ts.map +1 -0
  8. package/lib/ObservedCallEventMonitor.js +321 -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 +78 -145
  15. package/lib/ObservedClient.d.ts.map +1 -1
  16. package/lib/ObservedClient.js +661 -746
  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 +34 -0
  42. package/lib/ObservedInboundTrack.d.ts.map +1 -0
  43. package/lib/ObservedInboundTrack.js +92 -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 +34 -0
  54. package/lib/ObservedOutboundTrack.d.ts.map +1 -0
  55. package/lib/ObservedOutboundTrack.js +65 -0
  56. package/lib/ObservedPeerConnection.d.ts +154 -80
  57. package/lib/ObservedPeerConnection.d.ts.map +1 -1
  58. package/lib/ObservedPeerConnection.js +724 -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 +46 -54
  75. package/lib/Observer.d.ts.map +1 -1
  76. package/lib/Observer.js +131 -226
  77. package/lib/ObserverEventMonitor.d.ts +141 -0
  78. package/lib/ObserverEventMonitor.d.ts.map +1 -0
  79. package/lib/ObserverEventMonitor.js +440 -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/Reports.d.ts +85 -0
  84. package/lib/Reports.d.ts.map +1 -0
  85. package/lib/Reports.js +2 -0
  86. package/lib/common/Middleware.d.ts +10 -1
  87. package/lib/common/Middleware.d.ts.map +1 -1
  88. package/lib/common/Middleware.js +55 -36
  89. package/lib/common/logger.d.ts +8 -4
  90. package/lib/common/logger.d.ts.map +1 -1
  91. package/lib/common/logger.js +44 -68
  92. package/lib/common/types.d.ts +0 -21
  93. package/lib/common/types.d.ts.map +1 -1
  94. package/lib/common/types.js +1 -0
  95. package/lib/common/utils.d.ts +3 -1
  96. package/lib/common/utils.d.ts.map +1 -1
  97. package/lib/common/utils.js +23 -3
  98. package/lib/detectors/Detector.d.ts +5 -0
  99. package/lib/detectors/Detector.d.ts.map +1 -0
  100. package/lib/detectors/Detector.js +3 -0
  101. package/lib/detectors/Detectors.d.ts +11 -0
  102. package/lib/detectors/Detectors.d.ts.map +1 -0
  103. package/lib/detectors/Detectors.js +34 -0
  104. package/lib/index.d.ts +27 -25
  105. package/lib/index.d.ts.map +1 -1
  106. package/lib/index.js +45 -41
  107. package/lib/mediasoup/ObservedMediaRouter.d.ts +10 -0
  108. package/lib/mediasoup/ObservedMediaRouter.d.ts.map +1 -0
  109. package/lib/mediasoup/ObservedMediaRouter.js +6 -0
  110. package/lib/monitors/TurnUsageMonitor.d.ts +0 -52
  111. package/lib/monitors/TurnUsageMonitor.d.ts.map +1 -1
  112. package/lib/monitors/TurnUsageMonitor.js +145 -120
  113. package/lib/schema/ClientEventTypes.d.ts +228 -0
  114. package/lib/schema/ClientEventTypes.d.ts.map +1 -0
  115. package/lib/schema/ClientEventTypes.js +41 -0
  116. package/lib/schema/ClientMetaTypes.d.ts +34 -0
  117. package/lib/schema/ClientMetaTypes.d.ts.map +1 -0
  118. package/lib/schema/ClientMetaTypes.js +16 -0
  119. package/lib/schema/ClientSample.d.ts +1333 -0
  120. package/lib/schema/ClientSample.d.ts.map +1 -0
  121. package/lib/schema/ClientSample.js +4 -0
  122. package/lib/scores/CalculatedScore.d.ts +6 -0
  123. package/lib/scores/CalculatedScore.d.ts.map +1 -0
  124. package/lib/scores/CalculatedScore.js +2 -0
  125. package/lib/scores/DefaultCallScoreCalculator.d.ts +7 -0
  126. package/lib/scores/DefaultCallScoreCalculator.d.ts.map +1 -0
  127. package/lib/scores/DefaultCallScoreCalculator.js +21 -0
  128. package/lib/scores/ScoreCalculator.d.ts +4 -0
  129. package/lib/scores/ScoreCalculator.d.ts.map +1 -0
  130. package/lib/scores/ScoreCalculator.js +2 -0
  131. package/lib/updaters/CallUpdater.d.ts +5 -0
  132. package/lib/updaters/CallUpdater.d.ts.map +1 -0
  133. package/lib/updaters/CallUpdater.js +2 -0
  134. package/lib/updaters/ObserverUpdater.d.ts +5 -0
  135. package/lib/updaters/ObserverUpdater.d.ts.map +1 -0
  136. package/lib/updaters/ObserverUpdater.js +2 -0
  137. package/lib/updaters/OnAllCallObserverUpdater.d.ts +15 -0
  138. package/lib/updaters/OnAllCallObserverUpdater.d.ts.map +1 -0
  139. package/lib/updaters/OnAllCallObserverUpdater.js +50 -0
  140. package/lib/updaters/OnAllClientCallUpdater.d.ts +15 -0
  141. package/lib/updaters/OnAllClientCallUpdater.d.ts.map +1 -0
  142. package/lib/updaters/OnAllClientCallUpdater.js +53 -0
  143. package/lib/updaters/OnAnyCallObserverUpdater.d.ts +12 -0
  144. package/lib/updaters/OnAnyCallObserverUpdater.d.ts.map +1 -0
  145. package/lib/updaters/OnAnyCallObserverUpdater.js +37 -0
  146. package/lib/updaters/OnAnyClientCallUpdater.d.ts +12 -0
  147. package/lib/updaters/OnAnyClientCallUpdater.d.ts.map +1 -0
  148. package/lib/updaters/OnAnyClientCallUpdater.js +36 -0
  149. package/lib/updaters/OnIntervalUpdater.d.ts +10 -0
  150. package/lib/updaters/OnIntervalUpdater.d.ts.map +1 -0
  151. package/lib/updaters/OnIntervalUpdater.js +17 -0
  152. package/lib/updaters/Updater.d.ts +6 -0
  153. package/lib/updaters/Updater.d.ts.map +1 -0
  154. package/lib/updaters/Updater.js +2 -0
  155. package/lib/utils/MediasoupRemoteTrackResolver.d.ts +25 -0
  156. package/lib/utils/MediasoupRemoteTrackResolver.d.ts.map +1 -0
  157. package/lib/utils/MediasoupRemoteTrackResolver.js +110 -0
  158. package/lib/utils/RemoteTrackResolver.d.ts +7 -0
  159. package/lib/utils/RemoteTrackResolver.d.ts.map +1 -0
  160. package/lib/utils/RemoteTrackResolver.js +2 -0
  161. package/package.json +4 -4
  162. package/src/ObservedCall.ts +243 -161
  163. package/src/ObservedCallEventMonitor.ts +402 -0
  164. package/src/ObservedCallSummary.ts +22 -0
  165. package/src/ObservedCertificate.ts +43 -0
  166. package/src/ObservedClient.ts +715 -1003
  167. package/src/ObservedClientEventMonitor.ts +309 -0
  168. package/src/ObservedClientSummary.ts +24 -0
  169. package/src/ObservedCodec.ts +49 -0
  170. package/src/ObservedDataChannel.ts +71 -181
  171. package/src/ObservedIceCandidate.ts +64 -0
  172. package/src/ObservedIceCandidatePair.ts +134 -0
  173. package/src/ObservedIceTransport.ts +99 -0
  174. package/src/ObservedInboundRtp.ts +205 -0
  175. package/src/ObservedInboundTrack.ts +105 -0
  176. package/src/ObservedMediaPlayout.ts +49 -0
  177. package/src/ObservedMediaSource.ts +60 -0
  178. package/src/ObservedOutboundRtp.ts +156 -0
  179. package/src/ObservedOutboundTrack.ts +82 -0
  180. package/src/ObservedPeerConnection.ts +933 -402
  181. package/src/ObservedPeerConnectionTransport.ts +38 -0
  182. package/src/ObservedRemoteInboundRtp.ts +64 -0
  183. package/src/ObservedRemoteOutboundRtp.ts +65 -0
  184. package/src/ObservedTURN.ts +86 -0
  185. package/src/ObservedTurnServer.ts +72 -0
  186. package/src/Observer.ts +183 -298
  187. package/src/ObserverEventMonitor.ts +561 -0
  188. package/src/ObserverSummary.ts +15 -0
  189. package/src/Reports.ts +87 -0
  190. package/src/common/Middleware.ts +70 -42
  191. package/src/common/logger.ts +60 -69
  192. package/src/common/types.ts +0 -42
  193. package/src/common/utils.ts +24 -2
  194. package/src/detectors/Detector.ts +6 -0
  195. package/src/detectors/Detectors.ts +38 -0
  196. package/src/index.ts +30 -91
  197. package/src/mediasoup/ObservedMediaRouter.ts +10 -0
  198. package/src/monitors/TurnUsageMonitor.ts +164 -164
  199. package/src/schema/ClientEventTypes.ts +280 -0
  200. package/src/schema/ClientMetaTypes.ts +41 -0
  201. package/src/schema/ClientSample.ts +1682 -0
  202. package/src/scores/CalculatedScore.ts +6 -0
  203. package/src/scores/DefaultCallScoreCalculator.ts +23 -0
  204. package/src/scores/ScoreCalculator.ts +3 -0
  205. package/src/updaters/CallUpdater.ts +5 -0
  206. package/src/updaters/ObserverUpdater.ts +5 -0
  207. package/src/updaters/OnAllCallObserverUpdater.ts +59 -0
  208. package/src/updaters/OnAllClientCallUpdater.ts +61 -0
  209. package/src/updaters/OnAnyCallObserverUpdater.ts +41 -0
  210. package/src/updaters/OnAnyClientCallUpdater.ts +39 -0
  211. package/src/updaters/OnIntervalUpdater.ts +19 -0
  212. package/src/updaters/Updater.ts +5 -0
  213. package/src/utils/MediasoupRemoteTrackResolver.ts +155 -0
  214. package/src/utils/RemoteTrackResolver.ts +12 -0
  215. package/tsconfig.json +3 -3
  216. package/lib/ObservedICE.d.ts +0 -64
  217. package/lib/ObservedICE.d.ts.map +0 -1
  218. package/lib/ObservedICE.js +0 -141
  219. package/lib/ObservedInboundAudioTrack.d.ts +0 -96
  220. package/lib/ObservedInboundAudioTrack.d.ts.map +0 -1
  221. package/lib/ObservedInboundAudioTrack.js +0 -217
  222. package/lib/ObservedInboundVideoTrack.d.ts +0 -101
  223. package/lib/ObservedInboundVideoTrack.d.ts.map +0 -1
  224. package/lib/ObservedInboundVideoTrack.js +0 -232
  225. package/lib/ObservedOutboundAudioTrack.d.ts +0 -87
  226. package/lib/ObservedOutboundAudioTrack.d.ts.map +0 -1
  227. package/lib/ObservedOutboundAudioTrack.js +0 -186
  228. package/lib/ObservedOutboundVideoTrack.d.ts +0 -91
  229. package/lib/ObservedOutboundVideoTrack.d.ts.map +0 -1
  230. package/lib/ObservedOutboundVideoTrack.js +0 -193
  231. package/lib/ObservedSfu.d.ts +0 -59
  232. package/lib/ObservedSfu.d.ts.map +0 -1
  233. package/lib/ObservedSfu.js +0 -157
  234. package/lib/ObservedSfuInboundRtpPad.d.ts +0 -42
  235. package/lib/ObservedSfuInboundRtpPad.d.ts.map +0 -1
  236. package/lib/ObservedSfuInboundRtpPad.js +0 -71
  237. package/lib/ObservedSfuOutboundRtpPad.d.ts +0 -42
  238. package/lib/ObservedSfuOutboundRtpPad.d.ts.map +0 -1
  239. package/lib/ObservedSfuOutboundRtpPad.js +0 -72
  240. package/lib/ObservedSfuSctpChannel.d.ts +0 -42
  241. package/lib/ObservedSfuSctpChannel.d.ts.map +0 -1
  242. package/lib/ObservedSfuSctpChannel.js +0 -57
  243. package/lib/ObservedSfuTransport.d.ts +0 -58
  244. package/lib/ObservedSfuTransport.d.ts.map +0 -1
  245. package/lib/ObservedSfuTransport.js +0 -120
  246. package/lib/RemoteTrackAssigner.d.ts +0 -14
  247. package/lib/RemoteTrackAssigner.d.ts.map +0 -1
  248. package/lib/RemoteTrackAssigner.js +0 -52
  249. package/lib/ReportsCollector.d.ts +0 -109
  250. package/lib/ReportsCollector.d.ts.map +0 -1
  251. package/lib/ReportsCollector.js +0 -207
  252. package/lib/common/CalculatedScore.d.ts +0 -80
  253. package/lib/common/CalculatedScore.d.ts.map +0 -1
  254. package/lib/common/CalculatedScore.js +0 -162
  255. package/lib/common/CallEventType.d.ts +0 -63
  256. package/lib/common/CallEventType.d.ts.map +0 -1
  257. package/lib/common/CallEventType.js +0 -39
  258. package/lib/common/CallMetaReports.d.ts +0 -42
  259. package/lib/common/CallMetaReports.d.ts.map +0 -1
  260. package/lib/common/CallMetaReports.js +0 -36
  261. package/lib/common/QualityScoreUtils.d.ts +0 -1
  262. package/lib/common/QualityScoreUtils.d.ts.map +0 -1
  263. package/lib/common/QualityScoreUtils.js +0 -1
  264. package/lib/common/TypedEventEmitter.d.ts +0 -22
  265. package/lib/common/TypedEventEmitter.d.ts.map +0 -1
  266. package/lib/common/TypedEventEmitter.js +0 -11
  267. package/lib/common/callEventReports.d.ts +0 -10
  268. package/lib/common/callEventReports.d.ts.map +0 -1
  269. package/lib/common/callEventReports.js +0 -112
  270. package/lib/monitors/CallSummary.d.ts +0 -37
  271. package/lib/monitors/CallSummary.d.ts.map +0 -1
  272. package/lib/monitors/CallSummaryMonitor.d.ts +0 -32
  273. package/lib/monitors/CallSummaryMonitor.d.ts.map +0 -1
  274. package/lib/monitors/CallSummaryMonitor.js +0 -152
  275. package/lib/monitors/ClientIssueMonitor.d.ts +0 -32
  276. package/lib/monitors/ClientIssueMonitor.d.ts.map +0 -1
  277. package/lib/monitors/ClientIssueMonitor.js +0 -49
  278. package/lib/monitors/SfuServerMonitor.d.ts +0 -79
  279. package/lib/monitors/SfuServerMonitor.d.ts.map +0 -1
  280. package/lib/monitors/SfuServerMonitor.js +0 -198
  281. package/src/ObservedICE.ts +0 -237
  282. package/src/ObservedInboundAudioTrack.ts +0 -344
  283. package/src/ObservedInboundVideoTrack.ts +0 -361
  284. package/src/ObservedOutboundAudioTrack.ts +0 -307
  285. package/src/ObservedOutboundVideoTrack.ts +0 -319
  286. package/src/ObservedSfu.ts +0 -231
  287. package/src/ObservedSfuInboundRtpPad.ts +0 -106
  288. package/src/ObservedSfuOutboundRtpPad.ts +0 -107
  289. package/src/ObservedSfuSctpChannel.ts +0 -103
  290. package/src/ObservedSfuTransport.ts +0 -185
  291. package/src/RemoteTrackAssigner.ts +0 -68
  292. package/src/ReportsCollector.ts +0 -336
  293. package/src/common/CalculatedScore.ts +0 -188
  294. package/src/common/CallEventType.ts +0 -69
  295. package/src/common/CallMetaReports.ts +0 -82
  296. package/src/common/QualityScoreUtils.ts +0 -0
  297. package/src/common/TypedEventEmitter.ts +0 -32
  298. package/src/common/callEventReports.ts +0 -178
  299. package/src/monitors/CallSummary.ts +0 -38
  300. package/src/monitors/CallSummaryMonitor.ts +0 -192
  301. package/src/monitors/ClientIssueMonitor.ts +0 -88
  302. package/src/monitors/SfuServerMonitor.ts +0 -285
  303. /package/lib/{monitors/CallSummary.js → ObservedCallSummary.js} +0 -0
@@ -1,319 +0,0 @@
1
- import { EventEmitter } from 'events';
2
- import { ObservedPeerConnection } from './ObservedPeerConnection';
3
- import { OutboundVideoTrack } from '@observertc/sample-schemas-js';
4
- import { OutboundAudioTrackReport, OutboundVideoTrackReport } from '@observertc/report-schemas-js';
5
- import { ObservedInboundVideoTrack } from './ObservedInboundVideoTrack';
6
- import { calculateBaseVideoScore, CalculatedScore } from './common/CalculatedScore';
7
- import { ClientIssue } from './monitors/CallSummary';
8
- import { SupportedVideoCodecType } from './common/types';
9
-
10
- export type ObservedOutboundVideoTrackModel = {
11
- trackId: string;
12
- sfuStreamId?: string;
13
- }
14
-
15
- export type ObservedOutboundVideoTrackEvents = {
16
- qualitylimitationchanged: [string];
17
- update: [{
18
- elapsedTimeInMs: number;
19
- }],
20
- score: [CalculatedScore],
21
- close: [],
22
- };
23
-
24
- export type ObservedOutboundVideoTrackStats = OutboundVideoTrack & {
25
- ssrc: number;
26
- bitrate: number;
27
- rttInMs?: number;
28
-
29
- deltaLostPackets: number;
30
- deltaSentPackets: number;
31
- deltaSentBytes: number;
32
- deltaSentFrames?: number;
33
- deltaEncodedFrames?: number;
34
-
35
- statsTimestamp: number;
36
- };
37
-
38
- // export type ObservedOutboundTrackStatsUpdate = {
39
- // [Property in keyof ObservedOutboundTrackStats<K>]: ObservedOutboundTrackStats<K>[Property];
40
- // }
41
-
42
- export declare interface ObservedOutboundVideoTrack {
43
- on<U extends keyof ObservedOutboundVideoTrackEvents>(event: U, listener: (...args: ObservedOutboundVideoTrackEvents[U]) => void): this;
44
- off<U extends keyof ObservedOutboundVideoTrackEvents>(event: U, listener: (...args: ObservedOutboundVideoTrackEvents[U]) => void): this;
45
- once<U extends keyof ObservedOutboundVideoTrackEvents>(event: U, listener: (...args: ObservedOutboundVideoTrackEvents[U]) => void): this;
46
- emit<U extends keyof ObservedOutboundVideoTrackEvents>(event: U, ...args: ObservedOutboundVideoTrackEvents[U]): boolean;
47
- update(sample: OutboundVideoTrack, timestamp: number): void;
48
- }
49
-
50
- export class ObservedOutboundVideoTrack extends EventEmitter {
51
- public readonly created = Date.now();
52
- public visited = false;
53
-
54
- // timestamp of the MEDIA_TRACK_ADDED event
55
- public added?: number;
56
- // timestamp of the MEDIA_TRACK_REMOVED event
57
- public removed?: number;
58
-
59
- public contentType: 'lowmotion' | 'standard' | 'highmotion' = 'standard';
60
- public codec?: SupportedVideoCodecType;
61
- public highestLayer?: ObservedOutboundVideoTrackStats;
62
-
63
- public bitrate = 0;
64
- public jitter?: number;
65
- public rttInMs?: number;
66
- public marker?: string;
67
-
68
- public totalLostPackets = 0;
69
- public totalSentPackets = 0;
70
- public totalSentBytes = 0;
71
- public totalSentFrames = 0;
72
-
73
- public deltaLostPackets = 0;
74
- public deltaSentPackets = 0;
75
- public deltaSentBytes = 0;
76
- public deltaSentFrames = 0;
77
- public deltaEncodedFrames = 0;
78
-
79
- public sendingBitrate = 0;
80
-
81
- private readonly _stats = new Map<number, ObservedOutboundVideoTrackStats>();
82
- private _lastMaxStatsTimestamp = 0;
83
-
84
- private _closed = false;
85
- private _updated = Date.now();
86
- public readonly remoteInboundTracks = new Map<string, ObservedInboundVideoTrack>();
87
-
88
- public score?: CalculatedScore;
89
- public ωpendingIssuesForScores: ClientIssue[] = [];
90
-
91
- public constructor(
92
- private readonly _model: ObservedOutboundVideoTrackModel,
93
- public readonly peerConnection: ObservedPeerConnection,
94
- ) {
95
- super();
96
- this.setMaxListeners(Infinity);
97
- }
98
-
99
- public get serviceId() {
100
- return this.peerConnection.serviceId;
101
- }
102
-
103
- public get roomId() {
104
- return this.peerConnection.roomId;
105
- }
106
-
107
- public get callId() {
108
- return this.peerConnection.callId;
109
- }
110
-
111
- public get clientId() {
112
- return this.peerConnection.clientId;
113
- }
114
-
115
- public get mediaUnitId() {
116
- return this.peerConnection.mediaUnitId;
117
- }
118
-
119
- public get peerConnectionId() {
120
- return this.peerConnection.peerConnectionId;
121
- }
122
-
123
- public get trackId() {
124
- return this._model.trackId;
125
- }
126
-
127
- public get sfuStreamId() {
128
- return this._model.sfuStreamId;
129
- }
130
-
131
- public get reports() {
132
- return this.peerConnection.reports;
133
- }
134
-
135
- public get updated() {
136
- return this._updated;
137
- }
138
-
139
- public get statsTimestamp() {
140
- return this._lastMaxStatsTimestamp;
141
- }
142
-
143
- public get stats(): ReadonlyMap<number, ObservedOutboundVideoTrackStats> {
144
- return this._stats;
145
- }
146
-
147
- public get closed() {
148
- return this._closed;
149
- }
150
-
151
- public close() {
152
- if (this._closed) return;
153
- this._closed = true;
154
-
155
- this.emit('close');
156
- }
157
-
158
- public update(sample: OutboundVideoTrack, statsTimestamp: number): void {
159
- if (this._closed) return;
160
-
161
- const now = Date.now();
162
- const report: OutboundAudioTrackReport | OutboundVideoTrackReport = {
163
- serviceId: this.peerConnection.client.serviceId,
164
- roomId: this.peerConnection.client.call.roomId,
165
- callId: this.peerConnection.client.call.callId,
166
- clientId: this.peerConnection.client.clientId,
167
- userId: this.peerConnection.client.userId,
168
- mediaUnitId: this.peerConnection.client.mediaUnitId,
169
- peerConnectionId: this.peerConnection.peerConnectionId,
170
- ...sample,
171
- timestamp: statsTimestamp,
172
- sampleSeq: -1,
173
- marker: this.marker,
174
- };
175
-
176
- this.reports.addOutboundVideoTrackReport(report);
177
-
178
- const elapsedTimeInMs = Math.max(1, now - this._updated);
179
- const lastStat = this._stats.get(sample.ssrc);
180
- const rttInMs = sample.roundTripTime ? sample.roundTripTime * 1000 : undefined;
181
- let bitrate = 0;
182
- let deltaLostPackets = 0;
183
- let deltaSentPackets = 0;
184
- let deltaSentBytes = 0;
185
-
186
- if (sample.bytesSent && lastStat?.bytesSent && lastStat.bytesSent < sample.bytesSent) {
187
- bitrate = (sample.bytesSent - lastStat.bytesSent) * 8 / (elapsedTimeInMs / 1000);
188
- }
189
- if (sample.packetsLost && lastStat?.packetsLost && lastStat.packetsLost < sample.packetsLost) {
190
- deltaLostPackets = sample.packetsLost - lastStat.packetsLost;
191
- }
192
- if (sample.packetsSent && lastStat?.packetsSent && lastStat.packetsSent < sample.packetsSent) {
193
- deltaSentPackets = sample.packetsSent - lastStat.packetsSent;
194
- }
195
- if (sample.bytesSent && lastStat?.bytesSent && lastStat.bytesSent < sample.bytesSent) {
196
- deltaSentBytes = sample.bytesSent - lastStat.bytesSent;
197
- }
198
-
199
- let deltaEncodedFrames: number | undefined;
200
- let deltaSentFrames: number | undefined;
201
-
202
- const videoSample = sample as OutboundVideoTrack;
203
- const lastVideoStats = lastStat as OutboundVideoTrack | undefined;
204
-
205
- if (videoSample?.framesEncoded && lastVideoStats?.framesEncoded && lastVideoStats.framesEncoded < videoSample.framesEncoded) {
206
- deltaEncodedFrames = videoSample.framesEncoded - lastVideoStats.framesEncoded;
207
- }
208
- if (videoSample?.framesSent && lastVideoStats?.framesSent && lastVideoStats.framesSent < videoSample.framesSent) {
209
- deltaSentFrames = videoSample.framesSent - lastVideoStats.framesSent;
210
- }
211
-
212
- if (videoSample.qualityLimitationReason && lastVideoStats?.qualityLimitationReason !== videoSample.qualityLimitationReason) {
213
- this.emit('qualitylimitationchanged', videoSample.qualityLimitationReason);
214
- }
215
-
216
- const stats: ObservedOutboundVideoTrackStats = {
217
- ...sample,
218
- rttInMs,
219
- bitrate,
220
- ssrc: sample.ssrc,
221
-
222
- deltaLostPackets,
223
- deltaSentPackets,
224
- deltaSentBytes,
225
- deltaEncodedFrames,
226
- deltaSentFrames,
227
-
228
- statsTimestamp,
229
- };
230
-
231
- this._stats.set(sample.ssrc, stats);
232
-
233
- this.visited = true;
234
- // a peer connection is active if it has at least one active track
235
- this.peerConnection.visited = true;
236
-
237
- this._updated = now;
238
- this.emit('update', {
239
- elapsedTimeInMs,
240
- });
241
- }
242
-
243
- private _lastUpdateMetrics?: number;
244
-
245
- public updateMetrics() {
246
- let maxStatsTimestamp = 0;
247
- let rttInMsSum = 0;
248
- let jitterSum = 0;
249
- let size = 0;
250
-
251
- this.bitrate = 0;
252
- this.rttInMs = undefined;
253
-
254
- this.sendingBitrate = 0;
255
- this.deltaLostPackets = 0;
256
- this.deltaSentPackets = 0;
257
- this.deltaSentBytes = 0;
258
- this.deltaSentFrames = 0;
259
- this.deltaEncodedFrames = 0;
260
-
261
- const highestLayer = { ssrc: 0, bitrate: -1 };
262
-
263
- for (const [ ssrc, stats ] of this._stats) {
264
- if (stats.statsTimestamp <= this._lastMaxStatsTimestamp) continue;
265
-
266
- this.deltaLostPackets += stats.deltaLostPackets ?? 0;
267
- this.deltaSentPackets += stats.deltaSentPackets ?? 0;
268
- this.deltaSentBytes += stats.deltaSentBytes ?? 0;
269
- this.deltaSentFrames += stats.deltaSentFrames ?? 0;
270
- this.deltaEncodedFrames += stats.deltaEncodedFrames ?? 0;
271
- this.bitrate += stats.bitrate;
272
-
273
- maxStatsTimestamp = Math.max(maxStatsTimestamp, stats.statsTimestamp);
274
-
275
- rttInMsSum += stats.rttInMs ?? 0;
276
- jitterSum += stats.jitter ?? 0;
277
- ++size;
278
-
279
- if (stats.bitrate > highestLayer.bitrate) {
280
- highestLayer.ssrc = ssrc;
281
- highestLayer.bitrate = stats.bitrate;
282
- }
283
- }
284
-
285
- const now = Date.now();
286
-
287
- if (this._lastUpdateMetrics) {
288
- this.sendingBitrate = (this.deltaSentBytes * 8) / ((now - this._lastUpdateMetrics) / 1000);
289
- }
290
- this._lastUpdateMetrics = now;
291
- this.highestLayer = this._stats.get(highestLayer.ssrc);
292
- this.totalLostPackets += this.deltaLostPackets;
293
- this.totalSentPackets += this.deltaSentPackets;
294
- this.totalSentBytes += this.deltaSentBytes;
295
- this.totalSentFrames += this.deltaSentFrames;
296
-
297
- this.rttInMs = rttInMsSum / Math.max(size, 1);
298
- this.jitter = jitterSum / Math.max(size, 1);
299
-
300
- this._lastMaxStatsTimestamp = maxStatsTimestamp;
301
- this._updateQualityScore(maxStatsTimestamp);
302
- }
303
-
304
- private _updateQualityScore(timestamp: number) {
305
- const newIssues = this.ωpendingIssuesForScores;
306
- const score = calculateBaseVideoScore(this, newIssues);
307
-
308
- if (0 < newIssues.length) {
309
- this.ωpendingIssuesForScores = [];
310
- }
311
-
312
- if (!score) return (this.score = undefined);
313
-
314
- score.timestamp = timestamp;
315
- this.score = score;
316
-
317
- this.emit('score', this.score);
318
- }
319
- }
@@ -1,231 +0,0 @@
1
- import { EventEmitter } from 'events';
2
- import { Observer } from './Observer';
3
- import { SfuSample } from '@observertc/sample-schemas-js';
4
- import { ObservedSfuTransport, ObservedSfuTransportModel } from './ObservedSfuTransport';
5
- import { SfuEventReport, SfuExtensionReport } from '@observertc/report-schemas-js';
6
- import { PartialBy } from './common/utils';
7
-
8
- export type ObservedSfuModel= {
9
- serviceId: string;
10
- mediaUnitId: string;
11
- sfuId: string;
12
- joined?: number;
13
- };
14
-
15
- export type ObservedSfuEvents = {
16
- update: [{
17
- elapsedTimeInMs: number;
18
- }],
19
- close: [],
20
- newtransport: [ObservedSfuTransport],
21
- };
22
-
23
- export declare interface ObservedSfu<AppData extends Record<string, unknown> = Record<string, unknown>> {
24
- on<U extends keyof ObservedSfuEvents>(event: U, listener: (...args: ObservedSfuEvents[U]) => void): this;
25
- off<U extends keyof ObservedSfuEvents>(event: U, listener: (...args: ObservedSfuEvents[U]) => void): this;
26
- once<U extends keyof ObservedSfuEvents>(event: U, listener: (...args: ObservedSfuEvents[U]) => void): this;
27
- emit<U extends keyof ObservedSfuEvents>(event: U, ...args: ObservedSfuEvents[U]): boolean;
28
-
29
- readonly appData: AppData;
30
- update(sample: SfuSample): void;
31
- }
32
-
33
- export class ObservedSfu<AppData extends Record<string, unknown> = Record<string, unknown>> extends EventEmitter {
34
- public readonly created = Date.now();
35
-
36
- private _updated = Date.now();
37
- private _closed = false;
38
- private _marker?: string;
39
- private _timeZoneOffsetInHours?: number;
40
- private _left?: number;
41
-
42
- private readonly _transports = new Map<string, ObservedSfuTransport>();
43
-
44
- public constructor(
45
- private readonly _model: ObservedSfuModel,
46
- public readonly observer: Observer,
47
- public readonly appData: AppData,
48
- ) {
49
- super();
50
- this.setMaxListeners(Infinity);
51
- }
52
-
53
- public get marker() {
54
- return this._marker;
55
- }
56
-
57
- public get reports() {
58
- return this.observer.reports;
59
- }
60
-
61
- public get serviceId() {
62
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
63
- return this._model.serviceId!;
64
- }
65
-
66
- public get mediaUnitId() {
67
- return this._model.mediaUnitId;
68
- }
69
-
70
- public get sfuId() {
71
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
72
- return this._model.sfuId!;
73
- }
74
-
75
- public get joined() {
76
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
77
- return Number(this._model.joined!);
78
- }
79
-
80
- public get transports(): ReadonlyMap<string, ObservedSfuTransport> {
81
- return this._transports;
82
- }
83
-
84
- public get updated() {
85
- return this._updated;
86
- }
87
-
88
- public get closed() {
89
- return this._closed;
90
- }
91
-
92
- public close() {
93
- if (this._closed) return;
94
- this._closed = true;
95
-
96
- [ ...this._transports.values() ].forEach((transport) => transport.close());
97
-
98
- this.emit('close');
99
- }
100
-
101
- public addEventReport(params: PartialBy<Omit<SfuEventReport, 'serviceId' | 'sfuId' | 'marker' | 'attachments'>, 'timestamp'> & { attachments?: Record<string, unknown> }) {
102
- const {
103
- attachments,
104
- ...fields
105
- } = params;
106
-
107
- this.reports.addCallEventReport({
108
- ...fields,
109
- serviceId: this.serviceId,
110
- mediaUnitId: this.mediaUnitId,
111
- marker: this.marker,
112
- timestamp: params.timestamp ?? Date.now(),
113
- attachments: attachments ? JSON.stringify(attachments) : undefined,
114
- });
115
- }
116
-
117
- public addExtensionStatsReport(extensionType: string, payload?: Record<string, unknown>) {
118
- this.reports.addSfuExtensionReport({
119
- serviceId: this.serviceId,
120
- mediaUnitId: this.mediaUnitId,
121
- timestamp: Date.now(),
122
- extensionType,
123
- payload: payload ? JSON.stringify(payload) : undefined,
124
- marker: this.marker,
125
- sfuId: this.sfuId,
126
- });
127
- }
128
-
129
- public update(sample: SfuSample) {
130
- if (this._closed) throw new Error(`Sfu ${this.sfuId} is closed`);
131
- if (sample.sfuId !== this.sfuId) throw new Error(`Sfu ${this.sfuId} is not the same as sample.sfuId`);
132
-
133
- if (!this._timeZoneOffsetInHours && sample.timeZoneOffsetInHours) {
134
- this._timeZoneOffsetInHours = sample.timeZoneOffsetInHours;
135
- }
136
-
137
- this._marker = sample.marker;
138
-
139
- const now = Date.now();
140
- const elapsedTimeInMs = now - this._updated;
141
-
142
- for (const customSfuEvents of sample.customSfuEvents ?? []) {
143
- const report: SfuEventReport = {
144
- serviceId: this.serviceId,
145
- mediaUnitId: this.mediaUnitId,
146
- sfuId: this.sfuId,
147
- ...customSfuEvents,
148
- timestamp: sample.timestamp,
149
- marker: this._marker,
150
- };
151
-
152
- this.reports.addSfuEventReport(report);
153
- }
154
-
155
- for (const extensionStats of sample.extensionStats ?? []) {
156
-
157
- const report: SfuExtensionReport = {
158
- serviceId: this.serviceId,
159
- mediaUnitId: this.mediaUnitId,
160
- sfuId: this.sfuId,
161
- extensionType: extensionStats.type,
162
- payload: extensionStats.payload,
163
- timestamp: sample.timestamp,
164
- };
165
-
166
- this.reports.addSfuExtensionReport(report);
167
- }
168
-
169
- for (const transport of sample.transports ?? []) {
170
- const observedSfuTransport = this._transports.get(transport.transportId) ?? this._createTransport({
171
- sfuTransportId: transport.transportId,
172
- });
173
-
174
- observedSfuTransport.update(transport, sample.timestamp);
175
- }
176
-
177
- for (const inboundRtpPad of sample.inboundRtpPads ?? []) {
178
- const transport = this._transports.get(inboundRtpPad.transportId) ?? this._createTransport({
179
- sfuTransportId: inboundRtpPad.transportId,
180
- });
181
-
182
- const observedSfuInboundRtpPad = transport.inboundRtpPads.get(inboundRtpPad.padId) ?? transport.createSfuInboundRtpPad({
183
- sfuInboundRtpPadId: inboundRtpPad.padId,
184
- });
185
-
186
- observedSfuInboundRtpPad.update(inboundRtpPad, sample.timestamp);
187
- }
188
-
189
- for (const outboundRtpPad of sample.outboundRtpPads ?? []) {
190
- const transport = this._transports.get(outboundRtpPad.transportId) ?? this._createTransport({
191
- sfuTransportId: outboundRtpPad.transportId,
192
- });
193
-
194
- const observedSfuOutboundRtpPad = transport.outboundRtpPads.get(outboundRtpPad.padId) ?? transport.createSfuOutboundRtpPad({
195
- sfuOutboundRtpPadId: outboundRtpPad.padId,
196
- });
197
-
198
- observedSfuOutboundRtpPad.update(outboundRtpPad, sample.timestamp);
199
- }
200
-
201
- for (const sctpChannel of sample.sctpChannels ?? []) {
202
- const transport = this._transports.get(sctpChannel.transportId) ?? this._createTransport({
203
- sfuTransportId: sctpChannel.transportId,
204
- });
205
-
206
- const observedSfuSctpChannel = transport.sctpChannels.get(sctpChannel.channelId) ?? transport.createSfuSctpChannel({
207
- sfuSctpChannelId: sctpChannel.channelId,
208
- });
209
-
210
- observedSfuSctpChannel.update(sctpChannel, sample.timestamp);
211
- }
212
-
213
- this._updated = now;
214
- this.emit('update', {
215
- elapsedTimeInMs,
216
- });
217
- }
218
-
219
- private _createTransport(model: ObservedSfuTransportModel) {
220
- const result = new ObservedSfuTransport(model, this);
221
-
222
- result.once('close', () => {
223
- this._transports.delete(model.sfuTransportId);
224
- });
225
- this._transports.set(model.sfuTransportId, result);
226
-
227
- this.emit('newtransport', result);
228
-
229
- return result;
230
- }
231
- }
@@ -1,106 +0,0 @@
1
- import { EventEmitter } from 'events';
2
- import { SfuInboundRtpPad } from '@observertc/sample-schemas-js';
3
- import { ObservedSfuTransport } from './ObservedSfuTransport';
4
- import { SfuInboundRtpPadReport } from '@observertc/report-schemas-js';
5
-
6
- export type ObservedSfuInboundRtpPadModel= {
7
- sfuInboundRtpPadId: string;
8
- };
9
-
10
- export type ObservedSfuInboundRtpPadEvents = {
11
- update: [{
12
- elapsedTimeInMs: number;
13
- }],
14
- close: [],
15
- };
16
-
17
- export declare interface ObservedSfuInboundRtpPad {
18
- on<U extends keyof ObservedSfuInboundRtpPadEvents>(event: U, listener: (...args: ObservedSfuInboundRtpPadEvents[U]) => void): this;
19
- off<U extends keyof ObservedSfuInboundRtpPadEvents>(event: U, listener: (...args: ObservedSfuInboundRtpPadEvents[U]) => void): this;
20
- once<U extends keyof ObservedSfuInboundRtpPadEvents>(event: U, listener: (...args: ObservedSfuInboundRtpPadEvents[U]) => void): this;
21
- emit<U extends keyof ObservedSfuInboundRtpPadEvents>(event: U, ...args: ObservedSfuInboundRtpPadEvents[U]): boolean;
22
-
23
- update(sample: SfuInboundRtpPad, timestamp: number): void;
24
- }
25
-
26
- export class ObservedSfuInboundRtpPad extends EventEmitter {
27
- public readonly created = Date.now();
28
-
29
- public stats?: SfuInboundRtpPad;
30
- public marker?: string;
31
- private _updated = Date.now();
32
- private _closed = false;
33
-
34
- public constructor(
35
- private readonly _model: ObservedSfuInboundRtpPadModel,
36
- public readonly transport: ObservedSfuTransport,
37
- ) {
38
- super();
39
- this.setMaxListeners(Infinity);
40
- }
41
-
42
- public get reports() {
43
- return this.transport.reports;
44
- }
45
-
46
- public get serviceId() {
47
- return this.transport.serviceId;
48
- }
49
-
50
- public get mediaUnitId() {
51
- return this.transport.mediaUnitId;
52
- }
53
-
54
- public get sfuId() {
55
- return this.transport.sfuId;
56
- }
57
-
58
- public get sfuTransportId() {
59
- return this.transport.sfuTransportId;
60
- }
61
-
62
- public get sfuRtpPadId() {
63
- return this._model.sfuInboundRtpPadId;
64
- }
65
-
66
- public get updated() {
67
- return this._updated;
68
- }
69
-
70
- public get closed() {
71
- return this._closed;
72
- }
73
-
74
- public close() {
75
- if (this._closed) return;
76
- this._closed = true;
77
- this.emit('close');
78
- }
79
-
80
- public update(sample: SfuInboundRtpPad, timestamp: number) {
81
- const now = Date.now();
82
- const elapsedTimeInMs = now - this._updated;
83
-
84
- const { streamId: sfuStreamId, padId: rtpPadId, ...reportData } = sample;
85
-
86
- const report: SfuInboundRtpPadReport = {
87
- serviceId: this.serviceId,
88
- mediaUnitId: this.mediaUnitId,
89
- sfuId: this.sfuId,
90
- callId: undefined, // TODO: where to get this from?
91
- sfuStreamId,
92
- rtpPadId,
93
- ...reportData,
94
- timestamp,
95
- marker: this.marker,
96
- };
97
-
98
- this.reports.addSfuInboundRtpPadReport(report);
99
- this.stats = sample;
100
-
101
- this._updated = now;
102
- this.emit('update', {
103
- elapsedTimeInMs,
104
- });
105
- }
106
- }