add error checking for set sink id (case of no devices at all)

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

View file

@ -266,12 +266,16 @@ export const AudioPlayer = forwardRef(
// 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) {
if (audioDeviceId !== 'default') { try {
// @ts-ignore if (audioDeviceId !== 'default') {
webAudio.context.setSinkId(audioDeviceId); // @ts-ignore
} else { webAudio.context.setSinkId(audioDeviceId);
// @ts-ignore } else {
webAudio.context.setSinkId(''); // @ts-ignore
webAudio.context.setSinkId('');
}
} catch (error) {
toast.error({ message: `Error setting sink: ${(error as Error).message}` });
} }
} }
}, [audioDeviceId, webAudio]); }, [audioDeviceId, webAudio]);