Spaces:
Running
Running
Update scripts/video.js
Browse files- scripts/video.js +17 -20
scripts/video.js
CHANGED
@@ -1,33 +1,30 @@
|
|
1 |
// scripts/video.js
|
2 |
|
3 |
-
// This function will contain the logic for the video recording feature.
|
4 |
async function startRecording() {
|
5 |
-
|
6 |
-
|
7 |
-
//
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
}
|
12 |
-
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
console.error("Error starting screen recording:", error);
|
22 |
-
alert(`Could not start recording. Error: ${error.message}`);
|
23 |
}
|
24 |
}
|
25 |
|
26 |
-
|
27 |
export function initVideo() {
|
28 |
const startBtn = document.getElementById('start-recording');
|
29 |
if (startBtn) {
|
30 |
-
// We replace the old alert with a call to our new function.
|
31 |
startBtn.addEventListener('click', startRecording);
|
32 |
}
|
33 |
}
|
|
|
1 |
// scripts/video.js
|
2 |
|
|
|
3 |
async function startRecording() {
|
4 |
+
// First, check if the browser supports the getDisplayMedia API at all.
|
5 |
+
if (navigator.mediaDevices && navigator.mediaDevices.getDisplayMedia) {
|
6 |
+
// If it exists, try to use it.
|
7 |
+
try {
|
8 |
+
const stream = await navigator.mediaDevices.getDisplayMedia({
|
9 |
+
video: true
|
10 |
+
});
|
11 |
+
// If the user gives permission, this code will run.
|
12 |
+
alert("Screen access granted! Recording can now begin.");
|
13 |
+
// (The actual logic to handle the video stream would go here)
|
14 |
|
15 |
+
} catch (error) {
|
16 |
+
// This will run if the user denies permission.
|
17 |
+
alert(`Screen recording was cancelled or denied. Error: ${error.message}`);
|
18 |
+
}
|
19 |
+
} else {
|
20 |
+
// If the API doesn't exist, inform the user gracefully.
|
21 |
+
alert("Sorry, your browser or current viewing environment does not support screen recording.");
|
|
|
|
|
22 |
}
|
23 |
}
|
24 |
|
|
|
25 |
export function initVideo() {
|
26 |
const startBtn = document.getElementById('start-recording');
|
27 |
if (startBtn) {
|
|
|
28 |
startBtn.addEventListener('click', startRecording);
|
29 |
}
|
30 |
}
|