Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	Update static/script.js
Browse files- static/script.js +20 -8
    	
        static/script.js
    CHANGED
    
    | @@ -12,10 +12,16 @@ $(document).ready(function () { | |
| 12 | 
             
                    $("#banner2").hide(1000);
         | 
| 13 | 
             
                });
         | 
| 14 | 
             
            });
         | 
|  | |
| 15 | 
             
            // Function to start the camera and display the feed in the video element
         | 
| 16 | 
             
            function startCamera() {
         | 
| 17 | 
             
                const videoElement = document.getElementById('feed_video');
         | 
| 18 |  | 
|  | |
|  | |
|  | |
|  | |
|  | |
| 19 | 
             
                navigator.mediaDevices.getUserMedia({ video: true })
         | 
| 20 | 
             
                    .then(function (stream) {
         | 
| 21 | 
             
                        videoElement.srcObject = stream;
         | 
| @@ -28,18 +34,24 @@ function startCamera() { | |
| 28 | 
             
            // Function to stop the camera
         | 
| 29 | 
             
            function stopCamera() {
         | 
| 30 | 
             
                const videoElement = document.getElementById('feed_video');
         | 
| 31 | 
            -
                 | 
| 32 | 
            -
             | 
| 33 | 
            -
                     | 
|  | |
|  | |
| 34 |  | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
                    });
         | 
| 38 |  | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
|  | |
|  | |
|  | |
| 41 | 
             
            }
         | 
| 42 |  | 
|  | |
|  | |
| 43 | 
             
            function startVideo() {
         | 
| 44 | 
             
                var url = $('#url').val();
         | 
| 45 | 
             
                $('#urlForm').attr('action', '/index'); 
         | 
|  | |
| 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 videoElement = document.getElementById('feed_video');
         | 
| 19 |  | 
| 20 | 
            +
                if (!videoElement) {
         | 
| 21 | 
            +
                    console.error('Video element with ID "feed_video" not found');
         | 
| 22 | 
            +
                    return;
         | 
| 23 | 
            +
                }
         | 
| 24 | 
            +
             | 
| 25 | 
             
                navigator.mediaDevices.getUserMedia({ video: true })
         | 
| 26 | 
             
                    .then(function (stream) {
         | 
| 27 | 
             
                        videoElement.srcObject = stream;
         | 
|  | |
| 34 | 
             
            // Function to stop the camera
         | 
| 35 | 
             
            function stopCamera() {
         | 
| 36 | 
             
                const videoElement = document.getElementById('feed_video');
         | 
| 37 | 
            +
                
         | 
| 38 | 
            +
                if (!videoElement || !videoElement.srcObject) {
         | 
| 39 | 
            +
                    console.error('Video element or video source object is null');
         | 
| 40 | 
            +
                    return;
         | 
| 41 | 
            +
                }
         | 
| 42 |  | 
| 43 | 
            +
                const stream = videoElement.srcObject;
         | 
| 44 | 
            +
                const tracks = stream.getTracks();
         | 
|  | |
| 45 |  | 
| 46 | 
            +
                tracks.forEach(function (track) {
         | 
| 47 | 
            +
                    track.stop();
         | 
| 48 | 
            +
                });
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                videoElement.srcObject = null;
         | 
| 51 | 
             
            }
         | 
| 52 |  | 
| 53 | 
            +
             | 
| 54 | 
            +
             | 
| 55 | 
             
            function startVideo() {
         | 
| 56 | 
             
                var url = $('#url').val();
         | 
| 57 | 
             
                $('#urlForm').attr('action', '/index'); 
         | 
