Fix crashing with GainNode when the stream has no sound

This commit is contained in:
redphx 2024-05-25 09:55:20 +07:00
parent 18027ed1c5
commit 567770c86e

View File

@ -4,6 +4,7 @@ import { BxEvent } from "@utils/bx-event";
import { STATES } from "@utils/global";
import { getPref, PrefKey } from "@utils/preferences";
import { UserAgent } from "@utils/user-agent";
import { BxLogger } from "./bx-logger";
export enum InputType {
CONTROLLER = 'Controller',
@ -107,11 +108,15 @@ export const BxExposed = {
});
}
try {
const audioCtx = STATES.currentStream.audioContext!;
const source = audioCtx.createMediaStreamSource(audioStream);
const gainNode = audioCtx.createGain(); // call monkey-patched createGain() in BxAudioContext
source.connect(gainNode).connect(audioCtx.destination);
} catch (e) {
BxLogger.error('setupGainNode', e);
}
},
handleControllerShortcut: ControllerShortcut.handle,