forked from steveseguin/vdo.ninja
-
Notifications
You must be signed in to change notification settings - Fork 0
/
supports.html
244 lines (226 loc) · 7.39 KB
/
supports.html
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
<html>
<head>
<link rel="stylesheet" href="./lineawesome/css/line-awesome.min.css" />
<link rel="stylesheet" href="./main.css?ver=11" />
<link rel="stylesheet" href="./supports.css?ver=1" />
<meta charset="utf8" />
</head>
<body id="supports">
<div id="header">
<a
id="logoname"
href="./"
style="text-decoration: none; color: white; margin: 2px"
>
<span data-translate="logo-header"> <font id="qos">V</font>DO.Ninja </span>
</a>
</div>
<div class="card">
<h1 id="browserSupportedOptionsTitle">💻 Browser supported options</h1>
<p style="margin-bottom: 20px">
List of options your browser reports as supported. If an option lights up
green, your currently selected camera reports that it supports that option.
</p>
<div id="browserSupportedOptions"></div>
</div>
<div class="card">
<h1>Device to check</h1>
<select id="cameraSelector" onchange="changeCamera()"></select>
</div>
<div class="card">
<h1 id="cameraSupportedOptionsTitle">📹 Camera supported options</h1>
<div id="cameraSupportedOptions"></div>
</div>
<div class="card">
<h1>📹 Camera settings</h1>
<div id="cameraSettings"></div>
</div>
<script>
function getChromeVersion() {
var raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
return raw ? parseInt(raw[2], 10) : false;
}
function safariVersion() {
try {
var ver = navigator.appVersion.split("Version/");
if (ver.length > 1) {
ver = ver[1].split(" Safari");
}
if (ver.length > 1) {
ver = ver[0].split(".");
}
if (ver.length > 1) {
ver = parseInt(ver[0]);
} else {
ver = 0;
}
} catch (e) {
return 0;
}
return ver;
}
if (!((safariVersion() && safariVersion()>=15) || (getChromeVersion() || getChromeVersion >=60))){
alert("This tool really only works with recent Chromium based browsers; Firefox is not supported: "+ safariVersion());
}
function prettyPrintJsonToId(json, element) {
var output = "<div class='prettyJson three-col'>";
Object.entries(json)
.sort()
.forEach(([key, value]) => {
if (value == true) {
value = "<i class='las la-check'></i>";
}
if (value == false) {
value = "<i class='las la-times'></i>";
}
output += "<div class='property' id=" + key + ">";
output += "<span>" + key + "</span><span>" + value + "</span>";
output += "</div>";
});
output += "</div>";
document.getElementById(element).innerHTML = output;
}
function prettyPrintSupportedOptions(json, element) {
long_ass_strings = [json.deviceId, json.groupId];
var output = "<div class='prettyJson two-col'>";
var nestedObjs;
delete json.deviceId;
delete json.groupId;
Object.entries(json)
.sort()
.forEach(([key, value]) => {
output += "<div class='supportedOption'>";
nestedObjs = "";
if (typeof value === "object" && value !== null) {
Object.entries(value)
.sort()
.forEach(([key, value]) => {
nestedObjs +=
"<div class='subproperty'><span>" +
key +
"</span><span>" +
value +
"</span></div>";
});
output += "<span>" + key + "</span><span>" + nestedObjs + "</span>";
} else {
output += "<span>" + key + "</span><span>" + value + "</span>";
}
output += "</div>";
});
output += "</div>";
output += "<div id='longCameraSupportedStrings'><span>IDs</span>";
output += "<span>deviceId: " + long_ass_strings[0] + "</span>";
output += "<span>groupId: " + long_ass_strings[1] + "</span></div>";
document.getElementById(element).innerHTML = output;
}
function changeCamera() {
var deviceId = document.getElementById("cameraSelector").value;
getCameraDetails(deviceId);
}
function getCameraDetails(deviceId) {
console.log(deviceId);
navigator.mediaDevices
.getUserMedia({
video: {
deviceId: {exact: deviceId},
zoom: true,
pan: true,
tilt: true
},
audio: false,
})
.then(function (mediaStream) {
console.log("worked");
setTimeout(function () {
mediaStream.getVideoTracks().forEach((track) => {
try{
const capabilities = track.getCapabilities();
const settings = track.getSettings();
prettyPrintSupportedOptions(capabilities, "cameraSupportedOptions");
document
.querySelectorAll(".property")
.forEach((el) => el.classList.remove("ok"));
Object.entries(capabilities)
.sort()
.forEach(([key, value]) => {
document.getElementById(key).classList.add("ok");
});
prettyPrintJsonToId(settings, "cameraSettings");
} catch (e){
document
.querySelectorAll(".property")
.forEach((el) => el.classList.remove("ok"));
}
});
}, 1000);
}).catch(function(e){
setTimeout(function(){getCameraDetailsFallback(deviceId)},0);
})
}
function getCameraDetailsFallback(deviceId) {
console.log(deviceId);
navigator.mediaDevices
.getUserMedia({
video: {
deviceId: deviceId
},
audio: false,
})
.then(function (mediaStream) {
console.log("worked");
setTimeout(function () {
mediaStream.getVideoTracks().forEach((track) => {
try{
const capabilities = track.getCapabilities();
const settings = track.getSettings();
prettyPrintSupportedOptions(capabilities, "cameraSupportedOptions");
document
.querySelectorAll(".property")
.forEach((el) => el.classList.remove("ok"));
Object.entries(capabilities)
.sort()
.forEach(([key, value]) => {
document.getElementById(key).classList.add("ok");
});
prettyPrintJsonToId(settings, "cameraSettings");
} catch (e){
document
.querySelectorAll(".property")
.forEach((el) => el.classList.remove("ok"));
}
});
}, 1000);
//updateDeviceList();
});
}
var supports = navigator.mediaDevices.getSupportedConstraints();
prettyPrintJsonToId(supports, "browserSupportedOptions");
document.getElementById("browserSupportedOptionsTitle").innerText +=
" (" + Object.keys(supports).length + ")";
function updateDeviceList(){
navigator.mediaDevices
.enumerateDevices()
.then(function (devices) {
setTimeout(function (devices) {
console.log("Listing devices");
devices.forEach(function (device) {
if (device.kind == "videoinput") {
var element = document.createElement("option");
element.setAttribute("value", device.deviceId);
element.innerText = device.label || "No Label Available";
document.getElementById("cameraSelector").appendChild(element);
console.log(device);
}
});
setTimeout(function(){changeCamera();},10);
}, 1000, devices);
})
.catch(function (err) {
console.log(err.name + ": " + err.message);
});
}
updateDeviceList();
</script>
</body>
</html>