From f67df0c793f0557f2da1a8b56460e478c396cf4a Mon Sep 17 00:00:00 2001 From: Jonathan Gros-Dubois Date: Tue, 8 Dec 2015 22:55:45 +1100 Subject: [PATCH] v3.1.1 --- bower.json | 2 +- index.js | 2 +- package.json | 2 +- socketcluster.js | 42 ++++++++++++++++++++++++++++-------------- socketcluster.min.js | 4 ++-- 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/bower.json b/bower.json index 948245c..7764440 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "socketcluster-client", "main": "socketcluster.js", - "version": "3.1.0", + "version": "3.1.1", "homepage": "https://github.com/SocketCluster/socketcluster-client", "description": "SocketCluster JavaScript client", "authors": [ diff --git a/index.js b/index.js index 3438fa9..5a909b5 100644 --- a/index.js +++ b/index.js @@ -14,4 +14,4 @@ module.exports.destroy = function (options) { return SCSocketCreator.destroy(options); }; -module.exports.version = '3.1.0'; +module.exports.version = '3.1.1'; diff --git a/package.json b/package.json index 5d9885b..2d861d2 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "socketcluster-client", "description": "SocketCluster JavaScript client", - "version": "3.1.0", + "version": "3.1.1", "homepage": "http://socketcluster.io", "contributors": [ { diff --git a/socketcluster.js b/socketcluster.js index b168ae2..248b6c3 100644 --- a/socketcluster.js +++ b/socketcluster.js @@ -15,7 +15,7 @@ module.exports.destroy = function (options) { return SCSocketCreator.destroy(options); }; -module.exports.version = '3.1.0'; +module.exports.version = '3.1.1'; },{"./lib/scsocket":5,"./lib/scsocketcreator":6,"sc-emitter":12}],2:[function(require,module,exports){ (function (global){ @@ -894,23 +894,34 @@ var SCSocket = require('./scsocket'); var _connections = {}; -function getMultiplexId(isSecure, hostname, port, path) { - var protocolPrefix = isSecure ? 'https://' : 'http://'; - return protocolPrefix + hostname + ':' + port + path; +function getMultiplexId(options) { + var protocolPrefix = options.secure ? 'https://' : 'http://'; + return protocolPrefix + options.hostname + ':' + options.port + options.path; +} + +function isUrlSecure() { + return global.location && location.protocol == 'https:'; +} + +function getPort(options, isSecureDefault) { + var isSecure = options.secure == null ? isSecureDefault : options.secure; + return options.port || (global.location && location.port ? location.port : isSecure ? 443 : 80); } function connect(options) { var self = this; + options = options || {}; - var isSecure = global.location && location.protocol == 'https:'; + var isSecureDefault = isUrlSecure(); + var opts = { - port: options.port || global.location && location.port ? location.port : isSecure ? 443 : 80, + port: getPort(options, isSecureDefault), + hostname: global.location && location.hostname, + path: '/socketcluster/', + secure: isSecureDefault, autoReconnect: true, autoProcessSubscriptions: true, ackTimeout: 10000, - hostname: global.location && location.hostname, - path: '/socketcluster/', - secure: isSecure, timestampRequests: false, timestampParam: 't', authEngine: null, @@ -923,7 +934,7 @@ function connect(options) { opts[i] = options[i]; } } - var multiplexId = getMultiplexId(isSecure, opts.hostname, opts.port, opts.path); + var multiplexId = getMultiplexId(opts); if (opts.multiplex === false) { return new SCSocket(opts); } @@ -935,19 +946,22 @@ function connect(options) { function destroy(options) { var self = this; + options = options || {}; - var isSecure = global.location && location.protocol == 'https:'; + var isSecureDefault = isUrlSecure(); + var opts = { - port: options.port || global.location && location.port ? location.port : isSecure ? 443 : 80, + port: getPort(options, isSecureDefault), hostname: global.location && location.hostname, - path: '/socketcluster/' + path: '/socketcluster/', + secure: isSecureDefault }; for (var i in options) { if (options.hasOwnProperty(i)) { opts[i] = options[i]; } } - var multiplexId = getMultiplexId(isSecure, opts.hostname, opts.port, opts.path); + var multiplexId = getMultiplexId(opts); delete _connections[multiplexId]; } diff --git a/socketcluster.min.js b/socketcluster.min.js index 88f4818..bb6d53e 100644 --- a/socketcluster.min.js +++ b/socketcluster.min.js @@ -1,3 +1,3 @@ -(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.socketCluster=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;omaxTimeout){throw new Error("The "+propertyName+" value provided exceeded the maximum amount allowed")}};verifyDuration("ackTimeout");verifyDuration("pingTimeout");this._localEvents={connect:1,connectAbort:1,disconnect:1,message:1,error:1,raw:1,fail:1,kickOut:1,subscribe:1,unsubscribe:1,authenticate:1,removeAuthToken:1,subscribeRequest:1};this._connectAttempts=0;this._emitBuffer=new LinkedList;this._channels={};this.options=opts;this._cid=1;this.options.callIdGenerator=function(){return self._callIdGenerator()};if(this.options.autoReconnect){if(this.options.autoReconnectOptions==null){this.options.autoReconnectOptions={}}var reconnectOptions=this.options.autoReconnectOptions;if(reconnectOptions.initialDelay==null){reconnectOptions.initialDelay=1e4}if(reconnectOptions.randomness==null){reconnectOptions.randomness=1e4}if(reconnectOptions.multiplier==null){reconnectOptions.multiplier=1.5}if(reconnectOptions.maxDelay==null){reconnectOptions.maxDelay=6e4}}if(this.options.subscriptionRetryOptions==null){this.options.subscriptionRetryOptions={}}if(this.options.authEngine){this.auth=this.options.authEngine}else{this.auth=new AuthEngine}this.options.path=this.options.path.replace(/\/$/,"")+"/";this.options.query=opts.query||{};if(typeof this.options.query=="string"){this.options.query=querystring.parse(this.options.query)}this.connect();this._channelEmitter=new SCEmitter;if(isBrowser){var unloadHandler=function(){self.disconnect()};if(global.attachEvent){global.attachEvent("onunload",unloadHandler)}else if(global.addEventListener){global.addEventListener("beforeunload",unloadHandler,false)}}};SCSocket.prototype=Object.create(SCEmitter.prototype);SCSocket.CONNECTING=SCSocket.prototype.CONNECTING=SCTransport.prototype.CONNECTING;SCSocket.OPEN=SCSocket.prototype.OPEN=SCTransport.prototype.OPEN;SCSocket.CLOSED=SCSocket.prototype.CLOSED=SCTransport.prototype.CLOSED;SCSocket.ignoreStatuses={1e3:"Socket closed normally",1001:"Socket hung up"};SCSocket.errorStatuses={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"};SCSocket.prototype._privateEventHandlerMap={"#fail":function(data){this._onSCError(data)},"#publish":function(data){var isSubscribed=this.isSubscribed(data.channel,true);if(isSubscribed){this._channelEmitter.emit(data.channel,data.data)}},"#kickOut":function(data){var channelName=data.channel;var channel=this._channels[channelName];if(channel){SCEmitter.prototype.emit.call(this,"kickOut",data.message,channelName);channel.emit("kickOut",data.message,channelName);this._triggerChannelUnsubscribe(channel)}},"#setAuthToken":function(data,response){var self=this;if(data){var triggerAuthenticate=function(err){if(err){response.error(err.message||err);self._onSCError(err)}else{SCEmitter.prototype.emit.call(self,"authenticate",data.token);response.end()}};this.auth.saveToken(this.options.authTokenName,data.token,{},triggerAuthenticate)}else{response.error("No token data provided by #setAuthToken event")}},"#removeAuthToken":function(data,response){var self=this;this.auth.removeToken(this.options.authTokenName,function(err){if(err){response.error(err.message||err);self._onSCError(err)}else{SCEmitter.prototype.emit.call(self,"removeAuthToken");response.end()}})},"#disconnect":function(data){this.transport.close(data.code,data.data)}};SCSocket.prototype._callIdGenerator=function(){return this._cid++};SCSocket.prototype.getState=function(){return this.state};SCSocket.prototype.getBytesReceived=function(){return this.transport.getBytesReceived()};SCSocket.prototype.removeAuthToken=function(callback){var self=this;this.auth.removeToken(this.options.authTokenName,function(err){callback&&callback(err);if(err){self._onSCError(err)}else{SCEmitter.prototype.emit.call(self,"removeAuthToken")}})};SCSocket.prototype.connect=SCSocket.prototype.open=function(){var self=this;if(this.state==this.CLOSED){clearTimeout(this._reconnectTimeout);this.state=this.CONNECTING;if(this.transport){this.transport.off()}this.transport=new SCTransport(this.auth,this.options);this.transport.on("open",function(status){self.state=self.OPEN;self._onSCOpen(status)});this.transport.on("error",function(err){self._onSCError(err)});this.transport.on("close",function(code,data){self.state=self.CLOSED;self._onSCClose(code,data)});this.transport.on("openAbort",function(code,data){self.state=self.CLOSED;self._onSCClose(code,data,true)});this.transport.on("event",function(event,data,res){self._onSCEvent(event,data,res)})}};SCSocket.prototype.reconnect=function(){this.disconnect();this.connect()};SCSocket.prototype.disconnect=function(code,data){code=code||1e3;if(this.state==this.OPEN){var packet={code:code,data:data};this.transport.emit("#disconnect",packet);this.transport.close(code)}else if(this.state==this.CONNECTING){this.transport.close(code)}};SCSocket.prototype.authenticate=function(signedAuthToken,callback){var self=this;this.emit("#authenticate",signedAuthToken,function(err,authStatus){if(err){callback&&callback(err,authStatus)}else{self.auth.saveToken(self.options.authTokenName,signedAuthToken,{},function(err){callback&&callback(err,authStatus);if(err){self._onSCError(err)}else if(authStatus.isAuthenticated){SCEmitter.prototype.emit.call(self,"authenticate",signedAuthToken)}})}})};SCSocket.prototype._tryReconnect=function(initialDelay){var self=this;var exponent=this._connectAttempts++;var reconnectOptions=this.options.autoReconnectOptions;var timeout;if(initialDelay==null||exponent>0){var initialTimeout=Math.round(reconnectOptions.initialDelay+(reconnectOptions.randomness||0)*Math.random());timeout=Math.round(initialTimeout*Math.pow(reconnectOptions.multiplier,exponent))}else{timeout=initialDelay}if(timeout>reconnectOptions.maxDelay){timeout=reconnectOptions.maxDelay}clearTimeout(this._reconnectTimeout);this._reconnectTimeout=setTimeout(function(){self.connect()},timeout)};SCSocket.prototype._onSCOpen=function(status){var self=this;if(status){this.id=status.id;this.pingTimeout=status.pingTimeout;this.transport.pingTimeout=this.pingTimeout}this._connectAttempts=0;if(this.options.autoProcessSubscriptions){this.processPendingSubscriptions()}else{this.pendingConnectCallback=true}SCEmitter.prototype.emit.call(this,"connect",status,function(){self.processPendingSubscriptions()});this._flushEmitBuffer()};SCSocket.prototype._onSCError=function(err){var self=this;setTimeout(function(){if(self.listeners("error").length<1){throw err}else{SCEmitter.prototype.emit.call(self,"error",err)}},0)};SCSocket.prototype._suspendSubscriptions=function(){var channel,newState;for(var channelName in this._channels){if(this._channels.hasOwnProperty(channelName)){channel=this._channels[channelName];if(channel.state==channel.SUBSCRIBED||channel.state==channel.PENDING){newState=channel.PENDING}else{newState=channel.UNSUBSCRIBED}this._triggerChannelUnsubscribe(channel,newState)}}};SCSocket.prototype._onSCClose=function(code,data,openAbort){var self=this;this.id=null;if(this.transport){this.transport.off()}clearTimeout(this._reconnectTimeout);this._suspendSubscriptions();if(openAbort){SCEmitter.prototype.emit.call(self,"connectAbort",code,data)}else{SCEmitter.prototype.emit.call(self,"disconnect",code,data)}if(this.options.autoReconnect){if(code==4e3||code==4001||code==1005){this._tryReconnect(0)}else if(code!=1e3){this._tryReconnect()}}if(!SCSocket.ignoreStatuses[code]){var err=new Error(SCSocket.errorStatuses[code]||"Socket connection failed for unknown reasons");err.code=code;this._onSCError(err)}};SCSocket.prototype._onSCEvent=function(event,data,res){var handler=this._privateEventHandlerMap[event];if(handler){handler.call(this,data,res)}else{SCEmitter.prototype.emit.call(this,event,data,function(){res&&res.callback.apply(res,arguments)})}};SCSocket.prototype.parse=function(message){return this.transport.parse(message)};SCSocket.prototype.stringify=function(object){return this.transport.stringify(object)};SCSocket.prototype._flushEmitBuffer=function(){var currentNode=this._emitBuffer.head;var nextNode;while(currentNode){nextNode=currentNode.next;var eventObject=currentNode.data;currentNode.detach();this.transport.emitRaw(eventObject);currentNode=nextNode}};SCSocket.prototype._handleEventAckTimeout=function(eventObject,eventNode){var errorMessage="Event response for '"+eventObject.event+"' timed out";var error=new Error(errorMessage);error.type="timeout";var callback=eventObject.callback;delete eventObject.callback;if(eventNode){eventNode.detach()}callback.call(eventObject,error,eventObject);this._onSCError(error)};SCSocket.prototype._emit=function(event,data,callback){var self=this;if(this.state==this.CLOSED){this.connect()}var eventObject={event:event,data:data,callback:callback};var eventNode=new LinkedList.Item;eventNode.data=eventObject;if(callback){eventObject.timeout=setTimeout(function(){self._handleEventAckTimeout(eventObject,eventNode)},this.ackTimeout)}this._emitBuffer.append(eventNode);if(this.state==this.OPEN){this._flushEmitBuffer()}};SCSocket.prototype.send=function(data){this.transport.send(data)};SCSocket.prototype.emit=function(event,data,callback){if(this._localEvents[event]==null){this._emit(event,data,callback)}else{SCEmitter.prototype.emit.call(this,event,data)}};SCSocket.prototype.publish=function(channelName,data,callback){var pubData={channel:channelName,data:data};this.emit("#publish",pubData,callback)};SCSocket.prototype._triggerChannelSubscribe=function(channel){var channelName=channel.name;if(channel.state!=channel.SUBSCRIBED){channel.state=channel.SUBSCRIBED;channel.emit("subscribe",channelName);SCEmitter.prototype.emit.call(this,"subscribe",channelName)}};SCSocket.prototype._triggerChannelSubscribeFail=function(err,channel){var channelName=channel.name;if(channel.state!=channel.UNSUBSCRIBED){channel.state=channel.UNSUBSCRIBED;channel.emit("subscribeFail",err,channelName);SCEmitter.prototype.emit.call(this,"subscribeFail",err,channelName)}};SCSocket.prototype._cancelPendingSubscribeCallback=function(channel){if(channel._pendingSubscriptionCid!=null){this.transport.cancelPendingResponse(channel._pendingSubscriptionCid);delete channel._pendingSubscriptionCid}};SCSocket.prototype._trySubscribe=function(channel){var self=this;if(this.state==this.OPEN&&!this.pendingConnectCallback&&channel._pendingSubscriptionCid==null){var options={noTimeout:true};channel._pendingSubscriptionCid=this.transport.emit("#subscribe",channel.name,options,function(err){delete channel._pendingSubscriptionCid;if(err){self._triggerChannelSubscribeFail(err,channel)}else{self._triggerChannelSubscribe(channel)}});SCEmitter.prototype.emit.call(this,"subscribeRequest",channel.name)}};SCSocket.prototype.subscribe=function(channelName){var channel=this._channels[channelName];if(!channel){channel=new SCChannel(channelName,this);this._channels[channelName]=channel}if(channel.state==channel.UNSUBSCRIBED){channel.state=channel.PENDING;this._trySubscribe(channel)}return channel};SCSocket.prototype._triggerChannelUnsubscribe=function(channel,newState){var channelName=channel.name;var oldState=channel.state;if(newState){channel.state=newState}else{channel.state=channel.UNSUBSCRIBED}this._cancelPendingSubscribeCallback(channel);if(oldState==channel.SUBSCRIBED){channel.emit("unsubscribe",channelName);SCEmitter.prototype.emit.call(this,"unsubscribe",channelName)}};SCSocket.prototype._tryUnsubscribe=function(channel){var self=this;if(this.state==this.OPEN){var options={noTimeout:true};this._cancelPendingSubscribeCallback(channel);this.transport.emit("#unsubscribe",channel.name,options)}};SCSocket.prototype.unsubscribe=function(channelName){var channel=this._channels[channelName];if(channel){if(channel.state!=channel.UNSUBSCRIBED){this._triggerChannelUnsubscribe(channel);this._tryUnsubscribe(channel)}}};SCSocket.prototype.channel=function(channelName){var currentChannel=this._channels[channelName];if(!currentChannel){currentChannel=new SCChannel(channelName,this);this._channels[channelName]=currentChannel}return currentChannel};SCSocket.prototype.destroyChannel=function(channelName){var channel=this._channels[channelName];channel.unwatch();channel.unsubscribe();delete this._channels[channelName]};SCSocket.prototype.subscriptions=function(includePending){var subs=[];var channel,includeChannel;for(var channelName in this._channels){if(this._channels.hasOwnProperty(channelName)){channel=this._channels[channelName];if(includePending){includeChannel=channel&&(channel.state==channel.SUBSCRIBED||channel.state==channel.PENDING)}else{includeChannel=channel&&channel.state==channel.SUBSCRIBED}if(includeChannel){subs.push(channelName)}}}return subs};SCSocket.prototype.isSubscribed=function(channel,includePending){var channel=this._channels[channel];if(includePending){return!!channel&&(channel.state==channel.SUBSCRIBED||channel.state==channel.PENDING)}return!!channel&&channel.state==channel.SUBSCRIBED};SCSocket.prototype.processPendingSubscriptions=function(){var self=this;this.pendingConnectCallback=false;var channels=[];for(var channelName in this._channels){if(this._channels.hasOwnProperty(channelName)){channels.push(channelName)}}for(var i in this._channels){if(this._channels.hasOwnProperty(i)){(function(channel){if(channel.state==channel.PENDING){self._trySubscribe(channel)}})(this._channels[i])}}};SCSocket.prototype.watch=function(channelName,handler){if(typeof handler!="function"){throw new Error("No handler function was provided")}this._channelEmitter.on(channelName,handler)};SCSocket.prototype.unwatch=function(channelName,handler){if(handler){this._channelEmitter.removeListener(channelName,handler)}else{this._channelEmitter.removeAllListeners(channelName)}};SCSocket.prototype.watchers=function(channelName){return this._channelEmitter.listeners(channelName)};module.exports=SCSocket}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./auth":2,"./objectcreate":3,"./response":4,"./sctransport":7,"linked-list":9,querystring:19,"sc-channel":10,"sc-emitter":12}],6:[function(require,module,exports){(function(global){var SCSocket=require("./scsocket");var _connections={};function getMultiplexId(isSecure,hostname,port,path){var protocolPrefix=isSecure?"https://":"http://";return protocolPrefix+hostname+":"+port+path}function connect(options){var self=this;options=options||{};var isSecure=global.location&&location.protocol=="https:";var opts={port:options.port||global.location&&location.port?location.port:isSecure?443:80,autoReconnect:true,autoProcessSubscriptions:true,ackTimeout:1e4,hostname:global.location&&location.hostname,path:"/socketcluster/",secure:isSecure,timestampRequests:false,timestampParam:"t",authEngine:null,authTokenName:"socketCluster.authToken",binaryType:"arraybuffer",multiplex:true};for(var i in options){if(options.hasOwnProperty(i)){opts[i]=options[i]}}var multiplexId=getMultiplexId(isSecure,opts.hostname,opts.port,opts.path);if(opts.multiplex===false){return new SCSocket(opts)}if(!_connections[multiplexId]){_connections[multiplexId]=new SCSocket(opts)}return _connections[multiplexId]}function destroy(options){var self=this;options=options||{};var isSecure=global.location&&location.protocol=="https:";var opts={port:options.port||global.location&&location.port?location.port:isSecure?443:80,hostname:global.location&&location.hostname,path:"/socketcluster/"};for(var i in options){if(options.hasOwnProperty(i)){opts[i]=options[i]}}var multiplexId=getMultiplexId(isSecure,opts.hostname,opts.port,opts.path);delete _connections[multiplexId]}module.exports={connect:connect,destroy:destroy}}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./scsocket":5}],7:[function(require,module,exports){var WebSocket=require("sc-ws");var SCEmitter=require("sc-emitter").SCEmitter;var formatter=require("sc-formatter");var Response=require("./response").Response;var querystring=require("querystring");var SCTransport=function(authEngine,options){this.state=this.CLOSED;this.auth=authEngine;this.options=options;this.pingTimeout=options.ackTimeout;this.callIdGenerator=options.callIdGenerator;this._pingTimeoutTicker=null;this._callbackMap={};this.open()};SCTransport.prototype=Object.create(SCEmitter.prototype);SCTransport.CONNECTING=SCTransport.prototype.CONNECTING="connecting";SCTransport.OPEN=SCTransport.prototype.OPEN="open";SCTransport.CLOSED=SCTransport.prototype.CLOSED="closed";SCTransport.prototype.uri=function(){var query=this.options.query||{};var schema=this.options.secure?"wss":"ws";var port="";if(this.options.port&&("wss"==schema&&this.options.port!=443||"ws"==schema&&this.options.port!=80)){port=":"+this.options.port}if(this.options.timestampRequests){query[this.options.timestampParam]=(new Date).getTime()}query=querystring.stringify(query);if(query.length){query="?"+query}return schema+"://"+this.options.hostname+port+this.options.path+query};SCTransport.prototype.open=function(){var self=this;this.state=this.CONNECTING;var uri=this.uri();var wsSocket=new WebSocket(uri,null,this.options);wsSocket.binaryType=this.options.binaryType;this.socket=wsSocket;wsSocket.onopen=function(){self._onOpen()};wsSocket.onclose=function(event){self._onClose(event.code,event.reason)};wsSocket.onmessage=function(message,flags){self._onMessage(message.data)};wsSocket.onerror=function(error){if(self.state===self.CONNECTING){self._onClose(1006)}}};SCTransport.prototype._onOpen=function(){var self=this;this._resetPingTimeout();this._handshake(function(err,status){if(err){self._onError(err);self._onClose(4003);self.socket.close(4003)}else{self.state=self.OPEN;SCEmitter.prototype.emit.call(self,"open",status);self._resetPingTimeout()}})};SCTransport.prototype._handshake=function(callback){var self=this;this.auth.loadToken(this.options.authTokenName,function(err,token){if(err){callback(err)}else{var options={force:true};self.emit("#handshake",{authToken:token},options,callback)}})};SCTransport.prototype._onClose=function(code,data){delete this.socket.onopen;delete this.socket.onclose;delete this.socket.onmessage;delete this.socket.onerror;if(this.state==this.OPEN){this.state=this.CLOSED;SCEmitter.prototype.emit.call(this,"close",code,data)}else if(this.state==this.CONNECTING){this.state=this.CLOSED;SCEmitter.prototype.emit.call(this,"openAbort",code,data)}};SCTransport.prototype._onMessage=function(message){SCEmitter.prototype.emit.call(this,"event","message",message);if(message=="#1"){this._resetPingTimeout();if(this.socket.readyState==this.socket.OPEN){this.socket.send("#2")}}else{var obj;try{obj=this.parse(message)}catch(err){obj=message}var event=obj.event;if(event){var response=new Response(this,obj.cid);SCEmitter.prototype.emit.call(this,"event",event,obj.data,response)}else if(obj.rid!=null){var eventObject=this._callbackMap[obj.rid];if(eventObject){clearTimeout(eventObject.timeout);delete this._callbackMap[obj.rid];if(eventObject.callback){eventObject.callback(obj.error,obj.data)}}if(obj.error){this._onError(obj.error)}}else{SCEmitter.prototype.emit.call(this,"event","raw",obj)}}};SCTransport.prototype._onError=function(err){SCEmitter.prototype.emit.call(this,"error",err)};SCTransport.prototype._resetPingTimeout=function(){var self=this;var now=(new Date).getTime();clearTimeout(this._pingTimeoutTicker);this._pingTimeoutTicker=setTimeout(function(){self._onClose(4e3);self.socket.close(4e3)},this.pingTimeout)};SCTransport.prototype.getBytesReceived=function(){return this.socket.bytesReceived};SCTransport.prototype.close=function(code,data){code=code||1e3;if(this.state==this.OPEN){var packet={code:code,data:data};this.emit("#disconnect",packet);this._onClose(code,data);this.socket.close(code)}else if(this.state==this.CONNECTING){this._onClose(code,data);this.socket.close(code)}};SCTransport.prototype.emitRaw=function(eventObject){eventObject.cid=this.callIdGenerator();if(eventObject.callback){this._callbackMap[eventObject.cid]=eventObject}var simpleEventObject={event:eventObject.event,data:eventObject.data,cid:eventObject.cid};this.sendObject(simpleEventObject);return eventObject.cid};SCTransport.prototype._handleEventAckTimeout=function(eventObject){var errorMessage="Event response for '"+eventObject.event+"' timed out";var error=new Error(errorMessage);error.type="timeout";if(eventObject.cid){delete this._callbackMap[eventObject.cid]}var callback=eventObject.callback;delete eventObject.callback;callback.call(eventObject,error,eventObject);this._onError(error)};SCTransport.prototype.emit=function(event,data,a,b){var self=this;var callback,options;if(b){options=a;callback=b}else{if(a instanceof Function){options={};callback=a}else{options=a}}var eventObject={event:event,data:data,callback:callback};if(callback&&!options.noTimeout){eventObject.timeout=setTimeout(function(){self._handleEventAckTimeout(eventObject)},this.options.ackTimeout)}var cid=null;if(this.state==this.OPEN||options.force){cid=this.emitRaw(eventObject)}return cid};SCTransport.prototype.cancelPendingResponse=function(cid){delete this._callbackMap[cid]};SCTransport.prototype.parse=function(message){return formatter.parse(message)};SCTransport.prototype.stringify=function(object){return formatter.stringify(object)};SCTransport.prototype.send=function(data){if(this.socket.readyState!=this.socket.OPEN){this._onClose(1005)}else{this.socket.send(data)}};SCTransport.prototype.sendObject=function(object){var str,formatError;try{str=this.stringify(object)}catch(err){formatError=err;this._onError(formatError)}if(!formatError){this.send(str)}};module.exports.SCTransport=SCTransport},{"./response":4,querystring:19,"sc-emitter":12,"sc-formatter":15,"sc-ws":16}],8:[function(require,module,exports){"use strict";var errorMessage;errorMessage="An argument without append, prepend, "+"or detach methods was given to `List";function List(){if(arguments.length){return List.from(arguments)}}var ListPrototype;ListPrototype=List.prototype;List.of=function(){return List.from.call(this,arguments)};List.from=function(items){var list=new this,length,iterator,item;if(items&&(length=items.length)){iterator=-1;while(++iteratormaxTimeout){throw new Error("The "+propertyName+" value provided exceeded the maximum amount allowed")}};verifyDuration("ackTimeout");verifyDuration("pingTimeout");this._localEvents={connect:1,connectAbort:1,disconnect:1,message:1,error:1,raw:1,fail:1,kickOut:1,subscribe:1,unsubscribe:1,authenticate:1,removeAuthToken:1,subscribeRequest:1};this._connectAttempts=0;this._emitBuffer=new LinkedList;this._channels={};this.options=opts;this._cid=1;this.options.callIdGenerator=function(){return self._callIdGenerator()};if(this.options.autoReconnect){if(this.options.autoReconnectOptions==null){this.options.autoReconnectOptions={}}var reconnectOptions=this.options.autoReconnectOptions;if(reconnectOptions.initialDelay==null){reconnectOptions.initialDelay=1e4}if(reconnectOptions.randomness==null){reconnectOptions.randomness=1e4}if(reconnectOptions.multiplier==null){reconnectOptions.multiplier=1.5}if(reconnectOptions.maxDelay==null){reconnectOptions.maxDelay=6e4}}if(this.options.subscriptionRetryOptions==null){this.options.subscriptionRetryOptions={}}if(this.options.authEngine){this.auth=this.options.authEngine}else{this.auth=new AuthEngine}this.options.path=this.options.path.replace(/\/$/,"")+"/";this.options.query=opts.query||{};if(typeof this.options.query=="string"){this.options.query=querystring.parse(this.options.query)}this.connect();this._channelEmitter=new SCEmitter;if(isBrowser){var unloadHandler=function(){self.disconnect()};if(global.attachEvent){global.attachEvent("onunload",unloadHandler)}else if(global.addEventListener){global.addEventListener("beforeunload",unloadHandler,false)}}};SCSocket.prototype=Object.create(SCEmitter.prototype);SCSocket.CONNECTING=SCSocket.prototype.CONNECTING=SCTransport.prototype.CONNECTING;SCSocket.OPEN=SCSocket.prototype.OPEN=SCTransport.prototype.OPEN;SCSocket.CLOSED=SCSocket.prototype.CLOSED=SCTransport.prototype.CLOSED;SCSocket.ignoreStatuses={1e3:"Socket closed normally",1001:"Socket hung up"};SCSocket.errorStatuses={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"};SCSocket.prototype._privateEventHandlerMap={"#fail":function(data){this._onSCError(data)},"#publish":function(data){var isSubscribed=this.isSubscribed(data.channel,true);if(isSubscribed){this._channelEmitter.emit(data.channel,data.data)}},"#kickOut":function(data){var channelName=data.channel;var channel=this._channels[channelName];if(channel){SCEmitter.prototype.emit.call(this,"kickOut",data.message,channelName);channel.emit("kickOut",data.message,channelName);this._triggerChannelUnsubscribe(channel)}},"#setAuthToken":function(data,response){var self=this;if(data){var triggerAuthenticate=function(err){if(err){response.error(err.message||err);self._onSCError(err)}else{SCEmitter.prototype.emit.call(self,"authenticate",data.token);response.end()}};this.auth.saveToken(this.options.authTokenName,data.token,{},triggerAuthenticate)}else{response.error("No token data provided by #setAuthToken event")}},"#removeAuthToken":function(data,response){var self=this;this.auth.removeToken(this.options.authTokenName,function(err){if(err){response.error(err.message||err);self._onSCError(err)}else{SCEmitter.prototype.emit.call(self,"removeAuthToken");response.end()}})},"#disconnect":function(data){this.transport.close(data.code,data.data)}};SCSocket.prototype._callIdGenerator=function(){return this._cid++};SCSocket.prototype.getState=function(){return this.state};SCSocket.prototype.getBytesReceived=function(){return this.transport.getBytesReceived()};SCSocket.prototype.removeAuthToken=function(callback){var self=this;this.auth.removeToken(this.options.authTokenName,function(err){callback&&callback(err);if(err){self._onSCError(err)}else{SCEmitter.prototype.emit.call(self,"removeAuthToken")}})};SCSocket.prototype.connect=SCSocket.prototype.open=function(){var self=this;if(this.state==this.CLOSED){clearTimeout(this._reconnectTimeout);this.state=this.CONNECTING;if(this.transport){this.transport.off()}this.transport=new SCTransport(this.auth,this.options);this.transport.on("open",function(status){self.state=self.OPEN;self._onSCOpen(status)});this.transport.on("error",function(err){self._onSCError(err)});this.transport.on("close",function(code,data){self.state=self.CLOSED;self._onSCClose(code,data)});this.transport.on("openAbort",function(code,data){self.state=self.CLOSED;self._onSCClose(code,data,true)});this.transport.on("event",function(event,data,res){self._onSCEvent(event,data,res)})}};SCSocket.prototype.reconnect=function(){this.disconnect();this.connect()};SCSocket.prototype.disconnect=function(code,data){code=code||1e3;if(this.state==this.OPEN){var packet={code:code,data:data};this.transport.emit("#disconnect",packet);this.transport.close(code)}else if(this.state==this.CONNECTING){this.transport.close(code)}};SCSocket.prototype.authenticate=function(signedAuthToken,callback){var self=this;this.emit("#authenticate",signedAuthToken,function(err,authStatus){if(err){callback&&callback(err,authStatus)}else{self.auth.saveToken(self.options.authTokenName,signedAuthToken,{},function(err){callback&&callback(err,authStatus);if(err){self._onSCError(err)}else if(authStatus.isAuthenticated){SCEmitter.prototype.emit.call(self,"authenticate",signedAuthToken)}})}})};SCSocket.prototype._tryReconnect=function(initialDelay){var self=this;var exponent=this._connectAttempts++;var reconnectOptions=this.options.autoReconnectOptions;var timeout;if(initialDelay==null||exponent>0){var initialTimeout=Math.round(reconnectOptions.initialDelay+(reconnectOptions.randomness||0)*Math.random());timeout=Math.round(initialTimeout*Math.pow(reconnectOptions.multiplier,exponent))}else{timeout=initialDelay}if(timeout>reconnectOptions.maxDelay){timeout=reconnectOptions.maxDelay}clearTimeout(this._reconnectTimeout);this._reconnectTimeout=setTimeout(function(){self.connect()},timeout)};SCSocket.prototype._onSCOpen=function(status){var self=this;if(status){this.id=status.id;this.pingTimeout=status.pingTimeout;this.transport.pingTimeout=this.pingTimeout}this._connectAttempts=0;if(this.options.autoProcessSubscriptions){this.processPendingSubscriptions()}else{this.pendingConnectCallback=true}SCEmitter.prototype.emit.call(this,"connect",status,function(){self.processPendingSubscriptions()});this._flushEmitBuffer()};SCSocket.prototype._onSCError=function(err){var self=this;setTimeout(function(){if(self.listeners("error").length<1){throw err}else{SCEmitter.prototype.emit.call(self,"error",err)}},0)};SCSocket.prototype._suspendSubscriptions=function(){var channel,newState;for(var channelName in this._channels){if(this._channels.hasOwnProperty(channelName)){channel=this._channels[channelName];if(channel.state==channel.SUBSCRIBED||channel.state==channel.PENDING){newState=channel.PENDING}else{newState=channel.UNSUBSCRIBED}this._triggerChannelUnsubscribe(channel,newState)}}};SCSocket.prototype._onSCClose=function(code,data,openAbort){var self=this;this.id=null;if(this.transport){this.transport.off()}clearTimeout(this._reconnectTimeout);this._suspendSubscriptions();if(openAbort){SCEmitter.prototype.emit.call(self,"connectAbort",code,data)}else{SCEmitter.prototype.emit.call(self,"disconnect",code,data)}if(this.options.autoReconnect){if(code==4e3||code==4001||code==1005){this._tryReconnect(0)}else if(code!=1e3){this._tryReconnect()}}if(!SCSocket.ignoreStatuses[code]){var err=new Error(SCSocket.errorStatuses[code]||"Socket connection failed for unknown reasons");err.code=code;this._onSCError(err)}};SCSocket.prototype._onSCEvent=function(event,data,res){var handler=this._privateEventHandlerMap[event];if(handler){handler.call(this,data,res)}else{SCEmitter.prototype.emit.call(this,event,data,function(){res&&res.callback.apply(res,arguments)})}};SCSocket.prototype.parse=function(message){return this.transport.parse(message)};SCSocket.prototype.stringify=function(object){return this.transport.stringify(object)};SCSocket.prototype._flushEmitBuffer=function(){var currentNode=this._emitBuffer.head;var nextNode;while(currentNode){nextNode=currentNode.next;var eventObject=currentNode.data;currentNode.detach();this.transport.emitRaw(eventObject);currentNode=nextNode}};SCSocket.prototype._handleEventAckTimeout=function(eventObject,eventNode){var errorMessage="Event response for '"+eventObject.event+"' timed out";var error=new Error(errorMessage);error.type="timeout";var callback=eventObject.callback;delete eventObject.callback;if(eventNode){eventNode.detach()}callback.call(eventObject,error,eventObject);this._onSCError(error)};SCSocket.prototype._emit=function(event,data,callback){var self=this;if(this.state==this.CLOSED){this.connect()}var eventObject={event:event,data:data,callback:callback};var eventNode=new LinkedList.Item;eventNode.data=eventObject;if(callback){eventObject.timeout=setTimeout(function(){self._handleEventAckTimeout(eventObject,eventNode)},this.ackTimeout)}this._emitBuffer.append(eventNode);if(this.state==this.OPEN){this._flushEmitBuffer()}};SCSocket.prototype.send=function(data){this.transport.send(data)};SCSocket.prototype.emit=function(event,data,callback){if(this._localEvents[event]==null){this._emit(event,data,callback)}else{SCEmitter.prototype.emit.call(this,event,data)}};SCSocket.prototype.publish=function(channelName,data,callback){var pubData={channel:channelName,data:data};this.emit("#publish",pubData,callback)};SCSocket.prototype._triggerChannelSubscribe=function(channel){var channelName=channel.name;if(channel.state!=channel.SUBSCRIBED){channel.state=channel.SUBSCRIBED;channel.emit("subscribe",channelName);SCEmitter.prototype.emit.call(this,"subscribe",channelName)}};SCSocket.prototype._triggerChannelSubscribeFail=function(err,channel){var channelName=channel.name;if(channel.state!=channel.UNSUBSCRIBED){channel.state=channel.UNSUBSCRIBED;channel.emit("subscribeFail",err,channelName);SCEmitter.prototype.emit.call(this,"subscribeFail",err,channelName)}};SCSocket.prototype._cancelPendingSubscribeCallback=function(channel){if(channel._pendingSubscriptionCid!=null){this.transport.cancelPendingResponse(channel._pendingSubscriptionCid);delete channel._pendingSubscriptionCid}};SCSocket.prototype._trySubscribe=function(channel){var self=this;if(this.state==this.OPEN&&!this.pendingConnectCallback&&channel._pendingSubscriptionCid==null){var options={noTimeout:true};channel._pendingSubscriptionCid=this.transport.emit("#subscribe",channel.name,options,function(err){delete channel._pendingSubscriptionCid;if(err){self._triggerChannelSubscribeFail(err,channel)}else{self._triggerChannelSubscribe(channel)}});SCEmitter.prototype.emit.call(this,"subscribeRequest",channel.name)}};SCSocket.prototype.subscribe=function(channelName){var channel=this._channels[channelName];if(!channel){channel=new SCChannel(channelName,this);this._channels[channelName]=channel}if(channel.state==channel.UNSUBSCRIBED){channel.state=channel.PENDING;this._trySubscribe(channel)}return channel};SCSocket.prototype._triggerChannelUnsubscribe=function(channel,newState){var channelName=channel.name;var oldState=channel.state;if(newState){channel.state=newState}else{channel.state=channel.UNSUBSCRIBED}this._cancelPendingSubscribeCallback(channel);if(oldState==channel.SUBSCRIBED){channel.emit("unsubscribe",channelName);SCEmitter.prototype.emit.call(this,"unsubscribe",channelName)}};SCSocket.prototype._tryUnsubscribe=function(channel){var self=this;if(this.state==this.OPEN){var options={noTimeout:true};this._cancelPendingSubscribeCallback(channel);this.transport.emit("#unsubscribe",channel.name,options)}};SCSocket.prototype.unsubscribe=function(channelName){var channel=this._channels[channelName];if(channel){if(channel.state!=channel.UNSUBSCRIBED){this._triggerChannelUnsubscribe(channel);this._tryUnsubscribe(channel)}}};SCSocket.prototype.channel=function(channelName){var currentChannel=this._channels[channelName];if(!currentChannel){currentChannel=new SCChannel(channelName,this);this._channels[channelName]=currentChannel}return currentChannel};SCSocket.prototype.destroyChannel=function(channelName){var channel=this._channels[channelName];channel.unwatch();channel.unsubscribe();delete this._channels[channelName]};SCSocket.prototype.subscriptions=function(includePending){var subs=[];var channel,includeChannel;for(var channelName in this._channels){if(this._channels.hasOwnProperty(channelName)){channel=this._channels[channelName];if(includePending){includeChannel=channel&&(channel.state==channel.SUBSCRIBED||channel.state==channel.PENDING)}else{includeChannel=channel&&channel.state==channel.SUBSCRIBED}if(includeChannel){subs.push(channelName)}}}return subs};SCSocket.prototype.isSubscribed=function(channel,includePending){var channel=this._channels[channel];if(includePending){return!!channel&&(channel.state==channel.SUBSCRIBED||channel.state==channel.PENDING)}return!!channel&&channel.state==channel.SUBSCRIBED};SCSocket.prototype.processPendingSubscriptions=function(){var self=this;this.pendingConnectCallback=false;var channels=[];for(var channelName in this._channels){if(this._channels.hasOwnProperty(channelName)){channels.push(channelName)}}for(var i in this._channels){if(this._channels.hasOwnProperty(i)){(function(channel){if(channel.state==channel.PENDING){self._trySubscribe(channel)}})(this._channels[i])}}};SCSocket.prototype.watch=function(channelName,handler){if(typeof handler!="function"){throw new Error("No handler function was provided")}this._channelEmitter.on(channelName,handler)};SCSocket.prototype.unwatch=function(channelName,handler){if(handler){this._channelEmitter.removeListener(channelName,handler)}else{this._channelEmitter.removeAllListeners(channelName)}};SCSocket.prototype.watchers=function(channelName){return this._channelEmitter.listeners(channelName)};module.exports=SCSocket}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./auth":2,"./objectcreate":3,"./response":4,"./sctransport":7,"linked-list":9,querystring:19,"sc-channel":10,"sc-emitter":12}],6:[function(require,module,exports){(function(global){var SCSocket=require("./scsocket");var _connections={};function getMultiplexId(options){var protocolPrefix=options.secure?"https://":"http://";return protocolPrefix+options.hostname+":"+options.port+options.path}function isUrlSecure(){return global.location&&location.protocol=="https:"}function getPort(options,isSecureDefault){var isSecure=options.secure==null?isSecureDefault:options.secure;return options.port||(global.location&&location.port?location.port:isSecure?443:80)}function connect(options){var self=this;options=options||{};var isSecureDefault=isUrlSecure();var opts={port:getPort(options,isSecureDefault),hostname:global.location&&location.hostname,path:"/socketcluster/",secure:isSecureDefault,autoReconnect:true,autoProcessSubscriptions:true,ackTimeout:1e4,timestampRequests:false,timestampParam:"t",authEngine:null,authTokenName:"socketCluster.authToken",binaryType:"arraybuffer",multiplex:true};for(var i in options){if(options.hasOwnProperty(i)){opts[i]=options[i]}}var multiplexId=getMultiplexId(opts);if(opts.multiplex===false){return new SCSocket(opts)}if(!_connections[multiplexId]){_connections[multiplexId]=new SCSocket(opts)}return _connections[multiplexId]}function destroy(options){var self=this;options=options||{};var isSecureDefault=isUrlSecure();var opts={port:getPort(options,isSecureDefault),hostname:global.location&&location.hostname,path:"/socketcluster/",secure:isSecureDefault};for(var i in options){if(options.hasOwnProperty(i)){opts[i]=options[i]}}var multiplexId=getMultiplexId(opts);delete _connections[multiplexId]}module.exports={connect:connect,destroy:destroy}}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./scsocket":5}],7:[function(require,module,exports){var WebSocket=require("sc-ws");var SCEmitter=require("sc-emitter").SCEmitter;var formatter=require("sc-formatter");var Response=require("./response").Response;var querystring=require("querystring");var SCTransport=function(authEngine,options){this.state=this.CLOSED;this.auth=authEngine;this.options=options;this.pingTimeout=options.ackTimeout;this.callIdGenerator=options.callIdGenerator;this._pingTimeoutTicker=null;this._callbackMap={};this.open()};SCTransport.prototype=Object.create(SCEmitter.prototype);SCTransport.CONNECTING=SCTransport.prototype.CONNECTING="connecting";SCTransport.OPEN=SCTransport.prototype.OPEN="open";SCTransport.CLOSED=SCTransport.prototype.CLOSED="closed";SCTransport.prototype.uri=function(){var query=this.options.query||{};var schema=this.options.secure?"wss":"ws";var port="";if(this.options.port&&("wss"==schema&&this.options.port!=443||"ws"==schema&&this.options.port!=80)){port=":"+this.options.port}if(this.options.timestampRequests){query[this.options.timestampParam]=(new Date).getTime()}query=querystring.stringify(query);if(query.length){query="?"+query}return schema+"://"+this.options.hostname+port+this.options.path+query};SCTransport.prototype.open=function(){var self=this;this.state=this.CONNECTING;var uri=this.uri();var wsSocket=new WebSocket(uri,null,this.options);wsSocket.binaryType=this.options.binaryType;this.socket=wsSocket;wsSocket.onopen=function(){self._onOpen()};wsSocket.onclose=function(event){self._onClose(event.code,event.reason)};wsSocket.onmessage=function(message,flags){self._onMessage(message.data)};wsSocket.onerror=function(error){if(self.state===self.CONNECTING){self._onClose(1006)}}};SCTransport.prototype._onOpen=function(){var self=this;this._resetPingTimeout();this._handshake(function(err,status){if(err){self._onError(err);self._onClose(4003);self.socket.close(4003)}else{self.state=self.OPEN;SCEmitter.prototype.emit.call(self,"open",status);self._resetPingTimeout()}})};SCTransport.prototype._handshake=function(callback){var self=this;this.auth.loadToken(this.options.authTokenName,function(err,token){if(err){callback(err)}else{var options={force:true};self.emit("#handshake",{authToken:token},options,callback)}})};SCTransport.prototype._onClose=function(code,data){delete this.socket.onopen;delete this.socket.onclose;delete this.socket.onmessage;delete this.socket.onerror;if(this.state==this.OPEN){this.state=this.CLOSED;SCEmitter.prototype.emit.call(this,"close",code,data)}else if(this.state==this.CONNECTING){this.state=this.CLOSED;SCEmitter.prototype.emit.call(this,"openAbort",code,data)}};SCTransport.prototype._onMessage=function(message){SCEmitter.prototype.emit.call(this,"event","message",message);if(message=="#1"){this._resetPingTimeout();if(this.socket.readyState==this.socket.OPEN){this.socket.send("#2")}}else{var obj;try{obj=this.parse(message)}catch(err){obj=message}var event=obj.event;if(event){var response=new Response(this,obj.cid);SCEmitter.prototype.emit.call(this,"event",event,obj.data,response)}else if(obj.rid!=null){var eventObject=this._callbackMap[obj.rid];if(eventObject){clearTimeout(eventObject.timeout);delete this._callbackMap[obj.rid];if(eventObject.callback){eventObject.callback(obj.error,obj.data)}}if(obj.error){this._onError(obj.error)}}else{SCEmitter.prototype.emit.call(this,"event","raw",obj)}}};SCTransport.prototype._onError=function(err){SCEmitter.prototype.emit.call(this,"error",err)};SCTransport.prototype._resetPingTimeout=function(){var self=this;var now=(new Date).getTime();clearTimeout(this._pingTimeoutTicker);this._pingTimeoutTicker=setTimeout(function(){self._onClose(4e3);self.socket.close(4e3)},this.pingTimeout)};SCTransport.prototype.getBytesReceived=function(){return this.socket.bytesReceived};SCTransport.prototype.close=function(code,data){code=code||1e3;if(this.state==this.OPEN){var packet={code:code,data:data};this.emit("#disconnect",packet);this._onClose(code,data);this.socket.close(code)}else if(this.state==this.CONNECTING){this._onClose(code,data);this.socket.close(code)}};SCTransport.prototype.emitRaw=function(eventObject){eventObject.cid=this.callIdGenerator();if(eventObject.callback){this._callbackMap[eventObject.cid]=eventObject}var simpleEventObject={event:eventObject.event,data:eventObject.data,cid:eventObject.cid};this.sendObject(simpleEventObject);return eventObject.cid};SCTransport.prototype._handleEventAckTimeout=function(eventObject){var errorMessage="Event response for '"+eventObject.event+"' timed out";var error=new Error(errorMessage);error.type="timeout";if(eventObject.cid){delete this._callbackMap[eventObject.cid]}var callback=eventObject.callback;delete eventObject.callback;callback.call(eventObject,error,eventObject);this._onError(error)};SCTransport.prototype.emit=function(event,data,a,b){var self=this;var callback,options;if(b){options=a;callback=b}else{if(a instanceof Function){options={};callback=a}else{options=a}}var eventObject={event:event,data:data,callback:callback};if(callback&&!options.noTimeout){eventObject.timeout=setTimeout(function(){self._handleEventAckTimeout(eventObject)},this.options.ackTimeout)}var cid=null;if(this.state==this.OPEN||options.force){cid=this.emitRaw(eventObject)}return cid};SCTransport.prototype.cancelPendingResponse=function(cid){delete this._callbackMap[cid]};SCTransport.prototype.parse=function(message){return formatter.parse(message)};SCTransport.prototype.stringify=function(object){return formatter.stringify(object)};SCTransport.prototype.send=function(data){if(this.socket.readyState!=this.socket.OPEN){this._onClose(1005)}else{this.socket.send(data)}};SCTransport.prototype.sendObject=function(object){var str,formatError;try{str=this.stringify(object)}catch(err){formatError=err;this._onError(formatError)}if(!formatError){this.send(str)}};module.exports.SCTransport=SCTransport},{"./response":4,querystring:19,"sc-emitter":12,"sc-formatter":15,"sc-ws":16}],8:[function(require,module,exports){"use strict";var errorMessage;errorMessage="An argument without append, prepend, "+"or detach methods was given to `List";function List(){if(arguments.length){return List.from(arguments)}}var ListPrototype;ListPrototype=List.prototype;List.of=function(){return List.from.call(this,arguments)};List.from=function(items){var list=new this,length,iterator,item;if(items&&(length=items.length)){iterator=-1;while(++iterator>2];base64+=base64Chars[(bytes[i]&3)<<4|bytes[i+1]>>4];base64+=base64Chars[(bytes[i+1]&15)<<2|bytes[i+2]>>6];base64+=base64Chars[bytes[i+2]&63]}if(len%3===2){base64=base64.substring(0,base64.length-1)+"="}else if(len%3===1){base64=base64.substring(0,base64.length-2)+"=="}return base64};var isOwnDescendant=function(object,ancestors){for(var i in ancestors){if(ancestors.hasOwnProperty(i)){if(ancestors[i]===object){return true}}}return false};var convertBuffersToBase64=function(object,ancestors){if(!ancestors){ancestors=[]}if(isOwnDescendant(object,ancestors)){throw new Error("Cannot traverse circular structure")}var newAncestors=ancestors.concat([object]);if(global.ArrayBuffer&&object instanceof global.ArrayBuffer){object={base64:true,data:arrayBufferToBase64(object)}}else if(global.Buffer&&object instanceof global.Buffer){object={base64:true,data:object.toString("base64")}}else if(object instanceof Array){for(var i in object){if(object.hasOwnProperty(i)){object[i]=convertBuffersToBase64(object[i],newAncestors)}}}else if(object instanceof Object){for(var j in object){if(object.hasOwnProperty(j)){object[j]=convertBuffersToBase64(object[j],newAncestors)}}}return object};module.exports.stringify=function(object){var base64Object=convertBuffersToBase64(object);return JSON.stringify(base64Object)}}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{}],16:[function(require,module,exports){var global=function(){return this}();var WebSocket=global.WebSocket||global.MozWebSocket;module.exports=WebSocket?ws:null;function ws(uri,protocols,opts){var instance;if(protocols){instance=new WebSocket(uri,protocols)}else{instance=new WebSocket(uri)}return instance}if(WebSocket)ws.prototype=WebSocket.prototype},{}],17:[function(require,module,exports){"use strict";function hasOwnProperty(obj,prop){return Object.prototype.hasOwnProperty.call(obj,prop)}module.exports=function(qs,sep,eq,options){sep=sep||"&";eq=eq||"=";var obj={};if(typeof qs!=="string"||qs.length===0){return obj}var regexp=/\+/g;qs=qs.split(sep);var maxKeys=1e3;if(options&&typeof options.maxKeys==="number"){maxKeys=options.maxKeys}var len=qs.length;if(maxKeys>0&&len>maxKeys){len=maxKeys}for(var i=0;i=0){kstr=x.substr(0,idx);vstr=x.substr(idx+1)}else{kstr=x;vstr=""}k=decodeURIComponent(kstr);v=decodeURIComponent(vstr);if(!hasOwnProperty(obj,k)){obj[k]=v}else if(isArray(obj[k])){obj[k].push(v)}else{obj[k]=[obj[k],v]}}return obj};var isArray=Array.isArray||function(xs){return Object.prototype.toString.call(xs)==="[object Array]"}},{}],18:[function(require,module,exports){"use strict";var stringifyPrimitive=function(v){switch(typeof v){case"string":return v;case"boolean":return v?"true":"false";case"number":return isFinite(v)?v:"";default:return""}};module.exports=function(obj,sep,eq,name){sep=sep||"&";eq=eq||"=";if(obj===null){obj=undefined}if(typeof obj==="object"){return map(objectKeys(obj),function(k){var ks=encodeURIComponent(stringifyPrimitive(k))+eq;if(isArray(obj[k])){return map(obj[k],function(v){return ks+encodeURIComponent(stringifyPrimitive(v))}).join(sep)}else{return ks+encodeURIComponent(stringifyPrimitive(obj[k]))}}).join(sep)}if(!name)return"";return encodeURIComponent(stringifyPrimitive(name))+eq+encodeURIComponent(stringifyPrimitive(obj))};var isArray=Array.isArray||function(xs){return Object.prototype.toString.call(xs)==="[object Array]"};function map(xs,f){if(xs.map)return xs.map(f);var res=[];for(var i=0;i>2];base64+=base64Chars[(bytes[i]&3)<<4|bytes[i+1]>>4];base64+=base64Chars[(bytes[i+1]&15)<<2|bytes[i+2]>>6];base64+=base64Chars[bytes[i+2]&63]}if(len%3===2){base64=base64.substring(0,base64.length-1)+"="}else if(len%3===1){base64=base64.substring(0,base64.length-2)+"=="}return base64};var isOwnDescendant=function(object,ancestors){for(var i in ancestors){if(ancestors.hasOwnProperty(i)){if(ancestors[i]===object){return true}}}return false};var convertBuffersToBase64=function(object,ancestors){if(!ancestors){ancestors=[]}if(isOwnDescendant(object,ancestors)){throw new Error("Cannot traverse circular structure")}var newAncestors=ancestors.concat([object]);if(global.ArrayBuffer&&object instanceof global.ArrayBuffer){object={base64:true,data:arrayBufferToBase64(object)}}else if(global.Buffer&&object instanceof global.Buffer){object={base64:true,data:object.toString("base64")}}else if(object instanceof Array){for(var i in object){if(object.hasOwnProperty(i)){object[i]=convertBuffersToBase64(object[i],newAncestors)}}}else if(object instanceof Object){for(var j in object){if(object.hasOwnProperty(j)){object[j]=convertBuffersToBase64(object[j],newAncestors)}}}return object};module.exports.stringify=function(object){var base64Object=convertBuffersToBase64(object);return JSON.stringify(base64Object)}}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{}],16:[function(require,module,exports){var global=function(){return this}();var WebSocket=global.WebSocket||global.MozWebSocket;module.exports=WebSocket?ws:null;function ws(uri,protocols,opts){var instance;if(protocols){instance=new WebSocket(uri,protocols)}else{instance=new WebSocket(uri)}return instance}if(WebSocket)ws.prototype=WebSocket.prototype},{}],17:[function(require,module,exports){"use strict";function hasOwnProperty(obj,prop){return Object.prototype.hasOwnProperty.call(obj,prop)}module.exports=function(qs,sep,eq,options){sep=sep||"&";eq=eq||"=";var obj={};if(typeof qs!=="string"||qs.length===0){return obj}var regexp=/\+/g;qs=qs.split(sep);var maxKeys=1e3;if(options&&typeof options.maxKeys==="number"){maxKeys=options.maxKeys}var len=qs.length;if(maxKeys>0&&len>maxKeys){len=maxKeys}for(var i=0;i=0){kstr=x.substr(0,idx);vstr=x.substr(idx+1)}else{kstr=x;vstr=""}k=decodeURIComponent(kstr);v=decodeURIComponent(vstr);if(!hasOwnProperty(obj,k)){obj[k]=v}else if(isArray(obj[k])){obj[k].push(v)}else{obj[k]=[obj[k],v]}}return obj};var isArray=Array.isArray||function(xs){return Object.prototype.toString.call(xs)==="[object Array]"}},{}],18:[function(require,module,exports){"use strict";var stringifyPrimitive=function(v){switch(typeof v){case"string":return v;case"boolean":return v?"true":"false";case"number":return isFinite(v)?v:"";default:return""}};module.exports=function(obj,sep,eq,name){sep=sep||"&";eq=eq||"=";if(obj===null){obj=undefined}if(typeof obj==="object"){return map(objectKeys(obj),function(k){var ks=encodeURIComponent(stringifyPrimitive(k))+eq;if(isArray(obj[k])){return map(obj[k],function(v){return ks+encodeURIComponent(stringifyPrimitive(v))}).join(sep)}else{return ks+encodeURIComponent(stringifyPrimitive(obj[k]))}}).join(sep)}if(!name)return"";return encodeURIComponent(stringifyPrimitive(name))+eq+encodeURIComponent(stringifyPrimitive(obj))};var isArray=Array.isArray||function(xs){return Object.prototype.toString.call(xs)==="[object Array]"};function map(xs,f){if(xs.map)return xs.map(f);var res=[];for(var i=0;i