From: riqo Date: Mon, 26 Apr 2021 12:22:38 +0000 (-0500) Subject: fix audio stream shutdown X-Git-Tag: v0.9.9^2~1 X-Git-Url: https://andrewgundersen.net/repos?a=commitdiff_plain;h=7c2f3cad8cfcecdb98cdb2d6e5e6fb3bae5f0de6;p=mime-chat fix audio stream shutdown --- diff --git a/src/background/audio.ts b/src/background/audio.ts index 6dd3bdd..0a98206 100644 --- a/src/background/audio.ts +++ b/src/background/audio.ts @@ -40,7 +40,7 @@ const onRecordingEnd = async (_event: any, payload: any) => { try { resolve(audioContainer.input); - record = false; + record = false; } catch (e) { reject() } @@ -120,7 +120,7 @@ export function play(input: string): void { // Format the audio. const audio = bufSplit( - Buffer.from(input as string, 'hex'), + Buffer.from(input as string, 'hex'), 8192 ); @@ -165,15 +165,24 @@ export function play(input: string): void { // ------------------------------------------------------------- // Get's called on window close. -// export function stopStream() { -// console.log("AUDIO:Stopping audio stream.") -// if (ai) { -// ai.quit() -// } -// if (ao) { -// ao.quit() -// } -// console.log("AUDIO:Audio closed.") -// } +export async function stopStream() { + console.log("AUDIO:Stopping audio stream.") + if (ai) { + try { + await ai.quit() + } catch(e){ + console.log('AUDIO: Failed to shutdown audio input.'); + throw e; + } + } + if (ao) { + try { + await ao.quit() + } catch(e){ + console.log('AUDIO: Failed to shutdown audio output.'); + throw e; + } + } +} diff --git a/src/background/init.ts b/src/background/init.ts index 715228a..a17716c 100644 --- a/src/background/init.ts +++ b/src/background/init.ts @@ -4,7 +4,7 @@ import { app, dialog } from "electron"; import { createWindow } from './window'; import { initSession } from './session'; -import { initAudioIO } from './audio'; +import { initAudioIO, stopStream } from './audio'; import { backgroundMitt } from '@/modules/emitter'; let win: boolean; @@ -63,7 +63,8 @@ export function initApp(dev: boolean): void { }); // Must keep to ensure app doesn't quit on close. - app.on("before-quit", () => { + app.on("before-quit", async () => { + await stopStream(); }); // Must keep to ensure app doesn't quit on close.