From abfdfdc5d96a3d222020bb1d51dce6a6611a636b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Li=C5=A1ka?= Date: Wed, 23 Sep 2020 10:56:41 +0200 Subject: [PATCH 1/2] Refactoring mediaSessionInit variable to event option once --- app/cyp.js | 7 +++---- app/js/elements/app.js | 5 +---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/app/cyp.js b/app/cyp.js index ac66206..903dfb8 100644 --- a/app/cyp.js +++ b/app/cyp.js @@ -643,12 +643,11 @@ class App extends HTMLElement { node("source", {src: 'https://raw.githubusercontent.com/anars/blank-audio/master/10-seconds-of-silence.mp3'}, '', audio); // Init event session (play audio) on click (because restrictions by web browsers) - let mediaSessionInit = false; window.addEventListener('click', () => { - if (mediaSessionInit) return; - mediaSessionInit = true; audio.play(); - }); + alert('ok'); + console.log('ok'); + }, {once: true}); // mediaSession define metadata navigator.mediaSession.metadata = new MediaMetadata({ diff --git a/app/js/elements/app.js b/app/js/elements/app.js index aed9997..15bc5a4 100644 --- a/app/js/elements/app.js +++ b/app/js/elements/app.js @@ -82,12 +82,9 @@ class App extends HTMLElement { html.node("source", {src: 'https://raw.githubusercontent.com/anars/blank-audio/master/10-seconds-of-silence.mp3'}, '', audio); // Init event session (play audio) on click (because restrictions by web browsers) - let mediaSessionInit = false; window.addEventListener('click', () => { - if (mediaSessionInit) return; - mediaSessionInit = true; audio.play(); - }); + }, {once: true}); // mediaSession define metadata navigator.mediaSession.metadata = new MediaMetadata({ From 8269340a2e52389ede4aafe52090fcc0632022ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Li=C5=A1ka?= Date: Wed, 23 Sep 2020 11:07:41 +0200 Subject: [PATCH 2/2] Refactoring mediaSessionInit variable to event option once (part 2) --- app/cyp.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/cyp.js b/app/cyp.js index 903dfb8..50138d1 100644 --- a/app/cyp.js +++ b/app/cyp.js @@ -645,8 +645,6 @@ class App extends HTMLElement { // Init event session (play audio) on click (because restrictions by web browsers) window.addEventListener('click', () => { audio.play(); - alert('ok'); - console.log('ok'); }, {once: true}); // mediaSession define metadata