VolumeBooster: Fix playing sound in wrong output device (#2840)

This commit is contained in:
sadan4 2024-09-04 07:04:17 -04:00 committed by GitHub
parent 7f784befc2
commit d10e649b63
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -39,7 +39,7 @@ interface StreamData {
gainNode?: GainNode, gainNode?: GainNode,
id: string, id: string,
levelNode: AudioWorkletNode, levelNode: AudioWorkletNode,
sinkId: string, sinkId: string | "default",
stream: MediaStream, stream: MediaStream,
streamSourceNode?: MediaStreamAudioSourceNode, streamSourceNode?: MediaStreamAudioSourceNode,
videoStreamId: string, videoStreamId: string,
@ -128,6 +128,12 @@ export default definePlugin({
gain.connect(data.audioContext.destination); gain.connect(data.audioContext.destination);
} }
// @ts-expect-error
if (data.sinkId != null && data.sinkId !== data.audioContext.sinkId && "setSinkId" in AudioContext.prototype) {
// @ts-expect-error https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/setSinkId
data.audioContext.setSinkId(data.sinkId);
}
data.gainNode.gain.value = data._mute data.gainNode.gain.value = data._mute
? 0 ? 0
: data._volume / 100; : data._volume / 100;