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

Commit c617af6

Browse files
authored
Merge pull request #16 from mizerlou/configurable-timeout
make xhr.timeout configurable
2 parents 56b70d9 + 9ad80e0 commit c617af6

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

EventSource.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ var EventSource = function (url, options) {
5050
if (lastEventId != null) xhr.setRequestHeader('Last-Event-ID', lastEventId);
5151
cache = '';
5252

53-
xhr.timeout = 50000;
53+
xhr.timeout = (this.OPTIONS && this.OPTIONS.timeout !== undefined)
54+
? this.OPTIONS.timeout
55+
: 50000
56+
5457
xhr.onreadystatechange = function () {
5558
if (this.readyState == 3 || (this.readyState == 4 && this.status == 200)) {
5659
// on success
@@ -119,9 +122,11 @@ var EventSource = function (url, options) {
119122

120123
xhr.send();
121124

122-
setTimeout(function () {
123-
if (true || xhr.readyState == 3) xhr.abort();
124-
}, xhr.timeout);
125+
if (xhr.timeout > 0) {
126+
setTimeout(function () {
127+
if (true || xhr.readyState == 3) xhr.abort();
128+
}, xhr.timeout);
129+
}
125130

126131
eventsource._xhr = xhr;
127132

0 commit comments

Comments
 (0)