UNPKG

injam-sdk

Version:

Javascript Client for Injam Platform

7 lines 72.6 kB
!function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=7)}([function(t,e){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(t){"object"==typeof window&&(n=window)}t.exports=n},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])===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 r(t,e){this.name="AuthTokenExpiredError",this.message=t,this.expiry=e,Error.captureStackTrace&&!k?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function o(t){this.name="AuthTokenInvalidError",this.message=t,Error.captureStackTrace&&!k?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function i(t,e){this.name="AuthTokenNotBeforeError",this.message=t,this.date=e,Error.captureStackTrace&&!k?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function s(t){this.name="AuthTokenError",this.message=t,Error.captureStackTrace&&!k?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function a(t,e){this.name="SilentMiddlewareBlockedError",this.message=t,this.type=e,Error.captureStackTrace&&!k?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function c(t){this.name="InvalidActionError",this.message=t,Error.captureStackTrace&&!k?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function u(t){this.name="InvalidArgumentsError",this.message=t,Error.captureStackTrace&&!k?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function h(t){this.name="InvalidOptionsError",this.message=t,Error.captureStackTrace&&!k?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function l(t){this.name="InvalidMessageError",this.message=t,Error.captureStackTrace&&!k?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function p(t,e){this.name="SocketProtocolError",this.message=t,this.code=e,Error.captureStackTrace&&!k?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function f(t){this.name="ServerProtocolError",this.message=t,Error.captureStackTrace&&!k?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function d(t){this.name="HTTPServerError",this.message=t,Error.captureStackTrace&&!k?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function y(t){this.name="ResourceLimitError",this.message=t,Error.captureStackTrace&&!k?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function v(t){this.name="TimeoutError",this.message=t,Error.captureStackTrace&&!k?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function g(t,e){this.name="BadConnectionError",this.message=t,this.type=e,Error.captureStackTrace&&!k?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function m(t){this.name="BrokerError",this.message=t,Error.captureStackTrace&&!k?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function b(t,e){this.name="ProcessExitError",this.message=t,this.code=e,Error.captureStackTrace&&!k?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function E(t){this.name="UnknownError",this.message=t,Error.captureStackTrace&&!k?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}var w=n(14),k=function(){return!this}();r.prototype=Object.create(Error.prototype),o.prototype=Object.create(Error.prototype),i.prototype=Object.create(Error.prototype),s.prototype=Object.create(Error.prototype),a.prototype=Object.create(Error.prototype),c.prototype=Object.create(Error.prototype),u.prototype=Object.create(Error.prototype),h.prototype=Object.create(Error.prototype),l.prototype=Object.create(Error.prototype),p.prototype=Object.create(Error.prototype),f.prototype=Object.create(Error.prototype),d.prototype=Object.create(Error.prototype),y.prototype=Object.create(Error.prototype),v.prototype=Object.create(Error.prototype),g.prototype=Object.create(Error.prototype),m.prototype=Object.create(Error.prototype),b.prototype=Object.create(Error.prototype),E.prototype=Object.create(Error.prototype),t.exports={AuthTokenExpiredError:r,AuthTokenInvalidError:o,AuthTokenNotBeforeError:i,AuthTokenError:s,SilentMiddlewareBlockedError:a,InvalidActionError:c,InvalidArgumentsError:u,InvalidOptionsError:h,InvalidMessageError:l,SocketProtocolError:p,ServerProtocolError:f,HTTPServerError:d,ResourceLimitError:y,TimeoutError:v,BadConnectionError:g,BrokerError:m,ProcessExitError:b,UnknownError:E},t.exports.socketProtocolErrorStatuses={1001:"Socket was disconnected",1002:"A WebSocket protocol error was encountered",1003:"Server terminated socket because it received invalid data",1005:"Socket closed without status code",1006:"Socket hung up",1007:"Message format was incorrect",1008:"Encountered a policy violation",1009:"Message was too big to process",1010:"Client ended the connection because the server did not comply with extension requirements",1011:"Server encountered an unexpected fatal condition",4e3:"Server ping timed out",4001:"Client pong timed out",4002:"Server failed to sign auth token",4003:"Failed to complete handshake",4004:"Client failed to save auth token",4005:"Did not receive #handshake from client before timeout",4006:"Failed to bind socket to message broker",4007:"Client connection establishment timed out"},t.exports.socketProtocolIgnoreStatuses={1e3:"Socket closed normally",1001:"Socket hung up"};var T={domain:1,domainEmitter:1,domainThrown:1};t.exports.dehydrateError=function(t,e){var n;if(t&&"object"==typeof t){n={message:t.message},e&&(n.stack=t.stack);for(var r in t)T[r]||(n[r]=t[r])}else n="function"==typeof t?"[function "+(t.name||"anonymous")+"]":t;return w(n)},t.exports.hydrateError=function(t){var e=null;if(null!=t)if("object"==typeof t){e=new Error(t.message);for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])}else e=t;return e},t.exports.decycle=w},function(t,e,n){(function(e,r){var o=n(1),i=n(13).SCChannel,s=(n(5).Response,n(15).AuthEngine),a=n(16),c=n(17).SCTransport,u=n(6),h=n(21),l=n(23),p=n(25),f=n(2),d=f.InvalidArgumentsError,y=f.InvalidMessageError,v=f.SocketProtocolError,g=f.TimeoutError,m=f.BadConnectionError,b="undefined"!=typeof window,E=function(t){var n=this;o.call(this),this.id=null,this.state=this.CLOSED,this.authState=this.UNAUTHENTICATED,this.signedAuthToken=null,this.authToken=null,this.pendingReconnect=!1,this.pendingReconnectTimeout=null,this.preparingPendingSubscriptions=!1,this.connectTimeout=t.connectTimeout,this.ackTimeout=t.ackTimeout,this.channelPrefix=t.channelPrefix||null,this.disconnectOnUnload=null==t.disconnectOnUnload||t.disconnectOnUnload,this.authTokenName=t.authTokenName,this.pingTimeout=this.ackTimeout;var r=Math.pow(2,31)-1,i=function(t){if(n[t]>r)throw new d("The "+t+" value provided exceeded the maximum amount allowed")};if(i("connectTimeout"),i("ackTimeout"),i("pingTimeout"),this._localEvents={connect:1,connectAbort:1,disconnect:1,message:1,error:1,raw:1,fail:1,kickOut:1,subscribe:1,unsubscribe:1,subscribeStateChange:1,authStateChange:1,authenticate:1,deauthenticate:1,removeAuthToken:1,subscribeRequest:1},this.connectAttempts=0,this._emitBuffer=new h,this.channels={},this.options=t,this._cid=1,this.options.callIdGenerator=function(){return n._cid++},this.options.autoReconnect){null==this.options.autoReconnectOptions&&(this.options.autoReconnectOptions={});var c=this.options.autoReconnectOptions;null==c.initialDelay&&(c.initialDelay=1e4),null==c.randomness&&(c.randomness=1e4),null==c.multiplier&&(c.multiplier=1.5),null==c.maxDelay&&(c.maxDelay=6e4)}null==this.options.subscriptionRetryOptions&&(this.options.subscriptionRetryOptions={}),this.options.authEngine?this.auth=this.options.authEngine:this.auth=new s,this.options.codecEngine?this.codec=this.options.codecEngine:this.codec=a,this.options.path=this.options.path.replace(/\/$/,"")+"/",this.options.query=t.query||{},"string"==typeof this.options.query&&(this.options.query=u.parse(this.options.query)),this.options.autoConnect&&this.connect(),this._channelEmitter=new o,b&&this.disconnectOnUnload&&e.addEventListener&&(this._unloadHandler=function(){n.disconnect()},e.addEventListener("beforeunload",this._unloadHandler,!1))};E.prototype=Object.create(o.prototype),E.CONNECTING=E.prototype.CONNECTING=c.prototype.CONNECTING,E.OPEN=E.prototype.OPEN=c.prototype.OPEN,E.CLOSED=E.prototype.CLOSED=c.prototype.CLOSED,E.AUTHENTICATED=E.prototype.AUTHENTICATED="authenticated",E.UNAUTHENTICATED=E.prototype.UNAUTHENTICATED="unauthenticated",E.PENDING=E.prototype.PENDING="pending",E.ignoreStatuses=f.socketProtocolIgnoreStatuses,E.errorStatuses=f.socketProtocolErrorStatuses,E.prototype._privateEventHandlerMap={"#publish":function(t){var e=this._undecorateChannelName(t.channel);this.isSubscribed(e,!0)&&this._channelEmitter.emit(e,t.data)},"#kickOut":function(t){var e=this._undecorateChannelName(t.channel),n=this.channels[e];n&&(o.prototype.emit.call(this,"kickOut",t.message,e),n.emit("kickOut",t.message,e),this._triggerChannelUnsubscribe(n))},"#setAuthToken":function(t,e){var n=this;if(t){var r=function(r){r?(e.error(r),n._onSCError(r)):(n._changeToAuthenticatedState(t.token),e.end())};this.auth.saveToken(this.authTokenName,t.token,{},r)}else e.error(new y("No token data provided by #setAuthToken event"))},"#removeAuthToken":function(t,e){var n=this;this.auth.removeToken(this.authTokenName,function(t,r){t?(e.error(t),n._onSCError(t)):(o.prototype.emit.call(n,"removeAuthToken",r),n._changeToUnauthenticatedStateAndClearTokens(),e.end())})},"#disconnect":function(t){this.transport.close(t.code,t.data)}},E.prototype.getState=function(){return this.state},E.prototype.getBytesReceived=function(){return this.transport.getBytesReceived()},E.prototype.deauthenticate=function(t){var e=this;this.auth.removeToken(this.authTokenName,function(n,r){n?e._onSCError(n):(o.prototype.emit.call(e,"removeAuthToken",r),e.state!=e.CLOSED&&e.emit("#removeAuthToken"),e._changeToUnauthenticatedStateAndClearTokens()),t&&t(n)})},E.prototype.connect=E.prototype.open=function(){var t=this;this.state==this.CLOSED&&(this.pendingReconnect=!1,this.pendingReconnectTimeout=null,clearTimeout(this._reconnectTimeoutRef),this.state=this.CONNECTING,o.prototype.emit.call(this,"connecting"),this.transport&&this.transport.off(),this.transport=new c(this.auth,this.codec,this.options),this.transport.on("open",function(e){t.state=t.OPEN,t._onSCOpen(e)}),this.transport.on("error",function(e){t._onSCError(e)}),this.transport.on("close",function(e,n){t.state=t.CLOSED,t._onSCClose(e,n)}),this.transport.on("openAbort",function(e,n){t.state=t.CLOSED,t._onSCClose(e,n,!0)}),this.transport.on("event",function(e,n,r){t._onSCEvent(e,n,r)}))},E.prototype.reconnect=function(){this.disconnect(),this.connect()},E.prototype.disconnect=function(t,e){if("number"!=typeof(t=t||1e3))throw new d("If specified, the code argument must be a number");this.state==this.OPEN||this.state==this.CONNECTING?this.transport.close(t,e):(this.pendingReconnect=!1,this.pendingReconnectTimeout=null,clearTimeout(this._reconnectTimeoutRef))},E.prototype.destroy=function(){this._unloadHandler&&e.removeEventListener("beforeunload",this._unloadHandler,!1),this.disconnect()},E.prototype._changeToUnauthenticatedStateAndClearTokens=function(){if(this.authState!=this.UNAUTHENTICATED){var t=this.authState;this.authState=this.UNAUTHENTICATED,this.signedAuthToken=null,this.authToken=null;var e={oldState:t,newState:this.authState};o.prototype.emit.call(this,"authStateChange",e),t==this.AUTHENTICATED&&o.prototype.emit.call(this,"deauthenticate"),o.prototype.emit.call(this,"authTokenChange",this.signedAuthToken)}},E.prototype._changeToAuthenticatedState=function(t){if(this.signedAuthToken=t,this.authToken=this._extractAuthTokenData(t),this.authState!=this.AUTHENTICATED){var e=this.authState;this.authState=this.AUTHENTICATED;var n={oldState:e,newState:this.authState,signedAuthToken:t,authToken:this.authToken};this.preparingPendingSubscriptions||this.processPendingSubscriptions(),o.prototype.emit.call(this,"authStateChange",n),o.prototype.emit.call(this,"authenticate",t)}o.prototype.emit.call(this,"authTokenChange",t)},E.prototype.decodeBase64=function(t){var n;if(void 0===r)n=e.atob?e.atob(t):l.decode(t);else{n=new r(t,"base64").toString("utf8")}return n},E.prototype.encodeBase64=function(t){var n;if(void 0===r)n=e.btoa?e.btoa(t):l.encode(t);else{n=new r(t,"utf8").toString("base64")}return n},E.prototype._extractAuthTokenData=function(t){var e=(t||"").split("."),n=e[1];if(null!=n){var r=n;try{return r=this.decodeBase64(r),JSON.parse(r)}catch(t){return r}}return null},E.prototype.getAuthToken=function(){return this.authToken},E.prototype.getSignedAuthToken=function(){return this.signedAuthToken},E.prototype.authenticate=function(t,e){var n=this;this.emit("#authenticate",t,function(r,o){o&&null!=o.isAuthenticated?o.authError&&(o.authError=f.hydrateError(o.authError)):o={isAuthenticated:n.authState,authError:null},r?("BadConnectionError"!=r.name&&"TimeoutError"!=r.name&&n._changeToUnauthenticatedStateAndClearTokens(),e&&e(r,o)):n.auth.saveToken(n.authTokenName,t,{},function(r){r&&n._onSCError(r),o.isAuthenticated?n._changeToAuthenticatedState(t):n._changeToUnauthenticatedStateAndClearTokens(),e&&e(r,o)})})},E.prototype._tryReconnect=function(t){var e,n=this,r=this.connectAttempts++,o=this.options.autoReconnectOptions;if(null==t||r>0){var i=Math.round(o.initialDelay+(o.randomness||0)*Math.random());e=Math.round(i*Math.pow(o.multiplier,r))}else e=t;e>o.maxDelay&&(e=o.maxDelay),clearTimeout(this._reconnectTimeoutRef),this.pendingReconnect=!0,this.pendingReconnectTimeout=e,this._reconnectTimeoutRef=setTimeout(function(){n.connect()},e)},E.prototype._onSCOpen=function(t){var e=this;this.preparingPendingSubscriptions=!0,t?(this.id=t.id,this.pingTimeout=t.pingTimeout,this.transport.pingTimeout=this.pingTimeout,t.isAuthenticated?this._changeToAuthenticatedState(t.authToken):this._changeToUnauthenticatedStateAndClearTokens()):this._changeToUnauthenticatedStateAndClearTokens(),this.connectAttempts=0,this.options.autoSubscribeOnConnect&&this.processPendingSubscriptions(),o.prototype.emit.call(this,"connect",t,function(){e.processPendingSubscriptions()}),this._flushEmitBuffer()},E.prototype._onSCError=function(t){var e=this;setTimeout(function(){if(e.listeners("error").length<1)throw t;o.prototype.emit.call(e,"error",t)},0)},E.prototype._suspendSubscriptions=function(){var t,e;for(var n in this.channels)this.channels.hasOwnProperty(n)&&(t=this.channels[n],e=t.state==t.SUBSCRIBED||t.state==t.PENDING?t.PENDING:t.UNSUBSCRIBED,this._triggerChannelUnsubscribe(t,e))},E.prototype._abortAllPendingEventsDueToBadConnection=function(t){for(var e,n=this._emitBuffer.head;n;){e=n.next;var r=n.data;clearTimeout(r.timeout),delete r.timeout,n.detach(),n=e;var o=r.callback;if(o){delete r.callback;var i="Event '"+r.event+"' was aborted due to a bad connection",s=new m(i,t);o.call(r,s,r)}}},E.prototype._onSCClose=function(t,e,n){var r=this;if(this.id=null,this.transport&&this.transport.off(),this.pendingReconnect=!1,this.pendingReconnectTimeout=null,clearTimeout(this._reconnectTimeoutRef),this._suspendSubscriptions(),this._abortAllPendingEventsDueToBadConnection(n?"connectAbort":"disconnect"),this.options.autoReconnect&&(4e3==t||4001==t||1005==t?this._tryReconnect(0):1e3!=t&&t<4500&&this._tryReconnect()),n?o.prototype.emit.call(r,"connectAbort",t,e):o.prototype.emit.call(r,"disconnect",t,e),!E.ignoreStatuses[t]){var i;i=e?"Socket connection failed: "+e:"Socket connection failed for unknown reasons";var s=new v(E.errorStatuses[t]||i,t);this._onSCError(s)}},E.prototype._onSCEvent=function(t,e,n){var r=this._privateEventHandlerMap[t];r?r.call(this,e,n):o.prototype.emit.call(this,t,e,function(){n&&n.callback.apply(n,arguments)})},E.prototype.decode=function(t){return this.transport.decode(t)},E.prototype.encode=function(t){return this.transport.encode(t)},E.prototype._flushEmitBuffer=function(){for(var t,e=this._emitBuffer.head;e;){t=e.next;var n=e.data;e.detach(),this.transport.emitObject(n),e=t}},E.prototype._handleEventAckTimeout=function(t,e){e&&e.detach(),delete t.timeout;var n=t.callback;if(n){delete t.callback;var r=new g("Event response for '"+t.event+"' timed out");n.call(t,r,t)}},E.prototype._emit=function(t,e,n){var r=this;this.state==this.CLOSED&&this.connect();var o={event:t,callback:n},i=new h.Item;this.options.cloneData?o.data=p(e):o.data=e,i.data=o,o.timeout=setTimeout(function(){r._handleEventAckTimeout(o,i)},this.ackTimeout),this._emitBuffer.append(i),this.state==this.OPEN&&this._flushEmitBuffer()},E.prototype.send=function(t){this.transport.send(t)},E.prototype.emit=function(t,e,n){null==this._localEvents[t]?this._emit(t,e,n):o.prototype.emit.call(this,t,e)},E.prototype.publish=function(t,e,n){var r={channel:this._decorateChannelName(t),data:e};this.emit("#publish",r,n)},E.prototype._triggerChannelSubscribe=function(t,e){var n=t.name;if(t.state!=t.SUBSCRIBED){var r=t.state;t.state=t.SUBSCRIBED;var i={channel:n,oldState:r,newState:t.state,subscriptionOptions:e};t.emit("subscribeStateChange",i),t.emit("subscribe",n,e),o.prototype.emit.call(this,"subscribeStateChange",i),o.prototype.emit.call(this,"subscribe",n,e)}},E.prototype._triggerChannelSubscribeFail=function(t,e,n){var r=e.name,i=!e.waitForAuth||this.authState==this.AUTHENTICATED;e.state!=e.UNSUBSCRIBED&&i&&(e.state=e.UNSUBSCRIBED,e.emit("subscribeFail",t,r,n),o.prototype.emit.call(this,"subscribeFail",t,r,n))},E.prototype._cancelPendingSubscribeCallback=function(t){null!=t._pendingSubscriptionCid&&(this.transport.cancelPendingResponse(t._pendingSubscriptionCid),delete t._pendingSubscriptionCid)},E.prototype._decorateChannelName=function(t){return this.channelPrefix&&(t=this.channelPrefix+t),t},E.prototype._undecorateChannelName=function(t){return this.channelPrefix&&0==t.indexOf(this.channelPrefix)?t.replace(this.channelPrefix,""):t},E.prototype._trySubscribe=function(t){var e=this,n=!t.waitForAuth||this.authState==this.AUTHENTICATED;if(this.state==this.OPEN&&!this.preparingPendingSubscriptions&&null==t._pendingSubscriptionCid&&n){var r={noTimeout:!0},i={channel:this._decorateChannelName(t.name)};t.waitForAuth&&(r.waitForAuth=!0,i.waitForAuth=r.waitForAuth),t.data&&(i.data=t.data),t._pendingSubscriptionCid=this.transport.emit("#subscribe",i,r,function(n){delete t._pendingSubscriptionCid,n?e._triggerChannelSubscribeFail(n,t,i):e._triggerChannelSubscribe(t,i)}),o.prototype.emit.call(this,"subscribeRequest",t.name,i)}},E.prototype.subscribe=function(t,e){var n=this.channels[t];return n?e&&n.setOptions(e):(n=new i(t,this,e),this.channels[t]=n),n.state==n.UNSUBSCRIBED&&(n.state=n.PENDING,this._trySubscribe(n)),n},E.prototype._triggerChannelUnsubscribe=function(t,e){var n=t.name,r=t.state;if(t.state=e||t.UNSUBSCRIBED,this._cancelPendingSubscribeCallback(t),r==t.SUBSCRIBED){var i={channel:n,oldState:r,newState:t.state};t.emit("subscribeStateChange",i),t.emit("unsubscribe",n),o.prototype.emit.call(this,"subscribeStateChange",i),o.prototype.emit.call(this,"unsubscribe",n)}},E.prototype._tryUnsubscribe=function(t){if(this.state==this.OPEN){var e={noTimeout:!0};this._cancelPendingSubscribeCallback(t);var n=this._decorateChannelName(t.name);this.transport.emit("#unsubscribe",n,e)}},E.prototype.unsubscribe=function(t){var e=this.channels[t];e&&e.state!=e.UNSUBSCRIBED&&(this._triggerChannelUnsubscribe(e),this._tryUnsubscribe(e))},E.prototype.channel=function(t,e){var n=this.channels[t];return n||(n=new i(t,this,e),this.channels[t]=n),n},E.prototype.destroyChannel=function(t){var e=this.channels[t];e.unwatch(),e.unsubscribe(),delete this.channels[t]},E.prototype.subscriptions=function(t){var e,n=[];for(var r in this.channels)this.channels.hasOwnProperty(r)&&(e=this.channels[r],(t?e&&(e.state==e.SUBSCRIBED||e.state==e.PENDING):e&&e.state==e.SUBSCRIBED)&&n.push(r));return n},E.prototype.isSubscribed=function(t,e){var n=this.channels[t];return e?!!n&&(n.state==n.SUBSCRIBED||n.state==n.PENDING):!!n&&n.state==n.SUBSCRIBED},E.prototype.processPendingSubscriptions=function(){var t=this;this.preparingPendingSubscriptions=!1;var e=[];for(var n in this.channels)if(this.channels.hasOwnProperty(n)){var r=this.channels[n];r.state==r.PENDING&&e.push(r)}e.sort(function(t,e){var n=t.priority||0,r=e.priority||0;return n>r?-1:n<r?1:0}),e.forEach(function(e){t._trySubscribe(e)})},E.prototype.watch=function(t,e){if("function"!=typeof e)throw new d("No handler function was provided");this._channelEmitter.on(t,e)},E.prototype.unwatch=function(t,e){e?this._channelEmitter.removeListener(t,e):this._channelEmitter.removeAllListeners(t)},E.prototype.watchers=function(t){return this._channelEmitter.listeners(t)},t.exports=E}).call(e,n(0),n(4).Buffer)},function(t,e,n){"use strict";(function(t){function r(){return i.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function o(t,e){if(r()<e)throw new RangeError("Invalid typed array length");return i.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e),t.__proto__=i.prototype):(null===t&&(t=new i(e)),t.length=e),t}function i(t,e,n){if(!(i.TYPED_ARRAY_SUPPORT||this instanceof i))return new i(t,e,n);if("number"==typeof t){if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return u(this,t)}return s(this,t,e,n)}function s(t,e,n,r){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?p(t,e,n,r):"string"==typeof e?h(t,e,n):f(t,e)}function a(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function c(t,e,n,r){return a(e),e<=0?o(t,e):void 0!==n?"string"==typeof r?o(t,e).fill(n,r):o(t,e).fill(n):o(t,e)}function u(t,e){if(a(e),t=o(t,e<0?0:0|d(e)),!i.TYPED_ARRAY_SUPPORT)for(var n=0;n<e;++n)t[n]=0;return t}function h(t,e,n){if("string"==typeof n&&""!==n||(n="utf8"),!i.isEncoding(n))throw new TypeError('"encoding" must be a valid string encoding');var r=0|v(e,n);t=o(t,r);var s=t.write(e,n);return s!==r&&(t=t.slice(0,s)),t}function l(t,e){var n=e.length<0?0:0|d(e.length);t=o(t,n);for(var r=0;r<n;r+=1)t[r]=255&e[r];return t}function p(t,e,n,r){if(e.byteLength,n<0||e.byteLength<n)throw new RangeError("'offset' is out of bounds");if(e.byteLength<n+(r||0))throw new RangeError("'length' is out of bounds");return e=void 0===n&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,n):new Uint8Array(e,n,r),i.TYPED_ARRAY_SUPPORT?(t=e,t.__proto__=i.prototype):t=l(t,e),t}function f(t,e){if(i.isBuffer(e)){var n=0|d(e.length);return t=o(t,n),0===t.length?t:(e.copy(t,0,0,n),t)}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||K(e.length)?o(t,0):l(t,e);if("Buffer"===e.type&&Z(e.data))return l(t,e.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}function d(t){if(t>=r())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+r().toString(16)+" bytes");return 0|t}function y(t){return+t!=t&&(t=0),i.alloc(+t)}function v(t,e){if(i.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var n=t.length;if(0===n)return 0;for(var r=!1;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return q(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return J(t).length;default:if(r)return q(t).length;e=(""+e).toLowerCase(),r=!0}}function g(t,e,n){var r=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if(n>>>=0,e>>>=0,n<=e)return"";for(t||(t="utf8");;)switch(t){case"hex":return N(this,e,n);case"utf8":case"utf-8":return P(this,e,n);case"ascii":return R(this,e,n);case"latin1":case"binary":return I(this,e,n);case"base64":return C(this,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return B(this,e,n);default:if(r)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),r=!0}}function m(t,e,n){var r=t[e];t[e]=t[n],t[n]=r}function b(t,e,n,r,o){if(0===t.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,isNaN(n)&&(n=o?0:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(o)return-1;n=t.length-1}else if(n<0){if(!o)return-1;n=0}if("string"==typeof e&&(e=i.from(e,r)),i.isBuffer(e))return 0===e.length?-1:E(t,e,n,r,o);if("number"==typeof e)return e&=255,i.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):E(t,[e],n,r,o);throw new TypeError("val must be string, number or Buffer")}function E(t,e,n,r,o){function i(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}var s=1,a=t.length,c=e.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(t.length<2||e.length<2)return-1;s=2,a/=2,c/=2,n/=2}var u;if(o){var h=-1;for(u=n;u<a;u++)if(i(t,u)===i(e,-1===h?0:u-h)){if(-1===h&&(h=u),u-h+1===c)return h*s}else-1!==h&&(u-=u-h),h=-1}else for(n+c>a&&(n=a-c),u=n;u>=0;u--){for(var l=!0,p=0;p<c;p++)if(i(t,u+p)!==i(e,p)){l=!1;break}if(l)return u}return-1}function w(t,e,n,r){n=Number(n)||0;var o=t.length-n;r?(r=Number(r))>o&&(r=o):r=o;var i=e.length;if(i%2!=0)throw new TypeError("Invalid hex string");r>i/2&&(r=i/2);for(var s=0;s<r;++s){var a=parseInt(e.substr(2*s,2),16);if(isNaN(a))return s;t[n+s]=a}return s}function k(t,e,n,r){return W(q(e,t.length-n),t,n,r)}function T(t,e,n,r){return W(z(e),t,n,r)}function S(t,e,n,r){return T(t,e,n,r)}function _(t,e,n,r){return W(J(e),t,n,r)}function A(t,e,n,r){return W($(e,t.length-n),t,n,r)}function C(t,e,n){return 0===e&&n===t.length?V.fromByteArray(t):V.fromByteArray(t.slice(e,n))}function P(t,e,n){n=Math.min(t.length,n);for(var r=[],o=e;o<n;){var i=t[o],s=null,a=i>239?4:i>223?3:i>191?2:1;if(o+a<=n){var c,u,h,l;switch(a){case 1:i<128&&(s=i);break;case 2:c=t[o+1],128==(192&c)&&(l=(31&i)<<6|63&c)>127&&(s=l);break;case 3:c=t[o+1],u=t[o+2],128==(192&c)&&128==(192&u)&&(l=(15&i)<<12|(63&c)<<6|63&u)>2047&&(l<55296||l>57343)&&(s=l);break;case 4:c=t[o+1],u=t[o+2],h=t[o+3],128==(192&c)&&128==(192&u)&&128==(192&h)&&(l=(15&i)<<18|(63&c)<<12|(63&u)<<6|63&h)>65535&&l<1114112&&(s=l)}}null===s?(s=65533,a=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|1023&s),r.push(s),o+=a}return O(r)}function O(t){var e=t.length;if(e<=Q)return String.fromCharCode.apply(String,t);for(var n="",r=0;r<e;)n+=String.fromCharCode.apply(String,t.slice(r,r+=Q));return n}function R(t,e,n){var r="";n=Math.min(t.length,n);for(var o=e;o<n;++o)r+=String.fromCharCode(127&t[o]);return r}function I(t,e,n){var r="";n=Math.min(t.length,n);for(var o=e;o<n;++o)r+=String.fromCharCode(t[o]);return r}function N(t,e,n){var r=t.length;(!e||e<0)&&(e=0),(!n||n<0||n>r)&&(n=r);for(var o="",i=e;i<n;++i)o+=H(t[i]);return o}function B(t,e,n){for(var r=t.slice(e,n),o="",i=0;i<r.length;i+=2)o+=String.fromCharCode(r[i]+256*r[i+1]);return o}function x(t,e,n){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>n)throw new RangeError("Trying to access beyond buffer length")}function U(t,e,n,r,o,s){if(!i.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||e<s)throw new RangeError('"value" argument is out of bounds');if(n+r>t.length)throw new RangeError("Index out of range")}function L(t,e,n,r){e<0&&(e=65535+e+1);for(var o=0,i=Math.min(t.length-n,2);o<i;++o)t[n+o]=(e&255<<8*(r?o:1-o))>>>8*(r?o:1-o)}function D(t,e,n,r){e<0&&(e=4294967295+e+1);for(var o=0,i=Math.min(t.length-n,4);o<i;++o)t[n+o]=e>>>8*(r?o:3-o)&255}function j(t,e,n,r,o,i){if(n+r>t.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function M(t,e,n,r,o){return o||j(t,e,n,4,3.4028234663852886e38,-3.4028234663852886e38),X.write(t,e,n,r,23,4),n+4}function Y(t,e,n,r,o){return o||j(t,e,n,8,1.7976931348623157e308,-1.7976931348623157e308),X.write(t,e,n,r,52,8),n+8}function F(t){if(t=G(t).replace(tt,""),t.length<2)return"";for(;t.length%4!=0;)t+="=";return t}function G(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function H(t){return t<16?"0"+t.toString(16):t.toString(16)}function q(t,e){e=e||1/0;for(var n,r=t.length,o=null,i=[],s=0;s<r;++s){if((n=t.charCodeAt(s))>55295&&n<57344){if(!o){if(n>56319){(e-=3)>-1&&i.push(239,191,189);continue}if(s+1===r){(e-=3)>-1&&i.push(239,191,189);continue}o=n;continue}if(n<56320){(e-=3)>-1&&i.push(239,191,189),o=n;continue}n=65536+(o-55296<<10|n-56320)}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=null,n<128){if((e-=1)<0)break;i.push(n)}else if(n<2048){if((e-=2)<0)break;i.push(n>>6|192,63&n|128)}else if(n<65536){if((e-=3)<0)break;i.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return i}function z(t){for(var e=[],n=0;n<t.length;++n)e.push(255&t.charCodeAt(n));return e}function $(t,e){for(var n,r,o,i=[],s=0;s<t.length&&!((e-=2)<0);++s)n=t.charCodeAt(s),r=n>>8,o=n%256,i.push(o),i.push(r);return i}function J(t){return V.toByteArray(F(t))}function W(t,e,n,r){for(var o=0;o<r&&!(o+n>=e.length||o>=t.length);++o)e[o+n]=t[o];return o}function K(t){return t!==t}/*! * The buffer module from node.js, for the browser. * * @author Injam <info@injam.io> <https://injam.io> * @license MIT */ var V=n(10),X=n(11),Z=n(12);e.Buffer=i,e.SlowBuffer=y,e.INSPECT_MAX_BYTES=50,i.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:function(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()&&"function"==typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(t){return!1}}(),e.kMaxLength=r(),i.poolSize=8192,i._augment=function(t){return t.__proto__=i.prototype,t},i.from=function(t,e,n){return s(null,t,e,n)},i.TYPED_ARRAY_SUPPORT&&(i.prototype.__proto__=Uint8Array.prototype,i.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&i[Symbol.species]===i&&Object.defineProperty(i,Symbol.species,{value:null,configurable:!0})),i.alloc=function(t,e,n){return c(null,t,e,n)},i.allocUnsafe=function(t){return u(null,t)},i.allocUnsafeSlow=function(t){return u(null,t)},i.isBuffer=function(t){return!(null==t||!t._isBuffer)},i.compare=function(t,e){if(!i.isBuffer(t)||!i.isBuffer(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var n=t.length,r=e.length,o=0,s=Math.min(n,r);o<s;++o)if(t[o]!==e[o]){n=t[o],r=e[o];break}return n<r?-1:r<n?1:0},i.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},i.concat=function(t,e){if(!Z(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return i.alloc(0);var n;if(void 0===e)for(e=0,n=0;n<t.length;++n)e+=t[n].length;var r=i.allocUnsafe(e),o=0;for(n=0;n<t.length;++n){var s=t[n];if(!i.isBuffer(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(r,o),o+=s.length}return r},i.byteLength=v,i.prototype._isBuffer=!0,i.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)m(this,e,e+1);return this},i.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)m(this,e,e+3),m(this,e+1,e+2);return this},i.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)m(this,e,e+7),m(this,e+1,e+6),m(this,e+2,e+5),m(this,e+3,e+4);return this},i.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?P(this,0,t):g.apply(this,arguments)},i.prototype.equals=function(t){if(!i.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===i.compare(this,t)},i.prototype.inspect=function(){var t="",n=e.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,n).match(/.{2}/g).join(" "),this.length>n&&(t+=" ... ")),"<Buffer "+t+">"},i.prototype.compare=function(t,e,n,r,o){if(!i.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===n&&(n=t?t.length:0),void 0===r&&(r=0),void 0===o&&(o=this.length),e<0||n>t.length||r<0||o>this.length)throw new RangeError("out of range index");if(r>=o&&e>=n)return 0;if(r>=o)return-1;if(e>=n)return 1;if(e>>>=0,n>>>=0,r>>>=0,o>>>=0,this===t)return 0;for(var s=o-r,a=n-e,c=Math.min(s,a),u=this.slice(r,o),h=t.slice(e,n),l=0;l<c;++l)if(u[l]!==h[l]){s=u[l],a=h[l];break}return s<a?-1:a<s?1:0},i.prototype.includes=function(t,e,n){return-1!==this.indexOf(t,e,n)},i.prototype.indexOf=function(t,e,n){return b(this,t,e,n,!0)},i.prototype.lastIndexOf=function(t,e,n){return b(this,t,e,n,!1)},i.prototype.write=function(t,e,n,r){if(void 0===e)r="utf8",n=this.length,e=0;else if(void 0===n&&"string"==typeof e)r=e,n=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(n)?(n|=0,void 0===r&&(r="utf8")):(r=n,n=void 0)}var o=this.length-e;if((void 0===n||n>o)&&(n=o),t.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var i=!1;;)switch(r){case"hex":return w(this,t,e,n);case"utf8":case"utf-8":return k(this,t,e,n);case"ascii":return T(this,t,e,n);case"latin1":case"binary":return S(this,t,e,n);case"base64":return _(this,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return A(this,t,e,n);default:if(i)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),i=!0}},i.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var Q=4096;i.prototype.slice=function(t,e){var n=this.length;t=~~t,e=void 0===e?n:~~e,t<0?(t+=n)<0&&(t=0):t>n&&(t=n),e<0?(e+=n)<0&&(e=0):e>n&&(e=n),e<t&&(e=t);var r;if(i.TYPED_ARRAY_SUPPORT)r=this.subarray(t,e),r.__proto__=i.prototype;else{var o=e-t;r=new i(o,void 0);for(var s=0;s<o;++s)r[s]=this[s+t]}return r},i.prototype.readUIntLE=function(t,e,n){t|=0,e|=0,n||x(t,e,this.length);for(var r=this[t],o=1,i=0;++i<e&&(o*=256);)r+=this[t+i]*o;return r},i.prototype.readUIntBE=function(t,e,n){t|=0,e|=0,n||x(t,e,this.length);for(var r=this[t+--e],o=1;e>0&&(o*=256);)r+=this[t+--e]*o;return r},i.prototype.readUInt8=function(t,e){return e||x(t,1,this.length),this[t]},i.prototype.readUInt16LE=function(t,e){return e||x(t,2,this.length),this[t]|this[t+1]<<8},i.prototype.readUInt16BE=function(t,e){return e||x(t,2,this.length),this[t]<<8|this[t+1]},i.prototype.readUInt32LE=function(t,e){return e||x(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},i.prototype.readUInt32BE=function(t,e){return e||x(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},i.prototype.readIntLE=function(t,e,n){t|=0,e|=0,n||x(t,e,this.length);for(var r=this[t],o=1,i=0;++i<e&&(o*=256);)r+=this[t+i]*o;return o*=128,r>=o&&(r-=Math.pow(2,8*e)),r},i.prototype.readIntBE=function(t,e,n){t|=0,e|=0,n||x(t,e,this.length);for(var r=e,o=1,i=this[t+--r];r>0&&(o*=256);)i+=this[t+--r]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*e)),i},i.prototype.readInt8=function(t,e){return e||x(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},i.prototype.readInt16LE=function(t,e){e||x(t,2,this.length);var n=this[t]|this[t+1]<<8;return 32768&n?4294901760|n:n},i.prototype.readInt16BE=function(t,e){e||x(t,2,this.length);var n=this[t+1]|this[t]<<8;return 32768&n?4294901760|n:n},i.prototype.readInt32LE=function(t,e){return e||x(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},i.prototype.readInt32BE=function(t,e){return e||x(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},i.prototype.readFloatLE=function(t,e){return e||x(t,4,this.length),X.read(this,t,!0,23,4)},i.prototype.readFloatBE=function(t,e){return e||x(t,4,this.length),X.read(this,t,!1,23,4)},i.prototype.readDoubleLE=function(t,e){return e||x(t,8,this.length),X.read(this,t,!0,52,8)},i.prototype.readDoubleBE=function(t,e){return e||x(t,8,this.length),X.read(this,t,!1,52,8)},i.prototype.writeUIntLE=function(t,e,n,r){if(t=+t,e|=0,n|=0,!r){U(this,t,e,n,Math.pow(2,8*n)-1,0)}var o=1,i=0;for(this[e]=255&t;++i<n&&(o*=256);)this[e+i]=t/o&255;return e+n},i.prototype.writeUIntBE=function(t,e,n,r){if(t=+t,e|=0,n|=0,!r){U(this,t,e,n,Math.pow(2,8*n)-1,0)}var o=n-1,i=1;for(this[e+o]=255&t;--o>=0&&(i*=256);)this[e+o]=t/i&255;return e+n},i.prototype.writeUInt8=function(t,e,n){return t=+t,e|=0,n||U(this,t,e,1,255,0),i.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},i.prototype.writeUInt16LE=function(t,e,n){return t=+t,e|=0,n||U(this,t,e,2,65535,0),i.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):L(this,t,e,!0),e+2},i.prototype.writeUInt16BE=function(t,e,n){return t=+t,e|=0,n||U(this,t,e,2,65535,0),i.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):L(this,t,e,!1),e+2},i.prototype.writeUInt32LE=function(t,e,n){return t=+t,e|=0,n||U(this,t,e,4,4294967295,0),i.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):D(this,t,e,!0),e+4},i.prototype.writeUInt32BE=function(t,e,n){return t=+t,e|=0,n||U(this,t,e,4,4294967295,0),i.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):D(this,t,e,!1),e+4},i.prototype.writeIntLE=function(t,e,n,r){if(t=+t,e|=0,!r){var o=Math.pow(2,8*n-1);U(this,t,e,n,o-1,-o)}var i=0,s=1,a=0;for(this[e]=255&t;++i<n&&(s*=256);)t<0&&0===a&&0!==this[e+i-1]&&(a=1),this[e+i]=(t/s>>0)-a&255;return e+n},i.prototype.writeIntBE=function(t,e,n,r){if(t=+t,e|=0,!r){var o=Math.pow(2,8*n-1);U(this,t,e,n,o-1,-o)}var i=n-1,s=1,a=0;for(this[e+i]=255&t;--i>=0&&(s*=256);)t<0&&0===a&&0!==this[e+i+1]&&(a=1),this[e+i]=(t/s>>0)-a&255;return e+n},i.prototype.writeInt8=function(t,e,n){return t=+t,e|=0,n||U(this,t,e,1,127,-128),i.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},i.prototype.writeInt16LE=function(t,e,n){return t=+t,e|=0,n||U(this,t,e,2,32767,-32768),i.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):L(this,t,e,!0),e+2},i.prototype.writeInt16BE=function(t,e,n){return t=+t,e|=0,n||U(this,t,e,2,32767,-32768),i.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):L(this,t,e,!1),e+2},i.prototype.writeInt32LE=function(t,e,n){return t=+t,e|=0,n||U(this,t,e,4,2147483647,-2147483648),i.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):D(this,t,e,!0),e+4},i.prototype.writeInt32BE=function(t,e,n){return t=+t,e|=0,n||U(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),i.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):D(this,t,e,!1),e+4},i.prototype.writeFloatLE=function(t,e,n){return M(this,t,e,!0,n)},i.prototype.writeFloatBE=function(t,e,n){return M(this,t,e,!1,n)},i.prototype.writeDoubleLE=function(t,e,n){return Y(this,t,e,!0,n)},i.prototype.writeDoubleBE=function(t,e,n){return Y(this,t,e,!1,n)},i.prototype.copy=function(t,e,n,r){if(n||(n=0),r||0===r||(r=this.length),e>=t.length&&(e=t.length),e||(e=0),r>0&&r<n&&(r=n),r===n)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),t.length-e<r-n&&(r=t.length-e+n);var o,s=r-n;if(this===t&&n<e&&e<r)for(o=s-1;o>=0;--o)t[o+e]=this[o+n];else if(s<1e3||!i.TYPED_ARRAY_SUPPORT)for(o=0;o<s;++o)t[o+e]=this[o+n];else Uint8Array.prototype.set.call(t,this.subarray(n,n+s),e);return s},i.prototype.fill=function(t,e,n,r){if("string"==typeof t){if("string"==typeof e?(r=e,e=0,n=this.length):"string"==typeof n&&(r=n,n=this.length),1===t.length){var o=t.charCodeAt(0);o<256&&(t=o)}if(void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!i.isEncoding(r))throw new TypeError("Unknown encoding: "+r)}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<n)throw new RangeError("Out of range index");if(n<=e)return this;e>>>=0,n=void 0===n?this.length:n>>>0,t||(t=0);var s;if("number"==typeof t)for(s=e;s<n;++s)this[s]=t;else{var a=i.isBuffer(t)?t:q(new i(t,r).toString()),c=a.length;for(s=0;s<n-e;++s)this[s+e]=a[s%c]}return this};var tt=/[^+\/0-9A-Za-z-_]/g}).call(e,n(0))},function(t,e,n){var r=n(2),o=r.InvalidActionError,i=function(t,e){this.socket=t,this.id=e,this.sent=!1};i.prototype._respond=function(t){if(this.sent)throw new o("Response "+this.id+" has already been sent");this.sent=!0,this.socket.send(this.socket.encode(t))},i.prototype.end=function(t){if(this.id){var e={rid:this.id};void 0!==t&&(e.data=t),this._respond(e)}},i.prototype.error=function(t,e){if(this.id){var n=r.dehydrateError(t),o={rid:this.id,error:n};void 0!==e&&(o.data=e),this._respond(o)}},i.prototype.callback=function(t,e){t?this.error(t,e):this.end(e)},t.exports.Response=i},function(t,e,n){"use strict";e.decode=e.parse=n(18),e.encode=e.stringify=n(19)},function(t,e,n){"use strict";(function(t){function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function o(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}var i=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),s=n(8),a=n(9),c=n(27).EventEmitter;t.Injam=function(n){function c(t){e(this,c);var n=r(this,(c.__proto__||Object.getPrototypeOf(c)).call(this,t));return n.credentials=t,n}return o(c,n),i(c,[{key:"connect",value:function(){var e=this;t.Socket=a.connect({hostname:s.host,secure:s.secure,port:s.port,path:s.path,authTokenName:"Injam.authToken"}),t.batchPositions=[],Socket.on("connecting",function(){e.emit("connecting")}).on("connect",function(t){e.emit("connected"),t.isAuthenticated||(e.emit("unauthorized"),e.credentials.package_name=e.getPackageName(),Socket.emit("login",e.credentials,function(t){}))}).on("toSubscribe",function(t){e.subscribe(t)}).on("subscribe",function(t){e.emit("subscribed",t)}).on("subscribeFail",function(t){e.emit("subscribeFail",t)}).on("unsubscribe",function(t){e.emit("unsubscribed",t)}).on("authenticate",function(t){e.emit("authenticated")}).on("deauthenticate",function(){e.emit("unauthorized"),Socket.emit("login",e.credentials,function(t){})}).on("disconnect",function(t){e.emit("disconnected")}).on("connectAbort",function(t){e.emit("connectionAborted")}).on("close",function(t){e.emit("closed")})}},{key:"watchLocation",value:function(e,n){e=void 0===e||e,n=void 0!==n&&n;var r=this,o={timeout:5e3,enableHighAccuracy:!0,maximumAge:1/0};e?(t.watchLocationInterval=setInterval(function(){t.getCurrentPosition=navigator.geolocation.getCurrentPosition(r.setBatchPositions,this.geolocationError,o)},500),t.emitNewPositionInterval=setInterval(function(){t.batchPositions.length&&(r.emit("newPosition",{coordinates:h(t.batchPositions)}),t.batchPositions=[])},5e3)):n&&n>=3e3?t.emitNewPositionInterval=setInterval(function(){t.getCurrentPosition=navigator.geolocation.getCurrentPosition(function(t){r.emit("newPosition",{lat:t.coords.latitude,lng:t.coords.longitude})},this.geolocationError,o)},n):t.watchPosition=navigator.geolocation.watchPosition(function(t){r.emit("newPosition",{lat:t.coords.latitude,lng:t.coords.longitude})},this.geolocationError,o)}},{key:"stopWatchLocation",value:function(){navigator.geolocation.clearWatch(t.watchPosition),clearInterval(t.watchLocationInterval),clearInterval(t.emitNewPositionInterval)}},{key:"updateLocation",value:function(t){Socket.emit("newPosition",t)}},{key:"subscribe",value:function(t){var e=this;Socket.subscribe(t,{waitForAuth:!0}).watch(function(n){e.watchData(t,n)})}},{key:"unsubscribe",value:function(t){Socket.unsubscribe(t)}},{key:"watch",value:function(t){Socket.watch(function(e){$this.watchData(t,e)})}},{key:"unwatch",value:function(t){Socket.unwatch(t)}},{key:"isSubscribed",value:function(t,e){e=void 0===e||e,Socket.isSubscribed(t,e)}},{key:"publish",value:function(t){Socket.publish(this.credentials.physical_id,t)}},{key:"watchData",value:function(t,e){var n=this;if(u(e)?(e=JSON.parse(e),e.channel=t):e={channel:t,data:e},e.location)if(e.location.coordinates){var r=e.location.coordinates;delete e.location.coordinates,function t(){setTimeout(function(){++o<r.length&&(e.location.lat=r[o].lat,e.location.lng=r[o].lng,n.emit("tracking",e),t())},500)}();var o=0}else n.emit("tracking",e);else n.emit("rawData",e)}},{key:"geolocationError",value:function(t){t.length>0&&console.log("Geo Error: "+JSON.stringify(t))}},{key:"setBatchPositions",value:function(e){var n={lat:e.coords.latitude,lng:e.coords.longitude};t.batchPositions.push(n),t.batchPositions.length>50&&(t.batchPositions=t.batchPositions.slice(t.batchPositions.length-50,t.batchPositions.length))}},{key:"disconnect",value:function(){Socket.destroy(),this.removeAllListeners("connecting"),this.removeAllListeners("connected"),this.removeAllListeners("authenticated"),this.removeAllListeners("unauthorized"),this.removeAllListeners("subscribed"),this.removeAllListeners("subscribeFail"),this.removeAllListeners("unsubscribed"),this.removeAllListeners("rawData"),this.removeAllListeners("tracking"),this.removeAllListeners("newPosition"),this.removeAllListeners("disconnected"),this.removeAllListeners("closed"),clearInterval(t.watchLocationInterval),clearInterval(t.emitNewPositionInterval)}},{key:"getPackageName",value:function(){return t.location&&""!=t.location.hostname?t.location.hostname:"localhost"}},{key:"clearToken",value:function(){t.localStorage.removeItem("Injam.authToken")}}]),c}(c);var u=function(t){try{JSON.parse(t)}catch(t){return!1}return!0},h=function(t,e){for(var n={},r=0,o=t.length;r<o;r++)n[t[r][e]]||(n[t[r][e]]=t[r]);var i=[];for(var s in n)i.push(n[s]);return i};Array.prototype.indexOf||(Array.prototype.indexOf=function(t,e){var n;if(null==this)throw new TypeError('"this" is null or not defined');var r=Object(this),o=r.length>>>0;if(0===o)return-1;if(n=+e||0,1/0===Math.abs(n)&&(n=0),n>=o)return-1;for(n=Math.max(0<=n?n:o-Math.abs(n),0);n<o;){if(n in r&&r[n]===t)return n;n++}return-1})}).call(e,n(0))},function(t,e){t.exports={host:"core.injam.io",port:8080,path:"/s",secure:!0}},function(t,e,n){var r=n(3),o=n(26);t.exports.SCSocketCreator=o,t.exports.SCSocket=r,t.exports.Emitter=n(1),t.exports.connect=function(t){return o.connect(t)},t.exports.destroy=function(t){return o.destroy(t)},t.exports.connections=o.connections,t.exports.version="7.0.2"},function(t,e,n){"use strict";function r(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");return"="===t[e-2]?2:"="===t[e-1]?1:0}function o(t){return 3*t.length/4-r(t)}function i(t){var e,n,o,i,s,a=t.length;i=r(t),s=new l(3*a/4-i),n=i>0?a-4:a;var c=0;for(e=0;e<n;e+=4)o=h[t.charCodeAt(e)]<<18|h[t.charCodeAt(e+1)]<<12|h[t.charCodeAt(e+2)]<<6|h[t.charCodeAt(e+3)],s[c++]=o>>16&255,s[c++]=o>>8&255,s[c++]=255&o;return 2===i?(o=h[t.charCodeAt(e)]<<2|h[t.charCodeAt(e+1)]>>4,s[c++]=255&o):1===i&&(o=h[t.charCodeAt(e)]<<10|h[t.charCodeAt(e+1)]<<4|h[t.charCodeAt(e+2)]>>2,s[c++]=o>>8&255,s[c++]=255&o),s}function s(t){return u[t>>18&63]+u[t>>12&63]+u[t>>6&63]+u[63&t]}function a(t,e,n){for(var r,o=[],i=e;i<n;i+=3)r=(t[i]<<16)+(t[i+1]<<8)+t[i+2],o.push(s(r));return o.join("")}function c(t){for(var e,n=t.length,r=n%3,o="",i=[],s=0,c=n-r;s<c;s+=16383)i.push(a(t,s,s+16383>c?c:s+16383));return 1===r?(e=t[n-1],o+=u[e>>2],o+=u[e<<4&63],o+="=="):2===r&&(e=(t[n-