]> Repos - mime-chat/commitdiff
add stream restart to recorder
authorEnrique Hernandez <enrique.hernandez@fii-usa.com>
Thu, 4 Feb 2021 19:15:04 +0000 (13:15 -0600)
committerEnrique Hernandez <enrique.hernandez@fii-usa.com>
Thu, 4 Feb 2021 19:15:04 +0000 (13:15 -0600)
src/background/recorder.ts

index d078585f745f4c9cfe362d0eb0896a386da3bbc3..d1fd614b484272dbaeb7ffb505738c7986a6459c 100644 (file)
@@ -12,11 +12,11 @@ interface RecorderI {
 }
 
 type inputOptions = {
-    channelCount: number,
-    sampleFormat: number,
-    sampleRate: number,
-    deviceId: number,
-    closeOnError: boolean
+    channelCount: number;
+    sampleFormat: number;
+    sampleRate: number;
+    deviceId: number;
+    closeOnError: boolean;
 }
 
 class StringWritable extends Writable {
@@ -55,9 +55,13 @@ export class Recorder implements RecorderI {
     this.recorderOptions = options;
     this.micWritable = new StringWritable({
         defaultEncoding: encoding
-    })
-    this.restart();
-    ipcMain.on('update-recorder', this._update);
+    });
+    try {
+        this.restart();
+        ipcMain.on('update-recorder', this._update);
+    } catch(e) {
+        console.log('MEGA ERROR!');
+    }
   }
 
   restart() {
@@ -94,23 +98,22 @@ export class Recorder implements RecorderI {
       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);
+          this.ia.unpipe(this.micWritable);
 
           // stop stream
-          // this.ia.quit();
-          // this.ia = null;
+          this.ia.quit();
+          this.ia = null;
 
           // get stream data
-          // this.micWritable.on('finish', () => {
-          //     console.log('finished writing data');
-          // })
-          // this.restart();
+          this.micWritable.on('finish', () => {
+              console.log('finished writing data');
+          })
+          this.restart();
       }
   }
 }