Spaces:
Sleeping
Sleeping
Update static/script.js
Browse files- static/script.js +36 -5
static/script.js
CHANGED
|
@@ -13,14 +13,45 @@ $(document).ready(function () {
|
|
| 13 |
});
|
| 14 |
});
|
| 15 |
|
|
|
|
| 16 |
function startCamera() {
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
}
|
| 23 |
|
|
|
|
| 24 |
function startVideo() {
|
| 25 |
var url = $('#url').val();
|
| 26 |
$('#urlForm').attr('action', '/index');
|
|
|
|
| 13 |
});
|
| 14 |
});
|
| 15 |
|
| 16 |
+
// Function to start the camera
|
| 17 |
function startCamera() {
|
| 18 |
+
// Get the video element by its ID
|
| 19 |
+
const videoElement = document.getElementById('videoElement');
|
| 20 |
+
|
| 21 |
+
// Check if user's browser supports media devices and getUserMedia
|
| 22 |
+
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
|
| 23 |
+
// Request access to the camera
|
| 24 |
+
navigator.mediaDevices.getUserMedia({ video: true })
|
| 25 |
+
.then(function (stream) {
|
| 26 |
+
videoElement.srcObject = stream;
|
| 27 |
+
})
|
| 28 |
+
.catch(function (error) {
|
| 29 |
+
console.error('Error accessing the camera: ', error);
|
| 30 |
+
});
|
| 31 |
+
} else {
|
| 32 |
+
alert('getUserMedia is not supported by this browser.');
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
// Function to stop the camera
|
| 37 |
+
function stopCamera() {
|
| 38 |
+
// Get the video element by its ID
|
| 39 |
+
const videoElement = document.getElementById('videoElement');
|
| 40 |
+
|
| 41 |
+
// Stop the camera stream
|
| 42 |
+
if (videoElement.srcObject) {
|
| 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');
|