Skip to content
This repository has been archived by the owner on Apr 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #16 from mizerlou/configurable-timeout
Browse files Browse the repository at this point in the history
make xhr.timeout configurable
  • Loading branch information
jordanbyron authored Mar 20, 2019
2 parents 56b70d9 + 9ad80e0 commit c617af6
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions EventSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ var EventSource = function (url, options) {
if (lastEventId != null) xhr.setRequestHeader('Last-Event-ID', lastEventId);
cache = '';

xhr.timeout = 50000;
xhr.timeout = (this.OPTIONS && this.OPTIONS.timeout !== undefined)
? this.OPTIONS.timeout
: 50000

xhr.onreadystatechange = function () {
if (this.readyState == 3 || (this.readyState == 4 && this.status == 200)) {
// on success
Expand Down Expand Up @@ -119,9 +122,11 @@ var EventSource = function (url, options) {

xhr.send();

setTimeout(function () {
if (true || xhr.readyState == 3) xhr.abort();
}, xhr.timeout);
if (xhr.timeout > 0) {
setTimeout(function () {
if (true || xhr.readyState == 3) xhr.abort();
}, xhr.timeout);
}

eventsource._xhr = xhr;

Expand Down

0 comments on commit c617af6

Please sign in to comment.