-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera.js
44 lines (35 loc) · 1.2 KB
/
camera.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
function getDevices(deviceInfos) {
let devices = []
for (let i = 0; i !== deviceInfos.length; ++i) {
const deviceInfo = deviceInfos[i];
if (deviceInfo.kind == 'videoinput') {
devices.push({
label: deviceInfo.label,
id: deviceInfo.deviceId
});
}
}
console.log(devices);
let supportedConstraints = navigator.mediaDevices.getSupportedConstraints();
console.log(supportedConstraints);
return devices
}
function selectDevice(devices) {
capture = createCapture(VIDEO);
capture.hide();
for (let device of devices) {
var result = confirm(`カメラ"${device.label}(${device.id})"を使いますか?\n(使わない場合、別のカメラを使うかこの後聞きます)`);
if (!result) continue
var constraints = {
video: {
deviceId: {
exact: device.id
},
}
};
capture = createCapture(constraints);
return capture
}
alert("カメラが見つかりませんでした。リロードしてださい。");
throw new Error("カメラが見つかりませんでした。")
}