diff --git a/src/xhr.js b/src/xhr.js index b77cd3eac..bb5923082 100644 --- a/src/xhr.js +++ b/src/xhr.js @@ -74,7 +74,11 @@ const xhrFactory = function() { } } - const request = videojsXHR(options, function(error, response) { + // Use the standard videojs.xhr() method unless `videojs.Vhs.xhr` has been overriden + // TODO: switch back to videojs.Vhs.xhr.name === 'XhrFunction' when we drop IE11 + const xhrMethod = videojs.Vhs.xhr.original === true ? videojsXHR : videojs.Vhs.xhr; + + const request = xhrMethod(options, function(error, response) { return callbackWrapper(request, error, response, callback); }); const originalAbort = request.abort; @@ -88,6 +92,8 @@ const xhrFactory = function() { return request; }; + xhr.original = true; + return xhr; }; diff --git a/test/videojs-http-streaming.test.js b/test/videojs-http-streaming.test.js index d20e48596..c59a5e252 100644 --- a/test/videojs-http-streaming.test.js +++ b/test/videojs-http-streaming.test.js @@ -4267,6 +4267,36 @@ QUnit.test('Allows specifying the beforeRequest function globally', function(ass assert.equal(this.player.tech_.vhs.stats.bandwidth, 4194304, 'default'); }); +QUnit.test('Allows specifying custom xhr() function globally', function(assert) { + const originalXhr = videojs.Vhs.xhr; + let customXhr = false; + + videojs.Vhs.xhr = function(opts, callback) { + customXhr = true; + return videojs.xhr(opts, function(err, response, body) { + callback(err, response); + }); + }; + + this.player.src({ + src: 'master.m3u8', + type: 'application/vnd.apple.mpegurl' + }); + + this.clock.tick(1); + + openMediaSource(this.player, this.clock); + // master + this.standardXHRResponse(this.requests.shift()); + + assert.ok(customXhr, 'customXhr was called'); + + videojs.Vhs.xhr = originalXhr; + + // verify stats + assert.equal(this.player.tech_.vhs.stats.bandwidth, 4194304, 'default'); +}); + QUnit.test('Allows overriding the global beforeRequest function', function(assert) { let beforeGlobalRequestCalled = 0; let beforeLocalRequestCalled = 0;