-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
38 lines (28 loc) · 977 Bytes
/
script.js
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
34
35
36
37
const videoElement = document.getElementById('video');
const openButton = document.getElementById('open-button');
const startButton = document.getElementById('start-button');
//Prompt to select media stream, pass to video element, then play
const selectMediaStream = async () => {
try{
const mediaStream = await navigator.mediaDevices.getDisplayMedia();
videoElement.srcObject = mediaStream;
videoElement.onloadedmetadata = () => {
videoElement.play();
}
}catch(err) {
console.log("Something went wrong", err)
}
}
startButton.addEventListener('click', async () => {
//Disable Button when on click
startButton.disabled = true;
await videoElement.requestPictureInPicture();
//Reset the button
startButton.disabled = true;
});
openButton.addEventListener('click', () => {
openButton.disabled = true;
selectMediaStream()
//Reset the button
openButton.disabled = true;
})