Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	Update static/script.js
Browse files- static/script.js +25 -27
    	
        static/script.js
    CHANGED
    
    | @@ -12,42 +12,40 @@ $(document).ready(function () { | |
| 12 | 
             
                    $("#banner2").hide(1000);
         | 
| 13 | 
             
                });
         | 
| 14 | 
             
            });
         | 
| 15 | 
            -
             | 
| 16 | 
            -
            // Function to start the camera and display the feed in the video element
         | 
| 17 | 
             
            function startCamera() {
         | 
| 18 | 
            -
                const  | 
| 19 | 
            -
             | 
| 20 | 
            -
                if  | 
| 21 | 
            -
             | 
| 22 | 
            -
                     | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 23 | 
             
                }
         | 
| 24 | 
            -
             | 
| 25 | 
            -
                navigator.mediaDevices.getUserMedia({ video: true })
         | 
| 26 | 
            -
                    .then(function (stream) {
         | 
| 27 | 
            -
                        videoElement.srcObject = stream;
         | 
| 28 | 
            -
                    })
         | 
| 29 | 
            -
                    .catch(function (error) {
         | 
| 30 | 
            -
                        console.error('Error accessing the camera: ', error);
         | 
| 31 | 
            -
                    });
         | 
| 32 | 
             
            }
         | 
| 33 |  | 
| 34 | 
             
            // Function to stop the camera
         | 
| 35 | 
             
            function stopCamera() {
         | 
| 36 | 
            -
                const  | 
| 37 | 
            -
                
         | 
| 38 | 
            -
                if (!videoElement || !videoElement.srcObject) {
         | 
| 39 | 
            -
                    console.error('Video element or video source object is null');
         | 
| 40 | 
            -
                    return;
         | 
| 41 | 
            -
                }
         | 
| 42 |  | 
| 43 | 
            -
                 | 
| 44 | 
            -
                 | 
|  | |
|  | |
| 45 |  | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 |  | 
| 50 | 
            -
             | 
|  | |
| 51 | 
             
            }
         | 
| 52 |  | 
| 53 |  | 
|  | |
| 12 | 
             
                    $("#banner2").hide(1000);
         | 
| 13 | 
             
                });
         | 
| 14 | 
             
            });
         | 
| 15 | 
            +
            // Function to start the camera capture
         | 
|  | |
| 16 | 
             
            function startCamera() {
         | 
| 17 | 
            +
                const videoFeedElement = document.getElementById('video_feed');
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                // Check if the browser supports getUserMedia
         | 
| 20 | 
            +
                if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
         | 
| 21 | 
            +
                    navigator.mediaDevices.getUserMedia({ video: true })
         | 
| 22 | 
            +
                        .then(function (stream) {
         | 
| 23 | 
            +
                            // Set the video stream as the source for the image tag
         | 
| 24 | 
            +
                            videoFeedElement.srcObject = stream;
         | 
| 25 | 
            +
                        })
         | 
| 26 | 
            +
                        .catch(function (error) {
         | 
| 27 | 
            +
                            console.error('Error accessing the camera: ', error);
         | 
| 28 | 
            +
                        });
         | 
| 29 | 
            +
                } else {
         | 
| 30 | 
            +
                    console.error('getUserMedia is not supported by this browser');
         | 
| 31 | 
             
                }
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 32 | 
             
            }
         | 
| 33 |  | 
| 34 | 
             
            // Function to stop the camera
         | 
| 35 | 
             
            function stopCamera() {
         | 
| 36 | 
            +
                const videoFeedElement = document.getElementById('video_feed');
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
| 37 |  | 
| 38 | 
            +
                // Stop the video stream by setting source object to null
         | 
| 39 | 
            +
                if (videoFeedElement.srcObject) {
         | 
| 40 | 
            +
                    const stream = videoFeedElement.srcObject;
         | 
| 41 | 
            +
                    const tracks = stream.getTracks();
         | 
| 42 |  | 
| 43 | 
            +
                    tracks.forEach(function (track) {
         | 
| 44 | 
            +
                        track.stop();
         | 
| 45 | 
            +
                    });
         | 
| 46 |  | 
| 47 | 
            +
                    videoFeedElement.srcObject = null;
         | 
| 48 | 
            +
                }
         | 
| 49 | 
             
            }
         | 
| 50 |  | 
| 51 |  | 
