@observertc/observer-js 0.42.9 → 1.0.1-57a1811.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 (247) hide show
  1. package/.prettierrc +6 -6
  2. package/README.md +0 -104
  3. package/lib/ObservedCall.d.ts +38 -41
  4. package/lib/ObservedCall.d.ts.map +1 -1
  5. package/lib/ObservedCall.js +97 -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 +49 -127
  10. package/lib/ObservedClient.d.ts.map +1 -1
  11. package/lib/ObservedClient.js +201 -750
  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 +23 -69
  16. package/lib/ObservedDataChannel.d.ts.map +1 -1
  17. package/lib/ObservedDataChannel.js +67 -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 +44 -0
  22. package/lib/ObservedIceCandidatePair.d.ts.map +1 -0
  23. package/lib/ObservedIceCandidatePair.js +111 -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 +128 -78
  46. package/lib/ObservedPeerConnection.d.ts.map +1 -1
  47. package/lib/ObservedPeerConnection.js +624 -357
  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/ObservedTURN.d.ts +31 -0
  58. package/lib/ObservedTURN.d.ts.map +1 -0
  59. package/lib/ObservedTURN.js +58 -0
  60. package/lib/ObservedTurnServer.d.ts +25 -0
  61. package/lib/ObservedTurnServer.d.ts.map +1 -0
  62. package/lib/ObservedTurnServer.js +59 -0
  63. package/lib/Observer.d.ts +31 -51
  64. package/lib/Observer.d.ts.map +1 -1
  65. package/lib/Observer.js +75 -229
  66. package/lib/common/Middleware.d.ts +10 -1
  67. package/lib/common/Middleware.d.ts.map +1 -1
  68. package/lib/common/Middleware.js +55 -36
  69. package/lib/common/logger.d.ts +8 -4
  70. package/lib/common/logger.d.ts.map +1 -1
  71. package/lib/common/logger.js +44 -68
  72. package/lib/common/types.d.ts +0 -21
  73. package/lib/common/types.d.ts.map +1 -1
  74. package/lib/common/types.js +1 -0
  75. package/lib/common/utils.d.ts +1 -0
  76. package/lib/common/utils.d.ts.map +1 -1
  77. package/lib/common/utils.js +13 -1
  78. package/lib/detectors/Detector.d.ts +5 -0
  79. package/lib/detectors/Detector.d.ts.map +1 -0
  80. package/lib/detectors/Detector.js +3 -0
  81. package/lib/detectors/Detectors.d.ts +11 -0
  82. package/lib/detectors/Detectors.d.ts.map +1 -0
  83. package/lib/detectors/Detectors.js +34 -0
  84. package/lib/index.d.ts +24 -25
  85. package/lib/index.d.ts.map +1 -1
  86. package/lib/index.js +41 -41
  87. package/lib/monitors/TurnUsageMonitor.d.ts +0 -52
  88. package/lib/monitors/TurnUsageMonitor.d.ts.map +1 -1
  89. package/lib/monitors/TurnUsageMonitor.js +145 -120
  90. package/lib/schema/ClientEventTypes.d.ts +33 -0
  91. package/lib/schema/ClientEventTypes.d.ts.map +1 -0
  92. package/lib/schema/ClientEventTypes.js +38 -0
  93. package/lib/schema/ClientMetaTypes.d.ts +34 -0
  94. package/lib/schema/ClientMetaTypes.d.ts.map +1 -0
  95. package/lib/schema/ClientMetaTypes.js +16 -0
  96. package/lib/schema/ClientSample.d.ts +1333 -0
  97. package/lib/schema/ClientSample.d.ts.map +1 -0
  98. package/lib/schema/ClientSample.js +4 -0
  99. package/lib/scores/CalculatedScore.d.ts +6 -0
  100. package/lib/scores/CalculatedScore.d.ts.map +1 -0
  101. package/lib/scores/DefaultCallScoreCalculator.d.ts +7 -0
  102. package/lib/scores/DefaultCallScoreCalculator.d.ts.map +1 -0
  103. package/lib/scores/DefaultCallScoreCalculator.js +21 -0
  104. package/lib/scores/ScoreCalculator.d.ts +4 -0
  105. package/lib/scores/ScoreCalculator.d.ts.map +1 -0
  106. package/lib/scores/ScoreCalculator.js +2 -0
  107. package/lib/utils/CallUpdater.d.ts +5 -0
  108. package/lib/utils/CallUpdater.d.ts.map +1 -0
  109. package/lib/utils/CallUpdater.js +2 -0
  110. package/lib/utils/OnAllClientCallUpdater.d.ts +16 -0
  111. package/lib/utils/OnAllClientCallUpdater.d.ts.map +1 -0
  112. package/lib/utils/OnAllClientCallUpdater.js +58 -0
  113. package/lib/utils/RemoteTrackResolver.d.ts +7 -0
  114. package/lib/utils/RemoteTrackResolver.d.ts.map +1 -0
  115. package/lib/utils/RemoteTrackResolver.js +2 -0
  116. package/lib/utils/onAnyClientCallUpdater.d.ts +14 -0
  117. package/lib/utils/onAnyClientCallUpdater.d.ts.map +1 -0
  118. package/lib/utils/onAnyClientCallUpdater.js +51 -0
  119. package/package.json +4 -4
  120. package/src/ObservedCall.ts +116 -166
  121. package/src/ObservedCertificate.ts +43 -0
  122. package/src/ObservedClient.ts +213 -1060
  123. package/src/ObservedCodec.ts +49 -0
  124. package/src/ObservedDataChannel.ts +68 -181
  125. package/src/ObservedIceCandidate.ts +64 -0
  126. package/src/ObservedIceCandidatePair.ts +118 -0
  127. package/src/ObservedIceTransport.ts +70 -0
  128. package/src/ObservedInboundRtp.ts +205 -0
  129. package/src/ObservedInboundTrack.ts +70 -0
  130. package/src/ObservedMediaPlayout.ts +49 -0
  131. package/src/ObservedMediaSource.ts +60 -0
  132. package/src/ObservedOutboundRtp.ts +156 -0
  133. package/src/ObservedOutboundTrack.ts +69 -0
  134. package/src/ObservedPeerConnection.ts +827 -405
  135. package/src/ObservedPeerConnectionTransport.ts +38 -0
  136. package/src/ObservedRemoteInboundRtp.ts +64 -0
  137. package/src/ObservedRemoteOutboundRtp.ts +65 -0
  138. package/src/ObservedTURN.ts +86 -0
  139. package/src/ObservedTurnServer.ts +72 -0
  140. package/src/Observer.ts +91 -302
  141. package/src/common/Middleware.ts +70 -42
  142. package/src/common/logger.ts +60 -69
  143. package/src/common/types.ts +0 -42
  144. package/src/common/utils.ts +12 -0
  145. package/src/detectors/Detector.ts +6 -0
  146. package/src/detectors/Detectors.ts +38 -0
  147. package/src/index.ts +24 -90
  148. package/src/monitors/TurnUsageMonitor.ts +164 -164
  149. package/src/schema/ClientEventTypes.ts +36 -0
  150. package/src/schema/ClientMetaTypes.ts +41 -0
  151. package/src/schema/ClientSample.ts +1682 -0
  152. package/src/scores/CalculatedScore.ts +6 -0
  153. package/src/scores/DefaultCallScoreCalculator.ts +23 -0
  154. package/src/scores/ScoreCalculator.ts +3 -0
  155. package/src/utils/CallUpdater.ts +5 -0
  156. package/src/utils/OnAllClientCallUpdater.ts +68 -0
  157. package/src/utils/RemoteTrackResolver.ts +12 -0
  158. package/src/utils/onAnyClientCallUpdater.ts +59 -0
  159. package/tsconfig.json +3 -3
  160. package/lib/ObservedICE.d.ts +0 -64
  161. package/lib/ObservedICE.d.ts.map +0 -1
  162. package/lib/ObservedICE.js +0 -141
  163. package/lib/ObservedInboundAudioTrack.d.ts +0 -96
  164. package/lib/ObservedInboundAudioTrack.d.ts.map +0 -1
  165. package/lib/ObservedInboundAudioTrack.js +0 -217
  166. package/lib/ObservedInboundVideoTrack.d.ts +0 -101
  167. package/lib/ObservedInboundVideoTrack.d.ts.map +0 -1
  168. package/lib/ObservedInboundVideoTrack.js +0 -232
  169. package/lib/ObservedOutboundAudioTrack.d.ts +0 -87
  170. package/lib/ObservedOutboundAudioTrack.d.ts.map +0 -1
  171. package/lib/ObservedOutboundAudioTrack.js +0 -186
  172. package/lib/ObservedOutboundVideoTrack.d.ts +0 -91
  173. package/lib/ObservedOutboundVideoTrack.d.ts.map +0 -1
  174. package/lib/ObservedOutboundVideoTrack.js +0 -193
  175. package/lib/ObservedSfu.d.ts +0 -59
  176. package/lib/ObservedSfu.d.ts.map +0 -1
  177. package/lib/ObservedSfu.js +0 -157
  178. package/lib/ObservedSfuInboundRtpPad.d.ts +0 -42
  179. package/lib/ObservedSfuInboundRtpPad.d.ts.map +0 -1
  180. package/lib/ObservedSfuInboundRtpPad.js +0 -71
  181. package/lib/ObservedSfuOutboundRtpPad.d.ts +0 -42
  182. package/lib/ObservedSfuOutboundRtpPad.d.ts.map +0 -1
  183. package/lib/ObservedSfuOutboundRtpPad.js +0 -72
  184. package/lib/ObservedSfuSctpChannel.d.ts +0 -42
  185. package/lib/ObservedSfuSctpChannel.d.ts.map +0 -1
  186. package/lib/ObservedSfuSctpChannel.js +0 -57
  187. package/lib/ObservedSfuTransport.d.ts +0 -58
  188. package/lib/ObservedSfuTransport.d.ts.map +0 -1
  189. package/lib/ObservedSfuTransport.js +0 -120
  190. package/lib/RemoteTrackAssigner.d.ts +0 -14
  191. package/lib/RemoteTrackAssigner.d.ts.map +0 -1
  192. package/lib/RemoteTrackAssigner.js +0 -52
  193. package/lib/ReportsCollector.d.ts +0 -109
  194. package/lib/ReportsCollector.d.ts.map +0 -1
  195. package/lib/ReportsCollector.js +0 -207
  196. package/lib/common/CalculatedScore.d.ts +0 -80
  197. package/lib/common/CalculatedScore.d.ts.map +0 -1
  198. package/lib/common/CalculatedScore.js +0 -162
  199. package/lib/common/CallEventType.d.ts +0 -63
  200. package/lib/common/CallEventType.d.ts.map +0 -1
  201. package/lib/common/CallEventType.js +0 -39
  202. package/lib/common/CallMetaReports.d.ts +0 -42
  203. package/lib/common/CallMetaReports.d.ts.map +0 -1
  204. package/lib/common/CallMetaReports.js +0 -36
  205. package/lib/common/QualityScoreUtils.d.ts +0 -1
  206. package/lib/common/QualityScoreUtils.d.ts.map +0 -1
  207. package/lib/common/QualityScoreUtils.js +0 -1
  208. package/lib/common/TypedEventEmitter.d.ts +0 -22
  209. package/lib/common/TypedEventEmitter.d.ts.map +0 -1
  210. package/lib/common/TypedEventEmitter.js +0 -11
  211. package/lib/common/callEventReports.d.ts +0 -10
  212. package/lib/common/callEventReports.d.ts.map +0 -1
  213. package/lib/common/callEventReports.js +0 -112
  214. package/lib/monitors/CallSummary.d.ts +0 -37
  215. package/lib/monitors/CallSummary.d.ts.map +0 -1
  216. package/lib/monitors/CallSummaryMonitor.d.ts +0 -32
  217. package/lib/monitors/CallSummaryMonitor.d.ts.map +0 -1
  218. package/lib/monitors/CallSummaryMonitor.js +0 -152
  219. package/lib/monitors/ClientIssueMonitor.d.ts +0 -32
  220. package/lib/monitors/ClientIssueMonitor.d.ts.map +0 -1
  221. package/lib/monitors/ClientIssueMonitor.js +0 -49
  222. package/lib/monitors/SfuServerMonitor.d.ts +0 -79
  223. package/lib/monitors/SfuServerMonitor.d.ts.map +0 -1
  224. package/lib/monitors/SfuServerMonitor.js +0 -198
  225. package/src/ObservedICE.ts +0 -237
  226. package/src/ObservedInboundAudioTrack.ts +0 -344
  227. package/src/ObservedInboundVideoTrack.ts +0 -361
  228. package/src/ObservedOutboundAudioTrack.ts +0 -307
  229. package/src/ObservedOutboundVideoTrack.ts +0 -319
  230. package/src/ObservedSfu.ts +0 -231
  231. package/src/ObservedSfuInboundRtpPad.ts +0 -106
  232. package/src/ObservedSfuOutboundRtpPad.ts +0 -107
  233. package/src/ObservedSfuSctpChannel.ts +0 -103
  234. package/src/ObservedSfuTransport.ts +0 -185
  235. package/src/RemoteTrackAssigner.ts +0 -68
  236. package/src/ReportsCollector.ts +0 -336
  237. package/src/common/CalculatedScore.ts +0 -188
  238. package/src/common/CallEventType.ts +0 -69
  239. package/src/common/CallMetaReports.ts +0 -82
  240. package/src/common/QualityScoreUtils.ts +0 -0
  241. package/src/common/TypedEventEmitter.ts +0 -32
  242. package/src/common/callEventReports.ts +0 -178
  243. package/src/monitors/CallSummary.ts +0 -38
  244. package/src/monitors/CallSummaryMonitor.ts +0 -192
  245. package/src/monitors/ClientIssueMonitor.ts +0 -88
  246. package/src/monitors/SfuServerMonitor.ts +0 -285
  247. /package/lib/{monitors/CallSummary.js → scores/CalculatedScore.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
- }