-
Notifications
You must be signed in to change notification settings - Fork 0
/
screenRecorder.js
72 lines (68 loc) · 1.79 KB
/
screenRecorder.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
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
let mediaRecorder;
let recordedBlobs;
const startRecording = () => {
// you can also record your shared screen using this function. just replace "stream" with "mediaStream" in next line inside the "if" condition
if (!stream) {
alert("No current feed");
return;
}
console.log("start recording");
recordedBlobs = []; // an array to hold the blobs for playback
// you can also record your shared screen using this function. just replace "stream" with "mediaStream" inside "MediaRecorder" in the next line
mediaRecorder = new MediaRecorder(stream); // make a media recorder form the constructor
mediaRecorder.ondataavailable = (e) => {
// ondataavailable will run when the stream ends, or stopped, or we specifically asked for it
console.log("data is available");
recordedBlobs.push(e.data);
};
mediaRecorder.start();
changeButtons([
"green",
"green",
"blue",
"blue",
"green",
"blue",
"grey",
"blue",
]);
};
const stopRecording = () => {
if (!mediaRecorder) {
alert("please record before stopping!");
return;
}
console.log("stop recording");
mediaRecorder.stop();
changeButtons([
"green",
"green",
"blue",
"blue",
"green",
"green",
"blue",
"blue",
]);
};
const playRecording = () => {
if (!recordedBlobs) {
alert("No recording saved!");
}
console.log("play recording");
const superBuffer = new Blob(recordedBlobs); //superBuffer is a super buffer of our array of blobs
const recordedVideoEl = document.querySelector("#other-video");
recordedVideoEl.src = window.URL.createObjectURL(superBuffer);
recordedVideoEl.controls = true;
recordedVideoEl.play();
changeButtons([
"green",
"green",
"blue",
"blue",
"green",
"green",
"green",
"blue",
]);
};