-
Notifications
You must be signed in to change notification settings - Fork 0
/
window.js
45 lines (36 loc) · 1016 Bytes
/
window.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
function onSelectChange(elm) {
loadCameraSrc(elm.value)
}
function loadCameraSrc(deviceId) {
const videoSettings = deviceId ? {
optional: [{ sourceId: deviceId }]
} : true;
navigator.mediaDevices
.getUserMedia({
video: videoSettings
})
.then(stream => {
const videoElm = document.getElementById('camera');
videoElm.onloadedmetadata = function() {
videoElm.play();
};
videoElm.srcObject = stream;
});
}
document.addEventListener('DOMContentLoaded', function() {
loadCameraSrc();
navigator.mediaDevices
.enumerateDevices({ video: true })
.then(items => {
return items.filter(item => item.kind === 'videoinput');
})
.then(devices => {
const dropdownElm = document.getElementById('cam-dropdown');
devices.forEach(item => {
const option = document.createElement('option');
option.text = item.label;
option.value = item.deviceId;
dropdownElm.add(option);
});
});
});