forked from QwenLM/Qwen2-VL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
74 lines (73 loc) · 2.4 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
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
// main.js
if (!ScreenCastRecorder.isSupportedBrowser()) {
console.error("Screen Recording not supported in this browser");
}
let recorder;
let outputBlob;
const stopRecording = () => __awaiter(void 0, void 0, void 0, function* () {
let currentState = "RECORDING";
// We should do nothing if the user try to stop recording when it is not started
if (currentState === "OFF" || recorder == null) {
return;
}
// if (currentState === "COUNTDOWN") {
// this.setState({
// currentState: "OFF",
// })
// }
if (currentState === "RECORDING") {
if (recorder.getState() === "inactive") {
// this.setState({
// currentState: "OFF",
// })
console.log("Inactive");
}
else {
outputBlob = yield recorder.stop();
console.log("Done recording");
// this.setState({
// outputBlob,
// currentState: "PREVIEW_FILE",
// })
window.currentState = "PREVIEW_FILE";
const videoSource = URL.createObjectURL(outputBlob);
window.videoSource = videoSource;
const fileName = "recording";
const link = document.createElement("a");
link.setAttribute("href", videoSource);
link.setAttribute("download", `${fileName}.webm`);
link.click();
}
}
});
const startRecording = () => __awaiter(void 0, void 0, void 0, function* () {
const recordAudio = true;
recorder = new ScreenCastRecorder({
recordAudio,
onErrorOrStop: () => stopRecording(),
});
try {
yield recorder.initialize();
}
catch (e) {
console.warn(`ScreenCastRecorder.initialize error: ${e}`);
// this.setState({ currentState: "UNSUPPORTED" })
window.currentState = "UNSUPPORTED";
return;
}
// this.setState({ currentState: "COUNTDOWN" })
const hasStarted = recorder.start();
if (hasStarted) {
// this.setState({
// currentState: "RECORDING",
// })
console.log("Started recording");
window.currentState = "RECORDING";
}
else {
stopRecording().catch(err => console.warn(`withScreencast.stopRecording threw an error: ${err}`));
}
});
// Set global functions to window.
window.startRecording = startRecording;
window.stopRecording = stopRecording;