-
Notifications
You must be signed in to change notification settings - Fork 343
/
filter.js
83 lines (73 loc) · 1.84 KB
/
filter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import {Transform} from 'stream';
/**
* Reforms the interesting data from an RTCStatsReport into something grokkable
*/
export default class StatsFilter extends Transform {
/**
* Tells the Stream we're operating in objectMode
* @private
*/
constructor() {
super({objectMode: true});
}
/**
* Filters out just the interesting part of a RTCStatsReport
* @param {RTCStatsReport} report
* @param {*} encoding
* @param {Function} callback
* @private
* @returns {undefined}
*/
_transform(report, encoding, callback) {
if (!report) {
callback();
return;
}
const incomingAudio = {
local: null,
remote: null
};
const incomingVideo = {
local: null,
remote: null
};
const outgoingAudio = {
local: null,
remote: null
};
const outgoingVideo = {
local: null,
remote: null
};
for (const item of report.values()) {
if (['outbound-rtp', 'outboundrtp'].includes(item.type) && !item.isRemote) {
if (item.mediaType === 'audio') {
outgoingAudio.local = item;
outgoingAudio.remote = report.get(item.remoteId);
}
if (item.mediaType === 'video') {
outgoingVideo.local = item;
outgoingVideo.remote = report.get(item.remoteId);
}
}
if (['inbound-rtp', 'inboundrtp'].includes(item.type) && !item.isRemote) {
if (item.mediaType === 'audio') {
incomingAudio.local = item;
incomingAudio.remote = report.get(item.remoteId);
}
if (item.mediaType === 'video') {
incomingVideo.local = item;
incomingVideo.remote = report.get(item.remoteId);
}
}
}
this.push({
incomingAudio,
incomingVideo,
outgoingAudio,
outgoingVideo,
report
});
callback();
}
}