cloudcms-server 3.3.1-beta.1 → 3.3.1-beta.10

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.
Files changed (38) hide show
  1. package/.last_command +7 -0
  2. package/broadcast/providers/redis.js +32 -57
  3. package/clients/nrp.js +117 -0
  4. package/clients/redis.js +48 -0
  5. package/duster/helpers/sample/nyt.js +5 -7
  6. package/framework/controllers.js +0 -1
  7. package/index.js +23 -13
  8. package/insight/insight.js +6 -9
  9. package/locks/providers/redis.js +29 -58
  10. package/middleware/admin/admin.js +4 -4
  11. package/middleware/awareness/awareness.js +4 -1
  12. package/middleware/awareness/plugins/editorial.js +41 -66
  13. package/middleware/awareness/plugins/resources.js +74 -0
  14. package/middleware/awareness/providers/redis.js +263 -237
  15. package/middleware/cache/providers/redis.js +134 -92
  16. package/middleware/config/config.js +41 -2
  17. package/middleware/deployment/deployment.js +19 -22
  18. package/middleware/form/form.js +18 -33
  19. package/middleware/modules/modules.js +64 -11
  20. package/middleware/proxy/proxy.js +1 -2
  21. package/middleware/stores/engines/s3.js +0 -2
  22. package/middleware/stores/stores.js +50 -6
  23. package/middleware/themes/themes.js +49 -0
  24. package/middleware/virtual-config/virtual-config.js +35 -39
  25. package/notifications/notifications.js +75 -2
  26. package/package.json +18 -19
  27. package/server/index.js +105 -24
  28. package/server/standalone.js +2 -0
  29. package/util/auth.js +2 -7
  30. package/util/cloudcms.js +19 -34
  31. package/util/proxy-factory.js +17 -7
  32. package/util/redis.js +113 -0
  33. package/util/renditions.js +6 -12
  34. package/util/request.js +117 -0
  35. package/util/util.js +23 -36
  36. package/web/socket.io/socket.io.js +4240 -2
  37. package/web/cms/ice.js +0 -109
  38. package/web/cms/preview.js +0 -106
