Fix not awaiting the AudioSystem.arrayBufferDigest promise (#524)

This commit is contained in:
toasted-nutbread 2020-05-09 12:28:48 -04:00 committed by GitHub
parent 69c783f861
commit 9900291b07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -173,9 +173,9 @@ class AudioSystem {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
xhr.responseType = 'arraybuffer'; xhr.responseType = 'arraybuffer';
xhr.addEventListener('load', () => { xhr.addEventListener('load', async () => {
const arrayBuffer = xhr.response; const arrayBuffer = xhr.response;
if (!this._isAudioBinaryValid(arrayBuffer)) { if (!await this._isAudioBinaryValid(arrayBuffer)) {
reject(new Error('Could not retrieve audio')); reject(new Error('Could not retrieve audio'));
} else { } else {
resolve(arrayBuffer); resolve(arrayBuffer);
@ -195,8 +195,8 @@ class AudioSystem {
); );
} }
_isAudioBinaryValid(arrayBuffer) { async _isAudioBinaryValid(arrayBuffer) {
const digest = AudioSystem.arrayBufferDigest(arrayBuffer); const digest = await AudioSystem.arrayBufferDigest(arrayBuffer);
switch (digest) { switch (digest) {
case 'ae6398b5a27bc8c0a771df6c907ade794be15518174773c58c7c7ddd17098906': // jpod101 invalid audio case 'ae6398b5a27bc8c0a771df6c907ade794be15518174773c58c7c7ddd17098906': // jpod101 invalid audio
return false; return false;