]> Repos - mime-chat/commitdiff
add main function for window
authorEnrique Hernandez <enrique.hernandez@fii-usa.com>
Thu, 4 Feb 2021 22:36:50 +0000 (16:36 -0600)
committerEnrique Hernandez <enrique.hernandez@fii-usa.com>
Thu, 4 Feb 2021 22:36:50 +0000 (16:36 -0600)
src/background/initApp.ts
src/background/main.ts [new file with mode: 0644]
src/background/recorder.ts

index e0ea2034ab81b0805a854b9822c3cbd5842e8b99..01910c5fb56ecd1c022e3b0be6d844c8941e3b6b 100644 (file)
@@ -26,8 +26,6 @@ function createWindow() {
   if (process.env.WEBPACK_DEV_SERVER_URL) {
     // Load the url of the dev server if in development mode
     win.loadURL(process.env.WEBPACK_DEV_SERVER_URL as string);
-    // NOTE uncomment for dev tools on app launch
-    if (!process.env.IS_TEST) win.webContents.openDevTools();
   } else {
     createProtocol("app");
     // Load the index.html when not in development
diff --git a/src/background/main.ts b/src/background/main.ts
new file mode 100644 (file)
index 0000000..b36af61
--- /dev/null
@@ -0,0 +1,39 @@
+import {Recorder} from './recorder';
+import { ipcMain } from "electron";
+/*
+ * this code will be run after window has finished loading
+ */
+export function main() {
+    // connect to crimata-platform ws server
+
+    // start recorder
+    const recorder = new Recorder({
+        channelCount: 1,
+        sampleFormat: 16,
+        sampleRate: 16000,
+        deviceId: -1,
+        closeOnError: false,
+    }, 'binary');
+
+    const updateRecorder = (Event: any, record: boolean) => {
+      if (record) {
+          console.log('recording')
+          recorder.resume();
+      } else {
+          console.log('stop recording')
+          recorder.pause();
+          const data = recorder.getData();
+          // TODO: send data()
+      }
+    }
+
+    const sendMessage = (Event: any, payload: any) => {
+
+    }
+
+    // event handlers
+    ipcMain.on('update-recorder', updateRecorder);
+    ipcMain.on('send-message', updateRecorder);
+    // send message
+
+}
index d1fd614b484272dbaeb7ffb505738c7986a6459c..cc4570a8f3c6cb48a7ad7ce34fd2d1f2731e4851 100644 (file)
@@ -57,18 +57,19 @@ export class Recorder implements RecorderI {
         defaultEncoding: encoding
     });
     try {
-        this.restart();
-        ipcMain.on('update-recorder', this._update);
+        this.start();
     } catch(e) {
         console.log('MEGA ERROR!');
     }
   }
 
-  restart() {
+  private start(): void {
     this.ia = new portAudio.AudioIO({
       inOptions: this.recorderOptions
     });
-    this._start();
+    this.ia.pipe(this.micWritable);
+    this.ia.start();
+    this.pause();
   }
 
   pause(): void {
@@ -80,40 +81,13 @@ export class Recorder implements RecorderI {
   }
 
   getData(): string {
-    return this.micWritable.data;
+    const data = this.micWritable.data;
+    this.micWritable.data = '';
+    return data;
   }
 
   stop(): string {
     this.ia.quit();
     return this.getData();
   }
-
-  private _start(): void {
-    this.ia.pipe(this.micWritable);
-    this.ia.start();
-    this.pause();
-  }
-
-  private _update = (Event: any, record: boolean) => {
-      if (record) {
-          // check for stream status
-          console.log('recording')
-          this.resume();
-          // this.ia.pipe(this.micWritable);
-      } else {
-          console.log('stop recording')
-          // unpipe
-          this.ia.unpipe(this.micWritable);
-
-          // stop stream
-          this.ia.quit();
-          this.ia = null;
-
-          // get stream data
-          this.micWritable.on('finish', () => {
-              console.log('finished writing data');
-          })
-          this.restart();
-      }
-  }
 }