1 line
22 KiB
JavaScript
1 line
22 KiB
JavaScript
!function(t,e,n){e[t]=n.call(e),"undefined"!=typeof module&&module.exports?module.exports=e[t]:"function"==typeof define&&define.amd&&define(function(){return e[t]})}("Primus",this,function(){var t,e=function n(t,e,r){function o(s,c){if(!e[s]){if(!t[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=e[s]={exports:{}};t[s][0].call(f.exports,function(e){var n=t[s][1][e];return o(n?n:e)},f,f.exports,n,t,e,r)}return e[s].exports}for(var i="function"==typeof require&&require,s=0;s<r.length;s++)o(r[s]);return o}({1:[function(t,e){"use strict";e.exports=function(t,e){function n(t,n){if(e[t]){if("string"==typeof e[t]&&(e[t]=e[t].split(r)),"function"==typeof e[t])return e[t].call(n);for(var o,i,s=0;s<e[t].length;s++)i=e[t][s],o=typeof i,"function"===o?i.call(n):"string"===o&&"function"==typeof n[i]&&n[i]()}}var r=/[, ]+/;return e=e||{},t=t||[],"string"==typeof t&&(t=t.split(r)),function(){var e,r=this,o=0;if(null===r[t[0]])return!1;for(n("before",r);o<t.length;o++)e=t[o],r[e]&&("function"==typeof r[e].destroy&&r[e].destroy(),r[e]=null);return r.emit&&r.emit("destroy"),n("after",r),!0}}},{}],2:[function(t,e){"use strict";e.exports=function(){for(var t,e=this,n=0,r=arguments.length,o=new Array(r);r>n;n++)o[n]=arguments[n];return"function"!=typeof o[o.length-1]?function(){for(var t=0,n=arguments.length,r=new Array(n);n>t;t++)r[t]=arguments[t];return e.emit.apply(e,o.concat(r))}:(t=o.pop(),function(){for(var n=0,r=arguments.length,i=new Array(r+1);r>n;n++)i[n+1]=arguments[n];return i[0]=function(t,n){return t?e.emit("error",t):(i=void 0===n?i.slice(1):null===n?[]:n,void e.emit.apply(e,o.concat(i)))},t.apply(e,i),!0})}},{}],3:[function(t,e){"use strict";function n(t,e,n){this.fn=t,this.context=e,this.once=n||!1}function r(){}r.prototype._events=void 0,r.prototype.listeners=function(t){if(!this._events||!this._events[t])return[];if(this._events[t].fn)return[this._events[t].fn];for(var e=0,n=this._events[t].length,r=new Array(n);n>e;e++)r[e]=this._events[t][e].fn;return r},r.prototype.emit=function(t,e,n,r,o,i){if(!this._events||!this._events[t])return!1;var s,c,a=this._events[t],u=arguments.length;if("function"==typeof a.fn){switch(a.once&&this.removeListener(t,a.fn,!0),u){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,e),!0;case 3:return a.fn.call(a.context,e,n),!0;case 4:return a.fn.call(a.context,e,n,r),!0;case 5:return a.fn.call(a.context,e,n,r,o),!0;case 6:return a.fn.call(a.context,e,n,r,o,i),!0}for(c=1,s=new Array(u-1);u>c;c++)s[c-1]=arguments[c];a.fn.apply(a.context,s)}else{var f,p=a.length;for(c=0;p>c;c++)switch(a[c].once&&this.removeListener(t,a[c].fn,!0),u){case 1:a[c].fn.call(a[c].context);break;case 2:a[c].fn.call(a[c].context,e);break;case 3:a[c].fn.call(a[c].context,e,n);break;default:if(!s)for(f=1,s=new Array(u-1);u>f;f++)s[f-1]=arguments[f];a[c].fn.apply(a[c].context,s)}}return!0},r.prototype.on=function(t,e,r){var o=new n(e,r||this);return this._events||(this._events={}),this._events[t]?this._events[t].fn?this._events[t]=[this._events[t],o]:this._events[t].push(o):this._events[t]=o,this},r.prototype.once=function(t,e,r){var o=new n(e,r||this,!0);return this._events||(this._events={}),this._events[t]?this._events[t].fn?this._events[t]=[this._events[t],o]:this._events[t].push(o):this._events[t]=o,this},r.prototype.removeListener=function(t,e,n){if(!this._events||!this._events[t])return this;var r=this._events[t],o=[];if(e&&(r.fn&&(r.fn!==e||n&&!r.once)&&o.push(r),!r.fn))for(var i=0,s=r.length;s>i;i++)(r[i].fn!==e||n&&!r[i].once)&&o.push(r[i]);return o.length?this._events[t]=1===o.length?o[0]:o:delete this._events[t],this},r.prototype.removeAllListeners=function(t){return this._events?(t?delete this._events[t]:this._events={},this):this},r.prototype.off=r.prototype.removeListener,r.prototype.addListener=r.prototype.on,r.prototype.setMaxListeners=function(){return this},r.EventEmitter=r,r.EventEmitter2=r,r.EventEmitter3=r,e.exports=r},{}],4:[function(t,e,n){"use strict";function r(t){for(var e,n=/([^=?&]+)=([^&]*)/g,r={};e=n.exec(t);r[decodeURIComponent(e[1])]=decodeURIComponent(e[2]));return r}function o(t,e){e=e||"";var n=[];"string"!=typeof e&&(e="?");for(var r in t)i.call(t,r)&&n.push(encodeURIComponent(r)+"="+encodeURIComponent(t[r]));return e+n.join("&")}var i=Object.prototype.hasOwnProperty;n.stringify=o,n.parse=r},{}],5:[function(t,e){"use strict";function n(t,e,n){return i(t in n?n[t]:t in e?e[t]:r[t])}function r(t){var e=this;return e instanceof r?(t=t||{},e.attempt=null,e._fn=null,e["reconnect timeout"]=n("reconnect timeout",e,t),e.retries=n("retries",e,t),e.factor=n("factor",e,t),e.max=n("max",e,t),e.min=n("min",e,t),void(e.timers=new c(e))):new r(t)}var o=t("eventemitter3"),i=t("millisecond"),s=t("demolish"),c=t("tick-tock"),a=t("one-time");r.prototype=new o,r.prototype.constructor=r,r["reconnect timeout"]="30 seconds",r.max=1/0,r.min="500 ms",r.retries=10,r.factor=2,r.prototype.reconnect=function(){var t=this;return t.backoff(function(e,n){return n.duration=+new Date-n.start,e?t.emit("reconnect failed",e,n):void t.emit("reconnected",n)},t.attempt)},r.prototype.backoff=function(t,e){var r=this;return e=e||r.attempt||{},e.backoff?r:(e["reconnect timeout"]=n("reconnect timeout",r,e),e.retries=n("retries",r,e),e.factor=n("factor",r,e),e.max=n("max",r,e),e.min=n("min",r,e),e.start=+e.start||+new Date,e.duration=+e.duration||0,e.attempt=+e.attempt||0,e.attempt===e.retries?(t.call(r,new Error("Unable to recover"),e),r):(e.backoff=!0,e.attempt++,r.attempt=e,e.scheduled=1!==e.attempt?Math.min(Math.round((Math.random()+1)*e.min*Math.pow(e.factor,e.attempt-1)),e.max):e.min,r.timers.setTimeout("reconnect",function(){e.duration=+new Date-e.start,e.backoff=!1,r.timers.clear("reconnect, timeout");var n=r._fn=a(function(n){return r.reset(),n?r.backoff(t,e):void t.call(r,void 0,e)});r.emit("reconnect",e,n),r.timers.setTimeout("timeout",function(){var t=new Error("Failed to reconnect in a timely manner");e.duration=+new Date-e.start,r.emit("reconnect timeout",t,e),n(t)},e["reconnect timeout"])},e.scheduled),r.emit("reconnect scheduled",e),r))},r.prototype.reconnecting=function(){return!!this.attempt},r.prototype.reconnected=function(t){return this._fn&&this._fn(t),this},r.prototype.reset=function(){return this._fn=this.attempt=null,this.timers.clear("reconnect, timeout"),this},r.prototype.destroy=s("timers attempt _fn"),e.exports=r},{demolish:1,eventemitter3:3,millisecond:6,"one-time":7,"tick-tock":8}],6:[function(t,e){e.exports=function(t){"use strict";if("string"!=typeof t||"0"===t||+t)return+t;var e,n=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(t),r=1e3,o=60*r,i=60*o,s=24*i;if(!n)return 0;switch(e=parseFloat(n[1]),n[2].toLowerCase()){case"days":case"day":case"d":return e*s;case"hours":case"hour":case"hrs":case"hr":case"h":return e*i;case"minutes":case"minute":case"mins":case"min":case"m":return e*o;case"seconds":case"second":case"secs":case"sec":case"s":return e*r;default:return e}}},{}],7:[function(t,e){"use strict";e.exports=function(t){var e,n=!1;return function(){return n?e:(n=!0,e=t.apply(this,arguments),t=null,e)}}},{}],8:[function(t,e){"use strict";function n(t){return this instanceof n?(this.timers={},void(this.context=t||this)):new n(t)}var r=Object.prototype.hasOwnProperty,o=t("millisecond");n.prototype.tock=function(t,e){var n=this;return function(){if(t in n.timers){var r=n.timers[t],o=r.fns.slice(),i=o.length,s=0;for(e&&n.clear(t);i>s;s++)o[s].call(n.context)}}},n.prototype.setTimeout=function(t,e,n){var r=this;return r.timers[t]?(r.timers[t].fns.push(e),r):(r.timers[t]={timer:setTimeout(r.tock(t,!0),o(n)),clear:function(t){clearTimeout(t)},fns:[e]},r)},n.prototype.setInterval=function(t,e,n){var r=this;return r.timers[t]?(r.timers[t].fns.push(e),r):(r.timers[t]={timer:setInterval(r.tock(t),o(n)),clear:function(t){clearInterval(t)},fns:[e]},r)},n.prototype.setImmediate=function(t,e){var n=this;return"function"!=typeof setImmediate?n.setTimeout(t,e,0):n.timers[t]?(n.timers[t].fns.push(e),n):(n.timers[t]={timer:setImmediate(n.tock(t,!0)),clear:function(t){clearImmediate(t)},fns:[e]},n)},n.prototype.active=function(t){return t in this.timers},n.prototype.clear=function(){var t,e,n,o=arguments.length?arguments:[],i=this;if(1===o.length&&"string"==typeof o[0]&&(o=o[0].split(/[, ]+/)),!o.length)for(t in i.timers)r.call(i.timers,t)&&o.push(t);for(e=0,n=o.length;n>e;e++)t=i.timers[o[e]],t&&(t.clear(t.timer),t.fns=t.timer=t.clear=null,delete i.timers[o[e]]);return i},n.prototype.end=n.prototype.destroy=function(){return this.context?(this.clear(),this.context=this.timers=null,!0):!1},n.prototype.adjust=function(t,e){var n,r=this,i=r.timers[t];return i?(n=i.clear===clearInterval,i.clear(i.timer),i.timer=(n?setInterval:setTimeout)(r.tock(t,!n),o(e)),r):r},e.exports=n},{millisecond:9}],9:[function(t,e,n){arguments[4][6][0].apply(n,arguments)},{dup:6}],10:[function(e,n){"use strict";function r(t,e){if(!(t instanceof o)){var n=new Error("Primus#"+e+"'s context should called with a Primus instance");if("function"!=typeof t.listeners||!t.listeners("error").length)throw n;t.emit("error",n)}}function o(t,e){if(!(this instanceof o))return new o(t,e);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 t?(e=t,t=e.url||e.uri||i):e=e||{};var r=this;e.queueSize="queueSize"in e?e.queueSize:1/0,e.timeout="timeout"in e?e.timeout:1e4,e.reconnect="reconnect"in e?e.reconnect:{},e.ping="ping"in e?e.ping:25e3,e.pong="pong"in e?e.pong:1e4,e.strategy="strategy"in e?e.strategy:[],e.transport="transport"in e?e.transport:{},r.buffer=[],r.writable=!0,r.readable=!0,r.url=r.parse(t||i),r.readyState=o.CLOSED,r.options=e,r.timers=new c(this),r.socket=null,r.latency=0,r.stamps=0,r.disconnect=!1,r.transport=e.transport,r.transformers={outgoing:[],incoming:[]},r.recovery=new a(e.reconnect),"string"==typeof e.strategy&&(e.strategy=e.strategy.split(/\s?\,\s?/g)),!1===e.strategy?e.strategy=[]:e.strategy.length||(e.strategy.push("disconnect","online"),this.authorization||e.strategy.push("timeout")),e.strategy=e.strategy.join(",").toLowerCase(),"websockets"in e&&(r.AVOID_WEBSOCKETS=!e.websockets),"network"in e&&(r.NETWORK_EVENTS=e.network),e.manual||r.timers.setTimeout("open",function(){r.timers.clear("open"),r.open()},0),r.initialise(e)}var i,s=e("eventemitter3"),c=e("tick-tock"),a=e("recovery"),u=e("querystringify"),f=e("demolish");try{i=location.origin?location.origin:location.protocol+"//"+location.hostname+(location.port?":"+location.port:"")}catch(p){i="http://127.0.0.1"}o.require=function(n){return"function"!=typeof e?void 0:"function"==typeof t&&t.amd?void 0:e(n)};var m,l;try{o.Stream=m=o.require("stream"),l=o.require("url").parse,o.require("util").inherits(o,m)}catch(p){o.Stream=s,o.prototype=new s,l=function(t){var e,n=document.createElement("a"),r={};n.href=t;for(e in n)("string"==typeof n[e]||"number"==typeof n[e])&&(r[e]=n[e]);if(r.href=encodeURI(decodeURI(r.href)),!r.port){var o=(r.href||"").split("/");if(o.length>2){var i=o[2],s=i.lastIndexOf("@");~s&&(i=i.slice(s+1)),o=i.split(":"),2===o.length&&(r.port=o[1])}}if(r.protocol&&":"!==r.protocol||(r.protocol=r.href.substr(0,r.href.indexOf(":")+1)),"0"===r.port&&(r.port=""),~r.href.indexOf("@")&&!r.auth){var c=r.protocol.length+2;r.auth=r.href.slice(c,r.href.indexOf(r.pathname,c)).split("@")[0]}return r}}o.OPENING=1,o.CLOSED=2,o.OPEN=3,o.prototype.AVOID_WEBSOCKETS=!1,o.prototype.NETWORK_EVENTS=!1,o.prototype.online=!0;try{(o.prototype.NETWORK_EVENTS="onLine"in navigator&&(window.addEventListener||document.body.attachEvent))&&(navigator.onLine||(o.prototype.online=!1))}catch(p){}if(o.prototype.ark={},o.prototype.emits=e("emits"),o.prototype.trigger=function(){for(var t=0,e=arguments.length,n=new Array(e);e>t;t++)n[t]=arguments[t];return"function"!=typeof n[e-1]&&n.push(function(t){setTimeout(t,0)}),this.emits.apply(this,n)},o.prototype.plugin=function(t){if(r(this,"plugin"),t)return this.ark[t];var e={};for(t in this.ark)e[t]=this.ark[t];return e},o.prototype.reserved=function(t){return/^(incoming|outgoing)::/.test(t)||t in this.reserved.events},o.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},o.prototype.initialise=function(t){function e(){i.online&&(i.online=!1,i.emit("offline"),i.end(),i.recovery.reset())}function n(){i.online||(i.online=!0,i.emit("online"),~i.options.strategy.indexOf("online")&&i.recovery.reconnect())}var r,i=this;i.recovery.on("reconnected",i.emits("reconnected")).on("reconnect failed",i.emits("reconnect failed",function(t){return i.emit("end"),t})).on("reconnect timeout",i.emits("reconnect timeout")).on("reconnect scheduled",i.emits("reconnect scheduled")).on("reconnect",i.emits("reconnect",function(t){i.emit("outgoing::reconnect"),t()})),i.on("outgoing::open",function(){var t=i.readyState;i.readyState=o.OPENING,t!==i.readyState&&i.emit("readyStateChange","opening"),r=+new Date}),i.on("incoming::open",function(){var t=i.readyState;if(i.recovery.reconnecting()&&i.recovery.reconnected(),i.writable=!0,i.readable=!0,i.online||(i.online=!0,i.emit("online")),i.readyState=o.OPEN,t!==i.readyState&&i.emit("readyStateChange","open"),i.latency=+new Date-r,i.timers.clear("ping","pong"),i.heartbeat(),i.buffer.length){var e=i.buffer.slice(),n=e.length,s=0;for(i.buffer.length=0;n>s;s++)i._write(e[s])}i.emit("open")}),i.on("incoming::pong",function(t){i.online=!0,i.timers.clear("pong"),i.heartbeat(),i.latency=+new Date-t}),i.on("incoming::error",function(t){var e=i.timers.active("connect"),n=t;if("string"==typeof t)n=new Error(t);else if(!(t instanceof Error)&&"object"==typeof t){n=new Error(t.message||t.reason);for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r])}return i.recovery.reconnecting()?i.recovery.reconnected(n):(i.listeners("error").length&&i.emit("error",n),void(e&&(~i.options.strategy.indexOf("timeout")?i.recovery.reconnect():i.end())))}),i.on("incoming::data",function(t){i.decoder(t,function(e,n){return e?i.listeners("error").length&&i.emit("error",e):void(i.protocol(n)||i.transforms(i,i,"incoming",n,t))})}),i.on("incoming::end",function(){var t=i.readyState;return i.disconnect?(i.disconnect=!1,i.end()):(i.readyState=o.CLOSED,t!==i.readyState&&i.emit("readyStateChange","end"),i.timers.active("connect")&&i.end(),t!==o.OPEN?i.recovery.reconnecting()?i.recovery.reconnect():!1:(this.writable=!1,this.readable=!1,this.timers.clear(),i.emit("close"),~i.options.strategy.indexOf("disconnect")?i.recovery.reconnect():(i.emit("outgoing::end"),void i.emit("end"))))}),i.client();for(var s in i.ark)i.ark[s].call(i,i,t);return i.NETWORK_EVENTS?(window.addEventListener?(window.addEventListener("offline",e,!1),window.addEventListener("online",n,!1)):document.body.attachEvent&&(document.body.attachEvent("onoffline",e),document.body.attachEvent("ononline",n)),i):i},o.prototype.protocol=function(t){if("string"!=typeof t||0!==t.indexOf("primus::"))return!1;var e=t.indexOf(":",8),n=t.slice(e+2);switch(t.slice(8,e)){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},o.prototype.transforms=function(t,e,n,r,o){var i={data:r},s=t.transformers[n];return function c(t,n){var r=s[t++];if(!r)return n();if(1===r.length){if(!1===r.call(e,i))return;return c(t,n)}r.call(e,i,function(r,o){return r?e.emit("error",r):void(!1!==o&&c(t,n))})}(0,function(){return"incoming"===n?e.emit("data",i.data,o):void e._write(i.data)}),this},o.prototype.id=function(t){return this.socket&&this.socket.id?t(this.socket.id):(this._write("primus::id::"),this.once("incoming::id",t))},o.prototype.open=function(){return r(this,"open"),!this.recovery.reconnecting()&&this.options.timeout&&this.timeout(),this.emit("outgoing::open"),this},o.prototype.write=function(t){return r(this,"write"),this.transforms(this,this,"outgoing",t),!0},o.prototype._write=function(t){var e=this;return o.OPEN!==e.readyState?(this.buffer.length===this.options.queueSize&&this.buffer.splice(0,1),this.buffer.push(t),!1):(e.encoder(t,function(t,n){return t?e.listeners("error").length&&e.emit("error",t):void e.emit("outgoing::data",n)}),!0)},o.prototype.heartbeat=function(){function t(){n.timers.clear("pong"),n.online&&(n.online=!1,n.emit("offline"),n.emit("incoming::end"))}function e(){var e=+new Date;n.timers.clear("ping"),n._write("primus::ping::"+e),n.emit("outgoing::ping",e),n.timers.setTimeout("pong",t,n.options.pong)}var n=this;return n.options.ping?(n.timers.setTimeout("ping",e,n.options.ping),this):n},o.prototype.timeout=function(){function t(){e.removeListener("error",t).removeListener("open",t).removeListener("end",t).timers.clear("connect")}var e=this;return e.timers.setTimeout("connect",function(){t(),e.readyState===o.OPEN||e.recovery.reconnecting()||(e.emit("timeout"),~e.options.strategy.indexOf("timeout")?e.recovery.reconnect():e.end())},e.options.timeout),e.on("error",t).on("open",t).on("end",t)},o.prototype.end=function(t){if(r(this,"end"),this.readyState===o.CLOSED&&!this.timers.active("connect"))return this.recovery.reconnecting()&&(this.recovery.reset(),this.emit("end")),this;void 0!==t&&this.write(t),this.writable=!1,this.readable=!1;var e=this.readyState;return this.readyState=o.CLOSED,e!==this.readyState&&this.emit("readyStateChange","end"),this.timers.clear(),this.emit("outgoing::end"),this.emit("close"),this.emit("end"),this},o.prototype.destroy=f("url timers options recovery socket transport transformers",{before:"end",after:"removeAllListeners"}),o.prototype.clone=function(t){return this.merge({},t)},o.prototype.merge=function(t){for(var e,n,r=Array.prototype.slice.call(arguments,1),o=0,i=r.length;i>o;o++){n=r[o];for(e in n)n.hasOwnProperty(e)&&(t[e]=n[e])}return t},o.prototype.parse=l,o.prototype.querystring=u.parse,o.prototype.querystringify=u.stringify,o.prototype.uri=function(t){var e=this.url,n=[],r=!1;t.query&&(r=!0),t=t||{},t.protocol="protocol"in t?t.protocol:"http",t.query=e.search&&"query"in t?"?"===e.search.charAt(0)?e.search.slice(1):e.search:!1,t.secure="secure"in t?t.secure:"https:"===e.protocol||"wss:"===e.protocol,t.auth="auth"in t?t.auth:e.auth,t.pathname="pathname"in t?t.pathname:this.pathname.slice(1),t.port="port"in t?+t.port:+e.port||(t.secure?443:80),t.host="host"in t?t.host:e.hostname||e.host.replace(":"+e.port,""),this.emit("outgoing::url",t);var o=443!==t.port&&80!==t.port?t.host+":"+t.port:t.host,i=this.querystring(t.query||"");return i._primuscb=+new Date+"-"+this.stamps++,t.query=this.querystringify(i),n.push(t.secure?t.protocol+"s:":t.protocol+":",""),n.push(t.auth?t.auth+"@"+o:o),t.pathname&&n.push(t.pathname),r?n.push("?"+t.query):delete t.query,t.object?t:n.join("/")},o.prototype.transform=function(t,e){return r(this,"transform"),t in this.transformers?(this.transformers[t].push(e),this):this.critical(new Error("Invalid transformer type"))},o.prototype.critical=function(t){if(this.listeners("error").length)return this.emit("error",t),this;throw t},o.connect=function(t,e){return new o(t,e)},o.EventEmitter=s,o.prototype.client=function(){var t,e=this,n=function(){if("undefined"!=typeof WebSocket)return WebSocket;if("undefined"!=typeof MozWebSocket)return MozWebSocket;try{return o.require("ws")}catch(t){}return void 0}();return n?(e.on("outgoing::open",function(){e.emit("outgoing::end");try{var r="ws+unix:"===e.url.protocol?"ws+unix":"ws",o="ws"===r;e.socket=t=3===n.length?new n(e.uri({protocol:r,query:o}),[],e.transport):new n(e.uri({protocol:r,query:o}))}catch(i){return e.emit("error",i)}t.binaryType="arraybuffer",t.onopen=e.trigger("incoming::open"),t.onerror=e.trigger("incoming::error"),t.onclose=e.trigger("incoming::end"),t.onmessage=e.trigger("incoming::data",function(t,e){setTimeout(function(){t(void 0,e.data)},0)})}),e.on("outgoing::data",function(r){if(t&&t.readyState===n.OPEN)try{t.send(r)}catch(o){e.emit("incoming::error",o)}}),e.on("outgoing::reconnect",function(){e.emit("outgoing::open")}),void e.on("outgoing::end",function(){t&&(t.onerror=t.onopen=t.onclose=t.onmessage=function(){},t.close(),t=null)})):e.critical(new Error("Missing required `ws` module. Please run `npm install --save ws`"))},o.prototype.authorization=!1,o.prototype.pathname="/primus",o.prototype.encoder=function(t,e){var n;try{t=JSON.stringify(t)}catch(r){n=r}e(n,t)},o.prototype.decoder=function(t,e){var n;if("string"!=typeof t)return e(n,t);try{t=JSON.parse(t)}catch(r){n=r}e(n,t)},o.prototype.version="3.0.2","object"==typeof JSON&&"function"==typeof JSON.stringify&&'["\u2028\u2029"]'===JSON.stringify(["\u2028\u2029"])&&(JSON.stringify=function(t){var e=/\u2028/g,n=/\u2029/g;return function(r,o,i){var s=t.call(this,r,o,i);return s&&(~s.indexOf("\u2028")&&(s=s.replace(e,"\\u2028")),~s.indexOf("\u2029")&&(s=s.replace(n,"\\u2029"))),s}}(JSON.stringify)),"undefined"!=typeof document&&"undefined"!=typeof navigator){document.addEventListener&&document.addEventListener("keydown",function(t){27===t.keyCode&&t.preventDefault&&t.preventDefault()},!1);var h=(navigator.userAgent||"").toLowerCase(),d=h.match(/.+(?:rv|it|ra|ie)[\/: ](\d+)\.(\d+)(?:\.(\d+))?/)||[],y=+[d[1],d[2]].join(".");!~h.indexOf("chrome")&&~h.indexOf("safari")&&534.54>y&&(o.prototype.AVOID_WEBSOCKETS=!0)}n.exports=o},{demolish:1,emits:2,eventemitter3:3,querystringify:4,recovery:5,"tick-tock":8}]},{},[10])(10);return e.prototype.ark.emit=function(t){var e=Object.prototype.toString,n=t.emit;t.transform("incoming",function(r){var o=r.data;if("object"==typeof o&&~e.call(o.emit).indexOf(" Array]"))return this.reserved(o.emit[0])||n.apply(t,o.emit),!1}),t.emit=function(e){return t.reserved(e)||"newListener"===e||"removeListener"===e?n.apply(this,arguments):(t.write({emit:Array.prototype.slice.call(arguments,0)}),!0)}},e}); |