Skip to content

Commit e7512fc

Browse files
authored
ow switch button if more than one camera
1 parent e4975a9 commit e7512fc

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

haiku.html

+8-4
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@
9999
let currentStream;
100100
let currentCamera = "front";
101101

102+
// Show switch button if more than one camera
103+
navigator.mediaDevices.enumerateDevices().then(devices => {
104+
const cameras = devices.filter(device => device.kind === 'videoinput');
105+
if (cameras.length > 1) {
106+
switchCameraBtn.style.display = "block";
107+
}
108+
});
109+
102110
// Request access to the webcam
103111
function startCamera() {
104112
const constraints = {
@@ -110,10 +118,6 @@
110118
.getUserMedia(constraints)
111119
.then((stream) => {
112120
currentStream = stream;
113-
// Show switchCameraBtn if multiple cameras are available
114-
if (currentStream.getTracks().length > 1) {
115-
switchCameraBtn.style.display = "block";
116-
}
117121
video.srcObject = stream;
118122
})
119123
.catch((error) => {

0 commit comments

Comments
 (0)