event-source-polyfill 1.0.21 → 1.0.22
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 +14 -2
- package/package.json +1 -1
- package/src/eventsource.js +2 -1
- package/src/eventsource.min.js +2 -2
package/README.md
CHANGED
|
@@ -52,9 +52,9 @@ Browser support:
|
|
|
52
52
|
----------------
|
|
53
53
|
|
|
54
54
|
* IE 10+, Firefox 3.5+, Chrome 3+, Safari 4+, Opera 12+
|
|
55
|
-
* IE 8 - IE 9: XDomainRequest is used internally, which has some limitations (2KB padding is required, no way to send cookies, no way to use client certificates)
|
|
55
|
+
* IE 8 - IE 9: XDomainRequest is used internally, which has some limitations (2KB padding in the beginning is required, no way to send cookies, no way to use client certificates)
|
|
56
56
|
* It works on Mobile Safari, Opera Mobile, Chrome for Android, Firefox for Android
|
|
57
|
-
* It does not work on: Android Browser(requires 4 KB padding), Opera Mini
|
|
57
|
+
* It does not work on: Android Browser(requires 4 KB padding after every chunk), Opera Mini
|
|
58
58
|
|
|
59
59
|
Advantages:
|
|
60
60
|
-----------
|
|
@@ -93,6 +93,18 @@ var es = new EventSourcePolyfill('/events', {
|
|
|
93
93
|
});
|
|
94
94
|
```
|
|
95
95
|
|
|
96
|
+
Custom query parameter name for the last event id:
|
|
97
|
+
---------------
|
|
98
|
+
* Some server require a special query parameter name for last-event-id, you can change that via option
|
|
99
|
+
* The default is `lastEventId`
|
|
100
|
+
* Example for mercure-hub (https://mercure.rocks/)
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
var es = new EventSourcePolyfill(hubUrl, {
|
|
104
|
+
lastEventIdQueryParameterName: 'Last-Event-Id'
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
96
108
|
Other EventSource polyfills:
|
|
97
109
|
----------------------------
|
|
98
110
|
|
package/package.json
CHANGED
package/src/eventsource.js
CHANGED
|
@@ -736,6 +736,7 @@
|
|
|
736
736
|
function start(es, url, options) {
|
|
737
737
|
url = String(url);
|
|
738
738
|
var withCredentials = Boolean(options.withCredentials);
|
|
739
|
+
var lastEventIdQueryParameterName = options.lastEventIdQueryParameterName || "lastEventId";
|
|
739
740
|
|
|
740
741
|
var initialRetry = clampDuration(1000);
|
|
741
742
|
var heartbeatTimeout = parseDuration(options.heartbeatTimeout, 45000);
|
|
@@ -967,7 +968,7 @@
|
|
|
967
968
|
var requestURL = url;
|
|
968
969
|
if (url.slice(0, 5) !== "data:" && url.slice(0, 5) !== "blob:") {
|
|
969
970
|
if (lastEventId !== "") {
|
|
970
|
-
requestURL += (url.indexOf("?") === -1 ? "?" : "&") + "
|
|
971
|
+
requestURL += (url.indexOf("?") === -1 ? "?" : "&") + lastEventIdQueryParameterName +"=" + encodeURIComponent(lastEventId);
|
|
971
972
|
}
|
|
972
973
|
}
|
|
973
974
|
var withCredentials = es.withCredentials;
|
package/src/eventsource.min.js
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
* eventsource.js
|
|
3
3
|
* Available under MIT License (MIT)
|
|
4
4
|
* https://github.com/Yaffle/EventSource/
|
|
5
|
-
*/
|
|
6
|
-
!function(a){"use strict";function b(){this.bitsNeeded=0,this.codePoint=0}function c(a){this.withCredentials=!1,this.readyState=0,this.status=0,this.statusText="",this.responseText="",this.onprogress=G,this.onload=G,this.onerror=G,this.onreadystatechange=G,this._contentType="",this._xhr=a,this._sendTimeout=0,this._abort=G}function d(a){return a.replace(/[A-Z]/g,function(a){return String.fromCharCode(a.charCodeAt(0)+32)})}function e(a){for(var b=Object.create(null),c=a.split("\r\n"),e=0;e<c.length;e+=1){var f=c[e],g=f.split(": "),h=g.shift(),i=g.join(": ");b[d(h)]=i}this._map=b}function f(){}function g(a){this._headers=a}function h(){}function i(){this._listeners=Object.create(null)}function j(a){r(function(){throw a},0)}function k(a){this.type=a,this.target=void 0}function l(a,b){k.call(this,a),this.data=b.data,this.lastEventId=b.lastEventId}function m(a,b){k.call(this,a),this.status=b.status,this.statusText=b.statusText,this.headers=b.headers}function n(a,b){k.call(this,a),this.error=b.error}function o(a,b){i.call(this),b=b||{},this.onopen=void 0,this.onmessage=void 0,this.onerror=void 0,this.url=void 0,this.readyState=void 0,this.withCredentials=void 0,this.headers=void 0,this._close=void 0,q(this,a,b)}function p(){return void 0!=t&&"withCredentials"in t.prototype||void 0==u?new t:new u}function q(a,b,d){b=String(b);var e=Boolean(d.withCredentials),g=U(1e3),i=T(d.heartbeatTimeout,45e3),j="",k=g,o=!1,q=0,t=d.headers||{},u=d.Transport,v=W&&void 0==u?void 0:new c(void 0!=u?new u:p()),w=null!=u&&"string"!=typeof u?new u:void 0==v?new h:new f,x=void 0,y=0,z=H,A="",B="",C="",D="",E=M,F=0,G=0,R=function(b,c,d,e){if(z===I)if(200===b&&void 0!=d&&Q.test(d)){z=J,o=Date.now(),k=g,a.readyState=J;var f=new m("open",{status:b,statusText:c,headers:e});a.dispatchEvent(f),V(a,a.onopen,f)}else{var h="";200!==b?(c&&(c=c.replace(/\s+/g," ")),h="EventSource's response has a status "+b+" "+c+" that is not 200. Aborting the connection."):h="EventSource's response has a Content-Type specifying an unsupported type: "+(void 0==d?"-":d.replace(/\s+/g," "))+". Aborting the connection.",Y();var f=new m("error",{status:b,statusText:c,headers:e});a.dispatchEvent(f),V(a,a.onerror,f)}},S=function(b){if(z===J){for(var c=-1,d=0;d<b.length;d+=1){var e=b.charCodeAt(d);(e==="\n".charCodeAt(0)||e==="\r".charCodeAt(0))&&(c=d)}var f=(-1!==c?D:"")+b.slice(0,c+1);D=(-1===c?D:"")+b.slice(c+1),""!==b&&(o=Date.now(),q+=b.length);for(var h=0;h<f.length;h+=1){var e=f.charCodeAt(h);if(E===L&&e==="\n".charCodeAt(0))E=M;else if(E===L&&(E=M),e==="\r".charCodeAt(0)||e==="\n".charCodeAt(0)){if(E!==M){E===N&&(G=h+1);var m=f.slice(F,G-1),n=f.slice(G+(h>G&&f.charCodeAt(G)===" ".charCodeAt(0)?1:0),h);"data"===m?(A+="\n",A+=n):"id"===m?B=n:"event"===m?C=n:"retry"===m?(g=T(n,g),k=g):"heartbeatTimeout"===m&&(i=T(n,i),0!==y&&(s(y),y=r(function(){Z()},i)))}if(E===M){if(""!==A){j=B,""===C&&(C="message");var p=new l(C,{data:A.slice(1),lastEventId:B});if(a.dispatchEvent(p),"open"===C?V(a,a.onopen,p):"message"===C?V(a,a.onmessage,p):"error"===C&&V(a,a.onerror,p),z===K)return}A="",C=""}E=e==="\r".charCodeAt(0)?L:M}else E===M&&(F=h,E=N),E===N?e===":".charCodeAt(0)&&(G=h+1,E=O):E===O&&(E=P)}}},X=function(b){if(z===J||z===I){z=H,0!==y&&(s(y),y=0),y=r(function(){Z()},k),k=U(Math.min(16*g,2*k)),a.readyState=I;var c=new n("error",{error:b});a.dispatchEvent(c),V(a,a.onerror,c)}},Y=function(){z=K,void 0!=x&&(x.abort(),x=void 0),0!==y&&(s(y),y=0),a.readyState=K},Z=function(){if(y=0,z===H){o=!1,q=0,y=r(function(){Z()},i),z=I,A="",C="",B=j,D="",F=0,G=0,E=M;var c=b;"data:"!==b.slice(0,5)&&"blob:"!==b.slice(0,5)&&""!==j&&(c+=(-1===b.indexOf("?")?"?":"&")+"lastEventId="+encodeURIComponent(j));var d=a.withCredentials,e={};e.Accept="text/event-stream";var f=a.headers;if(void 0!=f)for(var g in f)Object.prototype.hasOwnProperty.call(f,g)&&(e[g]=f[g]);try{x=w.open(v,R,S,X,c,d,e)}catch(h){throw Y(),h}}else if(o||void 0==x){var k=Math.max((o||Date.now())+i-Date.now(),1);o=!1,y=r(function(){Z()},k)}else X(new Error("No activity within "+i+" milliseconds. "+(z===I?"No response received.":q+" chars received.")+" Reconnecting.")),void 0!=x&&(x.abort(),x=void 0)};a.url=b,a.readyState=I,a.withCredentials=e,a.headers=t,a._close=Y,Z()}var r=a.setTimeout,s=a.clearTimeout,t=a.XMLHttpRequest,u=a.XDomainRequest,v=a.ActiveXObject,w=a.EventSource,x=a.document,y=a.Promise,z=a.fetch,A=a.Response,B=a.TextDecoder,C=a.TextEncoder,D=a.AbortController;if("undefined"==typeof window||"readyState"in x||null!=x.body||(x.readyState="loading",window.addEventListener("load",function(a){x.readyState="complete"},!1)),null==t&&null!=v&&(t=function(){return new v("Microsoft.XMLHTTP")}),void 0==Object.create&&(Object.create=function(a){function b(){}return b.prototype=a,new b}),Date.now||(Date.now=function(){return(new Date).getTime()}),void 0==D){var E=z;z=function(a,b){var c=b.signal;return E(a,{headers:b.headers,credentials:b.credentials,cache:b.cache}).then(function(a){var b=a.body.getReader();return c._reader=b,c._aborted&&c._reader.cancel(),{status:a.status,statusText:a.statusText,headers:a.headers,body:{getReader:function(){return b}}}})},D=function(){this.signal={_reader:null,_aborted:!1},this.abort=function(){null!=this.signal._reader&&this.signal._reader.cancel(),this.signal._aborted=!0}}}b.prototype.decode=function(a){function b(a,b,c){if(1===c)return a>=128>>b&&2047>=a<<b;if(2===c)return a>=2048>>b&&55295>=a<<b||a>=57344>>b&&65535>=a<<b;if(3===c)return a>=65536>>b&&1114111>=a<<b;throw new Error}function c(a,b){if(6===a)return b>>6>15?3:b>31?2:1;if(12===a)return b>15?3:2;if(18===a)return 3;throw new Error}for(var d=65533,e="",f=this.bitsNeeded,g=this.codePoint,h=0;h<a.length;h+=1){var i=a[h];0!==f&&(128>i||i>191||!b(g<<6|63&i,f-6,c(f,g)))&&(f=0,g=d,e+=String.fromCharCode(g)),0===f?(i>=0&&127>=i?(f=0,g=i):i>=192&&223>=i?(f=6,g=31&i):i>=224&&239>=i?(f=12,g=15&i):i>=240&&247>=i?(f=18,g=7&i):(f=0,g=d),0===f||b(g,f,c(f,g))||(f=0,g=d)):(f-=6,g=g<<6|63&i),0===f&&(65535>=g?e+=String.fromCharCode(g):(e+=String.fromCharCode(55296+(g-65535-1>>10)),e+=String.fromCharCode(56320+(g-65535-1&1023))))}return this.bitsNeeded=f,this.codePoint=g,e};var F=function(){try{return"test"===(new B).decode((new C).encode("test"),{stream:!0})}catch(a){}return!1};void 0!=B&&void 0!=C&&F()||(B=b);var G=function(){};c.prototype.open=function(a,b){this._abort(!0);var c=this,d=this._xhr,e=1,f=0;this._abort=function(a){0!==c._sendTimeout&&(s(c._sendTimeout),c._sendTimeout=0),(1===e||2===e||3===e)&&(e=4,d.onload=G,d.onerror=G,d.onabort=G,d.onprogress=G,d.onreadystatechange=G,d.abort(),0!==f&&(s(f),f=0),a||(c.readyState=4,c.onabort(null),c.onreadystatechange())),e=0};var g=function(){if(1===e){var a=0,b="",f=void 0;if("contentType"in d)a=200,b="OK",f=d.contentType;else try{a=d.status,b=d.statusText,f=d.getResponseHeader("Content-Type")}catch(g){a=0,b="",f=void 0}0!==a&&(e=2,c.readyState=2,c.status=a,c.statusText=b,c._contentType=f,c.onreadystatechange())}},h=function(){if(g(),2===e||3===e){e=3;var a="";try{a=d.responseText}catch(b){}c.readyState=3,c.responseText=a,c.onprogress()}},i=function(a,b){if((null==b||null==b.preventDefault)&&(b={preventDefault:G}),h(),1===e||2===e||3===e){if(e=4,0!==f&&(s(f),f=0),c.readyState=4,"load"===a)c.onload(b);else if("error"===a)c.onerror(b);else{if("abort"!==a)throw new TypeError;c.onabort(b)}c.onreadystatechange()}},j=function(a){void 0!=d&&(4===d.readyState?"onload"in d&&"onerror"in d&&"onabort"in d||i(""===d.responseText?"error":"load",a):3===d.readyState?"onprogress"in d||h():2===d.readyState&&g())},k=function(){f=r(function(){k()},500),3===d.readyState&&h()};"onload"in d&&(d.onload=function(a){i("load",a)}),"onerror"in d&&(d.onerror=function(a){i("error",a)}),"onabort"in d&&(d.onabort=function(a){i("abort",a)}),"onprogress"in d&&(d.onprogress=h),"onreadystatechange"in d&&(d.onreadystatechange=function(a){j(a)}),("contentType"in d||!("ontimeout"in t.prototype))&&(b+=(-1===b.indexOf("?")?"?":"&")+"padding=true"),d.open(a,b,!0),"readyState"in d&&(f=r(function(){k()},0))},c.prototype.abort=function(){this._abort(!1)},c.prototype.getResponseHeader=function(a){return this._contentType},c.prototype.setRequestHeader=function(a,b){var c=this._xhr;"setRequestHeader"in c&&c.setRequestHeader(a,b)},c.prototype.getAllResponseHeaders=function(){return void 0!=this._xhr.getAllResponseHeaders?this._xhr.getAllResponseHeaders()||"":""},c.prototype.send=function(){if(!("ontimeout"in t.prototype&&("sendAsBinary"in t.prototype||"mozAnon"in t.prototype)||void 0==x||void 0==x.readyState||"complete"===x.readyState)){var a=this;return void(a._sendTimeout=r(function(){a._sendTimeout=0,a.send()},4))}var b=this._xhr;"withCredentials"in b&&(b.withCredentials=this.withCredentials);try{b.send(void 0)}catch(c){throw c}},e.prototype.get=function(a){return this._map[d(a)]},null!=t&&null==t.HEADERS_RECEIVED&&(t.HEADERS_RECEIVED=2),f.prototype.open=function(a,b,c,d,f,g,h){a.open("GET",f);var i=0;a.onprogress=function(){var b=a.responseText,d=b.slice(i);i+=d.length,c(d)},a.onerror=function(a){a.preventDefault(),d(new Error("NetworkError"))},a.onload=function(){d(null)},a.onabort=function(){d(null)},a.onreadystatechange=function(){if(a.readyState===t.HEADERS_RECEIVED){var c=a.status,d=a.statusText,f=a.getResponseHeader("Content-Type"),g=a.getAllResponseHeaders();b(c,d,f,new e(g))}},a.withCredentials=g;for(var j in h)Object.prototype.hasOwnProperty.call(h,j)&&a.setRequestHeader(j,h[j]);return a.send(),a},g.prototype.get=function(a){return this._headers.get(a)},h.prototype.open=function(a,b,c,d,e,f,h){var i=null,j=new D,k=j.signal,l=new B;return z(e,{headers:h,credentials:f?"include":"same-origin",signal:k,cache:"no-store"}).then(function(a){return i=a.body.getReader(),b(a.status,a.statusText,a.headers.get("Content-Type"),new g(a.headers)),new y(function(a,b){var d=function(){i.read().then(function(b){if(b.done)a(void 0);else{var e=l.decode(b.value,{stream:!0});c(e),d()}})["catch"](function(a){b(a)})};d()})})["catch"](function(a){return"AbortError"===a.name?void 0:a}).then(function(a){d(a)}),{abort:function(){null!=i&&i.cancel(),j.abort()}}},i.prototype.dispatchEvent=function(a){a.target=this;var b=this._listeners[a.type];if(void 0!=b)for(var c=b.length,d=0;c>d;d+=1){var e=b[d];try{"function"==typeof e.handleEvent?e.handleEvent(a):e.call(this,a)}catch(f){j(f)}}},i.prototype.addEventListener=function(a,b){a=String(a);var c=this._listeners,d=c[a];void 0==d&&(d=[],c[a]=d);for(var e=!1,f=0;f<d.length;f+=1)d[f]===b&&(e=!0);e||d.push(b)},i.prototype.removeEventListener=function(a,b){a=String(a);var c=this._listeners,d=c[a];if(void 0!=d){for(var e=[],f=0;f<d.length;f+=1)d[f]!==b&&e.push(d[f]);0===e.length?delete c[a]:c[a]=e}},l.prototype=Object.create(k.prototype),m.prototype=Object.create(k.prototype),n.prototype=Object.create(k.prototype);var H=-1,I=0,J=1,K=2,L=-1,M=0,N=1,O=2,P=3,Q=/^text\/event\-stream(;.*)?$/i,R=1e3,S=18e6,T=function(a,b){var c=null==a?b:parseInt(a,10);return c!==c&&(c=b),U(c)},U=function(a){return Math.min(Math.max(a,R),S)},V=function(a,b,c){try{"function"==typeof b&&b.call(a,c)}catch(d){j(d)}},W=void 0!=z&&void 0!=A&&"body"in A.prototype;o.prototype=Object.create(i.prototype),o.prototype.CONNECTING=I,o.prototype.OPEN=J,o.prototype.CLOSED=K,o.prototype.close=function(){this._close()},o.CONNECTING=I,o.OPEN=J,o.CLOSED=K,o.prototype.withCredentials=void 0;var X=w;void 0==t||void 0!=w&&"withCredentials"in w.prototype||(X=o),function(b){if("object"==typeof module&&"object"==typeof module.exports){var c=b(exports);void 0!==c&&(module.exports=c)}else"function"==typeof define&&define.amd?define(["exports"],b):b(a)}(function(a){a.EventSourcePolyfill=o,a.NativeEventSource=w,a.EventSource=X})}("undefined"==typeof globalThis?"undefined"!=typeof window?window:"undefined"!=typeof self?self:this:globalThis);
|
|
5
|
+
*/
|
|
6
|
+
!function(a){"use strict";function b(){this.bitsNeeded=0,this.codePoint=0}function c(a){this.withCredentials=!1,this.readyState=0,this.status=0,this.statusText="",this.responseText="",this.onprogress=G,this.onload=G,this.onerror=G,this.onreadystatechange=G,this._contentType="",this._xhr=a,this._sendTimeout=0,this._abort=G}function d(a){return a.replace(/[A-Z]/g,function(a){return String.fromCharCode(a.charCodeAt(0)+32)})}function e(a){for(var b=Object.create(null),c=a.split("\r\n"),e=0;e<c.length;e+=1){var f=c[e],g=f.split(": "),h=g.shift(),i=g.join(": ");b[d(h)]=i}this._map=b}function f(){}function g(a){this._headers=a}function h(){}function i(){this._listeners=Object.create(null)}function j(a){r(function(){throw a},0)}function k(a){this.type=a,this.target=void 0}function l(a,b){k.call(this,a),this.data=b.data,this.lastEventId=b.lastEventId}function m(a,b){k.call(this,a),this.status=b.status,this.statusText=b.statusText,this.headers=b.headers}function n(a,b){k.call(this,a),this.error=b.error}function o(a,b){i.call(this),b=b||{},this.onopen=void 0,this.onmessage=void 0,this.onerror=void 0,this.url=void 0,this.readyState=void 0,this.withCredentials=void 0,this.headers=void 0,this._close=void 0,q(this,a,b)}function p(){return void 0!=t&&"withCredentials"in t.prototype||void 0==u?new t:new u}function q(a,b,d){b=String(b);var e=Boolean(d.withCredentials),g=d.lastEventIdQueryParameterName||"lastEventId",i=U(1e3),j=T(d.heartbeatTimeout,45e3),k="",o=i,q=!1,t=0,u=d.headers||{},v=d.Transport,w=W&&void 0==v?void 0:new c(void 0!=v?new v:p()),x=null!=v&&"string"!=typeof v?new v:void 0==w?new h:new f,y=void 0,z=0,A=H,B="",C="",D="",E="",F=M,G=0,R=0,S=function(b,c,d,e){if(A===I)if(200===b&&void 0!=d&&Q.test(d)){A=J,q=Date.now(),o=i,a.readyState=J;var f=new m("open",{status:b,statusText:c,headers:e});a.dispatchEvent(f),V(a,a.onopen,f)}else{var g="";200!==b?(c&&(c=c.replace(/\s+/g," ")),g="EventSource's response has a status "+b+" "+c+" that is not 200. Aborting the connection."):g="EventSource's response has a Content-Type specifying an unsupported type: "+(void 0==d?"-":d.replace(/\s+/g," "))+". Aborting the connection.",Z();var f=new m("error",{status:b,statusText:c,headers:e});a.dispatchEvent(f),V(a,a.onerror,f)}},X=function(b){if(A===J){for(var c=-1,d=0;d<b.length;d+=1){var e=b.charCodeAt(d);(e==="\n".charCodeAt(0)||e==="\r".charCodeAt(0))&&(c=d)}var f=(-1!==c?E:"")+b.slice(0,c+1);E=(-1===c?E:"")+b.slice(c+1),""!==b&&(q=Date.now(),t+=b.length);for(var g=0;g<f.length;g+=1){var e=f.charCodeAt(g);if(F===L&&e==="\n".charCodeAt(0))F=M;else if(F===L&&(F=M),e==="\r".charCodeAt(0)||e==="\n".charCodeAt(0)){if(F!==M){F===N&&(R=g+1);var h=f.slice(G,R-1),m=f.slice(R+(g>R&&f.charCodeAt(R)===" ".charCodeAt(0)?1:0),g);"data"===h?(B+="\n",B+=m):"id"===h?C=m:"event"===h?D=m:"retry"===h?(i=T(m,i),o=i):"heartbeatTimeout"===h&&(j=T(m,j),0!==z&&(s(z),z=r(function(){$()},j)))}if(F===M){if(""!==B){k=C,""===D&&(D="message");var n=new l(D,{data:B.slice(1),lastEventId:C});if(a.dispatchEvent(n),"open"===D?V(a,a.onopen,n):"message"===D?V(a,a.onmessage,n):"error"===D&&V(a,a.onerror,n),A===K)return}B="",D=""}F=e==="\r".charCodeAt(0)?L:M}else F===M&&(G=g,F=N),F===N?e===":".charCodeAt(0)&&(R=g+1,F=O):F===O&&(F=P)}}},Y=function(b){if(A===J||A===I){A=H,0!==z&&(s(z),z=0),z=r(function(){$()},o),o=U(Math.min(16*i,2*o)),a.readyState=I;var c=new n("error",{error:b});a.dispatchEvent(c),V(a,a.onerror,c)}},Z=function(){A=K,void 0!=y&&(y.abort(),y=void 0),0!==z&&(s(z),z=0),a.readyState=K},$=function(){if(z=0,A===H){q=!1,t=0,z=r(function(){$()},j),A=I,B="",D="",C=k,E="",G=0,R=0,F=M;var c=b;"data:"!==b.slice(0,5)&&"blob:"!==b.slice(0,5)&&""!==k&&(c+=(-1===b.indexOf("?")?"?":"&")+g+"="+encodeURIComponent(k));var d=a.withCredentials,e={};e.Accept="text/event-stream";var f=a.headers;if(void 0!=f)for(var h in f)Object.prototype.hasOwnProperty.call(f,h)&&(e[h]=f[h]);try{y=x.open(w,S,X,Y,c,d,e)}catch(i){throw Z(),i}}else if(q||void 0==y){var l=Math.max((q||Date.now())+j-Date.now(),1);q=!1,z=r(function(){$()},l)}else Y(new Error("No activity within "+j+" milliseconds. "+(A===I?"No response received.":t+" chars received.")+" Reconnecting.")),void 0!=y&&(y.abort(),y=void 0)};a.url=b,a.readyState=I,a.withCredentials=e,a.headers=u,a._close=Z,$()}var r=a.setTimeout,s=a.clearTimeout,t=a.XMLHttpRequest,u=a.XDomainRequest,v=a.ActiveXObject,w=a.EventSource,x=a.document,y=a.Promise,z=a.fetch,A=a.Response,B=a.TextDecoder,C=a.TextEncoder,D=a.AbortController;if("undefined"==typeof window||"readyState"in x||null!=x.body||(x.readyState="loading",window.addEventListener("load",function(a){x.readyState="complete"},!1)),null==t&&null!=v&&(t=function(){return new v("Microsoft.XMLHTTP")}),void 0==Object.create&&(Object.create=function(a){function b(){}return b.prototype=a,new b}),Date.now||(Date.now=function(){return(new Date).getTime()}),void 0==D){var E=z;z=function(a,b){var c=b.signal;return E(a,{headers:b.headers,credentials:b.credentials,cache:b.cache}).then(function(a){var b=a.body.getReader();return c._reader=b,c._aborted&&c._reader.cancel(),{status:a.status,statusText:a.statusText,headers:a.headers,body:{getReader:function(){return b}}}})},D=function(){this.signal={_reader:null,_aborted:!1},this.abort=function(){null!=this.signal._reader&&this.signal._reader.cancel(),this.signal._aborted=!0}}}b.prototype.decode=function(a){function b(a,b,c){if(1===c)return a>=128>>b&&2047>=a<<b;if(2===c)return a>=2048>>b&&55295>=a<<b||a>=57344>>b&&65535>=a<<b;if(3===c)return a>=65536>>b&&1114111>=a<<b;throw new Error}function c(a,b){if(6===a)return b>>6>15?3:b>31?2:1;if(12===a)return b>15?3:2;if(18===a)return 3;throw new Error}for(var d=65533,e="",f=this.bitsNeeded,g=this.codePoint,h=0;h<a.length;h+=1){var i=a[h];0!==f&&(128>i||i>191||!b(g<<6|63&i,f-6,c(f,g)))&&(f=0,g=d,e+=String.fromCharCode(g)),0===f?(i>=0&&127>=i?(f=0,g=i):i>=192&&223>=i?(f=6,g=31&i):i>=224&&239>=i?(f=12,g=15&i):i>=240&&247>=i?(f=18,g=7&i):(f=0,g=d),0===f||b(g,f,c(f,g))||(f=0,g=d)):(f-=6,g=g<<6|63&i),0===f&&(65535>=g?e+=String.fromCharCode(g):(e+=String.fromCharCode(55296+(g-65535-1>>10)),e+=String.fromCharCode(56320+(g-65535-1&1023))))}return this.bitsNeeded=f,this.codePoint=g,e};var F=function(){try{return"test"===(new B).decode((new C).encode("test"),{stream:!0})}catch(a){}return!1};void 0!=B&&void 0!=C&&F()||(B=b);var G=function(){};c.prototype.open=function(a,b){this._abort(!0);var c=this,d=this._xhr,e=1,f=0;this._abort=function(a){0!==c._sendTimeout&&(s(c._sendTimeout),c._sendTimeout=0),(1===e||2===e||3===e)&&(e=4,d.onload=G,d.onerror=G,d.onabort=G,d.onprogress=G,d.onreadystatechange=G,d.abort(),0!==f&&(s(f),f=0),a||(c.readyState=4,c.onabort(null),c.onreadystatechange())),e=0};var g=function(){if(1===e){var a=0,b="",f=void 0;if("contentType"in d)a=200,b="OK",f=d.contentType;else try{a=d.status,b=d.statusText,f=d.getResponseHeader("Content-Type")}catch(g){a=0,b="",f=void 0}0!==a&&(e=2,c.readyState=2,c.status=a,c.statusText=b,c._contentType=f,c.onreadystatechange())}},h=function(){if(g(),2===e||3===e){e=3;var a="";try{a=d.responseText}catch(b){}c.readyState=3,c.responseText=a,c.onprogress()}},i=function(a,b){if((null==b||null==b.preventDefault)&&(b={preventDefault:G}),h(),1===e||2===e||3===e){if(e=4,0!==f&&(s(f),f=0),c.readyState=4,"load"===a)c.onload(b);else if("error"===a)c.onerror(b);else{if("abort"!==a)throw new TypeError;c.onabort(b)}c.onreadystatechange()}},j=function(a){void 0!=d&&(4===d.readyState?"onload"in d&&"onerror"in d&&"onabort"in d||i(""===d.responseText?"error":"load",a):3===d.readyState?"onprogress"in d||h():2===d.readyState&&g())},k=function(){f=r(function(){k()},500),3===d.readyState&&h()};"onload"in d&&(d.onload=function(a){i("load",a)}),"onerror"in d&&(d.onerror=function(a){i("error",a)}),"onabort"in d&&(d.onabort=function(a){i("abort",a)}),"onprogress"in d&&(d.onprogress=h),"onreadystatechange"in d&&(d.onreadystatechange=function(a){j(a)}),("contentType"in d||!("ontimeout"in t.prototype))&&(b+=(-1===b.indexOf("?")?"?":"&")+"padding=true"),d.open(a,b,!0),"readyState"in d&&(f=r(function(){k()},0))},c.prototype.abort=function(){this._abort(!1)},c.prototype.getResponseHeader=function(a){return this._contentType},c.prototype.setRequestHeader=function(a,b){var c=this._xhr;"setRequestHeader"in c&&c.setRequestHeader(a,b)},c.prototype.getAllResponseHeaders=function(){return void 0!=this._xhr.getAllResponseHeaders?this._xhr.getAllResponseHeaders()||"":""},c.prototype.send=function(){if(!("ontimeout"in t.prototype&&("sendAsBinary"in t.prototype||"mozAnon"in t.prototype)||void 0==x||void 0==x.readyState||"complete"===x.readyState)){var a=this;return void(a._sendTimeout=r(function(){a._sendTimeout=0,a.send()},4))}var b=this._xhr;"withCredentials"in b&&(b.withCredentials=this.withCredentials);try{b.send(void 0)}catch(c){throw c}},e.prototype.get=function(a){return this._map[d(a)]},null!=t&&null==t.HEADERS_RECEIVED&&(t.HEADERS_RECEIVED=2),f.prototype.open=function(a,b,c,d,f,g,h){a.open("GET",f);var i=0;a.onprogress=function(){var b=a.responseText,d=b.slice(i);i+=d.length,c(d)},a.onerror=function(a){a.preventDefault(),d(new Error("NetworkError"))},a.onload=function(){d(null)},a.onabort=function(){d(null)},a.onreadystatechange=function(){if(a.readyState===t.HEADERS_RECEIVED){var c=a.status,d=a.statusText,f=a.getResponseHeader("Content-Type"),g=a.getAllResponseHeaders();b(c,d,f,new e(g))}},a.withCredentials=g;for(var j in h)Object.prototype.hasOwnProperty.call(h,j)&&a.setRequestHeader(j,h[j]);return a.send(),a},g.prototype.get=function(a){return this._headers.get(a)},h.prototype.open=function(a,b,c,d,e,f,h){var i=null,j=new D,k=j.signal,l=new B;return z(e,{headers:h,credentials:f?"include":"same-origin",signal:k,cache:"no-store"}).then(function(a){return i=a.body.getReader(),b(a.status,a.statusText,a.headers.get("Content-Type"),new g(a.headers)),new y(function(a,b){var d=function(){i.read().then(function(b){if(b.done)a(void 0);else{var e=l.decode(b.value,{stream:!0});c(e),d()}})["catch"](function(a){b(a)})};d()})})["catch"](function(a){return"AbortError"===a.name?void 0:a}).then(function(a){d(a)}),{abort:function(){null!=i&&i.cancel(),j.abort()}}},i.prototype.dispatchEvent=function(a){a.target=this;var b=this._listeners[a.type];if(void 0!=b)for(var c=b.length,d=0;c>d;d+=1){var e=b[d];try{"function"==typeof e.handleEvent?e.handleEvent(a):e.call(this,a)}catch(f){j(f)}}},i.prototype.addEventListener=function(a,b){a=String(a);var c=this._listeners,d=c[a];void 0==d&&(d=[],c[a]=d);for(var e=!1,f=0;f<d.length;f+=1)d[f]===b&&(e=!0);e||d.push(b)},i.prototype.removeEventListener=function(a,b){a=String(a);var c=this._listeners,d=c[a];if(void 0!=d){for(var e=[],f=0;f<d.length;f+=1)d[f]!==b&&e.push(d[f]);0===e.length?delete c[a]:c[a]=e}},l.prototype=Object.create(k.prototype),m.prototype=Object.create(k.prototype),n.prototype=Object.create(k.prototype);var H=-1,I=0,J=1,K=2,L=-1,M=0,N=1,O=2,P=3,Q=/^text\/event\-stream(;.*)?$/i,R=1e3,S=18e6,T=function(a,b){var c=null==a?b:parseInt(a,10);return c!==c&&(c=b),U(c)},U=function(a){return Math.min(Math.max(a,R),S)},V=function(a,b,c){try{"function"==typeof b&&b.call(a,c)}catch(d){j(d)}},W=void 0!=z&&void 0!=A&&"body"in A.prototype;o.prototype=Object.create(i.prototype),o.prototype.CONNECTING=I,o.prototype.OPEN=J,o.prototype.CLOSED=K,o.prototype.close=function(){this._close()},o.CONNECTING=I,o.OPEN=J,o.CLOSED=K,o.prototype.withCredentials=void 0;var X=w;void 0==t||void 0!=w&&"withCredentials"in w.prototype||(X=o),function(b){if("object"==typeof module&&"object"==typeof module.exports){var c=b(exports);void 0!==c&&(module.exports=c)}else"function"==typeof define&&define.amd?define(["exports"],b):b(a)}(function(a){a.EventSourcePolyfill=o,a.NativeEventSource=w,a.EventSource=X})}("undefined"==typeof globalThis?"undefined"!=typeof window?window:"undefined"!=typeof self?self:this:globalThis);
|