From 446f8c950289be0f59847c3cccbb127d1f22408a Mon Sep 17 00:00:00 2001 From: Chrystian Huot Date: Mon, 2 Sep 2019 09:53:44 -0400 Subject: [PATCH] Minor improvements to radio.service --- client/imports/app/radio/radio.service.ts | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/client/imports/app/radio/radio.service.ts b/client/imports/app/radio/radio.service.ts index 7600b7f..0e598f6 100644 --- a/client/imports/app/radio/radio.service.ts +++ b/client/imports/app/radio/radio.service.ts @@ -236,20 +236,10 @@ export class AppRadioService implements OnDestroy { this.audioTimer = setInterval(() => this.emitTimeEvent(), 500); if (this.audioContext.state === 'suspended') { - const resume = () => { - this.audioContext.resume(); - - setTimeout(() => { - if (this.audioContext.state === 'running') { - EVENTS.forEach((event) => document.body.removeEventListener(event, resume)); - } - }); - }; - - EVENTS.forEach((event) => document.body.addEventListener(event, resume)); + this.audioContext.resume(); } } - }, () => this.skip(true)); + }, () => this.skip()); } } } @@ -333,13 +323,15 @@ export class AppRadioService implements OnDestroy { } else { this.audioContext = new AudioContext(); } + } - if (this.audioContext && this.audioContext.state === 'suspended') { + if (this.audioContext) { + EVENTS.forEach((event) => document.body.removeEventListener(event, bootstrap)); + + if (this.audioContext.state === 'suspended') { this.audioContext.resume(); } } - - EVENTS.forEach((event) => document.body.removeEventListener(event, bootstrap)); }; EVENTS.forEach((event) => document.body.addEventListener(event, bootstrap));