-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
47 lines (40 loc) · 1.08 KB
/
main.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
38
39
40
41
42
43
44
45
46
const id = [
vid,
begshare,
endshare,
begrec,
endrec
] = [
"video",
"startScreenShare",
"stopScreenShare",
"startRecording",
"stopRecording",
].map(id => document.getElementById(id));
let stream, record;
begshare.addEventListener("click", async()=>{
stream = await navigator.mediaDevices.getDisplayMedia();
record = new MediaRecorder(stream);
video.srcObject = stream;
begrec.disabled=false;
endshare.disabled=false;
});
endshare.addEventListener("click", async()=>{
stream.getTracks().forEach(track => track.stop());
video.srcObject = null;
endshare.disabled=true;
begrec.disabled=true;
endrec.disabled=true;
});
begrec.addEventListener("click", async()=>{
let setnam = "screen-rec.webm",
handle = await window.showSaveFilePicker({ setnam });
writable = await handle.createWriteable();
record.start();
record.addEventListener("dataavailable", async (event) => {
await writable.write(event.data);
if (record.state == "inactive"){ await writable.close(); }
});
endrec.disabled=false;
});
endrec.addEventListener("click", ()=> { record.stop(); endrec.disabled=true; }