From 567770c86ec80c620060dc994e9850209ada2cfb Mon Sep 17 00:00:00 2001 From: redphx <96280+redphx@users.noreply.github.com> Date: Sat, 25 May 2024 09:55:20 +0700 Subject: [PATCH] Fix crashing with GainNode when the stream has no sound --- src/utils/bx-exposed.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/utils/bx-exposed.ts b/src/utils/bx-exposed.ts index f15649b..d38aada 100644 --- a/src/utils/bx-exposed.ts +++ b/src/utils/bx-exposed.ts @@ -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 = { }); } - const audioCtx = STATES.currentStream.audioContext!; - const source = audioCtx.createMediaStreamSource(audioStream); + 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); + 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,