forked from steveseguin/vdo.ninja
-
Notifications
You must be signed in to change notification settings - Fork 0
/
supports.html
159 lines (149 loc) · 4.97 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
<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">O</font>BS.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 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) {
navigator.mediaDevices
.getUserMedia({
video: {
deviceId: deviceId,
},
audio: false,
})
.then(function (mediaStream) {
console.log("worked");
setTimeout(function () {
mediaStream.getVideoTracks().forEach((track) => {
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");
});
}, 1000);
});
}
var supports = navigator.mediaDevices.getSupportedConstraints();
prettyPrintJsonToId(supports, "browserSupportedOptions");
document.getElementById("browserSupportedOptionsTitle").innerText +=
" (" + Object.keys(supports).length + ")";
navigator.mediaDevices
.enumerateDevices()
.then(function (devices) {
setTimeout(function () {
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;
document.getElementById("cameraSelector").appendChild(element);
console.log(device);
}
});
getCameraDetails(devices[0]);
}, 1000);
})
.catch(function (err) {
console.log(err.name + ": " + err.message);
});
</script>
</body>
</html>