!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Colyseus=t():e.Colyseus=t()}("undefined"!=typeof self?self:this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=13)}([function(e,t,n){"use strict";function r(e,t,n,r){var i,o=!1;switch(t){case"number":case"int8":case"uint8":case"int16":case"uint16":case"int32":case"uint32":case"int64":case"uint64":case"float32":case"float64":i="number",isNaN(e)&&console.log('trying to encode "NaN" in '+n.constructor.name+"#"+r);break;case"string":i="string",o=!0;break;case"boolean":return}if(typeof e!==i&&(!o||o&&null!==e)){var s="'"+JSON.stringify(e)+"'"+(e&&e.constructor&&" ("+e.constructor.name+")");throw new d("a '"+i+"' was expected, but "+s+" was provided in "+n.constructor.name+"#"+r)}}function i(e,t,n,r){if(!(e instanceof t))throw new d("a '"+t.name+"' was expected, but '"+e.constructor.name+"' was provided in "+n.constructor.name+"#"+r)}function o(e,t,n,i,o){var s=u[e];return void 0===n?t.push(c.NIL):r(n,e,i,o),!!s&&(s(t,n),!0)}function s(e,t,n){var r=h[e];return r?r(t,n):null}var a=this&&this.__extends||function(){var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(t,n)};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(t,"__esModule",{value:!0});var c=n(10),u=n(31),h=n(32),f=n(1),l=n(2),p=n(11),d=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return a(t,e),t}(Error),v=function(){function e(){for(var e=[],t=0;t0;var m=!1;v.length>b&&Array.prototype.splice.call(v,b).forEach(function(t,n){if(t&&t.onRemove)try{t.onRemove()}catch(t){e.onError(t)}if(_.onRemove)try{_.onRemove(t,b+n)}catch(t){e.onError(t)}});for(var C=0;C0;for(var m=!1,P=Object.keys(I),C=0;C0)try{this.onChange(r)}catch(t){e.onError(t)}return this},e.prototype.encode=function(e,t,n){var r=this;void 0===e&&(e=this),void 0===t&&(t=!1);var s=[],a=function(){r!==e&&s.push(c.END_OF_STRUCTURE)};if(!this.$changes.changed&&!t)return a(),s;for(var h=this._schema,p=this._indexes,d=this._filters,v=t||n?this.$changes.allChanges:this.$changes.changes,y=this,g=0,_=v.length;g<_;g++)!function(a,g){var _=v[a],b=h[_],w=d&&d[_],m=y["_"+_],C=p[_];if(void 0===m)return"continue";var O=[];if(b._schema){if(n&&w&&!w.call(y,n,m,e))return"continue";u.number(O,C),m?(i(m,b,y,_),y.tryEncodeTypeId(O,b,m.constructor),O=O.concat(m.encode(e,t,n))):u.uint8(O,c.NIL)}else if(Array.isArray(b)){u.number(O,C),u.number(O,m.length);var S=(t||n?m.$changes.allChanges:m.$changes.changes).filter(function(e){return void 0!==r["_"+_][e]}).sort(function(e,t){return e-t}),A=S.length;u.number(O,A);var k="string"!=typeof b[0];i(y["_"+_],f.ArraySchema,y,_);for(var I=0;I=e+t-1});return i.map(function(e){e&&e.$changes&&(e.$changes.parent.deleteIndex(e),e.$changes.parent.deleteIndexChange(e),delete e.$changes.parent)}),o.forEach(function(e){e&&e.$changes&&e.$changes.parentField--}),i},t}(Array);t.ArraySchema=i},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(t){var n=this;void 0===t&&(t={});for(var r in t)this[r]=t[r];Object.defineProperties(this,{$changes:{value:void 0,enumerable:!1,writable:!0},onAdd:{value:void 0,enumerable:!1,writable:!0},onRemove:{value:void 0,enumerable:!1,writable:!0},onChange:{value:void 0,enumerable:!1,writable:!0},clone:{value:function(){var t=Object.assign(new e,n);return t.onAdd=n.onAdd,t.onRemove=n.onRemove,t.onChange=n.onChange,t}},triggerAll:{value:function(){if(n.onAdd)for(var e in n)n.onAdd(n[e],e)}},toJSON:{value:function(){var e={};for(var t in n)e[t]="function"==typeof n[t].toJSON?n[t].toJSON():n[t];return e}},_indexes:{value:new Map,enumerable:!1,writable:!0},_updateIndexes:{value:function(){var e=0,t=new Map;for(var r in n)t.set(r,e++);n._indexes=t}}})}return e}();t.MapSchema=r},function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var i=r(n(16)),o=r(n(17));t.decode=i.default,t.encode=o.default},function(e,t,n){"use strict";function r(e,t){t.headers=e.headers||{},t.statusMessage=e.statusText,t.statusCode=e.status,t.data=e.response}function i(e,t,n){return new Promise(function(i,o){n=n||{};var s,a,c,u,h=new XMLHttpRequest,f=n.headers||{};h.timeout=n.timeout,h.ontimeout=h.onerror=function(e){e.timeout="timeout"==e.type,o(e)},h.open(e,t),h.onload=function(){for(u=h.getAllResponseHeaders().trim().split(/[\r\n]+/),r(h,h);c=u.shift();)c=c.split(": "),h.headers[c.shift().toLowerCase()]=c.join(": ");if((c=h.headers["content-type"])&&~c.indexOf("application/json"))try{h.data=JSON.parse(h.data,n.reviver)}catch(e){return r(h,e),o(e)}(h.status>=400?o:i)(h)},(a=n.body)&&/Array|Object/.test(a.constructor)&&(f["content-type"]="application/json",a=JSON.stringify(a));for(s in f)h.setRequestHeader(s,f[s]);h.send(a)})}Object.defineProperty(t,"__esModule",{value:!0}),t.send=i,n.d(t,"get",function(){return o}),n.d(t,"post",function(){return s}),n.d(t,"patch",function(){return a}),n.d(t,"del",function(){return c}),n.d(t,"put",function(){return u});var o=i.bind(i,"GET"),s=i.bind(i,"POST"),a=i.bind(i,"PATCH"),c=i.bind(i,"DELETE"),u=i.bind(i,"PUT")},function(e,t,n){"use strict";var r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t};Object.defineProperty(t,"__esModule",{value:!0});var i=r(n(3)),o=n(18),s=n(19),a=n(6),c=n(7),u=function(){function e(e,t){var n=this;this.onJoin=o.createSignal(),this.onStateChange=o.createSignal(),this.onMessage=o.createSignal(),this.onError=o.createSignal(),this.onLeave=o.createSignal(),this.id=null,this.name=e,t?(this.serializer=new(a.getSerializer("schema")),this.rootSchema=t,this.serializer.state=new t):this.serializer=new(a.getSerializer("fossil-delta")),this.onError(function(e){return console.error(e)}),this.onLeave(function(){return n.removeAllListeners()})}return e.prototype.connect=function(e){var t=this;this.connection=new s.Connection(e,!1),this.connection.reconnectEnabled=!1,this.connection.onmessage=this.onMessageCallback.bind(this),this.connection.onclose=function(e){t.onLeave.invoke(e.code)},this.connection.onerror=function(e){console.warn("Room, onError ("+e.code+"): "+e.reason),t.onError.invoke(e.reason)},this.connection.open()},e.prototype.leave=function(e){void 0===e&&(e=!0),this.connection?e?this.connection.send([c.Protocol.LEAVE_ROOM]):this.connection.close():this.onLeave.invoke(4e3)},e.prototype.send=function(e){this.connection.send([c.Protocol.ROOM_DATA,e])},Object.defineProperty(e.prototype,"state",{get:function(){return this.serializer.getState()},enumerable:!0,configurable:!0}),e.prototype.listen=function(e,t,n){return"schema"===this.serializerId?void console.error("'"+this.serializerId+"' serializer doesn't support .listen() method."):(this.serializerId||console.warn("room.Listen() should be called after room.onJoin has been called (DEPRECATION WARNING)"),this.serializer.api.listen(e,t,n))},e.prototype.removeListener=function(e){return this.serializer.api.removeListener(e)},e.prototype.removeAllListeners=function(){this.serializer&&this.serializer.teardown(),this.onJoin.clear(),this.onStateChange.clear(),this.onMessage.clear(),this.onError.clear(),this.onLeave.clear()},e.prototype.onMessageCallback=function(e){if(this.previousCode)this.previousCode===c.Protocol.ROOM_STATE?this.setState(Array.from(new Uint8Array(e.data))):this.previousCode===c.Protocol.ROOM_STATE_PATCH?this.patch(Array.from(new Uint8Array(e.data))):this.previousCode===c.Protocol.ROOM_DATA&&this.onMessage.invoke(i.decode(e.data)),this.previousCode=void 0;else{var t=new DataView(e.data),n=t.getUint8(0);if(n===c.Protocol.JOIN_ROOM){var r=1;this.serializerId=c.utf8Read(t,r),r+=c.utf8Length(this.serializerId);var o=a.getSerializer(this.serializerId);if(!o)throw new Error("missing serializer: "+this.serializerId);if("fossil-delta"===this.serializerId||this.rootSchema||(this.serializer=new o),t.buffer.byteLength>r&&this.serializer.handshake){var s=Array.from(new Uint8Array(t.buffer.slice(r)));this.serializer.handshake(s)}this.onJoin.invoke()}else n===c.Protocol.JOIN_ERROR?this.onError.invoke(c.utf8Read(t,1)):n===c.Protocol.LEAVE_ROOM?this.leave():this.previousCode=n}},e.prototype.setState=function(e){this.serializer.setState(e),this.onStateChange.invoke(this.serializer.getState())},e.prototype.patch=function(e){this.serializer.patch(e),this.onStateChange.invoke(this.serializer.getState())},e}();t.Room=u},function(e,t,n){"use strict";function r(e,t){o[e]=t}function i(e){return o[e]}Object.defineProperty(t,"__esModule",{value:!0});var o={};t.registerSerializer=r,t.getSerializer=i},function(e,t,n){"use strict";function r(e,t){for(var n=e.getUint8(t++),r="",i=0,o=t,s=t+n;o=65536?(i-=65536,r+=String.fromCharCode(55296+(i>>>10),56320+(1023&i))):r+=String.fromCharCode(i)}else r+=String.fromCharCode((15&a)<<12|(63&e.getUint8(++o))<<6|(63&e.getUint8(++o))<<0);else r+=String.fromCharCode((31&a)<<6|63&e.getUint8(++o));else r+=String.fromCharCode(a)}return r}function i(e){void 0===e&&(e="");for(var t=0,n=0,r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n+1}Object.defineProperty(t,"__esModule",{value:!0});!function(e){e[e.JOIN_ROOM=10]="JOIN_ROOM",e[e.JOIN_ERROR=11]="JOIN_ERROR",e[e.LEAVE_ROOM=12]="LEAVE_ROOM",e[e.ROOM_DATA=13]="ROOM_DATA",e[e.ROOM_STATE=14]="ROOM_STATE",e[e.ROOM_STATE_PATCH=15]="ROOM_STATE_PATCH"}(t.Protocol||(t.Protocol={})),t.utf8Read=r,t.utf8Length=i},function(e,t,n){"use strict";var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))(function(i,o){function s(e){try{c(r.next(e))}catch(e){o(e)}}function a(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){e.done?i(e.value):new n(function(t){t(e.value)}).then(s,a)}c((r=r.apply(e,t||[])).next())})},i=this&&this.__generator||function(e,t){function n(e){return function(t){return r([e,t])}}function r(n){if(i)throw new TypeError("Generator is already executing.");for(;c;)try{if(i=1,o&&(s=2&n[0]?o.return:n[0]?o.throw||((s=o.return)&&s.call(o),0):o.next)&&!(s=s.call(o,n[1])).done)return s;switch(o=0,s&&(n=[2&n[0],s.value]),n[0]){case 0:case 1:s=n;break;case 4:return c.label++,{value:n[1],done:!1};case 5:c.label++,o=n[1],n=[0];continue;case 7:n=c.ops.pop(),c.trys.pop();continue;default:if(s=c.trys,!(s=s.length>0&&s[s.length-1])&&(6===n[0]||2===n[0])){c=0;continue}if(3===n[0]&&(!s||n[1]>s[0]&&n[1]=0&&this.allChanges.splice(n,1):this.allChanges.push(e),this.parent&&this.parent.change(this.parentField)},e.prototype.mapIndex=function(e,t){this.indexMap||(this.indexMap=new Map,this.indexChange=new Map),this.indexMap.set(e,t)},e.prototype.getIndex=function(e){return this.indexMap&&this.indexMap.get(e)},e.prototype.deleteIndex=function(e){this.indexMap.delete(e)},e.prototype.mapIndexChange=function(e,t){this.indexChange.set(e,t)},e.prototype.getIndexChange=function(e){return this.indexChange&&this.indexChange.get(e)},e.prototype.deleteIndexChange=function(e){this.indexChange.delete(e)},e.prototype.changeAll=function(e){if(e instanceof r.Schema){var t=e._schema;for(var n in t)(e[n]instanceof r.Schema||e[n]instanceof i.ArraySchema||e[n]instanceof o.MapSchema)&&!e[n].$changes.parent.parent&&(e[n].$changes.parent=this),this.change(n)}else for(var s=Object.keys(e),a=0,c=s;a0&&s[s.length-1])&&(6===n[0]||2===n[0])){c=0;continue}if(3===n[0]&&(!s||n[1]>s[0]&&n[1]=65536?(i-=65536,r+=String.fromCharCode(55296+(i>>>10),56320+(1023&i))):r+=String.fromCharCode(i)}else r+=String.fromCharCode((15&a)<<12|(63&e.getUint8(++o))<<6|(63&e.getUint8(++o))<<0);else r+=String.fromCharCode((31&a)<<6|63&e.getUint8(++o));else r+=String.fromCharCode(a)}return r}function o(e){var t=new r(e),n=t._parse();if(t._offset!==e.byteLength)throw new Error(e.byteLength-t._offset+" trailing bytes");return n}r.prototype._array=function(e){for(var t=new Array(e),n=0;n223)return-1*(255-t+1);switch(t){case 192:return null;case 194:return!1;case 195:return!0;case 196:return n=this._view.getUint8(this._offset),this._offset+=1,this._bin(n);case 197:return n=this._view.getUint16(this._offset),this._offset+=2,this._bin(n);case 198:return n=this._view.getUint32(this._offset),this._offset+=4,this._bin(n);case 199:return n=this._view.getUint8(this._offset),r=this._view.getInt8(this._offset+1),this._offset+=2,[r,this._bin(n)];case 200:return n=this._view.getUint16(this._offset),r=this._view.getInt8(this._offset+2),this._offset+=3,[r,this._bin(n)];case 201:return n=this._view.getUint32(this._offset),r=this._view.getInt8(this._offset+4),this._offset+=5,[r,this._bin(n)];case 202:return e=this._view.getFloat32(this._offset),this._offset+=4,e;case 203:return e=this._view.getFloat64(this._offset),this._offset+=8,e;case 204:return e=this._view.getUint8(this._offset),this._offset+=1,e;case 205:return e=this._view.getUint16(this._offset),this._offset+=2,e;case 206:return e=this._view.getUint32(this._offset),this._offset+=4,e;case 207:return i=this._view.getUint32(this._offset)*Math.pow(2,32),o=this._view.getUint32(this._offset+4),this._offset+=8,i+o;case 208:return e=this._view.getInt8(this._offset),this._offset+=1,e;case 209:return e=this._view.getInt16(this._offset),this._offset+=2,e;case 210:return e=this._view.getInt32(this._offset),this._offset+=4,e;case 211:return i=this._view.getInt32(this._offset)*Math.pow(2,32),o=this._view.getUint32(this._offset+4),this._offset+=8,i+o;case 212:return r=this._view.getInt8(this._offset),this._offset+=1,0===r?void(this._offset+=1):[r,this._bin(1)];case 213:return r=this._view.getInt8(this._offset),this._offset+=1,[r,this._bin(2)];case 214:return r=this._view.getInt8(this._offset),this._offset+=1,[r,this._bin(4)];case 215:return r=this._view.getInt8(this._offset),this._offset+=1,0===r?(i=this._view.getInt32(this._offset)*Math.pow(2,32),o=this._view.getUint32(this._offset+4),this._offset+=8,new Date(i+o)):[r,this._bin(8)];case 216:return r=this._view.getInt8(this._offset),this._offset+=1,[r,this._bin(16)];case 217:return n=this._view.getUint8(this._offset),this._offset+=1,this._str(n);case 218:return n=this._view.getUint16(this._offset),this._offset+=2,this._str(n);case 219:return n=this._view.getUint32(this._offset),this._offset+=4,this._str(n);case 220:return n=this._view.getUint16(this._offset),this._offset+=2,this._array(n);case 221:return n=this._view.getUint32(this._offset),this._offset+=4,this._array(n);case 222:return n=this._view.getUint16(this._offset),this._offset+=2,this._map(n);case 223:return n=this._view.getUint32(this._offset),this._offset+=4,this._map(n)}throw new Error("Could not parse")},e.exports=o},function(e,t,n){"use strict";function r(e,t,n){for(var r=0,i=0,o=n.length;i>6),e.setUint8(t++,128|63&r)):r<55296||r>=57344?(e.setUint8(t++,224|r>>12),e.setUint8(t++,128|r>>6&63),e.setUint8(t++,128|63&r)):(i++,r=65536+((1023&r)<<10|1023&n.charCodeAt(i)),e.setUint8(t++,240|r>>18),e.setUint8(t++,128|r>>12&63),e.setUint8(t++,128|r>>6&63),e.setUint8(t++,128|63&r))}function i(e){for(var t=0,n=0,r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}function o(e,t,n){var r=typeof n,s=0,a=0,c=0,u=0,h=0,f=0;if("string"===r){if((h=i(n))<32)e.push(160|h),f=1;else if(h<256)e.push(217,h),f=2;else if(h<65536)e.push(218,h>>8,h),f=3;else{if(!(h<4294967296))throw new Error("String too long");e.push(219,h>>24,h>>16,h>>8,h),f=5}return t.push({_str:n,_length:h,_offset:e.length}),f+h}if("number"===r)return Math.floor(n)===n&&isFinite(n)?n>=0?n<128?(e.push(n),1):n<256?(e.push(204,n),2):n<65536?(e.push(205,n>>8,n),3):n<4294967296?(e.push(206,n>>24,n>>16,n>>8,n),5):(c=n/Math.pow(2,32)>>0,u=n>>>0,e.push(207,c>>24,c>>16,c>>8,c,u>>24,u>>16,u>>8,u),9):n>=-32?(e.push(n),1):n>=-128?(e.push(208,n),2):n>=-32768?(e.push(209,n>>8,n),3):n>=-2147483648?(e.push(210,n>>24,n>>16,n>>8,n),5):(c=Math.floor(n/Math.pow(2,32)),u=n>>>0,e.push(211,c>>24,c>>16,c>>8,c,u>>24,u>>16,u>>8,u),9):(e.push(203),t.push({_float:n,_length:8,_offset:e.length}),9);if("object"===r){if(null===n)return e.push(192),1;if(Array.isArray(n)){if((h=n.length)<16)e.push(144|h),f=1;else if(h<65536)e.push(220,h>>8,h),f=3;else{if(!(h<4294967296))throw new Error("Array too large");e.push(221,h>>24,h>>16,h>>8,h),f=5}for(s=0;s>>0,e.push(215,0,c>>24,c>>16,c>>8,c,u>>24,u>>16,u>>8,u),10}if(n instanceof ArrayBuffer){if((h=n.byteLength)<256)e.push(196,h),f=2;else if(h<65536)e.push(197,h>>8,h),f=3;else{if(!(h<4294967296))throw new Error("Buffer too large");e.push(198,h>>24,h>>16,h>>8,h),f=5}return t.push({_bin:n,_length:h,_offset:e.length}),f+h}if("function"==typeof n.toJSON)return o(e,t,n.toJSON());var p=[],d="",v=Object.keys(n);for(s=0,a=v.length;s>8,h),f=3;else{if(!(h<4294967296))throw new Error("Object too large");e.push(223,h>>24,h>>16,h>>8,h),f=5}for(s=0;s0&&(h=n[0]._offset);for(var f,l=0,p=0,d=0,v=t.length;d0){for(var n=0,r=this._enqueuedCalls;n2&&void 0!==arguments[2]?arguments[2]:{};r(this,e),this.url=t,this.protocols=n,this.reconnectEnabled=!0,this.listeners={},this.backoff=o(i.backoff||"exponential",i),this.backoff.onReady=this.onBackoffReady.bind(this),(void 0===i.connect||i.connect)&&this.open()}return i(e,[{key:"open",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.isReconnect=e;var t=this.ws&&this.ws.binaryType;this.ws=new s(this.url,this.protocols),this.ws.onclose=this.onCloseCallback.bind(this),this.ws.onerror=this.onErrorCallback.bind(this),this.ws.onmessage=this.onMessageCallback.bind(this),this.ws.onopen=this.onOpenCallback.bind(this),t&&(this.ws.binaryType=t)}},{key:"onBackoffReady",value:function(e,t){this.open(!0)}},{key:"onCloseCallback",value:function(e){!this.isReconnect&&this.listeners.onclose&&this.listeners.onclose.apply(null,arguments),this.reconnectEnabled&&e.code<3e3&&this.backoff.backoff()}},{key:"onErrorCallback",value:function(){this.listeners.onerror&&this.listeners.onerror.apply(null,arguments)}},{key:"onMessageCallback",value:function(){this.listeners.onmessage&&this.listeners.onmessage.apply(null,arguments)}},{key:"onOpenCallback",value:function(){this.listeners.onopen&&this.listeners.onopen.apply(null,arguments),this.isReconnect&&this.listeners.onreconnect&&this.listeners.onreconnect.apply(null,arguments),this.isReconnect=!1}},{key:"close",value:function(e,t){void 0===e&&(e=1e3),this.reconnectEnabled=!1,this.ws.close(e,t)}},{key:"send",value:function(e){this.ws.send(e)}},{key:"bufferedAmount",get:function(){return this.ws.bufferedAmount}},{key:"readyState",get:function(){return this.ws.readyState}},{key:"binaryType",get:function(){return this.ws.binaryType},set:function(e){this.ws.binaryType=e}},{key:"extensions",get:function(){return this.ws.extensions},set:function(e){this.ws.extensions=e}},{key:"protocol",get:function(){return this.ws.protocol},set:function(e){this.ws.protocol=e}},{key:"onclose",set:function(e){this.listeners.onclose=e},get:function(){return this.listeners.onclose}},{key:"onerror",set:function(e){this.listeners.onerror=e},get:function(){return this.listeners.onerror}},{key:"onmessage",set:function(e){this.listeners.onmessage=e},get:function(){return this.listeners.onmessage}},{key:"onopen",set:function(e){this.listeners.onopen=e},get:function(){return this.listeners.onopen}},{key:"onreconnect",set:function(e){this.listeners.onreconnect=e},get:function(){return this.listeners.onreconnect}}]),e}();a.CONNECTING=s.CONNECTING,a.OPEN=s.OPEN,a.CLOSING=s.CLOSING,a.CLOSED=s.CLOSED,t.default=a},function(e,t,n){"use strict";function r(e,t){return new i(o[e],t)}function i(e,t){this.func=e,this.attempts=0,this.delay=void 0!==t.initialDelay?t.initialDelay:100}Object.defineProperty(t,"__esModule",{value:!0}),t.createBackoff=r;var o={exponential:function(e,t){return Math.floor(Math.random()*Math.pow(2,e)*t)},fibonacci:function(e,t){var n=1;if(e>n)for(var r=1,n=2,i=2;i0&&s[s.length-1])&&(6===n[0]||2===n[0])){c=0;continue}if(3===n[0]&&(!s||n[1]>s[0]&&n[1]1&&console.warn(".listen() accepts only one parameter.");var s={callback:t,rawRules:i,rules:i.map(function(e){return"string"==typeof e?0===e.indexOf(":")?o.matcherPlaceholders[e]||o.matcherPlaceholders[":*"]:new RegExp("^"+e+"$"):e})};return 0===i.length?this.defaultListener=s:this.listeners.push(s),n&&this.checkPatches(r.compare({},this.state),[s]),s},e.prototype.removeListener=function(e){for(var t=this.listeners.length-1;t>=0;t--)this.listeners[t]===e&&this.listeners.splice(t,1)},e.prototype.removeAllListeners=function(){this.reset()},e.prototype.checkPatches=function(e,t,n){for(var r=0,i=t.length;r=0;s--){var a=o&&this.getPathVariables(e[s],o);a&&(o.callback({path:a,rawPath:e[s].path,operation:e[s].operation,value:e[s].value}),e[s].matched=!0)}if(n)for(var s=e.length-1;s>=0;s--)e[s].matched||n.callback(e[s])},e.prototype.getPathVariables=function(e,t){if(e.path.length!==t.rules.length)return!1;for(var n={},r=0,i=t.rules.length;r2)return!1;":"===t.rawRules[r].substr(0,1)&&(n[t.rawRules[r].substr(1)]=o[1])}return n},e.prototype.reset=function(){this.listeners=[]},e}();t.StateContainer=i},function(e,t,n){"use strict";function r(e,t){var n=[];return s(e,t,n,[]),n}function i(e,t){var n=e.slice();return n.push(t),n}function o(e){if(Array.isArray(e)){for(var t=new Array(e.length),n=0;n=0;h--){var f=c[h],l=e[f];if(!t.hasOwnProperty(f)||void 0===t[f]&&void 0!==l&&!1===Array.isArray(t))n.push({operation:"remove",path:i(r,f)}),u=!0;else{var p=t[f];"object"==typeof l&&null!=l&&"object"==typeof p&&null!=p?s(l,p,n,i(r,f)):l!==p&&n.push({operation:"replace",path:i(r,f),value:p,previousValue:l})}}if(u||a.length!=c.length)for(var h=a.length-1;h>=0;h--){var f=a[h];if(!e.hasOwnProperty(f)&&void 0!==t[f]){var p=t[f],d=i(r,f);"object"==typeof p&&null!=p&&s({},p,n,d),n.push({operation:"add",path:d,value:p})}}}Object.defineProperty(t,"__esModule",{value:!0}),t.compare=r},function(e,t){!function(t,n){void 0!==e&&e.exports?e.exports=n():t.fossilDelta=n()}(this,function(){"use strict";function e(){this.a=0,this.b=0,this.i=0,this.z=new Array(s)}function t(e){this.a=e,this.pos=0}function n(){this.a=[]}function r(e){var t,n;for(t=1,n=64;e>=n;t++,n<<=6);return t}function i(e){for(var t=0,n=0,r=0,i=0,o=0,s=e.length;s>=16;)t=t+e[o+0]|0,n=n+e[o+1]|0,r=r+e[o+2]|0,i=i+e[o+3]|0,t=t+e[o+4]|0,n=n+e[o+5]|0,r=r+e[o+6]|0,i=i+e[o+7]|0,t=t+e[o+8]|0,n=n+e[o+9]|0,r=r+e[o+10]|0,i=i+e[o+11]|0,t=t+e[o+12]|0,n=n+e[o+13]|0,r=r+e[o+14]|0,i=i+e[o+15]|0,o+=16,s-=16;for(;s>=4;)t=t+e[o+0]|0,n=n+e[o+1]|0,r=r+e[o+2]|0,i=i+e[o+3]|0,o+=4,s-=4;switch(i=((i+(r<<8)|0)+(n<<16)|0)+(t<<24)|0,s){case 3:i=i+(e[o+2]<<8)|0;case 2:i=i+(e[o+1]<<16)|0;case 1:i=i+(e[o+0]<<24)|0}return i>>>0}var o={},s=16;e.prototype.init=function(e,t){var n,r,i=0,o=0;for(n=0;n>>0};var a="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~".split("").map(function(e){return e.charCodeAt(0)}),c=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1,-1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,36,-1,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,-1,-1,-1,63,-1];return t.prototype.haveBytes=function(){return this.posthis.a.length)throw new RangeError("out of bounds");return e},t.prototype.getChar=function(){return String.fromCharCode(this.getByte())},t.prototype.getInt=function(){for(var e,t=0;this.haveBytes()&&(e=c[127&this.getByte()])>=0;)t=(t<<6)+e;return this.pos--,t>>>0},n.prototype.toArray=function(){return this.a},n.prototype.putByte=function(e){this.a.push(255&e)},n.prototype.putChar=function(e){this.putByte(e.charCodeAt(0))},n.prototype.putInt=function(e){var t,n,r=[];if(0===e)return void this.putChar("0");for(t=0;e>0;t++,e>>>=6)r.push(a[63&e]);for(n=t-1;n>=0;n--)this.putByte(r[n])},n.prototype.putArray=function(e,t,n){for(var r=t;r=0&&O-- >0;){var S,A,k,I,E,P,x,M;for(g=_*s,I=0,P=g,x=C+a;P=M&&S>b&&(b=S,w=g-E,m=k),_=p[_]}if(b>0){m>0&&(c.putInt(m),c.putChar(":"),c.putArray(o,C,C+m),C+=m),C+=b,c.putInt(b),c.putChar("@"),c.putInt(w),c.putChar(","),w+b-1>f&&(f=w+b-1),b=0;break}if(C+a+s>=u){c.putInt(u-C),c.putChar(":"),c.putArray(o,C,C+u-C),C=u;break}y.next(o[C+a+s]),a++}return Cs)throw new Error("copy exceeds output file size");if(p+l>u)throw new Error("copy extends past end of input");f.putArray(e,p,p+l);break;case":":if((a+=l)>s)throw new Error("insert command gives an output larger than predicted");if(l>h)throw new Error("insert count exceeds size of delta");f.putArray(c.a,c.pos,c.pos+l),c.pos+=l;break;case";":var d=f.toArray();if((!o||!1!==o.verifyChecksum)&&l!==i(d))throw new Error("bad checksum");if(a!==s)throw new Error("generated size does not match predicted size");return d;default:throw new Error("unknown delta operator")}}throw new Error("unterminated delta")},o})},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(9),i=function(){function e(){}return e.prototype.setState=function(e){this.state.decode(e)},e.prototype.getState=function(){return this.state},e.prototype.patch=function(e){this.state.decode(e)},e.prototype.teardown=function(){},e.prototype.handshake=function(e){if(this.state){(new r.Reflection).decode(e)}else this.state=r.Reflection.decode(e)},e}();t.SchemaSerializer=i},function(e,t,n){"use strict";function r(e){for(var t=0,n=0,r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}function i(e,t,n){for(var r=0,i=0,o=n.length;i>6,e[t++]=128|63&r):r<55296||r>=57344?(e[t++]=224|r>>12,e[t++]=128|r>>6&63,e[t++]=128|63&r):(i++,r=65536+((1023&r)<<10|1023&n.charCodeAt(i)),e[t++]=240|r>>18,e[t++]=128|r>>12&63,e[t++]=128|r>>6&63,e[t++]=128|63&r)}function o(e,t){e.push(t)}function s(e,t){e.push(t)}function a(e,t){e.push(t),e.push(t>>8)}function c(e,t){e.push(t),e.push(t>>8)}function u(e,t){e.push(t),e.push(t>>8),e.push(t>>16),e.push(t>>24)}function h(e,t){var n=t>>24,r=t>>16,i=t>>8,o=t;e.push(o),e.push(i),e.push(r),e.push(n)}function f(e,t){var n=Math.floor(t/Math.pow(2,32));h(e,t>>>0),h(e,n)}function l(e,t){var n=t/Math.pow(2,32)>>0;h(e,t>>>0),h(e,n)}function p(e,t){v(e,t)}function d(e,t){y(e,t)}function v(e,t){C[0]=t,u(e,m[0])}function y(e,t){O[0]=t,u(e,m[w?0:1]),u(e,m[w?1:0])}function g(e,t){return s(e,t?1:0)}function _(e,t){t||(t="");var n=r(t),o=0;if(n<32)e.push(160|n),o=1;else if(n<256)e.push(217),s(e,n),o=2;else if(n<65536)e.push(218),c(e,n),o=3;else{if(!(n<4294967296))throw new Error("String too long");e.push(219),h(e,n),o=5}return i(e,e.length,t),o+n}function b(e,t){return isNaN(t)?b(e,0):isFinite(t)?t!==(0|t)?(e.push(203),y(e,t),9):t>=0?t<128?(s(e,t),1):t<256?(e.push(204),s(e,t),2):t<65536?(e.push(205),c(e,t),3):t<4294967296?(e.push(206),h(e,t),5):(e.push(207),l(e,t),9):t>=-32?(e.push(t),1):t>=-128?(e.push(208),o(e,t),2):t>=-32768?(e.push(209),a(e,t),3):t>=-2147483648?(e.push(210),u(e,t),5):(e.push(211),f(e,t),9):b(e,t>0?Number.MAX_SAFE_INTEGER:-Number.MAX_SAFE_INTEGER)}Object.defineProperty(t,"__esModule",{value:!0}),t.utf8Write=i,t.int8=o,t.uint8=s,t.int16=a,t.uint16=c,t.int32=u,t.uint32=h,t.int64=f,t.uint64=l,t.float32=p,t.float64=d;var w=!0,m=new Int32Array(2),C=new Float32Array(m.buffer),O=new Float64Array(m.buffer);t.writeFloat32=v,t.writeFloat64=y,t.boolean=g,t.string=_,t.number=b},function(e,t,n){"use strict";function r(e,t,n){for(var r="",i=0,o=t,s=t+n;o=65536?(i-=65536,r+=String.fromCharCode(55296+(i>>>10),56320+(1023&i))):r+=String.fromCharCode(i)}else r+=String.fromCharCode((15&a)<<12|(63&e[++o])<<6|(63&e[++o])<<0);else r+=String.fromCharCode((31&a)<<6|63&e[++o]);else r+=String.fromCharCode(a)}return r}function i(e,t){return o(e,t)<<24>>24}function o(e,t){return e[t.offset++]}function s(e,t){return a(e,t)<<16>>16}function a(e,t){return e[t.offset++]|e[t.offset++]<<8}function c(e,t){return e[t.offset++]|e[t.offset++]<<8|e[t.offset++]<<16|e[t.offset++]<<24}function u(e,t){return c(e,t)>>>0}function h(e,t){return d(e,t)}function f(e,t){return v(e,t)}function l(e,t){var n=u(e,t);return c(e,t)*Math.pow(2,32)+n}function p(e,t){var n=u(e,t);return u(e,t)*Math.pow(2,32)+n}function d(e,t){return k[0]=c(e,t),I[0]}function v(e,t){return k[A?0:1]=c(e,t),k[A?1:0]=c(e,t),E[0]}function y(e,t){return o(e,t)>0}function g(e,t){var n,i=e[t.offset++];i<192?n=31&i:217===i?n=o(e,t):218===i?n=a(e,t):219===i&&(n=u(e,t));var s=r(e,t.offset,n);return t.offset+=n,s}function _(e,t){var n=e[t.offset];return n<192&&n>160||217===n||218===n||219===n}function b(e,t){var n=e[t.offset++];return n<128?n:202===n?d(e,t):203===n?v(e,t):204===n?o(e,t):205===n?a(e,t):206===n?u(e,t):207===n?p(e,t):208===n?i(e,t):209===n?s(e,t):210===n?c(e,t):211===n?l(e,t):n>223?-1*(255-n+1):void 0}function w(e,t){var n=e[t.offset];return n<128||n>=202&&n<=211}function m(e,t){return e[t.offset]<160}function C(e,t){return e[t.offset]===S.NIL}function O(e,t){return e[t.offset]===S.INDEX_CHANGE}Object.defineProperty(t,"__esModule",{value:!0});var S=n(10);t.int8=i,t.uint8=o,t.int16=s,t.uint16=a,t.int32=c,t.uint32=u,t.float32=h,t.float64=f,t.int64=l,t.uint64=p;var A=!0,k=new Int32Array(2),I=new Float32Array(k.buffer),E=new Float64Array(k.buffer);t.readFloat32=d,t.readFloat64=v,t.boolean=y,t.string=g,t.stringCheck=_,t.number=b,t.numberCheck=w,t.arrayCheck=m,t.nilCheck=C,t.indexChangeCheck=O},function(e,t,n){"use strict";var r=this&&this.__extends||function(){var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(t,n)};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),i=this&&this.__decorate||function(e,t,n,r){var i,o=arguments.length,s=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(s=(o<3?i(s):o>3?i(t,n,s):i(t,n))||s);return o>3&&s&&Object.defineProperty(t,n,s),s};Object.defineProperty(t,"__esModule",{value:!0});var o=n(12),s=n(0),a=n(1),c=n(2),u=new o.Context,h=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),i([o.type("string",u)],t.prototype,"name",void 0),i([o.type("string",u)],t.prototype,"type",void 0),i([o.type("uint8",u)],t.prototype,"referencedType",void 0),t}(s.Schema);t.ReflectionField=h;var f=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.fields=new a.ArraySchema,t}return r(t,e),i([o.type("uint8",u)],t.prototype,"id",void 0),i([o.type([h],u)],t.prototype,"fields",void 0),t}(s.Schema);t.ReflectionType=f;var l=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.types=new a.ArraySchema,t}return r(t,e),t.encode=function(e){var n=e.constructor,r=new t;r.rootType=n._typeid;var i=n._context.types;for(var o in i){var s=new f;s.id=Number(o),function(e,t){for(var n in t){var i=new h;i.name=n;var o=void 0;if("string"==typeof t[n])o=t[n];else{var s="function"==typeof t[n],a=Array.isArray(t[n]),c=!a&&t[n].map,u=void 0;s?(o="ref",u=t[n]):a?(o="array","string"==typeof t[n][0]?o+=":"+t[n][0]:u=t[n][0]):c&&(o="map","string"==typeof t[n].map?o+=":"+t[n].map:u=t[n].map),i.referencedType=u?u._typeid:255}i.type=o,e.fields.push(i)}r.types.push(e)}(s,i[o]._schema)}return r.encodeAll()},t.decode=function(e){var n=new o.Context,i=new t;i.decode(e);var u=i.types.reduce(function(e,t){return e[t.id]=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t}(s.Schema),e},{});i.types.forEach(function(e,t){e.fields.forEach(function(t){var r=u[e.id];if(void 0!==t.referencedType){var i=u[t.referencedType];i||(i=t.type.split(":")[1]),0===t.type.indexOf("array")?o.type([i],n)(r.prototype,t.name):0===t.type.indexOf("map")?o.type({map:i},n)(r.prototype,t.name):"ref"===t.type&&o.type(i,n)(r.prototype,t.name)}else o.type(t.type,n)(r.prototype,t.name)})});var h=u[i.rootType],f=new h;for(var l in h._schema){var p=h._schema[l];if("string"!=typeof p){var d="function"==typeof p,v=Array.isArray(p),y=!v&&p.map;f[l]=v?new a.ArraySchema:y?new c.MapSchema:d?new p:void 0}}return f},i([o.type([f],u)],t.prototype,"types",void 0),i([o.type("uint8",u)],t.prototype,"rootType",void 0),t}(s.Schema);t.Reflection=l}])});