forked from electron/electron-quick-start
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
83 lines (65 loc) · 1.67 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<style>
video {
border: 1px solid red;
width: 100px;
}
</style>
<script>
function setDevices() {
let els = document.getElementsByTagName('video');
for (let i = 0; i < els.length; ++i) {
let camera = els[i];
let srcObject = camera.srcObject;
if (srcObject) {
if (srcObject) {
let audio = srcObject.getAudioTracks();
let video = srcObject.getVideoTracks();
if (audio[0]) {
srcObject.removeTrack(audio[0]);
}
if (video[0]) {
srcObject.removeTrack(video[0]);
}
srcObject = null;
camera.srcObject = null;
}
}
}
//setTimeout(() => {
document.body.innerHTML = "";
navigator.mediaDevices.enumerateDevices().then((devices, i) => {
console.log(devices);
let cams = devices.filter(device => device.kind === 'videoinput');
let len = cams.length;
for (let i = 0; i < len; ++i) {
let device = cams[i];
console.log(device.kind, device.label, device.deviceId);
navigator.mediaDevices.getUserMedia({
video: { deviceId: { exact: device.deviceId } }
}).then(stream => {
console.log(device.deviceId, String(i))
let el = document.createElement('video')
el.autoplay = true;
el.src = window.URL.createObjectURL(stream.clone());
console.log(el.src)
el.onload = () => {
console.log("load")
el.play();
}
document.body.appendChild(el);
}).catch(e => console.error(e));
}
}).catch(e => console.error(e));
//}, 2000);
}
navigator.mediaDevices.ondevicechange = setDevices;
setDevices();
</script>
</body>
</html>