diff --git a/src/hub.js b/src/hub.js index 8d0086d4ff41cedf85f50113e5fb7b6384474215..fd8b7ad95f0d47298fb024aa703e927c45821263 100644 --- a/src/hub.js +++ b/src/hub.js @@ -17,7 +17,7 @@ import "aframe-billboard-component"; import "aframe-rounded"; import "webrtc-adapter"; import "aframe-slice9-component"; -import "./utils/ios-audio-context-fix"; +import "./utils/audio-context-fix"; import trackpad_dpad4 from "./behaviours/trackpad-dpad4"; import joystick_dpad4 from "./behaviours/joystick-dpad4"; diff --git a/src/utils/audio-context-fix.js b/src/utils/audio-context-fix.js new file mode 100644 index 0000000000000000000000000000000000000000..1d3df3b08b23d216823980d924989ada5564f51f --- /dev/null +++ b/src/utils/audio-context-fix.js @@ -0,0 +1,22 @@ +/** + * Chrome and Safari will start Audio contexts in a "suspended" state. + * A user interaction (touch/mouse event) is needed in order to resume the AudioContext. + */ + +document.addEventListener("DOMContentLoaded", () => { + const ctx = THREE.AudioContext.getContext(); + + function resume() { + ctx.resume(); + + setTimeout(function() { + if (ctx.state === "running") { + document.body.removeEventListener("touchend", resume, false); + document.body.removeEventListener("mouseup", resume, false); + } + }, 0); + } + + document.body.addEventListener("touchend", resume, false); + document.body.addEventListener("mouseup", resume, false); +}); diff --git a/src/utils/ios-audio-context-fix.js b/src/utils/ios-audio-context-fix.js deleted file mode 100644 index ce474194f663ae81040f8fdadcdb5a5130792a37..0000000000000000000000000000000000000000 --- a/src/utils/ios-audio-context-fix.js +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Mobile Safari will start Audio contexts in a "suspended" state. - * A user interaction (touch event) is needed in order to resume the AudioContext. - */ -const iDevices = /\biPhone.*Mobile|\biPod|\biPad|AppleCoreMedia/; - -if (iDevices.test(navigator.userAgent)) { - document.addEventListener("DOMContentLoaded", () => { - const ctx = THREE.AudioContext.getContext(); - - function resume() { - ctx.resume(); - - setTimeout(function() { - if (ctx.state === "running") { - document.body.removeEventListener("touchend", resume, false); - } - }, 0); - } - - document.body.addEventListener("touchend", resume, false); - }); -}