diff --git a/bundles/org.openhab.ui/web/src/components/app.vue b/bundles/org.openhab.ui/web/src/components/app.vue index 37e76db245..50271ba088 100644 --- a/bundles/org.openhab.ui/web/src/components/app.vue +++ b/bundles/org.openhab.ui/web/src/components/app.vue @@ -626,24 +626,24 @@ export default { }, playAudioUrl (audioUrl) { try { - if(!this.context){ + if (!this.context) { window.AudioContext = window.AudioContext || window.webkitAudioContext if (typeof (window.AudioContext) !== 'undefined') { this.context = new AudioContext() - unlockAudioContext(this.context); + unlockAudioContext(this.context) } } let context = this.context console.log('Playing audio URL: ' + audioUrl) this.$oh.api.getPlain(audioUrl, '', '*/*', 'arraybuffer').then((data) => { - context.decodeAudioData(data, function (buffer) { + context.decodeAudioData(data, (buffer) => { let source = context.createBufferSource() source.buffer = buffer source.connect(context.destination) source.onended = function () { context.suspend() } - if(context.state == 'suspended'){ + if (context.state === 'suspended') { context.resume() } source.start(0) @@ -655,15 +655,15 @@ export default { this.context.suspend() } } - //Safari requires a touch event after the stream has started, hence this workaround - //Credit: https://www.mattmontag.com/web/unlock-web-audio-in-safari-for-ios-and-macos - function unlockAudioContext(audioCtx) { - if (audioCtx.state !== 'suspended') return; - const b = document.body; - const events = ['touchstart','touchend', 'mousedown','keydown']; - events.forEach(e => b.addEventListener(e, unlock, false)); - function unlock() { audioCtx.resume().then(clean); } - function clean() { events.forEach(e => b.removeEventListener(e, unlock)); } + // Safari requires a touch event after the stream has started, hence this workaround + // Credit: https://www.mattmontag.com/web/unlock-web-audio-in-safari-for-ios-and-macos + function unlockAudioContext (audioCtx) { + if (audioCtx.state !== 'suspended') return + const b = document.body + const events = ['touchstart', 'touchend', 'mousedown', 'keydown'] + events.forEach(e => b.addEventListener(e, unlock, false)) + function unlock () { audioCtx.resume().then(clean) } + function clean () { events.forEach(e => b.removeEventListener(e, unlock)) } } } },