forked from mozilla/webrtc-landing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enumerate.html
47 lines (41 loc) · 1.32 KB
/
enumerate.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
<html>
<meta charset=utf-8>
<video id="video" height="120" autoplay></video><br>
<button id="gum_audio">Start Mic!</button>
<button id="gum_video">Start Cam!</button>
<button id="gum_both">Start Both!</button>
<button id="stopp">Stop!</button>
<button id="list">Enumerate Devices!</button>
<label><input type="checkbox" id="muted">Face-muted</label>
<div id="div"><br></div>
<script>
const log = msg => div.innerHTML += `${msg}<br>`;
let unstopped = [];
async function gum(constraints) {
try {
video.srcObject = await navigator.mediaDevices.getUserMedia(constraints);
unstopped.push(...video.srcObject.getTracks());
} catch (e) {
log(e);
}
}
gum_audio.onclick = () => gum({audio: true});
gum_video.onclick = () => gum({video: true});
gum_both.onclick = () => gum({video: true, audio: true});
stopp.onclick = () => {
unstopped.forEach(track => track.stop());
unstopped = [];
};
muted.onclick = () => {
video.srcObject.getTracks().forEach(track => track.enabled = !muted.checked);
};
list.onclick = async () => {
let devices = await navigator.mediaDevices.enumerateDevices();
log(devices.length + " devices.");
for (let {kind, label, deviceId, groupId} of devices) {
log(`${kind}: ${label} id=${deviceId} group=${groupId}`);
}
}
navigator.mediaDevices.ondevicechange = () => log("device change!");
</script>
</html>