From 804b4013fc72941874b67739974fcbb09ed5593b Mon Sep 17 00:00:00 2001 From: julian laplace Date: Sun, 26 Jan 2025 17:28:59 +0100 Subject: always start audio context --- client/lib/util.js | 106 +++++++++++++++++++++++++++-------------------------- 1 file changed, 55 insertions(+), 51 deletions(-) (limited to 'client/lib') diff --git a/client/lib/util.js b/client/lib/util.js index 72be9b7..d11faf8 100644 --- a/client/lib/util.js +++ b/client/lib/util.js @@ -1,58 +1,62 @@ -import Tone from 'tone' -import StartAudioContext from './startAudioContext' +import Tone from "tone"; +import StartAudioContext from "./startAudioContext"; -const isIphone = (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) -const isIpad = (navigator.userAgent.match(/iPad/i)) -const isAndroid = (navigator.userAgent.match(/Android/i)) -const isMobile = isIphone || isIpad || isAndroid -const isDesktop = ! isMobile +const isIphone = + navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i); +const isIpad = navigator.userAgent.match(/iPad/i); +const isAndroid = navigator.userAgent.match(/Android/i); +const isMobile = isIphone || isIpad || isAndroid; +const isDesktop = !isMobile; -document.body.classList.add(isMobile ? 'mobile' : 'desktop') +document.body.classList.add(isMobile ? "mobile" : "desktop"); -const browser = { isIphone, isIpad, isMobile, isDesktop } +const browser = { isIphone, isIpad, isMobile, isDesktop }; -function choice (a){ return a[ Math.floor(Math.random() * a.length) ] } -function mod(n,m){ return n-(m * Math.floor(n/m)) } - -function requestAudioContext (fn) { - if (isMobile) { - const container = document.createElement('div') - const button = document.createElement('div') - button.innerHTML = 'Tap to start - please unmute your phone' - Object.assign(container.style, { - position: 'absolute', - width: '100%', - height: '100%', - zIndex: '10000', - top: '0px', - left: '0px', - backgroundColor: 'rgba(0, 0, 0, 0.8)', - }) - Object.assign(button.style, { - position: 'absolute', - left: '50%', - top: '50%', - padding: '20px', - backgroundColor: '#7F33ED', - color: 'white', - fontFamily: 'monospace', - borderRadius: '3px', - transform: 'translate3D(-50%,-50%,0)', - textAlign: 'center', - lineHeight: '1.5', - }) - container.appendChild(button) - document.body.appendChild(container) - StartAudioContext.setContext(Tone.context) - StartAudioContext.on(button) - StartAudioContext.onStarted(_ => { - container.remove() - fn() - }) - } else { - fn() - } +function choice(a) { + return a[Math.floor(Math.random() * a.length)]; +} +function mod(n, m) { + return n - m * Math.floor(n / m); } -export { choice, mod, browser, requestAudioContext } +function requestAudioContext(fn) { + // if (isMobile) { + const container = document.createElement("div"); + const button = document.createElement("div"); + button.innerHTML = "Tap to start - please unmute your phone"; + Object.assign(container.style, { + position: "absolute", + width: "100%", + height: "100%", + zIndex: "10000", + top: "0px", + left: "0px", + backgroundColor: "rgba(0, 0, 0, 0.8)", + }); + Object.assign(button.style, { + position: "absolute", + left: "50%", + top: "50%", + padding: "20px", + backgroundColor: "#7F33ED", + color: "white", + fontFamily: "monospace", + borderRadius: "3px", + transform: "translate3D(-50%,-50%,0)", + textAlign: "center", + lineHeight: "1.5", + }); + container.appendChild(button); + document.body.appendChild(container); + StartAudioContext.setContext(Tone.context); + StartAudioContext.on(button); + StartAudioContext.onStarted((_) => { + container.remove(); + fn(); + }); + // } else { + // fn() + // } +} +export { choice, mod, browser, requestAudioContext }; -- cgit v1.2.3-70-g09d2