From ccb6f2c8b05952cf9f82cd277fde031e8a0524a2 Mon Sep 17 00:00:00 2001 From: Kendall Garner <17521368+kgarner7@users.noreply.github.com> Date: Sat, 24 Aug 2024 20:36:04 -0700 Subject: [PATCH] very niche error handling for no audio device id but still have error checking --- .../components/audio-player/index.tsx | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/renderer/components/audio-player/index.tsx b/src/renderer/components/audio-player/index.tsx index 7f022f2e..56949f95 100644 --- a/src/renderer/components/audio-player/index.tsx +++ b/src/renderer/components/audio-player/index.tsx @@ -265,18 +265,22 @@ export const AudioPlayer = forwardRef( // Not standard, just used in chromium-based browsers. See // https://developer.chrome.com/blog/audiocontext-setsinkid/. // If the isElectron() check is every removed, fix this. - if (isElectron() && webAudio && 'setSinkId' in webAudio.context) { - try { - if (audioDeviceId !== 'default') { - // @ts-ignore - webAudio.context.setSinkId(audioDeviceId); - } else { - // @ts-ignore - webAudio.context.setSinkId(''); + if (isElectron() && webAudio && 'setSinkId' in webAudio.context && audioDeviceId) { + const setSink = async () => { + try { + if (audioDeviceId !== 'default') { + // @ts-ignore + await webAudio.context.setSinkId(audioDeviceId); + } else { + // @ts-ignore + await webAudio.context.setSinkId(''); + } + } catch (error) { + toast.error({ message: `Error setting sink: ${(error as Error).message}` }); } - } catch (error) { - toast.error({ message: `Error setting sink: ${(error as Error).message}` }); - } + }; + + setSink(); } }, [audioDeviceId, webAudio]);