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
--- /dev/null
+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
+
+}
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 {
}
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();
- }
- }
}