@@ -1,2 +1,4240 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.io=e():t.io=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";function r(t,e){"object"===("undefined"==typeof t?"undefined":o(t))&&(e=t,t=void 0),e=e||{};var n,r=i(t),s=r.source,u=r.id,h=r.path,f=p[u]&&h in p[u].nsps,l=e.forceNew||e["force new connection"]||!1===e.multiplex||f;return l?(c("ignoring socket cache for %s",s),n=a(s,e)):(p[u]||(c("new io instance for %s",s),p[u]=a(s,e)),n=p[u]),r.query&&!e.query&&(e.query=r.query),n.socket(r.path,e)}var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i=n(1),s=n(7),a=n(13),c=n(3)("socket.io-client");t.exports=e=r;var p=e.managers={};e.protocol=s.protocol,e.connect=r,e.Manager=n(13),e.Socket=n(39)},function(t,e,n){(function(e){"use strict";function r(t,n){var r=t;n=n||e.location,null==t&&(t=n.protocol+"//"+n.host),"string"==typeof t&&("/"===t.charAt(0)&&(t="/"===t.charAt(1)?n.protocol+t:n.host+t),/^(https?|wss?):\/\//.test(t)||(i("protocol-less url %s",t),t="undefined"!=typeof n?n.protocol+"//"+t:"https://"+t),i("parse %s",t),r=o(t)),r.port||(/^(http|ws)$/.test(r.protocol)?r.port="80":/^(http|ws)s$/.test(r.protocol)&&(r.port="443")),r.path=r.path||"/";var s=r.host.indexOf(":")!==-1,a=s?"["+r.host+"]":r.host;return r.id=r.protocol+"://"+a+":"+r.port,r.href=r.protocol+"://"+a+(n&&n.port===r.port?"":":"+r.port),r}var o=n(2),i=n(3)("socket.io-client:url");t.exports=r}).call(e,function(){return this}())},function(t,e){var n=/^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,r=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];t.exports=function(t){var e=t,o=t.indexOf("["),i=t.indexOf("]");o!=-1&&i!=-1&&(t=t.substring(0,o)+t.substring(o,i).replace(/:/g,";")+t.substring(i,t.length));for(var s=n.exec(t||""),a={},c=14;c--;)a[r[c]]=s[c]||"";return o!=-1&&i!=-1&&(a.source=e,a.host=a.host.substring(1,a.host.length-1).replace(/;/g,":"),a.authority=a.authority.replace("[","").replace("]","").replace(/;/g,":"),a.ipv6uri=!0),a}},function(t,e,n){(function(r){function o(){return!("undefined"==typeof window||!window.process||"renderer"!==window.process.type)||("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))}function i(t){var n=this.useColors;if(t[0]=(n?"%c":"")+this.namespace+(n?" %c":" ")+t[0]+(n?"%c ":" ")+"+"+e.humanize(this.diff),n){var r="color: "+this.color;t.splice(1,0,r,"color: inherit");var o=0,i=0;t[0].replace(/%[a-zA-Z%]/g,function(t){"%%"!==t&&(o++,"%c"===t&&(i=o))}),t.splice(i,0,r)}}function s(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function a(t){try{null==t?e.storage.removeItem("debug"):e.storage.debug=t}catch(n){}}function c(){var t;try{t=e.storage.debug}catch(n){}return!t&&"undefined"!=typeof r&&"env"in r&&(t=r.env.DEBUG),t}function p(){try{return window.localStorage}catch(t){}}e=t.exports=n(5),e.log=s,e.formatArgs=i,e.save=a,e.load=c,e.useColors=o,e.storage="undefined"!=typeof chrome&&"undefined"!=typeof chrome.storage?chrome.storage.local:p(),e.colors=["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"],e.formatters.j=function(t){try{return JSON.stringify(t)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}},e.enable(c())}).call(e,n(4))},function(t,e){function n(){throw new Error("setTimeout has not been defined")}function r(){throw new Error("clearTimeout has not been defined")}function o(t){if(u===setTimeout)return setTimeout(t,0);if((u===n||!u)&&setTimeout)return u=setTimeout,setTimeout(t,0);try{return u(t,0)}catch(e){try{return u.call(null,t,0)}catch(e){return u.call(this,t,0)}}}function i(t){if(h===clearTimeout)return clearTimeout(t);if((h===r||!h)&&clearTimeout)return h=clearTimeout,clearTimeout(t);try{return h(t)}catch(e){try{return h.call(null,t)}catch(e){return h.call(this,t)}}}function s(){y&&l&&(y=!1,l.length?d=l.concat(d):m=-1,d.length&&a())}function a(){if(!y){var t=o(s);y=!0;for(var e=d.length;e;){for(l=d,d=[];++m<e;)l&&l[m].run();m=-1,e=d.length}l=null,y=!1,i(t)}}function c(t,e){this.fun=t,this.array=e}function p(){}var u,h,f=t.exports={};!function(){try{u="function"==typeof setTimeout?setTimeout:n}catch(t){u=n}try{h="function"==typeof clearTimeout?clearTimeout:r}catch(t){h=r}}();var l,d=[],y=!1,m=-1;f.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)e[n-1]=arguments[n];d.push(new c(t,e)),1!==d.length||y||o(a)},c.prototype.run=function(){this.fun.apply(null,this.array)},f.title="browser",f.browser=!0,f.env={},f.argv=[],f.version="",f.versions={},f.on=p,f.addListener=p,f.once=p,f.off=p,f.removeListener=p,f.removeAllListeners=p,f.emit=p,f.prependListener=p,f.prependOnceListener=p,f.listeners=function(t){return[]},f.binding=function(t){throw new Error("process.binding is not supported")},f.cwd=function(){return"/"},f.chdir=function(t){throw new Error("process.chdir is not supported")},f.umask=function(){return 0}},function(t,e,n){function r(t){var n,r=0;for(n in t)r=(r<<5)-r+t.charCodeAt(n),r|=0;return e.colors[Math.abs(r)%e.colors.length]}function o(t){function n(){if(n.enabled){var t=n,r=+new Date,o=r-(p||r);t.diff=o,t.prev=p,t.curr=r,p=r;for(var i=new Array(arguments.length),s=0;s<i.length;s++)i[s]=arguments[s];i[0]=e.coerce(i[0]),"string"!=typeof i[0]&&i.unshift("%O");var a=0;i[0]=i[0].replace(/%([a-zA-Z%])/g,function(n,r){if("%%"===n)return n;a++;var o=e.formatters[r];if("function"==typeof o){var s=i[a];n=o.call(t,s),i.splice(a,1),a--}return n}),e.formatArgs.call(t,i);var c=n.log||e.log||console.log.bind(console);c.apply(t,i)}}return n.namespace=t,n.enabled=e.enabled(t),n.useColors=e.useColors(),n.color=r(t),"function"==typeof e.init&&e.init(n),n}function i(t){e.save(t),e.names=[],e.skips=[];for(var n=("string"==typeof t?t:"").split(/[\s,]+/),r=n.length,o=0;o<r;o++)n[o]&&(t=n[o].replace(/\*/g,".*?"),"-"===t[0]?e.skips.push(new RegExp("^"+t.substr(1)+"$")):e.names.push(new RegExp("^"+t+"$")))}function s(){e.enable("")}function a(t){var n,r;for(n=0,r=e.skips.length;n<r;n++)if(e.skips[n].test(t))return!1;for(n=0,r=e.names.length;n<r;n++)if(e.names[n].test(t))return!0;return!1}function c(t){return t instanceof Error?t.stack||t.message:t}e=t.exports=o.debug=o["default"]=o,e.coerce=c,e.disable=s,e.enable=i,e.enabled=a,e.humanize=n(6),e.names=[],e.skips=[],e.formatters={};var p},function(t,e){function n(t){if(t=String(t),!(t.length>100)){var e=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(t);if(e){var n=parseFloat(e[1]),r=(e[2]||"ms").toLowerCase();switch(r){case"years":case"year":case"yrs":case"yr":case"y":return n*u;case"days":case"day":case"d":return n*p;case"hours":case"hour":case"hrs":case"hr":case"h":return n*c;case"minutes":case"minute":case"mins":case"min":case"m":return n*a;case"seconds":case"second":case"secs":case"sec":case"s":return n*s;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}}}function r(t){return t>=p?Math.round(t/p)+"d":t>=c?Math.round(t/c)+"h":t>=a?Math.round(t/a)+"m":t>=s?Math.round(t/s)+"s":t+"ms"}function o(t){return i(t,p,"day")||i(t,c,"hour")||i(t,a,"minute")||i(t,s,"second")||t+" ms"}function i(t,e,n){if(!(t<e))return t<1.5*e?Math.floor(t/e)+" "+n:Math.ceil(t/e)+" "+n+"s"}var s=1e3,a=60*s,c=60*a,p=24*c,u=365.25*p;t.exports=function(t,e){e=e||{};var i=typeof t;if("string"===i&&t.length>0)return n(t);if("number"===i&&isNaN(t)===!1)return e["long"]?o(t):r(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))}},function(t,e,n){function r(){}function o(t){var n=""+t.type;return e.BINARY_EVENT!==t.type&&e.BINARY_ACK!==t.type||(n+=t.attachments+"-"),t.nsp&&"/"!==t.nsp&&(n+=t.nsp+","),null!=t.id&&(n+=t.id),null!=t.data&&(n+=JSON.stringify(t.data)),h("encoded %j as %s",t,n),n}function i(t,e){function n(t){var n=d.deconstructPacket(t),r=o(n.packet),i=n.buffers;i.unshift(r),e(i)}d.removeBlobs(t,n)}function s(){this.reconstructor=null}function a(t){var n=0,r={type:Number(t.charAt(0))};if(null==e.types[r.type])return u();if(e.BINARY_EVENT===r.type||e.BINARY_ACK===r.type){for(var o="";"-"!==t.charAt(++n)&&(o+=t.charAt(n),n!=t.length););if(o!=Number(o)||"-"!==t.charAt(n))throw new Error("Illegal attachments");r.attachments=Number(o)}if("/"===t.charAt(n+1))for(r.nsp="";++n;){var i=t.charAt(n);if(","===i)break;if(r.nsp+=i,n===t.length)break}else r.nsp="/";var s=t.charAt(n+1);if(""!==s&&Number(s)==s){for(r.id="";++n;){var i=t.charAt(n);if(null==i||Number(i)!=i){--n;break}if(r.id+=t.charAt(n),n===t.length)break}r.id=Number(r.id)}return t.charAt(++n)&&(r=c(r,t.substr(n))),h("decoded %s as %j",t,r),r}function c(t,e){try{t.data=JSON.parse(e)}catch(n){return u()}return t}function p(t){this.reconPack=t,this.buffers=[]}function u(){return{type:e.ERROR,data:"parser error"}}var h=n(3)("socket.io-parser"),f=n(8),l=n(9),d=n(11),y=n(12);e.protocol=4,e.types=["CONNECT","DISCONNECT","EVENT","ACK","ERROR","BINARY_EVENT","BINARY_ACK"],e.CONNECT=0,e.DISCONNECT=1,e.EVENT=2,e.ACK=3,e.ERROR=4,e.BINARY_EVENT=5,e.BINARY_ACK=6,e.Encoder=r,e.Decoder=s,r.prototype.encode=function(t,n){if(t.type!==e.EVENT&&t.type!==e.ACK||!l(t.data)||(t.type=t.type===e.EVENT?e.BINARY_EVENT:e.BINARY_ACK),h("encoding packet %j",t),e.BINARY_EVENT===t.type||e.BINARY_ACK===t.type)i(t,n);else{var r=o(t);n([r])}},f(s.prototype),s.prototype.add=function(t){var n;if("string"==typeof t)n=a(t),e.BINARY_EVENT===n.type||e.BINARY_ACK===n.type?(this.reconstructor=new p(n),0===this.reconstructor.reconPack.attachments&&this.emit("decoded",n)):this.emit("decoded",n);else{if(!y(t)&&!t.base64)throw new Error("Unknown type: "+t);if(!this.reconstructor)throw new Error("got binary data when not reconstructing a packet");n=this.reconstructor.takeBinaryData(t),n&&(this.reconstructor=null,this.emit("decoded",n))}},s.prototype.destroy=function(){this.reconstructor&&this.reconstructor.finishedReconstruction()},p.prototype.takeBinaryData=function(t){if(this.buffers.push(t),this.buffers.length===this.reconPack.attachments){var e=d.reconstructPacket(this.reconPack,this.buffers);return this.finishedReconstruction(),e}return null},p.prototype.finishedReconstruction=function(){this.reconPack=null,this.buffers=[]}},function(t,e,n){function r(t){if(t)return o(t)}function o(t){for(var e in r.prototype)t[e]=r.prototype[e];return t}t.exports=r,r.prototype.on=r.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(e),this},r.prototype.once=function(t,e){function n(){this.off(t,n),e.apply(this,arguments)}return n.fn=e,this.on(t,n),this},r.prototype.off=r.prototype.removeListener=r.prototype.removeAllListeners=r.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n=this._callbacks["$"+t];if(!n)return this;if(1==arguments.length)return delete this._callbacks["$"+t],this;for(var r,o=0;o<n.length;o++)if(r=n[o],r===e||r.fn===e){n.splice(o,1);break}return this},r.prototype.emit=function(t){this._callbacks=this._callbacks||{};var e=[].slice.call(arguments,1),n=this._callbacks["$"+t];if(n){n=n.slice(0);for(var r=0,o=n.length;r<o;++r)n[r].apply(this,e)}return this},r.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]},r.prototype.hasListeners=function(t){return!!this.listeners(t).length}},function(t,e,n){(function(e){function r(t){if(!t||"object"!=typeof t)return!1;if(o(t)){for(var n=0,i=t.length;n<i;n++)if(r(t[n]))return!0;return!1}if("function"==typeof e.Buffer&&e.Buffer.isBuffer&&e.Buffer.isBuffer(t)||"function"==typeof e.ArrayBuffer&&t instanceof ArrayBuffer||s&&t instanceof Blob||a&&t instanceof File)return!0;if(t.toJSON&&"function"==typeof t.toJSON&&1===arguments.length)return r(t.toJSON(),!0);for(var c in t)if(Object.prototype.hasOwnProperty.call(t,c)&&r(t[c]))return!0;return!1}var o=n(10),i=Object.prototype.toString,s="function"==typeof e.Blob||"[object BlobConstructor]"===i.call(e.Blob),a="function"==typeof e.File||"[object FileConstructor]"===i.call(e.File);t.exports=r}).call(e,function(){return this}())},function(t,e){var n={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==n.call(t)}},function(t,e,n){(function(t){function r(t,e){if(!t)return t;if(s(t)){var n={_placeholder:!0,num:e.length};return e.push(t),n}if(i(t)){for(var o=new Array(t.length),a=0;a<t.length;a++)o[a]=r(t[a],e);return o}if("object"==typeof t&&!(t instanceof Date)){var o={};for(var c in t)o[c]=r(t[c],e);return o}return t}function o(t,e){if(!t)return t;if(t&&t._placeholder)return e[t.num];if(i(t))for(var n=0;n<t.length;n++)t[n]=o(t[n],e);else if("object"==typeof t)for(var r in t)t[r]=o(t[r],e);return t}var i=n(10),s=n(12),a=Object.prototype.toString,c="function"==typeof t.Blob||"[object BlobConstructor]"===a.call(t.Blob),p="function"==typeof t.File||"[object FileConstructor]"===a.call(t.File);e.deconstructPacket=function(t){var e=[],n=t.data,o=t;return o.data=r(n,e),o.attachments=e.length,{packet:o,buffers:e}},e.reconstructPacket=function(t,e){return t.data=o(t.data,e),t.attachments=void 0,t},e.removeBlobs=function(t,e){function n(t,a,u){if(!t)return t;if(c&&t instanceof Blob||p&&t instanceof File){r++;var h=new FileReader;h.onload=function(){u?u[a]=this.result:o=this.result,--r||e(o)},h.readAsArrayBuffer(t)}else if(i(t))for(var f=0;f<t.length;f++)n(t[f],f,t);else if("object"==typeof t&&!s(t))for(var l in t)n(t[l],l,t)}var r=0,o=t;n(o),r||e(o)}}).call(e,function(){return this}())},function(t,e){(function(e){function n(t){return e.Buffer&&e.Buffer.isBuffer(t)||e.ArrayBuffer&&t instanceof ArrayBuffer}t.exports=n}).call(e,function(){return this}())},function(t,e,n){"use strict";function r(t,e){if(!(this instanceof r))return new r(t,e);t&&"object"===("undefined"==typeof t?"undefined":o(t))&&(e=t,t=void 0),e=e||{},e.path=e.path||"/socket.io",this.nsps={},this.subs=[],this.opts=e,this.reconnection(e.reconnection!==!1),this.reconnectionAttempts(e.reconnectionAttempts||1/0),this.reconnectionDelay(e.reconnectionDelay||1e3),this.reconnectionDelayMax(e.reconnectionDelayMax||5e3),this.randomizationFactor(e.randomizationFactor||.5),this.backoff=new l({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(null==e.timeout?2e4:e.timeout),this.readyState="closed",this.uri=t,this.connecting=[],this.lastPing=null,this.encoding=!1,this.packetBuffer=[];var n=e.parser||c;this.encoder=new n.Encoder,this.decoder=new n.Decoder,this.autoConnect=e.autoConnect!==!1,this.autoConnect&&this.open()}var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i=n(14),s=n(39),a=n(8),c=n(7),p=n(41),u=n(42),h=n(3)("socket.io-client:manager"),f=n(37),l=n(43),d=Object.prototype.hasOwnProperty;t.exports=r,r.prototype.emitAll=function(){this.emit.apply(this,arguments);for(var t in this.nsps)d.call(this.nsps,t)&&this.nsps[t].emit.apply(this.nsps[t],arguments)},r.prototype.updateSocketIds=function(){for(var t in this.nsps)d.call(this.nsps,t)&&(this.nsps[t].id=this.generateId(t))},r.prototype.generateId=function(t){return("/"===t?"":t+"#")+this.engine.id},a(r.prototype),r.prototype.reconnection=function(t){return arguments.length?(this._reconnection=!!t,this):this._reconnection},r.prototype.reconnectionAttempts=function(t){return arguments.length?(this._reconnectionAttempts=t,this):this._reconnectionAttempts},r.prototype.reconnectionDelay=function(t){return arguments.length?(this._reconnectionDelay=t,this.backoff&&this.backoff.setMin(t),this):this._reconnectionDelay},r.prototype.randomizationFactor=function(t){return arguments.length?(this._randomizationFactor=t,this.backoff&&this.backoff.setJitter(t),this):this._randomizationFactor},r.prototype.reconnectionDelayMax=function(t){return arguments.length?(this._reconnectionDelayMax=t,this.backoff&&this.backoff.setMax(t),this):this._reconnectionDelayMax},r.prototype.timeout=function(t){return arguments.length?(this._timeout=t,this):this._timeout},r.prototype.maybeReconnectOnOpen=function(){!this.reconnecting&&this._reconnection&&0===this.backoff.attempts&&this.reconnect()},r.prototype.open=r.prototype.connect=function(t,e){if(h("readyState %s",this.readyState),~this.readyState.indexOf("open"))return this;h("opening %s",this.uri),this.engine=i(this.uri,this.opts);var n=this.engine,r=this;this.readyState="opening",this.skipReconnect=!1;var o=p(n,"open",function(){r.onopen(),t&&t()}),s=p(n,"error",function(e){if(h("connect_error"),r.cleanup(),r.readyState="closed",r.emitAll("connect_error",e),t){var n=new Error("Connection error");n.data=e,t(n)}else r.maybeReconnectOnOpen()});if(!1!==this._timeout){var a=this._timeout;h("connect attempt will timeout after %d",a);var c=setTimeout(function(){h("connect attempt timed out after %d",a),o.destroy(),n.close(),n.emit("error","timeout"),r.emitAll("connect_timeout",a)},a);this.subs.push({destroy:function(){clearTimeout(c)}})}return this.subs.push(o),this.subs.push(s),this},r.prototype.onopen=function(){h("open"),this.cleanup(),this.readyState="open",this.emit("open");var t=this.engine;this.subs.push(p(t,"data",u(this,"ondata"))),this.subs.push(p(t,"ping",u(this,"onping"))),this.subs.push(p(t,"pong",u(this,"onpong"))),this.subs.push(p(t,"error",u(this,"onerror"))),this.subs.push(p(t,"close",u(this,"onclose"))),this.subs.push(p(this.decoder,"decoded",u(this,"ondecoded")))},r.prototype.onping=function(){this.lastPing=new Date,this.emitAll("ping")},r.prototype.onpong=function(){this.emitAll("pong",new Date-this.lastPing)},r.prototype.ondata=function(t){this.decoder.add(t)},r.prototype.ondecoded=function(t){this.emit("packet",t)},r.prototype.onerror=function(t){h("error",t),this.emitAll("error",t)},r.prototype.socket=function(t,e){function n(){~f(o.connecting,r)||o.connecting.push(r)}var r=this.nsps[t];if(!r){r=new s(this,t,e),this.nsps[t]=r;var o=this;r.on("connecting",n),r.on("connect",function(){r.id=o.generateId(t)}),this.autoConnect&&n()}return r},r.prototype.destroy=function(t){var e=f(this.connecting,t);~e&&this.connecting.splice(e,1),this.connecting.length||this.close()},r.prototype.packet=function(t){h("writing packet %j",t);var e=this;t.query&&0===t.type&&(t.nsp+="?"+t.query),e.encoding?e.packetBuffer.push(t):(e.encoding=!0,this.encoder.encode(t,function(n){for(var r=0;r<n.length;r++)e.engine.write(n[r],t.options);e.encoding=!1,e.processPacketQueue()}))},r.prototype.processPacketQueue=function(){if(this.packetBuffer.length>0&&!this.encoding){var t=this.packetBuffer.shift();this.packet(t)}},r.prototype.cleanup=function(){h("cleanup");for(var t=this.subs.length,e=0;e<t;e++){var n=this.subs.shift();n.destroy()}this.packetBuffer=[],this.encoding=!1,this.lastPing=null,this.decoder.destroy()},r.prototype.close=r.prototype.disconnect=function(){h("disconnect"),this.skipReconnect=!0,this.reconnecting=!1,"opening"===this.readyState&&this.cleanup(),this.backoff.reset(),this.readyState="closed",this.engine&&this.engine.close()},r.prototype.onclose=function(t){h("onclose"),this.cleanup(),this.backoff.reset(),this.readyState="closed",this.emit("close",t),this._reconnection&&!this.skipReconnect&&this.reconnect()},r.prototype.reconnect=function(){if(this.reconnecting||this.skipReconnect)return this;var t=this;if(this.backoff.attempts>=this._reconnectionAttempts)h("reconnect failed"),this.backoff.reset(),this.emitAll("reconnect_failed"),this.reconnecting=!1;else{var e=this.backoff.duration();h("will wait %dms before reconnect attempt",e),this.reconnecting=!0;var n=setTimeout(function(){t.skipReconnect||(h("attempting reconnect"),t.emitAll("reconnect_attempt",t.backoff.attempts),t.emitAll("reconnecting",t.backoff.attempts),t.skipReconnect||t.open(function(e){e?(h("reconnect attempt error"),t.reconnecting=!1,t.reconnect(),t.emitAll("reconnect_error",e.data)):(h("reconnect success"),t.onreconnect())}))},e);this.subs.push({destroy:function(){clearTimeout(n)}})}},r.prototype.onreconnect=function(){var t=this.backoff.attempts;this.reconnecting=!1,this.backoff.reset(),this.updateSocketIds(),this.emitAll("reconnect",t)}},function(t,e,n){t.exports=n(15)},function(t,e,n){t.exports=n(16),t.exports.parser=n(23)},function(t,e,n){(function(e){function r(t,n){if(!(this instanceof r))return new r(t,n);n=n||{},t&&"object"==typeof t&&(n=t,t=null),t?(t=u(t),n.hostname=t.host,n.secure="https"===t.protocol||"wss"===t.protocol,n.port=t.port,t.query&&(n.query=t.query)):n.host&&(n.hostname=u(n.host).host),this.secure=null!=n.secure?n.secure:e.location&&"https:"===location.protocol,n.hostname&&!n.port&&(n.port=this.secure?"443":"80"),this.agent=n.agent||!1,this.hostname=n.hostname||(e.location?location.hostname:"localhost"),this.port=n.port||(e.location&&location.port?location.port:this.secure?443:80),this.query=n.query||{},"string"==typeof this.query&&(this.query=f.decode(this.query)),this.upgrade=!1!==n.upgrade,this.path=(n.path||"/engine.io").replace(/\/$/,"")+"/",this.forceJSONP=!!n.forceJSONP,this.jsonp=!1!==n.jsonp,this.forceBase64=!!n.forceBase64,this.enablesXDR=!!n.enablesXDR,this.timestampParam=n.timestampParam||"t",this.timestampRequests=n.timestampRequests,this.transports=n.transports||["polling","websocket"],this.transportOptions=n.transportOptions||{},this.readyState="",this.writeBuffer=[],this.prevBufferLen=0,this.policyPort=n.policyPort||843,this.rememberUpgrade=n.rememberUpgrade||!1,this.binaryType=null,this.onlyBinaryUpgrades=n.onlyBinaryUpgrades,this.perMessageDeflate=!1!==n.perMessageDeflate&&(n.perMessageDeflate||{}),!0===this.perMessageDeflate&&(this.perMessageDeflate={}),this.perMessageDeflate&&null==this.perMessageDeflate.threshold&&(this.perMessageDeflate.threshold=1024),this.pfx=n.pfx||null,this.key=n.key||null,this.passphrase=n.passphrase||null,this.cert=n.cert||null,this.ca=n.ca||null,this.ciphers=n.ciphers||null,this.rejectUnauthorized=void 0===n.rejectUnauthorized||n.rejectUnauthorized,this.forceNode=!!n.forceNode;var o="object"==typeof e&&e;o.global===o&&(n.extraHeaders&&Object.keys(n.extraHeaders).length>0&&(this.extraHeaders=n.extraHeaders),n.localAddress&&(this.localAddress=n.localAddress)),this.id=null,this.upgrades=null,this.pingInterval=null,this.pingTimeout=null,this.pingIntervalTimer=null,this.pingTimeoutTimer=null,this.open()}function o(t){var e={};for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);return e}var i=n(17),s=n(8),a=n(3)("engine.io-client:socket"),c=n(37),p=n(23),u=n(2),h=n(38),f=n(31);t.exports=r,r.priorWebsocketSuccess=!1,s(r.prototype),r.protocol=p.protocol,r.Socket=r,r.Transport=n(22),r.transports=n(17),r.parser=n(23),r.prototype.createTransport=function(t){a('creating transport "%s"',t);var e=o(this.query);e.EIO=p.protocol,e.transport=t;var n=this.transportOptions[t]||{};this.id&&(e.sid=this.id);var r=new i[t]({query:e,socket:this,agent:n.agent||this.agent,hostname:n.hostname||this.hostname,port:n.port||this.port,secure:n.secure||this.secure,path:n.path||this.path,forceJSONP:n.forceJSONP||this.forceJSONP,jsonp:n.jsonp||this.jsonp,forceBase64:n.forceBase64||this.forceBase64,enablesXDR:n.enablesXDR||this.enablesXDR,timestampRequests:n.timestampRequests||this.timestampRequests,timestampParam:n.timestampParam||this.timestampParam,policyPort:n.policyPort||this.policyPort,pfx:n.pfx||this.pfx,key:n.key||this.key,passphrase:n.passphrase||this.passphrase,cert:n.cert||this.cert,ca:n.ca||this.ca,ciphers:n.ciphers||this.ciphers,rejectUnauthorized:n.rejectUnauthorized||this.rejectUnauthorized,perMessageDeflate:n.perMessageDeflate||this.perMessageDeflate,extraHeaders:n.extraHeaders||this.extraHeaders,forceNode:n.forceNode||this.forceNode,localAddress:n.localAddress||this.localAddress,requestTimeout:n.requestTimeout||this.requestTimeout,protocols:n.protocols||void 0});return r},r.prototype.open=function(){var t;if(this.rememberUpgrade&&r.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1)t="websocket";else{if(0===this.transports.length){var e=this;return void setTimeout(function(){e.emit("error","No transports available")},0)}t=this.transports[0]}this.readyState="opening";try{t=this.createTransport(t)}catch(n){return this.transports.shift(),void this.open()}t.open(),this.setTransport(t)},r.prototype.setTransport=function(t){a("setting transport %s",t.name);var e=this;this.transport&&(a("clearing existing transport %s",this.transport.name),this.transport.removeAllListeners()),this.transport=t,t.on("drain",function(){e.onDrain()}).on("packet",function(t){e.onPacket(t)}).on("error",function(t){e.onError(t)}).on("close",function(){e.onClose("transport close")})},r.prototype.probe=function(t){function e(){if(f.onlyBinaryUpgrades){var e=!this.supportsBinary&&f.transport.supportsBinary;h=h||e}h||(a('probe transport "%s" opened',t),u.send([{type:"ping",data:"probe"}]),u.once("packet",function(e){if(!h)if("pong"===e.type&&"probe"===e.data){if(a('probe transport "%s" pong',t),f.upgrading=!0,f.emit("upgrading",u),!u)return;r.priorWebsocketSuccess="websocket"===u.name,a('pausing current transport "%s"',f.transport.name),f.transport.pause(function(){h||"closed"!==f.readyState&&(a("changing transport and sending upgrade packet"),p(),f.setTransport(u),u.send([{type:"upgrade"}]),f.emit("upgrade",u),u=null,f.upgrading=!1,f.flush())})}else{a('probe transport "%s" failed',t);var n=new Error("probe error");n.transport=u.name,f.emit("upgradeError",n)}}))}function n(){h||(h=!0,p(),u.close(),u=null)}function o(e){var r=new Error("probe error: "+e);r.transport=u.name,n(),a('probe transport "%s" failed because of error: %s',t,e),f.emit("upgradeError",r)}function i(){o("transport closed")}function s(){o("socket closed")}function c(t){u&&t.name!==u.name&&(a('"%s" works - aborting "%s"',t.name,u.name),n())}function p(){u.removeListener("open",e),u.removeListener("error",o),u.removeListener("close",i),f.removeListener("close",s),f.removeListener("upgrading",c)}a('probing transport "%s"',t);var u=this.createTransport(t,{probe:1}),h=!1,f=this;r.priorWebsocketSuccess=!1,u.once("open",e),u.once("error",o),u.once("close",i),this.once("close",s),this.once("upgrading",c),u.open()},r.prototype.onOpen=function(){if(a("socket open"),this.readyState="open",r.priorWebsocketSuccess="websocket"===this.transport.name,this.emit("open"),this.flush(),"open"===this.readyState&&this.upgrade&&this.transport.pause){a("starting upgrade probes");for(var t=0,e=this.upgrades.length;t<e;t++)this.probe(this.upgrades[t])}},r.prototype.onPacket=function(t){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState)switch(a('socket receive: type "%s", data "%s"',t.type,t.data),this.emit("packet",t),this.emit("heartbeat"),t.type){case"open":this.onHandshake(h(t.data));break;case"pong":this.setPing(),this.emit("pong");break;case"error":var e=new Error("server error");e.code=t.data,this.onError(e);break;case"message":this.emit("data",t.data),this.emit("message",t.data)}else a('packet received with socket readyState "%s"',this.readyState)},r.prototype.onHandshake=function(t){this.emit("handshake",t),this.id=t.sid,this.transport.query.sid=t.sid,this.upgrades=this.filterUpgrades(t.upgrades),this.pingInterval=t.pingInterval,this.pingTimeout=t.pingTimeout,this.onOpen(),"closed"!==this.readyState&&(this.setPing(),this.removeListener("heartbeat",this.onHeartbeat),this.on("heartbeat",this.onHeartbeat))},r.prototype.onHeartbeat=function(t){clearTimeout(this.pingTimeoutTimer);var e=this;e.pingTimeoutTimer=setTimeout(function(){"closed"!==e.readyState&&e.onClose("ping timeout")},t||e.pingInterval+e.pingTimeout)},r.prototype.setPing=function(){var t=this;clearTimeout(t.pingIntervalTimer),t.pingIntervalTimer=setTimeout(function(){a("writing ping packet - expecting pong within %sms",t.pingTimeout),t.ping(),t.onHeartbeat(t.pingTimeout)},t.pingInterval)},r.prototype.ping=function(){var t=this;this.sendPacket("ping",function(){t.emit("ping")})},r.prototype.onDrain=function(){this.writeBuffer.splice(0,this.prevBufferLen),this.prevBufferLen=0,0===this.writeBuffer.length?this.emit("drain"):this.flush()},r.prototype.flush=function(){"closed"!==this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length&&(a("flushing %d packets in socket",this.writeBuffer.length),this.transport.send(this.writeBuffer),this.prevBufferLen=this.writeBuffer.length,this.emit("flush"))},r.prototype.write=r.prototype.send=function(t,e,n){return this.sendPacket("message",t,e,n),this},r.prototype.sendPacket=function(t,e,n,r){if("function"==typeof e&&(r=e,e=void 0),"function"==typeof n&&(r=n,n=null),"closing"!==this.readyState&&"closed"!==this.readyState){n=n||{},n.compress=!1!==n.compress;var o={type:t,data:e,options:n};this.emit("packetCreate",o),this.writeBuffer.push(o),r&&this.once("flush",r),this.flush()}},r.prototype.close=function(){function t(){r.onClose("forced close"),a("socket closing - telling transport to close"),r.transport.close()}function e(){r.removeListener("upgrade",e),r.removeListener("upgradeError",e),t()}function n(){r.once("upgrade",e),r.once("upgradeError",e)}if("opening"===this.readyState||"open"===this.readyState){this.readyState="closing";var r=this;this.writeBuffer.length?this.once("drain",function(){this.upgrading?n():t()}):this.upgrading?n():t()}return this},r.prototype.onError=function(t){a("socket error %j",t),r.priorWebsocketSuccess=!1,this.emit("error",t),this.onClose("transport error",t)},r.prototype.onClose=function(t,e){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState){a('socket close with reason: "%s"',t);var n=this;clearTimeout(this.pingIntervalTimer),clearTimeout(this.pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),this.readyState="closed",this.id=null,this.emit("close",t,e),n.writeBuffer=[],n.prevBufferLen=0}},r.prototype.filterUpgrades=function(t){for(var e=[],n=0,r=t.length;n<r;n++)~c(this.transports,t[n])&&e.push(t[n]);return e}}).call(e,function(){return this}())},function(t,e,n){(function(t){function r(e){var n,r=!1,a=!1,c=!1!==e.jsonp;if(t.location){var p="https:"===location.protocol,u=location.port;u||(u=p?443:80),r=e.hostname!==location.hostname||u!==e.port,a=e.secure!==p}if(e.xdomain=r,e.xscheme=a,n=new o(e),"open"in n&&!e.forceJSONP)return new i(e);if(!c)throw new Error("JSONP disabled");return new s(e)}var o=n(18),i=n(20),s=n(34),a=n(35);e.polling=r,e.websocket=a}).call(e,function(){return this}())},function(t,e,n){(function(e){var r=n(19);t.exports=function(t){var n=t.xdomain,o=t.xscheme,i=t.enablesXDR;try{if("undefined"!=typeof XMLHttpRequest&&(!n||r))return new XMLHttpRequest}catch(s){}try{if("undefined"!=typeof XDomainRequest&&!o&&i)return new XDomainRequest}catch(s){}if(!n)try{
2
- return new(e[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(s){}}}).call(e,function(){return this}())},function(t,e){try{t.exports="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(n){t.exports=!1}},function(t,e,n){(function(e){function r(){}function o(t){if(c.call(this,t),this.requestTimeout=t.requestTimeout,this.extraHeaders=t.extraHeaders,e.location){var n="https:"===location.protocol,r=location.port;r||(r=n?443:80),this.xd=t.hostname!==e.location.hostname||r!==t.port,this.xs=t.secure!==n}}function i(t){this.method=t.method||"GET",this.uri=t.uri,this.xd=!!t.xd,this.xs=!!t.xs,this.async=!1!==t.async,this.data=void 0!==t.data?t.data:null,this.agent=t.agent,this.isBinary=t.isBinary,this.supportsBinary=t.supportsBinary,this.enablesXDR=t.enablesXDR,this.requestTimeout=t.requestTimeout,this.pfx=t.pfx,this.key=t.key,this.passphrase=t.passphrase,this.cert=t.cert,this.ca=t.ca,this.ciphers=t.ciphers,this.rejectUnauthorized=t.rejectUnauthorized,this.extraHeaders=t.extraHeaders,this.create()}function s(){for(var t in i.requests)i.requests.hasOwnProperty(t)&&i.requests[t].abort()}var a=n(18),c=n(21),p=n(8),u=n(32),h=n(3)("engine.io-client:polling-xhr");t.exports=o,t.exports.Request=i,u(o,c),o.prototype.supportsBinary=!0,o.prototype.request=function(t){return t=t||{},t.uri=this.uri(),t.xd=this.xd,t.xs=this.xs,t.agent=this.agent||!1,t.supportsBinary=this.supportsBinary,t.enablesXDR=this.enablesXDR,t.pfx=this.pfx,t.key=this.key,t.passphrase=this.passphrase,t.cert=this.cert,t.ca=this.ca,t.ciphers=this.ciphers,t.rejectUnauthorized=this.rejectUnauthorized,t.requestTimeout=this.requestTimeout,t.extraHeaders=this.extraHeaders,new i(t)},o.prototype.doWrite=function(t,e){var n="string"!=typeof t&&void 0!==t,r=this.request({method:"POST",data:t,isBinary:n}),o=this;r.on("success",e),r.on("error",function(t){o.onError("xhr post error",t)}),this.sendXhr=r},o.prototype.doPoll=function(){h("xhr poll");var t=this.request(),e=this;t.on("data",function(t){e.onData(t)}),t.on("error",function(t){e.onError("xhr poll error",t)}),this.pollXhr=t},p(i.prototype),i.prototype.create=function(){var t={agent:this.agent,xdomain:this.xd,xscheme:this.xs,enablesXDR:this.enablesXDR};t.pfx=this.pfx,t.key=this.key,t.passphrase=this.passphrase,t.cert=this.cert,t.ca=this.ca,t.ciphers=this.ciphers,t.rejectUnauthorized=this.rejectUnauthorized;var n=this.xhr=new a(t),r=this;try{h("xhr open %s: %s",this.method,this.uri),n.open(this.method,this.uri,this.async);try{if(this.extraHeaders){n.setDisableHeaderCheck&&n.setDisableHeaderCheck(!0);for(var o in this.extraHeaders)this.extraHeaders.hasOwnProperty(o)&&n.setRequestHeader(o,this.extraHeaders[o])}}catch(s){}if("POST"===this.method)try{this.isBinary?n.setRequestHeader("Content-type","application/octet-stream"):n.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(s){}try{n.setRequestHeader("Accept","*/*")}catch(s){}"withCredentials"in n&&(n.withCredentials=!0),this.requestTimeout&&(n.timeout=this.requestTimeout),this.hasXDR()?(n.onload=function(){r.onLoad()},n.onerror=function(){r.onError(n.responseText)}):n.onreadystatechange=function(){if(2===n.readyState){var t;try{t=n.getResponseHeader("Content-Type")}catch(e){}"application/octet-stream"===t&&(n.responseType="arraybuffer")}4===n.readyState&&(200===n.status||1223===n.status?r.onLoad():setTimeout(function(){r.onError(n.status)},0))},h("xhr data %s",this.data),n.send(this.data)}catch(s){return void setTimeout(function(){r.onError(s)},0)}e.document&&(this.index=i.requestsCount++,i.requests[this.index]=this)},i.prototype.onSuccess=function(){this.emit("success"),this.cleanup()},i.prototype.onData=function(t){this.emit("data",t),this.onSuccess()},i.prototype.onError=function(t){this.emit("error",t),this.cleanup(!0)},i.prototype.cleanup=function(t){if("undefined"!=typeof this.xhr&&null!==this.xhr){if(this.hasXDR()?this.xhr.onload=this.xhr.onerror=r:this.xhr.onreadystatechange=r,t)try{this.xhr.abort()}catch(n){}e.document&&delete i.requests[this.index],this.xhr=null}},i.prototype.onLoad=function(){var t;try{var e;try{e=this.xhr.getResponseHeader("Content-Type")}catch(n){}t="application/octet-stream"===e?this.xhr.response||this.xhr.responseText:this.xhr.responseText}catch(n){this.onError(n)}null!=t&&this.onData(t)},i.prototype.hasXDR=function(){return"undefined"!=typeof e.XDomainRequest&&!this.xs&&this.enablesXDR},i.prototype.abort=function(){this.cleanup()},i.requestsCount=0,i.requests={},e.document&&(e.attachEvent?e.attachEvent("onunload",s):e.addEventListener&&e.addEventListener("beforeunload",s,!1))}).call(e,function(){return this}())},function(t,e,n){function r(t){var e=t&&t.forceBase64;u&&!e||(this.supportsBinary=!1),o.call(this,t)}var o=n(22),i=n(31),s=n(23),a=n(32),c=n(33),p=n(3)("engine.io-client:polling");t.exports=r;var u=function(){var t=n(18),e=new t({xdomain:!1});return null!=e.responseType}();a(r,o),r.prototype.name="polling",r.prototype.doOpen=function(){this.poll()},r.prototype.pause=function(t){function e(){p("paused"),n.readyState="paused",t()}var n=this;if(this.readyState="pausing",this.polling||!this.writable){var r=0;this.polling&&(p("we are currently polling - waiting to pause"),r++,this.once("pollComplete",function(){p("pre-pause polling complete"),--r||e()})),this.writable||(p("we are currently writing - waiting to pause"),r++,this.once("drain",function(){p("pre-pause writing complete"),--r||e()}))}else e()},r.prototype.poll=function(){p("polling"),this.polling=!0,this.doPoll(),this.emit("poll")},r.prototype.onData=function(t){var e=this;p("polling got data %s",t);var n=function(t,n,r){return"opening"===e.readyState&&e.onOpen(),"close"===t.type?(e.onClose(),!1):void e.onPacket(t)};s.decodePayload(t,this.socket.binaryType,n),"closed"!==this.readyState&&(this.polling=!1,this.emit("pollComplete"),"open"===this.readyState?this.poll():p('ignoring poll - transport state "%s"',this.readyState))},r.prototype.doClose=function(){function t(){p("writing close packet"),e.write([{type:"close"}])}var e=this;"open"===this.readyState?(p("transport open - closing"),t()):(p("transport not open - deferring close"),this.once("open",t))},r.prototype.write=function(t){var e=this;this.writable=!1;var n=function(){e.writable=!0,e.emit("drain")};s.encodePayload(t,this.supportsBinary,function(t){e.doWrite(t,n)})},r.prototype.uri=function(){var t=this.query||{},e=this.secure?"https":"http",n="";!1!==this.timestampRequests&&(t[this.timestampParam]=c()),this.supportsBinary||t.sid||(t.b64=1),t=i.encode(t),this.port&&("https"===e&&443!==Number(this.port)||"http"===e&&80!==Number(this.port))&&(n=":"+this.port),t.length&&(t="?"+t);var r=this.hostname.indexOf(":")!==-1;return e+"://"+(r?"["+this.hostname+"]":this.hostname)+n+this.path+t}},function(t,e,n){function r(t){this.path=t.path,this.hostname=t.hostname,this.port=t.port,this.secure=t.secure,this.query=t.query,this.timestampParam=t.timestampParam,this.timestampRequests=t.timestampRequests,this.readyState="",this.agent=t.agent||!1,this.socket=t.socket,this.enablesXDR=t.enablesXDR,this.pfx=t.pfx,this.key=t.key,this.passphrase=t.passphrase,this.cert=t.cert,this.ca=t.ca,this.ciphers=t.ciphers,this.rejectUnauthorized=t.rejectUnauthorized,this.forceNode=t.forceNode,this.extraHeaders=t.extraHeaders,this.localAddress=t.localAddress}var o=n(23),i=n(8);t.exports=r,i(r.prototype),r.prototype.onError=function(t,e){var n=new Error(t);return n.type="TransportError",n.description=e,this.emit("error",n),this},r.prototype.open=function(){return"closed"!==this.readyState&&""!==this.readyState||(this.readyState="opening",this.doOpen()),this},r.prototype.close=function(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this},r.prototype.send=function(t){if("open"!==this.readyState)throw new Error("Transport not open");this.write(t)},r.prototype.onOpen=function(){this.readyState="open",this.writable=!0,this.emit("open")},r.prototype.onData=function(t){var e=o.decodePacket(t,this.socket.binaryType);this.onPacket(e)},r.prototype.onPacket=function(t){this.emit("packet",t)},r.prototype.onClose=function(){this.readyState="closed",this.emit("close")}},function(t,e,n){(function(t){function r(t,n){var r="b"+e.packets[t.type]+t.data.data;return n(r)}function o(t,n,r){if(!n)return e.encodeBase64Packet(t,r);var o=t.data,i=new Uint8Array(o),s=new Uint8Array(1+o.byteLength);s[0]=v[t.type];for(var a=0;a<i.length;a++)s[a+1]=i[a];return r(s.buffer)}function i(t,n,r){if(!n)return e.encodeBase64Packet(t,r);var o=new FileReader;return o.onload=function(){t.data=o.result,e.encodePacket(t,n,!0,r)},o.readAsArrayBuffer(t.data)}function s(t,n,r){if(!n)return e.encodeBase64Packet(t,r);if(g)return i(t,n,r);var o=new Uint8Array(1);o[0]=v[t.type];var s=new k([o.buffer,t.data]);return r(s)}function a(t){try{t=d.decode(t,{strict:!1})}catch(e){return!1}return t}function c(t,e,n){for(var r=new Array(t.length),o=l(t.length,n),i=function(t,n,o){e(n,function(e,n){r[t]=n,o(e,r)})},s=0;s<t.length;s++)i(s,t[s],o)}var p,u=n(24),h=n(9),f=n(25),l=n(26),d=n(27);t&&t.ArrayBuffer&&(p=n(29));var y="undefined"!=typeof navigator&&/Android/i.test(navigator.userAgent),m="undefined"!=typeof navigator&&/PhantomJS/i.test(navigator.userAgent),g=y||m;e.protocol=3;var v=e.packets={open:0,close:1,ping:2,pong:3,message:4,upgrade:5,noop:6},b=u(v),w={type:"error",data:"parser error"},k=n(30);e.encodePacket=function(e,n,i,a){"function"==typeof n&&(a=n,n=!1),"function"==typeof i&&(a=i,i=null);var c=void 0===e.data?void 0:e.data.buffer||e.data;if(t.ArrayBuffer&&c instanceof ArrayBuffer)return o(e,n,a);if(k&&c instanceof t.Blob)return s(e,n,a);if(c&&c.base64)return r(e,a);var p=v[e.type];return void 0!==e.data&&(p+=i?d.encode(String(e.data),{strict:!1}):String(e.data)),a(""+p)},e.encodeBase64Packet=function(n,r){var o="b"+e.packets[n.type];if(k&&n.data instanceof t.Blob){var i=new FileReader;return i.onload=function(){var t=i.result.split(",")[1];r(o+t)},i.readAsDataURL(n.data)}var s;try{s=String.fromCharCode.apply(null,new Uint8Array(n.data))}catch(a){for(var c=new Uint8Array(n.data),p=new Array(c.length),u=0;u<c.length;u++)p[u]=c[u];s=String.fromCharCode.apply(null,p)}return o+=t.btoa(s),r(o)},e.decodePacket=function(t,n,r){if(void 0===t)return w;if("string"==typeof t){if("b"===t.charAt(0))return e.decodeBase64Packet(t.substr(1),n);if(r&&(t=a(t),t===!1))return w;var o=t.charAt(0);return Number(o)==o&&b[o]?t.length>1?{type:b[o],data:t.substring(1)}:{type:b[o]}:w}var i=new Uint8Array(t),o=i[0],s=f(t,1);return k&&"blob"===n&&(s=new k([s])),{type:b[o],data:s}},e.decodeBase64Packet=function(t,e){var n=b[t.charAt(0)];if(!p)return{type:n,data:{base64:!0,data:t.substr(1)}};var r=p.decode(t.substr(1));return"blob"===e&&k&&(r=new k([r])),{type:n,data:r}},e.encodePayload=function(t,n,r){function o(t){return t.length+":"+t}function i(t,r){e.encodePacket(t,!!s&&n,!1,function(t){r(null,o(t))})}"function"==typeof n&&(r=n,n=null);var s=h(t);return n&&s?k&&!g?e.encodePayloadAsBlob(t,r):e.encodePayloadAsArrayBuffer(t,r):t.length?void c(t,i,function(t,e){return r(e.join(""))}):r("0:")},e.decodePayload=function(t,n,r){if("string"!=typeof t)return e.decodePayloadAsBinary(t,n,r);"function"==typeof n&&(r=n,n=null);var o;if(""===t)return r(w,0,1);for(var i,s,a="",c=0,p=t.length;c<p;c++){var u=t.charAt(c);if(":"===u){if(""===a||a!=(i=Number(a)))return r(w,0,1);if(s=t.substr(c+1,i),a!=s.length)return r(w,0,1);if(s.length){if(o=e.decodePacket(s,n,!1),w.type===o.type&&w.data===o.data)return r(w,0,1);var h=r(o,c+i,p);if(!1===h)return}c+=i,a=""}else a+=u}return""!==a?r(w,0,1):void 0},e.encodePayloadAsArrayBuffer=function(t,n){function r(t,n){e.encodePacket(t,!0,!0,function(t){return n(null,t)})}return t.length?void c(t,r,function(t,e){var r=e.reduce(function(t,e){var n;return n="string"==typeof e?e.length:e.byteLength,t+n.toString().length+n+2},0),o=new Uint8Array(r),i=0;return e.forEach(function(t){var e="string"==typeof t,n=t;if(e){for(var r=new Uint8Array(t.length),s=0;s<t.length;s++)r[s]=t.charCodeAt(s);n=r.buffer}e?o[i++]=0:o[i++]=1;for(var a=n.byteLength.toString(),s=0;s<a.length;s++)o[i++]=parseInt(a[s]);o[i++]=255;for(var r=new Uint8Array(n),s=0;s<r.length;s++)o[i++]=r[s]}),n(o.buffer)}):n(new ArrayBuffer(0))},e.encodePayloadAsBlob=function(t,n){function r(t,n){e.encodePacket(t,!0,!0,function(t){var e=new Uint8Array(1);if(e[0]=1,"string"==typeof t){for(var r=new Uint8Array(t.length),o=0;o<t.length;o++)r[o]=t.charCodeAt(o);t=r.buffer,e[0]=0}for(var i=t instanceof ArrayBuffer?t.byteLength:t.size,s=i.toString(),a=new Uint8Array(s.length+1),o=0;o<s.length;o++)a[o]=parseInt(s[o]);if(a[s.length]=255,k){var c=new k([e.buffer,a.buffer,t]);n(null,c)}})}c(t,r,function(t,e){return n(new k(e))})},e.decodePayloadAsBinary=function(t,n,r){"function"==typeof n&&(r=n,n=null);for(var o=t,i=[];o.byteLength>0;){for(var s=new Uint8Array(o),a=0===s[0],c="",p=1;255!==s[p];p++){if(c.length>310)return r(w,0,1);c+=s[p]}o=f(o,2+c.length),c=parseInt(c);var u=f(o,0,c);if(a)try{u=String.fromCharCode.apply(null,new Uint8Array(u))}catch(h){var l=new Uint8Array(u);u="";for(var p=0;p<l.length;p++)u+=String.fromCharCode(l[p])}i.push(u),o=f(o,c)}var d=i.length;i.forEach(function(t,o){r(e.decodePacket(t,n,!0),o,d)})}}).call(e,function(){return this}())},function(t,e){t.exports=Object.keys||function(t){var e=[],n=Object.prototype.hasOwnProperty;for(var r in t)n.call(t,r)&&e.push(r);return e}},function(t,e){t.exports=function(t,e,n){var r=t.byteLength;if(e=e||0,n=n||r,t.slice)return t.slice(e,n);if(e<0&&(e+=r),n<0&&(n+=r),n>r&&(n=r),e>=r||e>=n||0===r)return new ArrayBuffer(0);for(var o=new Uint8Array(t),i=new Uint8Array(n-e),s=e,a=0;s<n;s++,a++)i[a]=o[s];return i.buffer}},function(t,e){function n(t,e,n){function o(t,r){if(o.count<=0)throw new Error("after called too many times");--o.count,t?(i=!0,e(t),e=n):0!==o.count||i||e(null,r)}var i=!1;return n=n||r,o.count=t,0===t?e():o}function r(){}t.exports=n},function(t,e,n){var r;(function(t,o){!function(i){function s(t){for(var e,n,r=[],o=0,i=t.length;o<i;)e=t.charCodeAt(o++),e>=55296&&e<=56319&&o<i?(n=t.charCodeAt(o++),56320==(64512&n)?r.push(((1023&e)<<10)+(1023&n)+65536):(r.push(e),o--)):r.push(e);return r}function a(t){for(var e,n=t.length,r=-1,o="";++r<n;)e=t[r],e>65535&&(e-=65536,o+=w(e>>>10&1023|55296),e=56320|1023&e),o+=w(e);return o}function c(t,e){if(t>=55296&&t<=57343){if(e)throw Error("Lone surrogate U+"+t.toString(16).toUpperCase()+" is not a scalar value");return!1}return!0}function p(t,e){return w(t>>e&63|128)}function u(t,e){if(0==(4294967168&t))return w(t);var n="";return 0==(4294965248&t)?n=w(t>>6&31|192):0==(4294901760&t)?(c(t,e)||(t=65533),n=w(t>>12&15|224),n+=p(t,6)):0==(4292870144&t)&&(n=w(t>>18&7|240),n+=p(t,12),n+=p(t,6)),n+=w(63&t|128)}function h(t,e){e=e||{};for(var n,r=!1!==e.strict,o=s(t),i=o.length,a=-1,c="";++a<i;)n=o[a],c+=u(n,r);return c}function f(){if(b>=v)throw Error("Invalid byte index");var t=255&g[b];if(b++,128==(192&t))return 63&t;throw Error("Invalid continuation byte")}function l(t){var e,n,r,o,i;if(b>v)throw Error("Invalid byte index");if(b==v)return!1;if(e=255&g[b],b++,0==(128&e))return e;if(192==(224&e)){if(n=f(),i=(31&e)<<6|n,i>=128)return i;throw Error("Invalid continuation byte")}if(224==(240&e)){if(n=f(),r=f(),i=(15&e)<<12|n<<6|r,i>=2048)return c(i,t)?i:65533;throw Error("Invalid continuation byte")}if(240==(248&e)&&(n=f(),r=f(),o=f(),i=(7&e)<<18|n<<12|r<<6|o,i>=65536&&i<=1114111))return i;throw Error("Invalid UTF-8 detected")}function d(t,e){e=e||{};var n=!1!==e.strict;g=s(t),v=g.length,b=0;for(var r,o=[];(r=l(n))!==!1;)o.push(r);return a(o)}var y="object"==typeof e&&e,m=("object"==typeof t&&t&&t.exports==y&&t,"object"==typeof o&&o);m.global!==m&&m.window!==m||(i=m);var g,v,b,w=String.fromCharCode,k={version:"2.1.2",encode:h,decode:d};r=function(){return k}.call(e,n,e,t),!(void 0!==r&&(t.exports=r))}(this)}).call(e,n(28)(t),function(){return this}())},function(t,e){t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children=[],t.webpackPolyfill=1),t}},function(t,e){!function(){"use strict";for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(256),r=0;r<t.length;r++)n[t.charCodeAt(r)]=r;e.encode=function(e){var n,r=new Uint8Array(e),o=r.length,i="";for(n=0;n<o;n+=3)i+=t[r[n]>>2],i+=t[(3&r[n])<<4|r[n+1]>>4],i+=t[(15&r[n+1])<<2|r[n+2]>>6],i+=t[63&r[n+2]];return o%3===2?i=i.substring(0,i.length-1)+"=":o%3===1&&(i=i.substring(0,i.length-2)+"=="),i},e.decode=function(t){var e,r,o,i,s,a=.75*t.length,c=t.length,p=0;"="===t[t.length-1]&&(a--,"="===t[t.length-2]&&a--);var u=new ArrayBuffer(a),h=new Uint8Array(u);for(e=0;e<c;e+=4)r=n[t.charCodeAt(e)],o=n[t.charCodeAt(e+1)],i=n[t.charCodeAt(e+2)],s=n[t.charCodeAt(e+3)],h[p++]=r<<2|o>>4,h[p++]=(15&o)<<4|i>>2,h[p++]=(3&i)<<6|63&s;return u}}()},function(t,e){(function(e){function n(t){for(var e=0;e<t.length;e++){var n=t[e];if(n.buffer instanceof ArrayBuffer){var r=n.buffer;if(n.byteLength!==r.byteLength){var o=new Uint8Array(n.byteLength);o.set(new Uint8Array(r,n.byteOffset,n.byteLength)),r=o.buffer}t[e]=r}}}function r(t,e){e=e||{};var r=new i;n(t);for(var o=0;o<t.length;o++)r.append(t[o]);return e.type?r.getBlob(e.type):r.getBlob()}function o(t,e){return n(t),new Blob(t,e||{})}var i=e.BlobBuilder||e.WebKitBlobBuilder||e.MSBlobBuilder||e.MozBlobBuilder,s=function(){try{var t=new Blob(["hi"]);return 2===t.size}catch(e){return!1}}(),a=s&&function(){try{var t=new Blob([new Uint8Array([1,2])]);return 2===t.size}catch(e){return!1}}(),c=i&&i.prototype.append&&i.prototype.getBlob;t.exports=function(){return s?a?e.Blob:o:c?r:void 0}()}).call(e,function(){return this}())},function(t,e){e.encode=function(t){var e="";for(var n in t)t.hasOwnProperty(n)&&(e.length&&(e+="&"),e+=encodeURIComponent(n)+"="+encodeURIComponent(t[n]));return e},e.decode=function(t){for(var e={},n=t.split("&"),r=0,o=n.length;r<o;r++){var i=n[r].split("=");e[decodeURIComponent(i[0])]=decodeURIComponent(i[1])}return e}},function(t,e){t.exports=function(t,e){var n=function(){};n.prototype=e.prototype,t.prototype=new n,t.prototype.constructor=t}},function(t,e){"use strict";function n(t){var e="";do e=s[t%a]+e,t=Math.floor(t/a);while(t>0);return e}function r(t){var e=0;for(u=0;u<t.length;u++)e=e*a+c[t.charAt(u)];return e}function o(){var t=n(+new Date);return t!==i?(p=0,i=t):t+"."+n(p++)}for(var i,s="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),a=64,c={},p=0,u=0;u<a;u++)c[s[u]]=u;o.encode=n,o.decode=r,t.exports=o},function(t,e,n){(function(e){function r(){}function o(t){i.call(this,t),this.query=this.query||{},a||(e.___eio||(e.___eio=[]),a=e.___eio),this.index=a.length;var n=this;a.push(function(t){n.onData(t)}),this.query.j=this.index,e.document&&e.addEventListener&&e.addEventListener("beforeunload",function(){n.script&&(n.script.onerror=r)},!1)}var i=n(21),s=n(32);t.exports=o;var a,c=/\n/g,p=/\\n/g;s(o,i),o.prototype.supportsBinary=!1,o.prototype.doClose=function(){this.script&&(this.script.parentNode.removeChild(this.script),this.script=null),this.form&&(this.form.parentNode.removeChild(this.form),this.form=null,this.iframe=null),i.prototype.doClose.call(this)},o.prototype.doPoll=function(){var t=this,e=document.createElement("script");this.script&&(this.script.parentNode.removeChild(this.script),this.script=null),e.async=!0,e.src=this.uri(),e.onerror=function(e){t.onError("jsonp poll error",e)};var n=document.getElementsByTagName("script")[0];n?n.parentNode.insertBefore(e,n):(document.head||document.body).appendChild(e),this.script=e;var r="undefined"!=typeof navigator&&/gecko/i.test(navigator.userAgent);r&&setTimeout(function(){var t=document.createElement("iframe");document.body.appendChild(t),document.body.removeChild(t)},100)},o.prototype.doWrite=function(t,e){function n(){r(),e()}function r(){if(o.iframe)try{o.form.removeChild(o.iframe)}catch(t){o.onError("jsonp polling iframe removal error",t)}try{var e='<iframe src="javascript:0" name="'+o.iframeId+'">';i=document.createElement(e)}catch(t){i=document.createElement("iframe"),i.name=o.iframeId,i.src="javascript:0"}i.id=o.iframeId,o.form.appendChild(i),o.iframe=i}var o=this;if(!this.form){var i,s=document.createElement("form"),a=document.createElement("textarea"),u=this.iframeId="eio_iframe_"+this.index;s.className="socketio",s.style.position="absolute",s.style.top="-1000px",s.style.left="-1000px",s.target=u,s.method="POST",s.setAttribute("accept-charset","utf-8"),a.name="d",s.appendChild(a),document.body.appendChild(s),this.form=s,this.area=a}this.form.action=this.uri(),r(),t=t.replace(p,"\\\n"),this.area.value=t.replace(c,"\\n");try{this.form.submit()}catch(h){}this.iframe.attachEvent?this.iframe.onreadystatechange=function(){"complete"===o.iframe.readyState&&n()}:this.iframe.onload=n}}).call(e,function(){return this}())},function(t,e,n){(function(e){function r(t){var e=t&&t.forceBase64;e&&(this.supportsBinary=!1),this.perMessageDeflate=t.perMessageDeflate,this.usingBrowserWebSocket=h&&!t.forceNode,this.protocols=t.protocols,this.usingBrowserWebSocket||(l=o),i.call(this,t)}var o,i=n(22),s=n(23),a=n(31),c=n(32),p=n(33),u=n(3)("engine.io-client:websocket"),h=e.WebSocket||e.MozWebSocket;if("undefined"==typeof window)try{o=n(36)}catch(f){}var l=h;l||"undefined"!=typeof window||(l=o),t.exports=r,c(r,i),r.prototype.name="websocket",r.prototype.supportsBinary=!0,r.prototype.doOpen=function(){if(this.check()){var t=this.uri(),e=this.protocols,n={agent:this.agent,perMessageDeflate:this.perMessageDeflate};n.pfx=this.pfx,n.key=this.key,n.passphrase=this.passphrase,n.cert=this.cert,n.ca=this.ca,n.ciphers=this.ciphers,n.rejectUnauthorized=this.rejectUnauthorized,this.extraHeaders&&(n.headers=this.extraHeaders),this.localAddress&&(n.localAddress=this.localAddress);try{this.ws=this.usingBrowserWebSocket?e?new l(t,e):new l(t):new l(t,e,n)}catch(r){return this.emit("error",r)}void 0===this.ws.binaryType&&(this.supportsBinary=!1),this.ws.supports&&this.ws.supports.binary?(this.supportsBinary=!0,this.ws.binaryType="nodebuffer"):this.ws.binaryType="arraybuffer",this.addEventListeners()}},r.prototype.addEventListeners=function(){var t=this;this.ws.onopen=function(){t.onOpen()},this.ws.onclose=function(){t.onClose()},this.ws.onmessage=function(e){t.onData(e.data)},this.ws.onerror=function(e){t.onError("websocket error",e)}},r.prototype.write=function(t){function n(){r.emit("flush"),setTimeout(function(){r.writable=!0,r.emit("drain")},0)}var r=this;this.writable=!1;for(var o=t.length,i=0,a=o;i<a;i++)!function(t){s.encodePacket(t,r.supportsBinary,function(i){if(!r.usingBrowserWebSocket){var s={};if(t.options&&(s.compress=t.options.compress),r.perMessageDeflate){var a="string"==typeof i?e.Buffer.byteLength(i):i.length;a<r.perMessageDeflate.threshold&&(s.compress=!1)}}try{r.usingBrowserWebSocket?r.ws.send(i):r.ws.send(i,s)}catch(c){u("websocket closed before onclose event")}--o||n()})}(t[i])},r.prototype.onClose=function(){i.prototype.onClose.call(this)},r.prototype.doClose=function(){"undefined"!=typeof this.ws&&this.ws.close()},r.prototype.uri=function(){var t=this.query||{},e=this.secure?"wss":"ws",n="";this.port&&("wss"===e&&443!==Number(this.port)||"ws"===e&&80!==Number(this.port))&&(n=":"+this.port),this.timestampRequests&&(t[this.timestampParam]=p()),this.supportsBinary||(t.b64=1),t=a.encode(t),t.length&&(t="?"+t);var r=this.hostname.indexOf(":")!==-1;return e+"://"+(r?"["+this.hostname+"]":this.hostname)+n+this.path+t},r.prototype.check=function(){return!(!l||"__initialize"in l&&this.name===r.prototype.name)}}).call(e,function(){return this}())},function(t,e){},function(t,e){var n=[].indexOf;t.exports=function(t,e){if(n)return t.indexOf(e);for(var r=0;r<t.length;++r)if(t[r]===e)return r;return-1}},function(t,e){(function(e){var n=/^[\],:{}\s]*$/,r=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,o=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,i=/(?:^|:|,)(?:\s*\[)+/g,s=/^\s+/,a=/\s+$/;t.exports=function(t){return"string"==typeof t&&t?(t=t.replace(s,"").replace(a,""),e.JSON&&JSON.parse?JSON.parse(t):n.test(t.replace(r,"@").replace(o,"]").replace(i,""))?new Function("return "+t)():void 0):null}}).call(e,function(){return this}())},function(t,e,n){"use strict";function r(t,e,n){this.io=t,this.nsp=e,this.json=this,this.ids=0,this.acks={},this.receiveBuffer=[],this.sendBuffer=[],this.connected=!1,this.disconnected=!0,n&&n.query&&(this.query=n.query),this.io.autoConnect&&this.open()}var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i=n(7),s=n(8),a=n(40),c=n(41),p=n(42),u=n(3)("socket.io-client:socket"),h=n(31);t.exports=e=r;var f={connect:1,connect_error:1,connect_timeout:1,connecting:1,disconnect:1,error:1,reconnect:1,reconnect_attempt:1,reconnect_failed:1,reconnect_error:1,reconnecting:1,ping:1,pong:1},l=s.prototype.emit;s(r.prototype),r.prototype.subEvents=function(){if(!this.subs){var t=this.io;this.subs=[c(t,"open",p(this,"onopen")),c(t,"packet",p(this,"onpacket")),c(t,"close",p(this,"onclose"))]}},r.prototype.open=r.prototype.connect=function(){return this.connected?this:(this.subEvents(),this.io.open(),"open"===this.io.readyState&&this.onopen(),this.emit("connecting"),this)},r.prototype.send=function(){var t=a(arguments);return t.unshift("message"),this.emit.apply(this,t),this},r.prototype.emit=function(t){if(f.hasOwnProperty(t))return l.apply(this,arguments),this;var e=a(arguments),n={type:i.EVENT,data:e};return n.options={},n.options.compress=!this.flags||!1!==this.flags.compress,"function"==typeof e[e.length-1]&&(u("emitting packet with ack id %d",this.ids),this.acks[this.ids]=e.pop(),n.id=this.ids++),this.connected?this.packet(n):this.sendBuffer.push(n),delete this.flags,this},r.prototype.packet=function(t){t.nsp=this.nsp,this.io.packet(t)},r.prototype.onopen=function(){if(u("transport is open - connecting"),"/"!==this.nsp)if(this.query){var t="object"===o(this.query)?h.encode(this.query):this.query;u("sending connect packet with query %s",t),this.packet({type:i.CONNECT,query:t})}else this.packet({type:i.CONNECT})},r.prototype.onclose=function(t){u("close (%s)",t),this.connected=!1,this.disconnected=!0,delete this.id,this.emit("disconnect",t)},r.prototype.onpacket=function(t){if(t.nsp===this.nsp)switch(t.type){case i.CONNECT:this.onconnect();break;case i.EVENT:this.onevent(t);break;case i.BINARY_EVENT:this.onevent(t);break;case i.ACK:this.onack(t);break;case i.BINARY_ACK:this.onack(t);break;case i.DISCONNECT:this.ondisconnect();break;case i.ERROR:this.emit("error",t.data)}},r.prototype.onevent=function(t){var e=t.data||[];u("emitting event %j",e),null!=t.id&&(u("attaching ack callback to event"),e.push(this.ack(t.id))),this.connected?l.apply(this,e):this.receiveBuffer.push(e)},r.prototype.ack=function(t){var e=this,n=!1;return function(){if(!n){n=!0;var r=a(arguments);u("sending ack %j",r),e.packet({type:i.ACK,id:t,data:r})}}},r.prototype.onack=function(t){var e=this.acks[t.id];"function"==typeof e?(u("calling ack %s with %j",t.id,t.data),e.apply(this,t.data),delete this.acks[t.id]):u("bad ack %s",t.id)},r.prototype.onconnect=function(){this.connected=!0,this.disconnected=!1,this.emit("connect"),this.emitBuffered()},r.prototype.emitBuffered=function(){var t;for(t=0;t<this.receiveBuffer.length;t++)l.apply(this,this.receiveBuffer[t]);for(this.receiveBuffer=[],t=0;t<this.sendBuffer.length;t++)this.packet(this.sendBuffer[t]);this.sendBuffer=[]},r.prototype.ondisconnect=function(){u("server disconnect (%s)",this.nsp),this.destroy(),this.onclose("io server disconnect")},r.prototype.destroy=function(){if(this.subs){for(var t=0;t<this.subs.length;t++)this.subs[t].destroy();this.subs=null}this.io.destroy(this)},r.prototype.close=r.prototype.disconnect=function(){return this.connected&&(u("performing disconnect (%s)",this.nsp),this.packet({type:i.DISCONNECT})),this.destroy(),this.connected&&this.onclose("io client disconnect"),this},r.prototype.compress=function(t){return this.flags=this.flags||{},this.flags.compress=t,this}},function(t,e){function n(t,e){var n=[];e=e||0;for(var r=e||0;r<t.length;r++)n[r-e]=t[r];return n}t.exports=n},function(t,e){"use strict";function n(t,e,n){return t.on(e,n),{destroy:function(){t.removeListener(e,n)}}}t.exports=n},function(t,e){var n=[].slice;t.exports=function(t,e){if("string"==typeof e&&(e=t[e]),"function"!=typeof e)throw new Error("bind() requires a function");var r=n.call(arguments,2);return function(){return e.apply(t,r.concat(n.call(arguments)))}}},function(t,e){function n(t){t=t||{},this.ms=t.min||100,this.max=t.max||1e4,this.factor=t.factor||2,this.jitter=t.jitter>0&&t.jitter<=1?t.jitter:0,this.attempts=0}t.exports=n,n.prototype.duration=function(){var t=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var e=Math.random(),n=Math.floor(e*this.jitter*t);t=0==(1&Math.floor(10*e))?t-n:t+n}return 0|Math.min(t,this.max)},n.prototype.reset=function(){this.attempts=0},n.prototype.setMin=function(t){this.ms=t},n.prototype.setMax=function(t){this.max=t},n.prototype.setJitter=function(t){this.jitter=t}}])});
1
+ /*!
2
+ * Socket.IO v4.4.1
3
+ * (c) 2014-2022 Guillermo Rauch
4
+ * Released under the MIT License.
5
+ */
6
+ (function (global, factory) {
7
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
8
+ typeof define === 'function' && define.amd ? define(factory) :
9
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.io = factory());
10
+ })(this, (function () { 'use strict';
11
+
12
+ function _typeof(obj) {
13
+ "@babel/helpers - typeof";
14
+
15
+ if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
16
+ _typeof = function (obj) {
17
+ return typeof obj;
18
+ };
19
+ } else {
20
+ _typeof = function (obj) {
21
+ return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
22
+ };
23
+ }
24
+
25
+ return _typeof(obj);
26
+ }
27
+
28
+ function _classCallCheck(instance, Constructor) {
29
+ if (!(instance instanceof Constructor)) {
30
+ throw new TypeError("Cannot call a class as a function");
31
+ }
32
+ }
33
+
34
+ function _defineProperties(target, props) {
35
+ for (var i = 0; i < props.length; i++) {
36
+ var descriptor = props[i];
37
+ descriptor.enumerable = descriptor.enumerable || false;
38
+ descriptor.configurable = true;
39
+ if ("value" in descriptor) descriptor.writable = true;
40
+ Object.defineProperty(target, descriptor.key, descriptor);
41
+ }
42
+ }
43
+
44
+ function _createClass(Constructor, protoProps, staticProps) {
45
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
46
+ if (staticProps) _defineProperties(Constructor, staticProps);
47
+ return Constructor;
48
+ }
49
+
50
+ function _extends() {
51
+ _extends = Object.assign || function (target) {
52
+ for (var i = 1; i < arguments.length; i++) {
53
+ var source = arguments[i];
54
+
55
+ for (var key in source) {
56
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
57
+ target[key] = source[key];
58
+ }
59
+ }
60
+ }
61
+
62
+ return target;
63
+ };
64
+
65
+ return _extends.apply(this, arguments);
66
+ }
67
+
68
+ function _inherits(subClass, superClass) {
69
+ if (typeof superClass !== "function" && superClass !== null) {
70
+ throw new TypeError("Super expression must either be null or a function");
71
+ }
72
+
73
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
74
+ constructor: {
75
+ value: subClass,
76
+ writable: true,
77
+ configurable: true
78
+ }
79
+ });
80
+ if (superClass) _setPrototypeOf(subClass, superClass);
81
+ }
82
+
83
+ function _getPrototypeOf(o) {
84
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
85
+ return o.__proto__ || Object.getPrototypeOf(o);
86
+ };
87
+ return _getPrototypeOf(o);
88
+ }
89
+
90
+ function _setPrototypeOf(o, p) {
91
+ _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
92
+ o.__proto__ = p;
93
+ return o;
94
+ };
95
+
96
+ return _setPrototypeOf(o, p);
97
+ }
98
+
99
+ function _isNativeReflectConstruct() {
100
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
101
+ if (Reflect.construct.sham) return false;
102
+ if (typeof Proxy === "function") return true;
103
+
104
+ try {
105
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
106
+ return true;
107
+ } catch (e) {
108
+ return false;
109
+ }
110
+ }
111
+
112
+ function _assertThisInitialized(self) {
113
+ if (self === void 0) {
114
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
115
+ }
116
+
117
+ return self;
118
+ }
119
+
120
+ function _possibleConstructorReturn(self, call) {
121
+ if (call && (typeof call === "object" || typeof call === "function")) {
122
+ return call;
123
+ } else if (call !== void 0) {
124
+ throw new TypeError("Derived constructors may only return object or undefined");
125
+ }
126
+
127
+ return _assertThisInitialized(self);
128
+ }
129
+
130
+ function _createSuper(Derived) {
131
+ var hasNativeReflectConstruct = _isNativeReflectConstruct();
132
+
133
+ return function _createSuperInternal() {
134
+ var Super = _getPrototypeOf(Derived),
135
+ result;
136
+
137
+ if (hasNativeReflectConstruct) {
138
+ var NewTarget = _getPrototypeOf(this).constructor;
139
+
140
+ result = Reflect.construct(Super, arguments, NewTarget);
141
+ } else {
142
+ result = Super.apply(this, arguments);
143
+ }
144
+
145
+ return _possibleConstructorReturn(this, result);
146
+ };
147
+ }
148
+
149
+ function _superPropBase(object, property) {
150
+ while (!Object.prototype.hasOwnProperty.call(object, property)) {
151
+ object = _getPrototypeOf(object);
152
+ if (object === null) break;
153
+ }
154
+
155
+ return object;
156
+ }
157
+
158
+ function _get(target, property, receiver) {
159
+ if (typeof Reflect !== "undefined" && Reflect.get) {
160
+ _get = Reflect.get;
161
+ } else {
162
+ _get = function _get(target, property, receiver) {
163
+ var base = _superPropBase(target, property);
164
+
165
+ if (!base) return;
166
+ var desc = Object.getOwnPropertyDescriptor(base, property);
167
+
168
+ if (desc.get) {
169
+ return desc.get.call(receiver);
170
+ }
171
+
172
+ return desc.value;
173
+ };
174
+ }
175
+
176
+ return _get(target, property, receiver || target);
177
+ }
178
+
179
+ function _unsupportedIterableToArray(o, minLen) {
180
+ if (!o) return;
181
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
182
+ var n = Object.prototype.toString.call(o).slice(8, -1);
183
+ if (n === "Object" && o.constructor) n = o.constructor.name;
184
+ if (n === "Map" || n === "Set") return Array.from(o);
185
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
186
+ }
187
+
188
+ function _arrayLikeToArray(arr, len) {
189
+ if (len == null || len > arr.length) len = arr.length;
190
+
191
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
192
+
193
+ return arr2;
194
+ }
195
+
196
+ function _createForOfIteratorHelper(o, allowArrayLike) {
197
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
198
+
199
+ if (!it) {
200
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
201
+ if (it) o = it;
202
+ var i = 0;
203
+
204
+ var F = function () {};
205
+
206
+ return {
207
+ s: F,
208
+ n: function () {
209
+ if (i >= o.length) return {
210
+ done: true
211
+ };
212
+ return {
213
+ done: false,
214
+ value: o[i++]
215
+ };
216
+ },
217
+ e: function (e) {
218
+ throw e;
219
+ },
220
+ f: F
221
+ };
222
+ }
223
+
224
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
225
+ }
226
+
227
+ var normalCompletion = true,
228
+ didErr = false,
229
+ err;
230
+ return {
231
+ s: function () {
232
+ it = it.call(o);
233
+ },
234
+ n: function () {
235
+ var step = it.next();
236
+ normalCompletion = step.done;
237
+ return step;
238
+ },
239
+ e: function (e) {
240
+ didErr = true;
241
+ err = e;
242
+ },
243
+ f: function () {
244
+ try {
245
+ if (!normalCompletion && it.return != null) it.return();
246
+ } finally {
247
+ if (didErr) throw err;
248
+ }
249
+ }
250
+ };
251
+ }
252
+
253
+ /**
254
+ * Parses an URI
255
+ *
256
+ * @author Steven Levithan <stevenlevithan.com> (MIT license)
257
+ * @api private
258
+ */
259
+ var re = /^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
260
+ var parts = ['source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'];
261
+
262
+ var parseuri = function parseuri(str) {
263
+ var src = str,
264
+ b = str.indexOf('['),
265
+ e = str.indexOf(']');
266
+
267
+ if (b != -1 && e != -1) {
268
+ str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ';') + str.substring(e, str.length);
269
+ }
270
+
271
+ var m = re.exec(str || ''),
272
+ uri = {},
273
+ i = 14;
274
+
275
+ while (i--) {
276
+ uri[parts[i]] = m[i] || '';
277
+ }
278
+
279
+ if (b != -1 && e != -1) {
280
+ uri.source = src;
281
+ uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ':');
282
+ uri.authority = uri.authority.replace('[', '').replace(']', '').replace(/;/g, ':');
283
+ uri.ipv6uri = true;
284
+ }
285
+
286
+ uri.pathNames = pathNames(uri, uri['path']);
287
+ uri.queryKey = queryKey(uri, uri['query']);
288
+ return uri;
289
+ };
290
+
291
+ function pathNames(obj, path) {
292
+ var regx = /\/{2,9}/g,
293
+ names = path.replace(regx, "/").split("/");
294
+
295
+ if (path.substr(0, 1) == '/' || path.length === 0) {
296
+ names.splice(0, 1);
297
+ }
298
+
299
+ if (path.substr(path.length - 1, 1) == '/') {
300
+ names.splice(names.length - 1, 1);
301
+ }
302
+
303
+ return names;
304
+ }
305
+
306
+ function queryKey(uri, query) {
307
+ var data = {};
308
+ query.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function ($0, $1, $2) {
309
+ if ($1) {
310
+ data[$1] = $2;
311
+ }
312
+ });
313
+ return data;
314
+ }
315
+
316
+ /**
317
+ * URL parser.
318
+ *
319
+ * @param uri - url
320
+ * @param path - the request path of the connection
321
+ * @param loc - An object meant to mimic window.location.
322
+ * Defaults to window.location.
323
+ * @public
324
+ */
325
+
326
+ function url(uri) {
327
+ var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
328
+ var loc = arguments.length > 2 ? arguments[2] : undefined;
329
+ var obj = uri; // default to window.location
330
+
331
+ loc = loc || typeof location !== "undefined" && location;
332
+ if (null == uri) uri = loc.protocol + "//" + loc.host; // relative path support
333
+
334
+ if (typeof uri === "string") {
335
+ if ("/" === uri.charAt(0)) {
336
+ if ("/" === uri.charAt(1)) {
337
+ uri = loc.protocol + uri;
338
+ } else {
339
+ uri = loc.host + uri;
340
+ }
341
+ }
342
+
343
+ if (!/^(https?|wss?):\/\//.test(uri)) {
344
+ if ("undefined" !== typeof loc) {
345
+ uri = loc.protocol + "//" + uri;
346
+ } else {
347
+ uri = "https://" + uri;
348
+ }
349
+ } // parse
350
+
351
+
352
+ obj = parseuri(uri);
353
+ } // make sure we treat `localhost:80` and `localhost` equally
354
+
355
+
356
+ if (!obj.port) {
357
+ if (/^(http|ws)$/.test(obj.protocol)) {
358
+ obj.port = "80";
359
+ } else if (/^(http|ws)s$/.test(obj.protocol)) {
360
+ obj.port = "443";
361
+ }
362
+ }
363
+
364
+ obj.path = obj.path || "/";
365
+ var ipv6 = obj.host.indexOf(":") !== -1;
366
+ var host = ipv6 ? "[" + obj.host + "]" : obj.host; // define unique id
367
+
368
+ obj.id = obj.protocol + "://" + host + ":" + obj.port + path; // define href
369
+
370
+ obj.href = obj.protocol + "://" + host + (loc && loc.port === obj.port ? "" : ":" + obj.port);
371
+ return obj;
372
+ }
373
+
374
+ var hasCors = {exports: {}};
375
+
376
+ /**
377
+ * Module exports.
378
+ *
379
+ * Logic borrowed from Modernizr:
380
+ *
381
+ * - https://github.com/Modernizr/Modernizr/blob/master/feature-detects/cors.js
382
+ */
383
+
384
+ try {
385
+ hasCors.exports = typeof XMLHttpRequest !== 'undefined' && 'withCredentials' in new XMLHttpRequest();
386
+ } catch (err) {
387
+ // if XMLHttp support is disabled in IE then it will throw
388
+ // when trying to create
389
+ hasCors.exports = false;
390
+ }
391
+
392
+ var hasCORS = hasCors.exports;
393
+
394
+ var globalThis = (function () {
395
+ if (typeof self !== "undefined") {
396
+ return self;
397
+ } else if (typeof window !== "undefined") {
398
+ return window;
399
+ } else {
400
+ return Function("return this")();
401
+ }
402
+ })();
403
+
404
+ // browser shim for xmlhttprequest module
405
+ function XMLHttpRequest$1 (opts) {
406
+ var xdomain = opts.xdomain; // XMLHttpRequest can be disabled on IE
407
+
408
+ try {
409
+ if ("undefined" !== typeof XMLHttpRequest && (!xdomain || hasCORS)) {
410
+ return new XMLHttpRequest();
411
+ }
412
+ } catch (e) {}
413
+
414
+ if (!xdomain) {
415
+ try {
416
+ return new globalThis[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
417
+ } catch (e) {}
418
+ }
419
+ }
420
+
421
+ function pick(obj) {
422
+ for (var _len = arguments.length, attr = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
423
+ attr[_key - 1] = arguments[_key];
424
+ }
425
+
426
+ return attr.reduce(function (acc, k) {
427
+ if (obj.hasOwnProperty(k)) {
428
+ acc[k] = obj[k];
429
+ }
430
+
431
+ return acc;
432
+ }, {});
433
+ } // Keep a reference to the real timeout functions so they can be used when overridden
434
+
435
+ var NATIVE_SET_TIMEOUT = setTimeout;
436
+ var NATIVE_CLEAR_TIMEOUT = clearTimeout;
437
+ function installTimerFunctions(obj, opts) {
438
+ if (opts.useNativeTimers) {
439
+ obj.setTimeoutFn = NATIVE_SET_TIMEOUT.bind(globalThis);
440
+ obj.clearTimeoutFn = NATIVE_CLEAR_TIMEOUT.bind(globalThis);
441
+ } else {
442
+ obj.setTimeoutFn = setTimeout.bind(globalThis);
443
+ obj.clearTimeoutFn = clearTimeout.bind(globalThis);
444
+ }
445
+ }
446
+
447
+ /**
448
+ * Expose `Emitter`.
449
+ */
450
+
451
+ var Emitter_1 = Emitter;
452
+ /**
453
+ * Initialize a new `Emitter`.
454
+ *
455
+ * @api public
456
+ */
457
+
458
+ function Emitter(obj) {
459
+ if (obj) return mixin(obj);
460
+ }
461
+ /**
462
+ * Mixin the emitter properties.
463
+ *
464
+ * @param {Object} obj
465
+ * @return {Object}
466
+ * @api private
467
+ */
468
+
469
+
470
+ function mixin(obj) {
471
+ for (var key in Emitter.prototype) {
472
+ obj[key] = Emitter.prototype[key];
473
+ }
474
+
475
+ return obj;
476
+ }
477
+ /**
478
+ * Listen on the given `event` with `fn`.
479
+ *
480
+ * @param {String} event
481
+ * @param {Function} fn
482
+ * @return {Emitter}
483
+ * @api public
484
+ */
485
+
486
+
487
+ Emitter.prototype.on = Emitter.prototype.addEventListener = function (event, fn) {
488
+ this._callbacks = this._callbacks || {};
489
+ (this._callbacks['$' + event] = this._callbacks['$' + event] || []).push(fn);
490
+ return this;
491
+ };
492
+ /**
493
+ * Adds an `event` listener that will be invoked a single
494
+ * time then automatically removed.
495
+ *
496
+ * @param {String} event
497
+ * @param {Function} fn
498
+ * @return {Emitter}
499
+ * @api public
500
+ */
501
+
502
+
503
+ Emitter.prototype.once = function (event, fn) {
504
+ function on() {
505
+ this.off(event, on);
506
+ fn.apply(this, arguments);
507
+ }
508
+
509
+ on.fn = fn;
510
+ this.on(event, on);
511
+ return this;
512
+ };
513
+ /**
514
+ * Remove the given callback for `event` or all
515
+ * registered callbacks.
516
+ *
517
+ * @param {String} event
518
+ * @param {Function} fn
519
+ * @return {Emitter}
520
+ * @api public
521
+ */
522
+
523
+
524
+ Emitter.prototype.off = Emitter.prototype.removeListener = Emitter.prototype.removeAllListeners = Emitter.prototype.removeEventListener = function (event, fn) {
525
+ this._callbacks = this._callbacks || {}; // all
526
+
527
+ if (0 == arguments.length) {
528
+ this._callbacks = {};
529
+ return this;
530
+ } // specific event
531
+
532
+
533
+ var callbacks = this._callbacks['$' + event];
534
+ if (!callbacks) return this; // remove all handlers
535
+
536
+ if (1 == arguments.length) {
537
+ delete this._callbacks['$' + event];
538
+ return this;
539
+ } // remove specific handler
540
+
541
+
542
+ var cb;
543
+
544
+ for (var i = 0; i < callbacks.length; i++) {
545
+ cb = callbacks[i];
546
+
547
+ if (cb === fn || cb.fn === fn) {
548
+ callbacks.splice(i, 1);
549
+ break;
550
+ }
551
+ } // Remove event specific arrays for event types that no
552
+ // one is subscribed for to avoid memory leak.
553
+
554
+
555
+ if (callbacks.length === 0) {
556
+ delete this._callbacks['$' + event];
557
+ }
558
+
559
+ return this;
560
+ };
561
+ /**
562
+ * Emit `event` with the given args.
563
+ *
564
+ * @param {String} event
565
+ * @param {Mixed} ...
566
+ * @return {Emitter}
567
+ */
568
+
569
+
570
+ Emitter.prototype.emit = function (event) {
571
+ this._callbacks = this._callbacks || {};
572
+ var args = new Array(arguments.length - 1),
573
+ callbacks = this._callbacks['$' + event];
574
+
575
+ for (var i = 1; i < arguments.length; i++) {
576
+ args[i - 1] = arguments[i];
577
+ }
578
+
579
+ if (callbacks) {
580
+ callbacks = callbacks.slice(0);
581
+
582
+ for (var i = 0, len = callbacks.length; i < len; ++i) {
583
+ callbacks[i].apply(this, args);
584
+ }
585
+ }
586
+
587
+ return this;
588
+ }; // alias used for reserved events (protected method)
589
+
590
+
591
+ Emitter.prototype.emitReserved = Emitter.prototype.emit;
592
+ /**
593
+ * Return array of callbacks for `event`.
594
+ *
595
+ * @param {String} event
596
+ * @return {Array}
597
+ * @api public
598
+ */
599
+
600
+ Emitter.prototype.listeners = function (event) {
601
+ this._callbacks = this._callbacks || {};
602
+ return this._callbacks['$' + event] || [];
603
+ };
604
+ /**
605
+ * Check if this emitter has `event` handlers.
606
+ *
607
+ * @param {String} event
608
+ * @return {Boolean}
609
+ * @api public
610
+ */
611
+
612
+
613
+ Emitter.prototype.hasListeners = function (event) {
614
+ return !!this.listeners(event).length;
615
+ };
616
+
617
+ var PACKET_TYPES = Object.create(null); // no Map = no polyfill
618
+
619
+ PACKET_TYPES["open"] = "0";
620
+ PACKET_TYPES["close"] = "1";
621
+ PACKET_TYPES["ping"] = "2";
622
+ PACKET_TYPES["pong"] = "3";
623
+ PACKET_TYPES["message"] = "4";
624
+ PACKET_TYPES["upgrade"] = "5";
625
+ PACKET_TYPES["noop"] = "6";
626
+ var PACKET_TYPES_REVERSE = Object.create(null);
627
+ Object.keys(PACKET_TYPES).forEach(function (key) {
628
+ PACKET_TYPES_REVERSE[PACKET_TYPES[key]] = key;
629
+ });
630
+ var ERROR_PACKET = {
631
+ type: "error",
632
+ data: "parser error"
633
+ };
634
+
635
+ var withNativeBlob$1 = typeof Blob === "function" || typeof Blob !== "undefined" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]";
636
+ var withNativeArrayBuffer$2 = typeof ArrayBuffer === "function"; // ArrayBuffer.isView method is not defined in IE10
637
+
638
+ var isView$1 = function isView(obj) {
639
+ return typeof ArrayBuffer.isView === "function" ? ArrayBuffer.isView(obj) : obj && obj.buffer instanceof ArrayBuffer;
640
+ };
641
+
642
+ var encodePacket = function encodePacket(_ref, supportsBinary, callback) {
643
+ var type = _ref.type,
644
+ data = _ref.data;
645
+
646
+ if (withNativeBlob$1 && data instanceof Blob) {
647
+ if (supportsBinary) {
648
+ return callback(data);
649
+ } else {
650
+ return encodeBlobAsBase64(data, callback);
651
+ }
652
+ } else if (withNativeArrayBuffer$2 && (data instanceof ArrayBuffer || isView$1(data))) {
653
+ if (supportsBinary) {
654
+ return callback(data);
655
+ } else {
656
+ return encodeBlobAsBase64(new Blob([data]), callback);
657
+ }
658
+ } // plain string
659
+
660
+
661
+ return callback(PACKET_TYPES[type] + (data || ""));
662
+ };
663
+
664
+ var encodeBlobAsBase64 = function encodeBlobAsBase64(data, callback) {
665
+ var fileReader = new FileReader();
666
+
667
+ fileReader.onload = function () {
668
+ var content = fileReader.result.split(",")[1];
669
+ callback("b" + content);
670
+ };
671
+
672
+ return fileReader.readAsDataURL(data);
673
+ };
674
+
675
+ /*
676
+ * base64-arraybuffer 1.0.1 <https://github.com/niklasvh/base64-arraybuffer>
677
+ * Copyright (c) 2021 Niklas von Hertzen <https://hertzen.com>
678
+ * Released under MIT License
679
+ */
680
+ var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; // Use a lookup table to find the index.
681
+
682
+ var lookup$1 = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
683
+
684
+ for (var i$1 = 0; i$1 < chars.length; i$1++) {
685
+ lookup$1[chars.charCodeAt(i$1)] = i$1;
686
+ }
687
+
688
+ var decode$1 = function decode(base64) {
689
+ var bufferLength = base64.length * 0.75,
690
+ len = base64.length,
691
+ i,
692
+ p = 0,
693
+ encoded1,
694
+ encoded2,
695
+ encoded3,
696
+ encoded4;
697
+
698
+ if (base64[base64.length - 1] === '=') {
699
+ bufferLength--;
700
+
701
+ if (base64[base64.length - 2] === '=') {
702
+ bufferLength--;
703
+ }
704
+ }
705
+
706
+ var arraybuffer = new ArrayBuffer(bufferLength),
707
+ bytes = new Uint8Array(arraybuffer);
708
+
709
+ for (i = 0; i < len; i += 4) {
710
+ encoded1 = lookup$1[base64.charCodeAt(i)];
711
+ encoded2 = lookup$1[base64.charCodeAt(i + 1)];
712
+ encoded3 = lookup$1[base64.charCodeAt(i + 2)];
713
+ encoded4 = lookup$1[base64.charCodeAt(i + 3)];
714
+ bytes[p++] = encoded1 << 2 | encoded2 >> 4;
715
+ bytes[p++] = (encoded2 & 15) << 4 | encoded3 >> 2;
716
+ bytes[p++] = (encoded3 & 3) << 6 | encoded4 & 63;
717
+ }
718
+
719
+ return arraybuffer;
720
+ };
721
+
722
+ var withNativeArrayBuffer$1 = typeof ArrayBuffer === "function";
723
+
724
+ var decodePacket = function decodePacket(encodedPacket, binaryType) {
725
+ if (typeof encodedPacket !== "string") {
726
+ return {
727
+ type: "message",
728
+ data: mapBinary(encodedPacket, binaryType)
729
+ };
730
+ }
731
+
732
+ var type = encodedPacket.charAt(0);
733
+
734
+ if (type === "b") {
735
+ return {
736
+ type: "message",
737
+ data: decodeBase64Packet(encodedPacket.substring(1), binaryType)
738
+ };
739
+ }
740
+
741
+ var packetType = PACKET_TYPES_REVERSE[type];
742
+
743
+ if (!packetType) {
744
+ return ERROR_PACKET;
745
+ }
746
+
747
+ return encodedPacket.length > 1 ? {
748
+ type: PACKET_TYPES_REVERSE[type],
749
+ data: encodedPacket.substring(1)
750
+ } : {
751
+ type: PACKET_TYPES_REVERSE[type]
752
+ };
753
+ };
754
+
755
+ var decodeBase64Packet = function decodeBase64Packet(data, binaryType) {
756
+ if (withNativeArrayBuffer$1) {
757
+ var decoded = decode$1(data);
758
+ return mapBinary(decoded, binaryType);
759
+ } else {
760
+ return {
761
+ base64: true,
762
+ data: data
763
+ }; // fallback for old browsers
764
+ }
765
+ };
766
+
767
+ var mapBinary = function mapBinary(data, binaryType) {
768
+ switch (binaryType) {
769
+ case "blob":
770
+ return data instanceof ArrayBuffer ? new Blob([data]) : data;
771
+
772
+ case "arraybuffer":
773
+ default:
774
+ return data;
775
+ // assuming the data is already an ArrayBuffer
776
+ }
777
+ };
778
+
779
+ var SEPARATOR = String.fromCharCode(30); // see https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text
780
+
781
+ var encodePayload = function encodePayload(packets, callback) {
782
+ // some packets may be added to the array while encoding, so the initial length must be saved
783
+ var length = packets.length;
784
+ var encodedPackets = new Array(length);
785
+ var count = 0;
786
+ packets.forEach(function (packet, i) {
787
+ // force base64 encoding for binary packets
788
+ encodePacket(packet, false, function (encodedPacket) {
789
+ encodedPackets[i] = encodedPacket;
790
+
791
+ if (++count === length) {
792
+ callback(encodedPackets.join(SEPARATOR));
793
+ }
794
+ });
795
+ });
796
+ };
797
+
798
+ var decodePayload = function decodePayload(encodedPayload, binaryType) {
799
+ var encodedPackets = encodedPayload.split(SEPARATOR);
800
+ var packets = [];
801
+
802
+ for (var i = 0; i < encodedPackets.length; i++) {
803
+ var decodedPacket = decodePacket(encodedPackets[i], binaryType);
804
+ packets.push(decodedPacket);
805
+
806
+ if (decodedPacket.type === "error") {
807
+ break;
808
+ }
809
+ }
810
+
811
+ return packets;
812
+ };
813
+
814
+ var protocol$1 = 4;
815
+
816
+ var Transport = /*#__PURE__*/function (_Emitter) {
817
+ _inherits(Transport, _Emitter);
818
+
819
+ var _super = _createSuper(Transport);
820
+
821
+ /**
822
+ * Transport abstract constructor.
823
+ *
824
+ * @param {Object} options.
825
+ * @api private
826
+ */
827
+ function Transport(opts) {
828
+ var _this;
829
+
830
+ _classCallCheck(this, Transport);
831
+
832
+ _this = _super.call(this);
833
+ _this.writable = false;
834
+ installTimerFunctions(_assertThisInitialized(_this), opts);
835
+ _this.opts = opts;
836
+ _this.query = opts.query;
837
+ _this.readyState = "";
838
+ _this.socket = opts.socket;
839
+ return _this;
840
+ }
841
+ /**
842
+ * Emits an error.
843
+ *
844
+ * @param {String} str
845
+ * @return {Transport} for chaining
846
+ * @api protected
847
+ */
848
+
849
+
850
+ _createClass(Transport, [{
851
+ key: "onError",
852
+ value: function onError(msg, desc) {
853
+ var err = new Error(msg); // @ts-ignore
854
+
855
+ err.type = "TransportError"; // @ts-ignore
856
+
857
+ err.description = desc;
858
+
859
+ _get(_getPrototypeOf(Transport.prototype), "emit", this).call(this, "error", err);
860
+
861
+ return this;
862
+ }
863
+ /**
864
+ * Opens the transport.
865
+ *
866
+ * @api public
867
+ */
868
+
869
+ }, {
870
+ key: "open",
871
+ value: function open() {
872
+ if ("closed" === this.readyState || "" === this.readyState) {
873
+ this.readyState = "opening";
874
+ this.doOpen();
875
+ }
876
+
877
+ return this;
878
+ }
879
+ /**
880
+ * Closes the transport.
881
+ *
882
+ * @api public
883
+ */
884
+
885
+ }, {
886
+ key: "close",
887
+ value: function close() {
888
+ if ("opening" === this.readyState || "open" === this.readyState) {
889
+ this.doClose();
890
+ this.onClose();
891
+ }
892
+
893
+ return this;
894
+ }
895
+ /**
896
+ * Sends multiple packets.
897
+ *
898
+ * @param {Array} packets
899
+ * @api public
900
+ */
901
+
902
+ }, {
903
+ key: "send",
904
+ value: function send(packets) {
905
+ if ("open" === this.readyState) {
906
+ this.write(packets);
907
+ }
908
+ }
909
+ /**
910
+ * Called upon open
911
+ *
912
+ * @api protected
913
+ */
914
+
915
+ }, {
916
+ key: "onOpen",
917
+ value: function onOpen() {
918
+ this.readyState = "open";
919
+ this.writable = true;
920
+
921
+ _get(_getPrototypeOf(Transport.prototype), "emit", this).call(this, "open");
922
+ }
923
+ /**
924
+ * Called with data.
925
+ *
926
+ * @param {String} data
927
+ * @api protected
928
+ */
929
+
930
+ }, {
931
+ key: "onData",
932
+ value: function onData(data) {
933
+ var packet = decodePacket(data, this.socket.binaryType);
934
+ this.onPacket(packet);
935
+ }
936
+ /**
937
+ * Called with a decoded packet.
938
+ *
939
+ * @api protected
940
+ */
941
+
942
+ }, {
943
+ key: "onPacket",
944
+ value: function onPacket(packet) {
945
+ _get(_getPrototypeOf(Transport.prototype), "emit", this).call(this, "packet", packet);
946
+ }
947
+ /**
948
+ * Called upon close.
949
+ *
950
+ * @api protected
951
+ */
952
+
953
+ }, {
954
+ key: "onClose",
955
+ value: function onClose() {
956
+ this.readyState = "closed";
957
+
958
+ _get(_getPrototypeOf(Transport.prototype), "emit", this).call(this, "close");
959
+ }
960
+ }]);
961
+
962
+ return Transport;
963
+ }(Emitter_1);
964
+
965
+ var alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_'.split(''),
966
+ length = 64,
967
+ map = {},
968
+ seed = 0,
969
+ i = 0,
970
+ prev;
971
+ /**
972
+ * Return a string representing the specified number.
973
+ *
974
+ * @param {Number} num The number to convert.
975
+ * @returns {String} The string representation of the number.
976
+ * @api public
977
+ */
978
+
979
+ function encode(num) {
980
+ var encoded = '';
981
+
982
+ do {
983
+ encoded = alphabet[num % length] + encoded;
984
+ num = Math.floor(num / length);
985
+ } while (num > 0);
986
+
987
+ return encoded;
988
+ }
989
+ /**
990
+ * Return the integer value specified by the given string.
991
+ *
992
+ * @param {String} str The string to convert.
993
+ * @returns {Number} The integer value represented by the string.
994
+ * @api public
995
+ */
996
+
997
+
998
+ function decode(str) {
999
+ var decoded = 0;
1000
+
1001
+ for (i = 0; i < str.length; i++) {
1002
+ decoded = decoded * length + map[str.charAt(i)];
1003
+ }
1004
+
1005
+ return decoded;
1006
+ }
1007
+ /**
1008
+ * Yeast: A tiny growing id generator.
1009
+ *
1010
+ * @returns {String} A unique id.
1011
+ * @api public
1012
+ */
1013
+
1014
+
1015
+ function yeast() {
1016
+ var now = encode(+new Date());
1017
+ if (now !== prev) return seed = 0, prev = now;
1018
+ return now + '.' + encode(seed++);
1019
+ } //
1020
+ // Map each character to its index.
1021
+ //
1022
+
1023
+
1024
+ for (; i < length; i++) {
1025
+ map[alphabet[i]] = i;
1026
+ } //
1027
+ // Expose the `yeast`, `encode` and `decode` functions.
1028
+ //
1029
+
1030
+
1031
+ yeast.encode = encode;
1032
+ yeast.decode = decode;
1033
+ var yeast_1 = yeast;
1034
+
1035
+ var parseqs = {};
1036
+
1037
+ /**
1038
+ * Compiles a querystring
1039
+ * Returns string representation of the object
1040
+ *
1041
+ * @param {Object}
1042
+ * @api private
1043
+ */
1044
+
1045
+ parseqs.encode = function (obj) {
1046
+ var str = '';
1047
+
1048
+ for (var i in obj) {
1049
+ if (obj.hasOwnProperty(i)) {
1050
+ if (str.length) str += '&';
1051
+ str += encodeURIComponent(i) + '=' + encodeURIComponent(obj[i]);
1052
+ }
1053
+ }
1054
+
1055
+ return str;
1056
+ };
1057
+ /**
1058
+ * Parses a simple querystring into an object
1059
+ *
1060
+ * @param {String} qs
1061
+ * @api private
1062
+ */
1063
+
1064
+
1065
+ parseqs.decode = function (qs) {
1066
+ var qry = {};
1067
+ var pairs = qs.split('&');
1068
+
1069
+ for (var i = 0, l = pairs.length; i < l; i++) {
1070
+ var pair = pairs[i].split('=');
1071
+ qry[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
1072
+ }
1073
+
1074
+ return qry;
1075
+ };
1076
+
1077
+ var Polling = /*#__PURE__*/function (_Transport) {
1078
+ _inherits(Polling, _Transport);
1079
+
1080
+ var _super = _createSuper(Polling);
1081
+
1082
+ function Polling() {
1083
+ var _this;
1084
+
1085
+ _classCallCheck(this, Polling);
1086
+
1087
+ _this = _super.apply(this, arguments);
1088
+ _this.polling = false;
1089
+ return _this;
1090
+ }
1091
+ /**
1092
+ * Transport name.
1093
+ */
1094
+
1095
+
1096
+ _createClass(Polling, [{
1097
+ key: "name",
1098
+ get: function get() {
1099
+ return "polling";
1100
+ }
1101
+ /**
1102
+ * Opens the socket (triggers polling). We write a PING message to determine
1103
+ * when the transport is open.
1104
+ *
1105
+ * @api private
1106
+ */
1107
+
1108
+ }, {
1109
+ key: "doOpen",
1110
+ value: function doOpen() {
1111
+ this.poll();
1112
+ }
1113
+ /**
1114
+ * Pauses polling.
1115
+ *
1116
+ * @param {Function} callback upon buffers are flushed and transport is paused
1117
+ * @api private
1118
+ */
1119
+
1120
+ }, {
1121
+ key: "pause",
1122
+ value: function pause(onPause) {
1123
+ var _this2 = this;
1124
+
1125
+ this.readyState = "pausing";
1126
+
1127
+ var pause = function pause() {
1128
+ _this2.readyState = "paused";
1129
+ onPause();
1130
+ };
1131
+
1132
+ if (this.polling || !this.writable) {
1133
+ var total = 0;
1134
+
1135
+ if (this.polling) {
1136
+ total++;
1137
+ this.once("pollComplete", function () {
1138
+ --total || pause();
1139
+ });
1140
+ }
1141
+
1142
+ if (!this.writable) {
1143
+ total++;
1144
+ this.once("drain", function () {
1145
+ --total || pause();
1146
+ });
1147
+ }
1148
+ } else {
1149
+ pause();
1150
+ }
1151
+ }
1152
+ /**
1153
+ * Starts polling cycle.
1154
+ *
1155
+ * @api public
1156
+ */
1157
+
1158
+ }, {
1159
+ key: "poll",
1160
+ value: function poll() {
1161
+ this.polling = true;
1162
+ this.doPoll();
1163
+ this.emit("poll");
1164
+ }
1165
+ /**
1166
+ * Overloads onData to detect payloads.
1167
+ *
1168
+ * @api private
1169
+ */
1170
+
1171
+ }, {
1172
+ key: "onData",
1173
+ value: function onData(data) {
1174
+ var _this3 = this;
1175
+
1176
+ var callback = function callback(packet) {
1177
+ // if its the first message we consider the transport open
1178
+ if ("opening" === _this3.readyState && packet.type === "open") {
1179
+ _this3.onOpen();
1180
+ } // if its a close packet, we close the ongoing requests
1181
+
1182
+
1183
+ if ("close" === packet.type) {
1184
+ _this3.onClose();
1185
+
1186
+ return false;
1187
+ } // otherwise bypass onData and handle the message
1188
+
1189
+
1190
+ _this3.onPacket(packet);
1191
+ }; // decode payload
1192
+
1193
+
1194
+ decodePayload(data, this.socket.binaryType).forEach(callback); // if an event did not trigger closing
1195
+
1196
+ if ("closed" !== this.readyState) {
1197
+ // if we got data we're not polling
1198
+ this.polling = false;
1199
+ this.emit("pollComplete");
1200
+
1201
+ if ("open" === this.readyState) {
1202
+ this.poll();
1203
+ }
1204
+ }
1205
+ }
1206
+ /**
1207
+ * For polling, send a close packet.
1208
+ *
1209
+ * @api private
1210
+ */
1211
+
1212
+ }, {
1213
+ key: "doClose",
1214
+ value: function doClose() {
1215
+ var _this4 = this;
1216
+
1217
+ var close = function close() {
1218
+ _this4.write([{
1219
+ type: "close"
1220
+ }]);
1221
+ };
1222
+
1223
+ if ("open" === this.readyState) {
1224
+ close();
1225
+ } else {
1226
+ // in case we're trying to close while
1227
+ // handshaking is in progress (GH-164)
1228
+ this.once("open", close);
1229
+ }
1230
+ }
1231
+ /**
1232
+ * Writes a packets payload.
1233
+ *
1234
+ * @param {Array} data packets
1235
+ * @param {Function} drain callback
1236
+ * @api private
1237
+ */
1238
+
1239
+ }, {
1240
+ key: "write",
1241
+ value: function write(packets) {
1242
+ var _this5 = this;
1243
+
1244
+ this.writable = false;
1245
+ encodePayload(packets, function (data) {
1246
+ _this5.doWrite(data, function () {
1247
+ _this5.writable = true;
1248
+
1249
+ _this5.emit("drain");
1250
+ });
1251
+ });
1252
+ }
1253
+ /**
1254
+ * Generates uri for connection.
1255
+ *
1256
+ * @api private
1257
+ */
1258
+
1259
+ }, {
1260
+ key: "uri",
1261
+ value: function uri() {
1262
+ var query = this.query || {};
1263
+ var schema = this.opts.secure ? "https" : "http";
1264
+ var port = ""; // cache busting is forced
1265
+
1266
+ if (false !== this.opts.timestampRequests) {
1267
+ query[this.opts.timestampParam] = yeast_1();
1268
+ }
1269
+
1270
+ if (!this.supportsBinary && !query.sid) {
1271
+ query.b64 = 1;
1272
+ } // avoid port if default for schema
1273
+
1274
+
1275
+ if (this.opts.port && ("https" === schema && Number(this.opts.port) !== 443 || "http" === schema && Number(this.opts.port) !== 80)) {
1276
+ port = ":" + this.opts.port;
1277
+ }
1278
+
1279
+ var encodedQuery = parseqs.encode(query);
1280
+ var ipv6 = this.opts.hostname.indexOf(":") !== -1;
1281
+ return schema + "://" + (ipv6 ? "[" + this.opts.hostname + "]" : this.opts.hostname) + port + this.opts.path + (encodedQuery.length ? "?" + encodedQuery : "");
1282
+ }
1283
+ }]);
1284
+
1285
+ return Polling;
1286
+ }(Transport);
1287
+
1288
+ /**
1289
+ * Empty function
1290
+ */
1291
+
1292
+ function empty() {}
1293
+
1294
+ var hasXHR2 = function () {
1295
+ var xhr = new XMLHttpRequest$1({
1296
+ xdomain: false
1297
+ });
1298
+ return null != xhr.responseType;
1299
+ }();
1300
+
1301
+ var XHR = /*#__PURE__*/function (_Polling) {
1302
+ _inherits(XHR, _Polling);
1303
+
1304
+ var _super = _createSuper(XHR);
1305
+
1306
+ /**
1307
+ * XHR Polling constructor.
1308
+ *
1309
+ * @param {Object} opts
1310
+ * @api public
1311
+ */
1312
+ function XHR(opts) {
1313
+ var _this;
1314
+
1315
+ _classCallCheck(this, XHR);
1316
+
1317
+ _this = _super.call(this, opts);
1318
+
1319
+ if (typeof location !== "undefined") {
1320
+ var isSSL = "https:" === location.protocol;
1321
+ var port = location.port; // some user agents have empty `location.port`
1322
+
1323
+ if (!port) {
1324
+ port = isSSL ? "443" : "80";
1325
+ }
1326
+
1327
+ _this.xd = typeof location !== "undefined" && opts.hostname !== location.hostname || port !== opts.port;
1328
+ _this.xs = opts.secure !== isSSL;
1329
+ }
1330
+ /**
1331
+ * XHR supports binary
1332
+ */
1333
+
1334
+
1335
+ var forceBase64 = opts && opts.forceBase64;
1336
+ _this.supportsBinary = hasXHR2 && !forceBase64;
1337
+ return _this;
1338
+ }
1339
+ /**
1340
+ * Creates a request.
1341
+ *
1342
+ * @param {String} method
1343
+ * @api private
1344
+ */
1345
+
1346
+
1347
+ _createClass(XHR, [{
1348
+ key: "request",
1349
+ value: function request() {
1350
+ var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1351
+
1352
+ _extends(opts, {
1353
+ xd: this.xd,
1354
+ xs: this.xs
1355
+ }, this.opts);
1356
+
1357
+ return new Request(this.uri(), opts);
1358
+ }
1359
+ /**
1360
+ * Sends data.
1361
+ *
1362
+ * @param {String} data to send.
1363
+ * @param {Function} called upon flush.
1364
+ * @api private
1365
+ */
1366
+
1367
+ }, {
1368
+ key: "doWrite",
1369
+ value: function doWrite(data, fn) {
1370
+ var _this2 = this;
1371
+
1372
+ var req = this.request({
1373
+ method: "POST",
1374
+ data: data
1375
+ });
1376
+ req.on("success", fn);
1377
+ req.on("error", function (err) {
1378
+ _this2.onError("xhr post error", err);
1379
+ });
1380
+ }
1381
+ /**
1382
+ * Starts a poll cycle.
1383
+ *
1384
+ * @api private
1385
+ */
1386
+
1387
+ }, {
1388
+ key: "doPoll",
1389
+ value: function doPoll() {
1390
+ var _this3 = this;
1391
+
1392
+ var req = this.request();
1393
+ req.on("data", this.onData.bind(this));
1394
+ req.on("error", function (err) {
1395
+ _this3.onError("xhr poll error", err);
1396
+ });
1397
+ this.pollXhr = req;
1398
+ }
1399
+ }]);
1400
+
1401
+ return XHR;
1402
+ }(Polling);
1403
+ var Request = /*#__PURE__*/function (_Emitter) {
1404
+ _inherits(Request, _Emitter);
1405
+
1406
+ var _super2 = _createSuper(Request);
1407
+
1408
+ /**
1409
+ * Request constructor
1410
+ *
1411
+ * @param {Object} options
1412
+ * @api public
1413
+ */
1414
+ function Request(uri, opts) {
1415
+ var _this4;
1416
+
1417
+ _classCallCheck(this, Request);
1418
+
1419
+ _this4 = _super2.call(this);
1420
+ installTimerFunctions(_assertThisInitialized(_this4), opts);
1421
+ _this4.opts = opts;
1422
+ _this4.method = opts.method || "GET";
1423
+ _this4.uri = uri;
1424
+ _this4.async = false !== opts.async;
1425
+ _this4.data = undefined !== opts.data ? opts.data : null;
1426
+
1427
+ _this4.create();
1428
+
1429
+ return _this4;
1430
+ }
1431
+ /**
1432
+ * Creates the XHR object and sends the request.
1433
+ *
1434
+ * @api private
1435
+ */
1436
+
1437
+
1438
+ _createClass(Request, [{
1439
+ key: "create",
1440
+ value: function create() {
1441
+ var _this5 = this;
1442
+
1443
+ var opts = pick(this.opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
1444
+ opts.xdomain = !!this.opts.xd;
1445
+ opts.xscheme = !!this.opts.xs;
1446
+ var xhr = this.xhr = new XMLHttpRequest$1(opts);
1447
+
1448
+ try {
1449
+ xhr.open(this.method, this.uri, this.async);
1450
+
1451
+ try {
1452
+ if (this.opts.extraHeaders) {
1453
+ xhr.setDisableHeaderCheck && xhr.setDisableHeaderCheck(true);
1454
+
1455
+ for (var i in this.opts.extraHeaders) {
1456
+ if (this.opts.extraHeaders.hasOwnProperty(i)) {
1457
+ xhr.setRequestHeader(i, this.opts.extraHeaders[i]);
1458
+ }
1459
+ }
1460
+ }
1461
+ } catch (e) {}
1462
+
1463
+ if ("POST" === this.method) {
1464
+ try {
1465
+ xhr.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
1466
+ } catch (e) {}
1467
+ }
1468
+
1469
+ try {
1470
+ xhr.setRequestHeader("Accept", "*/*");
1471
+ } catch (e) {} // ie6 check
1472
+
1473
+
1474
+ if ("withCredentials" in xhr) {
1475
+ xhr.withCredentials = this.opts.withCredentials;
1476
+ }
1477
+
1478
+ if (this.opts.requestTimeout) {
1479
+ xhr.timeout = this.opts.requestTimeout;
1480
+ }
1481
+
1482
+ xhr.onreadystatechange = function () {
1483
+ if (4 !== xhr.readyState) return;
1484
+
1485
+ if (200 === xhr.status || 1223 === xhr.status) {
1486
+ _this5.onLoad();
1487
+ } else {
1488
+ // make sure the `error` event handler that's user-set
1489
+ // does not throw in the same tick and gets caught here
1490
+ _this5.setTimeoutFn(function () {
1491
+ _this5.onError(typeof xhr.status === "number" ? xhr.status : 0);
1492
+ }, 0);
1493
+ }
1494
+ };
1495
+
1496
+ xhr.send(this.data);
1497
+ } catch (e) {
1498
+ // Need to defer since .create() is called directly from the constructor
1499
+ // and thus the 'error' event can only be only bound *after* this exception
1500
+ // occurs. Therefore, also, we cannot throw here at all.
1501
+ this.setTimeoutFn(function () {
1502
+ _this5.onError(e);
1503
+ }, 0);
1504
+ return;
1505
+ }
1506
+
1507
+ if (typeof document !== "undefined") {
1508
+ this.index = Request.requestsCount++;
1509
+ Request.requests[this.index] = this;
1510
+ }
1511
+ }
1512
+ /**
1513
+ * Called upon successful response.
1514
+ *
1515
+ * @api private
1516
+ */
1517
+
1518
+ }, {
1519
+ key: "onSuccess",
1520
+ value: function onSuccess() {
1521
+ this.emit("success");
1522
+ this.cleanup();
1523
+ }
1524
+ /**
1525
+ * Called if we have data.
1526
+ *
1527
+ * @api private
1528
+ */
1529
+
1530
+ }, {
1531
+ key: "onData",
1532
+ value: function onData(data) {
1533
+ this.emit("data", data);
1534
+ this.onSuccess();
1535
+ }
1536
+ /**
1537
+ * Called upon error.
1538
+ *
1539
+ * @api private
1540
+ */
1541
+
1542
+ }, {
1543
+ key: "onError",
1544
+ value: function onError(err) {
1545
+ this.emit("error", err);
1546
+ this.cleanup(true);
1547
+ }
1548
+ /**
1549
+ * Cleans up house.
1550
+ *
1551
+ * @api private
1552
+ */
1553
+
1554
+ }, {
1555
+ key: "cleanup",
1556
+ value: function cleanup(fromError) {
1557
+ if ("undefined" === typeof this.xhr || null === this.xhr) {
1558
+ return;
1559
+ }
1560
+
1561
+ this.xhr.onreadystatechange = empty;
1562
+
1563
+ if (fromError) {
1564
+ try {
1565
+ this.xhr.abort();
1566
+ } catch (e) {}
1567
+ }
1568
+
1569
+ if (typeof document !== "undefined") {
1570
+ delete Request.requests[this.index];
1571
+ }
1572
+
1573
+ this.xhr = null;
1574
+ }
1575
+ /**
1576
+ * Called upon load.
1577
+ *
1578
+ * @api private
1579
+ */
1580
+
1581
+ }, {
1582
+ key: "onLoad",
1583
+ value: function onLoad() {
1584
+ var data = this.xhr.responseText;
1585
+
1586
+ if (data !== null) {
1587
+ this.onData(data);
1588
+ }
1589
+ }
1590
+ /**
1591
+ * Aborts the request.
1592
+ *
1593
+ * @api public
1594
+ */
1595
+
1596
+ }, {
1597
+ key: "abort",
1598
+ value: function abort() {
1599
+ this.cleanup();
1600
+ }
1601
+ }]);
1602
+
1603
+ return Request;
1604
+ }(Emitter_1);
1605
+ Request.requestsCount = 0;
1606
+ Request.requests = {};
1607
+ /**
1608
+ * Aborts pending requests when unloading the window. This is needed to prevent
1609
+ * memory leaks (e.g. when using IE) and to ensure that no spurious error is
1610
+ * emitted.
1611
+ */
1612
+
1613
+ if (typeof document !== "undefined") {
1614
+ // @ts-ignore
1615
+ if (typeof attachEvent === "function") {
1616
+ // @ts-ignore
1617
+ attachEvent("onunload", unloadHandler);
1618
+ } else if (typeof addEventListener === "function") {
1619
+ var terminationEvent = "onpagehide" in globalThis ? "pagehide" : "unload";
1620
+ addEventListener(terminationEvent, unloadHandler, false);
1621
+ }
1622
+ }
1623
+
1624
+ function unloadHandler() {
1625
+ for (var i in Request.requests) {
1626
+ if (Request.requests.hasOwnProperty(i)) {
1627
+ Request.requests[i].abort();
1628
+ }
1629
+ }
1630
+ }
1631
+
1632
+ var nextTick = function () {
1633
+ var isPromiseAvailable = typeof Promise === "function" && typeof Promise.resolve === "function";
1634
+
1635
+ if (isPromiseAvailable) {
1636
+ return function (cb) {
1637
+ return Promise.resolve().then(cb);
1638
+ };
1639
+ } else {
1640
+ return function (cb, setTimeoutFn) {
1641
+ return setTimeoutFn(cb, 0);
1642
+ };
1643
+ }
1644
+ }();
1645
+ var WebSocket = globalThis.WebSocket || globalThis.MozWebSocket;
1646
+ var usingBrowserWebSocket = true;
1647
+ var defaultBinaryType = "arraybuffer";
1648
+
1649
+ var isReactNative = typeof navigator !== "undefined" && typeof navigator.product === "string" && navigator.product.toLowerCase() === "reactnative";
1650
+ var WS = /*#__PURE__*/function (_Transport) {
1651
+ _inherits(WS, _Transport);
1652
+
1653
+ var _super = _createSuper(WS);
1654
+
1655
+ /**
1656
+ * WebSocket transport constructor.
1657
+ *
1658
+ * @api {Object} connection options
1659
+ * @api public
1660
+ */
1661
+ function WS(opts) {
1662
+ var _this;
1663
+
1664
+ _classCallCheck(this, WS);
1665
+
1666
+ _this = _super.call(this, opts);
1667
+ _this.supportsBinary = !opts.forceBase64;
1668
+ return _this;
1669
+ }
1670
+ /**
1671
+ * Transport name.
1672
+ *
1673
+ * @api public
1674
+ */
1675
+
1676
+
1677
+ _createClass(WS, [{
1678
+ key: "name",
1679
+ get: function get() {
1680
+ return "websocket";
1681
+ }
1682
+ /**
1683
+ * Opens socket.
1684
+ *
1685
+ * @api private
1686
+ */
1687
+
1688
+ }, {
1689
+ key: "doOpen",
1690
+ value: function doOpen() {
1691
+ if (!this.check()) {
1692
+ // let probe timeout
1693
+ return;
1694
+ }
1695
+
1696
+ var uri = this.uri();
1697
+ var protocols = this.opts.protocols; // React Native only supports the 'headers' option, and will print a warning if anything else is passed
1698
+
1699
+ var opts = isReactNative ? {} : pick(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
1700
+
1701
+ if (this.opts.extraHeaders) {
1702
+ opts.headers = this.opts.extraHeaders;
1703
+ }
1704
+
1705
+ try {
1706
+ this.ws = usingBrowserWebSocket && !isReactNative ? protocols ? new WebSocket(uri, protocols) : new WebSocket(uri) : new WebSocket(uri, protocols, opts);
1707
+ } catch (err) {
1708
+ return this.emit("error", err);
1709
+ }
1710
+
1711
+ this.ws.binaryType = this.socket.binaryType || defaultBinaryType;
1712
+ this.addEventListeners();
1713
+ }
1714
+ /**
1715
+ * Adds event listeners to the socket
1716
+ *
1717
+ * @api private
1718
+ */
1719
+
1720
+ }, {
1721
+ key: "addEventListeners",
1722
+ value: function addEventListeners() {
1723
+ var _this2 = this;
1724
+
1725
+ this.ws.onopen = function () {
1726
+ if (_this2.opts.autoUnref) {
1727
+ _this2.ws._socket.unref();
1728
+ }
1729
+
1730
+ _this2.onOpen();
1731
+ };
1732
+
1733
+ this.ws.onclose = this.onClose.bind(this);
1734
+
1735
+ this.ws.onmessage = function (ev) {
1736
+ return _this2.onData(ev.data);
1737
+ };
1738
+
1739
+ this.ws.onerror = function (e) {
1740
+ return _this2.onError("websocket error", e);
1741
+ };
1742
+ }
1743
+ /**
1744
+ * Writes data to socket.
1745
+ *
1746
+ * @param {Array} array of packets.
1747
+ * @api private
1748
+ */
1749
+
1750
+ }, {
1751
+ key: "write",
1752
+ value: function write(packets) {
1753
+ var _this3 = this;
1754
+
1755
+ this.writable = false; // encodePacket efficient as it uses WS framing
1756
+ // no need for encodePayload
1757
+
1758
+ var _loop = function _loop(i) {
1759
+ var packet = packets[i];
1760
+ var lastPacket = i === packets.length - 1;
1761
+ encodePacket(packet, _this3.supportsBinary, function (data) {
1762
+ // always create a new object (GH-437)
1763
+ var opts = {};
1764
+ // have a chance of informing us about it yet, in that case send will
1765
+ // throw an error
1766
+
1767
+
1768
+ try {
1769
+ if (usingBrowserWebSocket) {
1770
+ // TypeError is thrown when passing the second argument on Safari
1771
+ _this3.ws.send(data);
1772
+ }
1773
+ } catch (e) {}
1774
+
1775
+ if (lastPacket) {
1776
+ // fake drain
1777
+ // defer to next tick to allow Socket to clear writeBuffer
1778
+ nextTick(function () {
1779
+ _this3.writable = true;
1780
+
1781
+ _this3.emit("drain");
1782
+ }, _this3.setTimeoutFn);
1783
+ }
1784
+ });
1785
+ };
1786
+
1787
+ for (var i = 0; i < packets.length; i++) {
1788
+ _loop(i);
1789
+ }
1790
+ }
1791
+ /**
1792
+ * Closes socket.
1793
+ *
1794
+ * @api private
1795
+ */
1796
+
1797
+ }, {
1798
+ key: "doClose",
1799
+ value: function doClose() {
1800
+ if (typeof this.ws !== "undefined") {
1801
+ this.ws.close();
1802
+ this.ws = null;
1803
+ }
1804
+ }
1805
+ /**
1806
+ * Generates uri for connection.
1807
+ *
1808
+ * @api private
1809
+ */
1810
+
1811
+ }, {
1812
+ key: "uri",
1813
+ value: function uri() {
1814
+ var query = this.query || {};
1815
+ var schema = this.opts.secure ? "wss" : "ws";
1816
+ var port = ""; // avoid port if default for schema
1817
+
1818
+ if (this.opts.port && ("wss" === schema && Number(this.opts.port) !== 443 || "ws" === schema && Number(this.opts.port) !== 80)) {
1819
+ port = ":" + this.opts.port;
1820
+ } // append timestamp to URI
1821
+
1822
+
1823
+ if (this.opts.timestampRequests) {
1824
+ query[this.opts.timestampParam] = yeast_1();
1825
+ } // communicate binary support capabilities
1826
+
1827
+
1828
+ if (!this.supportsBinary) {
1829
+ query.b64 = 1;
1830
+ }
1831
+
1832
+ var encodedQuery = parseqs.encode(query);
1833
+ var ipv6 = this.opts.hostname.indexOf(":") !== -1;
1834
+ return schema + "://" + (ipv6 ? "[" + this.opts.hostname + "]" : this.opts.hostname) + port + this.opts.path + (encodedQuery.length ? "?" + encodedQuery : "");
1835
+ }
1836
+ /**
1837
+ * Feature detection for WebSocket.
1838
+ *
1839
+ * @return {Boolean} whether this transport is available.
1840
+ * @api public
1841
+ */
1842
+
1843
+ }, {
1844
+ key: "check",
1845
+ value: function check() {
1846
+ return !!WebSocket && !("__initialize" in WebSocket && this.name === WS.prototype.name);
1847
+ }
1848
+ }]);
1849
+
1850
+ return WS;
1851
+ }(Transport);
1852
+
1853
+ var transports = {
1854
+ websocket: WS,
1855
+ polling: XHR
1856
+ };
1857
+
1858
+ var Socket$1 = /*#__PURE__*/function (_Emitter) {
1859
+ _inherits(Socket, _Emitter);
1860
+
1861
+ var _super = _createSuper(Socket);
1862
+
1863
+ /**
1864
+ * Socket constructor.
1865
+ *
1866
+ * @param {String|Object} uri or options
1867
+ * @param {Object} opts - options
1868
+ * @api public
1869
+ */
1870
+ function Socket(uri) {
1871
+ var _this;
1872
+
1873
+ var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1874
+
1875
+ _classCallCheck(this, Socket);
1876
+
1877
+ _this = _super.call(this);
1878
+
1879
+ if (uri && "object" === _typeof(uri)) {
1880
+ opts = uri;
1881
+ uri = null;
1882
+ }
1883
+
1884
+ if (uri) {
1885
+ uri = parseuri(uri);
1886
+ opts.hostname = uri.host;
1887
+ opts.secure = uri.protocol === "https" || uri.protocol === "wss";
1888
+ opts.port = uri.port;
1889
+ if (uri.query) opts.query = uri.query;
1890
+ } else if (opts.host) {
1891
+ opts.hostname = parseuri(opts.host).host;
1892
+ }
1893
+
1894
+ installTimerFunctions(_assertThisInitialized(_this), opts);
1895
+ _this.secure = null != opts.secure ? opts.secure : typeof location !== "undefined" && "https:" === location.protocol;
1896
+
1897
+ if (opts.hostname && !opts.port) {
1898
+ // if no port is specified manually, use the protocol default
1899
+ opts.port = _this.secure ? "443" : "80";
1900
+ }
1901
+
1902
+ _this.hostname = opts.hostname || (typeof location !== "undefined" ? location.hostname : "localhost");
1903
+ _this.port = opts.port || (typeof location !== "undefined" && location.port ? location.port : _this.secure ? "443" : "80");
1904
+ _this.transports = opts.transports || ["polling", "websocket"];
1905
+ _this.readyState = "";
1906
+ _this.writeBuffer = [];
1907
+ _this.prevBufferLen = 0;
1908
+ _this.opts = _extends({
1909
+ path: "/engine.io",
1910
+ agent: false,
1911
+ withCredentials: false,
1912
+ upgrade: true,
1913
+ timestampParam: "t",
1914
+ rememberUpgrade: false,
1915
+ rejectUnauthorized: true,
1916
+ perMessageDeflate: {
1917
+ threshold: 1024
1918
+ },
1919
+ transportOptions: {},
1920
+ closeOnBeforeunload: true
1921
+ }, opts);
1922
+ _this.opts.path = _this.opts.path.replace(/\/$/, "") + "/";
1923
+
1924
+ if (typeof _this.opts.query === "string") {
1925
+ _this.opts.query = parseqs.decode(_this.opts.query);
1926
+ } // set on handshake
1927
+
1928
+
1929
+ _this.id = null;
1930
+ _this.upgrades = null;
1931
+ _this.pingInterval = null;
1932
+ _this.pingTimeout = null; // set on heartbeat
1933
+
1934
+ _this.pingTimeoutTimer = null;
1935
+
1936
+ if (typeof addEventListener === "function") {
1937
+ if (_this.opts.closeOnBeforeunload) {
1938
+ // Firefox closes the connection when the "beforeunload" event is emitted but not Chrome. This event listener
1939
+ // ensures every browser behaves the same (no "disconnect" event at the Socket.IO level when the page is
1940
+ // closed/reloaded)
1941
+ addEventListener("beforeunload", function () {
1942
+ if (_this.transport) {
1943
+ // silently close the transport
1944
+ _this.transport.removeAllListeners();
1945
+
1946
+ _this.transport.close();
1947
+ }
1948
+ }, false);
1949
+ }
1950
+
1951
+ if (_this.hostname !== "localhost") {
1952
+ _this.offlineEventListener = function () {
1953
+ _this.onClose("transport close");
1954
+ };
1955
+
1956
+ addEventListener("offline", _this.offlineEventListener, false);
1957
+ }
1958
+ }
1959
+
1960
+ _this.open();
1961
+
1962
+ return _this;
1963
+ }
1964
+ /**
1965
+ * Creates transport of the given type.
1966
+ *
1967
+ * @param {String} transport name
1968
+ * @return {Transport}
1969
+ * @api private
1970
+ */
1971
+
1972
+
1973
+ _createClass(Socket, [{
1974
+ key: "createTransport",
1975
+ value: function createTransport(name) {
1976
+ var query = clone(this.opts.query); // append engine.io protocol identifier
1977
+
1978
+ query.EIO = protocol$1; // transport name
1979
+
1980
+ query.transport = name; // session id if we already have one
1981
+
1982
+ if (this.id) query.sid = this.id;
1983
+
1984
+ var opts = _extends({}, this.opts.transportOptions[name], this.opts, {
1985
+ query: query,
1986
+ socket: this,
1987
+ hostname: this.hostname,
1988
+ secure: this.secure,
1989
+ port: this.port
1990
+ });
1991
+
1992
+ return new transports[name](opts);
1993
+ }
1994
+ /**
1995
+ * Initializes transport to use and starts probe.
1996
+ *
1997
+ * @api private
1998
+ */
1999
+
2000
+ }, {
2001
+ key: "open",
2002
+ value: function open() {
2003
+ var _this2 = this;
2004
+
2005
+ var transport;
2006
+
2007
+ if (this.opts.rememberUpgrade && Socket.priorWebsocketSuccess && this.transports.indexOf("websocket") !== -1) {
2008
+ transport = "websocket";
2009
+ } else if (0 === this.transports.length) {
2010
+ // Emit error on next tick so it can be listened to
2011
+ this.setTimeoutFn(function () {
2012
+ _this2.emitReserved("error", "No transports available");
2013
+ }, 0);
2014
+ return;
2015
+ } else {
2016
+ transport = this.transports[0];
2017
+ }
2018
+
2019
+ this.readyState = "opening"; // Retry with the next transport if the transport is disabled (jsonp: false)
2020
+
2021
+ try {
2022
+ transport = this.createTransport(transport);
2023
+ } catch (e) {
2024
+ this.transports.shift();
2025
+ this.open();
2026
+ return;
2027
+ }
2028
+
2029
+ transport.open();
2030
+ this.setTransport(transport);
2031
+ }
2032
+ /**
2033
+ * Sets the current transport. Disables the existing one (if any).
2034
+ *
2035
+ * @api private
2036
+ */
2037
+
2038
+ }, {
2039
+ key: "setTransport",
2040
+ value: function setTransport(transport) {
2041
+ var _this3 = this;
2042
+
2043
+ if (this.transport) {
2044
+ this.transport.removeAllListeners();
2045
+ } // set up transport
2046
+
2047
+
2048
+ this.transport = transport; // set up transport listeners
2049
+
2050
+ transport.on("drain", this.onDrain.bind(this)).on("packet", this.onPacket.bind(this)).on("error", this.onError.bind(this)).on("close", function () {
2051
+ _this3.onClose("transport close");
2052
+ });
2053
+ }
2054
+ /**
2055
+ * Probes a transport.
2056
+ *
2057
+ * @param {String} transport name
2058
+ * @api private
2059
+ */
2060
+
2061
+ }, {
2062
+ key: "probe",
2063
+ value: function probe(name) {
2064
+ var _this4 = this;
2065
+
2066
+ var transport = this.createTransport(name);
2067
+ var failed = false;
2068
+ Socket.priorWebsocketSuccess = false;
2069
+
2070
+ var onTransportOpen = function onTransportOpen() {
2071
+ if (failed) return;
2072
+ transport.send([{
2073
+ type: "ping",
2074
+ data: "probe"
2075
+ }]);
2076
+ transport.once("packet", function (msg) {
2077
+ if (failed) return;
2078
+
2079
+ if ("pong" === msg.type && "probe" === msg.data) {
2080
+ _this4.upgrading = true;
2081
+
2082
+ _this4.emitReserved("upgrading", transport);
2083
+
2084
+ if (!transport) return;
2085
+ Socket.priorWebsocketSuccess = "websocket" === transport.name;
2086
+
2087
+ _this4.transport.pause(function () {
2088
+ if (failed) return;
2089
+ if ("closed" === _this4.readyState) return;
2090
+ cleanup();
2091
+
2092
+ _this4.setTransport(transport);
2093
+
2094
+ transport.send([{
2095
+ type: "upgrade"
2096
+ }]);
2097
+
2098
+ _this4.emitReserved("upgrade", transport);
2099
+
2100
+ transport = null;
2101
+ _this4.upgrading = false;
2102
+
2103
+ _this4.flush();
2104
+ });
2105
+ } else {
2106
+ var err = new Error("probe error"); // @ts-ignore
2107
+
2108
+ err.transport = transport.name;
2109
+
2110
+ _this4.emitReserved("upgradeError", err);
2111
+ }
2112
+ });
2113
+ };
2114
+
2115
+ function freezeTransport() {
2116
+ if (failed) return; // Any callback called by transport should be ignored since now
2117
+
2118
+ failed = true;
2119
+ cleanup();
2120
+ transport.close();
2121
+ transport = null;
2122
+ } // Handle any error that happens while probing
2123
+
2124
+
2125
+ var onerror = function onerror(err) {
2126
+ var error = new Error("probe error: " + err); // @ts-ignore
2127
+
2128
+ error.transport = transport.name;
2129
+ freezeTransport();
2130
+
2131
+ _this4.emitReserved("upgradeError", error);
2132
+ };
2133
+
2134
+ function onTransportClose() {
2135
+ onerror("transport closed");
2136
+ } // When the socket is closed while we're probing
2137
+
2138
+
2139
+ function onclose() {
2140
+ onerror("socket closed");
2141
+ } // When the socket is upgraded while we're probing
2142
+
2143
+
2144
+ function onupgrade(to) {
2145
+ if (transport && to.name !== transport.name) {
2146
+ freezeTransport();
2147
+ }
2148
+ } // Remove all listeners on the transport and on self
2149
+
2150
+
2151
+ var cleanup = function cleanup() {
2152
+ transport.removeListener("open", onTransportOpen);
2153
+ transport.removeListener("error", onerror);
2154
+ transport.removeListener("close", onTransportClose);
2155
+
2156
+ _this4.off("close", onclose);
2157
+
2158
+ _this4.off("upgrading", onupgrade);
2159
+ };
2160
+
2161
+ transport.once("open", onTransportOpen);
2162
+ transport.once("error", onerror);
2163
+ transport.once("close", onTransportClose);
2164
+ this.once("close", onclose);
2165
+ this.once("upgrading", onupgrade);
2166
+ transport.open();
2167
+ }
2168
+ /**
2169
+ * Called when connection is deemed open.
2170
+ *
2171
+ * @api private
2172
+ */
2173
+
2174
+ }, {
2175
+ key: "onOpen",
2176
+ value: function onOpen() {
2177
+ this.readyState = "open";
2178
+ Socket.priorWebsocketSuccess = "websocket" === this.transport.name;
2179
+ this.emitReserved("open");
2180
+ this.flush(); // we check for `readyState` in case an `open`
2181
+ // listener already closed the socket
2182
+
2183
+ if ("open" === this.readyState && this.opts.upgrade && this.transport.pause) {
2184
+ var i = 0;
2185
+ var l = this.upgrades.length;
2186
+
2187
+ for (; i < l; i++) {
2188
+ this.probe(this.upgrades[i]);
2189
+ }
2190
+ }
2191
+ }
2192
+ /**
2193
+ * Handles a packet.
2194
+ *
2195
+ * @api private
2196
+ */
2197
+
2198
+ }, {
2199
+ key: "onPacket",
2200
+ value: function onPacket(packet) {
2201
+ if ("opening" === this.readyState || "open" === this.readyState || "closing" === this.readyState) {
2202
+ this.emitReserved("packet", packet); // Socket is live - any packet counts
2203
+
2204
+ this.emitReserved("heartbeat");
2205
+
2206
+ switch (packet.type) {
2207
+ case "open":
2208
+ this.onHandshake(JSON.parse(packet.data));
2209
+ break;
2210
+
2211
+ case "ping":
2212
+ this.resetPingTimeout();
2213
+ this.sendPacket("pong");
2214
+ this.emitReserved("ping");
2215
+ this.emitReserved("pong");
2216
+ break;
2217
+
2218
+ case "error":
2219
+ var err = new Error("server error"); // @ts-ignore
2220
+
2221
+ err.code = packet.data;
2222
+ this.onError(err);
2223
+ break;
2224
+
2225
+ case "message":
2226
+ this.emitReserved("data", packet.data);
2227
+ this.emitReserved("message", packet.data);
2228
+ break;
2229
+ }
2230
+ }
2231
+ }
2232
+ /**
2233
+ * Called upon handshake completion.
2234
+ *
2235
+ * @param {Object} data - handshake obj
2236
+ * @api private
2237
+ */
2238
+
2239
+ }, {
2240
+ key: "onHandshake",
2241
+ value: function onHandshake(data) {
2242
+ this.emitReserved("handshake", data);
2243
+ this.id = data.sid;
2244
+ this.transport.query.sid = data.sid;
2245
+ this.upgrades = this.filterUpgrades(data.upgrades);
2246
+ this.pingInterval = data.pingInterval;
2247
+ this.pingTimeout = data.pingTimeout;
2248
+ this.onOpen(); // In case open handler closes socket
2249
+
2250
+ if ("closed" === this.readyState) return;
2251
+ this.resetPingTimeout();
2252
+ }
2253
+ /**
2254
+ * Sets and resets ping timeout timer based on server pings.
2255
+ *
2256
+ * @api private
2257
+ */
2258
+
2259
+ }, {
2260
+ key: "resetPingTimeout",
2261
+ value: function resetPingTimeout() {
2262
+ var _this5 = this;
2263
+
2264
+ this.clearTimeoutFn(this.pingTimeoutTimer);
2265
+ this.pingTimeoutTimer = this.setTimeoutFn(function () {
2266
+ _this5.onClose("ping timeout");
2267
+ }, this.pingInterval + this.pingTimeout);
2268
+
2269
+ if (this.opts.autoUnref) {
2270
+ this.pingTimeoutTimer.unref();
2271
+ }
2272
+ }
2273
+ /**
2274
+ * Called on `drain` event
2275
+ *
2276
+ * @api private
2277
+ */
2278
+
2279
+ }, {
2280
+ key: "onDrain",
2281
+ value: function onDrain() {
2282
+ this.writeBuffer.splice(0, this.prevBufferLen); // setting prevBufferLen = 0 is very important
2283
+ // for example, when upgrading, upgrade packet is sent over,
2284
+ // and a nonzero prevBufferLen could cause problems on `drain`
2285
+
2286
+ this.prevBufferLen = 0;
2287
+
2288
+ if (0 === this.writeBuffer.length) {
2289
+ this.emitReserved("drain");
2290
+ } else {
2291
+ this.flush();
2292
+ }
2293
+ }
2294
+ /**
2295
+ * Flush write buffers.
2296
+ *
2297
+ * @api private
2298
+ */
2299
+
2300
+ }, {
2301
+ key: "flush",
2302
+ value: function flush() {
2303
+ if ("closed" !== this.readyState && this.transport.writable && !this.upgrading && this.writeBuffer.length) {
2304
+ this.transport.send(this.writeBuffer); // keep track of current length of writeBuffer
2305
+ // splice writeBuffer and callbackBuffer on `drain`
2306
+
2307
+ this.prevBufferLen = this.writeBuffer.length;
2308
+ this.emitReserved("flush");
2309
+ }
2310
+ }
2311
+ /**
2312
+ * Sends a message.
2313
+ *
2314
+ * @param {String} message.
2315
+ * @param {Function} callback function.
2316
+ * @param {Object} options.
2317
+ * @return {Socket} for chaining.
2318
+ * @api public
2319
+ */
2320
+
2321
+ }, {
2322
+ key: "write",
2323
+ value: function write(msg, options, fn) {
2324
+ this.sendPacket("message", msg, options, fn);
2325
+ return this;
2326
+ }
2327
+ }, {
2328
+ key: "send",
2329
+ value: function send(msg, options, fn) {
2330
+ this.sendPacket("message", msg, options, fn);
2331
+ return this;
2332
+ }
2333
+ /**
2334
+ * Sends a packet.
2335
+ *
2336
+ * @param {String} packet type.
2337
+ * @param {String} data.
2338
+ * @param {Object} options.
2339
+ * @param {Function} callback function.
2340
+ * @api private
2341
+ */
2342
+
2343
+ }, {
2344
+ key: "sendPacket",
2345
+ value: function sendPacket(type, data, options, fn) {
2346
+ if ("function" === typeof data) {
2347
+ fn = data;
2348
+ data = undefined;
2349
+ }
2350
+
2351
+ if ("function" === typeof options) {
2352
+ fn = options;
2353
+ options = null;
2354
+ }
2355
+
2356
+ if ("closing" === this.readyState || "closed" === this.readyState) {
2357
+ return;
2358
+ }
2359
+
2360
+ options = options || {};
2361
+ options.compress = false !== options.compress;
2362
+ var packet = {
2363
+ type: type,
2364
+ data: data,
2365
+ options: options
2366
+ };
2367
+ this.emitReserved("packetCreate", packet);
2368
+ this.writeBuffer.push(packet);
2369
+ if (fn) this.once("flush", fn);
2370
+ this.flush();
2371
+ }
2372
+ /**
2373
+ * Closes the connection.
2374
+ *
2375
+ * @api public
2376
+ */
2377
+
2378
+ }, {
2379
+ key: "close",
2380
+ value: function close() {
2381
+ var _this6 = this;
2382
+
2383
+ var close = function close() {
2384
+ _this6.onClose("forced close");
2385
+
2386
+ _this6.transport.close();
2387
+ };
2388
+
2389
+ var cleanupAndClose = function cleanupAndClose() {
2390
+ _this6.off("upgrade", cleanupAndClose);
2391
+
2392
+ _this6.off("upgradeError", cleanupAndClose);
2393
+
2394
+ close();
2395
+ };
2396
+
2397
+ var waitForUpgrade = function waitForUpgrade() {
2398
+ // wait for upgrade to finish since we can't send packets while pausing a transport
2399
+ _this6.once("upgrade", cleanupAndClose);
2400
+
2401
+ _this6.once("upgradeError", cleanupAndClose);
2402
+ };
2403
+
2404
+ if ("opening" === this.readyState || "open" === this.readyState) {
2405
+ this.readyState = "closing";
2406
+
2407
+ if (this.writeBuffer.length) {
2408
+ this.once("drain", function () {
2409
+ if (_this6.upgrading) {
2410
+ waitForUpgrade();
2411
+ } else {
2412
+ close();
2413
+ }
2414
+ });
2415
+ } else if (this.upgrading) {
2416
+ waitForUpgrade();
2417
+ } else {
2418
+ close();
2419
+ }
2420
+ }
2421
+
2422
+ return this;
2423
+ }
2424
+ /**
2425
+ * Called upon transport error
2426
+ *
2427
+ * @api private
2428
+ */
2429
+
2430
+ }, {
2431
+ key: "onError",
2432
+ value: function onError(err) {
2433
+ Socket.priorWebsocketSuccess = false;
2434
+ this.emitReserved("error", err);
2435
+ this.onClose("transport error", err);
2436
+ }
2437
+ /**
2438
+ * Called upon transport close.
2439
+ *
2440
+ * @api private
2441
+ */
2442
+
2443
+ }, {
2444
+ key: "onClose",
2445
+ value: function onClose(reason, desc) {
2446
+ if ("opening" === this.readyState || "open" === this.readyState || "closing" === this.readyState) {
2447
+ // clear timers
2448
+ this.clearTimeoutFn(this.pingTimeoutTimer); // stop event from firing again for transport
2449
+
2450
+ this.transport.removeAllListeners("close"); // ensure transport won't stay open
2451
+
2452
+ this.transport.close(); // ignore further transport communication
2453
+
2454
+ this.transport.removeAllListeners();
2455
+
2456
+ if (typeof removeEventListener === "function") {
2457
+ removeEventListener("offline", this.offlineEventListener, false);
2458
+ } // set ready state
2459
+
2460
+
2461
+ this.readyState = "closed"; // clear session id
2462
+
2463
+ this.id = null; // emit close event
2464
+
2465
+ this.emitReserved("close", reason, desc); // clean buffers after, so users can still
2466
+ // grab the buffers on `close` event
2467
+
2468
+ this.writeBuffer = [];
2469
+ this.prevBufferLen = 0;
2470
+ }
2471
+ }
2472
+ /**
2473
+ * Filters upgrades, returning only those matching client transports.
2474
+ *
2475
+ * @param {Array} server upgrades
2476
+ * @api private
2477
+ *
2478
+ */
2479
+
2480
+ }, {
2481
+ key: "filterUpgrades",
2482
+ value: function filterUpgrades(upgrades) {
2483
+ var filteredUpgrades = [];
2484
+ var i = 0;
2485
+ var j = upgrades.length;
2486
+
2487
+ for (; i < j; i++) {
2488
+ if (~this.transports.indexOf(upgrades[i])) filteredUpgrades.push(upgrades[i]);
2489
+ }
2490
+
2491
+ return filteredUpgrades;
2492
+ }
2493
+ }]);
2494
+
2495
+ return Socket;
2496
+ }(Emitter_1);
2497
+ Socket$1.protocol = protocol$1;
2498
+
2499
+ function clone(obj) {
2500
+ var o = {};
2501
+
2502
+ for (var i in obj) {
2503
+ if (obj.hasOwnProperty(i)) {
2504
+ o[i] = obj[i];
2505
+ }
2506
+ }
2507
+
2508
+ return o;
2509
+ }
2510
+
2511
+ var withNativeArrayBuffer = typeof ArrayBuffer === "function";
2512
+
2513
+ var isView = function isView(obj) {
2514
+ return typeof ArrayBuffer.isView === "function" ? ArrayBuffer.isView(obj) : obj.buffer instanceof ArrayBuffer;
2515
+ };
2516
+
2517
+ var toString = Object.prototype.toString;
2518
+ var withNativeBlob = typeof Blob === "function" || typeof Blob !== "undefined" && toString.call(Blob) === "[object BlobConstructor]";
2519
+ var withNativeFile = typeof File === "function" || typeof File !== "undefined" && toString.call(File) === "[object FileConstructor]";
2520
+ /**
2521
+ * Returns true if obj is a Buffer, an ArrayBuffer, a Blob or a File.
2522
+ *
2523
+ * @private
2524
+ */
2525
+
2526
+ function isBinary(obj) {
2527
+ return withNativeArrayBuffer && (obj instanceof ArrayBuffer || isView(obj)) || withNativeBlob && obj instanceof Blob || withNativeFile && obj instanceof File;
2528
+ }
2529
+ function hasBinary(obj, toJSON) {
2530
+ if (!obj || _typeof(obj) !== "object") {
2531
+ return false;
2532
+ }
2533
+
2534
+ if (Array.isArray(obj)) {
2535
+ for (var i = 0, l = obj.length; i < l; i++) {
2536
+ if (hasBinary(obj[i])) {
2537
+ return true;
2538
+ }
2539
+ }
2540
+
2541
+ return false;
2542
+ }
2543
+
2544
+ if (isBinary(obj)) {
2545
+ return true;
2546
+ }
2547
+
2548
+ if (obj.toJSON && typeof obj.toJSON === "function" && arguments.length === 1) {
2549
+ return hasBinary(obj.toJSON(), true);
2550
+ }
2551
+
2552
+ for (var key in obj) {
2553
+ if (Object.prototype.hasOwnProperty.call(obj, key) && hasBinary(obj[key])) {
2554
+ return true;
2555
+ }
2556
+ }
2557
+
2558
+ return false;
2559
+ }
2560
+
2561
+ /**
2562
+ * Replaces every Buffer | ArrayBuffer | Blob | File in packet with a numbered placeholder.
2563
+ *
2564
+ * @param {Object} packet - socket.io event packet
2565
+ * @return {Object} with deconstructed packet and list of buffers
2566
+ * @public
2567
+ */
2568
+
2569
+ function deconstructPacket(packet) {
2570
+ var buffers = [];
2571
+ var packetData = packet.data;
2572
+ var pack = packet;
2573
+ pack.data = _deconstructPacket(packetData, buffers);
2574
+ pack.attachments = buffers.length; // number of binary 'attachments'
2575
+
2576
+ return {
2577
+ packet: pack,
2578
+ buffers: buffers
2579
+ };
2580
+ }
2581
+
2582
+ function _deconstructPacket(data, buffers) {
2583
+ if (!data) return data;
2584
+
2585
+ if (isBinary(data)) {
2586
+ var placeholder = {
2587
+ _placeholder: true,
2588
+ num: buffers.length
2589
+ };
2590
+ buffers.push(data);
2591
+ return placeholder;
2592
+ } else if (Array.isArray(data)) {
2593
+ var newData = new Array(data.length);
2594
+
2595
+ for (var i = 0; i < data.length; i++) {
2596
+ newData[i] = _deconstructPacket(data[i], buffers);
2597
+ }
2598
+
2599
+ return newData;
2600
+ } else if (_typeof(data) === "object" && !(data instanceof Date)) {
2601
+ var _newData = {};
2602
+
2603
+ for (var key in data) {
2604
+ if (data.hasOwnProperty(key)) {
2605
+ _newData[key] = _deconstructPacket(data[key], buffers);
2606
+ }
2607
+ }
2608
+
2609
+ return _newData;
2610
+ }
2611
+
2612
+ return data;
2613
+ }
2614
+ /**
2615
+ * Reconstructs a binary packet from its placeholder packet and buffers
2616
+ *
2617
+ * @param {Object} packet - event packet with placeholders
2618
+ * @param {Array} buffers - binary buffers to put in placeholder positions
2619
+ * @return {Object} reconstructed packet
2620
+ * @public
2621
+ */
2622
+
2623
+
2624
+ function reconstructPacket(packet, buffers) {
2625
+ packet.data = _reconstructPacket(packet.data, buffers);
2626
+ packet.attachments = undefined; // no longer useful
2627
+
2628
+ return packet;
2629
+ }
2630
+
2631
+ function _reconstructPacket(data, buffers) {
2632
+ if (!data) return data;
2633
+
2634
+ if (data && data._placeholder) {
2635
+ return buffers[data.num]; // appropriate buffer (should be natural order anyway)
2636
+ } else if (Array.isArray(data)) {
2637
+ for (var i = 0; i < data.length; i++) {
2638
+ data[i] = _reconstructPacket(data[i], buffers);
2639
+ }
2640
+ } else if (_typeof(data) === "object") {
2641
+ for (var key in data) {
2642
+ if (data.hasOwnProperty(key)) {
2643
+ data[key] = _reconstructPacket(data[key], buffers);
2644
+ }
2645
+ }
2646
+ }
2647
+
2648
+ return data;
2649
+ }
2650
+
2651
+ /**
2652
+ * Protocol version.
2653
+ *
2654
+ * @public
2655
+ */
2656
+
2657
+ var protocol = 5;
2658
+ var PacketType;
2659
+
2660
+ (function (PacketType) {
2661
+ PacketType[PacketType["CONNECT"] = 0] = "CONNECT";
2662
+ PacketType[PacketType["DISCONNECT"] = 1] = "DISCONNECT";
2663
+ PacketType[PacketType["EVENT"] = 2] = "EVENT";
2664
+ PacketType[PacketType["ACK"] = 3] = "ACK";
2665
+ PacketType[PacketType["CONNECT_ERROR"] = 4] = "CONNECT_ERROR";
2666
+ PacketType[PacketType["BINARY_EVENT"] = 5] = "BINARY_EVENT";
2667
+ PacketType[PacketType["BINARY_ACK"] = 6] = "BINARY_ACK";
2668
+ })(PacketType || (PacketType = {}));
2669
+ /**
2670
+ * A socket.io Encoder instance
2671
+ */
2672
+
2673
+
2674
+ var Encoder = /*#__PURE__*/function () {
2675
+ function Encoder() {
2676
+ _classCallCheck(this, Encoder);
2677
+ }
2678
+
2679
+ _createClass(Encoder, [{
2680
+ key: "encode",
2681
+ value:
2682
+ /**
2683
+ * Encode a packet as a single string if non-binary, or as a
2684
+ * buffer sequence, depending on packet type.
2685
+ *
2686
+ * @param {Object} obj - packet object
2687
+ */
2688
+ function encode(obj) {
2689
+ if (obj.type === PacketType.EVENT || obj.type === PacketType.ACK) {
2690
+ if (hasBinary(obj)) {
2691
+ obj.type = obj.type === PacketType.EVENT ? PacketType.BINARY_EVENT : PacketType.BINARY_ACK;
2692
+ return this.encodeAsBinary(obj);
2693
+ }
2694
+ }
2695
+
2696
+ return [this.encodeAsString(obj)];
2697
+ }
2698
+ /**
2699
+ * Encode packet as string.
2700
+ */
2701
+
2702
+ }, {
2703
+ key: "encodeAsString",
2704
+ value: function encodeAsString(obj) {
2705
+ // first is type
2706
+ var str = "" + obj.type; // attachments if we have them
2707
+
2708
+ if (obj.type === PacketType.BINARY_EVENT || obj.type === PacketType.BINARY_ACK) {
2709
+ str += obj.attachments + "-";
2710
+ } // if we have a namespace other than `/`
2711
+ // we append it followed by a comma `,`
2712
+
2713
+
2714
+ if (obj.nsp && "/" !== obj.nsp) {
2715
+ str += obj.nsp + ",";
2716
+ } // immediately followed by the id
2717
+
2718
+
2719
+ if (null != obj.id) {
2720
+ str += obj.id;
2721
+ } // json data
2722
+
2723
+
2724
+ if (null != obj.data) {
2725
+ str += JSON.stringify(obj.data);
2726
+ }
2727
+
2728
+ return str;
2729
+ }
2730
+ /**
2731
+ * Encode packet as 'buffer sequence' by removing blobs, and
2732
+ * deconstructing packet into object with placeholders and
2733
+ * a list of buffers.
2734
+ */
2735
+
2736
+ }, {
2737
+ key: "encodeAsBinary",
2738
+ value: function encodeAsBinary(obj) {
2739
+ var deconstruction = deconstructPacket(obj);
2740
+ var pack = this.encodeAsString(deconstruction.packet);
2741
+ var buffers = deconstruction.buffers;
2742
+ buffers.unshift(pack); // add packet info to beginning of data list
2743
+
2744
+ return buffers; // write all the buffers
2745
+ }
2746
+ }]);
2747
+
2748
+ return Encoder;
2749
+ }();
2750
+ /**
2751
+ * A socket.io Decoder instance
2752
+ *
2753
+ * @return {Object} decoder
2754
+ */
2755
+
2756
+ var Decoder = /*#__PURE__*/function (_Emitter) {
2757
+ _inherits(Decoder, _Emitter);
2758
+
2759
+ var _super = _createSuper(Decoder);
2760
+
2761
+ function Decoder() {
2762
+ _classCallCheck(this, Decoder);
2763
+
2764
+ return _super.call(this);
2765
+ }
2766
+ /**
2767
+ * Decodes an encoded packet string into packet JSON.
2768
+ *
2769
+ * @param {String} obj - encoded packet
2770
+ */
2771
+
2772
+
2773
+ _createClass(Decoder, [{
2774
+ key: "add",
2775
+ value: function add(obj) {
2776
+ var packet;
2777
+
2778
+ if (typeof obj === "string") {
2779
+ packet = this.decodeString(obj);
2780
+
2781
+ if (packet.type === PacketType.BINARY_EVENT || packet.type === PacketType.BINARY_ACK) {
2782
+ // binary packet's json
2783
+ this.reconstructor = new BinaryReconstructor(packet); // no attachments, labeled binary but no binary data to follow
2784
+
2785
+ if (packet.attachments === 0) {
2786
+ _get(_getPrototypeOf(Decoder.prototype), "emitReserved", this).call(this, "decoded", packet);
2787
+ }
2788
+ } else {
2789
+ // non-binary full packet
2790
+ _get(_getPrototypeOf(Decoder.prototype), "emitReserved", this).call(this, "decoded", packet);
2791
+ }
2792
+ } else if (isBinary(obj) || obj.base64) {
2793
+ // raw binary data
2794
+ if (!this.reconstructor) {
2795
+ throw new Error("got binary data when not reconstructing a packet");
2796
+ } else {
2797
+ packet = this.reconstructor.takeBinaryData(obj);
2798
+
2799
+ if (packet) {
2800
+ // received final buffer
2801
+ this.reconstructor = null;
2802
+
2803
+ _get(_getPrototypeOf(Decoder.prototype), "emitReserved", this).call(this, "decoded", packet);
2804
+ }
2805
+ }
2806
+ } else {
2807
+ throw new Error("Unknown type: " + obj);
2808
+ }
2809
+ }
2810
+ /**
2811
+ * Decode a packet String (JSON data)
2812
+ *
2813
+ * @param {String} str
2814
+ * @return {Object} packet
2815
+ */
2816
+
2817
+ }, {
2818
+ key: "decodeString",
2819
+ value: function decodeString(str) {
2820
+ var i = 0; // look up type
2821
+
2822
+ var p = {
2823
+ type: Number(str.charAt(0))
2824
+ };
2825
+
2826
+ if (PacketType[p.type] === undefined) {
2827
+ throw new Error("unknown packet type " + p.type);
2828
+ } // look up attachments if type binary
2829
+
2830
+
2831
+ if (p.type === PacketType.BINARY_EVENT || p.type === PacketType.BINARY_ACK) {
2832
+ var start = i + 1;
2833
+
2834
+ while (str.charAt(++i) !== "-" && i != str.length) {}
2835
+
2836
+ var buf = str.substring(start, i);
2837
+
2838
+ if (buf != Number(buf) || str.charAt(i) !== "-") {
2839
+ throw new Error("Illegal attachments");
2840
+ }
2841
+
2842
+ p.attachments = Number(buf);
2843
+ } // look up namespace (if any)
2844
+
2845
+
2846
+ if ("/" === str.charAt(i + 1)) {
2847
+ var _start = i + 1;
2848
+
2849
+ while (++i) {
2850
+ var c = str.charAt(i);
2851
+ if ("," === c) break;
2852
+ if (i === str.length) break;
2853
+ }
2854
+
2855
+ p.nsp = str.substring(_start, i);
2856
+ } else {
2857
+ p.nsp = "/";
2858
+ } // look up id
2859
+
2860
+
2861
+ var next = str.charAt(i + 1);
2862
+
2863
+ if ("" !== next && Number(next) == next) {
2864
+ var _start2 = i + 1;
2865
+
2866
+ while (++i) {
2867
+ var _c = str.charAt(i);
2868
+
2869
+ if (null == _c || Number(_c) != _c) {
2870
+ --i;
2871
+ break;
2872
+ }
2873
+
2874
+ if (i === str.length) break;
2875
+ }
2876
+
2877
+ p.id = Number(str.substring(_start2, i + 1));
2878
+ } // look up json data
2879
+
2880
+
2881
+ if (str.charAt(++i)) {
2882
+ var payload = tryParse(str.substr(i));
2883
+
2884
+ if (Decoder.isPayloadValid(p.type, payload)) {
2885
+ p.data = payload;
2886
+ } else {
2887
+ throw new Error("invalid payload");
2888
+ }
2889
+ }
2890
+
2891
+ return p;
2892
+ }
2893
+ }, {
2894
+ key: "destroy",
2895
+ value:
2896
+ /**
2897
+ * Deallocates a parser's resources
2898
+ */
2899
+ function destroy() {
2900
+ if (this.reconstructor) {
2901
+ this.reconstructor.finishedReconstruction();
2902
+ }
2903
+ }
2904
+ }], [{
2905
+ key: "isPayloadValid",
2906
+ value: function isPayloadValid(type, payload) {
2907
+ switch (type) {
2908
+ case PacketType.CONNECT:
2909
+ return _typeof(payload) === "object";
2910
+
2911
+ case PacketType.DISCONNECT:
2912
+ return payload === undefined;
2913
+
2914
+ case PacketType.CONNECT_ERROR:
2915
+ return typeof payload === "string" || _typeof(payload) === "object";
2916
+
2917
+ case PacketType.EVENT:
2918
+ case PacketType.BINARY_EVENT:
2919
+ return Array.isArray(payload) && payload.length > 0;
2920
+
2921
+ case PacketType.ACK:
2922
+ case PacketType.BINARY_ACK:
2923
+ return Array.isArray(payload);
2924
+ }
2925
+ }
2926
+ }]);
2927
+
2928
+ return Decoder;
2929
+ }(Emitter_1);
2930
+
2931
+ function tryParse(str) {
2932
+ try {
2933
+ return JSON.parse(str);
2934
+ } catch (e) {
2935
+ return false;
2936
+ }
2937
+ }
2938
+ /**
2939
+ * A manager of a binary event's 'buffer sequence'. Should
2940
+ * be constructed whenever a packet of type BINARY_EVENT is
2941
+ * decoded.
2942
+ *
2943
+ * @param {Object} packet
2944
+ * @return {BinaryReconstructor} initialized reconstructor
2945
+ */
2946
+
2947
+
2948
+ var BinaryReconstructor = /*#__PURE__*/function () {
2949
+ function BinaryReconstructor(packet) {
2950
+ _classCallCheck(this, BinaryReconstructor);
2951
+
2952
+ this.packet = packet;
2953
+ this.buffers = [];
2954
+ this.reconPack = packet;
2955
+ }
2956
+ /**
2957
+ * Method to be called when binary data received from connection
2958
+ * after a BINARY_EVENT packet.
2959
+ *
2960
+ * @param {Buffer | ArrayBuffer} binData - the raw binary data received
2961
+ * @return {null | Object} returns null if more binary data is expected or
2962
+ * a reconstructed packet object if all buffers have been received.
2963
+ */
2964
+
2965
+
2966
+ _createClass(BinaryReconstructor, [{
2967
+ key: "takeBinaryData",
2968
+ value: function takeBinaryData(binData) {
2969
+ this.buffers.push(binData);
2970
+
2971
+ if (this.buffers.length === this.reconPack.attachments) {
2972
+ // done with buffer list
2973
+ var packet = reconstructPacket(this.reconPack, this.buffers);
2974
+ this.finishedReconstruction();
2975
+ return packet;
2976
+ }
2977
+
2978
+ return null;
2979
+ }
2980
+ /**
2981
+ * Cleans up binary packet reconstruction variables.
2982
+ */
2983
+
2984
+ }, {
2985
+ key: "finishedReconstruction",
2986
+ value: function finishedReconstruction() {
2987
+ this.reconPack = null;
2988
+ this.buffers = [];
2989
+ }
2990
+ }]);
2991
+
2992
+ return BinaryReconstructor;
2993
+ }();
2994
+
2995
+ var parser = /*#__PURE__*/Object.freeze({
2996
+ __proto__: null,
2997
+ protocol: protocol,
2998
+ get PacketType () { return PacketType; },
2999
+ Encoder: Encoder,
3000
+ Decoder: Decoder
3001
+ });
3002
+
3003
+ function on(obj, ev, fn) {
3004
+ obj.on(ev, fn);
3005
+ return function subDestroy() {
3006
+ obj.off(ev, fn);
3007
+ };
3008
+ }
3009
+
3010
+ /**
3011
+ * Internal events.
3012
+ * These events can't be emitted by the user.
3013
+ */
3014
+
3015
+ var RESERVED_EVENTS = Object.freeze({
3016
+ connect: 1,
3017
+ connect_error: 1,
3018
+ disconnect: 1,
3019
+ disconnecting: 1,
3020
+ // EventEmitter reserved events: https://nodejs.org/api/events.html#events_event_newlistener
3021
+ newListener: 1,
3022
+ removeListener: 1
3023
+ });
3024
+ var Socket = /*#__PURE__*/function (_Emitter) {
3025
+ _inherits(Socket, _Emitter);
3026
+
3027
+ var _super = _createSuper(Socket);
3028
+
3029
+ /**
3030
+ * `Socket` constructor.
3031
+ *
3032
+ * @public
3033
+ */
3034
+ function Socket(io, nsp, opts) {
3035
+ var _this;
3036
+
3037
+ _classCallCheck(this, Socket);
3038
+
3039
+ _this = _super.call(this);
3040
+ _this.connected = false;
3041
+ _this.disconnected = true;
3042
+ _this.receiveBuffer = [];
3043
+ _this.sendBuffer = [];
3044
+ _this.ids = 0;
3045
+ _this.acks = {};
3046
+ _this.flags = {};
3047
+ _this.io = io;
3048
+ _this.nsp = nsp;
3049
+
3050
+ if (opts && opts.auth) {
3051
+ _this.auth = opts.auth;
3052
+ }
3053
+
3054
+ if (_this.io._autoConnect) _this.open();
3055
+ return _this;
3056
+ }
3057
+ /**
3058
+ * Subscribe to open, close and packet events
3059
+ *
3060
+ * @private
3061
+ */
3062
+
3063
+
3064
+ _createClass(Socket, [{
3065
+ key: "subEvents",
3066
+ value: function subEvents() {
3067
+ if (this.subs) return;
3068
+ var io = this.io;
3069
+ this.subs = [on(io, "open", this.onopen.bind(this)), on(io, "packet", this.onpacket.bind(this)), on(io, "error", this.onerror.bind(this)), on(io, "close", this.onclose.bind(this))];
3070
+ }
3071
+ /**
3072
+ * Whether the Socket will try to reconnect when its Manager connects or reconnects
3073
+ */
3074
+
3075
+ }, {
3076
+ key: "active",
3077
+ get: function get() {
3078
+ return !!this.subs;
3079
+ }
3080
+ /**
3081
+ * "Opens" the socket.
3082
+ *
3083
+ * @public
3084
+ */
3085
+
3086
+ }, {
3087
+ key: "connect",
3088
+ value: function connect() {
3089
+ if (this.connected) return this;
3090
+ this.subEvents();
3091
+ if (!this.io["_reconnecting"]) this.io.open(); // ensure open
3092
+
3093
+ if ("open" === this.io._readyState) this.onopen();
3094
+ return this;
3095
+ }
3096
+ /**
3097
+ * Alias for connect()
3098
+ */
3099
+
3100
+ }, {
3101
+ key: "open",
3102
+ value: function open() {
3103
+ return this.connect();
3104
+ }
3105
+ /**
3106
+ * Sends a `message` event.
3107
+ *
3108
+ * @return self
3109
+ * @public
3110
+ */
3111
+
3112
+ }, {
3113
+ key: "send",
3114
+ value: function send() {
3115
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
3116
+ args[_key] = arguments[_key];
3117
+ }
3118
+
3119
+ args.unshift("message");
3120
+ this.emit.apply(this, args);
3121
+ return this;
3122
+ }
3123
+ /**
3124
+ * Override `emit`.
3125
+ * If the event is in `events`, it's emitted normally.
3126
+ *
3127
+ * @return self
3128
+ * @public
3129
+ */
3130
+
3131
+ }, {
3132
+ key: "emit",
3133
+ value: function emit(ev) {
3134
+ if (RESERVED_EVENTS.hasOwnProperty(ev)) {
3135
+ throw new Error('"' + ev + '" is a reserved event name');
3136
+ }
3137
+
3138
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
3139
+ args[_key2 - 1] = arguments[_key2];
3140
+ }
3141
+
3142
+ args.unshift(ev);
3143
+ var packet = {
3144
+ type: PacketType.EVENT,
3145
+ data: args
3146
+ };
3147
+ packet.options = {};
3148
+ packet.options.compress = this.flags.compress !== false; // event ack callback
3149
+
3150
+ if ("function" === typeof args[args.length - 1]) {
3151
+ var id = this.ids++;
3152
+ var ack = args.pop();
3153
+
3154
+ this._registerAckCallback(id, ack);
3155
+
3156
+ packet.id = id;
3157
+ }
3158
+
3159
+ var isTransportWritable = this.io.engine && this.io.engine.transport && this.io.engine.transport.writable;
3160
+ var discardPacket = this.flags["volatile"] && (!isTransportWritable || !this.connected);
3161
+
3162
+ if (discardPacket) ; else if (this.connected) {
3163
+ this.packet(packet);
3164
+ } else {
3165
+ this.sendBuffer.push(packet);
3166
+ }
3167
+
3168
+ this.flags = {};
3169
+ return this;
3170
+ }
3171
+ /**
3172
+ * @private
3173
+ */
3174
+
3175
+ }, {
3176
+ key: "_registerAckCallback",
3177
+ value: function _registerAckCallback(id, ack) {
3178
+ var _this2 = this;
3179
+
3180
+ var timeout = this.flags.timeout;
3181
+
3182
+ if (timeout === undefined) {
3183
+ this.acks[id] = ack;
3184
+ return;
3185
+ } // @ts-ignore
3186
+
3187
+
3188
+ var timer = this.io.setTimeoutFn(function () {
3189
+ delete _this2.acks[id];
3190
+
3191
+ for (var i = 0; i < _this2.sendBuffer.length; i++) {
3192
+ if (_this2.sendBuffer[i].id === id) {
3193
+ _this2.sendBuffer.splice(i, 1);
3194
+ }
3195
+ }
3196
+
3197
+ ack.call(_this2, new Error("operation has timed out"));
3198
+ }, timeout);
3199
+
3200
+ this.acks[id] = function () {
3201
+ // @ts-ignore
3202
+ _this2.io.clearTimeoutFn(timer);
3203
+
3204
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
3205
+ args[_key3] = arguments[_key3];
3206
+ }
3207
+
3208
+ ack.apply(_this2, [null].concat(args));
3209
+ };
3210
+ }
3211
+ /**
3212
+ * Sends a packet.
3213
+ *
3214
+ * @param packet
3215
+ * @private
3216
+ */
3217
+
3218
+ }, {
3219
+ key: "packet",
3220
+ value: function packet(_packet) {
3221
+ _packet.nsp = this.nsp;
3222
+
3223
+ this.io._packet(_packet);
3224
+ }
3225
+ /**
3226
+ * Called upon engine `open`.
3227
+ *
3228
+ * @private
3229
+ */
3230
+
3231
+ }, {
3232
+ key: "onopen",
3233
+ value: function onopen() {
3234
+ var _this3 = this;
3235
+
3236
+ if (typeof this.auth == "function") {
3237
+ this.auth(function (data) {
3238
+ _this3.packet({
3239
+ type: PacketType.CONNECT,
3240
+ data: data
3241
+ });
3242
+ });
3243
+ } else {
3244
+ this.packet({
3245
+ type: PacketType.CONNECT,
3246
+ data: this.auth
3247
+ });
3248
+ }
3249
+ }
3250
+ /**
3251
+ * Called upon engine or manager `error`.
3252
+ *
3253
+ * @param err
3254
+ * @private
3255
+ */
3256
+
3257
+ }, {
3258
+ key: "onerror",
3259
+ value: function onerror(err) {
3260
+ if (!this.connected) {
3261
+ this.emitReserved("connect_error", err);
3262
+ }
3263
+ }
3264
+ /**
3265
+ * Called upon engine `close`.
3266
+ *
3267
+ * @param reason
3268
+ * @private
3269
+ */
3270
+
3271
+ }, {
3272
+ key: "onclose",
3273
+ value: function onclose(reason) {
3274
+ this.connected = false;
3275
+ this.disconnected = true;
3276
+ delete this.id;
3277
+ this.emitReserved("disconnect", reason);
3278
+ }
3279
+ /**
3280
+ * Called with socket packet.
3281
+ *
3282
+ * @param packet
3283
+ * @private
3284
+ */
3285
+
3286
+ }, {
3287
+ key: "onpacket",
3288
+ value: function onpacket(packet) {
3289
+ var sameNamespace = packet.nsp === this.nsp;
3290
+ if (!sameNamespace) return;
3291
+
3292
+ switch (packet.type) {
3293
+ case PacketType.CONNECT:
3294
+ if (packet.data && packet.data.sid) {
3295
+ var id = packet.data.sid;
3296
+ this.onconnect(id);
3297
+ } else {
3298
+ this.emitReserved("connect_error", new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));
3299
+ }
3300
+
3301
+ break;
3302
+
3303
+ case PacketType.EVENT:
3304
+ this.onevent(packet);
3305
+ break;
3306
+
3307
+ case PacketType.BINARY_EVENT:
3308
+ this.onevent(packet);
3309
+ break;
3310
+
3311
+ case PacketType.ACK:
3312
+ this.onack(packet);
3313
+ break;
3314
+
3315
+ case PacketType.BINARY_ACK:
3316
+ this.onack(packet);
3317
+ break;
3318
+
3319
+ case PacketType.DISCONNECT:
3320
+ this.ondisconnect();
3321
+ break;
3322
+
3323
+ case PacketType.CONNECT_ERROR:
3324
+ this.destroy();
3325
+ var err = new Error(packet.data.message); // @ts-ignore
3326
+
3327
+ err.data = packet.data.data;
3328
+ this.emitReserved("connect_error", err);
3329
+ break;
3330
+ }
3331
+ }
3332
+ /**
3333
+ * Called upon a server event.
3334
+ *
3335
+ * @param packet
3336
+ * @private
3337
+ */
3338
+
3339
+ }, {
3340
+ key: "onevent",
3341
+ value: function onevent(packet) {
3342
+ var args = packet.data || [];
3343
+
3344
+ if (null != packet.id) {
3345
+ args.push(this.ack(packet.id));
3346
+ }
3347
+
3348
+ if (this.connected) {
3349
+ this.emitEvent(args);
3350
+ } else {
3351
+ this.receiveBuffer.push(Object.freeze(args));
3352
+ }
3353
+ }
3354
+ }, {
3355
+ key: "emitEvent",
3356
+ value: function emitEvent(args) {
3357
+ if (this._anyListeners && this._anyListeners.length) {
3358
+ var listeners = this._anyListeners.slice();
3359
+
3360
+ var _iterator = _createForOfIteratorHelper(listeners),
3361
+ _step;
3362
+
3363
+ try {
3364
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
3365
+ var listener = _step.value;
3366
+ listener.apply(this, args);
3367
+ }
3368
+ } catch (err) {
3369
+ _iterator.e(err);
3370
+ } finally {
3371
+ _iterator.f();
3372
+ }
3373
+ }
3374
+
3375
+ _get(_getPrototypeOf(Socket.prototype), "emit", this).apply(this, args);
3376
+ }
3377
+ /**
3378
+ * Produces an ack callback to emit with an event.
3379
+ *
3380
+ * @private
3381
+ */
3382
+
3383
+ }, {
3384
+ key: "ack",
3385
+ value: function ack(id) {
3386
+ var self = this;
3387
+ var sent = false;
3388
+ return function () {
3389
+ // prevent double callbacks
3390
+ if (sent) return;
3391
+ sent = true;
3392
+
3393
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
3394
+ args[_key4] = arguments[_key4];
3395
+ }
3396
+
3397
+ self.packet({
3398
+ type: PacketType.ACK,
3399
+ id: id,
3400
+ data: args
3401
+ });
3402
+ };
3403
+ }
3404
+ /**
3405
+ * Called upon a server acknowlegement.
3406
+ *
3407
+ * @param packet
3408
+ * @private
3409
+ */
3410
+
3411
+ }, {
3412
+ key: "onack",
3413
+ value: function onack(packet) {
3414
+ var ack = this.acks[packet.id];
3415
+
3416
+ if ("function" === typeof ack) {
3417
+ ack.apply(this, packet.data);
3418
+ delete this.acks[packet.id];
3419
+ }
3420
+ }
3421
+ /**
3422
+ * Called upon server connect.
3423
+ *
3424
+ * @private
3425
+ */
3426
+
3427
+ }, {
3428
+ key: "onconnect",
3429
+ value: function onconnect(id) {
3430
+ this.id = id;
3431
+ this.connected = true;
3432
+ this.disconnected = false;
3433
+ this.emitBuffered();
3434
+ this.emitReserved("connect");
3435
+ }
3436
+ /**
3437
+ * Emit buffered events (received and emitted).
3438
+ *
3439
+ * @private
3440
+ */
3441
+
3442
+ }, {
3443
+ key: "emitBuffered",
3444
+ value: function emitBuffered() {
3445
+ var _this4 = this;
3446
+
3447
+ this.receiveBuffer.forEach(function (args) {
3448
+ return _this4.emitEvent(args);
3449
+ });
3450
+ this.receiveBuffer = [];
3451
+ this.sendBuffer.forEach(function (packet) {
3452
+ return _this4.packet(packet);
3453
+ });
3454
+ this.sendBuffer = [];
3455
+ }
3456
+ /**
3457
+ * Called upon server disconnect.
3458
+ *
3459
+ * @private
3460
+ */
3461
+
3462
+ }, {
3463
+ key: "ondisconnect",
3464
+ value: function ondisconnect() {
3465
+ this.destroy();
3466
+ this.onclose("io server disconnect");
3467
+ }
3468
+ /**
3469
+ * Called upon forced client/server side disconnections,
3470
+ * this method ensures the manager stops tracking us and
3471
+ * that reconnections don't get triggered for this.
3472
+ *
3473
+ * @private
3474
+ */
3475
+
3476
+ }, {
3477
+ key: "destroy",
3478
+ value: function destroy() {
3479
+ if (this.subs) {
3480
+ // clean subscriptions to avoid reconnections
3481
+ this.subs.forEach(function (subDestroy) {
3482
+ return subDestroy();
3483
+ });
3484
+ this.subs = undefined;
3485
+ }
3486
+
3487
+ this.io["_destroy"](this);
3488
+ }
3489
+ /**
3490
+ * Disconnects the socket manually.
3491
+ *
3492
+ * @return self
3493
+ * @public
3494
+ */
3495
+
3496
+ }, {
3497
+ key: "disconnect",
3498
+ value: function disconnect() {
3499
+ if (this.connected) {
3500
+ this.packet({
3501
+ type: PacketType.DISCONNECT
3502
+ });
3503
+ } // remove socket from pool
3504
+
3505
+
3506
+ this.destroy();
3507
+
3508
+ if (this.connected) {
3509
+ // fire events
3510
+ this.onclose("io client disconnect");
3511
+ }
3512
+
3513
+ return this;
3514
+ }
3515
+ /**
3516
+ * Alias for disconnect()
3517
+ *
3518
+ * @return self
3519
+ * @public
3520
+ */
3521
+
3522
+ }, {
3523
+ key: "close",
3524
+ value: function close() {
3525
+ return this.disconnect();
3526
+ }
3527
+ /**
3528
+ * Sets the compress flag.
3529
+ *
3530
+ * @param compress - if `true`, compresses the sending data
3531
+ * @return self
3532
+ * @public
3533
+ */
3534
+
3535
+ }, {
3536
+ key: "compress",
3537
+ value: function compress(_compress) {
3538
+ this.flags.compress = _compress;
3539
+ return this;
3540
+ }
3541
+ /**
3542
+ * Sets a modifier for a subsequent event emission that the event message will be dropped when this socket is not
3543
+ * ready to send messages.
3544
+ *
3545
+ * @returns self
3546
+ * @public
3547
+ */
3548
+
3549
+ }, {
3550
+ key: "volatile",
3551
+ get: function get() {
3552
+ this.flags["volatile"] = true;
3553
+ return this;
3554
+ }
3555
+ /**
3556
+ * Sets a modifier for a subsequent event emission that the callback will be called with an error when the
3557
+ * given number of milliseconds have elapsed without an acknowledgement from the server:
3558
+ *
3559
+ * ```
3560
+ * socket.timeout(5000).emit("my-event", (err) => {
3561
+ * if (err) {
3562
+ * // the server did not acknowledge the event in the given delay
3563
+ * }
3564
+ * });
3565
+ * ```
3566
+ *
3567
+ * @returns self
3568
+ * @public
3569
+ */
3570
+
3571
+ }, {
3572
+ key: "timeout",
3573
+ value: function timeout(_timeout) {
3574
+ this.flags.timeout = _timeout;
3575
+ return this;
3576
+ }
3577
+ /**
3578
+ * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
3579
+ * callback.
3580
+ *
3581
+ * @param listener
3582
+ * @public
3583
+ */
3584
+
3585
+ }, {
3586
+ key: "onAny",
3587
+ value: function onAny(listener) {
3588
+ this._anyListeners = this._anyListeners || [];
3589
+
3590
+ this._anyListeners.push(listener);
3591
+
3592
+ return this;
3593
+ }
3594
+ /**
3595
+ * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
3596
+ * callback. The listener is added to the beginning of the listeners array.
3597
+ *
3598
+ * @param listener
3599
+ * @public
3600
+ */
3601
+
3602
+ }, {
3603
+ key: "prependAny",
3604
+ value: function prependAny(listener) {
3605
+ this._anyListeners = this._anyListeners || [];
3606
+
3607
+ this._anyListeners.unshift(listener);
3608
+
3609
+ return this;
3610
+ }
3611
+ /**
3612
+ * Removes the listener that will be fired when any event is emitted.
3613
+ *
3614
+ * @param listener
3615
+ * @public
3616
+ */
3617
+
3618
+ }, {
3619
+ key: "offAny",
3620
+ value: function offAny(listener) {
3621
+ if (!this._anyListeners) {
3622
+ return this;
3623
+ }
3624
+
3625
+ if (listener) {
3626
+ var listeners = this._anyListeners;
3627
+
3628
+ for (var i = 0; i < listeners.length; i++) {
3629
+ if (listener === listeners[i]) {
3630
+ listeners.splice(i, 1);
3631
+ return this;
3632
+ }
3633
+ }
3634
+ } else {
3635
+ this._anyListeners = [];
3636
+ }
3637
+
3638
+ return this;
3639
+ }
3640
+ /**
3641
+ * Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
3642
+ * e.g. to remove listeners.
3643
+ *
3644
+ * @public
3645
+ */
3646
+
3647
+ }, {
3648
+ key: "listenersAny",
3649
+ value: function listenersAny() {
3650
+ return this._anyListeners || [];
3651
+ }
3652
+ }]);
3653
+
3654
+ return Socket;
3655
+ }(Emitter_1);
3656
+
3657
+ /**
3658
+ * Expose `Backoff`.
3659
+ */
3660
+
3661
+ var backo2 = Backoff;
3662
+ /**
3663
+ * Initialize backoff timer with `opts`.
3664
+ *
3665
+ * - `min` initial timeout in milliseconds [100]
3666
+ * - `max` max timeout [10000]
3667
+ * - `jitter` [0]
3668
+ * - `factor` [2]
3669
+ *
3670
+ * @param {Object} opts
3671
+ * @api public
3672
+ */
3673
+
3674
+ function Backoff(opts) {
3675
+ opts = opts || {};
3676
+ this.ms = opts.min || 100;
3677
+ this.max = opts.max || 10000;
3678
+ this.factor = opts.factor || 2;
3679
+ this.jitter = opts.jitter > 0 && opts.jitter <= 1 ? opts.jitter : 0;
3680
+ this.attempts = 0;
3681
+ }
3682
+ /**
3683
+ * Return the backoff duration.
3684
+ *
3685
+ * @return {Number}
3686
+ * @api public
3687
+ */
3688
+
3689
+
3690
+ Backoff.prototype.duration = function () {
3691
+ var ms = this.ms * Math.pow(this.factor, this.attempts++);
3692
+
3693
+ if (this.jitter) {
3694
+ var rand = Math.random();
3695
+ var deviation = Math.floor(rand * this.jitter * ms);
3696
+ ms = (Math.floor(rand * 10) & 1) == 0 ? ms - deviation : ms + deviation;
3697
+ }
3698
+
3699
+ return Math.min(ms, this.max) | 0;
3700
+ };
3701
+ /**
3702
+ * Reset the number of attempts.
3703
+ *
3704
+ * @api public
3705
+ */
3706
+
3707
+
3708
+ Backoff.prototype.reset = function () {
3709
+ this.attempts = 0;
3710
+ };
3711
+ /**
3712
+ * Set the minimum duration
3713
+ *
3714
+ * @api public
3715
+ */
3716
+
3717
+
3718
+ Backoff.prototype.setMin = function (min) {
3719
+ this.ms = min;
3720
+ };
3721
+ /**
3722
+ * Set the maximum duration
3723
+ *
3724
+ * @api public
3725
+ */
3726
+
3727
+
3728
+ Backoff.prototype.setMax = function (max) {
3729
+ this.max = max;
3730
+ };
3731
+ /**
3732
+ * Set the jitter
3733
+ *
3734
+ * @api public
3735
+ */
3736
+
3737
+
3738
+ Backoff.prototype.setJitter = function (jitter) {
3739
+ this.jitter = jitter;
3740
+ };
3741
+
3742
+ var Manager = /*#__PURE__*/function (_Emitter) {
3743
+ _inherits(Manager, _Emitter);
3744
+
3745
+ var _super = _createSuper(Manager);
3746
+
3747
+ function Manager(uri, opts) {
3748
+ var _this;
3749
+
3750
+ _classCallCheck(this, Manager);
3751
+
3752
+ var _a;
3753
+
3754
+ _this = _super.call(this);
3755
+ _this.nsps = {};
3756
+ _this.subs = [];
3757
+
3758
+ if (uri && "object" === _typeof(uri)) {
3759
+ opts = uri;
3760
+ uri = undefined;
3761
+ }
3762
+
3763
+ opts = opts || {};
3764
+ opts.path = opts.path || "/socket.io";
3765
+ _this.opts = opts;
3766
+ installTimerFunctions(_assertThisInitialized(_this), opts);
3767
+
3768
+ _this.reconnection(opts.reconnection !== false);
3769
+
3770
+ _this.reconnectionAttempts(opts.reconnectionAttempts || Infinity);
3771
+
3772
+ _this.reconnectionDelay(opts.reconnectionDelay || 1000);
3773
+
3774
+ _this.reconnectionDelayMax(opts.reconnectionDelayMax || 5000);
3775
+
3776
+ _this.randomizationFactor((_a = opts.randomizationFactor) !== null && _a !== void 0 ? _a : 0.5);
3777
+
3778
+ _this.backoff = new backo2({
3779
+ min: _this.reconnectionDelay(),
3780
+ max: _this.reconnectionDelayMax(),
3781
+ jitter: _this.randomizationFactor()
3782
+ });
3783
+
3784
+ _this.timeout(null == opts.timeout ? 20000 : opts.timeout);
3785
+
3786
+ _this._readyState = "closed";
3787
+ _this.uri = uri;
3788
+
3789
+ var _parser = opts.parser || parser;
3790
+
3791
+ _this.encoder = new _parser.Encoder();
3792
+ _this.decoder = new _parser.Decoder();
3793
+ _this._autoConnect = opts.autoConnect !== false;
3794
+ if (_this._autoConnect) _this.open();
3795
+ return _this;
3796
+ }
3797
+
3798
+ _createClass(Manager, [{
3799
+ key: "reconnection",
3800
+ value: function reconnection(v) {
3801
+ if (!arguments.length) return this._reconnection;
3802
+ this._reconnection = !!v;
3803
+ return this;
3804
+ }
3805
+ }, {
3806
+ key: "reconnectionAttempts",
3807
+ value: function reconnectionAttempts(v) {
3808
+ if (v === undefined) return this._reconnectionAttempts;
3809
+ this._reconnectionAttempts = v;
3810
+ return this;
3811
+ }
3812
+ }, {
3813
+ key: "reconnectionDelay",
3814
+ value: function reconnectionDelay(v) {
3815
+ var _a;
3816
+
3817
+ if (v === undefined) return this._reconnectionDelay;
3818
+ this._reconnectionDelay = v;
3819
+ (_a = this.backoff) === null || _a === void 0 ? void 0 : _a.setMin(v);
3820
+ return this;
3821
+ }
3822
+ }, {
3823
+ key: "randomizationFactor",
3824
+ value: function randomizationFactor(v) {
3825
+ var _a;
3826
+
3827
+ if (v === undefined) return this._randomizationFactor;
3828
+ this._randomizationFactor = v;
3829
+ (_a = this.backoff) === null || _a === void 0 ? void 0 : _a.setJitter(v);
3830
+ return this;
3831
+ }
3832
+ }, {
3833
+ key: "reconnectionDelayMax",
3834
+ value: function reconnectionDelayMax(v) {
3835
+ var _a;
3836
+
3837
+ if (v === undefined) return this._reconnectionDelayMax;
3838
+ this._reconnectionDelayMax = v;
3839
+ (_a = this.backoff) === null || _a === void 0 ? void 0 : _a.setMax(v);
3840
+ return this;
3841
+ }
3842
+ }, {
3843
+ key: "timeout",
3844
+ value: function timeout(v) {
3845
+ if (!arguments.length) return this._timeout;
3846
+ this._timeout = v;
3847
+ return this;
3848
+ }
3849
+ /**
3850
+ * Starts trying to reconnect if reconnection is enabled and we have not
3851
+ * started reconnecting yet
3852
+ *
3853
+ * @private
3854
+ */
3855
+
3856
+ }, {
3857
+ key: "maybeReconnectOnOpen",
3858
+ value: function maybeReconnectOnOpen() {
3859
+ // Only try to reconnect if it's the first time we're connecting
3860
+ if (!this._reconnecting && this._reconnection && this.backoff.attempts === 0) {
3861
+ // keeps reconnection from firing twice for the same reconnection loop
3862
+ this.reconnect();
3863
+ }
3864
+ }
3865
+ /**
3866
+ * Sets the current transport `socket`.
3867
+ *
3868
+ * @param {Function} fn - optional, callback
3869
+ * @return self
3870
+ * @public
3871
+ */
3872
+
3873
+ }, {
3874
+ key: "open",
3875
+ value: function open(fn) {
3876
+ var _this2 = this;
3877
+
3878
+ if (~this._readyState.indexOf("open")) return this;
3879
+ this.engine = new Socket$1(this.uri, this.opts);
3880
+ var socket = this.engine;
3881
+ var self = this;
3882
+ this._readyState = "opening";
3883
+ this.skipReconnect = false; // emit `open`
3884
+
3885
+ var openSubDestroy = on(socket, "open", function () {
3886
+ self.onopen();
3887
+ fn && fn();
3888
+ }); // emit `error`
3889
+
3890
+ var errorSub = on(socket, "error", function (err) {
3891
+ self.cleanup();
3892
+ self._readyState = "closed";
3893
+
3894
+ _this2.emitReserved("error", err);
3895
+
3896
+ if (fn) {
3897
+ fn(err);
3898
+ } else {
3899
+ // Only do this if there is no fn to handle the error
3900
+ self.maybeReconnectOnOpen();
3901
+ }
3902
+ });
3903
+
3904
+ if (false !== this._timeout) {
3905
+ var timeout = this._timeout;
3906
+
3907
+ if (timeout === 0) {
3908
+ openSubDestroy(); // prevents a race condition with the 'open' event
3909
+ } // set timer
3910
+
3911
+
3912
+ var timer = this.setTimeoutFn(function () {
3913
+ openSubDestroy();
3914
+ socket.close(); // @ts-ignore
3915
+
3916
+ socket.emit("error", new Error("timeout"));
3917
+ }, timeout);
3918
+
3919
+ if (this.opts.autoUnref) {
3920
+ timer.unref();
3921
+ }
3922
+
3923
+ this.subs.push(function subDestroy() {
3924
+ clearTimeout(timer);
3925
+ });
3926
+ }
3927
+
3928
+ this.subs.push(openSubDestroy);
3929
+ this.subs.push(errorSub);
3930
+ return this;
3931
+ }
3932
+ /**
3933
+ * Alias for open()
3934
+ *
3935
+ * @return self
3936
+ * @public
3937
+ */
3938
+
3939
+ }, {
3940
+ key: "connect",
3941
+ value: function connect(fn) {
3942
+ return this.open(fn);
3943
+ }
3944
+ /**
3945
+ * Called upon transport open.
3946
+ *
3947
+ * @private
3948
+ */
3949
+
3950
+ }, {
3951
+ key: "onopen",
3952
+ value: function onopen() {
3953
+ // clear old subs
3954
+ this.cleanup(); // mark as open
3955
+
3956
+ this._readyState = "open";
3957
+ this.emitReserved("open"); // add new subs
3958
+
3959
+ var socket = this.engine;
3960
+ this.subs.push(on(socket, "ping", this.onping.bind(this)), on(socket, "data", this.ondata.bind(this)), on(socket, "error", this.onerror.bind(this)), on(socket, "close", this.onclose.bind(this)), on(this.decoder, "decoded", this.ondecoded.bind(this)));
3961
+ }
3962
+ /**
3963
+ * Called upon a ping.
3964
+ *
3965
+ * @private
3966
+ */
3967
+
3968
+ }, {
3969
+ key: "onping",
3970
+ value: function onping() {
3971
+ this.emitReserved("ping");
3972
+ }
3973
+ /**
3974
+ * Called with data.
3975
+ *
3976
+ * @private
3977
+ */
3978
+
3979
+ }, {
3980
+ key: "ondata",
3981
+ value: function ondata(data) {
3982
+ this.decoder.add(data);
3983
+ }
3984
+ /**
3985
+ * Called when parser fully decodes a packet.
3986
+ *
3987
+ * @private
3988
+ */
3989
+
3990
+ }, {
3991
+ key: "ondecoded",
3992
+ value: function ondecoded(packet) {
3993
+ this.emitReserved("packet", packet);
3994
+ }
3995
+ /**
3996
+ * Called upon socket error.
3997
+ *
3998
+ * @private
3999
+ */
4000
+
4001
+ }, {
4002
+ key: "onerror",
4003
+ value: function onerror(err) {
4004
+ this.emitReserved("error", err);
4005
+ }
4006
+ /**
4007
+ * Creates a new socket for the given `nsp`.
4008
+ *
4009
+ * @return {Socket}
4010
+ * @public
4011
+ */
4012
+
4013
+ }, {
4014
+ key: "socket",
4015
+ value: function socket(nsp, opts) {
4016
+ var socket = this.nsps[nsp];
4017
+
4018
+ if (!socket) {
4019
+ socket = new Socket(this, nsp, opts);
4020
+ this.nsps[nsp] = socket;
4021
+ }
4022
+
4023
+ return socket;
4024
+ }
4025
+ /**
4026
+ * Called upon a socket close.
4027
+ *
4028
+ * @param socket
4029
+ * @private
4030
+ */
4031
+
4032
+ }, {
4033
+ key: "_destroy",
4034
+ value: function _destroy(socket) {
4035
+ var nsps = Object.keys(this.nsps);
4036
+
4037
+ for (var _i = 0, _nsps = nsps; _i < _nsps.length; _i++) {
4038
+ var nsp = _nsps[_i];
4039
+ var _socket = this.nsps[nsp];
4040
+
4041
+ if (_socket.active) {
4042
+ return;
4043
+ }
4044
+ }
4045
+
4046
+ this._close();
4047
+ }
4048
+ /**
4049
+ * Writes a packet.
4050
+ *
4051
+ * @param packet
4052
+ * @private
4053
+ */
4054
+
4055
+ }, {
4056
+ key: "_packet",
4057
+ value: function _packet(packet) {
4058
+ var encodedPackets = this.encoder.encode(packet);
4059
+
4060
+ for (var i = 0; i < encodedPackets.length; i++) {
4061
+ this.engine.write(encodedPackets[i], packet.options);
4062
+ }
4063
+ }
4064
+ /**
4065
+ * Clean up transport subscriptions and packet buffer.
4066
+ *
4067
+ * @private
4068
+ */
4069
+
4070
+ }, {
4071
+ key: "cleanup",
4072
+ value: function cleanup() {
4073
+ this.subs.forEach(function (subDestroy) {
4074
+ return subDestroy();
4075
+ });
4076
+ this.subs.length = 0;
4077
+ this.decoder.destroy();
4078
+ }
4079
+ /**
4080
+ * Close the current socket.
4081
+ *
4082
+ * @private
4083
+ */
4084
+
4085
+ }, {
4086
+ key: "_close",
4087
+ value: function _close() {
4088
+ this.skipReconnect = true;
4089
+ this._reconnecting = false;
4090
+ this.onclose("forced close");
4091
+ if (this.engine) this.engine.close();
4092
+ }
4093
+ /**
4094
+ * Alias for close()
4095
+ *
4096
+ * @private
4097
+ */
4098
+
4099
+ }, {
4100
+ key: "disconnect",
4101
+ value: function disconnect() {
4102
+ return this._close();
4103
+ }
4104
+ /**
4105
+ * Called upon engine close.
4106
+ *
4107
+ * @private
4108
+ */
4109
+
4110
+ }, {
4111
+ key: "onclose",
4112
+ value: function onclose(reason) {
4113
+ this.cleanup();
4114
+ this.backoff.reset();
4115
+ this._readyState = "closed";
4116
+ this.emitReserved("close", reason);
4117
+
4118
+ if (this._reconnection && !this.skipReconnect) {
4119
+ this.reconnect();
4120
+ }
4121
+ }
4122
+ /**
4123
+ * Attempt a reconnection.
4124
+ *
4125
+ * @private
4126
+ */
4127
+
4128
+ }, {
4129
+ key: "reconnect",
4130
+ value: function reconnect() {
4131
+ var _this3 = this;
4132
+
4133
+ if (this._reconnecting || this.skipReconnect) return this;
4134
+ var self = this;
4135
+
4136
+ if (this.backoff.attempts >= this._reconnectionAttempts) {
4137
+ this.backoff.reset();
4138
+ this.emitReserved("reconnect_failed");
4139
+ this._reconnecting = false;
4140
+ } else {
4141
+ var delay = this.backoff.duration();
4142
+ this._reconnecting = true;
4143
+ var timer = this.setTimeoutFn(function () {
4144
+ if (self.skipReconnect) return;
4145
+
4146
+ _this3.emitReserved("reconnect_attempt", self.backoff.attempts); // check again for the case socket closed in above events
4147
+
4148
+
4149
+ if (self.skipReconnect) return;
4150
+ self.open(function (err) {
4151
+ if (err) {
4152
+ self._reconnecting = false;
4153
+ self.reconnect();
4154
+
4155
+ _this3.emitReserved("reconnect_error", err);
4156
+ } else {
4157
+ self.onreconnect();
4158
+ }
4159
+ });
4160
+ }, delay);
4161
+
4162
+ if (this.opts.autoUnref) {
4163
+ timer.unref();
4164
+ }
4165
+
4166
+ this.subs.push(function subDestroy() {
4167
+ clearTimeout(timer);
4168
+ });
4169
+ }
4170
+ }
4171
+ /**
4172
+ * Called upon successful reconnect.
4173
+ *
4174
+ * @private
4175
+ */
4176
+
4177
+ }, {
4178
+ key: "onreconnect",
4179
+ value: function onreconnect() {
4180
+ var attempt = this.backoff.attempts;
4181
+ this._reconnecting = false;
4182
+ this.backoff.reset();
4183
+ this.emitReserved("reconnect", attempt);
4184
+ }
4185
+ }]);
4186
+
4187
+ return Manager;
4188
+ }(Emitter_1);
4189
+
4190
+ /**
4191
+ * Managers cache.
4192
+ */
4193
+
4194
+ var cache = {};
4195
+
4196
+ function lookup(uri, opts) {
4197
+ if (_typeof(uri) === "object") {
4198
+ opts = uri;
4199
+ uri = undefined;
4200
+ }
4201
+
4202
+ opts = opts || {};
4203
+ var parsed = url(uri, opts.path || "/socket.io");
4204
+ var source = parsed.source;
4205
+ var id = parsed.id;
4206
+ var path = parsed.path;
4207
+ var sameNamespace = cache[id] && path in cache[id]["nsps"];
4208
+ var newConnection = opts.forceNew || opts["force new connection"] || false === opts.multiplex || sameNamespace;
4209
+ var io;
4210
+
4211
+ if (newConnection) {
4212
+ io = new Manager(source, opts);
4213
+ } else {
4214
+ if (!cache[id]) {
4215
+ cache[id] = new Manager(source, opts);
4216
+ }
4217
+
4218
+ io = cache[id];
4219
+ }
4220
+
4221
+ if (parsed.query && !opts.query) {
4222
+ opts.query = parsed.queryKey;
4223
+ }
4224
+
4225
+ return io.socket(parsed.path, opts);
4226
+ } // so that "lookup" can be used both as a function (e.g. `io(...)`) and as a
4227
+ // namespace (e.g. `io.connect(...)`), for backward compatibility
4228
+
4229
+
4230
+ _extends(lookup, {
4231
+ Manager: Manager,
4232
+ Socket: Socket,
4233
+ io: lookup,
4234
+ connect: lookup
4235
+ });
4236
+
4237
+ return lookup;
4238
+
4239
+ }));
4240
+ //# sourceMappingURL=socket.io.js.map