From db8ba17147c1ae3bd0bb7438f5af629f94502c29 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Wed, 21 Feb 2018 14:39:43 -0800 Subject: [PATCH] Check audio context ctor before constructing --- src/SoundManager.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SoundManager.ts b/src/SoundManager.ts index dc61acbd..dbd4f02d 100644 --- a/src/SoundManager.ts +++ b/src/SoundManager.ts @@ -21,8 +21,9 @@ export class SoundManager implements ISoundManager { } public playBellSound(): void { - if (!this._audioContext) { - this._audioContext = new (window.AudioContext || window.webkitAudioContext)(); + const audioContextCtor: typeof AudioContext = (window).AudioContext || (window).webkitAudioContext; + if (!this._audioContext && audioContextCtor) { + this._audioContext = new audioContextCtor(); } if (this._audioContext) { @@ -33,8 +34,7 @@ export class SoundManager implements ISoundManager { bellAudioSource.connect(context.destination); bellAudioSource.start(0); }); - } - else { + } else { console.warn('Sorry, but the Web Audio API is not supported by your browser. Please, consider upgrading to the latest version'); } }