CoolFace
Apppublic

PoweRO/RBC

sourceHugging Facemitupdated 2y agoView on Hugging Face
0likes
record_button.js41 linesDownload Raw Back to report
1// Setup if needed and start recording.
2async () => {
3  // Set up recording functions if not already initialized
4  if (!window.startRecording) {
5      let recorder_js = null;
6      let main_js = null;
7  }
8
9  // Function to fetch and convert video blob to base64 using async/await without explicit Promise
10  async function getVideoBlobAsBase64(objectURL) {
11      const response = await fetch(objectURL);
12      if (!response.ok) {
13        throw new Error('Failed to fetch video blob.');
14      }
15
16      const blob = await response.blob();
17
18      const reader = new FileReader();
19      reader.readAsDataURL(blob);
20
21      return new Promise((resolve, reject) => {
22        reader.onloadend = () => {
23          if (reader.result) {
24            resolve(reader.result.split(',')[1]); // Return the base64 string (without data URI prefix)
25          } else {
26            reject('Failed to convert blob to base64.');
27          }
28        };
29      });
30  }
31
32  if (window.currentState === "RECORDING") {
33      await window.stopRecording();
34      const base64String = await getVideoBlobAsBase64(window.videoSource);
35      return base64String;
36  } else {
37      window.startRecording();
38      return "Record";
39  }
40}
41