From 5f5507b538715fa61698eecca9fab406c5aa02d6 Mon Sep 17 00:00:00 2001 From: Sterling Archer Date: Sun, 31 May 2026 14:16:28 -0700 Subject: [PATCH] fix: prime iOS WebKit audio pipeline with silent oscillator on first touch --- game.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/game.js b/game.js index 14a1b4e..491b84f 100644 --- a/game.js +++ b/game.js @@ -193,10 +193,23 @@ const SFX = (() => { return ctx; } + function primer() { + if (!ctx) ctx = new (window.AudioContext || window.webkitAudioContext)(); + ctx.resume().then(() => { + const osc = ctx.createOscillator(); + const gain = ctx.createGain(); + osc.connect(gain); + gain.connect(ctx.destination); + gain.gain.setValueAtTime(0.0001, ctx.currentTime); + osc.start(ctx.currentTime); + osc.stop(ctx.currentTime + 0.001); + }).catch(() => {}); + } function unlock() { if (!ctx) ctx = new (window.AudioContext || window.webkitAudioContext)(); if (ctx.state === 'suspended') ctx.resume().catch(() => {}); } + document.addEventListener('touchstart', primer, { once: true, passive: true }); document.addEventListener('touchstart', unlock, { passive: true }); document.addEventListener('touchend', unlock, { passive: true }); document.addEventListener('pointerdown', unlock, { passive: true });