very niche error handling for no audio device id but still have error checking

This commit is contained in:
Kendall Garner 2024-08-24 20:36:04 -07:00
parent a44071fedd
commit ccb6f2c8b0
No known key found for this signature in database
GPG Key ID: 18D2767419676C87

View File

@ -265,18 +265,22 @@ export const AudioPlayer = forwardRef(
// Not standard, just used in chromium-based browsers. See // Not standard, just used in chromium-based browsers. See
// https://developer.chrome.com/blog/audiocontext-setsinkid/. // https://developer.chrome.com/blog/audiocontext-setsinkid/.
// If the isElectron() check is every removed, fix this. // If the isElectron() check is every removed, fix this.
if (isElectron() && webAudio && 'setSinkId' in webAudio.context) { if (isElectron() && webAudio && 'setSinkId' in webAudio.context && audioDeviceId) {
const setSink = async () => {
try { try {
if (audioDeviceId !== 'default') { if (audioDeviceId !== 'default') {
// @ts-ignore // @ts-ignore
webAudio.context.setSinkId(audioDeviceId); await webAudio.context.setSinkId(audioDeviceId);
} else { } else {
// @ts-ignore // @ts-ignore
webAudio.context.setSinkId(''); await webAudio.context.setSinkId('');
} }
} catch (error) { } catch (error) {
toast.error({ message: `Error setting sink: ${(error as Error).message}` }); toast.error({ message: `Error setting sink: ${(error as Error).message}` });
} }
};
setSink();
} }
}, [audioDeviceId, webAudio]); }, [audioDeviceId, webAudio]);