Click here to Skip to main content
15,893,968 members
Articles / Web Development / HTML5

Remotely databind a Collection with Spike & Knockout.js

Rate me:
Please Sign up or sign in to vote.
4.88/5 (7 votes)
23 Jun 2015CPOL3 min read 23.1K   312   26  
Making an ObservableCollection observable by remote javascript clients.
typeof spike=="undefined"&&(spike={});spike.binarySupport=typeof Uint8Array!="undefined"&&typeof DataView!="undefined";spike.ByteArray=function(){this.position=0;this.bigEndian=!0;this.allowExceptions=!0;spike.binarySupport?(this.data=new ArrayBuffer(0),this._size=this._maxSize=this.data.byteLength,this.view=new DataView(this.data)):this.data=[]};with({p:spike.ByteArray.prototype}){p.ensureCapacity=function(n){if(!(this._maxSize>this.position+n)){var baseArrayBuffer=this.data,newByteSize=this._maxSize+Math.max(1024,n),resizedArrayBuffer=new ArrayBuffer(newByteSize),len=baseArrayBuffer.byteLength,resizeLen=len>newByteSize?newByteSize:len;new Uint8Array(resizedArrayBuffer,0,resizeLen).set(new Uint8Array(baseArrayBuffer,0,resizeLen));this.data=resizedArrayBuffer;this.view=new DataView(this.data);this._maxSize=newByteSize}};p.string_writeFloat=function(t,u,f){for(var bias=Math.pow(2,f-1)-1,minExp=-bias+1,maxExp=bias,minUnnormExp=minExp-u,status=isNaN(n=parseFloat(t))||n==-Infinity||n==+Infinity?n:0,exp=0,len=2*bias+1+u+3,bin=new Array(len),signal=(n=status!==0?0:n)<0,n=Math.abs(n),intPart=Math.floor(n),floatPart=n-intPart,lastBit,rounded,j,result,i=len;i;bin[--i]=0);for(i=bias+2;intPart&&i;bin[--i]=intPart%2,intPart=Math.floor(intPart/2));for(i=bias+1;floatPart>0&&i;(bin[++i]=((floatPart*=2)>=1)-0)&&--floatPart);for(i=-1;++i<len&&!bin[i];);if(bin[(lastBit=u-1+(i=(exp=bias+1-i)>=minExp&&exp<=maxExp?i+1:bias+1-(exp=minExp-1)))+1]){if(!(rounded=bin[lastBit]))for(j=lastBit+2;!rounded&&j<len;rounded=bin[j++]);for(j=lastBit+1;rounded&&--j>=0;(bin[j]=!bin[j]-0)&&(rounded=0));}for(i=i-2<0?-1:i-3;++i<len&&!bin[i];);for((exp=bias+1-i)>=minExp&&exp<=maxExp?++i:exp<minExp&&(exp!=bias+1-len&&exp<minUnnormExp&&this.warn("encodeFloat::float underflow"),i=bias+1-(exp=minExp-1)),(intPart||status!==0)&&(this.warn(intPart?"encodeFloat::float overflow":"encodeFloat::"+status),exp=maxExp+1,i=bias+2,status==-Infinity?signal=1:isNaN(status)&&(bin[i]=1)),n=Math.abs(exp+bias),j=f+1,result="";--j;result=n%2+result,n=n>>=1);for(n=0,j=0,i=(result=(signal?"1":"0")+result+bin.slice(i,i+u).join("")).length,r=[];i;n+=(1<<j)*result.charAt(--i),j==7&&(r[r.length]=String.fromCharCode(n),n=0),j=(j+1)%8);r[r.length]=n?String.fromCharCode(n):"";this.data+=(this.bigEndian?r.reverse():r).join("")};p.native_writeFloat=function(n,t,i){var bits=t+i+1;this.ensureCapacity(bits/8);switch(bits){case 32:this.view.setFloat32(this.position,n,!this.bigEndian);this.position+=4;this._size+=4;return;case 64:this.view.setFloat64(this.position,n,!this.bigEndian);this.position+=8;this._size+=8;return}};p.writeFloat=spike.binarySupport?p.native_writeFloat:p.string_writeFloat;p.string_writeInt=function(n,t,i){if(t==64){this.write64(n);return}var max=Math.pow(2,t),r=[],maxs=Math.pow(2,t-1);for(i&&(n>=maxs||n<-maxs)&&this.warn("writeInt::overflow with value"+n)&&(n=0),!i&&(n>=max||n<-(max>>1))&&this.warn("writeUInt::overflow with value"+n)&&(n=0),n<0&&(n+=max);n;r[r.length]=String.fromCharCode(n%256),n=Math.floor(n/256));for(t=-(-t>>3)-r.length;t--;r[r.length]='\0');this.data+=(this.bigEndian?r.reverse():r).join("")};p.native_writeInt=function(n,t,i){if(this.ensureCapacity(t/8),i)switch(t){case 8:this.view.setInt8(this.position,n);this.position+=1;this._size+=1;return;case 16:this.view.setInt16(this.position,n,!this.bigEndian);this.position+=2;this._size+=2;return;case 32:this.view.setInt32(this.position,n,!this.bigEndian);this.position+=4;this._size+=4;return;case 64:this.write64(n);return}else switch(t){case 8:this.view.setUint8(this.position,n);this.position+=1;this._size+=1;return;case 16:this.view.setUint16(this.position,n,!this.bigEndian);this.position+=2;this._size+=2;return;case 32:this.view.setUint32(this.position,n,!this.bigEndian);this.position+=4;this._size+=4;return;case 64:this.write64(n);return}};p.writeInt=spike.binarySupport?p.native_writeInt:p.string_writeInt;p.writeByte=function(n){this.writeInt(n,8,!1)};p.string_writeBytes=function(n){this.data+=n};p.native_writeBytes=function(n){this.ensureCapacity(n.length);var v=new Uint8Array(this.data,this.position,n.length);v.set(n,0);this.position+=n.length;this._size+=n.length};p.writeBytes=spike.binarySupport?p.native_writeBytes:p.string_writeBytes;p.write64=function(n){var type,i,v;if(n.length!=20)throw new Error("UInt64 or Int16 must be a string of exactly 20 bytes");if(type=n.substring(0,4),type!="-64x"&&type!="+64x")throw new Error("UInt64 or Int16 must start with +64x or -64x");for(n=n.slice(4),i=0;i<16;i+=2)v=parseInt(""+n[i]+n[i+1],16),this.writeByte(v)};p.string_readFloat=function(n,t){var blen=(n+t+1)/8,data=this.data.slice(this.position,this.position+blen);this.position+=blen;var b=((b=new this.Buffer(this.bigEndian,data)).checkBuffer(n+t+1),b),bias=Math.pow(2,t-1)-1,signal=b.readBits(n+t,1),exponent=b.readBits(n,t),significand=0,divisor=2,curByte=b.buffer.length+(-n>>3)-1,byteValue,startBit,mask;do for(byteValue=b.buffer[++curByte],startBit=n%8||8,mask=1<<startBit;mask>>=1;byteValue&mask&&(significand+=1/divisor),divisor*=2);while(n-=startBit);return exponent==(bias<<1)+1?significand?NaN:signal?-Infinity:+Infinity:(1+signal*-2)*(exponent||significand?exponent?Math.pow(2,exponent-bias)*(1+significand):Math.pow(2,-bias+1)*significand:0)};p.native_readFloat=function(n,t){var bits=n+t+1,value=0;switch(bits){case 32:return value=this.view.getFloat32(this.position,!this.bigEndian),this.position+=4,value;case 64:return value=this.view.getFloat64(this.position,!this.bigEndian),this.position+=8,value}};p.readFloat=spike.binarySupport?p.native_readFloat:p.string_readFloat;p.string_readInt=function(n,t){var blen,data;if(n==64)return this.read64(t);blen=n/8;data=this.data.slice(this.position,this.position+blen);this.position+=blen;var b=new this.Buffer(this.bigEndian,data),x=b.readBits(0,n),max=Math.pow(2,n);return t&&x>=max/2?x-max:x};p.native_readInt=function(n,t){var value=0;if(t)switch(n){case 8:return value=this.view.getInt8(this.position),this.position+=1,value<128?value:value-256;case 16:return value=this.view.getInt16(this.position,!this.bigEndian),this.position+=2,value;case 32:return value=this.view.getInt32(this.position,!this.bigEndian),this.position+=4,value;case 64:return this.read64(t)}else switch(n){case 8:return value=this.view.getUint8(this.position),this.position+=1,value;case 16:return value=this.view.getUint16(this.position,!this.bigEndian),this.position+=2,value;case 32:return value=this.view.getUint32(this.position,!this.bigEndian),this.position+=4,value;case 64:return this.read64(t)}};p.readInt=spike.binarySupport?p.native_readInt:p.string_readInt;p.readByte=function(){return this.readInt(8,!1)};p.string_readBytes=function(n){var r=this.data.slice(this.position,this.position+n);return this.position+=n,r};p.native_readBytes=function(n){var r=new Uint8Array(this.data,this.position,n);return this.position+=n,r};p.readBytes=spike.binarySupport?p.native_readBytes:p.string_readBytes;p._padN=function(n,t){return n.length>=t?n:new Array(t-n.length+1).join("0")+n};p._pad2=function(n){return n.length<2?"0"+n:n};p.read64=function(n){for(var b16="",i=0;i<8;++i)b16+=this._pad2(this.getAt(this.position).toString(16)),this.position++;return(n?"-64x":"+64x")+b16};p.string_getAt=function(n){return this.data.charCodeAt(n)&255};p.native_getAt=function(n){return this.view.getUint8(n)};p.getAt=spike.binarySupport?p.native_getAt:p.string_getAt;p.readBytesTo=function(n,t){n.writeBytes(this.readBytes(t))};p.string_getSize=function(){return this.data.length};p.native_getSize=function(){return this._size};p.getSize=spike.binarySupport?p.native_getSize:p.string_getSize;p.string_toBase64=function(){for(var cleanBuffer=[],result="",i=0;i<this.getSize();++i)cleanBuffer.push(this.getAt(i));for(i=0;i<cleanBuffer.length;i++)result+=String.fromCharCode(cleanBuffer[i]);return typeof btoa=="function"?btoa(result):this._btoa(result)};p.native_toBase64=function(){var array=new Uint8Array(this.data,0,this._size),text=String.fromCharCode.apply(null,array);return typeof btoa=="function"?btoa(text):this._btoa(text)};p.toBase64=spike.binarySupport?p.native_toBase64:p.string_toBase64;p.toBuffer=function(){var p=this.position,b;return this.position=0,b=this.readBytes(this.getSize()),this.position=p,b};p.string_writeBase64=function(n){typeof atob=="function"?this.writeBytes(atob(n)):this.writeBytes(this._atob(n))};p.native_writeBase64=function(n){var array=new Uint8Array(atob(n).split("").map(function(n){return n.charCodeAt(0)}));this.writeBytes(array)};p.writeBase64=spike.binarySupport?p.native_writeBase64:p.string_writeBase64;p._btoa=function(n){for(var chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encoded=[],c=0;c<n.length;){var b0=n.charCodeAt(c++),b1=n.charCodeAt(c++),b2=n.charCodeAt(c++),buf=(b0<<16)+((b1||0)<<8)+(b2||0),i0=(buf&16515072)>>18,i1=(buf&258048)>>12,i2=isNaN(b1)?64:(buf&4032)>>6,i3=isNaN(b2)?64:buf&63;encoded[encoded.length]=chars.charAt(i0);encoded[encoded.length]=chars.charAt(i1);encoded[encoded.length]=chars.charAt(i2);encoded[encoded.length]=chars.charAt(i3)}return encoded.join("")};p._atob=function(n){var b64array="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",output="",chr1,chr2,chr3="",enc1,enc2,enc3,enc4="",i=0;n=n.replace(/[^A-Za-z0-9\+\/\=]/g,"");do enc1=b64array.indexOf(n.charAt(i++)),enc2=b64array.indexOf(n.charAt(i++)),enc3=b64array.indexOf(n.charAt(i++)),enc4=b64array.indexOf(n.charAt(i++)),chr1=enc1<<2|enc2>>4,chr2=(enc2&15)<<4|enc3>>2,chr3=(enc3&3)<<6|enc4,output=output+String.fromCharCode(chr1),enc3!=64&&(output=output+String.fromCharCode(chr2)),enc4!=64&&(output=output+String.fromCharCode(chr3)),chr1=chr2=chr3="",enc1=enc2=enc3=enc4="";while(i<n.length);return output};with({p:(p.Buffer=function(n,t){this.bigEndian=n||0;this.buffer=[];this.setBuffer(t)}).prototype})p.readBits=function(n,t){function shl(n,t){for(++t;--t;n=((n%=2147483648)&1073741824)==1073741824?n*2:(n-1073741824)*2+2147483647+1);return n}if(n<0||t<=0)return 0;this.checkBuffer(n+t);for(var offsetLeft,offsetRight=n%8,curByte=this.buffer.length-(n>>3)-1,lastByte=this.buffer.length+(-(n+t)>>3),diff=curByte-lastByte,sum=(this.buffer[curByte]>>offsetRight&(1<<(diff?8-offsetRight:t))-1)+(diff&&(offsetLeft=(n+t)%8)?(this.buffer[lastByte++]&(1<<offsetLeft)-1)<<(diff--<<3)-offsetRight:0);diff;sum+=shl(this.buffer[lastByte++],(diff--<<3)-offsetRight));return sum},p.setBuffer=function(n){if(n){for(var l,i=l=n.length,b=this.buffer=new Array(l);i;b[l-i]=n.charCodeAt(--i));this.bigEndian&&b.reverse()}},p.hasNeededBits=function(n){return this.buffer.length>=-(-n>>3)},p.checkBuffer=function(n){if(!this.hasNeededBits(n))throw new Error("checkBuffer::missing bytes");};p.warn=function(n){if(this.allowExceptions)throw new Error(n);return 1}}spike.PacketCompressor=function(){this.HLOG=14;this.HSIZE=16384;this.MAX_LIT=32;this.MAX_OFF=8192;this.MAX_REF=264;this.HashTable=new Array(this.HSIZE);this.compress=function(n,t){var o,h;this.HashTable.splice(0,this.HSIZE);for(var f=new spike.ByteArray,l,i=0,e=0,s,u=n.getAt(i)<<8|n.getAt(i+1),c,r=0;;){if(i<t-2){if(u=u<<8|n.getAt(i+2),l=(u^u<<5)>>24-this.HLOG-u*5&this.HSIZE-1,s=this.HashTable[l],this.HashTable[l]=i,(c=i-s-1)<this.MAX_OFF&&i+4<t&&s>0&&n.getAt(s+0)==n.getAt(i+0)&&n.getAt(s+1)==n.getAt(i+1)&&n.getAt(s+2)==n.getAt(i+2)){o=2;h=t-i-o;h=h>this.MAX_REF?this.MAX_REF:h;do o++;while(o<h&&n.getAt(s+o)==n.getAt(i+o));if(r!=0){e++;f.writeByte(r-1);r=-r;do e++,f.writeByte(n.getAt(i+r));while(++r!=0)}o-=2;i++;o<7?(e++,f.writeByte((c>>8)+(o<<5))):(e++,e++,f.writeByte((c>>8)+224),f.writeByte(o-7));e++;f.writeByte(c);i+=o-1;u=n.getAt(i)<<8|n.getAt(i+1);u=u<<8|n.getAt(i+2);this.HashTable[(u^u<<5)>>24-this.HLOG-u*5&this.HSIZE-1]=i;i++;u=u<<8|n.getAt(i+2);this.HashTable[(u^u<<5)>>24-this.HLOG-u*5&this.HSIZE-1]=i;i++;continue}}else if(i==t)break;if(r++,i++,r==this.MAX_LIT){e++;f.writeByte(this.MAX_LIT-1);r=-r;do e++,f.writeByte(n.getAt(i+r));while(++r!=0)}}if(r!=0){e++;f.writeByte(r-1);r=-r;do e++,f.writeByte(n.getAt(i+r));while(++r!=0)}return f.length=e,f};this.decompress=function(n,t){var r=0,f=0,i=new spike.ByteArray,e,o,u;do if(e=n.getAt(r),r++,e<32){e++;do i.writeByte(n.getAt(r)),r++,f++;while(--e!=0)}else{if(o=e>>5,u=f-((e&31)<<8)-1,o==7&&(o+=n.getAt(r),r++),u-=n.getAt(r),r++,u<0)return i.length=0,i;i.writeByte(i.getAt(u));u++;f++;i.writeByte(i.getAt(u));u++;f++;do i.writeByte(i.getAt(u)),u++,f++;while(--o!=0)}while(r<t);return i.length=f,i}};spike.PacketWriter=function(){this.buffer=new spike.ByteArray};spike.PacketWriter.prototype.compress=function(){this.buffer=(new spike.PacketCompressor).compress(this.buffer,this.buffer.getSize())};spike.PacketWriter.prototype.writeBoolean=function(n){n?this.buffer.writeInt(1,8,!1):this.buffer.writeInt(0,8,!1)};spike.PacketWriter.prototype.writeKey=function(n){for(var i,r,t=0;t<8;t+=2)i=n.charAt(t)+n.charAt(t+1),r=parseInt(i,16),this.buffer.writeInt(r,8,!1)};spike.PacketWriter.prototype.writeByte=function(n){this.buffer.writeInt(n,8,!1)};spike.PacketWriter.prototype.writeSByte=function(n){this.buffer.writeInt(n,8,!0)};spike.PacketWriter.prototype.writeInt16=function(n){this.buffer.writeInt(n,16,!0)};spike.PacketWriter.prototype.writeInt32=function(n){this.buffer.writeInt(n,32,!0)};spike.PacketWriter.prototype.writeInt64=function(n){this.buffer.writeInt(n,64,!0)};spike.PacketWriter.prototype.writeUInt16=function(n){this.buffer.writeInt(n,16,!1)};spike.PacketWriter.prototype.writeUInt32=function(n){this.buffer.writeInt(n,32,!1)};spike.PacketWriter.prototype.writeUInt64=function(n){this.buffer.writeInt(n,64,!1)};spike.PacketWriter.prototype.writeDateTime=function(n){this.writeInt16(n.getFullYear());this.writeInt16(n.getMonth()+1);this.writeInt16(n.getDate());this.writeInt16(n.getHours());this.writeInt16(n.getMinutes());this.writeInt16(n.getSeconds());this.writeInt16(n.getMilliseconds())};spike.PacketWriter.prototype.writeSingle=function(n){this.buffer.writeFloat(n,23,8)};spike.PacketWriter.prototype.writeDouble=function(n){this.buffer.writeFloat(n,52,11)};spike.PacketWriter.prototype.writeString=function(n){var r,i,t,u;if(n=="undefined"||n==null||n.length==0)this.writeInt32(0);else{if(n=unescape(encodeURIComponent(n)),spike.binarySupport){for(r=new ArrayBuffer(n.length),i=new Uint8Array(r),t=0,u=n.length;t<u;++t)i[t]=n.charCodeAt(t);n=i}this.writeInt32(n.length);this.buffer.writeBytes(n)}};spike.PacketWriter.prototype.writeDynamicType=function(n){var t=typeof n,i;if(t=="number"){if(this.writeByte(1),i=(n|0)==n||(+n).toFixed(20).replace(/^-?\d*\.?|0+$/g,"").length==0,i){if(n>2147483647&&n<=4294967295){this.writeString("UInt32");this.writeUInt32(n);return}if(-255<=n&&n<=255){this.writeString("Byte");this.writeByte(n|0);return}if(-32768<=n&&n<=32768){this.writeString("Int16");this.writeInt16(n|0);return}if(-2147483648<=n&&n<=2147483648){this.writeString("Int32");this.writeInt32(n|0);return}}if(-340282347e30<=n&&n<=340282347e30){this.writeString("Single");this.writeSingle(n);return}this.writeString("Double");this.writeDouble(n);return}if(t=="boolean"){this.writeByte(1);this.writeString("Boolean");this.writeBoolean(n);return}if(t=="string"){if(n.length==20){if(n.substring(0,4)=="+64x"){this.writeByte(1);this.writeString("UInt64");this.writeUInt64(n);return}if(n.substring(0,4)=="-64x"){this.writeByte(1);this.writeString("Int64");this.writeInt64(n);return}}else{this.writeByte(1);this.writeString("String");this.writeString(n);return}this.writeByte(0);return}if(t=="object"&&n instanceof Date){this.writeByte(1);this.writeString("DateTime");this.writeDateTime(n);return}this.writeByte(0);return};spike.PacketWriter.prototype.writeArrayOfByte=function(n){var t=typeof n;t=="object"&&n instanceof ByteArray?(this.writeInt32(n.getSize()),this.buffer.writeBytes(n.data)):(this.writeInt32(n.length),this.buffer.writeBytes(n))};spike.PacketWriter.prototype.writeArrayOfUInt16=function(n){var i=typeof n,t;if(i=="object"&&n instanceof Array){if(this.writeInt32(n.length),n.length==0)return;for(t=0;t<n.length;++t)this.writeUInt16(n[t])}else this.writeInt32(0)};spike.PacketWriter.prototype.writeArrayOfInt16=function(n){var i=typeof n,t;if(i=="object"&&n instanceof Array){if(this.writeInt32(n.length),n.length==0)return;for(t=0;t<n.length;++t)this.writeInt16(n[t])}else this.writeInt32(0)};spike.PacketWriter.prototype.writeArrayOfInt32=function(n){var i=typeof n,t;if(i=="object"&&n instanceof Array){if(this.writeInt32(n.length),n.length==0)return;for(t=0;t<n.length;++t)this.writeInt32(n[t])}else this.writeInt32(0)};spike.PacketWriter.prototype.writeArrayOfUInt32=function(n){var i=typeof n,t;if(i=="object"&&n instanceof Array){if(this.writeInt32(n.length),n.length==0)return;for(t=0;t<n.length;++t)this.writeUInt32(n[t])}else this.writeInt32(0)};spike.PacketWriter.prototype.writeArrayOfInt64=function(n){var i=typeof n,t;if(i=="object"&&n instanceof Array){if(this.writeInt32(n.length),n.length==0)return;for(t=0;t<n.length;++t)this.writeInt64(n[t])}else this.writeInt32(0)};spike.PacketWriter.prototype.writeArrayOfUInt64=function(n){var i=typeof n,t;if(i=="object"&&n instanceof Array){if(this.writeInt32(n.length),n.length==0)return;for(t=0;t<n.length;++t)this.writeUInt64(n[t])}else this.writeInt32(0)};spike.PacketWriter.prototype.writeArrayOfDouble=function(n){var i=typeof n,t;if(i=="object"&&n instanceof Array){if(this.writeInt32(n.length),n.length==0)return;for(t=0;t<n.length;++t)this.writeDouble(n[t])}else this.writeInt32(0)};spike.PacketWriter.prototype.writeArrayOfSingle=function(n){var i=typeof n,t;if(i=="object"&&n instanceof Array){if(this.writeInt32(n.length),n.length==0)return;for(t=0;t<n.length;++t)this.writeSingle(n[t])}else this.writeInt32(0)};spike.PacketWriter.prototype.writeArrayOfDateTime=function(n){var i=typeof n,t;if(i=="object"&&n instanceof Array){if(this.writeInt32(n.length),n.length==0)return;for(t=0;t<n.length;++t)this.writeDateTime(n[t])}else this.writeInt32(0)};spike.PacketWriter.prototype.writeArrayOfString=function(n){var i=typeof n,t;if(i=="object"&&n instanceof Array){if(this.writeInt32(n.length),n.length==0)return;for(t=0;t<n.length;++t)this.writeString(n[t])}else this.writeInt32(0)};spike.PacketWriter.prototype.writeArrayOfBoolean=function(n){var i=typeof n,t;if(i=="object"&&n instanceof Array){if(this.writeInt32(n.length),n.length==0)return;for(t=0;t<n.length;++t)this.writeBoolean(n[t])}else this.writeInt32(0)};spike.PacketWriter.prototype.writeArrayOfDynamicType=function(n){var i=typeof n,t;if(i=="object"&&n instanceof Array){if(this.writeInt32(n.length),n.length==0)return;for(t=0;t<n.length;++t)this.writeDynamicType(n[t])}else this.writeInt32(0)};spike.PacketWriter.prototype.writeArray=function(n){var i=typeof n,t;if(i=="object"&&n instanceof Array){if(this.writeInt32(n.length),n.length==0)return;for(t=0;t<n.length;++t)if(n[t].write!="undefined")n[t].write(this);else throw"Unable to write, the array contains unknown elements";}else this.writeInt32(0)};spike.PacketReader=function(n){this.buffer=n};spike.PacketReader.prototype.decompress=function(){this.buffer=(new spike.PacketCompressor).decompress(this.buffer,this.buffer.getSize());this.buffer.position=0};spike.PacketReader.prototype.readBoolean=function(){return this.buffer.readInt(8,!1)==1};spike.PacketReader.prototype.readByte=function(){return this.buffer.readInt(8,!1)};spike.PacketReader.prototype.readSByte=function(){return this.buffer.readInt(8,!0)};spike.PacketReader.prototype.readInt16=function(){return this.buffer.readInt(16,!0)};spike.PacketReader.prototype.readInt32=function(){return this.buffer.readInt(32,!0)};spike.PacketReader.prototype.readInt64=function(){return this.buffer.readInt(64,!0)};spike.PacketReader.prototype.readUInt16=function(){return this.buffer.readInt(16,!1)};spike.PacketReader.prototype.readUInt32=function(){return this.buffer.readInt(32,!1)};spike.PacketReader.prototype.readUInt64=function(){return this.buffer.readInt(64,!1)};spike.PacketReader.prototype.readDateTime=function(){var n=this.readInt16(),t=this.readInt16()-1,i=this.readInt16(),r=this.readInt16(),u=this.readInt16(),f=this.readInt16(),e=this.readInt16();return new Date(n,t,i,r,u,f,e)};spike.PacketReader.prototype.readSingle=function(){return this.buffer.readFloat(23,8)};spike.PacketReader.prototype.readDouble=function(){return this.buffer.readFloat(52,11)};spike.PacketReader.prototype.readString=function(){var t=this.readInt32(),n;return t>0?(n=this.buffer.readBytes(t),spike.binarySupport?decodeURIComponent(escape(String.fromCharCode.apply(null,n))):decodeURIComponent(escape(n))):""};spike.PacketReader.prototype.readDynamicType=function(){if(this.readByte()==1){var n=this.readString();switch(n){case"Byte":return this.readByte();case"Int16":return this.readInt16();case"Int32":return this.readInt32();case"Int64":return this.readInt64();case"UInt16":return this.readUInt16();case"UInt32":return this.readUInt32();case"UInt64":return this.readUInt64();case"Boolean":return this.readBoolean();case"Single":return this.readSingle();case"Double":return this.readDouble();case"DateTime":return this.readDateTime();case"String":return this.readString();default:return null}}return null};spike.PacketReader.prototype.readPacket=function(n){return n.read(this),n};spike.PacketReader.prototype.readEntity=function(n){return n.read(this),n};spike.PacketReader.prototype.readArrayOfByte=function(){var t=this.readInt32(),n=new spike.ByteArray;return n.writeBytes(this.buffer.readBytes(t)),n.position=0,n};spike.PacketReader.prototype.readArrayOfEntity=function(n){var r=this.readInt32(),f="new "+n+"()",t=[],i,u;if(r==0)return t;for(i=0;i<r;++i)u=eval(f),t.push(this.readEntity(u));return t};spike.PacketReader.prototype.readArrayOfUInt16=function(){for(var i=this.readInt32(),t=[],n=0;n<i;++n)t.push(this.readUInt16());return t};spike.PacketReader.prototype.readArrayOfInt16=function(){for(var i=this.readInt32(),t=[],n=0;n<i;++n)t.push(this.readInt16());return t};spike.PacketReader.prototype.readArrayOfUInt32=function(){for(var i=this.readInt32(),t=[],n=0;n<i;++n)t.push(this.readUInt32());return t};spike.PacketReader.prototype.readArrayOfInt32=function(){for(var i=this.readInt32(),t=[],n=0;n<i;++n)t.push(this.readInt32());return t};spike.PacketReader.prototype.readArrayOfUInt64=function(){for(var i=this.readInt32(),t=[],n=0;n<i;++n)t.push(this.readUInt64());return t};spike.PacketReader.prototype.readArrayOfInt64=function(){for(var i=this.readInt32(),t=[],n=0;n<i;++n)t.push(this.readInt64());return t};spike.PacketReader.prototype.readArrayOfSingle=function(){for(var i=this.readInt32(),t=[],n=0;n<i;++n)t.push(this.readSingle());return t};spike.PacketReader.prototype.readArrayOfDouble=function(){for(var i=this.readInt32(),t=[],n=0;n<i;++n)t.push(this.readDouble());return t};spike.PacketReader.prototype.readArrayOfBoolean=function(){for(var i=this.readInt32(),t=[],n=0;n<i;++n)t.push(this.readBoolean());return t};spike.PacketReader.prototype.readArrayOfDateTime=function(){for(var i=this.readInt32(),t=[],n=0;n<i;++n)t.push(this.readDateTime());return t};spike.PacketReader.prototype.readArrayOfString=function(){for(var i=this.readInt32(),t=[],n=0;n<i;++n)t.push(this.readString());return t};spike.PacketReader.prototype.readArrayOfDynamicType=function(){for(var i=this.readInt32(),t=[],n=0;n<i;++n)t.push(this.readDynamicType());return t};!function(n){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define([],n);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self);t.eio=n()}}(function(){var n;return function t(n,i,r){function f(u,o){var h,c,s;if(!i[u]){if(!n[u]){if(h=typeof require=="function"&&require,!o&&h)return h(u,!0);if(e)return e(u,!0);c=new Error("Cannot find module '"+u+"'");throw c.code="MODULE_NOT_FOUND",c;}s=i[u]={exports:{}};n[u][0].call(s.exports,function(t){var i=n[u][1][t];return f(i?i:t)},s,s.exports,t,n,i,r)}return i[u].exports}for(var e=typeof require=="function"&&require,u=0;u<r.length;u++)f(r[u]);return f}({1:[function(n,t){t.exports=n("./lib/")},{"./lib/":2}],2:[function(n,t){t.exports=n("./socket");t.exports.parser=n("engine.io-parser")},{"./socket":3,"engine.io-parser":17}],3:[function(n,t){(function(i){function r(n,t){if(!(this instanceof r))return new r(n,t);if(t=t||{},n&&"object"==typeof n&&(t=n,n=null),n&&(n=h(n),t.host=n.host,t.secure=n.protocol=="https"||n.protocol=="wss",t.port=n.port,n.query&&(t.query=n.query)),this.secure=null!=t.secure?t.secure:i.location&&"https:"==location.protocol,t.host){var u=t.host.split(":");t.hostname=u.shift();u.length&&(t.port=u.pop())}this.agent=t.agent||!1;this.hostname=t.hostname||(i.location?location.hostname:"localhost");this.port=t.port||(i.location&&location.port?location.port:this.secure?443:80);this.query=t.query||{};"string"==typeof this.query&&(this.query=l.decode(this.query));this.upgrade=!1!==t.upgrade;this.path=(t.path||"/engine.io").replace(/\/$/,"")+"/";this.forceJSONP=!!t.forceJSONP;this.jsonp=!1!==t.jsonp;this.forceBase64=!!t.forceBase64;this.enablesXDR=!!t.enablesXDR;this.timestampParam=t.timestampParam||"t";this.timestampRequests=t.timestampRequests;this.transports=t.transports||["polling","websocket"];this.readyState="";this.writeBuffer=[];this.callbackBuffer=[];this.policyPort=t.policyPort||843;this.rememberUpgrade=t.rememberUpgrade||!1;this.open();this.binaryType=null;this.onlyBinaryUpgrades=t.onlyBinaryUpgrades}function a(n){var i={},t;for(t in n)n.hasOwnProperty(t)&&(i[t]=n[t]);return i}var e=n("./transports"),o=n("component-emitter"),u=n("debug")("engine.io-client:socket"),s=n("indexof"),f=n("engine.io-parser"),h=n("parseuri"),c=n("parsejson"),l=n("parseqs");t.exports=r;r.priorWebsocketSuccess=!1;o(r.prototype);r.protocol=f.protocol;r.Socket=r;r.Transport=n("./transport");r.transports=n("./transports");r.parser=n("engine.io-parser");r.prototype.createTransport=function(n){var t;return u('creating transport "%s"',n),t=a(this.query),t.EIO=f.protocol,t.transport=n,this.id&&(t.sid=this.id),new e[n]({agent:this.agent,hostname:this.hostname,port:this.port,secure:this.secure,path:this.path,query:t,forceJSONP:this.forceJSONP,jsonp:this.jsonp,forceBase64:this.forceBase64,enablesXDR:this.enablesXDR,timestampRequests:this.timestampRequests,timestampParam:this.timestampParam,policyPort:this.policyPort,socket:this})};r.prototype.open=function(){var t,n;if(this.rememberUpgrade&&r.priorWebsocketSuccess&&this.transports.indexOf("websocket")!=-1)n="websocket";else{if(0==this.transports.length){t=this;setTimeout(function(){t.emit("error","No transports available")},0);return}n=this.transports[0]}this.readyState="opening";try{n=this.createTransport(n)}catch(i){this.transports.shift();this.open();return}n.open();this.setTransport(n)};r.prototype.setTransport=function(n){u("setting transport %s",n.name);var t=this;this.transport&&(u("clearing existing transport %s",this.transport.name),this.transport.removeAllListeners());this.transport=n;n.on("drain",function(){t.onDrain()}).on("packet",function(n){t.onPacket(n)}).on("error",function(n){t.onError(n)}).on("close",function(){t.onClose("transport close")})};r.prototype.probe=function(n){function o(){if(i.onlyBinaryUpgrades){var e=!this.supportsBinary&&i.transport.supportsBinary;f=f||e}if(!f){u('probe transport "%s" opened',n);t.send([{type:"ping",data:"probe"}]);t.once("packet",function(e){if(!f)if("pong"==e.type&&"probe"==e.data){if(u('probe transport "%s" pong',n),i.upgrading=!0,i.emit("upgrading",t),!t)return;r.priorWebsocketSuccess="websocket"==t.name;u('pausing current transport "%s"',i.transport.name);i.transport.pause(function(){f||"closed"!=i.readyState&&(u("changing transport and sending upgrade packet"),a(),i.setTransport(t),t.send([{type:"upgrade"}]),i.emit("upgrade",t),t=null,i.upgrading=!1,i.flush())})}else{u('probe transport "%s" failed',n);var o=new Error("probe error");o.transport=t.name;i.emit("upgradeError",o)}})}}function s(){f||(f=!0,a(),t.close(),t=null)}function e(r){var f=new Error("probe error: "+r);f.transport=t.name;s();u('probe transport "%s" failed because of error: %s',n,r);i.emit("upgradeError",f)}function h(){e("transport closed")}function c(){e("socket closed")}function l(n){t&&n.name!=t.name&&(u('"%s" works - aborting "%s"',n.name,t.name),s())}function a(){t.removeListener("open",o);t.removeListener("error",e);t.removeListener("close",h);i.removeListener("close",c);i.removeListener("upgrading",l)}u('probing transport "%s"',n);var t=this.createTransport(n,{probe:1}),f=!1,i=this;r.priorWebsocketSuccess=!1;t.once("open",o);t.once("error",e);t.once("close",h);this.once("close",c);this.once("upgrading",l);t.open()};r.prototype.onOpen=function(){if(u("socket open"),this.readyState="open",r.priorWebsocketSuccess="websocket"==this.transport.name,this.emit("open"),this.flush(),"open"==this.readyState&&this.upgrade&&this.transport.pause){u("starting upgrade probes");for(var n=0,t=this.upgrades.length;n<t;n++)this.probe(this.upgrades[n])}};r.prototype.onPacket=function(n){if("opening"==this.readyState||"open"==this.readyState){this.emit("packet",n);this.emit("heartbeat");switch(n.type){case"open":this.onHandshake(c(n.data));break;case"pong":this.setPing();break;case"error":var t=new Error("server error");t.code=n.data;this.emit("error",t);break;case"message":this.emit("data",n.data);this.emit("message",n.data)}}else u('packet received with socket readyState "%s"',this.readyState)};r.prototype.onHandshake=function(n){if(this.emit("handshake",n),this.id=n.sid,this.transport.query.sid=n.sid,this.upgrades=this.filterUpgrades(n.upgrades),this.pingInterval=n.pingInterval,this.pingTimeout=n.pingTimeout,this.onOpen(),"closed"!=this.readyState){this.setPing();this.removeListener("heartbeat",this.onHeartbeat);this.on("heartbeat",this.onHeartbeat)}};r.prototype.onHeartbeat=function(n){clearTimeout(this.pingTimeoutTimer);var t=this;t.pingTimeoutTimer=setTimeout(function(){if("closed"!=t.readyState)t.onClose("ping timeout")},n||t.pingInterval+t.pingTimeout)};r.prototype.setPing=function(){var n=this;clearTimeout(n.pingIntervalTimer);n.pingIntervalTimer=setTimeout(function(){u("writing ping packet - expecting pong within %sms",n.pingTimeout);n.ping();n.onHeartbeat(n.pingTimeout)},n.pingInterval)};r.prototype.ping=function(){this.sendPacket("ping")};r.prototype.onDrain=function(){for(var n=0;n<this.prevBufferLen;n++)this.callbackBuffer[n]&&this.callbackBuffer[n]();this.writeBuffer.splice(0,this.prevBufferLen);this.callbackBuffer.splice(0,this.prevBufferLen);this.prevBufferLen=0;this.writeBuffer.length==0?this.emit("drain"):this.flush()};r.prototype.flush=function(){"closed"!=this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length&&(this.transport.send(this.writeBuffer),this.prevBufferLen=this.writeBuffer.length,this.emit("flush"))};r.prototype.write=r.prototype.send=function(n,t){return this.sendPacket("message",n,t),this};r.prototype.sendPacket=function(n,t,i){if("closing"!=this.readyState&&"closed"!=this.readyState){var r={type:n,data:t};this.emit("packetCreate",r);this.writeBuffer.push(r);this.callbackBuffer.push(i);this.flush()}};r.prototype.close=function(){if("opening"==this.readyState||"open"==this.readyState){this.readyState="closing";var n=this;function i(){n.onClose("forced close");u("socket closing - telling transport to close");n.transport.close()}function t(){n.removeListener("upgrade",t);n.removeListener("upgradeError",t);i()}function r(){n.once("upgrade",t);n.once("upgradeError",t)}if(this.writeBuffer.length)this.once("drain",function(){this.upgrading?r():i()});else this.upgrading?r():i()}return this};r.prototype.onError=function(n){u("socket error %j",n);r.priorWebsocketSuccess=!1;this.emit("error",n);this.onClose("transport error",n)};r.prototype.onClose=function(n,t){if("opening"==this.readyState||"open"==this.readyState||"closing"==this.readyState){u('socket close with reason: "%s"',n);var i=this;clearTimeout(this.pingIntervalTimer);clearTimeout(this.pingTimeoutTimer);setTimeout(function(){i.writeBuffer=[];i.callbackBuffer=[];i.prevBufferLen=0},0);this.transport.removeAllListeners("close");this.transport.close();this.transport.removeAllListeners();this.readyState="closed";this.id=null;this.emit("close",n,t)}};r.prototype.filterUpgrades=function(n){for(var i=[],t=0,r=n.length;t<r;t++)~s(this.transports,n[t])&&i.push(n[t]);return i}}).call(this,typeof self!="undefined"?self:typeof window!="undefined"?window:{})},{"./transport":4,"./transports":5,"component-emitter":12,debug:14,"engine.io-parser":17,indexof:25,parsejson:26,parseqs:27,parseuri:28}],4:[function(n,t){function i(n){this.path=n.path;this.hostname=n.hostname;this.port=n.port;this.secure=n.secure;this.query=n.query;this.timestampParam=n.timestampParam;this.timestampRequests=n.timestampRequests;this.readyState="";this.agent=n.agent||!1;this.socket=n.socket;this.enablesXDR=n.enablesXDR}var r=n("engine.io-parser"),u=n("component-emitter");t.exports=i;u(i.prototype);i.timestamps=0;i.prototype.onError=function(n,t){var i=new Error(n);return i.type="TransportError",i.description=t,this.emit("error",i),this};i.prototype.open=function(){return("closed"==this.readyState||""==this.readyState)&&(this.readyState="opening",this.doOpen()),this};i.prototype.close=function(){return("opening"==this.readyState||"open"==this.readyState)&&(this.doClose(),this.onClose()),this};i.prototype.send=function(n){if("open"==this.readyState)this.write(n);else throw new Error("Transport not open");};i.prototype.onOpen=function(){this.readyState="open";this.writable=!0;this.emit("open")};i.prototype.onData=function(n){var t=r.decodePacket(n,this.socket.binaryType);this.onPacket(t)};i.prototype.onPacket=function(n){this.emit("packet",n)};i.prototype.onClose=function(){this.readyState="closed";this.emit("close")}},{"component-emitter":12,"engine.io-parser":17}],5:[function(n,t,i){(function(t){function o(n){var o,s=!1,h=!1,c=!1!==n.jsonp,e,i;if(t.location&&(e="https:"==location.protocol,i=location.port,i||(i=e?443:80),s=n.hostname!=location.hostname||i!=n.port,h=n.secure!=e),n.xdomain=s,n.xscheme=h,o=new r(n),"open"in o&&!n.forceJSONP)return new u(n);if(!c)throw new Error("JSONP disabled");return new f(n)}var r=n("xmlhttprequest"),u=n("./polling-xhr"),f=n("./polling-jsonp"),e=n("./websocket");i.polling=o;i.websocket=e}).call(this,typeof self!="undefined"?self:typeof window!="undefined"?window:{})},{"./polling-jsonp":6,"./polling-xhr":7,"./websocket":9,xmlhttprequest:10}],6:[function(n,t){(function(i){function h(){}function r(n){f.call(this,n);this.query=this.query||{};u||(i.___eio||(i.___eio=[]),u=i.___eio);this.index=u.length;var t=this;u.push(function(n){t.onData(n)});this.query.j=this.index;i.document&&i.addEventListener&&i.addEventListener("beforeunload",function(){t.script&&(t.script.onerror=h)},!1)}var f=n("./polling"),e=n("component-inherit");t.exports=r;var o=/\n/g,s=/\\n/g,u;e(r,f);r.prototype.supportsBinary=!1;r.prototype.doClose=function(){this.script&&(this.script.parentNode.removeChild(this.script),this.script=null);this.form&&(this.form.parentNode.removeChild(this.form),this.form=null,this.iframe=null);f.prototype.doClose.call(this)};r.prototype.doPoll=function(){var r=this,n=document.createElement("script"),t,i;this.script&&(this.script.parentNode.removeChild(this.script),this.script=null);n.async=!0;n.src=this.uri();n.onerror=function(n){r.onError("jsonp poll error",n)};t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(n,t);this.script=n;i="undefined"!=typeof navigator&&/gecko/i.test(navigator.userAgent);i&&setTimeout(function(){var n=document.createElement("iframe");document.body.appendChild(n);document.body.removeChild(n)},100)};r.prototype.doWrite=function(n,t){function e(){h();t()}function h(){if(i.iframe)try{i.form.removeChild(i.iframe)}catch(n){i.onError("jsonp polling iframe removal error",n)}try{var t='<iframe src="javascript:0" name="'+i.iframeId+'">';u=document.createElement(t)}catch(n){u=document.createElement("iframe");u.name=i.iframeId;u.src="javascript:0"}u.id=i.iframeId;i.form.appendChild(u);i.iframe=u}var i=this;if(!this.form){var r=document.createElement("form"),f=document.createElement("textarea"),c=this.iframeId="eio_iframe_"+this.index,u;r.className="socketio";r.style.position="absolute";r.style.top="-1000px";r.style.left="-1000px";r.target=c;r.method="POST";r.setAttribute("accept-charset","utf-8");f.name="d";r.appendChild(f);document.body.appendChild(r);this.form=r;this.area=f}this.form.action=this.uri();h();n=n.replace(s,"\\\n");this.area.value=n.replace(o,"\\n");try{this.form.submit()}catch(l){}this.iframe.attachEvent?this.iframe.onreadystatechange=function(){i.iframe.readyState=="complete"&&e()}:this.iframe.onload=e}}).call(this,typeof self!="undefined"?self:typeof window!="undefined"?window:{})},{"./polling":8,"component-inherit":13}],7:[function(n,t){(function(i){function s(){}function u(n){if(e.call(this,n),i.location){var r="https:"==location.protocol,t=location.port;t||(t=r?443:80);this.xd=n.hostname!=i.location.hostname||t!=n.port;this.xs=n.secure!=r}}function r(n){this.method=n.method||"GET";this.uri=n.uri;this.xd=!!n.xd;this.xs=!!n.xs;this.async=!1!==n.async;this.data=undefined!=n.data?n.data:null;this.agent=n.agent;this.isBinary=n.isBinary;this.supportsBinary=n.supportsBinary;this.enablesXDR=n.enablesXDR;this.create()}function h(){for(var n in r.requests)r.requests.hasOwnProperty(n)&&r.requests[n].abort()}var c=n("xmlhttprequest"),e=n("./polling"),o=n("component-emitter"),l=n("component-inherit"),f=n("debug")("engine.io-client:polling-xhr");typeof spike=="undefined"&&(spike={});spike.Emitter=o;spike.debug=n("debug")("spike");t.exports=u;t.exports.Request=r;l(u,e);u.prototype.supportsBinary=!0;u.prototype.request=function(n){return n=n||{},n.uri=this.uri(),n.xd=this.xd,n.xs=this.xs,n.agent=this.agent||!1,n.supportsBinary=this.supportsBinary,n.enablesXDR=this.enablesXDR,new r(n)};u.prototype.doWrite=function(n,t){var r=typeof n!="string"&&n!==undefined,i=this.request({method:"POST",data:n,isBinary:r}),u=this;i.on("success",t);i.on("error",function(n){u.onError("xhr post error",n)});this.sendXhr=i};u.prototype.doPoll=function(){f("xhr poll");var n=this.request(),t=this;n.on("data",function(n){t.onData(n)});n.on("error",function(n){t.onError("xhr poll error",n)});this.pollXhr=n};o(r.prototype);r.prototype.create=function(){var n=this.xhr=new c({agent:this.agent,xdomain:this.xd,xscheme:this.xs,enablesXDR:this.enablesXDR}),t=this;try{if(f("xhr open %s: %s",this.method,this.uri),n.open(this.method,this.uri,this.async),this.supportsBinary&&(n.responseType="arraybuffer"),"POST"==this.method)try{this.isBinary?n.setRequestHeader("Content-type","application/octet-stream"):n.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(u){}"withCredentials"in n&&(n.withCredentials=!0);this.hasXDR()?(n.onload=function(){t.onLoad()},n.onerror=function(){t.onError(n.responseText)}):n.onreadystatechange=function(){4==n.readyState&&(200==n.status||1223==n.status?t.onLoad():setTimeout(function(){t.onError(n.status)},0))};f("xhr data %s",this.data);n.send(this.data)}catch(u){setTimeout(function(){t.onError(u)},0);return}i.document&&(this.index=r.requestsCount++,r.requests[this.index]=this)};r.prototype.onSuccess=function(){this.emit("success");this.cleanup()};r.prototype.onData=function(n){this.emit("data",n);this.onSuccess()};r.prototype.onError=function(n){this.emit("error",n);this.cleanup()};r.prototype.cleanup=function(){if("undefined"!=typeof this.xhr&&null!==this.xhr){this.hasXDR()?this.xhr.onload=this.xhr.onerror=s:this.xhr.onreadystatechange=s;try{this.xhr.abort()}catch(n){}i.document&&delete r.requests[this.index];this.xhr=null}};r.prototype.onLoad=function(){var n,t;try{try{t=this.xhr.getResponseHeader("Content-Type").split(";")[0]}catch(i){}n=t==="application/octet-stream"?this.xhr.response:this.supportsBinary?"ok":this.xhr.responseText}catch(i){this.onError(i)}if(null!=n)this.onData(n)};r.prototype.hasXDR=function(){return"undefined"!=typeof i.XDomainRequest&&!this.xs&&this.enablesXDR};r.prototype.abort=function(){this.cleanup()};i.document&&(r.requestsCount=0,r.requests={},i.attachEvent?i.attachEvent("onunload",h):i.addEventListener&&i.addEventListener("beforeunload",h,!1))}).call(this,typeof self!="undefined"?self:typeof window!="undefined"?window:{})},{"./polling":8,"component-emitter":12,"component-inherit":13,debug:14,xmlhttprequest:10}],8:[function(n,t){function r(n){var t=n&&n.forceBase64;(!e||t)&&(this.supportsBinary=!1);u.call(this,n)}var u=n("../transport"),o=n("parseqs"),f=n("engine.io-parser"),s=n("component-inherit"),i=n("debug")("engine.io-client:polling"),e;t.exports=r;e=function(){var t=n("xmlhttprequest"),i=new t({xdomain:!1});return null!=i.responseType}();s(r,u);r.prototype.name="polling";r.prototype.doOpen=function(){this.poll()};r.prototype.pause=function(n){function r(){i("paused");u.readyState="paused";n()}var u=this,t;if(this.readyState="pausing",this.polling||!this.writable){if(t=0,this.polling){i("we are currently polling - waiting to pause");t++;this.once("pollComplete",function(){i("pre-pause polling complete");--t||r()})}if(!this.writable){i("we are currently writing - waiting to pause");t++;this.once("drain",function(){i("pre-pause writing complete");--t||r()})}}else r()};r.prototype.poll=function(){i("polling");this.polling=!0;this.doPoll();this.emit("poll")};r.prototype.onData=function(n){var t=this,r;i("polling got data %s",n);r=function(n){if("opening"==t.readyState&&t.onOpen(),"close"==n.type)return t.onClose(),!1;t.onPacket(n)};f.decodePayload(n,this.socket.binaryType,r);"closed"!=this.readyState&&(this.polling=!1,this.emit("pollComplete"),"open"==this.readyState?this.poll():i('ignoring poll - transport state "%s"',this.readyState))};r.prototype.doClose=function(){function n(){i("writing close packet");t.write([{type:"close"}])}var t=this;if("open"==this.readyState)i("transport open - closing"),n();else{i("transport not open - deferring close");this.once("open",n)}};r.prototype.write=function(n){var t=this,i;this.writable=!1;i=function(){t.writable=!0;t.emit("drain")};t=this;f.encodePayload(n,this.supportsBinary,function(n){t.doWrite(n,i)})};r.prototype.uri=function(){var n=this.query||{},t=this.secure?"https":"http",i="";return!1!==this.timestampRequests&&(n[this.timestampParam]=+new Date+"-"+u.timestamps++),this.supportsBinary||n.sid||(n.b64=1),n=o.encode(n),this.port&&("https"==t&&this.port!=443||"http"==t&&this.port!=80)&&(i=":"+this.port),n.length&&(n="?"+n),t+"://"+this.hostname+i+this.path+n}},{"../transport":4,"component-inherit":13,debug:14,"engine.io-parser":17,parseqs:27,xmlhttprequest:10}],9:[function(n,t){function i(n){var t=n&&n.forceBase64;t&&(this.supportsBinary=!1);r.call(this,n)}var r=n("../transport"),f=n("engine.io-parser"),e=n("parseqs"),o=n("component-inherit"),s=n("debug")("engine.io-client:websocket"),u=n("ws");t.exports=i;o(i,r);i.prototype.name="websocket";i.prototype.supportsBinary=!0;i.prototype.doOpen=function(){if(this.check()){var i=this,n=this.uri(),t={agent:this.agent};this.ws=new u(n,void 0,t);this.ws.binaryType===undefined&&(this.supportsBinary=!1);this.ws.binaryType="arraybuffer";this.addEventListeners()}};i.prototype.addEventListeners=function(){var n=this;this.ws.onopen=function(){n.onOpen()};this.ws.onclose=function(){n.onClose()};this.ws.onmessage=function(t){n.onData(t.data)};this.ws.onerror=function(t){n.onError("websocket error",t)}};"undefined"!=typeof navigator&&/iPad|iPhone|iPod/i.test(navigator.userAgent)&&(i.prototype.onData=function(n){var t=this;setTimeout(function(){r.prototype.onData.call(t,n)},0)});i.prototype.write=function(n){function u(){i.writable=!0;i.emit("drain")}var i=this,t,r;for(this.writable=!1,t=0,r=n.length;t<r;t++)f.encodePacket(n[t],this.supportsBinary,function(n){try{i.ws.send(n)}catch(t){s("websocket closed before onclose event")}});setTimeout(u,0)};i.prototype.onClose=function(){r.prototype.onClose.call(this)};i.prototype.doClose=function(){typeof this.ws!="undefined"&&this.ws.close()};i.prototype.uri=function(){var n=this.query||{},t=this.secure?"wss":"ws",i="";return this.port&&("wss"==t&&this.port!=443||"ws"==t&&this.port!=80)&&(i=":"+this.port),this.timestampRequests&&(n[this.timestampParam]=+new Date),this.supportsBinary||(n.b64=1),n=e.encode(n),n.length&&(n="?"+n),t+"://"+this.hostname+i+this.path+n};i.prototype.check=function(){return!!u&&!("__initialize"in u&&this.name===i.prototype.name)}},{"../transport":4,"component-inherit":13,debug:14,"engine.io-parser":17,parseqs:27,ws:29}],10:[function(n,t){var i=n("has-cors");t.exports=function(n){var t=n.xdomain,r=n.xscheme,u=n.enablesXDR;try{if("undefined"!=typeof XMLHttpRequest&&(!t||i))return new XMLHttpRequest}catch(f){}try{if("undefined"!=typeof XDomainRequest&&!r&&u)return new XDomainRequest}catch(f){}if(!t)try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(f){}}},{"has-cors":23}],11:[function(n,t){(function(n){function f(n,t){var r,u;for(t=t||{},r=new i,u=0;u<n.length;u++)r.append(n[u]);return t.type?r.getBlob(t.type):r.getBlob()}var i=n.BlobBuilder||n.WebKitBlobBuilder||n.MSBlobBuilder||n.MozBlobBuilder,r=function(){try{var n=new Blob(["hi"]);return n.size==2}catch(t){return!1}}(),u=i&&i.prototype.append&&i.prototype.getBlob;t.exports=function(){return r?n.Blob:u?f:undefined}()}).call(this,typeof self!="undefined"?self:typeof window!="undefined"?window:{})},{}],12:[function(n,t){function i(n){if(n)return r(n)}function r(n){for(var t in i.prototype)n[t]=i.prototype[t];return n}t.exports=i;i.prototype.on=i.prototype.addEventListener=function(n,t){return this._callbacks=this._callbacks||{},(this._callbacks[n]=this._callbacks[n]||[]).push(t),this};i.prototype.once=function(n,t){function i(){r.off(n,i);t.apply(this,arguments)}var r=this;this._callbacks=this._callbacks||{};i.fn=t;this.on(n,i);return this};i.prototype.off=i.prototype.removeListener=i.prototype.removeAllListeners=i.prototype.removeEventListener=function(n,t){var i,u,r;if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;if(i=this._callbacks[n],!i)return this;if(1==arguments.length)return delete this._callbacks[n],this;for(r=0;r<i.length;r++)if(u=i[r],u===t||u.fn===t){i.splice(r,1);break}return this};i.prototype.emit=function(n){var r,t,i,u;if(this._callbacks=this._callbacks||{},r=[].slice.call(arguments,1),t=this._callbacks[n],t)for(t=t.slice(0),i=0,u=t.length;i<u;++i)t[i].apply(this,r);return this};i.prototype.listeners=function(n){return this._callbacks=this._callbacks||{},this._callbacks[n]||[]};i.prototype.hasListeners=function(n){return!!this.listeners(n).length}},{}],13:[function(n,t){t.exports=function(n,t){var i=function(){};i.prototype=t.prototype;n.prototype=new i;n.prototype.constructor=n}},{}],14:[function(n,t,i){function u(){return"WebkitAppearance"in document.documentElement.style||window.console&&(console.firebug||console.exception&&console.table)||navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31}function f(){var n=arguments,t=this.useColors,r,u,f;return(n[0]=(t?"%c":"")+this.namespace+(t?" %c":" ")+n[0]+(t?"%c ":" ")+"+"+i.humanize(this.diff),!t)?n:(r="color: "+this.color,n=[n[0],r,"color: inherit"].concat(Array.prototype.slice.call(n,1)),u=0,f=0,n[0].replace(/%[a-z%]/g,function(n){"%"!==n&&(u++,"%c"===n&&(f=u))}),n.splice(f,0,r),n)}function e(){return"object"==typeof console&&"function"==typeof console.log&&Function.prototype.apply.call(console.log,console,arguments)}function o(n){try{null==n?localStorage.removeItem("debug"):localStorage.debug=n}catch(t){}}function r(){var n;try{n=localStorage.debug}catch(t){}return n}i=t.exports=n("./debug");i.log=e;i.formatArgs=f;i.save=o;i.load=r;i.useColors=u;i.colors=["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"];i.formatters.j=function(n){return JSON.stringify(n)};i.enable(r())},{"./debug":15}],15:[function(n,t,i){function f(){return i.colors[u++%i.colors.length]}function e(n){function u(){}function t(){var u=t,o=+new Date,h=o-(r||o),n,e,s;u.diff=h;u.prev=r;u.curr=o;r=o;null==u.useColors&&(u.useColors=i.useColors());null==u.color&&u.useColors&&(u.color=f());n=Array.prototype.slice.call(arguments);n[0]=i.coerce(n[0]);"string"!=typeof n[0]&&(n=["%o"].concat(n));e=0;n[0]=n[0].replace(/%([a-z%])/g,function(t,r){var f,o;return t==="%"?t:(e++,f=i.formatters[r],"function"==typeof f&&(o=n[e],t=f.call(u,o),n.splice(e,1),e--),t)});"function"==typeof i.formatArgs&&(n=i.formatArgs.apply(u,n));s=t.log||i.log||console.log.bind(console);s.apply(u,n)}u.enabled=!1;t.enabled=!0;var e=i.enabled(n)?t:u;return e.namespace=n,e}function o(n){var r,u,t;for(i.save(n),r=(n||"").split(/[\s,]+/),u=r.length,t=0;t<u;t++)r[t]&&(n=r[t].replace(/\*/g,".*?"),n[0]==="-"?i.skips.push(new RegExp("^"+n.substr(1)+"$")):i.names.push(new RegExp("^"+n+"$")))}function s(){i.enable("")}function h(n){for(var t=0,r=i.skips.length;t<r;t++)if(i.skips[t].test(n))return!1;for(t=0,r=i.names.length;t<r;t++)if(i.names[t].test(n))return!0;return!1}function c(n){return n instanceof Error?n.stack||n.message:n}i=t.exports=e;i.coerce=c;i.disable=s;i.enable=o;i.enabled=h;i.humanize=n("ms");i.names=[];i.skips=[];i.formatters={};var u=0,r},{ms:16}],16:[function(n,t){function s(n){var e=/^((?:\d+)?\.?\d+) *(ms|seconds?|s|minutes?|m|hours?|h|days?|d|years?|y)?$/i.exec(n),t,s;if(e){t=parseFloat(e[1]);s=(e[2]||"ms").toLowerCase();switch(s){case"years":case"year":case"y":return t*o;case"days":case"day":case"d":return t*f;case"hours":case"hour":case"h":return t*u;case"minutes":case"minute":case"m":return t*r;case"seconds":case"second":case"s":return t*i;case"ms":return t}}}function h(n){return n>=f?Math.round(n/f)+"d":n>=u?Math.round(n/u)+"h":n>=r?Math.round(n/r)+"m":n>=i?Math.round(n/i)+"s":n+"ms"}function c(n){return e(n,f,"day")||e(n,u,"hour")||e(n,r,"minute")||e(n,i,"second")||n+" ms"}function e(n,t,i){if(!(n<t))return n<t*1.5?Math.floor(n/t)+" "+i:Math.ceil(n/t)+" "+i+"s"}var i=1e3,r=i*60,u=r*60,f=u*24,o=f*365.25;t.exports=function(n,t){return(t=t||{},"string"==typeof n)?s(n):t.long?c(n):h(n)}},{}],17:[function(n,t,i){(function(t){function y(n,t,r){var u;if(!t)return i.encodeBase64Packet(n,r);var e=n.data,s=new Uint8Array(e),f=new Uint8Array(1+e.byteLength);for(f[0]=o[n.type],u=0;u<s.length;u++)f[u+1]=s[u];return r(f.buffer)}function p(n,t,r){if(!t)return i.encodeBase64Packet(n,r);var u=new FileReader;return u.onload=function(){n.data=u.result;i.encodePacket(n,t,!0,r)},u.readAsArrayBuffer(n.data)}function w(n,t,u){var f,e;return t?c?p(n,t,u):(f=new Uint8Array(1),f[0]=o[n.type],e=new r([f.buffer,n.data]),u(e)):i.encodeBase64Packet(n,u)}function s(n,t,i){for(var u=new Array(n.length),f=v(n.length,i),e=function(n,i,r){t(i,function(t,i){u[n]=i;r(t,u)})},r=0;r<n.length;r++)e(r,n[r],f)}var l=n("./keys"),e=n("arraybuffer.slice"),a=n("base64-arraybuffer"),v=n("after"),h=n("utf8"),c=navigator.userAgent.match(/Android/i);i.protocol=3;var o=i.packets={open:0,close:1,ping:2,pong:3,message:4,upgrade:5,noop:6},f=l(o),u={type:"error",data:"parser error"},r=n("blob");i.encodePacket=function(n,i,u,f){var e,s;return("function"==typeof i&&(f=i,i=!1),"function"==typeof u&&(f=u,u=null),e=n.data===undefined?undefined:n.data.buffer||n.data,t.ArrayBuffer&&e instanceof ArrayBuffer)?y(n,i,f):r&&e instanceof t.Blob?w(n,i,f):(s=o[n.type],undefined!==n.data&&(s+=u?h.encode(String(n.data)):String(n.data)),f(""+s))};i.encodeBase64Packet=function(n,u){var s="b"+i.packets[n.type],e,h,o,c,f;if(r&&n.data instanceof r)return e=new FileReader,e.onload=function(){var n=e.result.split(",")[1];u(s+n)},e.readAsDataURL(n.data);try{h=String.fromCharCode.apply(null,new Uint8Array(n.data))}catch(l){for(o=new Uint8Array(n.data),c=new Array(o.length),f=0;f<o.length;f++)c[f]=o[f];h=String.fromCharCode.apply(null,c)}return s+=t.btoa(h),u(s)};i.decodePacket=function(n,t,o){var s;if(typeof n=="string"||n===undefined){if(n.charAt(0)=="b")return i.decodeBase64Packet(n.substr(1),t);if(o)try{n=h.decode(n)}catch(a){return u}return(s=n.charAt(0),Number(s)!=s||!f[s])?u:n.length>1?{type:f[s],data:n.substring(1)}:{type:f[s]}}var l=new Uint8Array(n),s=l[0],c=e(n,1);return r&&t==="blob"&&(c=new r([c])),{type:f[s],data:c}};i.decodeBase64Packet=function(n,i){var e=f[n.charAt(0)],u;return t.ArrayBuffer?(u=a.decode(n.substr(1)),i==="blob"&&r&&(u=new r([u])),{type:e,data:u}):{type:e,data:{base64:!0,data:n.substr(1)}}};i.encodePayload=function(n,t,u){function f(n){return n.length+":"+n}function e(n,r){i.encodePacket(n,t,!0,function(n){r(null,f(n))})}if(typeof t=="function"&&(u=t,t=null),t)return r&&!c?i.encodePayloadAsBlob(n,u):i.encodePayloadAsArrayBuffer(n,u);if(!n.length)return u("0:");s(n,e,function(n,t){return u(t.join(""))})};i.decodePayload=function(n,t,r){var o,f,s,h,e,c,l,a;if(typeof n!="string")return i.decodePayloadAsBinary(n,t,r);if(typeof t=="function"&&(r=t,t=null),n=="")return r(u,0,1);for(f="",e=0,c=n.length;e<c;e++)if(l=n.charAt(e),":"!=l)f+=l;else{if(""==f||f!=(s=Number(f))||(h=n.substr(e+1,s),f!=h.length))return r(u,0,1);if(h.length){if(o=i.decodePacket(h,t,!0),u.type==o.type&&u.data==o.data)return r(u,0,1);if(a=r(o,e+s,c),!1===a)return}e+=s;f=""}if(f!="")return r(u,0,1)};i.encodePayloadAsArrayBuffer=function(n,t){function r(n,t){i.encodePacket(n,!0,!0,function(n){return t(null,n)})}if(!n.length)return t(new ArrayBuffer(0));s(n,r,function(n,i){var f=i.reduce(function(n,t){var i;return i=typeof t=="string"?t.length:t.byteLength,n+i.toString().length+i+2},0),r=new Uint8Array(f),u=0;return i.forEach(function(n){var o=typeof n=="string",f=n,e,i,t;if(o){for(i=new Uint8Array(n.length),t=0;t<n.length;t++)i[t]=n.charCodeAt(t);f=i.buffer}for(r[u++]=o?0:1,e=f.byteLength.toString(),t=0;t<e.length;t++)r[u++]=parseInt(e[t]);for(r[u++]=255,i=new Uint8Array(f),t=0;t<i.length;t++)r[u++]=i[t]}),t(r.buffer)})};i.encodePayloadAsBlob=function(n,t){function u(n,t){i.encodePacket(n,!0,!0,function(n){var f=new Uint8Array(1),e,i,s;if(f[0]=1,typeof n=="string"){for(e=new Uint8Array(n.length),i=0;i<n.length;i++)e[i]=n.charCodeAt(i);n=e.buffer;f[0]=0}var h=n instanceof ArrayBuffer?n.byteLength:n.size,u=h.toString(),o=new Uint8Array(u.length+1);for(i=0;i<u.length;i++)o[i]=parseInt(u[i]);o[u.length]=255;r&&(s=new r([f.buffer,o.buffer,n]),t(null,s))})}s(n,u,function(n,i){return t(new r(i))})};i.decodePayloadAsBinary=function(n,t,r){var h,a,f,y;typeof t=="function"&&(r=t,t=null);for(var o=n,c=[],v=!1;o.byteLength>0;){var l=new Uint8Array(o),p=l[0]===0,s="";for(f=1;;f++){if(l[f]==255)break;if(s.length>310){v=!0;break}s+=l[f]}if(v)return r(u,0,1);if(o=e(o,2+s.length),s=parseInt(s),h=e(o,0,s),p)try{h=String.fromCharCode.apply(null,new Uint8Array(h))}catch(w){for(a=new Uint8Array(h),h="",f=0;f<a.length;f++)h+=String.fromCharCode(a[f])}c.push(h);o=e(o,s)}y=c.length;c.forEach(function(n,u){r(i.decodePacket(n,t,!0),u,y)})}}).call(this,typeof self!="undefined"?self:typeof window!="undefined"?window:{})},{"./keys":18,after:19,"arraybuffer.slice":20,"base64-arraybuffer":21,blob:11,utf8:22}],18:[function(n,t){t.exports=Object.keys||function(n){var i=[],r=Object.prototype.hasOwnProperty,t;for(t in n)r.call(n,t)&&i.push(t);return i}},{}],19:[function(n,t){function i(n,t,i){function u(n,r){if(u.count<=0)throw new Error("after called too many times");--u.count;n?(f=!0,t(n),t=i):u.count!==0||f||t(null,r)}var f=!1;return i=i||r,u.count=n,n===0?t():u}function r(){}t.exports=i},{}],20:[function(n,t){t.exports=function(n,t,i){var r=n.byteLength,o,f,u,e;if(t=t||0,i=i||r,n.slice)return n.slice(t,i);if(t<0&&(t+=r),i<0&&(i+=r),i>r&&(i=r),t>=r||t>=i||r===0)return new ArrayBuffer(0);for(o=new Uint8Array(n),f=new Uint8Array(i-t),u=t,e=0;u<i;u++,e++)f[e]=o[u];return f.buffer}},{}],21:[function(n,t,i){(function(n){"use strict";i.encode=function(t){for(var u=new Uint8Array(t),f=u.length,i="",r=0;r<f;r+=3)i+=n[u[r]>>2],i+=n[(u[r]&3)<<4|u[r+1]>>4],i+=n[(u[r+1]&15)<<2|u[r+2]>>6],i+=n[u[r+2]&63];return f%3==2?i=i.substring(0,i.length-1)+"=":f%3==1&&(i=i.substring(0,i.length-2)+"=="),i};i.decode=function(t){var u=t.length*.75,l=t.length,i,f=0,h,e,o,c,s,r;for(t[t.length-1]==="="&&(u--,t[t.length-2]==="="&&u--),s=new ArrayBuffer(u),r=new Uint8Array(s),i=0;i<l;i+=4)h=n.indexOf(t[i]),e=n.indexOf(t[i+1]),o=n.indexOf(t[i+2]),c=n.indexOf(t[i+3]),r[f++]=h<<2|e>>4,r[f++]=(e&15)<<4|o>>2,r[f++]=(o&3)<<6|c&63;return s}})("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")},{}],22:[function(t,i,r){(function(t){
/*! http://mths.be/utf8js v2.0.0 by @mathias */
(function(u){function w(n){for(var r=[],i=0,f=n.length,t,u;i<f;)t=n.charCodeAt(i++),t>=55296&&t<=56319&&i<f?(u=n.charCodeAt(i++),(u&64512)==56320?r.push(((t&1023)<<10)+(u&1023)+65536):(r.push(t),i--)):r.push(t);return r}function d(n){for(var u=n.length,r=-1,t,i="";++r<u;)t=n[r],t>65535&&(t-=65536,i+=f(t>>>10&1023|55296),t=56320|t&1023),i+=f(t);return i}function y(n,t){return f(n>>t&63|128)}function g(n){if((n&4294967168)==0)return f(n);var t="";return(n&4294965248)==0?t=f(n>>6&31|192):(n&4294901760)==0?t=f(n>>12&15|224)+y(n,6):(n&4292870144)==0&&(t=f(n>>18&7|240),t+=y(n,12),t+=y(n,6)),t+f(n&63|128)}function nt(n){for(var t=w(n),f=t.length,i=-1,r,u="";++i<f;)r=t[i],u+=g(r);return u}function s(){if(e>=a)throw Error("Invalid byte index");var n=l[e]&255;if(e++,(n&192)==128)return n&63;throw Error("Invalid continuation byte");}function tt(){var t,r,u,n,i;if(e>a)throw Error("Invalid byte index");if(e==a)return!1;if(t=l[e]&255,e++,(t&128)==0)return t;if((t&224)==192){if(i=s(),n=(t&31)<<6|i,n>=128)return n;throw Error("Invalid continuation byte");}if((t&240)==224){if(i=s(),r=s(),n=(t&15)<<12|i<<6|r,n>=2048)return n;throw Error("Invalid continuation byte");}if((t&248)==240&&(i=s(),r=s(),u=s(),n=(t&15)<<18|i<<12|r<<6|u,n>=65536&&n<=1114111))return n;throw Error("Invalid UTF-8 detected");}function it(n){l=w(n);a=l.length;e=0;for(var t=[],i;(i=tt())!==!1;)t.push(i);return d(t)}var c=typeof r=="object"&&r,p=typeof i=="object"&&i&&i.exports==c&&i,h=typeof t=="object"&&t,f,l,a,e,o,b,k,v;if((h.global===h||h.window===h)&&(u=h),f=String.fromCharCode,o={version:"2.0.0",encode:nt,decode:it},typeof n=="function"&&typeof n.amd=="object"&&n.amd)n(function(){return o});else if(c&&!c.nodeType)if(p)p.exports=o;else{b={};k=b.hasOwnProperty;for(v in o)k.call(o,v)&&(c[v]=o[v])}else u.utf8=o})(this)}).call(this,typeof self!="undefined"?self:typeof window!="undefined"?window:{})},{}],23:[function(n,t){var i=n("global");try{t.exports="XMLHttpRequest"in i&&"withCredentials"in new i.XMLHttpRequest}catch(r){t.exports=!1}},{global:24}],24:[function(n,t){t.exports=function(){return this}()},{}],25:[function(n,t){var i=[].indexOf;t.exports=function(n,t){if(i)return n.indexOf(t);for(var r=0;r<n.length;++r)if(n[r]===t)return r;return-1}},{}],26:[function(n,t){(function(n){var i=/^[\],:{}\s]*$/,r=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,u=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,f=/(?:^|:|,)(?:\s*\[)+/g,e=/^\s+/,o=/\s+$/;t.exports=function(t){return"string"!=typeof t||!t?null:(t=t.replace(e,"").replace(o,""),n.JSON&&JSON.parse)?JSON.parse(t):i.test(t.replace(r,"@").replace(u,"]").replace(f,""))?new Function("return "+t)():void 0}}).call(this,typeof self!="undefined"?self:typeof window!="undefined"?window:{})},{}],27:[function(n,t,i){i.encode=function(n){var t="",i;for(i in n)n.hasOwnProperty(i)&&(t.length&&(t+="&"),t+=encodeURIComponent(i)+"="+encodeURIComponent(n[i]));return t};i.decode=function(n){for(var r={},u=n.split("&"),i,t=0,f=u.length;t<f;t++)i=u[t].split("="),r[decodeURIComponent(i[0])]=decodeURIComponent(i[1]);return r}},{}],28:[function(n,t){var i=/^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,r=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];t.exports=function(n){var o=n,u=n.indexOf("["),f=n.indexOf("]");u!=-1&&f!=-1&&(n=n.substring(0,u)+n.substring(u,f).replace(/:/g,";")+n.substring(f,n.length));for(var s=i.exec(n||""),t={},e=14;e--;)t[r[e]]=s[e]||"";return u!=-1&&f!=-1&&(t.source=o,t.host=t.host.substring(1,t.host.length-1).replace(/;/g,":"),t.authority=t.authority.replace("[","").replace("]","").replace(/;/g,":"),t.ipv6uri=!0),t}},{}],29:[function(n,t){function u(n,t){return t?new i(n,t):new i(n)}var r=function(){return this}(),i=r.WebSocket||r.MozWebSocket;t.exports=i?u:null;i&&(u.prototype=i.prototype)},{}]},{},[1])(1)});spike.Channel=function(n,t){if(!(this instanceof spike.Channel))return new spike.Channel(n,t);n&&"object"==typeof n&&(t=n,n=undefined);t=t||{};t.path="/engine.io";var i=this;this.opts=t;this.subs=[];this.endPoint=n;this.buffer=new spike.ByteArray;this.readyState="closed";this.socket=null;this.transport="";this.autoConnect=t.autoConnect!==!1;this._partialRecord=!1;this.reconnection(t.reconnection!==!1);this.reconnectionAttempts(t.reconnectionAttempts||Infinity);this.reconnectionDelay(t.reconnectionDelay||1e3);this.reconnectionDelayMax(t.reconnectionDelayMax||1e4);this.randomizationFactor(t.randomizationFactor||.5);this.timeout(null==t.timeout?2e4:t.timeout);this.backoff=new spike.Backoff({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()});window.addEventListener("beforeunload",function(){try{i.disconnect();i.socket.transport.ws.onclose=function(){};i.socket.transport.ws.close()}catch(n){}});this.onConnect=null;this.onDisconnect=null;this.pingInform=null;this.getServerTimeInform=null;this.supplyCredentialsInform=null;this.revokeCredentialsInform=null;this.hubSubscribeInform=null;this.hubUnsubscribeInform=null;this.hubPublishInform=null;this.hubEventInform=null;this.autoConnect&&this.open()};spike.Channel.prototype.ping=function(n){var t=new spike.PacketWriter;t.writeInt32(n);this.send("B0AF6283",t)};spike.Channel.prototype.getServerTime=function(){var n=new spike.PacketWriter;this.send("33E7FBD1",n)};spike.Channel.prototype.supplyCredentials=function(n,t,i,r,u){var f=new spike.PacketWriter;f.writeString(n);f.writeString(t);f.writeString(i);f.writeString(r);f.writeString(u);f.compress();this.send("8D98E9FC",f)};spike.Channel.prototype.revokeCredentials=function(n,t){var i=new spike.PacketWriter;i.writeString(n);i.writeString(t);i.compress();this.send("4AC51818",i)};spike.Channel.prototype.hubSubscribe=function(n,t){var i=new spike.PacketWriter;i.writeString(n);i.writeString(t);i.compress();this.send("2DD19B9B",i)};spike.Channel.prototype.hubUnsubscribe=function(n,t){var i=new spike.PacketWriter;i.writeString(n);i.writeString(t);i.compress();this.send("6C63B75",i)};spike.Channel.prototype.hubPublish=function(n,t,i){var r=new spike.PacketWriter;r.writeString(n);r.writeString(t);r.writeString(i);r.compress();this.send("96B41079",r)};spike.Channel.prototype.onReceive=function(n,t){var i;switch(n){case"B0AF6283":i={};i.time=t.readInt32();this.pingInform!=null&&this.pingInform(i,this);this.emit("pingInform",i);this.emit("ping",i);break;case"33E7FBD1":t.decompress();i={};i.serverTime=t.readDateTime();this.getServerTimeInform!=null&&this.getServerTimeInform(i,this);this.emit("getServerTimeInform",i);this.emit("getServerTime",i);break;case"8D98E9FC":i={};i.result=t.readBoolean();this.supplyCredentialsInform!=null&&this.supplyCredentialsInform(i,this);this.emit("supplyCredentialsInform",i);this.emit("supplyCredentials",i);break;case"4AC51818":i={};i.result=t.readBoolean();this.revokeCredentialsInform!=null&&this.revokeCredentialsInform(i,this);this.emit("revokeCredentialsInform",i);this.emit("revokeCredentials",i);break;case"2DD19B9B":i={};i.status=t.readInt16();this.hubSubscribeInform!=null&&this.hubSubscribeInform(i,this);this.emit("hubSubscribeInform",i);this.emit("hubSubscribe",i);break;case"6C63B75":i={};i.status=t.readInt16();this.hubUnsubscribeInform!=null&&this.hubUnsubscribeInform(i,this);this.emit("hubUnsubscribeInform",i);this.emit("hubUnsubscribe",i);break;case"96B41079":i={};i.status=t.readInt16();this.hubPublishInform!=null&&this.hubPublishInform(i,this);this.emit("hubPublishInform",i);this.emit("hubPublish",i);break;case"65B2818C":t.decompress();i={};i.hubName=t.readString();i.message=t.readString();i.time=t.readDateTime();this.hubEventInform!=null&&this.hubEventInform(i,this);this.emit("hubEventInform",i);this.emit("hubEvent",i);break;default:throw new Error("Received an unknown packet with '"+n+"' key.");}};spike.Channel.prototype.send=function(n,t){var u;if(typeof n=="undefined")throw new Error("Attempting to send without specifying the operation.");if(typeof t=="undefined")throw new Error("Attempting to send an undefined buffer.");var r=t==null?0:t.buffer.getSize(),i=new spike.PacketWriter;i.writeUInt32(r+4);i.writeKey(n);r>0&&(t.buffer.position=0,i.buffer.writeBytes(t.buffer.readBytes(r)));u=spike.binarySupport?i.buffer.toBuffer():i.buffer.toBase64();this.socket.send(u)};spike.Channel.prototype.open=spike.Channel.prototype.connect=function(n){var t,r,u,f,i,e;if(~this.readyState.indexOf("open"))return this;this.socket=eio.Socket(this.endPoint);this.socket._channel=this;t=this;r=this.socket;this.readyState="opening";this.skipReconnect=!1;u=this.socket.on("open",function(){spike.debug("socket opened");this._channel.onopen();n&&n()});f=this.socket.on("error",function(i){if(spike.debug("socket error: %s",i),t.cleanup(),t.readyState="closed",t.emit("connect_error",i),n){var r=new Error("Connection error");r.data=i;n(r)}else t.maybeReconnectOnOpen()});!1!==this._timeout&&(i=this._timeout,spike.debug("connect attempt will timeout after %d",i),e=setTimeout(function(){t.readyState!="open"&&(spike.debug("connect attempt timed out after %d",i),r.close(),r.emit("error","timeout"),t.emit("connect_timeout",i))},i),this.subs.push({destroy:function(){clearTimeout(e)}}));this.socket.on("close",function(n){spike.debug("socket closed: "+n);t.transport=null;t.onDisconnect!=null&&t.onDisconnect();t.emit("disconnect");t.onclose(n)});this.socket.on("message",function(n){var o=4,t=new spike.ByteArray,i=this._channel,s,h,a,u,r,c,f,e,l;if(i._partialRecord&&(i.buffer.readBytesTo(t,i.buffer.getSize()),i._partialRecord=!1),typeof n=="string")t.writeBase64(n);else if(spike.binarySupport)t.writeBytes(new Uint8Array(n));else for(s=new Uint8Array(n),r=0;r<s.byteLength;++r)t.writeByte(s[r]);for(t.position=0;t.position<t.getSize();){if(t.getSize()-t.position<o){i.buffer=new spike.ByteArray;t.readBytesTo(i.buffer,t.getSize()-t.position);i._partialRecord=!0;break}if(h=t.readInt(32,!1)+o,t.position-=o,h<=t.getSize()-t.position){for(a=t.readInt(32,!1),u="",r=0;r<4;r++)c=t.readInt(8,!1),f=c.toString(16),f.length==1&&(f="0"+f),u+=f;u=u.toUpperCase();e=new spike.ByteArray;t.readBytesTo(e,h-8);e.position=0;l=new spike.PacketReader(e);i.onReceive(u,l)}else i.buffer=new spike.ByteArray,t.readBytesTo(i.buffer,t.getSize()-t.position),i._partialRecord=!0}});return this.subs.push(u),this.subs.push(f),this};spike.Channel.prototype.close=spike.Channel.prototype.disconnect=function(){this.skipReconnect=!0;this.readyState="closed";this.socket&&this.socket.close()};spike.Channel.prototype.onopen=function(){this.cleanup();this.readyState="open";this.onConnect!=null&&this.onConnect();this.emit("connect");this.emit("open")};spike.Channel.prototype.cleanup=function(){for(var n;n=this.subs.shift();)typeof n.destroy!="undefined"&&n.destroy()};spike.Channel.prototype.onclose=function(n){spike.debug("socket closed: %s",n);this.cleanup();this.backoff.reset();this.readyState="closed";this.emit("close",n);this._reconnection&&!this.skipReconnect&&this.reconnect()};spike.Backoff=function(n){n=n||{};this.ms=n.min||1e3;this.max=n.max||1e4;this.factor=n.factor||2;this.jitter=n.jitter>0&&n.jitter<=1?n.jitter:0;this.attempts=0};spike.Backoff.prototype.duration=function(){var n=this.ms*Math.pow(this.factor,this.attempts++),t,i;return this.jitter&&(t=Math.random(),i=Math.floor(t*this.jitter*n),n=(Math.floor(t*10)&1)==0?n-i:n+i),Math.min(n,this.max)|0};spike.Backoff.prototype.reset=function(){this.attempts=0};spike.Backoff.prototype.setMin=function(n){this.ms=n};spike.Backoff.prototype.setMax=function(n){this.max=n};spike.Backoff.prototype.setJitter=function(n){this.jitter=n};spike.Channel.prototype.onreconnect=function(){var n=this.backoff.attempts;this.reconnecting=!1;this.emit("reconnect",n)};spike.Channel.prototype.reconnection=function(n){return arguments.length?(this._reconnection=!!n,this):this._reconnection};spike.Channel.prototype.reconnectionAttempts=function(n){return arguments.length?(this._reconnectionAttempts=n,this):this._reconnectionAttempts};spike.Channel.prototype.reconnectionDelay=function(n){return arguments.length?(this._reconnectionDelay=n,this.backoff&&this.backoff.setMin(n),this):this._reconnectionDelay};spike.Channel.prototype.randomizationFactor=function(n){return arguments.length?(this._randomizationFactor=n,this.backoff&&this.backoff.setJitter(n),this):this._randomizationFactor};spike.Channel.prototype.reconnectionDelayMax=function(n){return arguments.length?(this._reconnectionDelayMax=n,this.backoff&&this.backoff.setMax(n),this):this._reconnectionDelayMax};spike.Channel.prototype.timeout=function(n){return arguments.length?(this._timeout=n,this):this._timeout};spike.Channel.prototype.maybeReconnectOnOpen=function(){!this.reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()};spike.Channel.prototype.reconnect=function(){var n,t,i;if(this.reconnecting||this.skipReconnect)return this;n=this;this.backoff.attempts>=this._reconnectionAttempts?(spike.debug("reconnect failed"),this.backoff.reset(),this.emit("reconnect_failed"),this.reconnecting=!1):(t=this.backoff.duration(),spike.debug("will wait %dms before reconnect attempt",t),this.reconnecting=!0,i=setTimeout(function(){n.skipReconnect||(spike.debug("attempting reconnect"),n.emit("reconnect_attempt",n.backoff.attempts),n.emit("reconnecting",n.backoff.attempts),n.skipReconnect)||n.open(function(t){t?(spike.debug("reconnect attempt error, %s",t),n.reconnecting=!1,n.reconnect(),n.emit("reconnect_error",t.data)):(spike.debug("reconnect success"),n.onreconnect())})},t),this.subs.push({destroy:function(){clearTimeout(i)}}))};spike.Emitter(spike.Channel.prototype);spike.ServerChannel=spike.Channel;spike.TcpChannel=spike.Channel

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer Misakai Ltd.
Ireland Ireland
Roman Atachiants, Ph.D. is the architect behind emitter.io service, a real-time, low-latency publish/subscribe service for IoT, Gaming. He is a software engineer and scientist with extensive experience in different computer science domains, programming languages/principles/patterns & frameworks.

His main expertise consists of C# and .NET platform, game technologies, cloud, human-computer interaction, big data and artificial intelligence. He has an extensive programming knowledge and R&D expertise.



Comments and Discussions