From: Enrique Hernandez Date: Thu, 4 Feb 2021 19:15:04 +0000 (-0600) Subject: add stream restart to recorder X-Git-Tag: v0.9~104 X-Git-Url: https://andrewgundersen.net/repos?a=commitdiff_plain;h=a534964b968203156a9d81e1bf5aa184bfb3409f;p=mime-chat add stream restart to recorder --- diff --git a/src/background/recorder.ts b/src/background/recorder.ts index d078585..d1fd614 100644 --- a/src/background/recorder.ts +++ b/src/background/recorder.ts @@ -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(); } } }