Skip to content

Commit

Permalink
Merge pull request #997 from kalizi/master
Browse files Browse the repository at this point in the history
Added custom headers parameter in init when using XHR to fetch audio
  • Loading branch information
goldfire authored Apr 3, 2020
2 parents 375de3a + 162ccbb commit c9ca0be
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/howler.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,16 @@
self._src = (typeof o.src !== 'string') ? o.src : [o.src];
self._volume = o.volume !== undefined ? o.volume : 1;
self._xhrWithCredentials = o.xhrWithCredentials || false;
self._xhrHeaders = [];

if (o.headers && Array.isArray(o.headers))
o.headers.forEach(h => {
if (h.name && h.value)
self._xhrHeaders.push({
name: h.name,
value: h.value
});
});

// Setup all other default properties.
self._duration = 0;
Expand Down Expand Up @@ -2327,6 +2337,13 @@
xhr.open('GET', url, true);
xhr.withCredentials = self._xhrWithCredentials;
xhr.responseType = 'arraybuffer';

if (self._xhrHeaders.length > 0) {
self._xhrHeaders.forEach(header => {
xhr.setRequestHeader(header.name, header.value);
});
}

xhr.onload = function() {
// Make sure we get a successful response back.
var code = (xhr.status + '')[0];
Expand Down

0 comments on commit c9ca0be

Please sign in to comment.