privateuserh commited on
Commit
eb315e4
·
verified ·
1 Parent(s): d6fb0af

Update scripts/video.js

Browse files
Files changed (1) hide show
  1. 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
- try {
6
- // Use the Media Devices API to request screen access from the user.
7
- // This will cause the browser to show a "Share your screen" permission pop-up.
8
- const stream = await navigator.mediaDevices.getDisplayMedia({
9
- video: {
10
- mediaSource: "screen"
11
- }
12
- });
 
 
13
 
14
- // For now, we will just log that we got permission.
15
- // In a real app, you would use this 'stream' object to record a video.
16
- console.log("Screen access granted!", stream);
17
- alert("Screen access granted! Recording has started (in theory).");
18
-
19
- } catch (error) {
20
- // This will run if the user clicks "Cancel" on the permission pop-up.
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
  }