|
|
| 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";
|
|
|
| if (currentState === "OFF" || recorder == null) {
|
| return;
|
| }
|
|
|
|
|
|
|
|
|
|
|
| if (currentState === "RECORDING") {
|
| if (recorder.getState() === "inactive") {
|
|
|
|
|
|
|
| console.log("Inactive");
|
| }
|
| else {
|
| outputBlob = yield recorder.stop();
|
| console.log("Done recording");
|
|
|
|
|
|
|
|
|
| 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 = false;
|
| recorder = new ScreenCastRecorder({
|
| recordAudio,
|
| onErrorOrStop: () => stopRecording(),
|
| });
|
| try {
|
| yield recorder.initialize();
|
| }
|
| catch (e) {
|
| console.warn(`ScreenCastRecorder.initialize error: ${e}`);
|
|
|
| window.currentState = "UNSUPPORTED";
|
| return;
|
| }
|
|
|
| const hasStarted = recorder.start();
|
| if (hasStarted) {
|
|
|
|
|
|
|
| console.log("Started recording");
|
| window.currentState = "RECORDING";
|
| }
|
| else {
|
| stopRecording().catch(err => console.warn(`withScreencast.stopRecording threw an error: ${err}`));
|
| }
|
| });
|
|
|
|
|
| window.startRecording = startRecording;
|
| window.stopRecording = stopRecording; |