diff --git a/public/index.html b/public/index.html index 149e8a3..0aac426 100644 --- a/public/index.html +++ b/public/index.html @@ -25,38 +25,6 @@ trackLinks:true, accurateTrackBounce:true }); - - (function() { - window.AudioContext = window.AudioContext || window.webkitAudioContext; - if (window.AudioContext) { - window.audioContext = new window.AudioContext(); - } - const fixAudioContext = function (e) { - if (window.audioContext) { - // Create empty buffer - const buffer = window.audioContext.createBuffer(1, 1, 22050); - const source = window.audioContext.createBufferSource(); - source.buffer = buffer; - // Connect to output (speakers) - source.connect(window.audioContext.destination); - // Play sound - if (source.start) { - source.start(0); - } else if (source.play) { - source.play(0); - } else if (source.noteOn) { - source.noteOn(0); - } - } - // Remove events - document.removeEventListener('touchstart', fixAudioContext); - document.removeEventListener('touchend', fixAudioContext); - }; - // iOS 6-8 - document.addEventListener('touchstart', fixAudioContext); - // iOS 9 - document.addEventListener('touchend', fixAudioContext); - })(); diff --git a/src/components/scan.js b/src/components/scan.js index 51a7471..b97216e 100644 --- a/src/components/scan.js +++ b/src/components/scan.js @@ -124,6 +124,38 @@ class Scan extends React.Component { }); }; + initializeAudio = () => { + window.AudioContext = window.AudioContext || window.webkitAudioContext; + if (window.AudioContext) { + window.audioContext = new window.AudioContext(); + } + const fixAudioContext = function (e) { + if (window.audioContext) { + // Create empty buffer + const buffer = window.audioContext.createBuffer(1, 1, 22050); + const source = window.audioContext.createBufferSource(); + source.buffer = buffer; + // Connect to output (speakers) + source.connect(window.audioContext.destination); + // Play sound + if (source.start) { + source.start(0); + } else if (source.play) { + source.play(0); + } else if (source.noteOn) { + source.noteOn(0); + } + } + // Remove events + document.removeEventListener('touchstart', fixAudioContext); + document.removeEventListener('touchend', fixAudioContext); + }; + // iOS 6-8 + document.addEventListener('touchstart', fixAudioContext); + // iOS 9 + document.addEventListener('touchend', fixAudioContext); + } + stopScan = () => { this.setState({ scanning: false, @@ -324,7 +356,7 @@ class Scan extends React.Component { renderButtons = () => { return
- {this.state.btnText} + {this.state.btnText} X-hair FPS B/W