[bugfix]: use chrome-specific implementation for web audio sink

This commit is contained in:
Kendall Garner 2024-08-19 22:38:51 -07:00
parent ebebdc1e03
commit af69a58418
No known key found for this signature in database
GPG key ID: 18D2767419676C87

View file

@ -262,16 +262,19 @@ export const AudioPlayer = forwardRef(
);
useEffect(() => {
if (isElectron()) {
if (audioDeviceId) {
player1Ref.current?.getInternalPlayer()?.setSinkId(audioDeviceId);
player2Ref.current?.getInternalPlayer()?.setSinkId(audioDeviceId);
// 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) {
if (audioDeviceId !== 'default') {
// @ts-ignore
webAudio.context.setSinkId(audioDeviceId);
} else {
player1Ref.current?.getInternalPlayer()?.setSinkId('');
player2Ref.current?.getInternalPlayer()?.setSinkId('');
// @ts-ignore
webAudio.context.setSinkId('');
}
}
}, [audioDeviceId]);
}, [audioDeviceId, webAudio]);
useEffect(() => {
if (webAudio && player1Source && player1 && currentPlayer === 1) {