-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecordScreen.js
More file actions
83 lines (80 loc) · 1.99 KB
/
recordScreen.js
File metadata and controls
83 lines (80 loc) · 1.99 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
document.addEventListener("keydown", handleKeyDown);
let recorder;
let framerate;
let start = 0;
let widthR;
let heightR;
async function handleKeyDown(e){
if(e.key == 's' || e.key == 'S'){
start = 1;
}
if(start == 1){
if(e.key == 'd' || e.key == 'D'){
framerate = 30;
widthR = 1280;
heightR = 720;
start = 3;
}
else if(e.key == 'v' || e.key == 'V') {
framerate = 10;
start = 2;
}
else if(e.key == 'l' || e.key == 'L'){
framerate = 20;
start = 2;
}
else if(e.key == 'm' || e.key == 'M'){
framerate = 30;
start = 2;
}
else if(e.key == 'h' || e.key == 'H'){
framerate = 40;
start = 2;
}
}
else if(start == 2){
if(e.key == 'v' || e.key == 'V') {
widthR = 640;
heightR = 360;
start = 3;
}
else if(e.key == 'l' || e.key == 'L'){
widthR = 853;
heightR = 480;
start = 3;
}
else if(e.key == 'm' || e.key == 'M'){
widthR = 1280;
heightR = 720;
start = 3;
}
else if(e.key == 'h' || e.key == 'H'){
widthR = 1920;
heightR = 1080;
start = 3;
}
else if(e.key == 'b' || e.key == 'B'){
widthR = 3840;
heightR = 2160;
start = 3;
}
}
if(start == 3){
let stream = await navigator.mediaDevices.getDisplayMedia({
video: {frameRate: framerate, width: widthR, height: heightR},
audio: true,
});
recorder = new MediaRecorder(stream);
recorder.start();
recorder.ondataavailable = e => {
var aElem = window.document.createElement('a');
aElem.href = window.URL.createObjectURL(e.data);
aElem.download = 'screen';
document.body.appendChild(aElem);
aElem.click();
document.body.removeChild(aElem);
start = 0;
framerate = 30;
}
}
}