@observertc/observer-js 0.42.9 → 1.0.1-23e88d8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) hide show
  1. package/.prettierrc +6 -6
  2. package/README.md +0 -104
  3. package/lib/ObservedCall.d.ts +25 -41
  4. package/lib/ObservedCall.d.ts.map +1 -1
  5. package/lib/ObservedCall.js +61 -109
  6. package/lib/ObservedCertificate.d.ts +19 -0
  7. package/lib/ObservedCertificate.d.ts.map +1 -0
  8. package/lib/ObservedCertificate.js +38 -0
  9. package/lib/ObservedClient.d.ts +33 -143
  10. package/lib/ObservedClient.d.ts.map +1 -1
  11. package/lib/ObservedClient.js +156 -757
  12. package/lib/ObservedCodec.d.ts +22 -0
  13. package/lib/ObservedCodec.d.ts.map +1 -0
  14. package/lib/ObservedCodec.js +45 -0
  15. package/lib/ObservedDataChannel.d.ts +20 -70
  16. package/lib/ObservedDataChannel.d.ts.map +1 -1
  17. package/lib/ObservedDataChannel.js +39 -109
  18. package/lib/ObservedIceCandidate.d.ts +29 -0
  19. package/lib/ObservedIceCandidate.d.ts.map +1 -0
  20. package/lib/ObservedIceCandidate.js +59 -0
  21. package/lib/ObservedIceCandidatePair.d.ts +40 -0
  22. package/lib/ObservedIceCandidatePair.d.ts.map +1 -0
  23. package/lib/ObservedIceCandidatePair.js +83 -0
  24. package/lib/ObservedIceTransport.d.ts +32 -0
  25. package/lib/ObservedIceTransport.d.ts.map +1 -0
  26. package/lib/ObservedIceTransport.js +65 -0
  27. package/lib/ObservedInboundRtp.d.ts +92 -0
  28. package/lib/ObservedInboundRtp.d.ts.map +1 -0
  29. package/lib/ObservedInboundRtp.js +193 -0
  30. package/lib/ObservedInboundTrack.d.ts +29 -0
  31. package/lib/ObservedInboundTrack.d.ts.map +1 -0
  32. package/lib/ObservedInboundTrack.js +57 -0
  33. package/lib/ObservedMediaPlayout.d.ts +22 -0
  34. package/lib/ObservedMediaPlayout.d.ts.map +1 -0
  35. package/lib/ObservedMediaPlayout.js +42 -0
  36. package/lib/ObservedMediaSource.d.ts +28 -0
  37. package/lib/ObservedMediaSource.d.ts.map +1 -0
  38. package/lib/ObservedMediaSource.js +55 -0
  39. package/lib/ObservedOutboundRtp.d.ts +62 -0
  40. package/lib/ObservedOutboundRtp.d.ts.map +1 -0
  41. package/lib/ObservedOutboundRtp.js +144 -0
  42. package/lib/ObservedOutboundTrack.d.ts +29 -0
  43. package/lib/ObservedOutboundTrack.d.ts.map +1 -0
  44. package/lib/ObservedOutboundTrack.js +57 -0
  45. package/lib/ObservedPeerConnection.d.ts +118 -78
  46. package/lib/ObservedPeerConnection.d.ts.map +1 -1
  47. package/lib/ObservedPeerConnection.js +556 -359
  48. package/lib/ObservedPeerConnectionTransport.d.ts +17 -0
  49. package/lib/ObservedPeerConnectionTransport.d.ts.map +1 -0
  50. package/lib/ObservedPeerConnectionTransport.js +34 -0
  51. package/lib/ObservedRemoteInboundRtp.d.ts +30 -0
  52. package/lib/ObservedRemoteInboundRtp.d.ts.map +1 -0
  53. package/lib/ObservedRemoteInboundRtp.js +60 -0
  54. package/lib/ObservedRemoteOutboundRtp.d.ts +30 -0
  55. package/lib/ObservedRemoteOutboundRtp.d.ts.map +1 -0
  56. package/lib/ObservedRemoteOutboundRtp.js +60 -0
  57. package/lib/Observer.d.ts +30 -53
  58. package/lib/Observer.d.ts.map +1 -1
  59. package/lib/Observer.js +52 -225
  60. package/lib/common/Middleware.d.ts +10 -1
  61. package/lib/common/Middleware.d.ts.map +1 -1
  62. package/lib/common/Middleware.js +55 -36
  63. package/lib/common/logger.d.ts +8 -4
  64. package/lib/common/logger.d.ts.map +1 -1
  65. package/lib/common/logger.js +44 -68
  66. package/lib/common/types.d.ts +0 -21
  67. package/lib/common/types.d.ts.map +1 -1
  68. package/lib/common/types.js +1 -0
  69. package/lib/common/utils.d.ts +1 -0
  70. package/lib/common/utils.d.ts.map +1 -1
  71. package/lib/common/utils.js +13 -1
  72. package/lib/detectors/Detector.d.ts +5 -0
  73. package/lib/detectors/Detector.d.ts.map +1 -0
  74. package/lib/detectors/Detector.js +3 -0
  75. package/lib/detectors/Detectors.d.ts +11 -0
  76. package/lib/detectors/Detectors.d.ts.map +1 -0
  77. package/lib/detectors/Detectors.js +34 -0
  78. package/lib/index.d.ts +23 -25
  79. package/lib/index.d.ts.map +1 -1
  80. package/lib/index.js +41 -41
  81. package/lib/monitors/TurnUsageMonitor.d.ts +0 -52
  82. package/lib/monitors/TurnUsageMonitor.d.ts.map +1 -1
  83. package/lib/monitors/TurnUsageMonitor.js +145 -120
  84. package/lib/schema/ClientEventTypes.d.ts +33 -0
  85. package/lib/schema/ClientEventTypes.d.ts.map +1 -0
  86. package/lib/schema/ClientEventTypes.js +38 -0
  87. package/lib/schema/ClientMetaTypes.d.ts +34 -0
  88. package/lib/schema/ClientMetaTypes.d.ts.map +1 -0
  89. package/lib/schema/ClientMetaTypes.js +16 -0
  90. package/lib/schema/ClientSample.d.ts +1333 -0
  91. package/lib/schema/ClientSample.d.ts.map +1 -0
  92. package/lib/schema/ClientSample.js +4 -0
  93. package/lib/scores/CalculatedScore.d.ts +6 -0
  94. package/lib/scores/CalculatedScore.d.ts.map +1 -0
  95. package/lib/scores/DefaultCallScoreCalculator.d.ts +7 -0
  96. package/lib/scores/DefaultCallScoreCalculator.d.ts.map +1 -0
  97. package/lib/scores/DefaultCallScoreCalculator.js +21 -0
  98. package/lib/scores/ScoreCalculator.d.ts +4 -0
  99. package/lib/scores/ScoreCalculator.d.ts.map +1 -0
  100. package/lib/scores/ScoreCalculator.js +2 -0
  101. package/lib/utils/CallUpdater.d.ts +5 -0
  102. package/lib/utils/CallUpdater.d.ts.map +1 -0
  103. package/lib/utils/CallUpdater.js +2 -0
  104. package/lib/utils/OnAllClientCallUpdater.d.ts +16 -0
  105. package/lib/utils/OnAllClientCallUpdater.d.ts.map +1 -0
  106. package/lib/utils/OnAllClientCallUpdater.js +58 -0
  107. package/lib/utils/RemoteTrackResolver.d.ts +7 -0
  108. package/lib/utils/RemoteTrackResolver.d.ts.map +1 -0
  109. package/lib/utils/RemoteTrackResolver.js +2 -0
  110. package/lib/utils/onAnyClientCallUpdater.d.ts +14 -0
  111. package/lib/utils/onAnyClientCallUpdater.d.ts.map +1 -0
  112. package/lib/utils/onAnyClientCallUpdater.js +51 -0
  113. package/package.json +4 -4
  114. package/src/ObservedCall.ts +74 -167
  115. package/src/ObservedCertificate.ts +43 -0
  116. package/src/ObservedClient.ts +173 -1085
  117. package/src/ObservedCodec.ts +49 -0
  118. package/src/ObservedDataChannel.ts +36 -178
  119. package/src/ObservedIceCandidate.ts +64 -0
  120. package/src/ObservedIceCandidatePair.ts +92 -0
  121. package/src/ObservedIceTransport.ts +70 -0
  122. package/src/ObservedInboundRtp.ts +205 -0
  123. package/src/ObservedInboundTrack.ts +70 -0
  124. package/src/ObservedMediaPlayout.ts +49 -0
  125. package/src/ObservedMediaSource.ts +60 -0
  126. package/src/ObservedOutboundRtp.ts +156 -0
  127. package/src/ObservedOutboundTrack.ts +69 -0
  128. package/src/ObservedPeerConnection.ts +743 -401
  129. package/src/ObservedPeerConnectionTransport.ts +38 -0
  130. package/src/ObservedRemoteInboundRtp.ts +64 -0
  131. package/src/ObservedRemoteOutboundRtp.ts +65 -0
  132. package/src/Observer.ts +65 -285
  133. package/src/common/Middleware.ts +70 -42
  134. package/src/common/logger.ts +60 -69
  135. package/src/common/types.ts +0 -42
  136. package/src/common/utils.ts +12 -0
  137. package/src/detectors/Detector.ts +6 -0
  138. package/src/detectors/Detectors.ts +38 -0
  139. package/src/index.ts +23 -90
  140. package/src/monitors/TurnUsageMonitor.ts +164 -164
  141. package/src/schema/ClientEventTypes.ts +36 -0
  142. package/src/schema/ClientMetaTypes.ts +41 -0
  143. package/src/schema/ClientSample.ts +1682 -0
  144. package/src/scores/CalculatedScore.ts +6 -0
  145. package/src/scores/DefaultCallScoreCalculator.ts +23 -0
  146. package/src/scores/ScoreCalculator.ts +3 -0
  147. package/src/utils/CallUpdater.ts +5 -0
  148. package/src/utils/OnAllClientCallUpdater.ts +68 -0
  149. package/src/utils/RemoteTrackResolver.ts +12 -0
  150. package/src/utils/onAnyClientCallUpdater.ts +59 -0
  151. package/tsconfig.json +3 -3
  152. package/lib/ObservedICE.d.ts +0 -64
  153. package/lib/ObservedICE.d.ts.map +0 -1
  154. package/lib/ObservedICE.js +0 -141
  155. package/lib/ObservedInboundAudioTrack.d.ts +0 -96
  156. package/lib/ObservedInboundAudioTrack.d.ts.map +0 -1
  157. package/lib/ObservedInboundAudioTrack.js +0 -217
  158. package/lib/ObservedInboundVideoTrack.d.ts +0 -101
  159. package/lib/ObservedInboundVideoTrack.d.ts.map +0 -1
  160. package/lib/ObservedInboundVideoTrack.js +0 -232
  161. package/lib/ObservedOutboundAudioTrack.d.ts +0 -87
  162. package/lib/ObservedOutboundAudioTrack.d.ts.map +0 -1
  163. package/lib/ObservedOutboundAudioTrack.js +0 -186
  164. package/lib/ObservedOutboundVideoTrack.d.ts +0 -91
  165. package/lib/ObservedOutboundVideoTrack.d.ts.map +0 -1
  166. package/lib/ObservedOutboundVideoTrack.js +0 -193
  167. package/lib/ObservedSfu.d.ts +0 -59
  168. package/lib/ObservedSfu.d.ts.map +0 -1
  169. package/lib/ObservedSfu.js +0 -157
  170. package/lib/ObservedSfuInboundRtpPad.d.ts +0 -42
  171. package/lib/ObservedSfuInboundRtpPad.d.ts.map +0 -1
  172. package/lib/ObservedSfuInboundRtpPad.js +0 -71
  173. package/lib/ObservedSfuOutboundRtpPad.d.ts +0 -42
  174. package/lib/ObservedSfuOutboundRtpPad.d.ts.map +0 -1
  175. package/lib/ObservedSfuOutboundRtpPad.js +0 -72
  176. package/lib/ObservedSfuSctpChannel.d.ts +0 -42
  177. package/lib/ObservedSfuSctpChannel.d.ts.map +0 -1
  178. package/lib/ObservedSfuSctpChannel.js +0 -57
  179. package/lib/ObservedSfuTransport.d.ts +0 -58
  180. package/lib/ObservedSfuTransport.d.ts.map +0 -1
  181. package/lib/ObservedSfuTransport.js +0 -120
  182. package/lib/RemoteTrackAssigner.d.ts +0 -14
  183. package/lib/RemoteTrackAssigner.d.ts.map +0 -1
  184. package/lib/RemoteTrackAssigner.js +0 -52
  185. package/lib/ReportsCollector.d.ts +0 -109
  186. package/lib/ReportsCollector.d.ts.map +0 -1
  187. package/lib/ReportsCollector.js +0 -207
  188. package/lib/common/CalculatedScore.d.ts +0 -80
  189. package/lib/common/CalculatedScore.d.ts.map +0 -1
  190. package/lib/common/CalculatedScore.js +0 -162
  191. package/lib/common/CallEventType.d.ts +0 -63
  192. package/lib/common/CallEventType.d.ts.map +0 -1
  193. package/lib/common/CallEventType.js +0 -39
  194. package/lib/common/CallMetaReports.d.ts +0 -42
  195. package/lib/common/CallMetaReports.d.ts.map +0 -1
  196. package/lib/common/CallMetaReports.js +0 -36
  197. package/lib/common/QualityScoreUtils.d.ts +0 -1
  198. package/lib/common/QualityScoreUtils.d.ts.map +0 -1
  199. package/lib/common/QualityScoreUtils.js +0 -1
  200. package/lib/common/TypedEventEmitter.d.ts +0 -22
  201. package/lib/common/TypedEventEmitter.d.ts.map +0 -1
  202. package/lib/common/TypedEventEmitter.js +0 -11
  203. package/lib/common/callEventReports.d.ts +0 -10
  204. package/lib/common/callEventReports.d.ts.map +0 -1
  205. package/lib/common/callEventReports.js +0 -112
  206. package/lib/monitors/CallSummary.d.ts +0 -37
  207. package/lib/monitors/CallSummary.d.ts.map +0 -1
  208. package/lib/monitors/CallSummaryMonitor.d.ts +0 -32
  209. package/lib/monitors/CallSummaryMonitor.d.ts.map +0 -1
  210. package/lib/monitors/CallSummaryMonitor.js +0 -152
  211. package/lib/monitors/ClientIssueMonitor.d.ts +0 -32
  212. package/lib/monitors/ClientIssueMonitor.d.ts.map +0 -1
  213. package/lib/monitors/ClientIssueMonitor.js +0 -49
  214. package/lib/monitors/SfuServerMonitor.d.ts +0 -79
  215. package/lib/monitors/SfuServerMonitor.d.ts.map +0 -1
  216. package/lib/monitors/SfuServerMonitor.js +0 -198
  217. package/src/ObservedICE.ts +0 -237
  218. package/src/ObservedInboundAudioTrack.ts +0 -344
  219. package/src/ObservedInboundVideoTrack.ts +0 -361
  220. package/src/ObservedOutboundAudioTrack.ts +0 -307
  221. package/src/ObservedOutboundVideoTrack.ts +0 -319
  222. package/src/ObservedSfu.ts +0 -231
  223. package/src/ObservedSfuInboundRtpPad.ts +0 -106
  224. package/src/ObservedSfuOutboundRtpPad.ts +0 -107
  225. package/src/ObservedSfuSctpChannel.ts +0 -103
  226. package/src/ObservedSfuTransport.ts +0 -185
  227. package/src/RemoteTrackAssigner.ts +0 -68
  228. package/src/ReportsCollector.ts +0 -336
  229. package/src/common/CalculatedScore.ts +0 -188
  230. package/src/common/CallEventType.ts +0 -69
  231. package/src/common/CallMetaReports.ts +0 -82
  232. package/src/common/QualityScoreUtils.ts +0 -0
  233. package/src/common/TypedEventEmitter.ts +0 -32
  234. package/src/common/callEventReports.ts +0 -178
  235. package/src/monitors/CallSummary.ts +0 -38
  236. package/src/monitors/CallSummaryMonitor.ts +0 -192
  237. package/src/monitors/ClientIssueMonitor.ts +0 -88
  238. package/src/monitors/SfuServerMonitor.ts +0 -285
  239. /package/lib/{monitors/CallSummary.js → scores/CalculatedScore.js} +0 -0
