!function(e,t,n,r){t[e]=n.call(t);for(var o=0;o<r.length;o++)r[o](t[e]);"undefined"!=typeof module&&module.exports?module.exports=t[e]:"function"==typeof define&&define.amd&&define(function(){return t[e]})}("Primus",this||{},function(){var e,t=function n(e,t,r){function o(s,c){if(!t[s]){if(!e[s]){var a="function"==typeof require&&require;if(!c&&a)return a(s,!0);if(i)return i(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var f=t[s]={exports:{}};e[s][0].call(f.exports,function(t){var n=e[s][1][t];return o(n?n:t)},f,f.exports,n,e,t,r)}return t[s].exports}for(var i="function"==typeof require&&require,s=0;s<r.length;s++)o(r[s]);return o}({1:[function(e,t,n){"use strict";t.exports=function(e,t){function n(e,n){if(t[e]){if("string"==typeof t[e]&&(t[e]=t[e].split(r)),"function"==typeof t[e])return t[e].call(n);for(var o,i,s=0;s<t[e].length;s++)i=t[e][s],o=typeof i,"function"===o?i.call(n):"string"===o&&"function"==typeof n[i]&&n[i]()}}var r=/[, ]+/;return t=t||{},e=e||[],"string"==typeof e&&(e=e.split(r)),function(){var t,r=this,o=0;if(null===r[e[0]])return!1;for(n("before",r);o<e.length;o++)t=e[o],r[t]&&("function"==typeof r[t].destroy&&r[t].destroy(),r[t]=null);return r.emit&&r.emit("destroy"),n("after",r),!0}}},{}],2:[function(e,t,n){"use strict";t.exports=function(){for(var e,t=this,n=0,r=arguments.length,o=new Array(r);n<r;n++)o[n]=arguments[n];return"function"!=typeof o[o.length-1]?function(){for(var e=0,n=arguments.length,r=new Array(n);e<n;e++)r[e]=arguments[e];return t.emit.apply(t,o.concat(r))}:(e=o.pop(),function(){for(var n=0,r=arguments.length,i=new Array(r+1);n<r;n++)i[n+1]=arguments[n];return i[0]=function(e,n){return e?t.emit("error",e):(i=void 0===n?i.slice(1):null===n?[]:n,void t.emit.apply(t,o.concat(i)))},e.apply(t,i),!0})}},{}],3:[function(e,t,n){"use strict";function r(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function o(){}var i=Object.prototype.hasOwnProperty,s="function"!=typeof Object.create&&"~";o.prototype._events=void 0,o.prototype.eventNames=function(){var e,t=this._events,n=[];if(!t)return n;for(e in t)i.call(t,e)&&n.push(s?e.slice(1):e);return Object.getOwnPropertySymbols?n.concat(Object.getOwnPropertySymbols(t)):n},o.prototype.listeners=function(e,t){var n=s?s+e:e,r=this._events&&this._events[n];if(t)return!!r;if(!r)return[];if(r.fn)return[r.fn];for(var o=0,i=r.length,c=new Array(i);o<i;o++)c[o]=r[o].fn;return c},o.prototype.emit=function(e,t,n,r,o,i){var c=s?s+e:e;if(!this._events||!this._events[c])return!1;var a,u,f=this._events[c],p=arguments.length;if("function"==typeof f.fn){switch(f.once&&this.removeListener(e,f.fn,void 0,!0),p){case 1:return f.fn.call(f.context),!0;case 2:return f.fn.call(f.context,t),!0;case 3:return f.fn.call(f.context,t,n),!0;case 4:return f.fn.call(f.context,t,n,r),!0;case 5:return f.fn.call(f.context,t,n,r,o),!0;case 6:return f.fn.call(f.context,t,n,r,o,i),!0}for(u=1,a=new Array(p-1);u<p;u++)a[u-1]=arguments[u];f.fn.apply(f.context,a)}else{var l,h=f.length;for(u=0;u<h;u++)switch(f[u].once&&this.removeListener(e,f[u].fn,void 0,!0),p){case 1:f[u].fn.call(f[u].context);break;case 2:f[u].fn.call(f[u].context,t);break;case 3:f[u].fn.call(f[u].context,t,n);break;default:if(!a)for(l=1,a=new Array(p-1);l<p;l++)a[l-1]=arguments[l];f[u].fn.apply(f[u].context,a)}}return!0},o.prototype.on=function(e,t,n){var o=new r(t,n||this),i=s?s+e:e;return this._events||(this._events=s?{}:Object.create(null)),this._events[i]?this._events[i].fn?this._events[i]=[this._events[i],o]:this._events[i].push(o):this._events[i]=o,this},o.prototype.once=function(e,t,n){var o=new r(t,n||this,(!0)),i=s?s+e:e;return this._events||(this._events=s?{}:Object.create(null)),this._events[i]?this._events[i].fn?this._events[i]=[this._events[i],o]:this._events[i].push(o):this._events[i]=o,this},o.prototype.removeListener=function(e,t,n,r){var o=s?s+e:e;if(!this._events||!this._events[o])return this;var i=this._events[o],c=[];if(t)if(i.fn)(i.fn!==t||r&&!i.once||n&&i.context!==n)&&c.push(i);else for(var a=0,u=i.length;a<u;a++)(i[a].fn!==t||r&&!i[a].once||n&&i[a].context!==n)&&c.push(i[a]);return c.length?this._events[o]=1===c.length?c[0]:c:delete this._events[o],this},o.prototype.removeAllListeners=function(e){return this._events?(e?delete this._events[s?s+e:e]:this._events=s?{}:Object.create(null),this):this},o.prototype.off=o.prototype.removeListener,o.prototype.addListener=o.prototype.on,o.prototype.setMaxListeners=function(){return this},o.prefixed=s,"undefined"!=typeof t&&(t.exports=o)},{}],4:[function(e,t,n){"use strict";var r=new RegExp("^((?:\\d+)?\\.?\\d+) *("+["milliseconds?","msecs?","ms","seconds?","secs?","s","minutes?","mins?","m","hours?","hrs?","h","days?","d","weeks?","wks?","w","years?","yrs?","y"].join("|")+")?$","i"),o=1e3,i=60*o,s=60*i,c=24*s,a=7*c,u=365*c;t.exports=function(e){var t,n,f=typeof e;if("number"===f)return e;if("string"!==f||"0"===e||!e)return 0;if(+e)return+e;if(e.length>1e4||!(n=r.exec(e)))return 0;switch(t=parseFloat(n[1]),n[2].toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return t*u;case"weeks":case"week":case"wks":case"wk":case"w":return t*a;case"days":case"day":case"d":return t*c;case"hours":case"hour":case"hrs":case"hr":case"h":return t*s;case"minutes":case"minute":case"mins":case"min":case"m":return t*i;case"seconds":case"second":case"secs":case"sec":case"s":return t*o;default:return t}}},{}],5:[function(e,t,n){"use strict";t.exports=function(e){function t(){return r?n:(r=1,n=e.apply(this,arguments),e=null,n)}var n,r=0;return t.displayName=e.displayName||e.name||t.displayName||t.name,t}},{}],6:[function(e,t,n){"use strict";function r(e){for(var t,n=/([^=?&]+)=([^&]*)/g,r={};t=n.exec(e);r[decodeURIComponent(t[1])]=decodeURIComponent(t[2]));return r}function o(e,t){t=t||"";var n=[];"string"!=typeof t&&(t="?");for(var r in e)i.call(e,r)&&n.push(encodeURIComponent(r)+"="+encodeURIComponent(e[r]));return n.length?t+n.join("&"):""}var i=Object.prototype.hasOwnProperty;n.stringify=o,n.parse=r},{}],7:[function(e,t,n){"use strict";function r(e,t,n){return s(e in n?n[e]:e in t?t[e]:o[e])}function o(e){var t=this;return t instanceof o?(e=e||{},t.attempt=null,t._fn=null,t["reconnect timeout"]=r("reconnect timeout",t,e),t.retries=r("retries",t,e),t.factor=r("factor",t,e),t.max=r("max",t,e),t.min=r("min",t,e),void(t.timers=new a(t))):new o(e)}var i=e("eventemitter3"),s=e("millisecond"),c=e("demolish"),a=e("tick-tock"),u=e("one-time");o.prototype=new i,o.prototype.constructor=o,o["reconnect timeout"]="30 seconds",o.max=1/0,o.min="500 ms",o.retries=10,o.factor=2,o.prototype.reconnect=function(){var e=this;return e.backoff(function(t,n){return n.duration=+new Date-n.start,t?e.emit("reconnect failed",t,n):void e.emit("reconnected",n)},e.attempt)},o.prototype.backoff=function(e,t){var n=this;return t=t||n.attempt||{},t.backoff?n:(t["reconnect timeout"]=r("reconnect timeout",n,t),t.retries=r("retries",n,t),t.factor=r("factor",n,t),t.max=r("max",n,t),t.min=r("min",n,t),t.start=+t.start||+new Date,t.duration=+t.duration||0,t.attempt=+t.attempt||0,t.attempt===t.retries?(e.call(n,new Error("Unable to recover"),t),n):(t.backoff=!0,t.attempt++,n.attempt=t,t.scheduled=1!==t.attempt?Math.min(Math.round((Math.random()+1)*t.min*Math.pow(t.factor,t.attempt-1)),t.max):t.min,n.timers.setTimeout("reconnect",function(){t.duration=+new Date-t.start,t.backoff=!1,n.timers.clear("reconnect, timeout");var r=n._fn=u(function(r){return n.reset(),r?n.backoff(e,t):void e.call(n,void 0,t)});n.emit("reconnect",t,r),n.timers.setTimeout("timeout",function(){var e=new Error("Failed to reconnect in a timely manner");t.duration=+new Date-t.start,n.emit("reconnect timeout",e,t),r(e)},t["reconnect timeout"])},t.scheduled),n.emit("reconnect scheduled",t),n))},o.prototype.reconnecting=function(){return!!this.attempt},o.prototype.reconnected=function(e){return this._fn&&this._fn(e),this},o.prototype.reset=function(){return this._fn=this.attempt=null,this.timers.clear("reconnect, timeout"),this},o.prototype.destroy=c("timers attempt _fn"),t.exports=o},{demolish:1,eventemitter3:8,millisecond:4,"one-time":5,"tick-tock":10}],8:[function(e,t,n){"use strict";function r(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function o(){}var i="function"!=typeof Object.create&&"~";o.prototype._events=void 0,o.prototype.listeners=function(e,t){var n=i?i+e:e,r=this._events&&this._events[n];if(t)return!!r;if(!r)return[];if(r.fn)return[r.fn];for(var o=0,s=r.length,c=new Array(s);o<s;o++)c[o]=r[o].fn;return c},o.prototype.emit=function(e,t,n,r,o,s){var c=i?i+e:e;if(!this._events||!this._events[c])return!1;var a,u,f=this._events[c],p=arguments.length;if("function"==typeof f.fn){switch(f.once&&this.removeListener(e,f.fn,void 0,!0),p){case 1:return f.fn.call(f.context),!0;case 2:return f.fn.call(f.context,t),!0;case 3:return f.fn.call(f.context,t,n),!0;case 4:return f.fn.call(f.context,t,n,r),!0;case 5:return f.fn.call(f.context,t,n,r,o),!0;case 6:return f.fn.call(f.context,t,n,r,o,s),!0}for(u=1,a=new Array(p-1);u<p;u++)a[u-1]=arguments[u];f.fn.apply(f.context,a)}else{var l,h=f.length;for(u=0;u<h;u++)switch(f[u].once&&this.removeListener(e,f[u].fn,void 0,!0),p){case 1:f[u].fn.call(f[u].context);break;case 2:f[u].fn.call(f[u].context,t);break;case 3:f[u].fn.call(f[u].context,t,n);break;default:if(!a)for(l=1,a=new Array(p-1);l<p;l++)a[l-1]=arguments[l];f[u].fn.apply(f[u].context,a)}}return!0},o.prototype.on=function(e,t,n){var o=new r(t,n||this),s=i?i+e:e;return this._events||(this._events=i?{}:Object.create(null)),this._events[s]?this._events[s].fn?this._events[s]=[this._events[s],o]:this._events[s].push(o):this._events[s]=o,this},o.prototype.once=function(e,t,n){var o=new r(t,n||this,(!0)),s=i?i+e:e;return this._events||(this._events=i?{}:Object.create(null)),this._events[s]?this._events[s].fn?this._events[s]=[this._events[s],o]:this._events[s].push(o):this._events[s]=o,this},o.prototype.removeListener=function(e,t,n,r){var o=i?i+e:e;if(!this._events||!this._events[o])return this;var s=this._events[o],c=[];if(t)if(s.fn)(s.fn!==t||r&&!s.once||n&&s.context!==n)&&c.push(s);else for(var a=0,u=s.length;a<u;a++)(s[a].fn!==t||r&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);return c.length?this._events[o]=1===c.length?c[0]:c:delete this._events[o],this},o.prototype.removeAllListeners=function(e){return this._events?(e?delete this._events[i?i+e:e]:this._events=i?{}:Object.create(null),this):this},o.prototype.off=o.prototype.removeListener,o.prototype.addListener=o.prototype.on,o.prototype.setMaxListeners=function(){return this},o.prefixed=i,"undefined"!=typeof t&&(t.exports=o)},{}],9:[function(e,t,n){"use strict";t.exports=function(e,t){if(t=t.split(":")[0],e=+e,!e)return!1;switch(t){case"http":case"ws":return 80!==e;case"https":case"wss":return 443!==e;case"ftp":return 21!==e;case"gopher":return 70!==e;case"file":return!1}return 0!==e}},{}],10:[function(e,t,n){"use strict";function r(e,t,n,r){this.start=+new Date,this.duration=n,this.clear=t,this.timer=e,this.fns=[r]}function o(e){clearTimeout(e)}function i(e){clearInterval(e)}function s(e){clearImmediate(e)}function c(e){return this instanceof c?(this.timers={},void(this.context=e||this)):new c(e)}var a=Object.prototype.hasOwnProperty,u=e("millisecond");r.prototype.remaining=function(){return this.duration-this.taken()},r.prototype.taken=function(){return+new Date-this.start},c.prototype.tock=function(e,t){var n=this;return function(){if(e in n.timers){var r=n.timers[e],o=r.fns.slice(),i=o.length,s=0;for(t?n.clear(e):n.start=+new Date;s<i;s++)o[s].call(n.context)}}},c.prototype.setTimeout=function(e,t,n){var i,s=this;return s.timers[e]?(s.timers[e].fns.push(t),s):(i=u(n),s.timers[e]=new r(setTimeout(s.tock(e,!0),u(n)),o,i,t),s)},c.prototype.setInterval=function(e,t,n){var o,s=this;return s.timers[e]?(s.timers[e].fns.push(t),s):(o=u(n),s.timers[e]=new r(setInterval(s.tock(e),u(n)),i,o,t),s)},c.prototype.setImmediate=function(e,t){var n=this;return"function"!=typeof setImmediate?n.setTimeout(e,t,0):n.timers[e]?(n.timers[e].fns.push(t),n):(n.timers[e]=new r(setImmediate(n.tock(e,!0)),s,0,t),n)},c.prototype.active=function(e){return e in this.timers},c.prototype.clear=function(){var e,t,n,r=arguments.length?arguments:[],o=this;if(1===r.length&&"string"==typeof r[0]&&(r=r[0].split(/[, ]+/)),!r.length)for(e in o.timers)a.call(o.timers,e)&&r.push(e);for(t=0,n=r.length;t<n;t++)e=o.timers[r[t]],e&&(e.clear(e.timer),e.fns=e.timer=e.clear=null,delete o.timers[r[t]]);return o},c.prototype.adjust=function(e,t){var n,r=this,o=u(t),s=r.timers[e];return s?(n=s.clear===i,s.clear(s.timer),s.start=+new Date,s.duration=o,s.timer=(n?setInterval:setTimeout)(r.tock(e,!n),o),r):r},c.prototype.end=c.prototype.destroy=function(){return!!this.context&&(this.clear(),this.context=this.timers=null,!0)},c.Timer=r,t.exports=c},{millisecond:4}],11:[function(e,t,n){"use strict";function r(e){var t=u.exec(e);return{protocol:t[1]?t[1].toLowerCase():"",slashes:!!t[2],rest:t[3]?t[3]:""}}function o(e,t,n){if(!(this instanceof o))return new o(e,t,n);var u,p,l,h,d=a.test(e),m=typeof t,y=this,v=0;"object"!==m&&"string"!==m&&(n=t,t=null),n&&"function"!=typeof n&&(n=c.parse),t=s(t);var g=r(e);for(y.protocol=g.protocol||t.protocol||"",y.slashes=g.slashes||t.slashes,e=g.rest;v<f.length;v++)p=f[v],u=p[0],h=p[1],u!==u?y[h]=e:"string"==typeof u?~(l=e.indexOf(u))&&("number"==typeof p[2]?(y[h]=e.slice(0,l),e=e.slice(l+p[2])):(y[h]=e.slice(l),e=e.slice(0,l))):(l=u.exec(e))&&(y[h]=l[1],e=e.slice(0,e.length-l[0].length)),y[h]=y[h]||(p[3]||"port"===h&&d?t[h]||"":""),p[4]&&(y[h]=y[h].toLowerCase());n&&(y.query=n(y.query)),i(y.port,y.protocol)||(y.host=y.hostname,y.port=""),y.username=y.password="",y.auth&&(p=y.auth.split(":"),y.username=p[0]||"",y.password=p[1]||""),y.href=y.toString()}var i=e("requires-port"),s=e("./lolcation"),c=e("querystringify"),a=/^\/(?!\/)/,u=/^([a-z0-9.+-]+:)?(\/\/)?(.*)$/i,f=[["#","hash"],["?","query"],["/","pathname"],["@","auth",1],[NaN,"host",void 0,1,1],[/\:(\d+)$/,"port"],[NaN,"hostname",void 0,1,1]];o.prototype.set=function(e,t,n){var r=this;return"query"===e?("string"==typeof t&&t.length&&(t=(n||c.parse)(t)),r[e]=t):"port"===e?(r[e]=t,i(t,r.protocol)?t&&(r.host=r.hostname+":"+t):(r.host=r.hostname,r[e]="")):"hostname"===e?(r[e]=t,r.port&&(t+=":"+r.port),r.host=t):"host"===e?(r[e]=t,/\:\d+/.test(t)&&(t=t.split(":"),r.hostname=t[0],r.port=t[1])):"protocol"===e?(r.protocol=t,r.slashes=!n):r[e]=t,r.href=r.toString(),r},o.prototype.toString=function(e){e&&"function"==typeof e||(e=c.stringify);var t,n=this,r=n.protocol;r&&":"!==r.charAt(r.length-1)&&(r+=":");var o=r+(n.slashes?"//":"");return n.username&&(o+=n.username,n.password&&(o+=":"+n.password),o+="@"),o+=n.hostname,n.port&&(o+=":"+n.port),o+=n.pathname,t="object"==typeof n.query?e(n.query):n.query,t&&(o+="?"!==t.charAt(0)?"?"+t:t),n.hash&&(o+=n.hash),o},o.qs=c,o.location=s,t.exports=o},{"./lolcation":12,querystringify:6,"requires-port":9}],12:[function(e,t,n){(function(n){"use strict";var r,o=/^[A-Za-z][A-Za-z0-9+-.]*:\/\//,i={hash:1,query:1};t.exports=function(t){t=t||n.location||{},r=r||e("./");var s,c={},a=typeof t;if("blob:"===t.protocol)c=new r(unescape(t.pathname),{});else if("string"===a){c=new r(t,{});for(s in i)delete c[s]}else if("object"===a){for(s in t)s in i||(c[s]=t[s]);void 0===c.slashes&&(c.slashes=o.test(t.href))}return c}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./":11}],13:[function(e,t,n){"use strict";function r(e){var t="";do t=c[e%a]+t,e=Math.floor(e/a);while(e>0);return t}function o(e){var t=0;for(p=0;p<e.length;p++)t=t*a+u[e.charAt(p)];return t}function i(){var e=r(+new Date);return e!==s?(f=0,s=e):e+"."+r(f++)}for(var s,c="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),a=64,u={},f=0,p=0;p<a;p++)u[c[p]]=p;i.encode=r,i.decode=o,t.exports=i},{}],14:[function(t,n,r){"use strict";function o(e,t){if(!(e instanceof i)){var n=new Error("Primus#"+t+"'s context should called with a Primus instance");if("function"!=typeof e.listeners||!e.listeners("error").length)throw n;e.emit("error",n)}}function i(e,t){if(!(this instanceof i))return new i(e,t);if("function"!=typeof this.client){var n="The client library has not been compiled correctly, see https://github.com/primus/primus#client-library for more details";return this.critical(new Error(n))}"object"==typeof e?(t=e,e=t.url||t.uri||s):t=t||{};var r=this;t.queueSize="queueSize"in t?t.queueSize:1/0,t.timeout="timeout"in t?t.timeout:1e4,t.reconnect="reconnect"in t?t.reconnect:{},t.ping="ping"in t?t.ping:25e3,t.pong="pong"in t?t.pong:1e4,t.strategy="strategy"in t?t.strategy:[],t.transport="transport"in t?t.transport:{},r.buffer=[],r.writable=!0,r.readable=!0,r.url=r.parse(e||s),r.readyState=i.CLOSED,r.options=t,r.timers=new a(this),r.socket=null,r.latency=0,r.disconnect=!1,r.transport=t.transport,r.transformers={outgoing:[],incoming:[]},r.recovery=new u(t.reconnect),"string"==typeof t.strategy&&(t.strategy=t.strategy.split(/\s?\,\s?/g)),!1===t.strategy?t.strategy=[]:t.strategy.length||(t.strategy.push("disconnect","online"),this.authorization||t.strategy.push("timeout")),t.strategy=t.strategy.join(",").toLowerCase(),"websockets"in t&&(r.AVOID_WEBSOCKETS=!t.websockets),"network"in t&&(r.NETWORK_EVENTS=t.network),t.manual||r.timers.setTimeout("open",function(){r.timers.clear("open"),r.open()},0),r.initialise(t)}var s,c=t("eventemitter3"),a=t("tick-tock"),u=t("recovery"),f=t("querystringify"),p=t("demolish"),l=t("yeast"),h=/\u2028/g,d=/\u2029/g;try{s=location.origin?location.origin:location.protocol+"//"+location.host}catch(m){s="http://127.0.0.1"}i.requires=i.require=function(n){if("function"==typeof t)return"function"==typeof e&&e.amd?void 0:t(n)};var y;try{i.Stream=y=i.requires("stream"),i.requires("util").inherits(i,y)}catch(m){i.Stream=c,i.prototype=new c}i.OPENING=1,i.CLOSED=2,i.OPEN=3,i.prototype.AVOID_WEBSOCKETS=!1,i.prototype.NETWORK_EVENTS=!1,i.prototype.online=!0;try{(i.prototype.NETWORK_EVENTS="onLine"in navigator&&(window.addEventListener||document.body.attachEvent))&&(navigator.onLine||(i.prototype.online=!1))}catch(m){}if(i.prototype.ark={},i.prototype.emits=t("emits"),i.prototype.plugin=function(e){if(o(this,"plugin"),e)return this.ark[e];var t={};for(e in this.ark)t[e]=this.ark[e];return t},i.prototype.reserved=function(e){return/^(incoming|outgoing)::/.test(e)||e in this.reserved.events},i.prototype.reserved.events={"reconnect scheduled":1,"reconnect timeout":1,readyStateChange:1,"reconnect failed":1,reconnected:1,reconnect:1,offline:1,timeout:1,online:1,error:1,close:1,open:1,data:1,end:1},i.prototype.initialise=function(e){var t,n=this;n.recovery.on("reconnected",n.emits("reconnected")).on("reconnect failed",n.emits("reconnect failed",function(e){n.emit("end"),e()})).on("reconnect timeout",n.emits("reconnect timeout")).on("reconnect scheduled",n.emits("reconnect scheduled")).on("reconnect",n.emits("reconnect",function(e){n.emit("outgoing::reconnect"),e()})),n.on("outgoing::open",function(){var e=n.readyState;n.readyState=i.OPENING,e!==n.readyState&&n.emit("readyStateChange","opening"),t=+new Date}),n.on("incoming::open",function(){var e=n.readyState;if(n.recovery.reconnecting()&&n.recovery.reconnected(),n.writable=!0,n.readable=!0,n.online||(n.online=!0,n.emit("online")),n.readyState=i.OPEN,e!==n.readyState&&n.emit("readyStateChange","open"),n.latency=+new Date-t,n.timers.clear("ping","pong"),n.heartbeat(),n.buffer.length){var r=n.buffer.slice(),o=r.length,s=0;for(n.buffer.length=0;s<o;s++)n._write(r[s])}n.emit("open")}),n.on("incoming::pong",function(e){n.online=!0,n.timers.clear("pong"),n.heartbeat(),n.latency=+new Date-e}),n.on("incoming::error",function(e){var t=n.timers.active("connect"),r=e;if("string"==typeof e)r=new Error(e);else if(!(e instanceof Error)&&"object"==typeof e){r=new Error(e.message||e.reason);for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return n.recovery.reconnecting()?n.recovery.reconnected(r):(n.listeners("error").length&&n.emit("error",r),void(t&&(~n.options.strategy.indexOf("timeout")?n.recovery.reconnect():n.end())))}),n.on("incoming::data",function(e){n.decoder(e,function(t,r){return t?n.listeners("error").length&&n.emit("error",t):void(n.protocol(r)||n.transforms(n,n,"incoming",r,e))})}),n.on("incoming::end",function(){var e=n.readyState;return n.disconnect?(n.disconnect=!1,n.end()):(n.readyState=i.CLOSED,e!==n.readyState&&n.emit("readyStateChange","end"),n.timers.active("connect")&&n.end(),e!==i.OPEN?!!n.recovery.reconnecting()&&n.recovery.reconnect():(this.writable=!1,this.readable=!1,this.timers.clear(),n.emit("close"),~n.options.strategy.indexOf("disconnect")?n.recovery.reconnect():(n.emit("outgoing::end"),void n.emit("end"))))}),n.client();for(var r in n.ark)n.ark[r].call(n,n,e);return n.NETWORK_EVENTS?(n.offlineHandler=function(){n.online&&(n.online=!1,n.emit("offline"),n.end(),n.recovery.reset())},n.onlineHandler=function(){n.online||(n.online=!0,n.emit("online"),~n.options.strategy.indexOf("online")&&n.recovery.reconnect())},window.addEventListener?(window.addEventListener("offline",n.offlineHandler,!1),window.addEventListener("online",n.onlineHandler,!1)):document.body.attachEvent&&(document.body.attachEvent("onoffline",n.offlineHandler),document.body.attachEvent("ononline",n.onlineHandler)),n):n},i.prototype.protocol=function(e){if("string"!=typeof e||0!==e.indexOf("primus::"))return!1;var t=e.indexOf(":",8),n=e.slice(t+2);switch(e.slice(8,t)){case"pong":this.emit("incoming::pong",+n);break;case"server":"close"===n&&(this.disconnect=!0);break;case"id":this.emit("incoming::id",n);break;default:return!1}return!0},i.prototype.transforms=function(e,t,n,r,o){var i={data:r},s=e.transformers[n];return function c(e,n){var r=s[e++];if(!r)return n();if(1===r.length){if(!1===r.call(t,i))return;return c(e,n)}r.call(t,i,function(r,o){return r?t.emit("error",r):void(!1!==o&&c(e,n))})}(0,function(){return"incoming"===n?t.emit("data",i.data,o):void t._write(i.data)}),this},i.prototype.id=function(e){return this.socket&&this.socket.id?e(this.socket.id):(this._write("primus::id::"),this.once("incoming::id",e))},i.prototype.open=function(){return o(this,"open"),!this.recovery.reconnecting()&&this.options.timeout&&this.timeout(),this.emit("outgoing::open"),this},i.prototype.write=function(e){return o(this,"write"),this.transforms(this,this,"outgoing",e),!0},i.prototype._write=function(e){var t=this;return i.OPEN!==t.readyState?(this.buffer.length===this.options.queueSize&&this.buffer.splice(0,1),this.buffer.push(e),!1):(t.encoder(e,function(e,n){return e?t.listeners("error").length&&t.emit("error",e):("string"==typeof n&&(~n.indexOf("\u2028")&&(n=n.replace(h,"\\u2028")),~n.indexOf("\u2029")&&(n=n.replace(d,"\\u2029"))),void t.emit("outgoing::data",n))}),!0)},i.prototype.heartbeat=function(){function e(){n.timers.clear("pong"),n.online&&(n.online=!1,n.emit("offline"),n.emit("incoming::end"))}function t(){var t=+new Date;n.timers.clear("ping"),n._write("primus::ping::"+t),n.emit("outgoing::ping",t),n.timers.setTimeout("pong",e,n.options.pong)}var n=this;return n.options.ping?(n.timers.setTimeout("ping",t,n.options.ping),this):n},i.prototype.timeout=function(){function e(){t.removeListener("error",e).removeListener("open",e).removeListener("end",e).timers.clear("connect")}var t=this;return t.timers.setTimeout("connect",function(){e(),t.readyState===i.OPEN||t.recovery.reconnecting()||(t.emit("timeout"),~t.options.strategy.indexOf("timeout")?t.recovery.reconnect():t.end())},t.options.timeout),t.on("error",e).on("open",e).on("end",e)},i.prototype.end=function(e){if(o(this,"end"),this.readyState===i.CLOSED&&!this.timers.active("connect")&&!this.timers.active("open"))return this.recovery.reconnecting()&&(this.recovery.reset(),this.emit("end")),this;void 0!==e&&this.write(e),this.writable=!1,this.readable=!1;var t=this.readyState;return this.readyState=i.CLOSED,t!==this.readyState&&this.emit("readyStateChange","end"),this.timers.clear(),this.emit("outgoing::end"),this.emit("close"),this.emit("end"),this},i.prototype.destroy=p("url timers options recovery socket transport transformers",{before:"end",after:["removeAllListeners",function(){this.NETWORK_EVENTS&&(window.addEventListener?(window.removeEventListener("offline",this.offlineHandler),window.removeEventListener("online",this.onlineHandler)):document.body.attachEvent&&(document.body.detachEvent("onoffline",this.offlineHandler),document.body.detachEvent("ononline",this.onlineHandler)))}]}),i.prototype.clone=function(e){return this.merge({},e)},i.prototype.merge=function(e){for(var t,n,r=1;r<arguments.length;r++){n=arguments[r];for(t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e},i.prototype.parse=t("url-parse"),i.prototype.querystring=f.parse,i.prototype.querystringify=f.stringify,i.prototype.uri=function(e){var t=this.url,n=[],r=!1;e.query&&(r=!0),e=e||{},e.protocol="protocol"in e?e.protocol:"http:",e.query=!(!t.query||!r)&&t.query.slice(1),e.secure="secure"in e?e.secure:"https:"===t.protocol||"wss:"===t.protocol,e.auth="auth"in e?e.auth:t.auth,e.pathname="pathname"in e?e.pathname:this.pathname,e.port="port"in e?+e.port:+t.port||(e.secure?443:80),this.emit("outgoing::url",e);var o=this.querystring(e.query||"");return o._primuscb=l(),e.query=this.querystringify(o),n.push(e.secure?e.protocol.replace(":","s:"):e.protocol,""),n.push(e.auth?e.auth+"@"+t.host:t.host),e.pathname&&n.push(e.pathname.slice(1)),r?n[n.length-1]+="?"+e.query:delete e.query,e.object?e:n.join("/")},i.prototype.transform=function(e,t){return o(this,"transform"),e in this.transformers?(this.transformers[e].push(t),this):this.critical(new Error("Invalid transformer type"))},i.prototype.critical=function(e){if(this.listeners("error").length)return this.emit("error",e),this;throw e},i.connect=function(e,t){return new i(e,t)},i.EventEmitter=c,i.prototype.client=function(){var e,t=this,n=function(){if("undefined"!=typeof WebSocket)return WebSocket;if("undefined"!=typeof MozWebSocket)return MozWebSocket;try{return i.requires("ws")}catch(e){}}();return n?(t.on("outgoing::open",function(){t.emit("outgoing::end");try{var r="ws+unix:"===t.url.protocol?"ws+unix:":"ws:",o="ws:"===r;3===n.length?t.socket=e=new n(t.uri({protocol:r,query:o}),[],t.transport):(t.socket=e=new n(t.uri({protocol:r,query:o})),e.binaryType="arraybuffer")}catch(i){return t.emit("error",i)}e.onopen=t.emits("incoming::open"),e.onerror=t.emits("incoming::error"),e.onclose=t.emits("incoming::end"),e.onmessage=t.emits("incoming::data",function(e,t){e(void 0,t.data)})}),t.on("outgoing::data",function(r){if(e&&e.readyState===n.OPEN)try{e.send(r)}catch(o){t.emit("incoming::error",o)}}),t.on("outgoing::reconnect",function(){t.emit("outgoing::open")}),void t.on("outgoing::end",function(){e&&(e.onerror=e.onopen=e.onclose=e.onmessage=function(){},e.close(),e=null)})):t.critical(new Error("Missing required `ws` module. Please run `npm install --save ws`"))},i.prototype.authorization=!1,i.prototype.pathname="/primus",i.prototype.encoder=function(e,t){var n;try{e=JSON.stringify(e)}catch(r){n=r}t(n,e)},i.prototype.decoder=function(e,t){var n;if("string"!=typeof e)return t(n,e);try{e=JSON.parse(e)}catch(r){n=r}t(n,e)},i.prototype.version="5.2.2","undefined"!=typeof document&&"undefined"!=typeof navigator){document.addEventListener&&document.addEventListener("keydown",function(e){27===e.keyCode&&e.preventDefault&&e.preventDefault()},!1);var v=(navigator.userAgent||"").toLowerCase(),g=v.match(/.+(?:rv|it|ra|ie)[\/: ](\d+)\.(\d+)(?:\.(\d+))?/)||[],w=+[g[1],g[2]].join(".");!~v.indexOf("chrome")&&~v.indexOf("safari")&&w<534.54&&(i.prototype.AVOID_WEBSOCKETS=!0)}n.exports=i},{demolish:1,emits:2,eventemitter3:3,querystringify:6,recovery:7,"tick-tock":10,"url-parse":11,yeast:13}]},{},[14])(14);return t},[]),function(e){var t=function(e,t){var n=this;n.callbacks={},n.id=null,n.events={},n.rooms=[],n.state="disconnected",n.options=n.defaults();for(var r in e)n.options[r]=e[r];t&&(n.externalClient=!0,n.client=t)};if("undefined"==typeof Primus){var n=require("util"),r=require("events").EventEmitter;n.inherits(t,r)}else t.prototype=new Primus.EventEmitter;t.prototype.defaults=function(){return{apiPath:"/api",url:window.location.origin}},t.prototype.connect=function(e){var t=this;t.messageCount=0,t.client&&t.externalClient!==!0?(t.client.end(),t.client.removeAllListeners(),delete t.client,t.client=Primus.connect(t.options.url,t.options)):t.client&&t.externalClient===!0?(t.client.end(),t.client.open()):t.client=Primus.connect(t.options.url,t.options),t.client.on("open",function(){t.configure(function(n){t.emit("connected"),"connected"===t.state||(t.state="connected","function"==typeof e&&e(null,n))})}),t.client.on("error",function(e){t.emit("error",e)}),t.client.on("reconnect",function(){t.messageCount=0,t.emit("reconnect")}),t.client.on("reconnecting",function(){t.emit("reconnecting"),t.state="reconnecting",t.emit("disconnected")}),t.client.on("timeout",function(){t.state="timeout",t.emit("timeout")}),t.client.on("close",function(){t.messageCount=0,"disconnected"!==t.state&&(t.state="disconnected",t.emit("disconnected"))}),t.client.on("end",function(){t.messageCount=0,"disconnected"!==t.state&&(t.state="disconnected",t.emit("disconnected"))}),t.client.on("data",function(e){t.handleMessage(e)})},t.prototype.configure=function(e){var t=this;t.rooms.forEach(function(e){t.send({event:"roomAdd",room:e})}),t.detailsView(function(n){t.id=n.data.id,t.fingerprint=n.data.fingerprint,t.rooms=n.data.rooms,e(n)})},t.prototype.send=function(e,t){var n=this;n.messageCount++,"function"==typeof t&&(n.callbacks[n.messageCount]=t),n.client.write(e)},t.prototype.handleMessage=function(e){var t=this;t.emit("message",e),"response"===e.context?("function"==typeof t.callbacks[e.messageCount]&&t.callbacks[e.messageCount](e),delete t.callbacks[e.messageCount]):"user"===e.context?t.emit("say",e):"alert"===e.context?t.emit("alert",e):e.welcome&&"api"===e.context?(t.welcomeMessage=e.welcome,t.emit("welcome",e)):"api"===e.context&&t.emit("api",e)},t.prototype.action=function(e,t,n){n||"function"!=typeof t||(n=t,t=null),t||(t={}),t.action=e,"connected"!==this.state?this.actionWeb(t,n):this.actionWebSocket(t,n)},t.prototype.actionWeb=function(e,t){var n=new XMLHttpRequest;n.onreadystatechange=function(){var e;if(4===n.readyState){if(200===n.status)e=JSON.parse(n.responseText);else try{e=JSON.parse(n.responseText)}catch(r){e={error:{statusText:n.statusText,responseText:n.responseText}}}t(e)}};var r=(e.httpMethod||"POST").toUpperCase(),o=this.options.url+this.options.apiPath+"?action="+e.action;if("GET"===r)for(var i in e)~["action","httpMethod"].indexOf(i)||(o+="&"+i+"="+e[i]);n.open(r,o,!0),n.setRequestHeader("Content-Type","application/json"),n.send(JSON.stringify(e))},t.prototype.actionWebSocket=function(e,t){this.send({event:"action",params:e},t)},t.prototype.say=function(e,t,n){this.send({event:"say",room:e,message:t},n)},t.prototype.file=function(e,t){this.send({event:"file",file:e},t)},t.prototype.detailsView=function(e){this.send({event:"detailsView"},e)},t.prototype.roomView=function(e,t){this.send({event:"roomView",room:e},t)},t.prototype.roomAdd=function(e,t){var n=this;n.send({event:"roomAdd",room:e},function(e){n.configure(function(){"function"==typeof t&&t(e)})})},t.prototype.roomLeave=function(e,t){var n=this,r=n.rooms.indexOf(e);r>-1&&n.rooms.splice(r,1),this.send({event:"roomLeave",room:e},function(e){n.configure(function(){"function"==typeof t&&t(e)})})},t.prototype.documentation=function(e){this.send({event:"documentation"},e)},t.prototype.disconnect=function(){this.state="disconnected",this.client.end(),this.emit("disconnected")};var o=t;e.ActionheroClient=t,e.actionheroClient=o}("undefined"==typeof exports?window:exports);