add stream restart to recorder

This commit is contained in:
Enrique Hernandez 2021-02-04 13:15:04 -06:00
commit a534964b96

View 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();
}
}
}