@@ -0,0 +1,205 @@
1
+ import { MediaKind } from './common/types';
2
+ import { ObservedPeerConnection } from './ObservedPeerConnection';
3
+ import { InboundRtpStats } from './schema/ClientSample';
4
+
5
+ export class ObservedInboundRtp implements InboundRtpStats {
6
+ public appData?: Record<string, unknown>;
7
+
8
+ private _visited = false;
9
+
10
+ transportId?: string | undefined;
11
+ codecId?: string | undefined;
12
+ packetsReceived?: number | undefined;
13
+ packetsLost?: number | undefined;
14
+ mid?: string | undefined;
15
+ remoteId?: string | undefined;
16
+ framesDecoded?: number | undefined;
17
+ keyFramesDecoded?: number | undefined;
18
+ framesRendered?: number | undefined;
19
+ framesDropped?: number | undefined;
20
+ frameWidth?: number | undefined;
21
+ frameHeight?: number | undefined;
22
+ framesPerSecond?: number | undefined;
23
+ qpSum?: number | undefined;
24
+ totalDecodeTime?: number | undefined;
25
+ totalInterFrameDelay?: number | undefined;
26
+ totalSquaredInterFrameDelay?: number | undefined;
27
+ pauseCount?: number | undefined;
28
+ totalPausesDuration?: number | undefined;
29
+ freezeCount?: number | undefined;
30
+ totalFreezesDuration?: number | undefined;
31
+ lastPacketReceivedTimestamp?: number | undefined;
32
+ headerBytesReceived?: number | undefined;
33
+ packetsDiscarded?: number | undefined;
34
+ fecBytesReceived?: number | undefined;
35
+ fecPacketsReceived?: number | undefined;
36
+ fecPacketsDiscarded?: number | undefined;
37
+ bytesReceived?: number | undefined;
38
+ nackCount?: number | undefined;
39
+ firCount?: number | undefined;
40
+ pliCount?: number | undefined;
41
+ totalProcessingDelay?: number | undefined;
42
+ estimatedPlayoutTimestamp?: number | undefined;
43
+ jitterBufferDelay?: number | undefined;
44
+ jitterBufferTargetDelay?: number | undefined;
45
+ jitterBufferEmittedCount?: number | undefined;
46
+ jitterBufferMinimumDelay?: number | undefined;
47
+ totalSamplesReceived?: number | undefined;
48
+ concealedSamples?: number | undefined;
49
+ silentConcealedSamples?: number | undefined;
50
+ concealmentEvents?: number | undefined;
51
+ insertedSamplesForDeceleration?: number | undefined;
52
+ removedSamplesForAcceleration?: number | undefined;
53
+ audioLevel?: number | undefined;
54
+ totalAudioEnergy?: number | undefined;
55
+ totalSamplesDuration?: number | undefined;
56
+ framesReceived?: number | undefined;
57
+ decoderImplementation?: string | undefined;
58
+ playoutId?: string | undefined;
59
+ powerEfficientDecoder?: boolean | undefined;
60
+ framesAssembledFromMultiplePackets?: number | undefined;
61
+ totalAssemblyTime?: number | undefined;
62
+ retransmittedPacketsReceived?: number | undefined;
63
+ retransmittedBytesReceived?: number | undefined;
64
+ rtxSsrc?: number | undefined;
65
+ fecSsrc?: number | undefined;
66
+ totalCorruptionProbability?: number | undefined;
67
+ totalSquaredCorruptionProbability?: number | undefined;
68
+ corruptionMeasurements?: number | undefined;
69
+ attachments?: Record<string, unknown> | undefined;
70
+ jitter?: number | undefined;
71
+
72
+ public bitrate = 0;
73
+ public fractionLost?: number;
74
+ public bitPerPixel = 0;
75
+
76
+ public deltaLostPackets = 0;
77
+ public deltaReceivedPackets = 0;
78
+ public deltaBytesReceived = 0;
79
+ public deltaReceivedSamples = 0;
80
+ public deltaSilentConcealedSamples = 0;
81
+
82
+ public constructor(
83
+ public timestamp: number,
84
+ public id: string,
85
+ public ssrc: number,
86
+ public kind: MediaKind,
87
+ public trackIdentifier: string,
88
+ private readonly _peerConnection: ObservedPeerConnection
89
+ ) {}
90
+
91
+ public get visited() {
92
+ const visited = this._visited;
93
+
94
+ this._visited = false;
95
+
96
+ return visited;
97
+ }
98
+
99
+ public getPeerConnection() {
100
+ return this._peerConnection;
101
+ }
102
+
103
+ public getRemoteOutboundRtp() {
104
+ return this._peerConnection.observedRemoteOutboundRtps.get(this.ssrc);
105
+ }
106
+
107
+ public getIceTransport() {
108
+ return this._peerConnection.observedIceTransports.get(this.transportId ?? '');
109
+ }
110
+
111
+ public getCodec() {
112
+ return this._peerConnection.observedCodecs.get(this.codecId ?? '');
113
+ }
114
+
115
+ public getMediaPlayout() {
116
+ return this._peerConnection.observedMediaPlayouts.get(this.playoutId ?? '');
117
+ }
118
+
119
+ public getTrack() {
120
+ return this._peerConnection.observedInboundTracks.get(this.trackIdentifier);
121
+ }
122
+
123
+ public update(stats: InboundRtpStats) {
124
+ this._visited = true;
125
+ this.deltaBytesReceived = 0;
126
+ this.deltaLostPackets = 0;
127
+ this.deltaReceivedPackets = 0;
128
+ this.deltaReceivedSamples = 0;
129
+ this.deltaSilentConcealedSamples = 0;
130
+ this.bitrate = 0;
131
+ this.jitter = undefined;
132
+ this.fractionLost = undefined;
133
+ this.bitPerPixel = 0;
134
+
135
+ const elapsedTimeInMs = stats.timestamp - this.timestamp;
136
+
137
+ if (elapsedTimeInMs) {
138
+ // update metrics here
139
+ if (this.bytesReceived && stats.bytesReceived && this.bytesReceived < stats.bytesReceived) {
140
+ this.bitrate = ((stats.bytesReceived - (this.bytesReceived ?? 0)) * 8) / elapsedTimeInMs;
141
+ }
142
+ if (this.packetsLost && stats.packetsLost && this.packetsLost < stats.packetsLost) {
143
+ this.deltaLostPackets = stats.packetsLost - this.packetsLost;
144
+ }
145
+ if (this.packetsReceived && stats.packetsReceived && this.packetsReceived < stats.packetsReceived) {
146
+ this.deltaReceivedPackets = stats.packetsReceived - this.packetsReceived;
147
+ }
148
+ if (this.totalSamplesReceived && stats.totalSamplesReceived && this.totalSamplesReceived < stats.totalSamplesReceived) {
149
+ this.deltaReceivedSamples = stats.totalSamplesReceived - this.totalSamplesReceived;
150
+ }
151
+ if (this.silentConcealedSamples && stats.silentConcealedSamples && this.silentConcealedSamples < stats.silentConcealedSamples) {
152
+ this.deltaSilentConcealedSamples = stats.silentConcealedSamples - this.silentConcealedSamples;
153
+ }
154
+ if (stats.bytesReceived && this.framesReceived && stats.framesReceived && this.framesReceived < stats.framesReceived) {
155
+ this.bitPerPixel = (stats.bytesReceived - (this.bytesReceived ?? 0)) / (stats.framesReceived - this.framesReceived);
156
+ }
157
+ if (this.deltaLostPackets && this.deltaReceivedPackets) {
158
+ this.fractionLost = this.deltaLostPackets / (this.deltaLostPackets + this.deltaReceivedPackets);
159
+ }
160
+ }
161
+
162
+ this.timestamp = stats.timestamp;
163
+ this.transportId = stats.transportId;
164
+ this.codecId = stats.codecId;
165
+ this.packetsReceived = stats.packetsReceived;
166
+ this.packetsLost = stats.packetsLost;
167
+ this.mid = stats.mid;
168
+ this.remoteId = stats.remoteId;
169
+ this.framesDecoded = stats.framesDecoded;
170
+ this.keyFramesDecoded = stats.keyFramesDecoded;
171
+ this.framesRendered = stats.framesRendered;
172
+ this.framesDropped = stats.framesDropped;
173
+ this.frameWidth = stats.frameWidth;
174
+ this.frameHeight = stats.frameHeight;
175
+ this.framesPerSecond = stats.framesPerSecond;
176
+ this.qpSum = stats.qpSum;
177
+ this.totalDecodeTime = stats.totalDecodeTime;
178
+ this.totalInterFrameDelay = stats.totalInterFrameDelay;
179
+ this.totalSquaredInterFrameDelay = stats.totalSquaredInterFrameDelay;
180
+ this.pauseCount = stats.pauseCount;
181
+ this.totalPausesDuration = stats.totalPausesDuration;
182
+ this.freezeCount = stats.freezeCount;
183
+ this.totalFreezesDuration = stats.totalFreezesDuration;
184
+ this.lastPacketReceivedTimestamp = stats.lastPacketReceivedTimestamp;
185
+ this.headerBytesReceived = stats.headerBytesReceived;
186
+ this.packetsDiscarded = stats.packetsDiscarded;
187
+ this.fecBytesReceived = stats.fecBytesReceived;
188
+ this.fecPacketsReceived = stats.fecPacketsReceived;
189
+ this.fecPacketsDiscarded = stats.fecPacketsDiscarded;
190
+ this.bytesReceived = stats.bytesReceived;
191
+ this.nackCount = stats.nackCount;
192
+ this.firCount = stats.firCount;
193
+ this.pliCount = stats.pliCount;
194
+ this.totalProcessingDelay = stats.totalProcessingDelay;
195
+ this.estimatedPlayoutTimestamp = stats.estimatedPlayoutTimestamp;
196
+ this.jitterBufferDelay = stats.jitterBufferDelay;
197
+ this.jitterBufferTargetDelay = stats.jitterBufferTargetDelay;
198
+ this.jitterBufferEmittedCount = stats.jitterBufferEmittedCount;
199
+ this.jitterBufferMinimumDelay = stats.jitterBufferMinimumDelay;
200
+ this.totalSamplesReceived = stats.totalSamplesReceived;
201
+ this.concealedSamples = stats.concealedSamples;
202
+ this.silentConcealedSamples = stats.silentConcealedSamples;
203
+ this.concealmentEvents = stats.concealmentEvents;
204
+ }
205
+ }
@@ -0,0 +1,70 @@
1
+ import { CalculatedScore } from './scores/CalculatedScore';
2
+ import { MediaKind } from './common/types';
3
+ import { InboundTrackSample } from './schema/ClientSample';
4
+ import { Detectors } from './detectors/Detectors';
5
+ import { ObservedPeerConnection } from './ObservedPeerConnection';
6
+ import { ObservedInboundRtp } from './ObservedInboundRtp';
7
+ import { ObservedMediaPlayout } from './ObservedMediaPlayout';
8
+
9
+ export class ObservedInboundTrack implements InboundTrackSample {
10
+ public readonly detectors: Detectors;
11
+ public readonly calculatedScore: CalculatedScore = {
12
+ weight: 1,
13
+ value: undefined,
14
+ };
15
+ public appData?: Record<string, unknown>;
16
+
17
+ private _visited = false;
18
+
19
+ attachments?: Record<string, unknown> | undefined;
20
+
21
+ constructor(
22
+ public timestamp: number,
23
+ public readonly id: string,
24
+ public readonly kind: MediaKind,
25
+ private readonly _peerConnection: ObservedPeerConnection,
26
+ private readonly _inboundRtp?: ObservedInboundRtp,
27
+ private readonly _mediaPlayout?: ObservedMediaPlayout,
28
+ ) {
29
+ this.detectors = new Detectors();
30
+ }
31
+
32
+ public get score() {
33
+ return this.calculatedScore.value;
34
+ }
35
+
36
+ public get visited() {
37
+ const visited = this._visited;
38
+
39
+ this._visited = false;
40
+
41
+ return visited;
42
+ }
43
+
44
+ public getPeerConnection() {
45
+ return this._peerConnection;
46
+ }
47
+
48
+ public getInboundRtp() {
49
+ return this._inboundRtp;
50
+ }
51
+
52
+ public getMediaPlayout() {
53
+ return this._mediaPlayout;
54
+ }
55
+
56
+ public getRemoteOutboundTrack() {
57
+ return this._peerConnection.client.call.remoteTrackResolver?.resolveRemoteOutboundTrack(this);
58
+ }
59
+
60
+ public update(stats: InboundTrackSample): void {
61
+ this._visited = true;
62
+
63
+ this.timestamp = stats.timestamp;
64
+ this.calculatedScore.value = stats.score;
65
+ this.attachments = stats.attachments;
66
+
67
+ this.detectors.update();
68
+ }
69
+
70
+ }
@@ -0,0 +1,49 @@
1
+ import { MediaKind } from './common/types';
2
+ import { ObservedPeerConnection } from './ObservedPeerConnection';
3
+ import { MediaPlayoutStats } from './schema/ClientSample';
4
+
5
+ export class ObservedMediaPlayout implements MediaPlayoutStats {
6
+ private _visited = false;
7
+ public appData?: Record<string, unknown>;
8
+
9
+ synthesizedSamplesDuration?: number | undefined;
10
+ synthesizedSamplesEvents?: number | undefined;
11
+ totalSamplesDuration?: number | undefined;
12
+ totalPlayoutDelay?: number | undefined;
13
+ totalSamplesCount?: number | undefined;
14
+ attachments?: Record<string, unknown> | undefined;
15
+
16
+ public constructor(
17
+ public timestamp: number,
18
+ public id: string,
19
+ public kind: MediaKind,
20
+ private readonly _peerConnection: ObservedPeerConnection
21
+ ) {}
22
+
23
+ public get visited() {
24
+ const visited = this._visited;
25
+
26
+ this._visited = false;
27
+
28
+ return visited;
29
+ }
30
+
31
+ public getPeerConnection() {
32
+ return this._peerConnection;
33
+ }
34
+
35
+
36
+
37
+ public update(stats: MediaPlayoutStats) {
38
+ this._visited = true;
39
+
40
+ this.timestamp = stats.timestamp;
41
+ this.synthesizedSamplesDuration = stats.synthesizedSamplesDuration;
42
+ this.synthesizedSamplesEvents = stats.synthesizedSamplesEvents;
43
+ this.totalSamplesDuration = stats.totalSamplesDuration;
44
+ this.totalPlayoutDelay = stats.totalPlayoutDelay;
45
+ this.totalSamplesCount = stats.totalSamplesCount;
46
+ this.attachments = stats.attachments;
47
+
48
+ }
49
+ }
@@ -0,0 +1,60 @@
1
+ import { MediaKind } from './common/types';
2
+ import { ObservedPeerConnection } from './ObservedPeerConnection';
3
+ import { MediaSourceStats } from './schema/ClientSample';
4
+
5
+ export class ObservedMediaSource implements MediaSourceStats {
6
+ private _visited = false;
7
+ public appData?: Record<string, unknown>;
8
+
9
+ trackIdentifier?: string | undefined;
10
+ audioLevel?: number | undefined;
11
+ totalAudioEnergy?: number | undefined;
12
+ totalSamplesDuration?: number | undefined;
13
+ echoReturnLoss?: number | undefined;
14
+ echoReturnLossEnhancement?: number | undefined;
15
+ width?: number | undefined;
16
+ height?: number | undefined;
17
+ frames?: number | undefined;
18
+ framesPerSecond?: number | undefined;
19
+ attachments?: Record<string, unknown> | undefined;
20
+
21
+ public constructor(
22
+ public timestamp: number,
23
+ public id: string,
24
+ public kind: MediaKind,
25
+ private readonly _peerConnection: ObservedPeerConnection
26
+ ) {}
27
+
28
+ public get visited() {
29
+ const visited = this._visited;
30
+
31
+ this._visited = false;
32
+
33
+ return visited;
34
+ }
35
+
36
+ public getPeerConnection() {
37
+ return this._peerConnection;
38
+ }
39
+
40
+ public getTrack() {
41
+ return this._peerConnection.observedOutboundTracks.get(this.trackIdentifier ?? '');
42
+ }
43
+
44
+ public update(stats: MediaSourceStats) {
45
+ this._visited = true;
46
+
47
+ this.timestamp = stats.timestamp;
48
+ this.trackIdentifier = stats.trackIdentifier;
49
+ this.audioLevel = stats.audioLevel;
50
+ this.totalAudioEnergy = stats.totalAudioEnergy;
51
+ this.totalSamplesDuration = stats.totalSamplesDuration;
52
+ this.echoReturnLoss = stats.echoReturnLoss;
53
+ this.echoReturnLossEnhancement = stats.echoReturnLossEnhancement;
54
+ this.width = stats.width;
55
+ this.height = stats.height;
56
+ this.frames = stats.frames;
57
+ this.framesPerSecond = stats.framesPerSecond;
58
+ this.attachments = stats.attachments;
59
+ }
60
+ }
@@ -0,0 +1,156 @@
1
+ import { MediaKind } from './common/types';
2
+ import { ObservedPeerConnection } from './ObservedPeerConnection';
3
+ import { OutboundRtpStats, QualityLimitationDurations } from './schema/ClientSample';
4
+
5
+ export class ObservedOutboundRtp implements OutboundRtpStats {
6
+ private _visited = false;
7
+ public appData?: Record<string, unknown>;
8
+
9
+ transportId?: string | undefined;
10
+ codecId?: string | undefined;
11
+ packetsSent?: number | undefined;
12
+ bytesSent?: number | undefined;
13
+ mid?: string | undefined;
14
+ mediaSourceId?: string | undefined;
15
+ remoteId?: string | undefined;
16
+ rid?: string | undefined;
17
+ headerBytesSent?: number | undefined;
18
+ retransmittedPacketsSent?: number | undefined;
19
+ retransmittedBytesSent?: number | undefined;
20
+ rtxSsrc?: number | undefined;
21
+ targetBitrate?: number | undefined;
22
+ totalEncodedBytesTarget?: number | undefined;
23
+ frameWidth?: number | undefined;
24
+ frameHeight?: number | undefined;
25
+ framesPerSecond?: number | undefined;
26
+ framesSent?: number | undefined;
27
+ hugeFramesSent?: number | undefined;
28
+ framesEncoded?: number | undefined;
29
+ keyFramesEncoded?: number | undefined;
30
+ qpSum?: number | undefined;
31
+ totalEncodeTime?: number | undefined;
32
+ totalPacketSendDelay?: number | undefined;
33
+ qualityLimitationReason?: string | undefined;
34
+ qualityLimitationResolutionChanges?: number | undefined;
35
+ nackCount?: number | undefined;
36
+ firCount?: number | undefined;
37
+ pliCount?: number | undefined;
38
+ encoderImplementation?: string | undefined;
39
+ powerEfficientEncoder?: boolean | undefined;
40
+ active?: boolean | undefined;
41
+ scalabilityMode?: string | undefined;
42
+ qualityLimitationDurations?: QualityLimitationDurations | undefined;
43
+ attachments?: Record<string, unknown> | undefined;
44
+
45
+ // derived fields
46
+ public bitrate = 0;
47
+ public payloadBitrate = 0;
48
+ public packetRate = 0;
49
+ public bitPerPixel = 0;
50
+
51
+ public deltaPacketsSent = 0;
52
+ public deltaBytesSent = 0;
53
+
54
+ public constructor(
55
+ public timestamp: number,
56
+ public id: string,
57
+ public ssrc: number,
58
+ public kind: MediaKind,
59
+ private readonly _peerConnection: ObservedPeerConnection,
60
+ ) {
61
+ }
62
+
63
+ public get visited() {
64
+ const visited = this._visited;
65
+
66
+ this._visited = false;
67
+
68
+ return visited;
69
+ }
70
+
71
+ public getPeerConnection() {
72
+ return this._peerConnection;
73
+ }
74
+
75
+ public getRemoteInboundRtp() {
76
+ return this._peerConnection.observedRemoteInboundRtps.get(this.ssrc);
77
+ }
78
+
79
+ public getCodec() {
80
+ return this._peerConnection.observedCodecs.get(this.codecId ?? '');
81
+ }
82
+
83
+ public getMediaSource() {
84
+ return this._peerConnection.observedMediaSources.get(this.mediaSourceId ?? '');
85
+ }
86
+
87
+ public getTrack() {
88
+ return this.getMediaSource()?.getTrack();
89
+ }
90
+
91
+ public update(stats: OutboundRtpStats) {
92
+ this._visited = true;
93
+ this.bitPerPixel = 0;
94
+ this.bitrate = 0;
95
+ this.payloadBitrate = 0;
96
+ this.packetRate = 0;
97
+ this.deltaPacketsSent = 0;
98
+ this.deltaBytesSent = 0;
99
+
100
+ const elapsedTimeInMs = stats.timestamp - this.timestamp;
101
+
102
+ if (elapsedTimeInMs) {
103
+ if (stats.packetsSent !== undefined && this.packetsSent !== undefined) {
104
+ this.deltaPacketsSent = stats.packetsSent - this.packetsSent;
105
+ this.packetRate = this.deltaPacketsSent / (elapsedTimeInMs / 1000);
106
+ }
107
+ if (stats.bytesSent !== undefined && this.bytesSent !== undefined) {
108
+ this.deltaBytesSent = stats.bytesSent - this.bytesSent;
109
+ this.bitrate = (this.deltaBytesSent * 8) / (elapsedTimeInMs / 1000);
110
+ }
111
+ if (stats.headerBytesSent !== undefined && this.headerBytesSent !== undefined) {
112
+ this.payloadBitrate = ((this.deltaBytesSent ?? 0 - (stats.headerBytesSent - this.headerBytesSent)) * 8) / (elapsedTimeInMs / 1000);
113
+ }
114
+ if (this.framesSent !== undefined && stats.framesSent !== undefined) {
115
+ this.bitPerPixel = this.deltaBytesSent ? (this.deltaBytesSent * 8) / (this.framesSent - stats.framesSent) : 0;
116
+ }
117
+ }
118
+
119
+ this.timestamp = stats.timestamp;
120
+ this.transportId = stats.transportId;
121
+ this.codecId = stats.codecId;
122
+ this.packetsSent = stats.packetsSent;
123
+ this.bytesSent = stats.bytesSent;
124
+ this.mid = stats.mid;
125
+ this.mediaSourceId = stats.mediaSourceId;
126
+ this.remoteId = stats.remoteId;
127
+ this.rid = stats.rid;
128
+ this.headerBytesSent = stats.headerBytesSent;
129
+ this.retransmittedPacketsSent = stats.retransmittedPacketsSent;
130
+ this.retransmittedBytesSent = stats.retransmittedBytesSent;
131
+ this.rtxSsrc = stats.rtxSsrc;
132
+ this.targetBitrate = stats.targetBitrate;
133
+ this.totalEncodedBytesTarget = stats.totalEncodedBytesTarget;
134
+ this.frameWidth = stats.frameWidth;
135
+ this.frameHeight = stats.frameHeight;
136
+ this.framesPerSecond = stats.framesPerSecond;
137
+ this.framesSent = stats.framesSent;
138
+ this.hugeFramesSent = stats.hugeFramesSent;
139
+ this.framesEncoded = stats.framesEncoded;
140
+ this.keyFramesEncoded = stats.keyFramesEncoded;
141
+ this.qpSum = stats.qpSum;
142
+ this.totalEncodeTime = stats.totalEncodeTime;
143
+ this.totalPacketSendDelay = stats.totalPacketSendDelay;
144
+ this.qualityLimitationReason = stats.qualityLimitationReason;
145
+ this.qualityLimitationResolutionChanges = stats.qualityLimitationResolutionChanges;
146
+ this.nackCount = stats.nackCount;
147
+ this.firCount = stats.firCount;
148
+ this.pliCount = stats.pliCount;
149
+ this.encoderImplementation = stats.encoderImplementation;
150
+ this.powerEfficientEncoder = stats.powerEfficientEncoder;
151
+ this.active = stats.active;
152
+ this.scalabilityMode = stats.scalabilityMode;
153
+ this.qualityLimitationDurations = stats.qualityLimitationDurations;
154
+ this.attachments = stats.attachments;
155
+ }
156
+ }
@@ -0,0 +1,69 @@
1
+ import { CalculatedScore } from './scores/CalculatedScore';
2
+ import { MediaKind } from './common/types';
3
+ import { OutboundTrackSample } from './schema/ClientSample';
4
+ import { Detectors } from './detectors/Detectors';
5
+ import { ObservedPeerConnection } from './ObservedPeerConnection';
6
+ import { ObservedOutboundRtp } from './ObservedOutboundRtp';
7
+ import { ObservedMediaSource } from './ObservedMediaSource';
8
+
9
+ export class ObservedOutboundTrack implements OutboundTrackSample {
10
+ public readonly detectors: Detectors;
11
+ private _visited = false;
12
+ public appData?: Record<string, unknown>;
13
+ public readonly calculatedScore: CalculatedScore = {
14
+ weight: 1,
15
+ value: undefined,
16
+ };
17
+
18
+ attachments?: Record<string, unknown> | undefined;
19
+
20
+ constructor(
21
+ public timestamp: number,
22
+ public readonly id: string,
23
+ public readonly kind: MediaKind,
24
+ private readonly _peerConnection: ObservedPeerConnection,
25
+ private readonly _outboundRtps?: ObservedOutboundRtp[],
26
+ private readonly _mediaSource?: ObservedMediaSource,
27
+ ) {
28
+ this.detectors = new Detectors();
29
+ }
30
+
31
+ public get score() {
32
+ return this.calculatedScore.value;
33
+ }
34
+
35
+ public get visited() {
36
+ const visited = this._visited;
37
+
38
+ this._visited = false;
39
+
40
+ return visited;
41
+ }
42
+
43
+ public getPeerConnection() {
44
+ return this._peerConnection;
45
+ }
46
+
47
+ public getOutboundRtps() {
48
+ return this._outboundRtps;
49
+ }
50
+
51
+ public getMediaSource() {
52
+ return this._mediaSource;
53
+ }
54
+
55
+ public getRemoteInboundTracks() {
56
+ return this._peerConnection.client.call.remoteTrackResolver?.resolveRemoteInboundTracks(this);
57
+ }
58
+
59
+ public update(stats: OutboundTrackSample): void {
60
+ this._visited = true;
61
+
62
+ this.timestamp = stats.timestamp;
63
+ this.calculatedScore.value = stats.score;
64
+ this.attachments = stats.attachments;
65
+
66
+ this.detectors.update();
67
+ }
68
+
69
+ }