-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecorder.js
More file actions
34 lines (28 loc) · 913 Bytes
/
recorder.js
File metadata and controls
34 lines (28 loc) · 913 Bytes
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
export function createCanvasRecorder(canvas) {
const stream = canvas.captureStream(30);
const recorder = new MediaRecorder(stream, { mimeType: "video/webm" });
const chunks = [];
let recording = false;
recorder.ondataavailable = e => {
if(e.data.size > 0) {
chunks.push(e.data);
}
};
recorder.onstart = () => {
recording = true;
console.log('Recording Started');
}
recorder.onstop = () => {
if(recording) {
console.log('Recording Stopped');
const blob = new Blob(chunks, { type: 'video/webm' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'recording.webm';
a.click();
recording = false;
}
}
return recorder
}