Spaces:
Running
Running
// scripts/video.js | |
async function startRecording() { | |
// First, check if the browser supports the getDisplayMedia API at all. | |
if (navigator.mediaDevices && navigator.mediaDevices.getDisplayMedia) { | |
// If it exists, try to use it. | |
try { | |
const stream = await navigator.mediaDevices.getDisplayMedia({ | |
video: true | |
}); | |
// If the user gives permission, this code will run. | |
alert("Screen access granted! Recording can now begin."); | |
// (The actual logic to handle the video stream would go here) | |
} catch (error) { | |
// This will run if the user denies permission. | |
alert(`Screen recording was cancelled or denied. Error: ${error.message}`); | |
} | |
} else { | |
// If the API doesn't exist, inform the user gracefully. | |
alert("Sorry, your browser or current viewing environment does not support screen recording."); | |
} | |
} | |
export function initVideo() { | |
const startBtn = document.getElementById('start-recording'); | |
if (startBtn) { | |
startBtn.addEventListener('click', startRecording); | |
} | |
} |