diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-06-13 10:23:04 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-13 10:23:04 -0400 |
commit | 8a7ff6a18c78bbc2048dd4017597ccc4f5ee4106 (patch) | |
tree | 58333fc1a5a3da13180e8d0bbd5e65d79b34fa27 /ext/mixed/js/audio-system.js | |
parent | 5cba421201b596f4430dd45f3715ad515661b109 (diff) |
Replace XMLHttpRequest (#562)
* Replace XMLHttpRequest with fetch
* Implement fetch placeholder for tests
Diffstat (limited to 'ext/mixed/js/audio-system.js')
-rw-r--r-- | ext/mixed/js/audio-system.js | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/ext/mixed/js/audio-system.js b/ext/mixed/js/audio-system.js index fdfb0b10..c590b909 100644 --- a/ext/mixed/js/audio-system.js +++ b/ext/mixed/js/audio-system.js @@ -169,22 +169,22 @@ class AudioSystem { }); } - _createAudioBinaryFromUrl(url) { - return new Promise((resolve, reject) => { - const xhr = new XMLHttpRequest(); - xhr.responseType = 'arraybuffer'; - xhr.addEventListener('load', async () => { - const arrayBuffer = xhr.response; - if (!await this._isAudioBinaryValid(arrayBuffer)) { - reject(new Error('Could not retrieve audio')); - } else { - resolve(arrayBuffer); - } - }); - xhr.addEventListener('error', () => reject(new Error('Failed to connect'))); - xhr.open('GET', url); - xhr.send(); + async _createAudioBinaryFromUrl(url) { + const response = await fetch(url, { + method: 'GET', + mode: 'no-cors', + cache: 'default', + credentials: 'omit', + redirect: 'follow', + referrerPolicy: 'no-referrer' }); + const arrayBuffer = await response.arrayBuffer(); + + if (!await this._isAudioBinaryValid(arrayBuffer)) { + throw new Error('Could not retrieve audio'); + } + + return arrayBuffer; } _isAudioValid(audio) { |