]> Repos - mime-chat/commitdiff
fix audio stream shutdown
authorriqo <hernandeze2@xavier.edu>
Mon, 26 Apr 2021 12:22:38 +0000 (07:22 -0500)
committerriqo <hernandeze2@xavier.edu>
Mon, 26 Apr 2021 12:22:38 +0000 (07:22 -0500)
src/background/audio.ts
src/background/init.ts

index 6dd3bdd443608edb616f5c9b7f09462c93cd81ed..0a98206086013a9eb2c7e98e498b81c55e234040 100644 (file)
@@ -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;
+        }
+    }
+}
 
 
index 715228a15840f7eb9ef55d8c1767db8739b1ecb2..a17716c75f1e1ebbe63be414e5adaa3447bd3a42 100644 (file)
@@ -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.