@pexip/peer-connection-stats 17.2.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.
@@ -0,0 +1,233 @@
1
+ import type {Signal} from '@pexip/signal';
2
+
3
+ export interface RTCStats {
4
+ id: string;
5
+ type: string;
6
+
7
+ kind?: 'audio' | 'video';
8
+ timestamp?: number;
9
+
10
+ [key: string]: unknown;
11
+ }
12
+
13
+ export interface Remote extends RTCStats {
14
+ type: 'remote-inbound-rtp';
15
+
16
+ jitter?: number;
17
+
18
+ packetsLost?: number;
19
+ roundTripTime?: number;
20
+
21
+ codec?: Codec;
22
+ // local:
23
+ transport?: Transport;
24
+ }
25
+
26
+ export interface CandidatePair extends RTCStats {
27
+ type: 'candidate-pair';
28
+
29
+ availableIncomingBitrate?: number;
30
+ availableOutgoingBitrate?: number;
31
+ currentRoundTripTime?: number;
32
+
33
+ transport?: Transport;
34
+ localCandidate?: CandidatePair;
35
+ remoteCandidate?: CandidatePair;
36
+ }
37
+
38
+ export interface Transport extends RTCStats {
39
+ type: 'transport';
40
+
41
+ // localCertificate:
42
+ // remoteCertificate:
43
+ selectedCandidatePair?: CandidatePair;
44
+ }
45
+
46
+ export interface Codec extends RTCStats {
47
+ type: 'codec';
48
+
49
+ mimeType?: string;
50
+ }
51
+
52
+ export interface InboundAudio extends RTCStats {
53
+ type: 'inbound-rtp';
54
+ kind: 'audio';
55
+
56
+ jitter?: number;
57
+
58
+ packetsReceived?: number;
59
+ packetsLost?: number;
60
+
61
+ bytesReceived?: number;
62
+
63
+ track?: Track;
64
+ transport?: Transport;
65
+ codec?: Codec;
66
+ }
67
+
68
+ export interface OutboundAudio extends RTCStats {
69
+ type: 'outbound-rtp';
70
+ kind: 'audio';
71
+
72
+ packetsSent?: number;
73
+ bytesSent?: number;
74
+
75
+ remote?: Remote;
76
+ transport?: Transport;
77
+ codec?: Codec;
78
+ }
79
+
80
+ export interface InboundVideo extends RTCStats {
81
+ type: 'inbound-rtp';
82
+ kind: 'video';
83
+
84
+ packetsReceived?: number;
85
+ packetsLost?: number;
86
+
87
+ bytesReceived?: number;
88
+
89
+ transport?: Transport;
90
+ codec?: Codec;
91
+
92
+ frameWidth?: number;
93
+ frameHeight?: number;
94
+ framesPerSecond?: number;
95
+
96
+ // typically firefox has these, but chrome does not:
97
+ bitrateMean?: number;
98
+ framerateMean?: number;
99
+ }
100
+
101
+ export interface OutboundVideo extends RTCStats {
102
+ type: 'outbound-rtp';
103
+ kind: 'video';
104
+
105
+ packetsSent?: number;
106
+ packetsLost?: number;
107
+
108
+ bytesSent?: number;
109
+
110
+ totalPacketSendDelay?: number;
111
+
112
+ frameWidth?: number;
113
+ frameHeight?: number;
114
+ framesPerSecond?: number;
115
+
116
+ codec?: Codec;
117
+ mediaSource?: MediaSource;
118
+ remote?: Remote;
119
+ track?: Track;
120
+ transport?: Transport;
121
+
122
+ // typically firefox has these, but chrome does not:
123
+ bitrateMean?: number;
124
+ framerateMean?: number;
125
+ }
126
+
127
+ export interface MediaSource extends RTCStats {
128
+ type: 'media-source';
129
+ kind: 'audio' | 'video';
130
+ }
131
+
132
+ export interface Track extends RTCStats {
133
+ type: 'track';
134
+ kind: 'audio' | 'video';
135
+
136
+ mediaSource?: MediaSource;
137
+ }
138
+
139
+ export interface Stream extends RTCStats {
140
+ type: 'stream';
141
+
142
+ tracks?: Track[];
143
+ }
144
+
145
+ export type AnyStats =
146
+ | CandidatePair
147
+ | Codec
148
+ | InboundAudio
149
+ | InboundVideo
150
+ | OutboundAudio
151
+ | OutboundVideo
152
+ | RTCStats
153
+ | Remote
154
+ | Stream
155
+ | Track
156
+ | Transport;
157
+
158
+ export interface Metrics {
159
+ type: 'inbound-rtp' | 'outbound-rtp';
160
+ kind: 'audio' | 'video';
161
+ bitrate?: number;
162
+ bytesTransmitted?: number;
163
+ codec?: string;
164
+ jitter?: number;
165
+ packetsLost: number;
166
+ packetsTransmitted: number;
167
+ recentPercentageLost?: number;
168
+ roundTripTime?: number;
169
+ timestamp?: number;
170
+ totalPercentageLost?: number;
171
+ }
172
+
173
+ export interface VideoMetrics extends Metrics {
174
+ framesPerSecond?: number;
175
+ resolution?: string;
176
+ resolutionHeight?: number;
177
+ resolutionWidth?: number;
178
+ }
179
+
180
+ export type InboundAudioMetrics = Metrics;
181
+ export type InboundVideoMetrics = VideoMetrics;
182
+ export type OutboundAudioMetrics = Metrics;
183
+ export type OutboundVideoMetrics = VideoMetrics & {
184
+ totalPacketSendDelay?: number;
185
+ averagePacketSendDelay?: number;
186
+ };
187
+
188
+ export type NormalizedRTCStats =
189
+ | InboundAudioMetrics
190
+ | InboundVideoMetrics
191
+ | OutboundAudioMetrics
192
+ | OutboundVideoMetrics;
193
+
194
+ export type PacketsStats = Array<[number, number]>; //packet loss, total packets
195
+ export type AudioQualityStats = Array<[number, number]>; //tuple with packet loss and jitter
196
+ export type VideoQualityStats = number[]; //packet loss
197
+
198
+ export type CallQualityStats = AudioQualityStats | VideoQualityStats;
199
+ export type CallPacketsStats = PacketsStats;
200
+
201
+ export interface CacheStats {
202
+ previous?: NormalizedRTCStats;
203
+ callPacketsStats: CallPacketsStats;
204
+ callQuality: Quality;
205
+ callQualityStats: CallQualityStats;
206
+ }
207
+
208
+ export enum Quality {
209
+ GOOD = 0,
210
+ OK = 1,
211
+ BAD = 2,
212
+ TERRIBLE = 3,
213
+ }
214
+
215
+ export interface StatsSignals {
216
+ onRtcStats: Signal<NormalizedRTCStats>;
217
+ onCallQuality: Signal<Quality>;
218
+ onCallQualityStats: Signal<CallQualityStats>;
219
+ }
220
+ export interface StatsCollectorOptions {
221
+ input: {
222
+ getStats: (
223
+ selector?: MediaStreamTrack | null,
224
+ ) => Promise<RTCStatsReport>;
225
+ };
226
+ signals: StatsSignals;
227
+ interval?: number;
228
+ }
229
+
230
+ export interface StatsCollector {
231
+ resetStats: () => () => void;
232
+ cleanup: () => void;
233
+ }
@@ -0,0 +1,208 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`StatsCollector addDeltaStats should calculate bitrate based on "previous" arg 1`] = `
4
+ {
5
+ "averagePacketSendDelay": 0.0401950221238938,
6
+ "bitrate": 1796157,
7
+ "bytesTransmitted": 9643326,
8
+ "codec": "video/VP9",
9
+ "framesPerSecond": 30,
10
+ "kind": "video",
11
+ "packetsLost": 0,
12
+ "packetsTransmitted": 9040,
13
+ "recentPercentageLost": 0,
14
+ "resolution": "1280x720",
15
+ "resolutionHeight": 720,
16
+ "resolutionWidth": 1280,
17
+ "roundTripTime": 0.032,
18
+ "timestamp": 1607629939687.857,
19
+ "totalPacketSendDelay": 363.363,
20
+ "totalPercentageLost": 0,
21
+ "type": "outbound-rtp",
22
+ }
23
+ `;
24
+
25
+ exports[`StatsCollector addDeltaStats should calculate bitrate based on "previous" arg for audio and video 1`] = `
26
+ {
27
+ "bitrate": 54669,
28
+ "bytesTransmitted": 315194,
29
+ "codec": "audio/opus",
30
+ "jitter": 0,
31
+ "kind": "audio",
32
+ "packetsLost": 0,
33
+ "packetsTransmitted": 2276,
34
+ "recentPercentageLost": 0,
35
+ "roundTripTime": 0.033,
36
+ "timestamp": 1607629939687.857,
37
+ "totalPercentageLost": 0,
38
+ "type": "inbound-rtp",
39
+ }
40
+ `;
41
+
42
+ exports[`StatsCollector addDeltaStats should calculate bitrate when no "previous" arg 1`] = `
43
+ {
44
+ "averagePacketSendDelay": 0.04034671151838534,
45
+ "bitrate": undefined,
46
+ "bytesTransmitted": 9194231,
47
+ "codec": "video/VP9",
48
+ "framesPerSecond": 31,
49
+ "kind": "video",
50
+ "packetsLost": 0,
51
+ "packetsTransmitted": 8621,
52
+ "recentPercentageLost": 0,
53
+ "resolution": "1280x720",
54
+ "resolutionHeight": 720,
55
+ "resolutionWidth": 1280,
56
+ "roundTripTime": 0.032,
57
+ "timestamp": 1607629937687.609,
58
+ "totalPacketSendDelay": 347.829,
59
+ "totalPercentageLost": 0,
60
+ "type": "outbound-rtp",
61
+ }
62
+ `;
63
+
64
+ exports[`StatsCollector createResolver should work for data with only string values 1`] = `
65
+ {
66
+ "id": "123",
67
+ "kind": "audio",
68
+ "type": "inbound-rtp",
69
+ }
70
+ `;
71
+
72
+ exports[`StatsCollector createResolver should work for flat data with strings & numbers 1`] = `
73
+ {
74
+ "id": "123",
75
+ "kind": "audio",
76
+ "packetsLost": 0,
77
+ "type": "inbound-rtp",
78
+ }
79
+ `;
80
+
81
+ exports[`StatsCollector createResolver should work for nested data 1`] = `
82
+ {
83
+ "codec": {
84
+ "id": "codec1",
85
+ "type": "codec",
86
+ },
87
+ "codecId": "codec1",
88
+ "id": "abc",
89
+ "kind": "audio",
90
+ "packetsLost": 0,
91
+ "type": "inbound-rtp",
92
+ }
93
+ `;
94
+
95
+ exports[`StatsCollector inboundAudio should return valid data for all fields 1`] = `
96
+ {
97
+ "bytesTransmitted": 60771,
98
+ "codec": "audio/opus",
99
+ "jitter": 0.001,
100
+ "kind": "audio",
101
+ "packetsLost": 0,
102
+ "packetsTransmitted": 456,
103
+ "roundTripTime": 0.038,
104
+ "timestamp": 1604007431820.096,
105
+ "totalPercentageLost": 0,
106
+ "type": "inbound-rtp",
107
+ }
108
+ `;
109
+
110
+ exports[`StatsCollector inboundVideo should work 1`] = `
111
+ {
112
+ "bitrate": undefined,
113
+ "bytesTransmitted": 1430276,
114
+ "codec": "video/VP9",
115
+ "framesPerSecond": 30,
116
+ "kind": "video",
117
+ "packetsLost": 0,
118
+ "packetsTransmitted": 1268,
119
+ "resolution": "1280x720",
120
+ "resolutionHeight": 720,
121
+ "resolutionWidth": 1280,
122
+ "roundTripTime": 0.039,
123
+ "timestamp": 1604007431820.096,
124
+ "totalPercentageLost": 0,
125
+ "type": "inbound-rtp",
126
+ }
127
+ `;
128
+
129
+ exports[`StatsCollector outboundAudio should work 1`] = `
130
+ {
131
+ "bytesTransmitted": 16689,
132
+ "codec": "audio/opus",
133
+ "jitter": 0.0028541666666666667,
134
+ "kind": "audio",
135
+ "packetsLost": 0,
136
+ "packetsTransmitted": 458,
137
+ "roundTripTime": 0.033,
138
+ "timestamp": 1604007411171.868,
139
+ "totalPercentageLost": 0,
140
+ "type": "outbound-rtp",
141
+ }
142
+ `;
143
+
144
+ exports[`StatsCollector outboundVideo should work 1`] = `
145
+ {
146
+ "averagePacketSendDelay": 0.057633950617283956,
147
+ "bitrate": undefined,
148
+ "bytesTransmitted": 1701105,
149
+ "codec": "video/VP9",
150
+ "framesPerSecond": 29,
151
+ "kind": "video",
152
+ "packetsLost": 0,
153
+ "packetsTransmitted": 1620,
154
+ "resolution": "1280x720",
155
+ "resolutionHeight": 720,
156
+ "resolutionWidth": 1280,
157
+ "roundTripTime": 0.033,
158
+ "timestamp": 1604007411171.868,
159
+ "totalPacketSendDelay": 93.367,
160
+ "totalPercentageLost": 0,
161
+ "type": "outbound-rtp",
162
+ }
163
+ `;
164
+
165
+ exports[`StatsCollector statsFrom should return complete data for chromeInboundStats 1`] = `
166
+ {
167
+ "bytesTransmitted": 60771,
168
+ "codec": "audio/opus",
169
+ "jitter": 0.001,
170
+ "kind": "audio",
171
+ "packetsLost": 0,
172
+ "packetsTransmitted": 456,
173
+ "roundTripTime": 0.038,
174
+ "timestamp": 1604007431820.096,
175
+ "totalPercentageLost": 0,
176
+ "type": "inbound-rtp",
177
+ }
178
+ `;
179
+
180
+ exports[`StatsCollector statsFrom should return complete data for chromeOutboundStats 1`] = `
181
+ {
182
+ "bytesTransmitted": 16689,
183
+ "codec": "audio/opus",
184
+ "jitter": 0.0028541666666666667,
185
+ "kind": "audio",
186
+ "packetsLost": 0,
187
+ "packetsTransmitted": 458,
188
+ "roundTripTime": 0.033,
189
+ "timestamp": 1604007411171.868,
190
+ "totalPercentageLost": 0,
191
+ "type": "outbound-rtp",
192
+ }
193
+ `;
194
+
195
+ exports[`StatsCollector statsFrom should return complete data for firefoxStats 1`] = `
196
+ {
197
+ "bytesTransmitted": 371213,
198
+ "codec": undefined,
199
+ "jitter": 0,
200
+ "kind": "audio",
201
+ "packetsLost": 0,
202
+ "packetsTransmitted": 2563,
203
+ "roundTripTime": undefined,
204
+ "timestamp": 1607359512687,
205
+ "totalPercentageLost": 0,
206
+ "type": "inbound-rtp",
207
+ }
208
+ `;