From 0adbdfc106f80cc950d208d9ef6473c3220248be Mon Sep 17 00:00:00 2001 From: Sterling Archer Date: Sun, 31 May 2026 14:01:11 -0700 Subject: [PATCH] fix: restore mobile Web Audio SFX on iOS/Android --- game.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/game.js b/game.js index 4c7af7d..1ae2249 100644 --- a/game.js +++ b/game.js @@ -189,19 +189,21 @@ const SFX = (() => { function getCtx() { if (!ctx) ctx = new (window.AudioContext || window.webkitAudioContext)(); - if (ctx.state === 'suspended') ctx.resume(); + if (ctx.state === 'suspended') ctx.resume().catch(() => {}); return ctx; } function unlock() { if (!ctx) ctx = new (window.AudioContext || window.webkitAudioContext)(); - if (ctx.state === 'suspended') ctx.resume().then(() => {}); + if (ctx.state === 'suspended') ctx.resume().catch(() => {}); } - document.addEventListener('touchstart', unlock, { once: true, passive: true }); - document.addEventListener('pointerdown', unlock, { once: true, passive: true }); + document.addEventListener('touchstart', unlock, { passive: true }); + document.addEventListener('touchend', unlock, { passive: true }); + document.addEventListener('pointerdown', unlock, { passive: true }); + document.addEventListener('click', unlock, { passive: true }); document.addEventListener('visibilitychange', () => { if (document.visibilityState === 'visible' && ctx && ctx.state === 'suspended') { - ctx.resume(); + ctx.resume().catch(() => {}); } });