-
Notifications
You must be signed in to change notification settings - Fork 44
/
features-client.js
244 lines (222 loc) · 9.39 KB
/
features-client.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
'use strict';
// https://en.wikipedia.org/wiki/Feature_extraction for peerconnection
// API traces and getStats data.
// there are two types of features
// 1) features which only take the client as argument. E.g. extracting the browser version
// 2) features which take the client and a connection argument. Those do something with the connection.
// 3) features which are specific to a track.
// The first type of feature is contained in this file.
const platform = require('platform');
const {timeBetween} = require('./utils');
module.exports = {
origin: function(client) {
return client.origin;
},
browser: function(client) {
if (!(client.userAgent && client.userAgent.length)) return;
const ua = platform.parse(client.userAgent);
const parts = {
name: ua.name || 'unknown',
version: ua.version || '-1',
os: ua.os.toString(),
userAgent: client.userAgent,
nameVersion: ua.name + '/' + ua.version,
nameOs: ua.name + '/' + ua.os.toString(),
nameVersionOs: ua.name + '/' + ua.version + '/' + ua.os.toString()
};
if (ua.version) {
parts.majorVersion = ua.version.split('.')[0];
}
return parts;
},
// did the page call getUserMedia at all?
calledGetUserMedia: function(client) {
return client.getUserMedia && client.getUserMedia.length > 0;
},
// did the page use the old getUserMedia?
calledLegacyGetUserMedia: function(client) {
const gum = client.getUserMedia || [];
for (let i = 0; i < gum.length; i++) {
if (gum[i].type === 'getUserMedia') return true;
}
return false;
},
// did the page use the new navigator.mediaDevices.getUserMedia?
calledMediadevicesGetUserMedia: function(client) {
const gum = client.getUserMedia || [];
for (let i = 0; i < gum.length; i++) {
if (gum[i].type === 'navigator.mediaDevices.getUserMedia') return true;
}
return false;
},
// TODO: was enumerateDevices used? rtcstats does not hook this and I do not think
// that tracing every call would be useful but enumerating hardware once might
// be nice for features like numberOfMicrophones, numberOfCameras, ...
// was there at least one getUserMedia success?
getUserMediaSuccess: function(client) {
const gum = client.getUserMedia || [];
for (let i = 0; i < gum.length; i++) {
if (gum[i].type === 'navigator.mediaDevices.getUserMediaOnSuccess' || gum[i].type === 'getUserMediaOnSuccess') {
return true;
}
}
return false;
},
// was there at least one getUserMedia error? If so, what was the error?
getUserMediaError: function(client) {
const gum = client.getUserMedia || [];
for (let i = 0; i < gum.length; i++) {
if (gum[i].type === 'navigator.mediaDevices.getUserMediaOnFailure' || gum[i].type === 'getUserMediaOnFailure') {
return gum[i].value;
}
}
},
// did the client ever request audio?
calledGetUserMediaRequestingAudio: function(client) {
const gum = client.getUserMedia || [];
let requested = false;
for (let i = 0; i < gum.length; i++) {
if (gum[i].type === 'navigator.mediaDevices.getUserMedia' || gum[i].type === 'getUserMedia') {
const options = gum[i].value;
if (options.audio && options.audio !== false) requested = true;
}
}
return requested;
},
// did the client ever request video (not screenshare)?
// screensharing is defined as
// mozMediaSource || mediaSource in FF (look for window || screen?)
// mandatory.chromeMediaSource: desktop in chrome
calledGetUserMediaRequestingVideo: function(client) {
const gum = client.getUserMedia || [];
let requested = false;
for (let i = 0; i < gum.length; i++) {
if (gum[i].type === 'navigator.mediaDevices.getUserMedia' || gum[i].type === 'getUserMedia') {
const options = gum[i].value;
if (options.video === true) {
requested = true;
break;
}
if (options.video && typeof options.video === 'object') {
if (!(options.video.mozMediaSource || options.video.mediaSource || options.video.chromeMediaSource)) {
requested = true;
break;
}
}
}
}
return requested;
},
// did the client ever request the screen?
// also returns the type even though (in chrome) that is not relevant.
calledGetUserMediaRequestingScreen: function(client) {
const gum = client.getUserMedia || [];
for (let i = 0; i < gum.length; i++) {
if (gum[i].type === 'navigator.mediaDevices.getUserMedia' || gum[i].type === 'getUserMedia') {
const options = gum[i].value;
if (options.video && typeof options.video === 'object') {
// Firefox
if (options.video.mozMediaSource || options.video.mediaSource) {
return options.video.mozMediaSource || options.video.mediaSource;
}
// Chrome
if (options.video.mandatory && options.video.mandatory.chromeMediaSource) {
return options.video.mandatory.chromeMediaSource;
}
}
}
if (gum[i].type === 'navigator.getDisplayMedia' || gum[i].type === 'navigator.mediaDevices.getDisplayMedia') {
const {value} = gum[i];
return value && value.video === true;
}
}
return false;
},
calledGetUserMediaRequestingAEC3: function(client) {
const gum = client.getUserMedia || [];
let requested = false;
for (let i = 0; i < gum.length; i++) {
if (gum[i].type === 'navigator.mediaDevices.getUserMedia' || gum[i].type === 'getUserMedia') {
const options = gum[i].value;
if (options.audio && options.audio.echoCancellationType === 'aec3') requested = true;
}
}
return requested;
},
timeBetweenGetUserMediaAndGetUserMediaSuccess: function(client) {
return timeBetween(
client.getUserMedia || [],
['navigator.mediaDevices.getUserMedia', 'getUserMedia'],
['navigator.mediaDevices.getUserMediaOnSuccess', 'getUserMediaOnSuccess']
);
},
timeBetweenGetUserMediaAndGetUserMediaFailure: function(client) {
return timeBetween(
client.getUserMedia || [],
['navigator.mediaDevices.getUserMedia', 'getUserMedia'],
['navigator.mediaDevices.getUserMediaOnFailure', 'getUserMediaOnFailure']
);
},
// return the label of the first audio device
firstAudioTrackLabel: function(client) {
const gum = client.getUserMedia || [];
for (let i = 0; i < gum.length; i++) {
if (gum[i].type === 'navigator.mediaDevices.getUserMediaOnSuccess' || gum[i].type === 'getUserMediaOnSuccess') {
const stream = gum[i].value;
const tracks = stream && stream.tracks || [];
for (let j = 0; j < tracks.length; j++) {
if (tracks[j].kind === 'audio') {
return tracks[j].label;
}
}
}
}
},
// return the label of the first video device
firstVideoTrackLabel: function(client) {
const gum = client.getUserMedia || [];
for (let i = 0; i < gum.length; i++) {
if (gum[i].type === 'navigator.mediaDevices.getUserMediaOnSuccess' || gum[i].type === 'getUserMediaOnSuccess') {
const stream = gum[i].value;
const tracks = stream && stream.tracks || [];
for (let j = 0; j < tracks.length; j++) {
if (tracks[j].kind === 'video') {
return tracks[j].label;
}
}
}
}
},
// TODO: gum statistics (audio, video, number of tracks, errors, fail-to-acquire aka ended readyState)
// TODO: resolution, framerate
// TODO: special goog constraints?
// TODO: feature for "were the promise-ified apis used or the legacy variants?"
// number of peerConnections created
numberOfPeerConnections: function(client) {
return Object.keys(client.peerConnections).length;
},
userfeedback: function(client) {
if (!client.feedback) return;
const feature = {};
feature[client.feedback.mediaType] = client.feedback.score;
return feature;
},
tags: function(client) {
return client.tags;
},
websocketConnectionTime: function(client) {
return client.websocketConnectionTime;
},
websocketError: function(client) {
return client.websocketError;
},
// which public address was used - taken from rtcstats websocket.
// can be a list of proxies from the x-forwarded-for header,
// take the last one.
publicIPAddress: function(client) {
return client.publicIP[client.publicIP.length - 1];
},
usesHTTPProxy: function(client) {
return client.publicIP.length > 1;
}
};