reconnecting-eventsource 1.6.2 → 1.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -75,3 +75,18 @@ Some errors, such as 502, are probably temporary, and ideally wouldn't cause cli
|
|
|
75
75
|
## So this thing reconnects forever. How do I make it stop?
|
|
76
76
|
|
|
77
77
|
The client has to explicitly stop by calling `es.close()`. If you want to control this from the server, have the server send some kind of close instruction for the client to act on.
|
|
78
|
+
|
|
79
|
+
## Compatibility
|
|
80
|
+
|
|
81
|
+
Browsers
|
|
82
|
+
* Chrome / Chrome Android 71 and newer
|
|
83
|
+
* Edge 79 and newer
|
|
84
|
+
* Safari 12.2 and newer
|
|
85
|
+
* Firefox / Firefox Android 65 and newer
|
|
86
|
+
* Firefox Android 65 or newer
|
|
87
|
+
* Opera 58 and newer
|
|
88
|
+
* Opera Android 50 and newer
|
|
89
|
+
|
|
90
|
+
Server
|
|
91
|
+
* Node.js 12.0 and newer
|
|
92
|
+
* Deno 1.38 and newer
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var _ReconnectingEventSource;(()=>{"use strict";var e={19:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EventSourceNotAvailableError=void 0;class n extends Error{constructor(){super("EventSource not available.\nConsider loading an EventSource polyfill and making it available globally as EventSource, or passing one in as eventSourceClass to the ReconnectingEventSource constructor.")}}t.EventSourceNotAvailableError=n;class s{constructor(e,t){if(this.CONNECTING=0,this.OPEN=1,this.CLOSED=2,this._configuration=null!=t?Object.assign({},t):void 0,this.withCredentials=!1,this._eventSource=null,this._lastEventId=null,this._timer=null,this._listeners={},this.url=e.toString(),this.readyState=this.CONNECTING,this.max_retry_time=3e3,this.eventSourceClass=globalThis.EventSource,null!=this._configuration&&(this._configuration.lastEventId&&(this._lastEventId=this._configuration.lastEventId,delete this._configuration.lastEventId),this._configuration.max_retry_time&&(this.max_retry_time=this._configuration.max_retry_time,delete this._configuration.max_retry_time),this._configuration.eventSourceClass&&(this.eventSourceClass=this._configuration.eventSourceClass,delete this._configuration.eventSourceClass)),null==this.eventSourceClass||"function"!=typeof this.eventSourceClass)throw new n;this._onevent_wrapped=e=>{this._onevent(e)},this._start()}dispatchEvent(e){throw new Error("Method not implemented.")}_start(){let e=this.url;this._lastEventId&&(-1===e.indexOf("?")?e+="?":e+="&",e+="lastEventId="+encodeURIComponent(this._lastEventId)),this._eventSource=new this.eventSourceClass(e,this._configuration),this._eventSource.onopen=e=>{this._onopen(e)},this._eventSource.onerror=e=>{this._onerror(e)},this._eventSource.onmessage=e=>{this.onmessage(e)};for(const e of Object.keys(this._listeners))this._eventSource.addEventListener(e,this._onevent_wrapped)}_onopen(e){0===this.readyState&&(this.readyState=1,this.onopen(e))}_onerror(e){if(1===this.readyState&&(this.readyState=0,this.onerror(e)),this._eventSource&&2===this._eventSource.readyState){this._eventSource.close(),this._eventSource=null;const e=Math.round(this.max_retry_time*Math.random());this._timer=setTimeout((()=>this._start()),e)}}_onevent(e){e instanceof MessageEvent&&(this._lastEventId=e.lastEventId);const t=this._listeners[e.type];if(null!=t)for(const n of[...t])n.call(this,e);"message"===e.type&&this.onmessage(e)}onopen(e){}onerror(e){}onmessage(e){}close(){this._timer&&(clearTimeout(this._timer),this._timer=null),this._eventSource&&(this._eventSource.close(),this._eventSource=null),this.readyState=2}addEventListener(e,t,n){e in this._listeners||(this._listeners[e]=[],null!=this._eventSource&&this._eventSource.addEventListener(e,this._onevent_wrapped));const s=this._listeners[e];Array.isArray(s)&&!s.includes(t)&&s.push(t)}removeEventListener(e,t,n){const s=this._listeners[e];if(null!=s){for(;;){const e=s.indexOf(t);if(-1===e)break;s.splice(e,1)}s.length<=0&&(delete this._listeners[e],null!=this._eventSource&&this._eventSource.removeEventListener(e,this._onevent_wrapped))}}}t.default=s,s.CONNECTING=0,s.OPEN=1,s.CLOSED=2}},t={};function n(s){var i=t[s];if(void 0!==i)return i.exports;var r=t[s]={exports:{}};return e[s](r,r.exports,n),r.exports}var s={};(()=>{var e=s;Object.defineProperty(e,"__esModule",{value:!0});const t=n(19);Object.assign(
|
|
1
|
+
var _ReconnectingEventSource;(()=>{"use strict";var e={19:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EventSourceNotAvailableError=void 0;class n extends Error{constructor(){super("EventSource not available.\nConsider loading an EventSource polyfill and making it available globally as EventSource, or passing one in as eventSourceClass to the ReconnectingEventSource constructor.")}}t.EventSourceNotAvailableError=n;class s{constructor(e,t){if(this.CONNECTING=0,this.OPEN=1,this.CLOSED=2,this._configuration=null!=t?Object.assign({},t):void 0,this.withCredentials=!1,this._eventSource=null,this._lastEventId=null,this._timer=null,this._listeners={},this.url=e.toString(),this.readyState=this.CONNECTING,this.max_retry_time=3e3,this.eventSourceClass=globalThis.EventSource,null!=this._configuration&&(this._configuration.lastEventId&&(this._lastEventId=this._configuration.lastEventId,delete this._configuration.lastEventId),this._configuration.max_retry_time&&(this.max_retry_time=this._configuration.max_retry_time,delete this._configuration.max_retry_time),this._configuration.eventSourceClass&&(this.eventSourceClass=this._configuration.eventSourceClass,delete this._configuration.eventSourceClass)),null==this.eventSourceClass||"function"!=typeof this.eventSourceClass)throw new n;this._onevent_wrapped=e=>{this._onevent(e)},this._start()}dispatchEvent(e){throw new Error("Method not implemented.")}_start(){let e=this.url;this._lastEventId&&(-1===e.indexOf("?")?e+="?":e+="&",e+="lastEventId="+encodeURIComponent(this._lastEventId)),this._eventSource=new this.eventSourceClass(e,this._configuration),this._eventSource.onopen=e=>{this._onopen(e)},this._eventSource.onerror=e=>{this._onerror(e)},this._eventSource.onmessage=e=>{this.onmessage(e)};for(const e of Object.keys(this._listeners))this._eventSource.addEventListener(e,this._onevent_wrapped)}_onopen(e){0===this.readyState&&(this.readyState=1,this.onopen(e))}_onerror(e){if(1===this.readyState&&(this.readyState=0,this.onerror(e)),this._eventSource&&2===this._eventSource.readyState){this._eventSource.close(),this._eventSource=null;const e=Math.round(this.max_retry_time*Math.random());this._timer=setTimeout((()=>this._start()),e)}}_onevent(e){e instanceof MessageEvent&&(this._lastEventId=e.lastEventId);const t=this._listeners[e.type];if(null!=t)for(const n of[...t])n.call(this,e);"message"===e.type&&this.onmessage(e)}onopen(e){}onerror(e){}onmessage(e){}close(){this._timer&&(clearTimeout(this._timer),this._timer=null),this._eventSource&&(this._eventSource.close(),this._eventSource=null),this.readyState=2}addEventListener(e,t,n){e in this._listeners||(this._listeners[e]=[],null!=this._eventSource&&this._eventSource.addEventListener(e,this._onevent_wrapped));const s=this._listeners[e];Array.isArray(s)&&!s.includes(t)&&s.push(t)}removeEventListener(e,t,n){const s=this._listeners[e];if(null!=s){for(;;){const e=s.indexOf(t);if(-1===e)break;s.splice(e,1)}s.length<=0&&(delete this._listeners[e],null!=this._eventSource&&this._eventSource.removeEventListener(e,this._onevent_wrapped))}}}t.default=s,s.CONNECTING=0,s.OPEN=1,s.CLOSED=2}},t={};function n(s){var i=t[s];if(void 0!==i)return i.exports;var r=t[s]={exports:{}};return e[s](r,r.exports,n),r.exports}var s={};(()=>{var e=s;Object.defineProperty(e,"__esModule",{value:!0});const t=n(19);Object.assign(globalThis,{ReconnectingEventSource:t.default,EventSourceNotAvailableError:t.EventSourceNotAvailableError})})(),_ReconnectingEventSource=s})();
|
|
2
2
|
//# sourceMappingURL=ReconnectingEventSource.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReconnectingEventSource.min.js","mappings":"yJAmCA,MAAaA,UAAqCC,MAC9CC,cACIC,MACE,0MAIN,EAPJ,iCAiBA,MAAqBC,EAyBjBF,YAAYG,EAAmBC,GA+B3B,GArDK,KAAAC,WAAa,EACb,KAAAC,KAAO,EACP,KAAAC,OAAS,EAqBdC,KAAKC,eAAkC,MAAjBL,EAAwBM,OAAOC,OAAO,CAAC,EAAGP,QAAiBQ,EACjFJ,KAAKK,iBAAkB,EAEvBL,KAAKM,aAAe,KACpBN,KAAKO,aAAe,KACpBP,K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AAiBY,QAAU,WACpBnD,KAAKS,WAAWoB,GACE,MAArB7B,KAAKM,cACLN,KAAKM,aAAa0C,oBAAoBnB,EAAM7B,KAAKiB,kB,CAIjE,EA5MJ,YAQoB,EAAApB,WAAa,EACb,EAAAC,KAAO,EACP,EAAAC,OAAS,C,GC7DzBqD,EAA2B,CAAC,EAGhC,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBlD,IAAjBmD,EACH,OAAOA,EAAaC,QAGrB,IAAIC,EAASL,EAAyBE,GAAY,CAGjDE,QAAS,CAAC,GAOX,OAHAE,EAAoBJ,GAAUG,EAAQA,EAAOD,QAASH,GAG/CI,EAAOD,OACf,C,wECtBA,cACAtD,OAAOC,OAAOwD,OAAQ,CACpBjE,wBAAA,UACAJ,6BAAA,EAAAA,8B","sources":["webpack://_ReconnectingEventSource/./src/reconnecting-eventsource.ts","webpack://_ReconnectingEventSource/webpack/bootstrap","webpack://_ReconnectingEventSource/./src/main.browser.ts"],"sourcesContent":["// MIT License:\n//\n// Copyright (C) 2022 Fanout, Inc.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to\n// deal in the Software without restriction, including without limitation the\n// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n// sell copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n// IN THE SOFTWARE.\n\nexport interface ReconnectingEventSourceInit extends EventSourceInit {\n // the maximum time to wait before attempting to reconnect in ms, default `3000`\n // note: wait time is randomised to prevent all clients from attempting to reconnect simultaneously\n max_retry_time?: number;\n\n // the EventSource class to wrap. This allows the use of a polyfill or alternate\n // implementation instead of the platform-provided EventSource class.\n eventSourceClass?: typeof EventSource;\n\n // the last event\n lastEventId?: string;\n}\n\nexport class EventSourceNotAvailableError extends Error {\n constructor() {\n super(\n 'EventSource not available.\\n' +\n 'Consider loading an EventSource polyfill and making it available globally as EventSource, ' +\n 'or passing one in as eventSourceClass to the ReconnectingEventSource constructor.'\n );\n }\n}\n\ntype EventType<T extends string> = T extends keyof EventSourceEventMap ? EventSourceEventMap[T] : MessageEvent<any>;\ntype EventListenerType<T extends string> = (this: EventSource, event: EventType<T>) => any;\n\ntype Listeners = {\n [name: string]: ((this: EventSource, event: Event) => any)[];\n};\n\nexport default class ReconnectingEventSource implements EventSource {\n\n readonly _configuration: ReconnectingEventSourceInit | undefined;\n readonly CONNECTING = 0;\n readonly OPEN = 1;\n readonly CLOSED = 2;\n\n // Evidently these are to exist both on the class and the instance\n static readonly CONNECTING = 0;\n static readonly OPEN = 1;\n static readonly CLOSED = 2;\n\n _eventSource: EventSource | null;\n _lastEventId: string | null;\n _timer: NodeJS.Timer | null;\n _listeners: Listeners;\n _onevent_wrapped: (this: EventSource, ev: Event) => any;\n\n readyState: 0 | 1 | 2;\n url: string;\n withCredentials: boolean;\n\n readonly max_retry_time: number;\n eventSourceClass: typeof EventSource;\n\n constructor(url: string | URL, configuration?: ReconnectingEventSourceInit) {\n this._configuration = configuration != null ? Object.assign({}, configuration) : undefined;\n this.withCredentials = false;\n\n this._eventSource = null;\n this._lastEventId = null;\n this._timer = null;\n this._listeners = {};\n\n this.url = url.toString();\n this.readyState = this.CONNECTING;\n this.max_retry_time = 3000;\n this.eventSourceClass = globalThis.EventSource;\n\n if (this._configuration != null) {\n if (this._configuration.lastEventId) {\n this._lastEventId = this._configuration.lastEventId;\n delete this._configuration['lastEventId'];\n }\n\n if (this._configuration.max_retry_time) {\n this.max_retry_time = this._configuration.max_retry_time;\n delete this._configuration['max_retry_time'];\n }\n\n if (this._configuration.eventSourceClass) {\n this.eventSourceClass = this._configuration.eventSourceClass;\n delete this._configuration['eventSourceClass'];\n }\n }\n\n if(this.eventSourceClass == null || typeof this.eventSourceClass !== 'function') {\n throw new EventSourceNotAvailableError();\n }\n\n this._onevent_wrapped = (event) => { this._onevent(event); };\n\n this._start();\n }\n\n dispatchEvent(event: Event): boolean {\n throw new Error(\"Method not implemented.\");\n }\n\n _start() {\n let url = this.url;\n\n if (this._lastEventId) {\n if (url.indexOf('?') === -1) {\n url += '?';\n } else {\n url += '&';\n }\n url += 'lastEventId=' + encodeURIComponent(this._lastEventId);\n }\n\n this._eventSource = new this.eventSourceClass(url, this._configuration);\n\n this._eventSource.onopen = (event) => { this._onopen(event); };\n this._eventSource.onerror = (event) => { this._onerror(event); };\n this._eventSource.onmessage = (event) => { this.onmessage(event); };\n\n // apply listen types\n for (const type of Object.keys(this._listeners)) {\n this._eventSource.addEventListener(type, this._onevent_wrapped);\n }\n }\n\n _onopen(event: Event) {\n if (this.readyState === 0) {\n this.readyState = 1;\n this.onopen(event);\n }\n }\n\n _onerror(event: Event) {\n if (this.readyState === 1) {\n this.readyState = 0;\n this.onerror(event);\n }\n\n if (this._eventSource) {\n if(this._eventSource.readyState === 2) {\n // reconnect with new object\n this._eventSource.close();\n this._eventSource = null;\n\n // reconnect after random timeout < max_retry_time\n const timeout = Math.round(this.max_retry_time * Math.random());\n this._timer = setTimeout(() => this._start(), timeout);\n }\n }\n }\n\n _onevent(event: Event) {\n if (event instanceof MessageEvent) {\n this._lastEventId = event.lastEventId;\n }\n\n const listenersForType = this._listeners[event.type];\n if (listenersForType != null) {\n // operate on a copy\n for (const listener of [...listenersForType]) {\n listener.call(this, event);\n }\n }\n\n if (event.type === 'message') {\n this.onmessage(event as MessageEvent);\n }\n }\n\n onopen(event: Event) {\n // may be overridden\n }\n\n onerror(event: Event) {\n // may be overridden\n }\n\n onmessage(event: MessageEvent) {\n // may be overridden\n }\n\n close() {\n if (this._timer) {\n clearTimeout(this._timer);\n this._timer = null;\n }\n\n if (this._eventSource) {\n this._eventSource.close();\n this._eventSource = null;\n }\n\n this.readyState = 2;\n }\n\n addEventListener<K extends keyof EventSourceEventMap>(type: K, listener: (this: EventSource, ev: EventSourceEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;\n addEventListener(type: string, listener: (this: EventSource, event: MessageEvent<any>) => any, options?: boolean | AddEventListenerOptions): void;\n addEventListener<K extends string>(type: K, listener: EventListenerType<K>, options?: boolean | AddEventListenerOptions): void {\n // We don't support the options arg at the moment\n\n if (!(type in this._listeners)) {\n this._listeners[type] = [];\n if (this._eventSource != null) {\n this._eventSource.addEventListener(type, this._onevent_wrapped);\n }\n }\n\n const listenersForType = this._listeners[type] as EventListenerType<K>[];\n if (Array.isArray(listenersForType) && !listenersForType.includes(listener)) {\n listenersForType.push(listener);\n }\n }\n\n removeEventListener<K extends keyof EventSourceEventMap>(type: K, listener: (this: EventSource, ev: EventSourceEventMap[K]) => any, options?: boolean | EventListenerOptions): void;\n removeEventListener(type: string, listener: (this: EventSource, event: MessageEvent<any>) => any, options?: boolean | EventListenerOptions): void;\n removeEventListener<K extends string>(type: K, listener: EventListenerType<K>, options?: boolean | EventListenerOptions): void {\n // We don't support the options arg at the moment\n\n const listenersForType = this._listeners[type] as EventListenerType<K>[];\n if (listenersForType != null) {\n // eslint-disable-next-line no-constant-condition\n while(true) {\n const index = listenersForType.indexOf(listener);\n if (index === -1) {\n break;\n }\n listenersForType.splice(index, 1);\n }\n\n if (listenersForType.length <= 0) {\n delete this._listeners[type];\n if (this._eventSource != null) {\n this._eventSource.removeEventListener(type, this._onevent_wrapped);\n }\n }\n }\n }\n}\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","import ReconnectingEventSource, { EventSourceNotAvailableError } from './reconnecting-eventsource';\nObject.assign(window, {\n ReconnectingEventSource,\n EventSourceNotAvailableError,\n});\n"],"names":["EventSourceNotAvailableError","Error","constructor","super","ReconnectingEventSource","url","configuration","CONNECTING","OPEN","CLOSED","this","_configuration","Object","assign","undefined","withCredentials","_eventSource","_lastEventId","_timer","_listeners","toString","readyState","max_retry_time","eventSourceClass","globalThis","EventSource","lastEventId","_onevent_wrapped","event","_onevent","_start","dispatchEvent","indexOf","encodeURIComponent","onopen","_onopen","onerror","_onerror","onmessage","type","keys","addEventListener","close","timeout","Math","round","random","setTimeout","MessageEvent","listenersForType","listener","call","clearTimeout","options","Array","isArray","includes","push","removeEventListener","index","splice","length","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","exports","module","__webpack_modules__","window"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"ReconnectingEventSource.min.js","mappings":"yJAmCA,MAAaA,UAAqCC,MAC9CC,cACIC,MACE,0MAIN,EAPJ,iCAiBA,MAAqBC,EAyBjBF,YAAYG,EAAmBC,GA+B3B,GArDK,KAAAC,WAAa,EACb,KAAAC,KAAO,EACP,KAAAC,OAAS,EAqBdC,KAAKC,eAAkC,MAAjBL,EAAwBM,OAAOC,OAAO,CAAC,EAAGP,QAAiBQ,EACjFJ,KAAKK,iBAAkB,EAEvBL,KAAKM,aAAe,KACpBN,KAAKO,aAAe,KACpBP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,EAAiBY,QAAU,WACpBnD,KAAKS,WAAWoB,GACE,MAArB7B,KAAKM,cACLN,KAAKM,aAAa0C,oBAAoBnB,EAAM7B,KAAKiB,kB,CAIjE,EA5MJ,YAQoB,EAAApB,WAAa,EACb,EAAAC,KAAO,EACP,EAAAC,OAAS,C,GC7DzBqD,EAA2B,CAAC,EAGhC,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBlD,IAAjBmD,EACH,OAAOA,EAAaC,QAGrB,IAAIC,EAASL,EAAyBE,GAAY,CAGjDE,QAAS,CAAC,GAOX,OAHAE,EAAoBJ,GAAUG,EAAQA,EAAOD,QAASH,GAG/CI,EAAOD,OACf,C,wECtBA,cACAtD,OAAOC,OAAOW,WAAY,CACxBpB,wBAAA,UACAJ,6BAAA,EAAAA,8B","sources":["webpack://_ReconnectingEventSource/./src/reconnecting-eventsource.ts","webpack://_ReconnectingEventSource/webpack/bootstrap","webpack://_ReconnectingEventSource/./src/main.browser.ts"],"sourcesContent":["// MIT License:\n//\n// Copyright (C) 2022 Fanout, Inc.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to\n// deal in the Software without restriction, including without limitation the\n// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n// sell copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n// IN THE SOFTWARE.\n\nexport interface ReconnectingEventSourceInit extends EventSourceInit {\n // the maximum time to wait before attempting to reconnect in ms, default `3000`\n // note: wait time is randomised to prevent all clients from attempting to reconnect simultaneously\n max_retry_time?: number;\n\n // the EventSource class to wrap. This allows the use of a polyfill or alternate\n // implementation instead of the platform-provided EventSource class.\n eventSourceClass?: typeof EventSource;\n\n // the last event\n lastEventId?: string;\n}\n\nexport class EventSourceNotAvailableError extends Error {\n constructor() {\n super(\n 'EventSource not available.\\n' +\n 'Consider loading an EventSource polyfill and making it available globally as EventSource, ' +\n 'or passing one in as eventSourceClass to the ReconnectingEventSource constructor.'\n );\n }\n}\n\ntype EventType<T extends string> = T extends keyof EventSourceEventMap ? EventSourceEventMap[T] : MessageEvent<any>;\ntype EventListenerType<T extends string> = (this: EventSource, event: EventType<T>) => any;\n\ntype Listeners = {\n [name: string]: ((this: EventSource, event: Event) => any)[];\n};\n\nexport default class ReconnectingEventSource implements EventSource {\n\n readonly _configuration: ReconnectingEventSourceInit | undefined;\n readonly CONNECTING = 0;\n readonly OPEN = 1;\n readonly CLOSED = 2;\n\n // Evidently these are to exist both on the class and the instance\n static readonly CONNECTING = 0;\n static readonly OPEN = 1;\n static readonly CLOSED = 2;\n\n _eventSource: EventSource | null;\n _lastEventId: string | null;\n _timer: NodeJS.Timer | null;\n _listeners: Listeners;\n _onevent_wrapped: (this: EventSource, ev: Event) => any;\n\n readyState: 0 | 1 | 2;\n url: string;\n withCredentials: boolean;\n\n readonly max_retry_time: number;\n eventSourceClass: typeof EventSource;\n\n constructor(url: string | URL, configuration?: ReconnectingEventSourceInit) {\n this._configuration = configuration != null ? Object.assign({}, configuration) : undefined;\n this.withCredentials = false;\n\n this._eventSource = null;\n this._lastEventId = null;\n this._timer = null;\n this._listeners = {};\n\n this.url = url.toString();\n this.readyState = this.CONNECTING;\n this.max_retry_time = 3000;\n this.eventSourceClass = globalThis.EventSource;\n\n if (this._configuration != null) {\n if (this._configuration.lastEventId) {\n this._lastEventId = this._configuration.lastEventId;\n delete this._configuration['lastEventId'];\n }\n\n if (this._configuration.max_retry_time) {\n this.max_retry_time = this._configuration.max_retry_time;\n delete this._configuration['max_retry_time'];\n }\n\n if (this._configuration.eventSourceClass) {\n this.eventSourceClass = this._configuration.eventSourceClass;\n delete this._configuration['eventSourceClass'];\n }\n }\n\n if(this.eventSourceClass == null || typeof this.eventSourceClass !== 'function') {\n throw new EventSourceNotAvailableError();\n }\n\n this._onevent_wrapped = (event) => { this._onevent(event); };\n\n this._start();\n }\n\n dispatchEvent(event: Event): boolean {\n throw new Error(\"Method not implemented.\");\n }\n\n _start() {\n let url = this.url;\n\n if (this._lastEventId) {\n if (url.indexOf('?') === -1) {\n url += '?';\n } else {\n url += '&';\n }\n url += 'lastEventId=' + encodeURIComponent(this._lastEventId);\n }\n\n this._eventSource = new this.eventSourceClass(url, this._configuration);\n\n this._eventSource.onopen = (event) => { this._onopen(event); };\n this._eventSource.onerror = (event) => { this._onerror(event); };\n this._eventSource.onmessage = (event) => { this.onmessage(event); };\n\n // apply listen types\n for (const type of Object.keys(this._listeners)) {\n this._eventSource.addEventListener(type, this._onevent_wrapped);\n }\n }\n\n _onopen(event: Event) {\n if (this.readyState === 0) {\n this.readyState = 1;\n this.onopen(event);\n }\n }\n\n _onerror(event: Event) {\n if (this.readyState === 1) {\n this.readyState = 0;\n this.onerror(event);\n }\n\n if (this._eventSource) {\n if(this._eventSource.readyState === 2) {\n // reconnect with new object\n this._eventSource.close();\n this._eventSource = null;\n\n // reconnect after random timeout < max_retry_time\n const timeout = Math.round(this.max_retry_time * Math.random());\n this._timer = setTimeout(() => this._start(), timeout);\n }\n }\n }\n\n _onevent(event: Event) {\n if (event instanceof MessageEvent) {\n this._lastEventId = event.lastEventId;\n }\n\n const listenersForType = this._listeners[event.type];\n if (listenersForType != null) {\n // operate on a copy\n for (const listener of [...listenersForType]) {\n listener.call(this, event);\n }\n }\n\n if (event.type === 'message') {\n this.onmessage(event as MessageEvent);\n }\n }\n\n onopen(event: Event) {\n // may be overridden\n }\n\n onerror(event: Event) {\n // may be overridden\n }\n\n onmessage(event: MessageEvent) {\n // may be overridden\n }\n\n close() {\n if (this._timer) {\n clearTimeout(this._timer);\n this._timer = null;\n }\n\n if (this._eventSource) {\n this._eventSource.close();\n this._eventSource = null;\n }\n\n this.readyState = 2;\n }\n\n addEventListener<K extends keyof EventSourceEventMap>(type: K, listener: (this: EventSource, ev: EventSourceEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;\n addEventListener(type: string, listener: (this: EventSource, event: MessageEvent<any>) => any, options?: boolean | AddEventListenerOptions): void;\n addEventListener<K extends string>(type: K, listener: EventListenerType<K>, options?: boolean | AddEventListenerOptions): void {\n // We don't support the options arg at the moment\n\n if (!(type in this._listeners)) {\n this._listeners[type] = [];\n if (this._eventSource != null) {\n this._eventSource.addEventListener(type, this._onevent_wrapped);\n }\n }\n\n const listenersForType = this._listeners[type] as EventListenerType<K>[];\n if (Array.isArray(listenersForType) && !listenersForType.includes(listener)) {\n listenersForType.push(listener);\n }\n }\n\n removeEventListener<K extends keyof EventSourceEventMap>(type: K, listener: (this: EventSource, ev: EventSourceEventMap[K]) => any, options?: boolean | EventListenerOptions): void;\n removeEventListener(type: string, listener: (this: EventSource, event: MessageEvent<any>) => any, options?: boolean | EventListenerOptions): void;\n removeEventListener<K extends string>(type: K, listener: EventListenerType<K>, options?: boolean | EventListenerOptions): void {\n // We don't support the options arg at the moment\n\n const listenersForType = this._listeners[type] as EventListenerType<K>[];\n if (listenersForType != null) {\n // eslint-disable-next-line no-constant-condition\n while(true) {\n const index = listenersForType.indexOf(listener);\n if (index === -1) {\n break;\n }\n listenersForType.splice(index, 1);\n }\n\n if (listenersForType.length <= 0) {\n delete this._listeners[type];\n if (this._eventSource != null) {\n this._eventSource.removeEventListener(type, this._onevent_wrapped);\n }\n }\n }\n }\n}\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","import ReconnectingEventSource, { EventSourceNotAvailableError } from './reconnecting-eventsource';\nObject.assign(globalThis, {\n ReconnectingEventSource,\n EventSourceNotAvailableError,\n});\n"],"names":["EventSourceNotAvailableError","Error","constructor","super","ReconnectingEventSource","url","configuration","CONNECTING","OPEN","CLOSED","this","_configuration","Object","assign","undefined","withCredentials","_eventSource","_lastEventId","_timer","_listeners","toString","readyState","max_retry_time","eventSourceClass","globalThis","EventSource","lastEventId","_onevent_wrapped","event","_onevent","_start","dispatchEvent","indexOf","encodeURIComponent","onopen","_onopen","onerror","_onerror","onmessage","type","keys","addEventListener","close","timeout","Math","round","random","setTimeout","MessageEvent","listenersForType","listener","call","clearTimeout","options","Array","isArray","includes","push","removeEventListener","index","splice","length","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","exports","module","__webpack_modules__"],"sourceRoot":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reconnecting-eventsource",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.3",
|
|
4
4
|
"description": "wrapper library around the JavaScript EventSource API to ensure it maintains a connection to the server.",
|
|
5
5
|
"main": "./build/src/reconnecting-eventsource.js",
|
|
6
6
|
"exports": {
|