Skip to content

Commit

Permalink
Updating to match mangui's suggestion.
Browse files Browse the repository at this point in the history
  • Loading branch information
brentsmith-dev committed Mar 13, 2017
1 parent 5077cf9 commit 5c865d5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 33 deletions.
20 changes: 0 additions & 20 deletions doc/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
- [`fLoader`](#floader)
- [`pLoader`](#ploader)
- [`xhrSetup`](#xhrsetup)
- [`xhrSetupBeforeOpen`](#xhrSetupBeforeOpen)
- [`fetchSetup`](#fetchsetup)
- [`abrController`](#abrcontroller)
- [`timelineController`](#timelinecontroller)
Expand Down Expand Up @@ -318,7 +317,6 @@ Configuration parameters could be provided to hls.js upon instantiation of `Hls`
fLoader: customFragmentLoader,
pLoader: customPlaylistLoader,
xhrSetup: XMLHttpRequestSetupCallback,
xhrSetupBeforeOpen: XMLHttpRequestSetupBeforeOpenCallback,
fetchSetup: FetchSetupCallback,
abrController: customAbrController,
timelineController: TimelineController,
Expand Down Expand Up @@ -710,24 +708,6 @@ This allows user to easily modify/setup XHR. See example below.
}
}
```
### `xhrSetupBeforeOpen`
(default: `undefined`)
`XMLHttpRequest` customization callback for default XHR based loader. This is called earlier
in the process than xhrSetup which occurs just before `xhr.send()`
Parameter should be a function with two arguments `(xhr: XMLHttpRequest, url: string)`.
If `xhrSetup` is specified, default loader will invoke it before calling `xhr.open()`.
This allows user to easily modify/setup XHR. See example below.
```js
var config = {
xhrSetupBeforeOpen: function(xhr, url) {
xhr.withCredentials = true; // do send cookies
}
}
```
### `fetchSetup`
Expand Down
1 change: 0 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export var hlsDefaultConfig = {
fLoader: undefined,
pLoader: undefined,
xhrSetup: undefined,
xhrSetupBeforeOpen: undefined,
fetchSetup: undefined,
abrController: AbrController,
bufferController: BufferController,
Expand Down
16 changes: 4 additions & 12 deletions src/utils/xhr-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ class XhrLoader {
if (config && config.xhrSetup) {
this.xhrSetup = config.xhrSetup;
}
if (config && config.xhrSetupBeforeOpen) {
this.xhrSetupBeforeOpen = config.xhrSetupBeforeOpen;
}
}

destroy() {
Expand Down Expand Up @@ -54,15 +51,6 @@ class XhrLoader {
xhr.onreadystatechange = this.readystatechange.bind(this);
xhr.onprogress = this.loadprogress.bind(this);

// IE/Edge on Win 10 thows an error on xhr.open for protocol mismatch
// for things like protocol matching on ts chunks this must be done here
// Issue #1020
if (this.xhrSetupBeforeOpen) {
this.xhrSetupBeforeOpen(xhr, context.url);
}

xhr.open('GET', context.url, true);

if (context.rangeEnd) {
xhr.setRequestHeader('Range','bytes=' + context.rangeStart + '-' + (context.rangeEnd-1));
}
Expand All @@ -73,6 +61,10 @@ class XhrLoader {
if (this.xhrSetup) {
this.xhrSetup(xhr, context.url);
}

if (!xhr.readyState) {
xhr.open('GET', context.url, true);
}
// setup timeout before we perform request
this.requestTimeout = window.setTimeout(this.loadtimeout.bind(this), this.config.timeout);
xhr.send();
Expand Down

0 comments on commit 5c865d5

Please sign in to comment.