event-source-polyfill.js 9.8 KB

1234567
  1. webpackJsonp([0],{"./node_modules/event-source-polyfill/src/eventsource.js":function(t,e){/** @license
  2. * eventsource.js
  3. * Available under MIT License (MIT)
  4. * https://github.com/Yaffle/EventSource/
  5. */
  6. !function(t){"use strict";function e(){this.bitsNeeded=0,this.codePoint=0}function n(t){this.withCredentials=!1,this.responseType="",this.readyState=0,this.status=0,this.statusText="",this.responseText="",this.onprogress=A,this.onreadystatechange=A,this._contentType="",this._xhr=t,this._sendTimeout=0,this._abort=A}function o(t){return t.replace(/[A-Z]/g,function(t){return String.fromCharCode(t.charCodeAt(0)+32)})}function r(t){for(var e=Object.create(null),n=t.split("\r\n"),r=0;r<n.length;r+=1){var i=n[r],s=i.split(": "),a=s.shift(),c=s.join(": ");e[o(a)]=c}this._map=e}function i(){}function s(t){this._headers=t}function a(){}function c(){this._listeners=Object.create(null)}function d(t){y(function(){throw t},0)}function h(t){this.type=t,this.target=void 0}function u(t,e){h.call(this,t),this.data=e.data,this.lastEventId=e.lastEventId}function p(t,e){h.call(this,t),this.status=e.status,this.statusText=e.statusText,this.headers=e.headers}function f(t,e){c.call(this),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._close=void 0,l(this,t,e)}function v(){return T&&"withCredentials"in T.prototype?T:w}function l(t,e,o){e=String(e);var r=void 0!=o&&Boolean(o.withCredentials),s=G(1e3),c=void 0!=o&&void 0!=o.heartbeatTimeout?M(o.heartbeatTimeout,45e3):G(45e3),f="",l=s,T=!1,w=void 0!=o&&void 0!=o.headers?JSON.parse(JSON.stringify(o.headers)):void 0,C=void 0!=o&&void 0!=o.Transport?o.Transport:v(),m=B?void 0:new n(new C),S=B?new a:new i,b=void 0,E=0,_=O,x="",A="",X="",k="",z=P,K=0,U=0,Z=function(e,n,o,r,i){if(_===R)if(b=i,200===e&&void 0!=o&&D.test(o)){_=N,T=!0,l=s,t.readyState=N;var a=new p("open",{status:e,statusText:n,headers:r});t.dispatchEvent(a),J(t,t.onopen,a)}else{var c="";200!==e?(n&&(n=n.replace(/\s+/g," ")),c="EventSource's response has a status "+e+" "+n+" that is not 200. Aborting the connection."):c="EventSource's response has a Content-Type specifying an unsupported type: "+(void 0==o?"-":o.replace(/\s+/g," "))+". Aborting the connection.",d(new Error(c)),Q();var a=new p("error",{status:e,statusText:n,headers:r});t.dispatchEvent(a),J(t,t.onerror,a)}},$=function(e){if(_===N){for(var n=-1,o=0;o<e.length;o+=1){var r=e.charCodeAt(o);r!=="\n".charCodeAt(0)&&r!=="\r".charCodeAt(0)||(n=o)}var i=(-1!==n?k:"")+e.slice(0,n+1);k=(-1===n?k:"")+e.slice(n+1),""!==i&&(T=!0);for(var a=0;a<i.length;a+=1){var r=i.charCodeAt(a);if(z===j&&r==="\n".charCodeAt(0))z=P;else if(z===j&&(z=P),r==="\r".charCodeAt(0)||r==="\n".charCodeAt(0)){if(z!==P){z===I&&(U=a+1);var d=i.slice(K,U-1),h=i.slice(U+(U<a&&i.charCodeAt(U)===" ".charCodeAt(0)?1:0),a);"data"===d?(x+="\n",x+=h):"id"===d?A=h:"event"===d?X=h:"retry"===d?(s=M(h,s),l=s):"heartbeatTimeout"===d&&(c=M(h,c),0!==E&&(g(E),E=y(function(){V()},c)))}if(z===P){if(""!==x){f=A,""===X&&(X="message");var p=new u(X,{data:x.slice(1),lastEventId:A});if(t.dispatchEvent(p),"message"===X&&J(t,t.onmessage,p),_===H)return}x="",X=""}z=r==="\r".charCodeAt(0)?j:P}else z===P&&(K=a,z=I),z===I?r===":".charCodeAt(0)&&(U=a+1,z=q):z===q&&(z=L)}}},F=function(){if(_===N||_===R){_=O,0!==E&&(g(E),E=0),E=y(function(){V()},l),l=G(Math.min(16*s,2*l)),t.readyState=R;var e=new h("error");t.dispatchEvent(e),J(t,t.onerror,e)}},Q=function(){_=H,void 0!=b&&(b(),b=void 0),0!==E&&(g(E),E=0),t.readyState=H},V=function(){if(E=0,_!==O)return void(T||void 0==b?(T=!1,E=y(function(){V()},c)):(d(new Error("No activity within "+c+" milliseconds. Reconnecting.")),b(),b=void 0));T=!1,E=y(function(){V()},c),_=R,x="",X="",A=f,k="",K=0,U=0,z=P;var t=e;"data:"!==e.slice(0,5)&&"blob:"!==e.slice(0,5)&&""!==f&&(t+=(-1===e.indexOf("?")?"?":"&")+"lastEventId="+encodeURIComponent(f));var n={};if(n.Accept="text/event-stream",void 0!=w)for(var o in w)Object.prototype.hasOwnProperty.call(w,o)&&(n[o]=w[o]);try{S.open(m,Z,$,F,t,r,n)}catch(t){throw Q(),t}};t.url=e,t.readyState=R,t.withCredentials=r,t._close=Q,V()}var y=t.setTimeout,g=t.clearTimeout,T=t.XMLHttpRequest,w=t.XDomainRequest,C=t.EventSource,m=t.document,S=t.Promise,b=t.fetch,E=t.Response,_=t.TextDecoder,x=t.TextEncoder;null==Object.create&&(Object.create=function(t){function e(){}return e.prototype=t,new e}),void 0!=S&&void 0==S.prototype.finally&&(S.prototype.finally=function(t){return this.then(function(e){return S.resolve(t()).then(function(){return e})},function(e){return S.resolve(t()).then(function(){throw e})})}),e.prototype.decode=function(t){function e(t,e,n){if(1===n)return t>=128>>e&&t<<e<=2047;if(2===n)return t>=2048>>e&&t<<e<=55295||t>=57344>>e&&t<<e<=65535;if(3===n)return t>=65536>>e&&t<<e<=1114111;throw new Error}function n(t,e){if(6===t)return e>>6>15?3:e>31?2:1;if(12===t)return e>15?3:2;if(18===t)return 3;throw new Error}for(var o="",r=this.bitsNeeded,i=this.codePoint,s=0;s<t.length;s+=1){var a=t[s];0!==r&&(a<128||a>191||!e(i<<6|63&a,r-6,n(r,i)))&&(r=0,i=65533,o+=String.fromCharCode(i)),0===r?(a>=0&&a<=127?(r=0,i=a):a>=192&&a<=223?(r=6,i=31&a):a>=224&&a<=239?(r=12,i=15&a):a>=240&&a<=247?(r=18,i=7&a):(r=0,i=65533),0===r||e(i,r,n(r,i))||(r=0,i=65533)):(r-=6,i=i<<6|63&a),0===r&&(i<=65535?o+=String.fromCharCode(i):(o+=String.fromCharCode(55296+(i-65535-1>>10)),o+=String.fromCharCode(56320+(i-65535-1&1023))))}return this.bitsNeeded=r,this.codePoint=i,o};void 0!=_&&void 0!=x&&function(){try{return"test"===(new _).decode((new x).encode("test"),{stream:!0})}catch(t){console.log(t)}return!1}()||(_=e);var A=function(){};n.prototype.open=function(t,e){this._abort(!0);var n=this,o=this._xhr,r=1,i=0;this._abort=function(t){0!==n._sendTimeout&&(g(n._sendTimeout),n._sendTimeout=0),1!==r&&2!==r&&3!==r||(r=4,o.onload=A,o.onerror=A,o.onabort=A,o.onprogress=A,o.onreadystatechange=A,o.abort(),0!==i&&(g(i),i=0),t||(n.readyState=4,n.onreadystatechange())),r=0};var s=function(){if(1===r){var t=0,e="",i=void 0;if("contentType"in o)t=200,e="OK",i=o.contentType;else try{t=o.status,e=o.statusText,i=o.getResponseHeader("Content-Type")}catch(n){t=0,e="",i=void 0}0!==t&&(r=2,n.readyState=2,n.status=t,n.statusText=e,n._contentType=i,n.onreadystatechange())}},a=function(){if(s(),2===r||3===r){r=3;var t="";try{t=o.responseText}catch(t){}n.readyState=3,n.responseText=t,n.onprogress()}},c=function(){a(),1!==r&&2!==r&&3!==r||(r=4,0!==i&&(g(i),i=0),n.readyState=4,n.onreadystatechange())},d=function(){void 0!=o&&(4===o.readyState?c():3===o.readyState?a():2===o.readyState&&s())},h=function(){i=y(function(){h()},500),3===o.readyState&&a()};o.onload=c,o.onerror=c,o.onabort=c,"sendAsBinary"in T.prototype||"mozAnon"in T.prototype||(o.onprogress=a),o.onreadystatechange=d,"contentType"in o&&(e+=(-1===e.indexOf("?")?"?":"&")+"padding=true"),o.open(t,e,!0),"readyState"in o&&(i=y(function(){h()},0))},n.prototype.abort=function(){this._abort(!1)},n.prototype.getResponseHeader=function(t){return this._contentType},n.prototype.setRequestHeader=function(t,e){var n=this._xhr;"setRequestHeader"in n&&n.setRequestHeader(t,e)},n.prototype.getAllResponseHeaders=function(){return void 0!=this._xhr.getAllResponseHeaders?this._xhr.getAllResponseHeaders():""},n.prototype.send=function(){if(!("ontimeout"in T.prototype)&&void 0!=m&&void 0!=m.readyState&&"complete"!==m.readyState){var t=this;return void(t._sendTimeout=y(function(){t._sendTimeout=0,t.send()},4))}var e=this._xhr;e.withCredentials=this.withCredentials,e.responseType=this.responseType;try{e.send(void 0)}catch(t){throw t}},r.prototype.get=function(t){return this._map[o(t)]},i.prototype.open=function(t,e,n,o,i,s,a){t.open("GET",i);var c=0;t.onprogress=function(){var e=t.responseText,o=e.slice(c);c+=o.length,n(o)},t.onreadystatechange=function(){if(2===t.readyState){var n=t.status,i=t.statusText,s=t.getResponseHeader("Content-Type"),a=t.getAllResponseHeaders();e(n,i,s,new r(a),function(){t.abort()})}else 4===t.readyState&&o()},t.withCredentials=s,t.responseType="text";for(var d in a)Object.prototype.hasOwnProperty.call(a,d)&&t.setRequestHeader(d,a[d]);t.send()},s.prototype.get=function(t){return this._headers.get(t)},a.prototype.open=function(t,e,n,o,r,i,a){var c=new _;b(r,{headers:a,credentials:i?"include":"same-origin"}).then(function(t){var o=t.body.getReader();return e(t.status,t.statusText,t.headers.get("Content-Type"),new s(t.headers),function(){o.cancel()}),new S(function(t,e){var r=function(){o.read().then(function(e){if(e.done)t(void 0);else{var o=c.decode(e.value,{stream:!0});n(o),r()}}).catch(function(t){e(t)})};r()})}).finally(function(){o()})},c.prototype.dispatchEvent=function(t){t.target=this;var e=this._listeners[t.type];if(void 0!=e)for(var n=e.length,o=0;o<n;o+=1){var r=e[o];try{"function"==typeof r.handleEvent?r.handleEvent(t):r.call(this,t)}catch(t){d(t)}}},c.prototype.addEventListener=function(t,e){t=String(t);var n=this._listeners,o=n[t];void 0==o&&(o=[],n[t]=o);for(var r=!1,i=0;i<o.length;i+=1)o[i]===e&&(r=!0);r||o.push(e)},c.prototype.removeEventListener=function(t,e){t=String(t);var n=this._listeners,o=n[t];if(void 0!=o){for(var r=[],i=0;i<o.length;i+=1)o[i]!==e&&r.push(o[i]);0===r.length?delete n[t]:n[t]=r}},u.prototype=Object.create(h.prototype),p.prototype=Object.create(h.prototype);var O=-1,R=0,N=1,H=2,j=-1,P=0,I=1,q=2,L=3,D=/^text\/event\-stream;?(\s*charset\=utf\-8)?$/i,M=function(t,e){var n=parseInt(t,10);return n!==n&&(n=e),G(n)},G=function(t){return Math.min(Math.max(t,1e3),18e6)},J=function(t,e,n){try{"function"==typeof e&&e.call(t,n)}catch(t){d(t)}},B=void 0!=b&&void 0!=E&&"body"in E.prototype;f.prototype=Object.create(c.prototype),f.prototype.CONNECTING=R,f.prototype.OPEN=N,f.prototype.CLOSED=H,f.prototype.close=function(){this._close()},f.CONNECTING=R,f.OPEN=N,f.CLOSED=H,f.prototype.withCredentials=void 0,t.EventSourcePolyfill=f,t.NativeEventSource=C,void 0==T||void 0!=C&&"withCredentials"in C.prototype||(t.EventSource=f)}("undefined"!=typeof window?window:this)}});
  7. //# sourceMappingURL=event-source-polyfill.js.map