File tree 1 file changed +8
-4
lines changed
1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change 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 = {
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 ) => {
You can’t perform that action at this time.
0 commit comments