File size: 1,229 Bytes
b27cb15
 
d6fb0af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b27cb15
 
d6fb0af
693b035
d6fb0af
 
693b035
b27cb15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// scripts/video.js

// This function will contain the logic for the video recording feature.
async function startRecording() {
    try {
        // Use the Media Devices API to request screen access from the user.
        // This will cause the browser to show a "Share your screen" permission pop-up.
        const stream = await navigator.mediaDevices.getDisplayMedia({
            video: {
                mediaSource: "screen"
            }
        });

        // For now, we will just log that we got permission.
        // In a real app, you would use this 'stream' object to record a video.
        console.log("Screen access granted!", stream);
        alert("Screen access granted! Recording has started (in theory).");

    } catch (error) {
        // This will run if the user clicks "Cancel" on the permission pop-up.
        console.error("Error starting screen recording:", error);
        alert(`Could not start recording. Error: ${error.message}`);
    }
}


export function initVideo() {
    const startBtn = document.getElementById('start-recording');
    if (startBtn) {
        // We replace the old alert with a call to our new function.
        startBtn.addEventListener('click', startRecording);
    }
}