diff --git a/example/eventsource-polyfill.js b/example/eventsource-polyfill.js index e2d17a6..d8747d5 100644 --- a/example/eventsource-polyfill.js +++ b/example/eventsource-polyfill.js @@ -7322,6 +7322,8 @@ function EventSource (url, eventSourceInitDict) { var streamOriginUrl = new URL(url).origin + let reconnectTimer + function makeRequestUrlAndOptions () { // Returns { url, options }; url is null/undefined if the URL properties are in options var actualUrl = url @@ -7430,7 +7432,9 @@ function EventSource (url, eventSourceInitDict) { event.delayMillis = delay _emit(event) - setTimeout(function () { + clearTimeout(reconnectTimer) + + reconnectTimer = setTimeout(function () { if (readyState !== EventSource.CONNECTING) return connect() }, delay) @@ -7605,6 +7609,8 @@ function EventSource (url, eventSourceInitDict) { } this._close = function () { + clearTimeout(reconnectTimer) + if (readyState === EventSource.CLOSED) return readyState = EventSource.CLOSED diff --git a/lib/eventsource.js b/lib/eventsource.js index 6d3efd9..1a4b040 100644 --- a/lib/eventsource.js +++ b/lib/eventsource.js @@ -85,6 +85,8 @@ function EventSource (url, eventSourceInitDict) { var streamOriginUrl = new URL(url).origin + let reconnectTimer + function makeRequestUrlAndOptions () { // Returns { url, options }; url is null/undefined if the URL properties are in options var actualUrl = url @@ -193,7 +195,9 @@ function EventSource (url, eventSourceInitDict) { event.delayMillis = delay _emit(event) - setTimeout(function () { + clearTimeout(reconnectTimer) + + reconnectTimer = setTimeout(function () { if (readyState !== EventSource.CONNECTING) return connect() }, delay) @@ -368,6 +372,8 @@ function EventSource (url, eventSourceInitDict) { } this._close = function () { + clearTimeout(reconnectTimer) + if (readyState === EventSource.CLOSED) return readyState = EventSource.CLOSED