From c98faf734e0c9703f71bae4bedf88a98575dd2e5 Mon Sep 17 00:00:00 2001 From: Endel Dreyer Date: Fri, 21 Feb 2020 14:05:59 -0300 Subject: [PATCH 01/11] WIP rewriting room.send() to support message types --- dist/colyseus.js | 4 ++-- dist/index.html | 33 +++++++-------------------------- package.json | 2 +- src/Connection.ts | 9 +++++++-- src/Room.ts | 28 +++++++++++++++++++++++++--- 5 files changed, 42 insertions(+), 34 deletions(-) diff --git a/dist/colyseus.js b/dist/colyseus.js index 70d0a25..e0a6557 100644 --- a/dist/colyseus.js +++ b/dist/colyseus.js @@ -1,2 +1,2 @@ -/*! colyseus.js@0.12.0 */ -!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()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=13)}([function(e,t,n){"use strict";var r,i=this&&this.__extends||(r=function(e,t){return(r=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])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),o=this&&this.__spreadArrays||function(){for(var e=0,t=0,n=arguments.length;t=e+t-1}));return i.map((function(e){var t=e&&e.$changes;t&&(t.parent.deleteIndex(e),delete t.parent)})),o.forEach((function(e){var t=e&&e.$changes;t&&t.parentField--})),i},t}(Array);t.ArraySchema=s},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function e(t){var n=this;for(var r in void 0===t&&(t={}),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(t){var r;if(t)(r=Object.assign(new e,n)).onAdd=n.onAdd,r.onRemove=n.onRemove,r.onChange=n.onChange;else{var i=new e;for(var o in n)"object"==typeof n[o]?i[o]=n[o].clone():i[o]=n[o]}return r}},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(e){for(var t=0,r=new Map,i=0,o=e;i0;var C=!1;g.length>w&&Array.prototype.splice.call(g,w).forEach((function(t,n){if(t&&t.onRemove)try{t.onRemove()}catch(t){e.onError(t)}if(m.onRemove)try{m.onRemove(t,w+n)}catch(t){e.onError(t)}}));for(var A=0;A0;C=!1;var M=Object.keys(E);for(A=0;A0)try{this.onChange(r)}catch(t){e.onError(t)}return this},e.prototype.encode=function(e,t,n,r){var i=this;if(void 0===e&&(e=this),void 0===t&&(t=!1),void 0===r&&(r=[]),!this.$changes.changed&&!t)return this._encodeEndOfStructure(this,e,r),r;for(var a=this._schema,h=this._indexes,f=this._fieldsByIndex,d=this._filters,v=Array.from(t||n?this.$changes.allChanges:this.$changes.changes).sort(),y=function(y,_){var b=f[v[y]]||v[y],m="_"+b,w=a[b],O=d&&d[b],C=g[m],A=h[b];if(void 0===C)s.uint8(r,o.NIL),s.number(r,A);else if(w._schema){if(n&&O&&!O.call(g,n,C,e))return"continue";C?(s.number(r,A),l(C,w,g,b),g.tryEncodeTypeId(r,w,C.constructor),C.encode(e,t,n,r)):(s.uint8(r,o.NIL),s.number(r,A))}else if(Array.isArray(w)){var S=C.$changes;s.number(r,A),s.number(r,C.length);var k=Array.from(t||n?S.allChanges:S.changes).filter((function(e){return void 0!==i[m][e]})).sort((function(e,t){return e-t})),I=k.length;s.number(r,I);var P="string"!=typeof w[0];l(g[m],c.ArraySchema,g,b);for(var E=0;E=400?o:i)(h)},(a=n.body)&&/Array|Object/.test(a.constructor)&&(f["content-type"]="application/json",a=JSON.stringify(a)),f)h.setRequestHeader(s,f[s]);h.send(a)}))}n.r(t),n.d(t,"send",(function(){return 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.hasJoined=!1,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){if(!t.hasJoined)return console.error("Room connection was closed unexpectedly ("+e.code+"): "+e.reason),void t.onError.invoke(e.reason);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){if("schema"!==this.serializerId)return this.serializerId||console.warn("room.Listen() should be called after room.onJoin has been called (DEPRECATION WARNING)"),this.serializer.api.listen(e,t,n);console.error("'"+this.serializerId+"' serializer doesn't support .listen() method.")},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){var t=Array.from(new Uint8Array(e.data)),n=t[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);"fossil-delta"===this.serializerId||this.rootSchema||(this.serializer=new o),t.length>r&&this.serializer.handshake&&this.serializer.handshake(t,{offset:1}),this.hasJoined=!0,this.onJoin.invoke(),this.connection.send([c.Protocol.JOIN_ROOM])}else if(n===c.Protocol.JOIN_ERROR)this.onError.invoke(c.utf8Read(t,1));else if(n===c.Protocol.LEAVE_ROOM)this.leave();else if(n===c.Protocol.ROOM_DATA_SCHEMA){var s=new(this.serializer.getState().constructor._context.get(t[1]));s.decode(t,{offset:2}),this.onMessage.invoke(s)}else n===c.Protocol.ROOM_STATE?(t.shift(),this.setState(t)):n===c.Protocol.ROOM_STATE_PATCH?(t.shift(),this.patch(t)):n===c.Protocol.ROOM_DATA&&this.onMessage.invoke(i.decode(e.data,1))},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";Object.defineProperty(t,"__esModule",{value:!0});var r={};t.registerSerializer=function(e,t){r[e]=t},t.getSerializer=function(e){return r[e]}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),function(e){e[e.HANDSHAKE=9]="HANDSHAKE",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",e[e.ROOM_DATA_SCHEMA=16]="ROOM_DATA_SCHEMA"}(t.Protocol||(t.Protocol={})),t.utf8Read=function(e,t){for(var n=e[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[++o])<<6|(63&e[++o])<<0);else r+=String.fromCharCode((31&a)<<6|63&e[++o]);else r+=String.fromCharCode(a)}return r},t.utf8Length=function(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}},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){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=(i=s.trys).length>0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0?"?"+r.join("&"):"",h={headers:a},o&&(h.body=o),[4,s[e](""+this.endpoint+t+u,h)];case 1:return[2,i.sent().data]}}))}))},e.prototype.logout=function(){this.token=void 0,a.removeItem("colyseus-auth-token"),this.unregisterPingService()},e.prototype.registerPingService=function(e){var t=this;void 0===e&&(e=15e3),this.unregisterPingService(),this.keepOnlineInterval=setInterval((function(){return t.request("get","/auth")}),e)},e.prototype.unregisterPingService=function(){clearInterval(this.keepOnlineInterval)},e}();t.Auth=c},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2);t.Schema=r.Schema;var i=n(1);t.MapSchema=i.MapSchema;var o=n(0);t.ArraySchema=o.ArraySchema;var s=n(33);t.dumpChanges=s.dumpChanges;var a=n(34);t.Reflection=a.Reflection,t.ReflectionType=a.ReflectionType,t.ReflectionField=a.ReflectionField;var c=n(12);t.type=c.type,t.deprecated=c.deprecated,t.filter=c.filter,t.defineTypes=c.defineTypes,t.Context=c.Context},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.END_OF_STRUCTURE=193,t.NIL=192,t.INDEX_CHANGE=212,t.TYPE_ID=213},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2),i=n(0),o=n(1),s=function(){function e(e,t,n){void 0===e&&(e={}),void 0===t&&(t=null),this.changed=!1,this.changes=new Set,this.allChanges=new Set,this.deletedKeys={},this.fieldIndexes=e,this.parent=n,this.parentField=t}return e.prototype.change=function(e,t){void 0===t&&(t=!1);var n=this.fieldIndexes[e],r="number"==typeof n?n:e;t?t&&(this.changed=!0,this.changes.add(r),this.allChanges.delete(r)):(this.changed=!0,this.changes.add(r),this.allChanges.add(r)),this.parent&&this.parent.change(this.parentField)},e.prototype.mapIndex=function(e,t){"object"==typeof e&&(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){"object"==typeof e&&(this.deletedKeys[this.indexMap.get(e)]=!0,this.indexMap.delete(e))},e.prototype.isDeleted=function(e){return void 0!==this.deletedKeys[e]},e.prototype.mapIndexChange=function(e,t){"object"!=typeof e||this.indexChange.has(e)||this.indexChange.set(e,t)},e.prototype.getIndexChange=function(e){return this.indexChange&&this.indexChange.get(e)},e.prototype.deleteIndexChange=function(e){"object"==typeof 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),void 0!==e[n]&&this.change(n)}else for(var s=0,a=Object.keys(e);s0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[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}(this._view,this._offset,e);return this._offset+=e,t},r.prototype._bin=function(e){var t=this._buffer.slice(this._offset,this._offset+e);return this._offset+=e,t},r.prototype._parse=function(){var e,t=this._view.getUint8(this._offset++),n=0,r=0,i=0,o=0;if(t<192)return t<128?t:t<144?this._map(15&t):t<160?this._array(15&t):this._str(31&t);if(t>223)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")},t.default=function(e,t){void 0===t&&(t=0);var n=new r(e,t),i=n._parse();if(n._offset!==e.byteLength)throw new Error(e.byteLength-n._offset+" trailing bytes");return i}},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))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){var t=[],n=[],i=function e(t,n,r){var i=typeof r,o=0,s=0,a=0,c=0,u=0,h=0;if("string"===i){if((u=function(e){for(var t=0,n=0,r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}(r))<32)t.push(160|u),h=1;else if(u<256)t.push(217,u),h=2;else if(u<65536)t.push(218,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("String too long");t.push(219,u>>24,u>>16,u>>8,u),h=5}return n.push({_str:r,_length:u,_offset:t.length}),h+u}if("number"===i)return Math.floor(r)===r&&isFinite(r)?r>=0?r<128?(t.push(r),1):r<256?(t.push(204,r),2):r<65536?(t.push(205,r>>8,r),3):r<4294967296?(t.push(206,r>>24,r>>16,r>>8,r),5):(a=r/Math.pow(2,32)>>0,c=r>>>0,t.push(207,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),9):r>=-32?(t.push(r),1):r>=-128?(t.push(208,r),2):r>=-32768?(t.push(209,r>>8,r),3):r>=-2147483648?(t.push(210,r>>24,r>>16,r>>8,r),5):(a=Math.floor(r/Math.pow(2,32)),c=r>>>0,t.push(211,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),9):(t.push(203),n.push({_float:r,_length:8,_offset:t.length}),9);if("object"===i){if(null===r)return t.push(192),1;if(Array.isArray(r)){if((u=r.length)<16)t.push(144|u),h=1;else if(u<65536)t.push(220,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("Array too large");t.push(221,u>>24,u>>16,u>>8,u),h=5}for(o=0;o>>0,t.push(215,0,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),10}if(r instanceof ArrayBuffer){if((u=r.byteLength)<256)t.push(196,u),h=2;else if(u<65536)t.push(197,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("Buffer too large");t.push(198,u>>24,u>>16,u>>8,u),h=5}return n.push({_bin:r,_length:u,_offset:t.length}),h+u}if("function"==typeof r.toJSON)return e(t,n,r.toJSON());var l=[],p="",d=Object.keys(r);for(o=0,s=d.length;o>8,u),h=3;else{if(!(u<4294967296))throw new Error("Object too large");t.push(223,u>>24,u>>16,u>>8,u),h=5}for(o=0;o0&&(u=n[0]._offset);for(var h,f=0,l=0,p=0,d=t.length;p0){for(var n=0,r=this._enqueuedCalls;n2&&void 0!==arguments[2]?arguments[2]:{};i(this,e),this.url=t,this.protocols=n,this.reconnectEnabled=!0,this.listeners={},this.backoff=o(r.backoff||"exponential",r),this.backoff.onReady=this.onBackoffReady.bind(this),(void 0===r.connect||r.connect)&&this.open()}return r(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";Object.defineProperty(t,"__esModule",{value:!0}),t.createBackoff=function(e,t){return new i(r[e],t)};var r={exponential:function(e,t){return Math.floor(Math.random()*Math.pow(2,e)*t)},fibonacci:function(e,t){if(e>(r=1))for(var n=1,r=2,i=2;i0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[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(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=e.slice();return n.push(t),n}function i(e){if(Array.isArray(e)){for(var t=new Array(e.length),n=0;n=0;h--){var f=c[h],l=t[f];if(!n.hasOwnProperty(f)||void 0===n[f]&&void 0!==l&&!1===Array.isArray(n))o.push({operation:"remove",path:r(s,f)}),u=!0;else{var p=n[f];"object"==typeof l&&null!=l&&"object"==typeof p&&null!=p?e(l,p,o,r(s,f)):l!==p&&o.push({operation:"replace",path:r(s,f),value:p,previousValue:l})}}if(!u&&a.length==c.length)return;for(h=a.length-1;h>=0;h--){f=a[h];if(!t.hasOwnProperty(f)&&void 0!==n[f]){p=n[f];var d=r(s,f);"object"==typeof p&&null!=p&&e({},p,o,d),o.push({operation:"add",path:d,value:p})}}}(e,t,n,[]),n}},function(e,t,n){var r,i;r=this,i=function(){"use strict";var e={};function t(){this.a=0,this.b=0,this.i=0,this.z=new Array(16)}t.prototype.init=function(e,t){var n,r,i=0,o=0;for(n=0;n<16;n++)i=i+(r=e[t+n])&65535,o=o+(16-n)*r&65535,this.z[n]=r;this.a=65535&i,this.b=65535&o,this.i=0},t.prototype.next=function(e){var t=this.z[this.i];this.z[this.i]=e,this.i=this.i+1&15,this.a=this.a-t+e&65535,this.b=this.b-16*t+this.a&65535},t.prototype.value=function(){return(65535&this.a|(65535&this.b)<<16)>>>0};var n="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~".split("").map((function(e){return e.charCodeAt(0)})),r=[-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];function i(e){this.a=e,this.pos=0}function o(){this.a=[]}function s(e){var t,n;for(t=1,n=64;e>=n;t++,n<<=6);return t}function a(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}return i.prototype.haveBytes=function(){return this.posthis.a.length)throw new RangeError("out of bounds");return e},i.prototype.getChar=function(){return String.fromCharCode(this.getByte())},i.prototype.getInt=function(){for(var e,t=0;this.haveBytes()&&(e=r[127&this.getByte()])>=0;)t=(t<<6)+e;return this.pos--,t>>>0},o.prototype.toArray=function(){return this.a},o.prototype.putByte=function(e){this.a.push(255&e)},o.prototype.putChar=function(e){this.putByte(e.charCodeAt(0))},o.prototype.putInt=function(e){var t,r,i=[];if(0!==e){for(t=0;e>0;t++,e>>>=6)i.push(n[63&e]);for(r=t-1;r>=0;r--)this.putByte(i[r])}else this.putChar("0")},o.prototype.putArray=function(e,t,n){for(var r=t;r=0&&O-- >0;){var C,A,S,k,I,P,E;for(k=0,P=y=16*g,E=w+r;P=s(r-I)+s(C)+s(A)+3&&C>_&&(_=C,b=y-I,m=S),g=l[g]}if(_>0){m>0&&(i.putInt(m),i.putChar(":"),i.putArray(n,w,w+m),w+=m),w+=_,i.putInt(_),i.putChar("@"),i.putInt(b),i.putChar(","),b+_-1>h&&(h=b+_-1),_=0;break}if(w+r+16>=c){i.putInt(c-w),i.putChar(":"),i.putArray(n,w,w+c-w),w=c;break}v.next(n[w+r+16]),r++}return wr)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((s+=l)>r)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((!n||!1!==n.verifyChecksum)&&l!==a(d))throw new Error("bad checksum");if(s!==r)throw new Error("generated size does not match predicted size");return d;default:throw new Error("unknown delta operator")}}throw new Error("unterminated delta")},e},e.exports?e.exports=i():r.fossilDelta=i()},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,t){this.state?(new r.Reflection).decode(e,t):this.state=r.Reflection.decode(e)},e}();t.SchemaSerializer=i},function(e,t,n){"use strict";function r(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 i(e,t){e.push(255&t)}function o(e,t){e.push(255&t)}function s(e,t){e.push(255&t),e.push(t>>8&255)}function a(e,t){e.push(255&t),e.push(t>>8&255)}function c(e,t){e.push(255&t),e.push(t>>8&255),e.push(t>>16&255),e.push(t>>24&255)}function u(e,t){var n=t>>24,r=t>>16,i=t>>8,o=t;e.push(255&o),e.push(255&i),e.push(255&r),e.push(255&n)}function h(e,t){var n=Math.floor(t/Math.pow(2,32));u(e,t>>>0),u(e,n)}function f(e,t){var n=t/Math.pow(2,32)>>0;u(e,t>>>0),u(e,n)}Object.defineProperty(t,"__esModule",{value:!0}),t.utf8Write=r,t.int8=i,t.uint8=o,t.int16=s,t.uint16=a,t.int32=c,t.uint32=u,t.int64=h,t.uint64=f,t.float32=function(e,t){v(e,t)},t.float64=function(e,t){y(e,t)};var l=new Int32Array(2),p=new Float32Array(l.buffer),d=new Float64Array(l.buffer);function v(e,t){p[0]=t,c(e,l[0])}function y(e,t){d[0]=t,c(e,l[0]),c(e,l[1])}t.writeFloat32=v,t.writeFloat64=y,t.boolean=function(e,t){return o(e,t?1:0)},t.string=function(e,t){t||(t="");var n=function(e){for(var t=0,n=0,r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}(t),i=0;if(n<32)e.push(160|n),i=1;else if(n<256)e.push(217),o(e,n),i=2;else if(n<65536)e.push(218),a(e,n),i=3;else{if(!(n<4294967296))throw new Error("String too long");e.push(219),u(e,n),i=5}return r(e,e.length,t),i+n},t.number=function e(t,n){return isNaN(n)?e(t,0):isFinite(n)?n!==(0|n)?(t.push(203),y(t,n),9):n>=0?n<128?(o(t,n),1):n<256?(t.push(204),o(t,n),2):n<65536?(t.push(205),a(t,n),3):n<4294967296?(t.push(206),u(t,n),5):(t.push(207),f(t,n),9):n>=-32?(t.push(n),1):n>=-128?(t.push(208),i(t,n),2):n>=-32768?(t.push(209),s(t,n),3):n>=-2147483648?(t.push(210),c(t,n),5):(t.push(211),h(t,n),9):e(t,n>0?Number.MAX_SAFE_INTEGER:-Number.MAX_SAFE_INTEGER)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(10);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){var n=u(e,t);return c(e,t)*Math.pow(2,32)+n}function f(e,t){var n=u(e,t);return u(e,t)*Math.pow(2,32)+n}t.int8=i,t.uint8=o,t.int16=s,t.uint16=a,t.int32=c,t.uint32=u,t.float32=function(e,t){return v(e,t)},t.float64=function(e,t){return y(e,t)},t.int64=h,t.uint64=f;var l=new Int32Array(2),p=new Float32Array(l.buffer),d=new Float64Array(l.buffer);function v(e,t){return l[0]=c(e,t),p[0]}function y(e,t){return l[0]=c(e,t),l[1]=c(e,t),d[0]}t.readFloat32=v,t.readFloat64=y,t.boolean=function(e,t){return o(e,t)>0},t.string=function(e,t){var n,r=e[t.offset++];r<192?n=31&r:217===r?n=o(e,t):218===r?n=a(e,t):219===r&&(n=u(e,t));var i=function(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}(e,t.offset,n);return t.offset+=n,i},t.stringCheck=function(e,t){var n=e[t.offset];return(n<192&&n>160||217===n||218===n||219===n)},t.number=function(e,t){var n=e[t.offset++];return n<128?n:202===n?v(e,t):203===n?y(e,t):204===n?o(e,t):205===n?a(e,t):206===n?u(e,t):207===n?f(e,t):208===n?i(e,t):209===n?s(e,t):210===n?c(e,t):211===n?h(e,t):n>223?-1*(255-n+1):void 0},t.numberCheck=function(e,t){var n=e[t.offset];return n<128||n>=202&&n<=211},t.arrayCheck=function(e,t){return e[t.offset]<160},t.nilCheck=function(e,t){return e[t.offset]===r.NIL},t.indexChangeCheck=function(e,t){return e[t.offset]===r.INDEX_CHANGE}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(9),i=n(1),o=n(0);t.dumpChanges=function e(t){for(var n={},s=t.$changes,a=t._fieldsByIndex||{},c=0,u=Array.from(s.changes);c=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 s=n(12),a=n(2),c=n(0),u=n(1),h=new s.Context,f=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),o([s.type("string",h)],t.prototype,"name",void 0),o([s.type("string",h)],t.prototype,"type",void 0),o([s.type("uint8",h)],t.prototype,"referencedType",void 0),t}(a.Schema);t.ReflectionField=f;var l=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.fields=new c.ArraySchema,t}return i(t,e),o([s.type("uint8",h)],t.prototype,"id",void 0),o([s.type([f],h)],t.prototype,"fields",void 0),t}(a.Schema);t.ReflectionType=l;var p=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.types=new c.ArraySchema,t}return i(t,e),t.encode=function(e){var n=e.constructor,r=new t;r.rootType=n._typeid;var i=function(e,t){for(var n in t){var i=new f;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)},o=n._context.types;for(var s in o){var a=new l;a.id=Number(s),i(a,o[s]._schema)}return r.encodeAll()},t.decode=function(e){var n=new s.Context,r=new t;r.decode(e);var o=r.types.reduce((function(e,t){return e[t.id]=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),t}(a.Schema),e}),{});r.types.forEach((function(e,t){e.fields.forEach((function(t){var r=o[e.id];if(void 0!==t.referencedType){var i=o[t.referencedType];i||(i=t.type.split(":")[1]),0===t.type.indexOf("array")?s.type([i],n)(r.prototype,t.name):0===t.type.indexOf("map")?s.type({map:i},n)(r.prototype,t.name):"ref"===t.type&&s.type(i,n)(r.prototype,t.name)}else s.type(t.type,n)(r.prototype,t.name)}))}));var h=o[r.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 c.ArraySchema:y?new u.MapSchema:d?new p:void 0}}return f},o([s.type([l],h)],t.prototype,"types",void 0),o([s.type("uint8",h)],t.prototype,"rootType",void 0),t}(a.Schema);t.Reflection=p}])})); \ No newline at end of file +/*! colyseus.js@0.13.0-alpha.0 */ +!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()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=14)}([function(e,t,n){"use strict";var r,i=this&&this.__extends||(r=function(e,t){return(r=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])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),o=this&&this.__spreadArrays||function(){for(var e=0,t=0,n=arguments.length;t=e+t-1}));return i.map((function(e){var t=e&&e.$changes;t&&(t.parent.deleteIndex(e),delete t.parent)})),o.forEach((function(e){var t=e&&e.$changes;t&&t.parentField--})),i},t}(Array);t.ArraySchema=s},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function e(t){var n=this;for(var r in void 0===t&&(t={}),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(t){var r;if(t)(r=Object.assign(new e,n)).onAdd=n.onAdd,r.onRemove=n.onRemove,r.onChange=n.onChange;else{var i=new e;for(var o in n)"object"==typeof n[o]?i[o]=n[o].clone():i[o]=n[o]}return r}},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(e){for(var t=0,r=new Map,i=0,o=e;i0;var C=!1;g.length>w&&Array.prototype.splice.call(g,w).forEach((function(t,n){if(t&&t.onRemove)try{t.onRemove()}catch(t){e.onError(t)}if(m.onRemove)try{m.onRemove(t,w+n)}catch(t){e.onError(t)}}));for(var A=0;A0;C=!1;var M=Object.keys(E);for(A=0;A0)try{this.onChange(r)}catch(t){e.onError(t)}return this},e.prototype.encode=function(e,t,n,r){var i=this;if(void 0===e&&(e=this),void 0===t&&(t=!1),void 0===r&&(r=[]),!this.$changes.changed&&!t)return this._encodeEndOfStructure(this,e,r),r;for(var a=this._schema,h=this._indexes,f=this._fieldsByIndex,d=this._filters,v=Array.from(t||n?this.$changes.allChanges:this.$changes.changes).sort(),y=function(y,_){var b=f[v[y]]||v[y],m="_"+b,w=a[b],O=d&&d[b],C=g[m],A=h[b];if(void 0===C)s.uint8(r,o.NIL),s.number(r,A);else if(w._schema){if(n&&O&&!O.call(g,n,C,e))return"continue";C?(s.number(r,A),l(C,w,g,b),g.tryEncodeTypeId(r,w,C.constructor),C.encode(e,t,n,r)):(s.uint8(r,o.NIL),s.number(r,A))}else if(Array.isArray(w)){var S=C.$changes;s.number(r,A),s.number(r,C.length);var k=Array.from(t||n?S.allChanges:S.changes).filter((function(e){return void 0!==i[m][e]})).sort((function(e,t){return e-t})),I=k.length;s.number(r,I);var P="string"!=typeof w[0];l(g[m],c.ArraySchema,g,b);for(var E=0;E=400?o:i)(h)},(a=n.body)&&/Array|Object/.test(a.constructor)&&(f["content-type"]="application/json",a=JSON.stringify(a)),f)h.setRequestHeader(s,f[s]);h.send(a)}))}n.r(t),n.d(t,"send",(function(){return 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(6)),o=n(19),s=n(20),a=n(7),c=n(8),u=n(3),h=r(n(10)),f=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.hasJoined=!1,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){if(!t.hasJoined)return console.error("Room connection was closed unexpectedly ("+e.code+"): "+e.reason),void t.onError.invoke(e.reason);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){if(e instanceof u.Schema)this.connection.send([c.Protocol.ROOM_DATA,e.constructor._typeid].concat(e.encodeAll()));else if("string"==typeof e){var t=arguments[1],n=i.encode(t),r=[c.Protocol.ROOM_DATA];h.string(r,arguments[0]);var o=new Uint8Array(r.length+n.byteLength);o.set(new Uint8Array(r),0),o.set(new Uint8Array(n),r.length),this.connection.send(o.buffer)}},Object.defineProperty(e.prototype,"state",{get:function(){return this.serializer.getState()},enumerable:!0,configurable:!0}),e.prototype.listen=function(e,t,n){if("schema"!==this.serializerId)return this.serializerId||console.warn("room.Listen() should be called after room.onJoin has been called (DEPRECATION WARNING)"),this.serializer.api.listen(e,t,n);console.error("'"+this.serializerId+"' serializer doesn't support .listen() method here.")},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){var t=Array.from(new Uint8Array(e.data)),n=t[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);"fossil-delta"===this.serializerId||this.rootSchema||(this.serializer=new o),t.length>r&&this.serializer.handshake&&this.serializer.handshake(t,{offset:1}),this.hasJoined=!0,this.onJoin.invoke(),this.connection.send([c.Protocol.JOIN_ROOM])}else if(n===c.Protocol.JOIN_ERROR)this.onError.invoke(c.utf8Read(t,1));else if(n===c.Protocol.LEAVE_ROOM)this.leave();else if(n===c.Protocol.ROOM_DATA_SCHEMA){var s=new(this.serializer.getState().constructor._context.get(t[1]));s.decode(t,{offset:2}),this.onMessage.invoke(s)}else n===c.Protocol.ROOM_STATE?(t.shift(),this.setState(t)):n===c.Protocol.ROOM_STATE_PATCH?(t.shift(),this.patch(t)):n===c.Protocol.ROOM_DATA&&this.onMessage.invoke(i.decode(e.data,1))},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=f},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(17)),o=r(n(18));t.decode=i.default,t.encode=o.default},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r={};t.registerSerializer=function(e,t){r[e]=t},t.getSerializer=function(e){return r[e]}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),function(e){e[e.HANDSHAKE=9]="HANDSHAKE",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",e[e.ROOM_DATA_SCHEMA=16]="ROOM_DATA_SCHEMA"}(t.Protocol||(t.Protocol={})),t.utf8Read=function(e,t){for(var n=e[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[++o])<<6|(63&e[++o])<<0);else r+=String.fromCharCode((31&a)<<6|63&e[++o]);else r+=String.fromCharCode(a)}return r},t.utf8Length=function(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}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.END_OF_STRUCTURE=193,t.NIL=192,t.INDEX_CHANGE=212,t.TYPE_ID=213},function(e,t,n){"use strict";function r(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 i(e,t){e.push(255&t)}function o(e,t){e.push(255&t)}function s(e,t){e.push(255&t),e.push(t>>8&255)}function a(e,t){e.push(255&t),e.push(t>>8&255)}function c(e,t){e.push(255&t),e.push(t>>8&255),e.push(t>>16&255),e.push(t>>24&255)}function u(e,t){var n=t>>24,r=t>>16,i=t>>8,o=t;e.push(255&o),e.push(255&i),e.push(255&r),e.push(255&n)}function h(e,t){var n=Math.floor(t/Math.pow(2,32));u(e,t>>>0),u(e,n)}function f(e,t){var n=t/Math.pow(2,32)>>0;u(e,t>>>0),u(e,n)}Object.defineProperty(t,"__esModule",{value:!0}),t.utf8Write=r,t.int8=i,t.uint8=o,t.int16=s,t.uint16=a,t.int32=c,t.uint32=u,t.int64=h,t.uint64=f,t.float32=function(e,t){v(e,t)},t.float64=function(e,t){y(e,t)};var l=new Int32Array(2),p=new Float32Array(l.buffer),d=new Float64Array(l.buffer);function v(e,t){p[0]=t,c(e,l[0])}function y(e,t){d[0]=t,c(e,l[0]),c(e,l[1])}t.writeFloat32=v,t.writeFloat64=y,t.boolean=function(e,t){return o(e,t?1:0)},t.string=function(e,t){t||(t="");var n=function(e){for(var t=0,n=0,r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}(t),i=0;if(n<32)e.push(160|n),i=1;else if(n<256)e.push(217),o(e,n),i=2;else if(n<65536)e.push(218),a(e,n),i=3;else{if(!(n<4294967296))throw new Error("String too long");e.push(219),u(e,n),i=5}return r(e,e.length,t),i+n},t.number=function e(t,n){return isNaN(n)?e(t,0):isFinite(n)?n!==(0|n)?(t.push(203),y(t,n),9):n>=0?n<128?(o(t,n),1):n<256?(t.push(204),o(t,n),2):n<65536?(t.push(205),a(t,n),3):n<4294967296?(t.push(206),u(t,n),5):(t.push(207),f(t,n),9):n>=-32?(t.push(n),1):n>=-128?(t.push(208),i(t,n),2):n>=-32768?(t.push(209),s(t,n),3):n>=-2147483648?(t.push(210),c(t,n),5):(t.push(211),h(t,n),9):e(t,n>0?Number.MAX_SAFE_INTEGER:-Number.MAX_SAFE_INTEGER)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2),i=n(0),o=n(1),s=function(){function e(e,t,n){void 0===e&&(e={}),void 0===t&&(t=null),this.changed=!1,this.changes=new Set,this.allChanges=new Set,this.deletedKeys={},this.fieldIndexes=e,this.parent=n,this.parentField=t}return e.prototype.change=function(e,t){void 0===t&&(t=!1);var n=this.fieldIndexes[e],r="number"==typeof n?n:e;t?t&&(this.changed=!0,this.changes.add(r),this.allChanges.delete(r)):(this.changed=!0,this.changes.add(r),this.allChanges.add(r)),this.parent&&this.parent.change(this.parentField)},e.prototype.mapIndex=function(e,t){"object"==typeof e&&(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){"object"==typeof e&&(this.deletedKeys[this.indexMap.get(e)]=!0,this.indexMap.delete(e))},e.prototype.isDeleted=function(e){return void 0!==this.deletedKeys[e]},e.prototype.mapIndexChange=function(e,t){"object"!=typeof e||this.indexChange.has(e)||this.indexChange.set(e,t)},e.prototype.getIndexChange=function(e){return this.indexChange&&this.indexChange.get(e)},e.prototype.deleteIndexChange=function(e){"object"==typeof 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),void 0!==e[n]&&this.change(n)}else for(var s=0,a=Object.keys(e);s0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0?"?"+r.join("&"):"",h={headers:a},o&&(h.body=o),[4,s[e](""+this.endpoint+t+u,h)];case 1:return[2,i.sent().data]}}))}))},e.prototype.logout=function(){this.token=void 0,a.removeItem("colyseus-auth-token"),this.unregisterPingService()},e.prototype.registerPingService=function(e){var t=this;void 0===e&&(e=15e3),this.unregisterPingService(),this.keepOnlineInterval=setInterval((function(){return t.request("get","/auth")}),e)},e.prototype.unregisterPingService=function(){clearInterval(this.keepOnlineInterval)},e}();t.Auth=c},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),n(15);var r=n(16);t.Client=r.Client;var i=n(8);t.Protocol=i.Protocol;var o=n(5);t.Room=o.Room;var s=n(13);t.Auth=s.Auth,t.Platform=s.Platform;var a=n(29);t.FossilDeltaSerializer=a.FossilDeltaSerializer;var c=n(34);t.SchemaSerializer=c.SchemaSerializer;var u=n(7);t.registerSerializer=u.registerSerializer,u.registerSerializer("fossil-delta",a.FossilDeltaSerializer),u.registerSerializer("schema",c.SchemaSerializer)},function(e,t){ArrayBuffer.isView||(ArrayBuffer.isView=function(e){return null!==e&&"object"==typeof e&&e.buffer instanceof ArrayBuffer})},function(e,t,n){"use strict";var r,i=this&&this.__extends||(r=function(e,t){return(r=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])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),o=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())}))},s=this&&this.__generator||function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=(i=s.trys).length>0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[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}(this._view,this._offset,e);return this._offset+=e,t},r.prototype._bin=function(e){var t=this._buffer.slice(this._offset,this._offset+e);return this._offset+=e,t},r.prototype._parse=function(){var e,t=this._view.getUint8(this._offset++),n=0,r=0,i=0,o=0;if(t<192)return t<128?t:t<144?this._map(15&t):t<160?this._array(15&t):this._str(31&t);if(t>223)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")},t.default=function(e,t){void 0===t&&(t=0);var n=new r(e,t),i=n._parse();if(n._offset!==e.byteLength)throw new Error(e.byteLength-n._offset+" trailing bytes");return i}},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))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){var t=[],n=[],i=function e(t,n,r){var i=typeof r,o=0,s=0,a=0,c=0,u=0,h=0;if("string"===i){if((u=function(e){for(var t=0,n=0,r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}(r))<32)t.push(160|u),h=1;else if(u<256)t.push(217,u),h=2;else if(u<65536)t.push(218,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("String too long");t.push(219,u>>24,u>>16,u>>8,u),h=5}return n.push({_str:r,_length:u,_offset:t.length}),h+u}if("number"===i)return Math.floor(r)===r&&isFinite(r)?r>=0?r<128?(t.push(r),1):r<256?(t.push(204,r),2):r<65536?(t.push(205,r>>8,r),3):r<4294967296?(t.push(206,r>>24,r>>16,r>>8,r),5):(a=r/Math.pow(2,32)>>0,c=r>>>0,t.push(207,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),9):r>=-32?(t.push(r),1):r>=-128?(t.push(208,r),2):r>=-32768?(t.push(209,r>>8,r),3):r>=-2147483648?(t.push(210,r>>24,r>>16,r>>8,r),5):(a=Math.floor(r/Math.pow(2,32)),c=r>>>0,t.push(211,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),9):(t.push(203),n.push({_float:r,_length:8,_offset:t.length}),9);if("object"===i){if(null===r)return t.push(192),1;if(Array.isArray(r)){if((u=r.length)<16)t.push(144|u),h=1;else if(u<65536)t.push(220,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("Array too large");t.push(221,u>>24,u>>16,u>>8,u),h=5}for(o=0;o>>0,t.push(215,0,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),10}if(r instanceof ArrayBuffer){if((u=r.byteLength)<256)t.push(196,u),h=2;else if(u<65536)t.push(197,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("Buffer too large");t.push(198,u>>24,u>>16,u>>8,u),h=5}return n.push({_bin:r,_length:u,_offset:t.length}),h+u}if("function"==typeof r.toJSON)return e(t,n,r.toJSON());var l=[],p="",d=Object.keys(r);for(o=0,s=d.length;o>8,u),h=3;else{if(!(u<4294967296))throw new Error("Object too large");t.push(223,u>>24,u>>16,u>>8,u),h=5}for(o=0;o0&&(u=n[0]._offset);for(var h,f=0,l=0,p=0,d=t.length;p0){for(var n=0,r=this._enqueuedCalls;n2&&void 0!==arguments[2]?arguments[2]:{};i(this,e),this.url=t,this.protocols=n,this.reconnectEnabled=!0,this.listeners={},this.backoff=o(r.backoff||"exponential",r),this.backoff.onReady=this.onBackoffReady.bind(this),(void 0===r.connect||r.connect)&&this.open()}return r(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";Object.defineProperty(t,"__esModule",{value:!0}),t.createBackoff=function(e,t){return new i(r[e],t)};var r={exponential:function(e,t){return Math.floor(Math.random()*Math.pow(2,e)*t)},fibonacci:function(e,t){if(e>(r=1))for(var n=1,r=2,i=2;i>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){var n=u(e,t);return c(e,t)*Math.pow(2,32)+n}function f(e,t){var n=u(e,t);return u(e,t)*Math.pow(2,32)+n}t.int8=i,t.uint8=o,t.int16=s,t.uint16=a,t.int32=c,t.uint32=u,t.float32=function(e,t){return v(e,t)},t.float64=function(e,t){return y(e,t)},t.int64=h,t.uint64=f;var l=new Int32Array(2),p=new Float32Array(l.buffer),d=new Float64Array(l.buffer);function v(e,t){return l[0]=c(e,t),p[0]}function y(e,t){return l[0]=c(e,t),l[1]=c(e,t),d[0]}t.readFloat32=v,t.readFloat64=y,t.boolean=function(e,t){return o(e,t)>0},t.string=function(e,t){var n,r=e[t.offset++];r<192?n=31&r:217===r?n=o(e,t):218===r?n=a(e,t):219===r&&(n=u(e,t));var i=function(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}(e,t.offset,n);return t.offset+=n,i},t.stringCheck=function(e,t){var n=e[t.offset];return(n<192&&n>160||217===n||218===n||219===n)},t.number=function(e,t){var n=e[t.offset++];return n<128?n:202===n?v(e,t):203===n?y(e,t):204===n?o(e,t):205===n?a(e,t):206===n?u(e,t):207===n?f(e,t):208===n?i(e,t):209===n?s(e,t):210===n?c(e,t):211===n?h(e,t):n>223?-1*(255-n+1):void 0},t.numberCheck=function(e,t){var n=e[t.offset];return n<128||n>=202&&n<=211},t.arrayCheck=function(e,t){return e[t.offset]<160},t.nilCheck=function(e,t){return e[t.offset]===r.NIL},t.indexChangeCheck=function(e,t){return e[t.offset]===r.INDEX_CHANGE}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(3),i=n(1),o=n(0);t.dumpChanges=function e(t){for(var n={},s=t.$changes,a=t._fieldsByIndex||{},c=0,u=Array.from(s.changes);c=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 s=n(12),a=n(2),c=n(0),u=n(1),h=new s.Context,f=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),o([s.type("string",h)],t.prototype,"name",void 0),o([s.type("string",h)],t.prototype,"type",void 0),o([s.type("uint8",h)],t.prototype,"referencedType",void 0),t}(a.Schema);t.ReflectionField=f;var l=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.fields=new c.ArraySchema,t}return i(t,e),o([s.type("uint8",h)],t.prototype,"id",void 0),o([s.type([f],h)],t.prototype,"fields",void 0),t}(a.Schema);t.ReflectionType=l;var p=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.types=new c.ArraySchema,t}return i(t,e),t.encode=function(e){var n=e.constructor,r=new t;r.rootType=n._typeid;var i=function(e,t){for(var n in t){var i=new f;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)},o=n._context.types;for(var s in o){var a=new l;a.id=Number(s),i(a,o[s]._schema)}return r.encodeAll()},t.decode=function(e){var n=new s.Context,r=new t;r.decode(e);var o=r.types.reduce((function(e,t){return e[t.id]=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),t}(a.Schema),e}),{});r.types.forEach((function(e,t){e.fields.forEach((function(t){var r=o[e.id];if(void 0!==t.referencedType){var i=o[t.referencedType];i||(i=t.type.split(":")[1]),0===t.type.indexOf("array")?s.type([i],n)(r.prototype,t.name):0===t.type.indexOf("map")?s.type({map:i},n)(r.prototype,t.name):"ref"===t.type&&s.type(i,n)(r.prototype,t.name)}else s.type(t.type,n)(r.prototype,t.name)}))}));var h=o[r.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 c.ArraySchema:y?new u.MapSchema:d?new p:void 0}}return f},o([s.type([l],h)],t.prototype,"types",void 0),o([s.type("uint8",h)],t.prototype,"rootType",void 0),t}(a.Schema);t.Reflection=p},function(e,t,n){"use strict";var r;function i(){return r||(r="undefined"!=typeof cc&&cc.sys&&cc.sys.localStorage?cc.sys.localStorage:"undefined"!=typeof window&&window.localStorage?window.localStorage:{cache:{},setItem:function(e,t){this.cache[e]=t},getItem:function(e){this.cache[e]},removeItem:function(e){delete this.cache[e]}}),r}Object.defineProperty(t,"__esModule",{value:!0}),t.setItem=function(e,t){i().setItem(e,t)},t.removeItem=function(e){i().removeItem(e)},t.getItem=function(e,t){var n=i().getItem(e);"undefined"!=typeof Promise&&n instanceof Promise?n.then((function(e){return t(e)})):t(n)}},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){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=(i=s.trys).length>0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[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(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=e.slice();return n.push(t),n}function i(e){if(Array.isArray(e)){for(var t=new Array(e.length),n=0;n=0;h--){var f=c[h],l=t[f];if(!n.hasOwnProperty(f)||void 0===n[f]&&void 0!==l&&!1===Array.isArray(n))o.push({operation:"remove",path:r(s,f)}),u=!0;else{var p=n[f];"object"==typeof l&&null!=l&&"object"==typeof p&&null!=p?e(l,p,o,r(s,f)):l!==p&&o.push({operation:"replace",path:r(s,f),value:p,previousValue:l})}}if(!u&&a.length==c.length)return;for(h=a.length-1;h>=0;h--){f=a[h];if(!t.hasOwnProperty(f)&&void 0!==n[f]){p=n[f];var d=r(s,f);"object"==typeof p&&null!=p&&e({},p,o,d),o.push({operation:"add",path:d,value:p})}}}(e,t,n,[]),n}},function(e,t,n){var r,i;r=this,i=function(){"use strict";var e={};function t(){this.a=0,this.b=0,this.i=0,this.z=new Array(16)}t.prototype.init=function(e,t){var n,r,i=0,o=0;for(n=0;n<16;n++)i=i+(r=e[t+n])&65535,o=o+(16-n)*r&65535,this.z[n]=r;this.a=65535&i,this.b=65535&o,this.i=0},t.prototype.next=function(e){var t=this.z[this.i];this.z[this.i]=e,this.i=this.i+1&15,this.a=this.a-t+e&65535,this.b=this.b-16*t+this.a&65535},t.prototype.value=function(){return(65535&this.a|(65535&this.b)<<16)>>>0};var n="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~".split("").map((function(e){return e.charCodeAt(0)})),r=[-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];function i(e){this.a=e,this.pos=0}function o(){this.a=[]}function s(e){var t,n;for(t=1,n=64;e>=n;t++,n<<=6);return t}function a(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}return i.prototype.haveBytes=function(){return this.posthis.a.length)throw new RangeError("out of bounds");return e},i.prototype.getChar=function(){return String.fromCharCode(this.getByte())},i.prototype.getInt=function(){for(var e,t=0;this.haveBytes()&&(e=r[127&this.getByte()])>=0;)t=(t<<6)+e;return this.pos--,t>>>0},o.prototype.toArray=function(){return this.a},o.prototype.putByte=function(e){this.a.push(255&e)},o.prototype.putChar=function(e){this.putByte(e.charCodeAt(0))},o.prototype.putInt=function(e){var t,r,i=[];if(0!==e){for(t=0;e>0;t++,e>>>=6)i.push(n[63&e]);for(r=t-1;r>=0;r--)this.putByte(i[r])}else this.putChar("0")},o.prototype.putArray=function(e,t,n){for(var r=t;r=0&&O-- >0;){var C,A,S,k,I,P,E;for(k=0,P=y=16*g,E=w+r;P=s(r-I)+s(C)+s(A)+3&&C>_&&(_=C,b=y-I,m=S),g=l[g]}if(_>0){m>0&&(i.putInt(m),i.putChar(":"),i.putArray(n,w,w+m),w+=m),w+=_,i.putInt(_),i.putChar("@"),i.putInt(b),i.putChar(","),b+_-1>h&&(h=b+_-1),_=0;break}if(w+r+16>=c){i.putInt(c-w),i.putChar(":"),i.putArray(n,w,w+c-w),w=c;break}v.next(n[w+r+16]),r++}return wr)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((s+=l)>r)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((!n||!1!==n.verifyChecksum)&&l!==a(d))throw new Error("bad checksum");if(s!==r)throw new Error("generated size does not match predicted size");return d;default:throw new Error("unknown delta operator")}}throw new Error("unterminated delta")},e},e.exports?e.exports=i():r.fossilDelta=i()},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(3),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,t){this.state?(new r.Reflection).decode(e,t):this.state=r.Reflection.decode(e)},e}();t.SchemaSerializer=i}])})); \ No newline at end of file diff --git a/dist/index.html b/dist/index.html index 3ef3143..c5f183e 100644 --- a/dist/index.html +++ b/dist/index.html @@ -11,8 +11,8 @@ Messages
- - + Room name:
+ Send data:
@@ -27,32 +27,13 @@ diff --git a/src/Room.ts b/src/Room.ts index 49ff63e..1c6d1a1 100644 --- a/src/Room.ts +++ b/src/Room.ts @@ -12,6 +12,7 @@ import { SchemaConstructor } from './serializer/SchemaSerializer'; import { Context, Schema } from '@colyseus/schema'; import * as encode from '@colyseus/schema/lib/encoding/encode'; +import * as decode from '@colyseus/schema/lib/encoding/decode'; export interface RoomAvailable { roomId: string; @@ -29,7 +30,6 @@ export class Room { // Public signals public onJoin = createSignal(); public onStateChange = createSignal<(state: State) => void>(); - public onMessage = createSignal<(data: any) => void>(); public onError = createSignal<(message: string) => void>(); public onLeave = createSignal<(code: number) => void>(); @@ -43,6 +43,8 @@ export class Room { // TODO: remove me on 1.0.0 protected rootSchema: SchemaConstructor; + protected onMessageHandlers: { [messageType: string]: (message: any) => void } = {}; + constructor(name: string, rootSchema?: SchemaConstructor) { this.id = null; this.name = name; @@ -94,28 +96,42 @@ export class Room { } } - public send(type: string, message?: any): void - public send(message: T): void { - if (message instanceof Schema) { - this.connection.send([ - Protocol.ROOM_DATA, - (message.constructor as typeof Schema)._typeid, - ...message.encodeAll() - ]); - - } else if (typeof (message) === "string") { - const data = arguments[1]; - const encoded = msgpack.encode(data); + public onMessage( + type: "*", + callback: (type: string | number | typeof Schema, message: T) => void + ) + public onMessage any))>( + type: T, + callback: (message: InstanceType) => void + ) + public onMessage( + type: T, + callback: (message: T) => void + ) + public onMessage( + type: '*' | string | number | typeof Schema, + callback: (...args: any[]) => void + ) { + this.onMessageHandlers[this.getMessageHandlerKey(type)] = callback; + return this; + } - const initialBytes: number[] = [Protocol.ROOM_DATA]; - encode.string(initialBytes, arguments[0]); + public send(type: string | number, message?: any): void { + const encoded = msgpack.encode(message); + const initialBytes: number[] = [Protocol.ROOM_DATA]; - const arr = new Uint8Array(initialBytes.length + encoded.byteLength); - arr.set(new Uint8Array(initialBytes), 0); - arr.set(new Uint8Array(encoded), initialBytes.length); + if (typeof(type) === "string") { + encode.string(initialBytes, type); - this.connection.send(arr.buffer); + } else { + encode.number(initialBytes, type); } + + const arr = new Uint8Array(initialBytes.length + encoded.byteLength); + arr.set(new Uint8Array(initialBytes), 0); + arr.set(new Uint8Array(encoded), initialBytes.length); + + this.connection.send(arr.buffer); } public get state (): State { @@ -148,7 +164,6 @@ export class Room { } this.onJoin.clear(); this.onStateChange.clear(); - this.onMessage.clear(); this.onError.clear(); this.onLeave.clear(); } @@ -197,7 +212,7 @@ export class Room { const message: Schema = new (type as any)(); message.decode(bytes, { offset: 2 }); - this.onMessage.invoke(message); + this.dispatchMessage(type, message); } else if (code === Protocol.ROOM_STATE) { bytes.shift(); // drop `code` byte @@ -208,7 +223,12 @@ export class Room { this.patch(bytes); } else if (code === Protocol.ROOM_DATA) { - this.onMessage.invoke(msgpack.decode(event.data, 1)); + const it: decode.Iterator = { offset: 1 }; + const type = (decode.stringCheck(bytes, it)) + ? decode.string(bytes, it) + : decode.number(bytes, it); + + this.dispatchMessage(type, msgpack.decode(bytes.slice(it.offset, bytes.length))); } } @@ -222,4 +242,33 @@ export class Room { this.onStateChange.invoke(this.serializer.getState()); } + private dispatchMessage(type: string | number | typeof Schema, message: any) { + const messageType = this.getMessageHandlerKey(type); + + if (this.onMessageHandlers[messageType]) { + this.onMessageHandlers[messageType](message); + + } else if (this.onMessageHandlers['*']) { + (this.onMessageHandlers[messageType] as any)(type, message); + + } else { + console.warn(`onMessage not registered for type '${type}'.`); + } + } + + private getMessageHandlerKey(type: string | number | typeof Schema): string { + switch (typeof(type)) { + // typeof Schema + case "object": return `$${(type as typeof Schema)._typeid}`; + + // string + case "string": return type; + + // number + case "number": return `i${type}`; + + default: throw new Error("invalid message type."); + } + } + } From 442a62ae49b54aec77b12829dc0e072004b37ebe Mon Sep 17 00:00:00 2001 From: Endel Dreyer Date: Sat, 14 Mar 2020 15:19:55 +0200 Subject: [PATCH 03/11] fixes parsing messages from Buffer. colyseus/colyseus#315 --- dist/colyseus.js | 4 ++-- package.json | 2 +- src/Room.ts | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dist/colyseus.js b/dist/colyseus.js index 7742719..e545697 100644 --- a/dist/colyseus.js +++ b/dist/colyseus.js @@ -1,2 +1,2 @@ -/*! colyseus.js@0.13.0-alpha.0 */ -!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()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=15)}([function(e,t,n){"use strict";var r,i=this&&this.__extends||(r=function(e,t){return(r=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])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),o=this&&this.__spreadArrays||function(){for(var e=0,t=0,n=arguments.length;t=e+t-1}));return i.map((function(e){var t=e&&e.$changes;t&&(t.parent.deleteIndex(e),delete t.parent)})),o.forEach((function(e){var t=e&&e.$changes;t&&t.parentField--})),i},t}(Array);t.ArraySchema=s},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function e(t){var n=this;for(var r in void 0===t&&(t={}),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(t){var r;if(t)(r=Object.assign(new e,n)).onAdd=n.onAdd,r.onRemove=n.onRemove,r.onChange=n.onChange;else{var i=new e;for(var o in n)"object"==typeof n[o]?i[o]=n[o].clone():i[o]=n[o]}return r}},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(e){for(var t=0,r=new Map,i=0,o=e;i0;var C=!1;g.length>w&&Array.prototype.splice.call(g,w).forEach((function(t,n){if(t&&t.onRemove)try{t.onRemove()}catch(t){e.onError(t)}if(m.onRemove)try{m.onRemove(t,w+n)}catch(t){e.onError(t)}}));for(var A=0;A0;C=!1;var x=Object.keys(M);for(A=0;A0)try{this.onChange(r)}catch(t){e.onError(t)}return this},e.prototype.encode=function(e,t,n,r){var i=this;if(void 0===e&&(e=this),void 0===t&&(t=!1),void 0===r&&(r=[]),!this.$changes.changed&&!t)return this._encodeEndOfStructure(this,e,r),r;for(var a=this._schema,h=this._indexes,f=this._fieldsByIndex,d=this._filters,v=Array.from(t||n?this.$changes.allChanges:this.$changes.changes).sort(),y=function(y,_){var b=f[v[y]]||v[y],m="_"+b,w=a[b],O=d&&d[b],C=g[m],A=h[b];if(void 0===C)s.uint8(r,o.NIL),s.number(r,A);else if(w._schema){if(n&&O&&!O.call(g,n,C,e))return"continue";C?(s.number(r,A),l(C,w,g,b),g.tryEncodeTypeId(r,w,C.constructor),C.encode(e,t,n,r)):(s.uint8(r,o.NIL),s.number(r,A))}else if(Array.isArray(w)){var S=C.$changes;s.number(r,A),s.number(r,C.length);var k=Array.from(t||n?S.allChanges:S.changes).filter((function(e){return void 0!==i[m][e]})).sort((function(e,t){return e-t})),I=k.length;s.number(r,I);var E="string"!=typeof w[0];l(g[m],c.ArraySchema,g,b);for(var M=0;M=400?o:i)(h)},(a=n.body)&&/Array|Object/.test(a.constructor)&&(f["content-type"]="application/json",a=JSON.stringify(a)),f)h.setRequestHeader(s,f[s]);h.send(a)}))}n.r(t),n.d(t,"send",(function(){return 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(5)),o=n(20),s=n(21),a=n(6),c=n(7),u=r(n(8)),h=r(n(9)),f=function(){function e(e,t){var n=this;this.onJoin=o.createSignal(),this.onStateChange=o.createSignal(),this.onError=o.createSignal(),this.onLeave=o.createSignal(),this.hasJoined=!1,this.onMessageHandlers={},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){if(!t.hasJoined)return console.error("Room connection was closed unexpectedly ("+e.code+"): "+e.reason),void t.onError.invoke(e.reason);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.onMessage=function(e,t){return this.onMessageHandlers[this.getMessageHandlerKey(e)]=t,this},e.prototype.send=function(e,t){var n=i.encode(t),r=[c.Protocol.ROOM_DATA];"string"==typeof e?u.string(r,e):u.number(r,e);var o=new Uint8Array(r.length+n.byteLength);o.set(new Uint8Array(r),0),o.set(new Uint8Array(n),r.length),this.connection.send(o.buffer)},Object.defineProperty(e.prototype,"state",{get:function(){return this.serializer.getState()},enumerable:!0,configurable:!0}),e.prototype.listen=function(e,t,n){if("schema"!==this.serializerId)return this.serializerId||console.warn("room.Listen() should be called after room.onJoin has been called (DEPRECATION WARNING)"),this.serializer.api.listen(e,t,n);console.error("'"+this.serializerId+"' serializer doesn't support .listen() method here.")},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.onError.clear(),this.onLeave.clear()},e.prototype.onMessageCallback=function(e){var t=Array.from(new Uint8Array(e.data)),n=t[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);"fossil-delta"===this.serializerId||this.rootSchema||(this.serializer=new o),t.length>r&&this.serializer.handshake&&this.serializer.handshake(t,{offset:1}),this.hasJoined=!0,this.onJoin.invoke(),this.connection.send([c.Protocol.JOIN_ROOM])}else if(n===c.Protocol.JOIN_ERROR)this.onError.invoke(c.utf8Read(t,1));else if(n===c.Protocol.LEAVE_ROOM)this.leave();else if(n===c.Protocol.ROOM_DATA_SCHEMA){var s=new(f=this.serializer.getState().constructor._context.get(t[1]));s.decode(t,{offset:2}),this.dispatchMessage(f,s)}else if(n===c.Protocol.ROOM_STATE)t.shift(),this.setState(t);else if(n===c.Protocol.ROOM_STATE_PATCH)t.shift(),this.patch(t);else if(n===c.Protocol.ROOM_DATA){var u={offset:1},f=h.stringCheck(t,u)?h.string(t,u):h.number(t,u);this.dispatchMessage(f,i.decode(t.slice(u.offset,t.length)))}},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.prototype.dispatchMessage=function(e,t){var n=this.getMessageHandlerKey(e);this.onMessageHandlers[n]?this.onMessageHandlers[n](t):this.onMessageHandlers["*"]?this.onMessageHandlers[n](t):console.warn("onMessage not registered for type '"+e+"'.")},e.prototype.getMessageHandlerKey=function(e){switch(console.log("TYPE =>",e,typeof e),typeof e){case"object":return"$"+e._typeid;case"string":return e;case"number":return"i"+e;default:throw new Error("invalid message type.")}},e}();t.Room=f},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(18)),o=r(n(19));t.decode=i.default,t.encode=o.default},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r={};t.registerSerializer=function(e,t){r[e]=t},t.getSerializer=function(e){return r[e]}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),function(e){e[e.HANDSHAKE=9]="HANDSHAKE",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",e[e.ROOM_DATA_SCHEMA=16]="ROOM_DATA_SCHEMA"}(t.Protocol||(t.Protocol={})),t.utf8Read=function(e,t){for(var n=e[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[++o])<<6|(63&e[++o])<<0);else r+=String.fromCharCode((31&a)<<6|63&e[++o]);else r+=String.fromCharCode(a)}return r},t.utf8Length=function(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}},function(e,t,n){"use strict";function r(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 i(e,t){e.push(255&t)}function o(e,t){e.push(255&t)}function s(e,t){e.push(255&t),e.push(t>>8&255)}function a(e,t){e.push(255&t),e.push(t>>8&255)}function c(e,t){e.push(255&t),e.push(t>>8&255),e.push(t>>16&255),e.push(t>>24&255)}function u(e,t){var n=t>>24,r=t>>16,i=t>>8,o=t;e.push(255&o),e.push(255&i),e.push(255&r),e.push(255&n)}function h(e,t){var n=Math.floor(t/Math.pow(2,32));u(e,t>>>0),u(e,n)}function f(e,t){var n=t/Math.pow(2,32)>>0;u(e,t>>>0),u(e,n)}Object.defineProperty(t,"__esModule",{value:!0}),t.utf8Write=r,t.int8=i,t.uint8=o,t.int16=s,t.uint16=a,t.int32=c,t.uint32=u,t.int64=h,t.uint64=f,t.float32=function(e,t){v(e,t)},t.float64=function(e,t){y(e,t)};var l=new Int32Array(2),p=new Float32Array(l.buffer),d=new Float64Array(l.buffer);function v(e,t){p[0]=t,c(e,l[0])}function y(e,t){d[0]=t,c(e,l[0]),c(e,l[1])}t.writeFloat32=v,t.writeFloat64=y,t.boolean=function(e,t){return o(e,t?1:0)},t.string=function(e,t){t||(t="");var n=function(e){for(var t=0,n=0,r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}(t),i=0;if(n<32)e.push(160|n),i=1;else if(n<256)e.push(217),o(e,n),i=2;else if(n<65536)e.push(218),a(e,n),i=3;else{if(!(n<4294967296))throw new Error("String too long");e.push(219),u(e,n),i=5}return r(e,e.length,t),i+n},t.number=function e(t,n){return isNaN(n)?e(t,0):isFinite(n)?n!==(0|n)?(t.push(203),y(t,n),9):n>=0?n<128?(o(t,n),1):n<256?(t.push(204),o(t,n),2):n<65536?(t.push(205),a(t,n),3):n<4294967296?(t.push(206),u(t,n),5):(t.push(207),f(t,n),9):n>=-32?(t.push(n),1):n>=-128?(t.push(208),i(t,n),2):n>=-32768?(t.push(209),s(t,n),3):n>=-2147483648?(t.push(210),c(t,n),5):(t.push(211),h(t,n),9):e(t,n>0?Number.MAX_SAFE_INTEGER:-Number.MAX_SAFE_INTEGER)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(10);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){var n=u(e,t);return c(e,t)*Math.pow(2,32)+n}function f(e,t){var n=u(e,t);return u(e,t)*Math.pow(2,32)+n}t.int8=i,t.uint8=o,t.int16=s,t.uint16=a,t.int32=c,t.uint32=u,t.float32=function(e,t){return v(e,t)},t.float64=function(e,t){return y(e,t)},t.int64=h,t.uint64=f;var l=new Int32Array(2),p=new Float32Array(l.buffer),d=new Float64Array(l.buffer);function v(e,t){return l[0]=c(e,t),p[0]}function y(e,t){return l[0]=c(e,t),l[1]=c(e,t),d[0]}t.readFloat32=v,t.readFloat64=y,t.boolean=function(e,t){return o(e,t)>0},t.string=function(e,t){var n,r=e[t.offset++];r<192?n=31&r:217===r?n=o(e,t):218===r?n=a(e,t):219===r&&(n=u(e,t));var i=function(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}(e,t.offset,n);return t.offset+=n,i},t.stringCheck=function(e,t){var n=e[t.offset];return(n<192&&n>160||217===n||218===n||219===n)},t.number=function(e,t){var n=e[t.offset++];return n<128?n:202===n?v(e,t):203===n?y(e,t):204===n?o(e,t):205===n?a(e,t):206===n?u(e,t):207===n?f(e,t):208===n?i(e,t):209===n?s(e,t):210===n?c(e,t):211===n?h(e,t):n>223?-1*(255-n+1):void 0},t.numberCheck=function(e,t){var n=e[t.offset];return n<128||n>=202&&n<=211},t.arrayCheck=function(e,t){return e[t.offset]<160},t.nilCheck=function(e,t){return e[t.offset]===r.NIL},t.indexChangeCheck=function(e,t){return e[t.offset]===r.INDEX_CHANGE}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.END_OF_STRUCTURE=193,t.NIL=192,t.INDEX_CHANGE=212,t.TYPE_ID=213},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){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=(i=s.trys).length>0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0?"?"+r.join("&"):"",h={headers:a},o&&(h.body=o),[4,s[e](""+this.endpoint+t+u,h)];case 1:return[2,i.sent().data]}}))}))},e.prototype.logout=function(){this.token=void 0,a.removeItem("colyseus-auth-token"),this.unregisterPingService()},e.prototype.registerPingService=function(e){var t=this;void 0===e&&(e=15e3),this.unregisterPingService(),this.keepOnlineInterval=setInterval((function(){return t.request("get","/auth")}),e)},e.prototype.unregisterPingService=function(){clearInterval(this.keepOnlineInterval)},e}();t.Auth=c},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2);t.Schema=r.Schema;var i=n(1);t.MapSchema=i.MapSchema;var o=n(0);t.ArraySchema=o.ArraySchema;var s=n(33);t.dumpChanges=s.dumpChanges;var a=n(34);t.Reflection=a.Reflection,t.ReflectionType=a.ReflectionType,t.ReflectionField=a.ReflectionField;var c=n(14);t.type=c.type,t.deprecated=c.deprecated,t.filter=c.filter,t.defineTypes=c.defineTypes,t.Context=c.Context},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2),i=n(0),o=n(1),s=function(){function e(e,t,n){void 0===e&&(e={}),void 0===t&&(t=null),this.changed=!1,this.changes=new Set,this.allChanges=new Set,this.deletedKeys={},this.fieldIndexes=e,this.parent=n,this.parentField=t}return e.prototype.change=function(e,t){void 0===t&&(t=!1);var n=this.fieldIndexes[e],r="number"==typeof n?n:e;t?t&&(this.changed=!0,this.changes.add(r),this.allChanges.delete(r)):(this.changed=!0,this.changes.add(r),this.allChanges.add(r)),this.parent&&this.parent.change(this.parentField)},e.prototype.mapIndex=function(e,t){"object"==typeof e&&(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){"object"==typeof e&&(this.deletedKeys[this.indexMap.get(e)]=!0,this.indexMap.delete(e))},e.prototype.isDeleted=function(e){return void 0!==this.deletedKeys[e]},e.prototype.mapIndexChange=function(e,t){"object"!=typeof e||this.indexChange.has(e)||this.indexChange.set(e,t)},e.prototype.getIndexChange=function(e){return this.indexChange&&this.indexChange.get(e)},e.prototype.deleteIndexChange=function(e){"object"==typeof 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),void 0!==e[n]&&this.change(n)}else for(var s=0,a=Object.keys(e);s0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[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}(this._view,this._offset,e);return this._offset+=e,t},r.prototype._bin=function(e){var t=this._buffer.slice(this._offset,this._offset+e);return this._offset+=e,t},r.prototype._parse=function(){var e,t=this._view.getUint8(this._offset++),n=0,r=0,i=0,o=0;if(t<192)return t<128?t:t<144?this._map(15&t):t<160?this._array(15&t):this._str(31&t);if(t>223)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")},t.default=function(e,t){void 0===t&&(t=0);var n=new r(e,t),i=n._parse();if(n._offset!==e.byteLength)throw new Error(e.byteLength-n._offset+" trailing bytes");return i}},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))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){var t=[],n=[],i=function e(t,n,r){var i=typeof r,o=0,s=0,a=0,c=0,u=0,h=0;if("string"===i){if((u=function(e){for(var t=0,n=0,r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}(r))<32)t.push(160|u),h=1;else if(u<256)t.push(217,u),h=2;else if(u<65536)t.push(218,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("String too long");t.push(219,u>>24,u>>16,u>>8,u),h=5}return n.push({_str:r,_length:u,_offset:t.length}),h+u}if("number"===i)return Math.floor(r)===r&&isFinite(r)?r>=0?r<128?(t.push(r),1):r<256?(t.push(204,r),2):r<65536?(t.push(205,r>>8,r),3):r<4294967296?(t.push(206,r>>24,r>>16,r>>8,r),5):(a=r/Math.pow(2,32)>>0,c=r>>>0,t.push(207,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),9):r>=-32?(t.push(r),1):r>=-128?(t.push(208,r),2):r>=-32768?(t.push(209,r>>8,r),3):r>=-2147483648?(t.push(210,r>>24,r>>16,r>>8,r),5):(a=Math.floor(r/Math.pow(2,32)),c=r>>>0,t.push(211,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),9):(t.push(203),n.push({_float:r,_length:8,_offset:t.length}),9);if("object"===i){if(null===r)return t.push(192),1;if(Array.isArray(r)){if((u=r.length)<16)t.push(144|u),h=1;else if(u<65536)t.push(220,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("Array too large");t.push(221,u>>24,u>>16,u>>8,u),h=5}for(o=0;o>>0,t.push(215,0,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),10}if(r instanceof ArrayBuffer){if((u=r.byteLength)<256)t.push(196,u),h=2;else if(u<65536)t.push(197,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("Buffer too large");t.push(198,u>>24,u>>16,u>>8,u),h=5}return n.push({_bin:r,_length:u,_offset:t.length}),h+u}if("function"==typeof r.toJSON)return e(t,n,r.toJSON());var l=[],p="",d=Object.keys(r);for(o=0,s=d.length;o>8,u),h=3;else{if(!(u<4294967296))throw new Error("Object too large");t.push(223,u>>24,u>>16,u>>8,u),h=5}for(o=0;o0&&(u=n[0]._offset);for(var h,f=0,l=0,p=0,d=t.length;p0){for(var n=0,r=this._enqueuedCalls;n2&&void 0!==arguments[2]?arguments[2]:{};i(this,e),this.url=t,this.protocols=n,this.reconnectEnabled=!0,this.listeners={},this.backoff=o(r.backoff||"exponential",r),this.backoff.onReady=this.onBackoffReady.bind(this),(void 0===r.connect||r.connect)&&this.open()}return r(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";Object.defineProperty(t,"__esModule",{value:!0}),t.createBackoff=function(e,t){return new i(r[e],t)};var r={exponential:function(e,t){return Math.floor(Math.random()*Math.pow(2,e)*t)},fibonacci:function(e,t){if(e>(r=1))for(var n=1,r=2,i=2;i0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[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(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=e.slice();return n.push(t),n}function i(e){if(Array.isArray(e)){for(var t=new Array(e.length),n=0;n=0;h--){var f=c[h],l=t[f];if(!n.hasOwnProperty(f)||void 0===n[f]&&void 0!==l&&!1===Array.isArray(n))o.push({operation:"remove",path:r(s,f)}),u=!0;else{var p=n[f];"object"==typeof l&&null!=l&&"object"==typeof p&&null!=p?e(l,p,o,r(s,f)):l!==p&&o.push({operation:"replace",path:r(s,f),value:p,previousValue:l})}}if(!u&&a.length==c.length)return;for(h=a.length-1;h>=0;h--){f=a[h];if(!t.hasOwnProperty(f)&&void 0!==n[f]){p=n[f];var d=r(s,f);"object"==typeof p&&null!=p&&e({},p,o,d),o.push({operation:"add",path:d,value:p})}}}(e,t,n,[]),n}},function(e,t,n){var r,i;r=this,i=function(){"use strict";var e={};function t(){this.a=0,this.b=0,this.i=0,this.z=new Array(16)}t.prototype.init=function(e,t){var n,r,i=0,o=0;for(n=0;n<16;n++)i=i+(r=e[t+n])&65535,o=o+(16-n)*r&65535,this.z[n]=r;this.a=65535&i,this.b=65535&o,this.i=0},t.prototype.next=function(e){var t=this.z[this.i];this.z[this.i]=e,this.i=this.i+1&15,this.a=this.a-t+e&65535,this.b=this.b-16*t+this.a&65535},t.prototype.value=function(){return(65535&this.a|(65535&this.b)<<16)>>>0};var n="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~".split("").map((function(e){return e.charCodeAt(0)})),r=[-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];function i(e){this.a=e,this.pos=0}function o(){this.a=[]}function s(e){var t,n;for(t=1,n=64;e>=n;t++,n<<=6);return t}function a(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}return i.prototype.haveBytes=function(){return this.posthis.a.length)throw new RangeError("out of bounds");return e},i.prototype.getChar=function(){return String.fromCharCode(this.getByte())},i.prototype.getInt=function(){for(var e,t=0;this.haveBytes()&&(e=r[127&this.getByte()])>=0;)t=(t<<6)+e;return this.pos--,t>>>0},o.prototype.toArray=function(){return this.a},o.prototype.putByte=function(e){this.a.push(255&e)},o.prototype.putChar=function(e){this.putByte(e.charCodeAt(0))},o.prototype.putInt=function(e){var t,r,i=[];if(0!==e){for(t=0;e>0;t++,e>>>=6)i.push(n[63&e]);for(r=t-1;r>=0;r--)this.putByte(i[r])}else this.putChar("0")},o.prototype.putArray=function(e,t,n){for(var r=t;r=0&&O-- >0;){var C,A,S,k,I,E,M;for(k=0,E=y=16*g,M=w+r;E=s(r-I)+s(C)+s(A)+3&&C>_&&(_=C,b=y-I,m=S),g=l[g]}if(_>0){m>0&&(i.putInt(m),i.putChar(":"),i.putArray(n,w,w+m),w+=m),w+=_,i.putInt(_),i.putChar("@"),i.putInt(b),i.putChar(","),b+_-1>h&&(h=b+_-1),_=0;break}if(w+r+16>=c){i.putInt(c-w),i.putChar(":"),i.putArray(n,w,w+c-w),w=c;break}v.next(n[w+r+16]),r++}return wr)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((s+=l)>r)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((!n||!1!==n.verifyChecksum)&&l!==a(d))throw new Error("bad checksum");if(s!==r)throw new Error("generated size does not match predicted size");return d;default:throw new Error("unknown delta operator")}}throw new Error("unterminated delta")},e},e.exports?e.exports=i():r.fossilDelta=i()},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(12),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,t){this.state?(new r.Reflection).decode(e,t):this.state=r.Reflection.decode(e)},e}();t.SchemaSerializer=i},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(12),i=n(1),o=n(0);t.dumpChanges=function e(t){for(var n={},s=t.$changes,a=t._fieldsByIndex||{},c=0,u=Array.from(s.changes);c=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 s=n(14),a=n(2),c=n(0),u=n(1),h=new s.Context,f=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),o([s.type("string",h)],t.prototype,"name",void 0),o([s.type("string",h)],t.prototype,"type",void 0),o([s.type("uint8",h)],t.prototype,"referencedType",void 0),t}(a.Schema);t.ReflectionField=f;var l=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.fields=new c.ArraySchema,t}return i(t,e),o([s.type("uint8",h)],t.prototype,"id",void 0),o([s.type([f],h)],t.prototype,"fields",void 0),t}(a.Schema);t.ReflectionType=l;var p=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.types=new c.ArraySchema,t}return i(t,e),t.encode=function(e){var n=e.constructor,r=new t;r.rootType=n._typeid;var i=function(e,t){for(var n in t){var i=new f;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)},o=n._context.types;for(var s in o){var a=new l;a.id=Number(s),i(a,o[s]._schema)}return r.encodeAll()},t.decode=function(e){var n=new s.Context,r=new t;r.decode(e);var o=r.types.reduce((function(e,t){return e[t.id]=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),t}(a.Schema),e}),{});r.types.forEach((function(e,t){e.fields.forEach((function(t){var r=o[e.id];if(void 0!==t.referencedType){var i=o[t.referencedType];i||(i=t.type.split(":")[1]),0===t.type.indexOf("array")?s.type([i],n)(r.prototype,t.name):0===t.type.indexOf("map")?s.type({map:i},n)(r.prototype,t.name):"ref"===t.type&&s.type(i,n)(r.prototype,t.name)}else s.type(t.type,n)(r.prototype,t.name)}))}));var h=o[r.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 c.ArraySchema:y?new u.MapSchema:d?new p:void 0}}return f},o([s.type([l],h)],t.prototype,"types",void 0),o([s.type("uint8",h)],t.prototype,"rootType",void 0),t}(a.Schema);t.Reflection=p}])})); \ No newline at end of file +/*! colyseus.js@0.13.0-alpha.3 */ +!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()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=15)}([function(e,t,n){"use strict";var r,i=this&&this.__extends||(r=function(e,t){return(r=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])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),o=this&&this.__spreadArrays||function(){for(var e=0,t=0,n=arguments.length;t=e+t-1}));return i.map((function(e){var t=e&&e.$changes;t&&(t.parent.deleteIndex(e),delete t.parent)})),o.forEach((function(e){var t=e&&e.$changes;t&&t.parentField--})),i},t}(Array);t.ArraySchema=s},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function e(t){var n=this;for(var r in void 0===t&&(t={}),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(t){var r;if(t)(r=Object.assign(new e,n)).onAdd=n.onAdd,r.onRemove=n.onRemove,r.onChange=n.onChange;else{var i=new e;for(var o in n)"object"==typeof n[o]?i[o]=n[o].clone():i[o]=n[o]}return r}},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(e){for(var t=0,r=new Map,i=0,o=e;i0;var C=!1;g.length>w&&Array.prototype.splice.call(g,w).forEach((function(t,n){if(t&&t.onRemove)try{t.onRemove()}catch(t){e.onError(t)}if(m.onRemove)try{m.onRemove(t,w+n)}catch(t){e.onError(t)}}));for(var A=0;A0;C=!1;var x=Object.keys(E);for(A=0;A0)try{this.onChange(r)}catch(t){e.onError(t)}return this},e.prototype.encode=function(e,t,n,r){var i=this;if(void 0===e&&(e=this),void 0===t&&(t=!1),void 0===r&&(r=[]),!this.$changes.changed&&!t)return this._encodeEndOfStructure(this,e,r),r;for(var a=this._schema,h=this._indexes,f=this._fieldsByIndex,d=this._filters,v=Array.from(t||n?this.$changes.allChanges:this.$changes.changes).sort(),y=function(y,_){var b=f[v[y]]||v[y],m="_"+b,w=a[b],O=d&&d[b],C=g[m],A=h[b];if(void 0===C)s.uint8(r,o.NIL),s.number(r,A);else if(w._schema){if(n&&O&&!O.call(g,n,C,e))return"continue";C?(s.number(r,A),l(C,w,g,b),g.tryEncodeTypeId(r,w,C.constructor),C.encode(e,t,n,r)):(s.uint8(r,o.NIL),s.number(r,A))}else if(Array.isArray(w)){var S=C.$changes;s.number(r,A),s.number(r,C.length);var k=Array.from(t||n?S.allChanges:S.changes).filter((function(e){return void 0!==i[m][e]})).sort((function(e,t){return e-t})),I=k.length;s.number(r,I);var M="string"!=typeof w[0];l(g[m],c.ArraySchema,g,b);for(var E=0;E=400?o:i)(h)},(a=n.body)&&/Array|Object/.test(a.constructor)&&(f["content-type"]="application/json",a=JSON.stringify(a)),f)h.setRequestHeader(s,f[s]);h.send(a)}))}n.r(t),n.d(t,"send",(function(){return 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(5)),o=n(20),s=n(21),a=n(6),c=n(7),u=r(n(8)),h=r(n(9)),f=function(){function e(e,t){var n=this;this.onJoin=o.createSignal(),this.onStateChange=o.createSignal(),this.onError=o.createSignal(),this.onLeave=o.createSignal(),this.hasJoined=!1,this.onMessageHandlers={},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){if(!t.hasJoined)return console.error("Room connection was closed unexpectedly ("+e.code+"): "+e.reason),void t.onError.invoke(e.reason);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.onMessage=function(e,t){return this.onMessageHandlers[this.getMessageHandlerKey(e)]=t,this},e.prototype.send=function(e,t){var n=i.encode(t),r=[c.Protocol.ROOM_DATA];"string"==typeof e?u.string(r,e):u.number(r,e);var o=new Uint8Array(r.length+n.byteLength);o.set(new Uint8Array(r),0),o.set(new Uint8Array(n),r.length),this.connection.send(o.buffer)},Object.defineProperty(e.prototype,"state",{get:function(){return this.serializer.getState()},enumerable:!0,configurable:!0}),e.prototype.listen=function(e,t,n){if("schema"!==this.serializerId)return this.serializerId||console.warn("room.Listen() should be called after room.onJoin has been called (DEPRECATION WARNING)"),this.serializer.api.listen(e,t,n);console.error("'"+this.serializerId+"' serializer doesn't support .listen() method here.")},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.onError.clear(),this.onLeave.clear()},e.prototype.onMessageCallback=function(e){var t=Array.from(new Uint8Array(e.data)),n=t[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);"fossil-delta"===this.serializerId||this.rootSchema||(this.serializer=new o),t.length>r&&this.serializer.handshake&&this.serializer.handshake(t,{offset:1}),this.hasJoined=!0,this.onJoin.invoke(),this.connection.send([c.Protocol.JOIN_ROOM])}else if(n===c.Protocol.JOIN_ERROR)this.onError.invoke(c.utf8Read(t,1));else if(n===c.Protocol.LEAVE_ROOM)this.leave();else if(n===c.Protocol.ROOM_DATA_SCHEMA){var s=new(f=this.serializer.getState().constructor._context.get(t[1]));s.decode(t,{offset:2}),this.dispatchMessage(f,s)}else if(n===c.Protocol.ROOM_STATE)t.shift(),this.setState(t);else if(n===c.Protocol.ROOM_STATE_PATCH)t.shift(),this.patch(t);else if(n===c.Protocol.ROOM_DATA){var u={offset:1},f=h.stringCheck(t,u)?h.string(t,u):h.number(t,u);this.dispatchMessage(f,i.decode(e.data.slice(u.offset,t.length)))}},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.prototype.dispatchMessage=function(e,t){var n=this.getMessageHandlerKey(e);this.onMessageHandlers[n]?this.onMessageHandlers[n](t):this.onMessageHandlers["*"]?this.onMessageHandlers[n](e,t):console.warn("onMessage not registered for type '"+e+"'.")},e.prototype.getMessageHandlerKey=function(e){switch(typeof e){case"function":return"$"+e._typeid;case"string":return e;case"number":return"i"+e;default:throw new Error("invalid message type.")}},e}();t.Room=f},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(18)),o=r(n(19));t.decode=i.default,t.encode=o.default},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r={};t.registerSerializer=function(e,t){r[e]=t},t.getSerializer=function(e){return r[e]}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),function(e){e[e.HANDSHAKE=9]="HANDSHAKE",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",e[e.ROOM_DATA_SCHEMA=16]="ROOM_DATA_SCHEMA"}(t.Protocol||(t.Protocol={})),t.utf8Read=function(e,t){for(var n=e[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[++o])<<6|(63&e[++o])<<0);else r+=String.fromCharCode((31&a)<<6|63&e[++o]);else r+=String.fromCharCode(a)}return r},t.utf8Length=function(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}},function(e,t,n){"use strict";function r(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 i(e,t){e.push(255&t)}function o(e,t){e.push(255&t)}function s(e,t){e.push(255&t),e.push(t>>8&255)}function a(e,t){e.push(255&t),e.push(t>>8&255)}function c(e,t){e.push(255&t),e.push(t>>8&255),e.push(t>>16&255),e.push(t>>24&255)}function u(e,t){var n=t>>24,r=t>>16,i=t>>8,o=t;e.push(255&o),e.push(255&i),e.push(255&r),e.push(255&n)}function h(e,t){var n=Math.floor(t/Math.pow(2,32));u(e,t>>>0),u(e,n)}function f(e,t){var n=t/Math.pow(2,32)>>0;u(e,t>>>0),u(e,n)}Object.defineProperty(t,"__esModule",{value:!0}),t.utf8Write=r,t.int8=i,t.uint8=o,t.int16=s,t.uint16=a,t.int32=c,t.uint32=u,t.int64=h,t.uint64=f,t.float32=function(e,t){v(e,t)},t.float64=function(e,t){y(e,t)};var l=new Int32Array(2),p=new Float32Array(l.buffer),d=new Float64Array(l.buffer);function v(e,t){p[0]=t,c(e,l[0])}function y(e,t){d[0]=t,c(e,l[0]),c(e,l[1])}t.writeFloat32=v,t.writeFloat64=y,t.boolean=function(e,t){return o(e,t?1:0)},t.string=function(e,t){t||(t="");var n=function(e){for(var t=0,n=0,r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}(t),i=0;if(n<32)e.push(160|n),i=1;else if(n<256)e.push(217),o(e,n),i=2;else if(n<65536)e.push(218),a(e,n),i=3;else{if(!(n<4294967296))throw new Error("String too long");e.push(219),u(e,n),i=5}return r(e,e.length,t),i+n},t.number=function e(t,n){return isNaN(n)?e(t,0):isFinite(n)?n!==(0|n)?(t.push(203),y(t,n),9):n>=0?n<128?(o(t,n),1):n<256?(t.push(204),o(t,n),2):n<65536?(t.push(205),a(t,n),3):n<4294967296?(t.push(206),u(t,n),5):(t.push(207),f(t,n),9):n>=-32?(t.push(n),1):n>=-128?(t.push(208),i(t,n),2):n>=-32768?(t.push(209),s(t,n),3):n>=-2147483648?(t.push(210),c(t,n),5):(t.push(211),h(t,n),9):e(t,n>0?Number.MAX_SAFE_INTEGER:-Number.MAX_SAFE_INTEGER)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(10);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){var n=u(e,t);return c(e,t)*Math.pow(2,32)+n}function f(e,t){var n=u(e,t);return u(e,t)*Math.pow(2,32)+n}t.int8=i,t.uint8=o,t.int16=s,t.uint16=a,t.int32=c,t.uint32=u,t.float32=function(e,t){return v(e,t)},t.float64=function(e,t){return y(e,t)},t.int64=h,t.uint64=f;var l=new Int32Array(2),p=new Float32Array(l.buffer),d=new Float64Array(l.buffer);function v(e,t){return l[0]=c(e,t),p[0]}function y(e,t){return l[0]=c(e,t),l[1]=c(e,t),d[0]}t.readFloat32=v,t.readFloat64=y,t.boolean=function(e,t){return o(e,t)>0},t.string=function(e,t){var n,r=e[t.offset++];r<192?n=31&r:217===r?n=o(e,t):218===r?n=a(e,t):219===r&&(n=u(e,t));var i=function(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}(e,t.offset,n);return t.offset+=n,i},t.stringCheck=function(e,t){var n=e[t.offset];return(n<192&&n>160||217===n||218===n||219===n)},t.number=function(e,t){var n=e[t.offset++];return n<128?n:202===n?v(e,t):203===n?y(e,t):204===n?o(e,t):205===n?a(e,t):206===n?u(e,t):207===n?f(e,t):208===n?i(e,t):209===n?s(e,t):210===n?c(e,t):211===n?h(e,t):n>223?-1*(255-n+1):void 0},t.numberCheck=function(e,t){var n=e[t.offset];return n<128||n>=202&&n<=211},t.arrayCheck=function(e,t){return e[t.offset]<160},t.nilCheck=function(e,t){return e[t.offset]===r.NIL},t.indexChangeCheck=function(e,t){return e[t.offset]===r.INDEX_CHANGE}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.END_OF_STRUCTURE=193,t.NIL=192,t.INDEX_CHANGE=212,t.TYPE_ID=213},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){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=(i=s.trys).length>0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0?"?"+r.join("&"):"",h={headers:a},o&&(h.body=o),[4,s[e](""+this.endpoint+t+u,h)];case 1:return[2,i.sent().data]}}))}))},e.prototype.logout=function(){this.token=void 0,a.removeItem("colyseus-auth-token"),this.unregisterPingService()},e.prototype.registerPingService=function(e){var t=this;void 0===e&&(e=15e3),this.unregisterPingService(),this.keepOnlineInterval=setInterval((function(){return t.request("get","/auth")}),e)},e.prototype.unregisterPingService=function(){clearInterval(this.keepOnlineInterval)},e}();t.Auth=c},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2);t.Schema=r.Schema;var i=n(1);t.MapSchema=i.MapSchema;var o=n(0);t.ArraySchema=o.ArraySchema;var s=n(33);t.dumpChanges=s.dumpChanges;var a=n(34);t.Reflection=a.Reflection,t.ReflectionType=a.ReflectionType,t.ReflectionField=a.ReflectionField;var c=n(14);t.type=c.type,t.deprecated=c.deprecated,t.filter=c.filter,t.defineTypes=c.defineTypes,t.Context=c.Context},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2),i=n(0),o=n(1),s=function(){function e(e,t,n){void 0===e&&(e={}),void 0===t&&(t=null),this.changed=!1,this.changes=new Set,this.allChanges=new Set,this.deletedKeys={},this.fieldIndexes=e,this.parent=n,this.parentField=t}return e.prototype.change=function(e,t){void 0===t&&(t=!1);var n=this.fieldIndexes[e],r="number"==typeof n?n:e;t?t&&(this.changed=!0,this.changes.add(r),this.allChanges.delete(r)):(this.changed=!0,this.changes.add(r),this.allChanges.add(r)),this.parent&&this.parent.change(this.parentField)},e.prototype.mapIndex=function(e,t){"object"==typeof e&&(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){"object"==typeof e&&(this.deletedKeys[this.indexMap.get(e)]=!0,this.indexMap.delete(e))},e.prototype.isDeleted=function(e){return void 0!==this.deletedKeys[e]},e.prototype.mapIndexChange=function(e,t){"object"!=typeof e||this.indexChange.has(e)||this.indexChange.set(e,t)},e.prototype.getIndexChange=function(e){return this.indexChange&&this.indexChange.get(e)},e.prototype.deleteIndexChange=function(e){"object"==typeof 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),void 0!==e[n]&&this.change(n)}else for(var s=0,a=Object.keys(e);s0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[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}(this._view,this._offset,e);return this._offset+=e,t},r.prototype._bin=function(e){var t=this._buffer.slice(this._offset,this._offset+e);return this._offset+=e,t},r.prototype._parse=function(){var e,t=this._view.getUint8(this._offset++),n=0,r=0,i=0,o=0;if(t<192)return t<128?t:t<144?this._map(15&t):t<160?this._array(15&t):this._str(31&t);if(t>223)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")},t.default=function(e,t){void 0===t&&(t=0);var n=new r(e,t),i=n._parse();if(n._offset!==e.byteLength)throw new Error(e.byteLength-n._offset+" trailing bytes");return i}},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))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){var t=[],n=[],i=function e(t,n,r){var i=typeof r,o=0,s=0,a=0,c=0,u=0,h=0;if("string"===i){if((u=function(e){for(var t=0,n=0,r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}(r))<32)t.push(160|u),h=1;else if(u<256)t.push(217,u),h=2;else if(u<65536)t.push(218,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("String too long");t.push(219,u>>24,u>>16,u>>8,u),h=5}return n.push({_str:r,_length:u,_offset:t.length}),h+u}if("number"===i)return Math.floor(r)===r&&isFinite(r)?r>=0?r<128?(t.push(r),1):r<256?(t.push(204,r),2):r<65536?(t.push(205,r>>8,r),3):r<4294967296?(t.push(206,r>>24,r>>16,r>>8,r),5):(a=r/Math.pow(2,32)>>0,c=r>>>0,t.push(207,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),9):r>=-32?(t.push(r),1):r>=-128?(t.push(208,r),2):r>=-32768?(t.push(209,r>>8,r),3):r>=-2147483648?(t.push(210,r>>24,r>>16,r>>8,r),5):(a=Math.floor(r/Math.pow(2,32)),c=r>>>0,t.push(211,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),9):(t.push(203),n.push({_float:r,_length:8,_offset:t.length}),9);if("object"===i){if(null===r)return t.push(192),1;if(Array.isArray(r)){if((u=r.length)<16)t.push(144|u),h=1;else if(u<65536)t.push(220,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("Array too large");t.push(221,u>>24,u>>16,u>>8,u),h=5}for(o=0;o>>0,t.push(215,0,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),10}if(r instanceof ArrayBuffer){if((u=r.byteLength)<256)t.push(196,u),h=2;else if(u<65536)t.push(197,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("Buffer too large");t.push(198,u>>24,u>>16,u>>8,u),h=5}return n.push({_bin:r,_length:u,_offset:t.length}),h+u}if("function"==typeof r.toJSON)return e(t,n,r.toJSON());var l=[],p="",d=Object.keys(r);for(o=0,s=d.length;o>8,u),h=3;else{if(!(u<4294967296))throw new Error("Object too large");t.push(223,u>>24,u>>16,u>>8,u),h=5}for(o=0;o0&&(u=n[0]._offset);for(var h,f=0,l=0,p=0,d=t.length;p0){for(var n=0,r=this._enqueuedCalls;n2&&void 0!==arguments[2]?arguments[2]:{};i(this,e),this.url=t,this.protocols=n,this.reconnectEnabled=!0,this.listeners={},this.backoff=o(r.backoff||"exponential",r),this.backoff.onReady=this.onBackoffReady.bind(this),(void 0===r.connect||r.connect)&&this.open()}return r(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";Object.defineProperty(t,"__esModule",{value:!0}),t.createBackoff=function(e,t){return new i(r[e],t)};var r={exponential:function(e,t){return Math.floor(Math.random()*Math.pow(2,e)*t)},fibonacci:function(e,t){if(e>(r=1))for(var n=1,r=2,i=2;i0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[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(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=e.slice();return n.push(t),n}function i(e){if(Array.isArray(e)){for(var t=new Array(e.length),n=0;n=0;h--){var f=c[h],l=t[f];if(!n.hasOwnProperty(f)||void 0===n[f]&&void 0!==l&&!1===Array.isArray(n))o.push({operation:"remove",path:r(s,f)}),u=!0;else{var p=n[f];"object"==typeof l&&null!=l&&"object"==typeof p&&null!=p?e(l,p,o,r(s,f)):l!==p&&o.push({operation:"replace",path:r(s,f),value:p,previousValue:l})}}if(!u&&a.length==c.length)return;for(h=a.length-1;h>=0;h--){f=a[h];if(!t.hasOwnProperty(f)&&void 0!==n[f]){p=n[f];var d=r(s,f);"object"==typeof p&&null!=p&&e({},p,o,d),o.push({operation:"add",path:d,value:p})}}}(e,t,n,[]),n}},function(e,t,n){var r,i;r=this,i=function(){"use strict";var e={};function t(){this.a=0,this.b=0,this.i=0,this.z=new Array(16)}t.prototype.init=function(e,t){var n,r,i=0,o=0;for(n=0;n<16;n++)i=i+(r=e[t+n])&65535,o=o+(16-n)*r&65535,this.z[n]=r;this.a=65535&i,this.b=65535&o,this.i=0},t.prototype.next=function(e){var t=this.z[this.i];this.z[this.i]=e,this.i=this.i+1&15,this.a=this.a-t+e&65535,this.b=this.b-16*t+this.a&65535},t.prototype.value=function(){return(65535&this.a|(65535&this.b)<<16)>>>0};var n="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~".split("").map((function(e){return e.charCodeAt(0)})),r=[-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];function i(e){this.a=e,this.pos=0}function o(){this.a=[]}function s(e){var t,n;for(t=1,n=64;e>=n;t++,n<<=6);return t}function a(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}return i.prototype.haveBytes=function(){return this.posthis.a.length)throw new RangeError("out of bounds");return e},i.prototype.getChar=function(){return String.fromCharCode(this.getByte())},i.prototype.getInt=function(){for(var e,t=0;this.haveBytes()&&(e=r[127&this.getByte()])>=0;)t=(t<<6)+e;return this.pos--,t>>>0},o.prototype.toArray=function(){return this.a},o.prototype.putByte=function(e){this.a.push(255&e)},o.prototype.putChar=function(e){this.putByte(e.charCodeAt(0))},o.prototype.putInt=function(e){var t,r,i=[];if(0!==e){for(t=0;e>0;t++,e>>>=6)i.push(n[63&e]);for(r=t-1;r>=0;r--)this.putByte(i[r])}else this.putChar("0")},o.prototype.putArray=function(e,t,n){for(var r=t;r=0&&O-- >0;){var C,A,S,k,I,M,E;for(k=0,M=y=16*g,E=w+r;M=s(r-I)+s(C)+s(A)+3&&C>_&&(_=C,b=y-I,m=S),g=l[g]}if(_>0){m>0&&(i.putInt(m),i.putChar(":"),i.putArray(n,w,w+m),w+=m),w+=_,i.putInt(_),i.putChar("@"),i.putInt(b),i.putChar(","),b+_-1>h&&(h=b+_-1),_=0;break}if(w+r+16>=c){i.putInt(c-w),i.putChar(":"),i.putArray(n,w,w+c-w),w=c;break}v.next(n[w+r+16]),r++}return wr)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((s+=l)>r)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((!n||!1!==n.verifyChecksum)&&l!==a(d))throw new Error("bad checksum");if(s!==r)throw new Error("generated size does not match predicted size");return d;default:throw new Error("unknown delta operator")}}throw new Error("unterminated delta")},e},e.exports?e.exports=i():r.fossilDelta=i()},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(12),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,t){this.state?(new r.Reflection).decode(e,t):this.state=r.Reflection.decode(e)},e}();t.SchemaSerializer=i},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(12),i=n(1),o=n(0);t.dumpChanges=function e(t){for(var n={},s=t.$changes,a=t._fieldsByIndex||{},c=0,u=Array.from(s.changes);c=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 s=n(14),a=n(2),c=n(0),u=n(1),h=new s.Context,f=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),o([s.type("string",h)],t.prototype,"name",void 0),o([s.type("string",h)],t.prototype,"type",void 0),o([s.type("uint8",h)],t.prototype,"referencedType",void 0),t}(a.Schema);t.ReflectionField=f;var l=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.fields=new c.ArraySchema,t}return i(t,e),o([s.type("uint8",h)],t.prototype,"id",void 0),o([s.type([f],h)],t.prototype,"fields",void 0),t}(a.Schema);t.ReflectionType=l;var p=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.types=new c.ArraySchema,t}return i(t,e),t.encode=function(e){var n=e.constructor,r=new t;r.rootType=n._typeid;var i=function(e,t){for(var n in t){var i=new f;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)},o=n._context.types;for(var s in o){var a=new l;a.id=Number(s),i(a,o[s]._schema)}return r.encodeAll()},t.decode=function(e){var n=new s.Context,r=new t;r.decode(e);var o=r.types.reduce((function(e,t){return e[t.id]=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),t}(a.Schema),e}),{});r.types.forEach((function(e,t){e.fields.forEach((function(t){var r=o[e.id];if(void 0!==t.referencedType){var i=o[t.referencedType];i||(i=t.type.split(":")[1]),0===t.type.indexOf("array")?s.type([i],n)(r.prototype,t.name):0===t.type.indexOf("map")?s.type({map:i},n)(r.prototype,t.name):"ref"===t.type&&s.type(i,n)(r.prototype,t.name)}else s.type(t.type,n)(r.prototype,t.name)}))}));var h=o[r.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 c.ArraySchema:y?new u.MapSchema:d?new p:void 0}}return f},o([s.type([l],h)],t.prototype,"types",void 0),o([s.type("uint8",h)],t.prototype,"rootType",void 0),t}(a.Schema);t.Reflection=p}])})); \ No newline at end of file diff --git a/package.json b/package.json index 2df110a..46bc0eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "colyseus.js", - "version": "0.13.0-alpha.0", + "version": "0.13.0-alpha.3", "description": "Multiplayer Game Client for the Browser", "keywords": [ "colyseus", diff --git a/src/Room.ts b/src/Room.ts index 1c6d1a1..006f9dc 100644 --- a/src/Room.ts +++ b/src/Room.ts @@ -98,7 +98,7 @@ export class Room { public onMessage( type: "*", - callback: (type: string | number | typeof Schema, message: T) => void + callback: (type: string | number | Schema, message: T) => void ) public onMessage any))>( type: T, @@ -228,7 +228,7 @@ export class Room { ? decode.string(bytes, it) : decode.number(bytes, it); - this.dispatchMessage(type, msgpack.decode(bytes.slice(it.offset, bytes.length))); + this.dispatchMessage(type, msgpack.decode(event.data.slice(it.offset, bytes.length))); } } @@ -259,7 +259,7 @@ export class Room { private getMessageHandlerKey(type: string | number | typeof Schema): string { switch (typeof(type)) { // typeof Schema - case "object": return `$${(type as typeof Schema)._typeid}`; + case "function": return `$${(type as typeof Schema)._typeid}`; // string case "string": return type; From 328d8afc5cbe3f39ccff6e4bea997dab88ce331e Mon Sep 17 00:00:00 2001 From: Endel Dreyer Date: Sat, 14 Mar 2020 15:46:01 +0200 Subject: [PATCH 04/11] reuse same buffer to decode with offset. colyseus/colyseus#315 --- package.json | 2 +- src/Room.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 46bc0eb..867113c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "colyseus.js", - "version": "0.13.0-alpha.3", + "version": "0.13.0-alpha.4", "description": "Multiplayer Game Client for the Browser", "keywords": [ "colyseus", diff --git a/src/Room.ts b/src/Room.ts index 006f9dc..8cbb888 100644 --- a/src/Room.ts +++ b/src/Room.ts @@ -228,7 +228,7 @@ export class Room { ? decode.string(bytes, it) : decode.number(bytes, it); - this.dispatchMessage(type, msgpack.decode(event.data.slice(it.offset, bytes.length))); + this.dispatchMessage(type, msgpack.decode(event.data, it.offset)); } } From 3580503281f6f4714d2dfa2cbdd91adfced5d015 Mon Sep 17 00:00:00 2001 From: Endel Dreyer Date: Sat, 14 Mar 2020 17:40:13 +0200 Subject: [PATCH 05/11] update repository link --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 867113c..e3ee042 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ ], "repository": { "type": "git", - "url": "git://github.com/gamestdio/colyseus.js.git" + "url": "git://github.com/colyseus/colyseus.js.git" }, "main": "lib/index.js", "typings": "lib/index.d.ts", From 34f252d053a1f46b5347718a7a728be5ef69b490 Mon Sep 17 00:00:00 2001 From: Endel Dreyer Date: Sun, 29 Mar 2020 20:10:00 +0300 Subject: [PATCH 06/11] allow send/receive messages by type without payload. colyseus/colyseus#315 --- dist/colyseus.js | 4 ++-- package.json | 2 +- src/Room.ts | 22 +++++++++++++++++----- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/dist/colyseus.js b/dist/colyseus.js index e545697..962f8c0 100644 --- a/dist/colyseus.js +++ b/dist/colyseus.js @@ -1,2 +1,2 @@ -/*! colyseus.js@0.13.0-alpha.3 */ -!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()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=15)}([function(e,t,n){"use strict";var r,i=this&&this.__extends||(r=function(e,t){return(r=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])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),o=this&&this.__spreadArrays||function(){for(var e=0,t=0,n=arguments.length;t=e+t-1}));return i.map((function(e){var t=e&&e.$changes;t&&(t.parent.deleteIndex(e),delete t.parent)})),o.forEach((function(e){var t=e&&e.$changes;t&&t.parentField--})),i},t}(Array);t.ArraySchema=s},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function e(t){var n=this;for(var r in void 0===t&&(t={}),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(t){var r;if(t)(r=Object.assign(new e,n)).onAdd=n.onAdd,r.onRemove=n.onRemove,r.onChange=n.onChange;else{var i=new e;for(var o in n)"object"==typeof n[o]?i[o]=n[o].clone():i[o]=n[o]}return r}},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(e){for(var t=0,r=new Map,i=0,o=e;i0;var C=!1;g.length>w&&Array.prototype.splice.call(g,w).forEach((function(t,n){if(t&&t.onRemove)try{t.onRemove()}catch(t){e.onError(t)}if(m.onRemove)try{m.onRemove(t,w+n)}catch(t){e.onError(t)}}));for(var A=0;A0;C=!1;var x=Object.keys(E);for(A=0;A0)try{this.onChange(r)}catch(t){e.onError(t)}return this},e.prototype.encode=function(e,t,n,r){var i=this;if(void 0===e&&(e=this),void 0===t&&(t=!1),void 0===r&&(r=[]),!this.$changes.changed&&!t)return this._encodeEndOfStructure(this,e,r),r;for(var a=this._schema,h=this._indexes,f=this._fieldsByIndex,d=this._filters,v=Array.from(t||n?this.$changes.allChanges:this.$changes.changes).sort(),y=function(y,_){var b=f[v[y]]||v[y],m="_"+b,w=a[b],O=d&&d[b],C=g[m],A=h[b];if(void 0===C)s.uint8(r,o.NIL),s.number(r,A);else if(w._schema){if(n&&O&&!O.call(g,n,C,e))return"continue";C?(s.number(r,A),l(C,w,g,b),g.tryEncodeTypeId(r,w,C.constructor),C.encode(e,t,n,r)):(s.uint8(r,o.NIL),s.number(r,A))}else if(Array.isArray(w)){var S=C.$changes;s.number(r,A),s.number(r,C.length);var k=Array.from(t||n?S.allChanges:S.changes).filter((function(e){return void 0!==i[m][e]})).sort((function(e,t){return e-t})),I=k.length;s.number(r,I);var M="string"!=typeof w[0];l(g[m],c.ArraySchema,g,b);for(var E=0;E=400?o:i)(h)},(a=n.body)&&/Array|Object/.test(a.constructor)&&(f["content-type"]="application/json",a=JSON.stringify(a)),f)h.setRequestHeader(s,f[s]);h.send(a)}))}n.r(t),n.d(t,"send",(function(){return 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(5)),o=n(20),s=n(21),a=n(6),c=n(7),u=r(n(8)),h=r(n(9)),f=function(){function e(e,t){var n=this;this.onJoin=o.createSignal(),this.onStateChange=o.createSignal(),this.onError=o.createSignal(),this.onLeave=o.createSignal(),this.hasJoined=!1,this.onMessageHandlers={},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){if(!t.hasJoined)return console.error("Room connection was closed unexpectedly ("+e.code+"): "+e.reason),void t.onError.invoke(e.reason);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.onMessage=function(e,t){return this.onMessageHandlers[this.getMessageHandlerKey(e)]=t,this},e.prototype.send=function(e,t){var n=i.encode(t),r=[c.Protocol.ROOM_DATA];"string"==typeof e?u.string(r,e):u.number(r,e);var o=new Uint8Array(r.length+n.byteLength);o.set(new Uint8Array(r),0),o.set(new Uint8Array(n),r.length),this.connection.send(o.buffer)},Object.defineProperty(e.prototype,"state",{get:function(){return this.serializer.getState()},enumerable:!0,configurable:!0}),e.prototype.listen=function(e,t,n){if("schema"!==this.serializerId)return this.serializerId||console.warn("room.Listen() should be called after room.onJoin has been called (DEPRECATION WARNING)"),this.serializer.api.listen(e,t,n);console.error("'"+this.serializerId+"' serializer doesn't support .listen() method here.")},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.onError.clear(),this.onLeave.clear()},e.prototype.onMessageCallback=function(e){var t=Array.from(new Uint8Array(e.data)),n=t[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);"fossil-delta"===this.serializerId||this.rootSchema||(this.serializer=new o),t.length>r&&this.serializer.handshake&&this.serializer.handshake(t,{offset:1}),this.hasJoined=!0,this.onJoin.invoke(),this.connection.send([c.Protocol.JOIN_ROOM])}else if(n===c.Protocol.JOIN_ERROR)this.onError.invoke(c.utf8Read(t,1));else if(n===c.Protocol.LEAVE_ROOM)this.leave();else if(n===c.Protocol.ROOM_DATA_SCHEMA){var s=new(f=this.serializer.getState().constructor._context.get(t[1]));s.decode(t,{offset:2}),this.dispatchMessage(f,s)}else if(n===c.Protocol.ROOM_STATE)t.shift(),this.setState(t);else if(n===c.Protocol.ROOM_STATE_PATCH)t.shift(),this.patch(t);else if(n===c.Protocol.ROOM_DATA){var u={offset:1},f=h.stringCheck(t,u)?h.string(t,u):h.number(t,u);this.dispatchMessage(f,i.decode(e.data.slice(u.offset,t.length)))}},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.prototype.dispatchMessage=function(e,t){var n=this.getMessageHandlerKey(e);this.onMessageHandlers[n]?this.onMessageHandlers[n](t):this.onMessageHandlers["*"]?this.onMessageHandlers[n](e,t):console.warn("onMessage not registered for type '"+e+"'.")},e.prototype.getMessageHandlerKey=function(e){switch(typeof e){case"function":return"$"+e._typeid;case"string":return e;case"number":return"i"+e;default:throw new Error("invalid message type.")}},e}();t.Room=f},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(18)),o=r(n(19));t.decode=i.default,t.encode=o.default},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r={};t.registerSerializer=function(e,t){r[e]=t},t.getSerializer=function(e){return r[e]}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),function(e){e[e.HANDSHAKE=9]="HANDSHAKE",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",e[e.ROOM_DATA_SCHEMA=16]="ROOM_DATA_SCHEMA"}(t.Protocol||(t.Protocol={})),t.utf8Read=function(e,t){for(var n=e[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[++o])<<6|(63&e[++o])<<0);else r+=String.fromCharCode((31&a)<<6|63&e[++o]);else r+=String.fromCharCode(a)}return r},t.utf8Length=function(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}},function(e,t,n){"use strict";function r(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 i(e,t){e.push(255&t)}function o(e,t){e.push(255&t)}function s(e,t){e.push(255&t),e.push(t>>8&255)}function a(e,t){e.push(255&t),e.push(t>>8&255)}function c(e,t){e.push(255&t),e.push(t>>8&255),e.push(t>>16&255),e.push(t>>24&255)}function u(e,t){var n=t>>24,r=t>>16,i=t>>8,o=t;e.push(255&o),e.push(255&i),e.push(255&r),e.push(255&n)}function h(e,t){var n=Math.floor(t/Math.pow(2,32));u(e,t>>>0),u(e,n)}function f(e,t){var n=t/Math.pow(2,32)>>0;u(e,t>>>0),u(e,n)}Object.defineProperty(t,"__esModule",{value:!0}),t.utf8Write=r,t.int8=i,t.uint8=o,t.int16=s,t.uint16=a,t.int32=c,t.uint32=u,t.int64=h,t.uint64=f,t.float32=function(e,t){v(e,t)},t.float64=function(e,t){y(e,t)};var l=new Int32Array(2),p=new Float32Array(l.buffer),d=new Float64Array(l.buffer);function v(e,t){p[0]=t,c(e,l[0])}function y(e,t){d[0]=t,c(e,l[0]),c(e,l[1])}t.writeFloat32=v,t.writeFloat64=y,t.boolean=function(e,t){return o(e,t?1:0)},t.string=function(e,t){t||(t="");var n=function(e){for(var t=0,n=0,r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}(t),i=0;if(n<32)e.push(160|n),i=1;else if(n<256)e.push(217),o(e,n),i=2;else if(n<65536)e.push(218),a(e,n),i=3;else{if(!(n<4294967296))throw new Error("String too long");e.push(219),u(e,n),i=5}return r(e,e.length,t),i+n},t.number=function e(t,n){return isNaN(n)?e(t,0):isFinite(n)?n!==(0|n)?(t.push(203),y(t,n),9):n>=0?n<128?(o(t,n),1):n<256?(t.push(204),o(t,n),2):n<65536?(t.push(205),a(t,n),3):n<4294967296?(t.push(206),u(t,n),5):(t.push(207),f(t,n),9):n>=-32?(t.push(n),1):n>=-128?(t.push(208),i(t,n),2):n>=-32768?(t.push(209),s(t,n),3):n>=-2147483648?(t.push(210),c(t,n),5):(t.push(211),h(t,n),9):e(t,n>0?Number.MAX_SAFE_INTEGER:-Number.MAX_SAFE_INTEGER)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(10);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){var n=u(e,t);return c(e,t)*Math.pow(2,32)+n}function f(e,t){var n=u(e,t);return u(e,t)*Math.pow(2,32)+n}t.int8=i,t.uint8=o,t.int16=s,t.uint16=a,t.int32=c,t.uint32=u,t.float32=function(e,t){return v(e,t)},t.float64=function(e,t){return y(e,t)},t.int64=h,t.uint64=f;var l=new Int32Array(2),p=new Float32Array(l.buffer),d=new Float64Array(l.buffer);function v(e,t){return l[0]=c(e,t),p[0]}function y(e,t){return l[0]=c(e,t),l[1]=c(e,t),d[0]}t.readFloat32=v,t.readFloat64=y,t.boolean=function(e,t){return o(e,t)>0},t.string=function(e,t){var n,r=e[t.offset++];r<192?n=31&r:217===r?n=o(e,t):218===r?n=a(e,t):219===r&&(n=u(e,t));var i=function(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}(e,t.offset,n);return t.offset+=n,i},t.stringCheck=function(e,t){var n=e[t.offset];return(n<192&&n>160||217===n||218===n||219===n)},t.number=function(e,t){var n=e[t.offset++];return n<128?n:202===n?v(e,t):203===n?y(e,t):204===n?o(e,t):205===n?a(e,t):206===n?u(e,t):207===n?f(e,t):208===n?i(e,t):209===n?s(e,t):210===n?c(e,t):211===n?h(e,t):n>223?-1*(255-n+1):void 0},t.numberCheck=function(e,t){var n=e[t.offset];return n<128||n>=202&&n<=211},t.arrayCheck=function(e,t){return e[t.offset]<160},t.nilCheck=function(e,t){return e[t.offset]===r.NIL},t.indexChangeCheck=function(e,t){return e[t.offset]===r.INDEX_CHANGE}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.END_OF_STRUCTURE=193,t.NIL=192,t.INDEX_CHANGE=212,t.TYPE_ID=213},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){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=(i=s.trys).length>0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0?"?"+r.join("&"):"",h={headers:a},o&&(h.body=o),[4,s[e](""+this.endpoint+t+u,h)];case 1:return[2,i.sent().data]}}))}))},e.prototype.logout=function(){this.token=void 0,a.removeItem("colyseus-auth-token"),this.unregisterPingService()},e.prototype.registerPingService=function(e){var t=this;void 0===e&&(e=15e3),this.unregisterPingService(),this.keepOnlineInterval=setInterval((function(){return t.request("get","/auth")}),e)},e.prototype.unregisterPingService=function(){clearInterval(this.keepOnlineInterval)},e}();t.Auth=c},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2);t.Schema=r.Schema;var i=n(1);t.MapSchema=i.MapSchema;var o=n(0);t.ArraySchema=o.ArraySchema;var s=n(33);t.dumpChanges=s.dumpChanges;var a=n(34);t.Reflection=a.Reflection,t.ReflectionType=a.ReflectionType,t.ReflectionField=a.ReflectionField;var c=n(14);t.type=c.type,t.deprecated=c.deprecated,t.filter=c.filter,t.defineTypes=c.defineTypes,t.Context=c.Context},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2),i=n(0),o=n(1),s=function(){function e(e,t,n){void 0===e&&(e={}),void 0===t&&(t=null),this.changed=!1,this.changes=new Set,this.allChanges=new Set,this.deletedKeys={},this.fieldIndexes=e,this.parent=n,this.parentField=t}return e.prototype.change=function(e,t){void 0===t&&(t=!1);var n=this.fieldIndexes[e],r="number"==typeof n?n:e;t?t&&(this.changed=!0,this.changes.add(r),this.allChanges.delete(r)):(this.changed=!0,this.changes.add(r),this.allChanges.add(r)),this.parent&&this.parent.change(this.parentField)},e.prototype.mapIndex=function(e,t){"object"==typeof e&&(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){"object"==typeof e&&(this.deletedKeys[this.indexMap.get(e)]=!0,this.indexMap.delete(e))},e.prototype.isDeleted=function(e){return void 0!==this.deletedKeys[e]},e.prototype.mapIndexChange=function(e,t){"object"!=typeof e||this.indexChange.has(e)||this.indexChange.set(e,t)},e.prototype.getIndexChange=function(e){return this.indexChange&&this.indexChange.get(e)},e.prototype.deleteIndexChange=function(e){"object"==typeof 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),void 0!==e[n]&&this.change(n)}else for(var s=0,a=Object.keys(e);s0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[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}(this._view,this._offset,e);return this._offset+=e,t},r.prototype._bin=function(e){var t=this._buffer.slice(this._offset,this._offset+e);return this._offset+=e,t},r.prototype._parse=function(){var e,t=this._view.getUint8(this._offset++),n=0,r=0,i=0,o=0;if(t<192)return t<128?t:t<144?this._map(15&t):t<160?this._array(15&t):this._str(31&t);if(t>223)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")},t.default=function(e,t){void 0===t&&(t=0);var n=new r(e,t),i=n._parse();if(n._offset!==e.byteLength)throw new Error(e.byteLength-n._offset+" trailing bytes");return i}},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))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){var t=[],n=[],i=function e(t,n,r){var i=typeof r,o=0,s=0,a=0,c=0,u=0,h=0;if("string"===i){if((u=function(e){for(var t=0,n=0,r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}(r))<32)t.push(160|u),h=1;else if(u<256)t.push(217,u),h=2;else if(u<65536)t.push(218,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("String too long");t.push(219,u>>24,u>>16,u>>8,u),h=5}return n.push({_str:r,_length:u,_offset:t.length}),h+u}if("number"===i)return Math.floor(r)===r&&isFinite(r)?r>=0?r<128?(t.push(r),1):r<256?(t.push(204,r),2):r<65536?(t.push(205,r>>8,r),3):r<4294967296?(t.push(206,r>>24,r>>16,r>>8,r),5):(a=r/Math.pow(2,32)>>0,c=r>>>0,t.push(207,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),9):r>=-32?(t.push(r),1):r>=-128?(t.push(208,r),2):r>=-32768?(t.push(209,r>>8,r),3):r>=-2147483648?(t.push(210,r>>24,r>>16,r>>8,r),5):(a=Math.floor(r/Math.pow(2,32)),c=r>>>0,t.push(211,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),9):(t.push(203),n.push({_float:r,_length:8,_offset:t.length}),9);if("object"===i){if(null===r)return t.push(192),1;if(Array.isArray(r)){if((u=r.length)<16)t.push(144|u),h=1;else if(u<65536)t.push(220,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("Array too large");t.push(221,u>>24,u>>16,u>>8,u),h=5}for(o=0;o>>0,t.push(215,0,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),10}if(r instanceof ArrayBuffer){if((u=r.byteLength)<256)t.push(196,u),h=2;else if(u<65536)t.push(197,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("Buffer too large");t.push(198,u>>24,u>>16,u>>8,u),h=5}return n.push({_bin:r,_length:u,_offset:t.length}),h+u}if("function"==typeof r.toJSON)return e(t,n,r.toJSON());var l=[],p="",d=Object.keys(r);for(o=0,s=d.length;o>8,u),h=3;else{if(!(u<4294967296))throw new Error("Object too large");t.push(223,u>>24,u>>16,u>>8,u),h=5}for(o=0;o0&&(u=n[0]._offset);for(var h,f=0,l=0,p=0,d=t.length;p0){for(var n=0,r=this._enqueuedCalls;n2&&void 0!==arguments[2]?arguments[2]:{};i(this,e),this.url=t,this.protocols=n,this.reconnectEnabled=!0,this.listeners={},this.backoff=o(r.backoff||"exponential",r),this.backoff.onReady=this.onBackoffReady.bind(this),(void 0===r.connect||r.connect)&&this.open()}return r(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";Object.defineProperty(t,"__esModule",{value:!0}),t.createBackoff=function(e,t){return new i(r[e],t)};var r={exponential:function(e,t){return Math.floor(Math.random()*Math.pow(2,e)*t)},fibonacci:function(e,t){if(e>(r=1))for(var n=1,r=2,i=2;i0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[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(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=e.slice();return n.push(t),n}function i(e){if(Array.isArray(e)){for(var t=new Array(e.length),n=0;n=0;h--){var f=c[h],l=t[f];if(!n.hasOwnProperty(f)||void 0===n[f]&&void 0!==l&&!1===Array.isArray(n))o.push({operation:"remove",path:r(s,f)}),u=!0;else{var p=n[f];"object"==typeof l&&null!=l&&"object"==typeof p&&null!=p?e(l,p,o,r(s,f)):l!==p&&o.push({operation:"replace",path:r(s,f),value:p,previousValue:l})}}if(!u&&a.length==c.length)return;for(h=a.length-1;h>=0;h--){f=a[h];if(!t.hasOwnProperty(f)&&void 0!==n[f]){p=n[f];var d=r(s,f);"object"==typeof p&&null!=p&&e({},p,o,d),o.push({operation:"add",path:d,value:p})}}}(e,t,n,[]),n}},function(e,t,n){var r,i;r=this,i=function(){"use strict";var e={};function t(){this.a=0,this.b=0,this.i=0,this.z=new Array(16)}t.prototype.init=function(e,t){var n,r,i=0,o=0;for(n=0;n<16;n++)i=i+(r=e[t+n])&65535,o=o+(16-n)*r&65535,this.z[n]=r;this.a=65535&i,this.b=65535&o,this.i=0},t.prototype.next=function(e){var t=this.z[this.i];this.z[this.i]=e,this.i=this.i+1&15,this.a=this.a-t+e&65535,this.b=this.b-16*t+this.a&65535},t.prototype.value=function(){return(65535&this.a|(65535&this.b)<<16)>>>0};var n="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~".split("").map((function(e){return e.charCodeAt(0)})),r=[-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];function i(e){this.a=e,this.pos=0}function o(){this.a=[]}function s(e){var t,n;for(t=1,n=64;e>=n;t++,n<<=6);return t}function a(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}return i.prototype.haveBytes=function(){return this.posthis.a.length)throw new RangeError("out of bounds");return e},i.prototype.getChar=function(){return String.fromCharCode(this.getByte())},i.prototype.getInt=function(){for(var e,t=0;this.haveBytes()&&(e=r[127&this.getByte()])>=0;)t=(t<<6)+e;return this.pos--,t>>>0},o.prototype.toArray=function(){return this.a},o.prototype.putByte=function(e){this.a.push(255&e)},o.prototype.putChar=function(e){this.putByte(e.charCodeAt(0))},o.prototype.putInt=function(e){var t,r,i=[];if(0!==e){for(t=0;e>0;t++,e>>>=6)i.push(n[63&e]);for(r=t-1;r>=0;r--)this.putByte(i[r])}else this.putChar("0")},o.prototype.putArray=function(e,t,n){for(var r=t;r=0&&O-- >0;){var C,A,S,k,I,M,E;for(k=0,M=y=16*g,E=w+r;M=s(r-I)+s(C)+s(A)+3&&C>_&&(_=C,b=y-I,m=S),g=l[g]}if(_>0){m>0&&(i.putInt(m),i.putChar(":"),i.putArray(n,w,w+m),w+=m),w+=_,i.putInt(_),i.putChar("@"),i.putInt(b),i.putChar(","),b+_-1>h&&(h=b+_-1),_=0;break}if(w+r+16>=c){i.putInt(c-w),i.putChar(":"),i.putArray(n,w,w+c-w),w=c;break}v.next(n[w+r+16]),r++}return wr)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((s+=l)>r)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((!n||!1!==n.verifyChecksum)&&l!==a(d))throw new Error("bad checksum");if(s!==r)throw new Error("generated size does not match predicted size");return d;default:throw new Error("unknown delta operator")}}throw new Error("unterminated delta")},e},e.exports?e.exports=i():r.fossilDelta=i()},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(12),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,t){this.state?(new r.Reflection).decode(e,t):this.state=r.Reflection.decode(e)},e}();t.SchemaSerializer=i},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(12),i=n(1),o=n(0);t.dumpChanges=function e(t){for(var n={},s=t.$changes,a=t._fieldsByIndex||{},c=0,u=Array.from(s.changes);c=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 s=n(14),a=n(2),c=n(0),u=n(1),h=new s.Context,f=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),o([s.type("string",h)],t.prototype,"name",void 0),o([s.type("string",h)],t.prototype,"type",void 0),o([s.type("uint8",h)],t.prototype,"referencedType",void 0),t}(a.Schema);t.ReflectionField=f;var l=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.fields=new c.ArraySchema,t}return i(t,e),o([s.type("uint8",h)],t.prototype,"id",void 0),o([s.type([f],h)],t.prototype,"fields",void 0),t}(a.Schema);t.ReflectionType=l;var p=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.types=new c.ArraySchema,t}return i(t,e),t.encode=function(e){var n=e.constructor,r=new t;r.rootType=n._typeid;var i=function(e,t){for(var n in t){var i=new f;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)},o=n._context.types;for(var s in o){var a=new l;a.id=Number(s),i(a,o[s]._schema)}return r.encodeAll()},t.decode=function(e){var n=new s.Context,r=new t;r.decode(e);var o=r.types.reduce((function(e,t){return e[t.id]=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),t}(a.Schema),e}),{});r.types.forEach((function(e,t){e.fields.forEach((function(t){var r=o[e.id];if(void 0!==t.referencedType){var i=o[t.referencedType];i||(i=t.type.split(":")[1]),0===t.type.indexOf("array")?s.type([i],n)(r.prototype,t.name):0===t.type.indexOf("map")?s.type({map:i},n)(r.prototype,t.name):"ref"===t.type&&s.type(i,n)(r.prototype,t.name)}else s.type(t.type,n)(r.prototype,t.name)}))}));var h=o[r.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 c.ArraySchema:y?new u.MapSchema:d?new p:void 0}}return f},o([s.type([l],h)],t.prototype,"types",void 0),o([s.type("uint8",h)],t.prototype,"rootType",void 0),t}(a.Schema);t.Reflection=p}])})); \ No newline at end of file +/*! colyseus.js@0.13.0-alpha.6 */ +!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()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=15)}([function(e,t,n){"use strict";var r,i=this&&this.__extends||(r=function(e,t){return(r=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])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),o=this&&this.__spreadArrays||function(){for(var e=0,t=0,n=arguments.length;t=e+t-1}));return i.map((function(e){var t=e&&e.$changes;t&&(t.parent.deleteIndex(e),delete t.parent)})),o.forEach((function(e){var t=e&&e.$changes;t&&t.parentField--})),i},t}(Array);t.ArraySchema=s},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function e(t){var n=this;for(var r in void 0===t&&(t={}),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(t){var r;if(t)(r=Object.assign(new e,n)).onAdd=n.onAdd,r.onRemove=n.onRemove,r.onChange=n.onChange;else{var i=new e;for(var o in n)"object"==typeof n[o]?i[o]=n[o].clone():i[o]=n[o]}return r}},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(e){for(var t=0,r=new Map,i=0,o=e;i0;var C=!1;g.length>w&&Array.prototype.splice.call(g,w).forEach((function(t,n){if(t&&t.onRemove)try{t.onRemove()}catch(t){e.onError(t)}if(m.onRemove)try{m.onRemove(t,w+n)}catch(t){e.onError(t)}}));for(var A=0;A0;C=!1;var x=Object.keys(E);for(A=0;A0)try{this.onChange(r)}catch(t){e.onError(t)}return this},e.prototype.encode=function(e,t,n,r){var i=this;if(void 0===e&&(e=this),void 0===t&&(t=!1),void 0===r&&(r=[]),!this.$changes.changed&&!t)return this._encodeEndOfStructure(this,e,r),r;for(var a=this._schema,h=this._indexes,f=this._fieldsByIndex,d=this._filters,v=Array.from(t||n?this.$changes.allChanges:this.$changes.changes).sort(),y=function(y,_){var b=f[v[y]]||v[y],m="_"+b,w=a[b],O=d&&d[b],C=g[m],A=h[b];if(void 0===C)s.uint8(r,o.NIL),s.number(r,A);else if(w._schema){if(n&&O&&!O.call(g,n,C,e))return"continue";C?(s.number(r,A),l(C,w,g,b),g.tryEncodeTypeId(r,w,C.constructor),C.encode(e,t,n,r)):(s.uint8(r,o.NIL),s.number(r,A))}else if(Array.isArray(w)){var S=C.$changes;s.number(r,A),s.number(r,C.length);var k=Array.from(t||n?S.allChanges:S.changes).filter((function(e){return void 0!==i[m][e]})).sort((function(e,t){return e-t})),I=k.length;s.number(r,I);var M="string"!=typeof w[0];l(g[m],c.ArraySchema,g,b);for(var E=0;E=400?o:i)(h)},(a=n.body)&&/Array|Object/.test(a.constructor)&&(f["content-type"]="application/json",a=JSON.stringify(a)),f)h.setRequestHeader(s,f[s]);h.send(a)}))}n.r(t),n.d(t,"send",(function(){return 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(5)),o=n(20),s=n(21),a=n(6),c=n(7),u=r(n(8)),h=r(n(9)),f=function(){function e(e,t){var n=this;this.onJoin=o.createSignal(),this.onStateChange=o.createSignal(),this.onError=o.createSignal(),this.onLeave=o.createSignal(),this.hasJoined=!1,this.onMessageHandlers={},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){if(!t.hasJoined)return console.error("Room connection was closed unexpectedly ("+e.code+"): "+e.reason),void t.onError.invoke(e.reason);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.onMessage=function(e,t){return this.onMessageHandlers[this.getMessageHandlerKey(e)]=t,this},e.prototype.send=function(e,t){var n,r=[c.Protocol.ROOM_DATA];if("string"==typeof e?u.string(r,e):u.number(r,e),void 0!==t){var o=i.encode(t);(n=new Uint8Array(r.length+o.byteLength)).set(new Uint8Array(r),0),n.set(new Uint8Array(o),r.length)}else n=new Uint8Array(r);this.connection.send(n.buffer)},Object.defineProperty(e.prototype,"state",{get:function(){return this.serializer.getState()},enumerable:!0,configurable:!0}),e.prototype.listen=function(e,t,n){if("schema"!==this.serializerId)return this.serializerId||console.warn("room.Listen() should be called after room.onJoin has been called (DEPRECATION WARNING)"),this.serializer.api.listen(e,t,n);console.error("'"+this.serializerId+"' serializer doesn't support .listen() method here.")},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.onError.clear(),this.onLeave.clear()},e.prototype.onMessageCallback=function(e){var t=Array.from(new Uint8Array(e.data)),n=t[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);"fossil-delta"===this.serializerId||this.rootSchema||(this.serializer=new o),t.length>r&&this.serializer.handshake&&this.serializer.handshake(t,{offset:1}),this.hasJoined=!0,this.onJoin.invoke(),this.connection.send([c.Protocol.JOIN_ROOM])}else if(n===c.Protocol.JOIN_ERROR)this.onError.invoke(c.utf8Read(t,1));else if(n===c.Protocol.LEAVE_ROOM)this.leave();else if(n===c.Protocol.ROOM_DATA_SCHEMA){(f=new(u=this.serializer.getState().constructor._context.get(t[1]))).decode(t,{offset:2}),this.dispatchMessage(u,f)}else if(n===c.Protocol.ROOM_STATE)t.shift(),this.setState(t);else if(n===c.Protocol.ROOM_STATE_PATCH)t.shift(),this.patch(t);else if(n===c.Protocol.ROOM_DATA){var s={offset:1},u=h.stringCheck(t,s)?h.string(t,s):h.number(t,s),f=t.length>s.offset?i.decode(e.data,s.offset):void 0;this.dispatchMessage(u,f)}},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.prototype.dispatchMessage=function(e,t){var n=this.getMessageHandlerKey(e);this.onMessageHandlers[n]?this.onMessageHandlers[n](t):this.onMessageHandlers["*"]?this.onMessageHandlers[n](e,t):console.warn("onMessage not registered for type '"+e+"'.")},e.prototype.getMessageHandlerKey=function(e){switch(typeof e){case"function":return"$"+e._typeid;case"string":return e;case"number":return"i"+e;default:throw new Error("invalid message type.")}},e}();t.Room=f},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(18)),o=r(n(19));t.decode=i.default,t.encode=o.default},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r={};t.registerSerializer=function(e,t){r[e]=t},t.getSerializer=function(e){return r[e]}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),function(e){e[e.HANDSHAKE=9]="HANDSHAKE",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",e[e.ROOM_DATA_SCHEMA=16]="ROOM_DATA_SCHEMA"}(t.Protocol||(t.Protocol={})),t.utf8Read=function(e,t){for(var n=e[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[++o])<<6|(63&e[++o])<<0);else r+=String.fromCharCode((31&a)<<6|63&e[++o]);else r+=String.fromCharCode(a)}return r},t.utf8Length=function(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}},function(e,t,n){"use strict";function r(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 i(e,t){e.push(255&t)}function o(e,t){e.push(255&t)}function s(e,t){e.push(255&t),e.push(t>>8&255)}function a(e,t){e.push(255&t),e.push(t>>8&255)}function c(e,t){e.push(255&t),e.push(t>>8&255),e.push(t>>16&255),e.push(t>>24&255)}function u(e,t){var n=t>>24,r=t>>16,i=t>>8,o=t;e.push(255&o),e.push(255&i),e.push(255&r),e.push(255&n)}function h(e,t){var n=Math.floor(t/Math.pow(2,32));u(e,t>>>0),u(e,n)}function f(e,t){var n=t/Math.pow(2,32)>>0;u(e,t>>>0),u(e,n)}Object.defineProperty(t,"__esModule",{value:!0}),t.utf8Write=r,t.int8=i,t.uint8=o,t.int16=s,t.uint16=a,t.int32=c,t.uint32=u,t.int64=h,t.uint64=f,t.float32=function(e,t){v(e,t)},t.float64=function(e,t){y(e,t)};var l=new Int32Array(2),p=new Float32Array(l.buffer),d=new Float64Array(l.buffer);function v(e,t){p[0]=t,c(e,l[0])}function y(e,t){d[0]=t,c(e,l[0]),c(e,l[1])}t.writeFloat32=v,t.writeFloat64=y,t.boolean=function(e,t){return o(e,t?1:0)},t.string=function(e,t){t||(t="");var n=function(e){for(var t=0,n=0,r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}(t),i=0;if(n<32)e.push(160|n),i=1;else if(n<256)e.push(217),o(e,n),i=2;else if(n<65536)e.push(218),a(e,n),i=3;else{if(!(n<4294967296))throw new Error("String too long");e.push(219),u(e,n),i=5}return r(e,e.length,t),i+n},t.number=function e(t,n){return isNaN(n)?e(t,0):isFinite(n)?n!==(0|n)?(t.push(203),y(t,n),9):n>=0?n<128?(o(t,n),1):n<256?(t.push(204),o(t,n),2):n<65536?(t.push(205),a(t,n),3):n<4294967296?(t.push(206),u(t,n),5):(t.push(207),f(t,n),9):n>=-32?(t.push(n),1):n>=-128?(t.push(208),i(t,n),2):n>=-32768?(t.push(209),s(t,n),3):n>=-2147483648?(t.push(210),c(t,n),5):(t.push(211),h(t,n),9):e(t,n>0?Number.MAX_SAFE_INTEGER:-Number.MAX_SAFE_INTEGER)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(10);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){var n=u(e,t);return c(e,t)*Math.pow(2,32)+n}function f(e,t){var n=u(e,t);return u(e,t)*Math.pow(2,32)+n}t.int8=i,t.uint8=o,t.int16=s,t.uint16=a,t.int32=c,t.uint32=u,t.float32=function(e,t){return v(e,t)},t.float64=function(e,t){return y(e,t)},t.int64=h,t.uint64=f;var l=new Int32Array(2),p=new Float32Array(l.buffer),d=new Float64Array(l.buffer);function v(e,t){return l[0]=c(e,t),p[0]}function y(e,t){return l[0]=c(e,t),l[1]=c(e,t),d[0]}t.readFloat32=v,t.readFloat64=y,t.boolean=function(e,t){return o(e,t)>0},t.string=function(e,t){var n,r=e[t.offset++];r<192?n=31&r:217===r?n=o(e,t):218===r?n=a(e,t):219===r&&(n=u(e,t));var i=function(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}(e,t.offset,n);return t.offset+=n,i},t.stringCheck=function(e,t){var n=e[t.offset];return(n<192&&n>160||217===n||218===n||219===n)},t.number=function(e,t){var n=e[t.offset++];return n<128?n:202===n?v(e,t):203===n?y(e,t):204===n?o(e,t):205===n?a(e,t):206===n?u(e,t):207===n?f(e,t):208===n?i(e,t):209===n?s(e,t):210===n?c(e,t):211===n?h(e,t):n>223?-1*(255-n+1):void 0},t.numberCheck=function(e,t){var n=e[t.offset];return n<128||n>=202&&n<=211},t.arrayCheck=function(e,t){return e[t.offset]<160},t.nilCheck=function(e,t){return e[t.offset]===r.NIL},t.indexChangeCheck=function(e,t){return e[t.offset]===r.INDEX_CHANGE}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.END_OF_STRUCTURE=193,t.NIL=192,t.INDEX_CHANGE=212,t.TYPE_ID=213},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){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=(i=s.trys).length>0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0?"?"+r.join("&"):"",h={headers:a},o&&(h.body=o),[4,s[e](""+this.endpoint+t+u,h)];case 1:return[2,i.sent().data]}}))}))},e.prototype.logout=function(){this.token=void 0,a.removeItem("colyseus-auth-token"),this.unregisterPingService()},e.prototype.registerPingService=function(e){var t=this;void 0===e&&(e=15e3),this.unregisterPingService(),this.keepOnlineInterval=setInterval((function(){return t.request("get","/auth")}),e)},e.prototype.unregisterPingService=function(){clearInterval(this.keepOnlineInterval)},e}();t.Auth=c},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2);t.Schema=r.Schema;var i=n(1);t.MapSchema=i.MapSchema;var o=n(0);t.ArraySchema=o.ArraySchema;var s=n(33);t.dumpChanges=s.dumpChanges;var a=n(34);t.Reflection=a.Reflection,t.ReflectionType=a.ReflectionType,t.ReflectionField=a.ReflectionField;var c=n(14);t.type=c.type,t.deprecated=c.deprecated,t.filter=c.filter,t.defineTypes=c.defineTypes,t.Context=c.Context},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2),i=n(0),o=n(1),s=function(){function e(e,t,n){void 0===e&&(e={}),void 0===t&&(t=null),this.changed=!1,this.changes=new Set,this.allChanges=new Set,this.deletedKeys={},this.fieldIndexes=e,this.parent=n,this.parentField=t}return e.prototype.change=function(e,t){void 0===t&&(t=!1);var n=this.fieldIndexes[e],r="number"==typeof n?n:e;t?t&&(this.changed=!0,this.changes.add(r),this.allChanges.delete(r)):(this.changed=!0,this.changes.add(r),this.allChanges.add(r)),this.parent&&this.parent.change(this.parentField)},e.prototype.mapIndex=function(e,t){"object"==typeof e&&(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){"object"==typeof e&&(this.deletedKeys[this.indexMap.get(e)]=!0,this.indexMap.delete(e))},e.prototype.isDeleted=function(e){return void 0!==this.deletedKeys[e]},e.prototype.mapIndexChange=function(e,t){"object"!=typeof e||this.indexChange.has(e)||this.indexChange.set(e,t)},e.prototype.getIndexChange=function(e){return this.indexChange&&this.indexChange.get(e)},e.prototype.deleteIndexChange=function(e){"object"==typeof 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),void 0!==e[n]&&this.change(n)}else for(var s=0,a=Object.keys(e);s0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[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}(this._view,this._offset,e);return this._offset+=e,t},r.prototype._bin=function(e){var t=this._buffer.slice(this._offset,this._offset+e);return this._offset+=e,t},r.prototype._parse=function(){var e,t=this._view.getUint8(this._offset++),n=0,r=0,i=0,o=0;if(t<192)return t<128?t:t<144?this._map(15&t):t<160?this._array(15&t):this._str(31&t);if(t>223)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")},t.default=function(e,t){void 0===t&&(t=0);var n=new r(e,t),i=n._parse();if(n._offset!==e.byteLength)throw new Error(e.byteLength-n._offset+" trailing bytes");return i}},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))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){var t=[],n=[],i=function e(t,n,r){var i=typeof r,o=0,s=0,a=0,c=0,u=0,h=0;if("string"===i){if((u=function(e){for(var t=0,n=0,r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}(r))<32)t.push(160|u),h=1;else if(u<256)t.push(217,u),h=2;else if(u<65536)t.push(218,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("String too long");t.push(219,u>>24,u>>16,u>>8,u),h=5}return n.push({_str:r,_length:u,_offset:t.length}),h+u}if("number"===i)return Math.floor(r)===r&&isFinite(r)?r>=0?r<128?(t.push(r),1):r<256?(t.push(204,r),2):r<65536?(t.push(205,r>>8,r),3):r<4294967296?(t.push(206,r>>24,r>>16,r>>8,r),5):(a=r/Math.pow(2,32)>>0,c=r>>>0,t.push(207,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),9):r>=-32?(t.push(r),1):r>=-128?(t.push(208,r),2):r>=-32768?(t.push(209,r>>8,r),3):r>=-2147483648?(t.push(210,r>>24,r>>16,r>>8,r),5):(a=Math.floor(r/Math.pow(2,32)),c=r>>>0,t.push(211,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),9):(t.push(203),n.push({_float:r,_length:8,_offset:t.length}),9);if("object"===i){if(null===r)return t.push(192),1;if(Array.isArray(r)){if((u=r.length)<16)t.push(144|u),h=1;else if(u<65536)t.push(220,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("Array too large");t.push(221,u>>24,u>>16,u>>8,u),h=5}for(o=0;o>>0,t.push(215,0,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),10}if(r instanceof ArrayBuffer){if((u=r.byteLength)<256)t.push(196,u),h=2;else if(u<65536)t.push(197,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("Buffer too large");t.push(198,u>>24,u>>16,u>>8,u),h=5}return n.push({_bin:r,_length:u,_offset:t.length}),h+u}if("function"==typeof r.toJSON)return e(t,n,r.toJSON());var l=[],p="",d=Object.keys(r);for(o=0,s=d.length;o>8,u),h=3;else{if(!(u<4294967296))throw new Error("Object too large");t.push(223,u>>24,u>>16,u>>8,u),h=5}for(o=0;o0&&(u=n[0]._offset);for(var h,f=0,l=0,p=0,d=t.length;p0){for(var n=0,r=this._enqueuedCalls;n2&&void 0!==arguments[2]?arguments[2]:{};i(this,e),this.url=t,this.protocols=n,this.reconnectEnabled=!0,this.listeners={},this.backoff=o(r.backoff||"exponential",r),this.backoff.onReady=this.onBackoffReady.bind(this),(void 0===r.connect||r.connect)&&this.open()}return r(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";Object.defineProperty(t,"__esModule",{value:!0}),t.createBackoff=function(e,t){return new i(r[e],t)};var r={exponential:function(e,t){return Math.floor(Math.random()*Math.pow(2,e)*t)},fibonacci:function(e,t){if(e>(r=1))for(var n=1,r=2,i=2;i0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[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(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=e.slice();return n.push(t),n}function i(e){if(Array.isArray(e)){for(var t=new Array(e.length),n=0;n=0;h--){var f=c[h],l=t[f];if(!n.hasOwnProperty(f)||void 0===n[f]&&void 0!==l&&!1===Array.isArray(n))o.push({operation:"remove",path:r(s,f)}),u=!0;else{var p=n[f];"object"==typeof l&&null!=l&&"object"==typeof p&&null!=p?e(l,p,o,r(s,f)):l!==p&&o.push({operation:"replace",path:r(s,f),value:p,previousValue:l})}}if(!u&&a.length==c.length)return;for(h=a.length-1;h>=0;h--){f=a[h];if(!t.hasOwnProperty(f)&&void 0!==n[f]){p=n[f];var d=r(s,f);"object"==typeof p&&null!=p&&e({},p,o,d),o.push({operation:"add",path:d,value:p})}}}(e,t,n,[]),n}},function(e,t,n){var r,i;r=this,i=function(){"use strict";var e={};function t(){this.a=0,this.b=0,this.i=0,this.z=new Array(16)}t.prototype.init=function(e,t){var n,r,i=0,o=0;for(n=0;n<16;n++)i=i+(r=e[t+n])&65535,o=o+(16-n)*r&65535,this.z[n]=r;this.a=65535&i,this.b=65535&o,this.i=0},t.prototype.next=function(e){var t=this.z[this.i];this.z[this.i]=e,this.i=this.i+1&15,this.a=this.a-t+e&65535,this.b=this.b-16*t+this.a&65535},t.prototype.value=function(){return(65535&this.a|(65535&this.b)<<16)>>>0};var n="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~".split("").map((function(e){return e.charCodeAt(0)})),r=[-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];function i(e){this.a=e,this.pos=0}function o(){this.a=[]}function s(e){var t,n;for(t=1,n=64;e>=n;t++,n<<=6);return t}function a(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}return i.prototype.haveBytes=function(){return this.posthis.a.length)throw new RangeError("out of bounds");return e},i.prototype.getChar=function(){return String.fromCharCode(this.getByte())},i.prototype.getInt=function(){for(var e,t=0;this.haveBytes()&&(e=r[127&this.getByte()])>=0;)t=(t<<6)+e;return this.pos--,t>>>0},o.prototype.toArray=function(){return this.a},o.prototype.putByte=function(e){this.a.push(255&e)},o.prototype.putChar=function(e){this.putByte(e.charCodeAt(0))},o.prototype.putInt=function(e){var t,r,i=[];if(0!==e){for(t=0;e>0;t++,e>>>=6)i.push(n[63&e]);for(r=t-1;r>=0;r--)this.putByte(i[r])}else this.putChar("0")},o.prototype.putArray=function(e,t,n){for(var r=t;r=0&&O-- >0;){var C,A,S,k,I,M,E;for(k=0,M=y=16*g,E=w+r;M=s(r-I)+s(C)+s(A)+3&&C>_&&(_=C,b=y-I,m=S),g=l[g]}if(_>0){m>0&&(i.putInt(m),i.putChar(":"),i.putArray(n,w,w+m),w+=m),w+=_,i.putInt(_),i.putChar("@"),i.putInt(b),i.putChar(","),b+_-1>h&&(h=b+_-1),_=0;break}if(w+r+16>=c){i.putInt(c-w),i.putChar(":"),i.putArray(n,w,w+c-w),w=c;break}v.next(n[w+r+16]),r++}return wr)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((s+=l)>r)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((!n||!1!==n.verifyChecksum)&&l!==a(d))throw new Error("bad checksum");if(s!==r)throw new Error("generated size does not match predicted size");return d;default:throw new Error("unknown delta operator")}}throw new Error("unterminated delta")},e},e.exports?e.exports=i():r.fossilDelta=i()},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(12),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,t){this.state?(new r.Reflection).decode(e,t):this.state=r.Reflection.decode(e)},e}();t.SchemaSerializer=i},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(12),i=n(1),o=n(0);t.dumpChanges=function e(t){for(var n={},s=t.$changes,a=t._fieldsByIndex||{},c=0,u=Array.from(s.changes);c=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 s=n(14),a=n(2),c=n(0),u=n(1),h=new s.Context,f=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),o([s.type("string",h)],t.prototype,"name",void 0),o([s.type("string",h)],t.prototype,"type",void 0),o([s.type("uint8",h)],t.prototype,"referencedType",void 0),t}(a.Schema);t.ReflectionField=f;var l=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.fields=new c.ArraySchema,t}return i(t,e),o([s.type("uint8",h)],t.prototype,"id",void 0),o([s.type([f],h)],t.prototype,"fields",void 0),t}(a.Schema);t.ReflectionType=l;var p=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.types=new c.ArraySchema,t}return i(t,e),t.encode=function(e){var n=e.constructor,r=new t;r.rootType=n._typeid;var i=function(e,t){for(var n in t){var i=new f;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)},o=n._context.types;for(var s in o){var a=new l;a.id=Number(s),i(a,o[s]._schema)}return r.encodeAll()},t.decode=function(e){var n=new s.Context,r=new t;r.decode(e);var o=r.types.reduce((function(e,t){return e[t.id]=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),t}(a.Schema),e}),{});r.types.forEach((function(e,t){e.fields.forEach((function(t){var r=o[e.id];if(void 0!==t.referencedType){var i=o[t.referencedType];i||(i=t.type.split(":")[1]),0===t.type.indexOf("array")?s.type([i],n)(r.prototype,t.name):0===t.type.indexOf("map")?s.type({map:i},n)(r.prototype,t.name):"ref"===t.type&&s.type(i,n)(r.prototype,t.name)}else s.type(t.type,n)(r.prototype,t.name)}))}));var h=o[r.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 c.ArraySchema:y?new u.MapSchema:d?new p:void 0}}return f},o([s.type([l],h)],t.prototype,"types",void 0),o([s.type("uint8",h)],t.prototype,"rootType",void 0),t}(a.Schema);t.Reflection=p}])})); \ No newline at end of file diff --git a/package.json b/package.json index e3ee042..413ddb8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "colyseus.js", - "version": "0.13.0-alpha.4", + "version": "0.13.0-alpha.6", "description": "Multiplayer Game Client for the Browser", "keywords": [ "colyseus", diff --git a/src/Room.ts b/src/Room.ts index 8cbb888..8570754 100644 --- a/src/Room.ts +++ b/src/Room.ts @@ -117,7 +117,6 @@ export class Room { } public send(type: string | number, message?: any): void { - const encoded = msgpack.encode(message); const initialBytes: number[] = [Protocol.ROOM_DATA]; if (typeof(type) === "string") { @@ -127,9 +126,17 @@ export class Room { encode.number(initialBytes, type); } - const arr = new Uint8Array(initialBytes.length + encoded.byteLength); - arr.set(new Uint8Array(initialBytes), 0); - arr.set(new Uint8Array(encoded), initialBytes.length); + let arr: Uint8Array; + + if (message !== undefined) { + const encoded = msgpack.encode(message); + arr = new Uint8Array(initialBytes.length + encoded.byteLength); + arr.set(new Uint8Array(initialBytes), 0); + arr.set(new Uint8Array(encoded), initialBytes.length); + + } else { + arr = new Uint8Array(initialBytes); + } this.connection.send(arr.buffer); } @@ -224,11 +231,16 @@ export class Room { } else if (code === Protocol.ROOM_DATA) { const it: decode.Iterator = { offset: 1 }; + const type = (decode.stringCheck(bytes, it)) ? decode.string(bytes, it) : decode.number(bytes, it); - this.dispatchMessage(type, msgpack.decode(event.data, it.offset)); + const message = (bytes.length > it.offset) + ? msgpack.decode(event.data, it.offset) + : undefined; + + this.dispatchMessage(type, message); } } From 6574473d0b945d0729fc8d0fc259ddd8cff64035 Mon Sep 17 00:00:00 2001 From: Endel Dreyer Date: Fri, 10 Apr 2020 23:05:53 +0300 Subject: [PATCH 07/11] improve error handling. expose ErrorCode enum. colyseus/colyseus#317 --- dist/colyseus.js | 4 ++-- package.json | 4 ++-- src/Client.ts | 3 ++- src/Protocol.ts | 13 ++++++++++++- src/Room.ts | 17 +++++++++++------ src/errors/ServerError.ts | 11 +++++++++++ src/index.ts | 2 +- 7 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 src/errors/ServerError.ts diff --git a/dist/colyseus.js b/dist/colyseus.js index 962f8c0..0554e9f 100644 --- a/dist/colyseus.js +++ b/dist/colyseus.js @@ -1,2 +1,2 @@ -/*! colyseus.js@0.13.0-alpha.6 */ -!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()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=15)}([function(e,t,n){"use strict";var r,i=this&&this.__extends||(r=function(e,t){return(r=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])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),o=this&&this.__spreadArrays||function(){for(var e=0,t=0,n=arguments.length;t=e+t-1}));return i.map((function(e){var t=e&&e.$changes;t&&(t.parent.deleteIndex(e),delete t.parent)})),o.forEach((function(e){var t=e&&e.$changes;t&&t.parentField--})),i},t}(Array);t.ArraySchema=s},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function e(t){var n=this;for(var r in void 0===t&&(t={}),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(t){var r;if(t)(r=Object.assign(new e,n)).onAdd=n.onAdd,r.onRemove=n.onRemove,r.onChange=n.onChange;else{var i=new e;for(var o in n)"object"==typeof n[o]?i[o]=n[o].clone():i[o]=n[o]}return r}},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(e){for(var t=0,r=new Map,i=0,o=e;i0;var C=!1;g.length>w&&Array.prototype.splice.call(g,w).forEach((function(t,n){if(t&&t.onRemove)try{t.onRemove()}catch(t){e.onError(t)}if(m.onRemove)try{m.onRemove(t,w+n)}catch(t){e.onError(t)}}));for(var A=0;A0;C=!1;var x=Object.keys(E);for(A=0;A0)try{this.onChange(r)}catch(t){e.onError(t)}return this},e.prototype.encode=function(e,t,n,r){var i=this;if(void 0===e&&(e=this),void 0===t&&(t=!1),void 0===r&&(r=[]),!this.$changes.changed&&!t)return this._encodeEndOfStructure(this,e,r),r;for(var a=this._schema,h=this._indexes,f=this._fieldsByIndex,d=this._filters,v=Array.from(t||n?this.$changes.allChanges:this.$changes.changes).sort(),y=function(y,_){var b=f[v[y]]||v[y],m="_"+b,w=a[b],O=d&&d[b],C=g[m],A=h[b];if(void 0===C)s.uint8(r,o.NIL),s.number(r,A);else if(w._schema){if(n&&O&&!O.call(g,n,C,e))return"continue";C?(s.number(r,A),l(C,w,g,b),g.tryEncodeTypeId(r,w,C.constructor),C.encode(e,t,n,r)):(s.uint8(r,o.NIL),s.number(r,A))}else if(Array.isArray(w)){var S=C.$changes;s.number(r,A),s.number(r,C.length);var k=Array.from(t||n?S.allChanges:S.changes).filter((function(e){return void 0!==i[m][e]})).sort((function(e,t){return e-t})),I=k.length;s.number(r,I);var M="string"!=typeof w[0];l(g[m],c.ArraySchema,g,b);for(var E=0;E=400?o:i)(h)},(a=n.body)&&/Array|Object/.test(a.constructor)&&(f["content-type"]="application/json",a=JSON.stringify(a)),f)h.setRequestHeader(s,f[s]);h.send(a)}))}n.r(t),n.d(t,"send",(function(){return 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(5)),o=n(20),s=n(21),a=n(6),c=n(7),u=r(n(8)),h=r(n(9)),f=function(){function e(e,t){var n=this;this.onJoin=o.createSignal(),this.onStateChange=o.createSignal(),this.onError=o.createSignal(),this.onLeave=o.createSignal(),this.hasJoined=!1,this.onMessageHandlers={},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){if(!t.hasJoined)return console.error("Room connection was closed unexpectedly ("+e.code+"): "+e.reason),void t.onError.invoke(e.reason);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.onMessage=function(e,t){return this.onMessageHandlers[this.getMessageHandlerKey(e)]=t,this},e.prototype.send=function(e,t){var n,r=[c.Protocol.ROOM_DATA];if("string"==typeof e?u.string(r,e):u.number(r,e),void 0!==t){var o=i.encode(t);(n=new Uint8Array(r.length+o.byteLength)).set(new Uint8Array(r),0),n.set(new Uint8Array(o),r.length)}else n=new Uint8Array(r);this.connection.send(n.buffer)},Object.defineProperty(e.prototype,"state",{get:function(){return this.serializer.getState()},enumerable:!0,configurable:!0}),e.prototype.listen=function(e,t,n){if("schema"!==this.serializerId)return this.serializerId||console.warn("room.Listen() should be called after room.onJoin has been called (DEPRECATION WARNING)"),this.serializer.api.listen(e,t,n);console.error("'"+this.serializerId+"' serializer doesn't support .listen() method here.")},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.onError.clear(),this.onLeave.clear()},e.prototype.onMessageCallback=function(e){var t=Array.from(new Uint8Array(e.data)),n=t[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);"fossil-delta"===this.serializerId||this.rootSchema||(this.serializer=new o),t.length>r&&this.serializer.handshake&&this.serializer.handshake(t,{offset:1}),this.hasJoined=!0,this.onJoin.invoke(),this.connection.send([c.Protocol.JOIN_ROOM])}else if(n===c.Protocol.JOIN_ERROR)this.onError.invoke(c.utf8Read(t,1));else if(n===c.Protocol.LEAVE_ROOM)this.leave();else if(n===c.Protocol.ROOM_DATA_SCHEMA){(f=new(u=this.serializer.getState().constructor._context.get(t[1]))).decode(t,{offset:2}),this.dispatchMessage(u,f)}else if(n===c.Protocol.ROOM_STATE)t.shift(),this.setState(t);else if(n===c.Protocol.ROOM_STATE_PATCH)t.shift(),this.patch(t);else if(n===c.Protocol.ROOM_DATA){var s={offset:1},u=h.stringCheck(t,s)?h.string(t,s):h.number(t,s),f=t.length>s.offset?i.decode(e.data,s.offset):void 0;this.dispatchMessage(u,f)}},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.prototype.dispatchMessage=function(e,t){var n=this.getMessageHandlerKey(e);this.onMessageHandlers[n]?this.onMessageHandlers[n](t):this.onMessageHandlers["*"]?this.onMessageHandlers[n](e,t):console.warn("onMessage not registered for type '"+e+"'.")},e.prototype.getMessageHandlerKey=function(e){switch(typeof e){case"function":return"$"+e._typeid;case"string":return e;case"number":return"i"+e;default:throw new Error("invalid message type.")}},e}();t.Room=f},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(18)),o=r(n(19));t.decode=i.default,t.encode=o.default},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r={};t.registerSerializer=function(e,t){r[e]=t},t.getSerializer=function(e){return r[e]}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),function(e){e[e.HANDSHAKE=9]="HANDSHAKE",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",e[e.ROOM_DATA_SCHEMA=16]="ROOM_DATA_SCHEMA"}(t.Protocol||(t.Protocol={})),t.utf8Read=function(e,t){for(var n=e[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[++o])<<6|(63&e[++o])<<0);else r+=String.fromCharCode((31&a)<<6|63&e[++o]);else r+=String.fromCharCode(a)}return r},t.utf8Length=function(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}},function(e,t,n){"use strict";function r(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 i(e,t){e.push(255&t)}function o(e,t){e.push(255&t)}function s(e,t){e.push(255&t),e.push(t>>8&255)}function a(e,t){e.push(255&t),e.push(t>>8&255)}function c(e,t){e.push(255&t),e.push(t>>8&255),e.push(t>>16&255),e.push(t>>24&255)}function u(e,t){var n=t>>24,r=t>>16,i=t>>8,o=t;e.push(255&o),e.push(255&i),e.push(255&r),e.push(255&n)}function h(e,t){var n=Math.floor(t/Math.pow(2,32));u(e,t>>>0),u(e,n)}function f(e,t){var n=t/Math.pow(2,32)>>0;u(e,t>>>0),u(e,n)}Object.defineProperty(t,"__esModule",{value:!0}),t.utf8Write=r,t.int8=i,t.uint8=o,t.int16=s,t.uint16=a,t.int32=c,t.uint32=u,t.int64=h,t.uint64=f,t.float32=function(e,t){v(e,t)},t.float64=function(e,t){y(e,t)};var l=new Int32Array(2),p=new Float32Array(l.buffer),d=new Float64Array(l.buffer);function v(e,t){p[0]=t,c(e,l[0])}function y(e,t){d[0]=t,c(e,l[0]),c(e,l[1])}t.writeFloat32=v,t.writeFloat64=y,t.boolean=function(e,t){return o(e,t?1:0)},t.string=function(e,t){t||(t="");var n=function(e){for(var t=0,n=0,r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}(t),i=0;if(n<32)e.push(160|n),i=1;else if(n<256)e.push(217),o(e,n),i=2;else if(n<65536)e.push(218),a(e,n),i=3;else{if(!(n<4294967296))throw new Error("String too long");e.push(219),u(e,n),i=5}return r(e,e.length,t),i+n},t.number=function e(t,n){return isNaN(n)?e(t,0):isFinite(n)?n!==(0|n)?(t.push(203),y(t,n),9):n>=0?n<128?(o(t,n),1):n<256?(t.push(204),o(t,n),2):n<65536?(t.push(205),a(t,n),3):n<4294967296?(t.push(206),u(t,n),5):(t.push(207),f(t,n),9):n>=-32?(t.push(n),1):n>=-128?(t.push(208),i(t,n),2):n>=-32768?(t.push(209),s(t,n),3):n>=-2147483648?(t.push(210),c(t,n),5):(t.push(211),h(t,n),9):e(t,n>0?Number.MAX_SAFE_INTEGER:-Number.MAX_SAFE_INTEGER)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(10);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){var n=u(e,t);return c(e,t)*Math.pow(2,32)+n}function f(e,t){var n=u(e,t);return u(e,t)*Math.pow(2,32)+n}t.int8=i,t.uint8=o,t.int16=s,t.uint16=a,t.int32=c,t.uint32=u,t.float32=function(e,t){return v(e,t)},t.float64=function(e,t){return y(e,t)},t.int64=h,t.uint64=f;var l=new Int32Array(2),p=new Float32Array(l.buffer),d=new Float64Array(l.buffer);function v(e,t){return l[0]=c(e,t),p[0]}function y(e,t){return l[0]=c(e,t),l[1]=c(e,t),d[0]}t.readFloat32=v,t.readFloat64=y,t.boolean=function(e,t){return o(e,t)>0},t.string=function(e,t){var n,r=e[t.offset++];r<192?n=31&r:217===r?n=o(e,t):218===r?n=a(e,t):219===r&&(n=u(e,t));var i=function(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}(e,t.offset,n);return t.offset+=n,i},t.stringCheck=function(e,t){var n=e[t.offset];return(n<192&&n>160||217===n||218===n||219===n)},t.number=function(e,t){var n=e[t.offset++];return n<128?n:202===n?v(e,t):203===n?y(e,t):204===n?o(e,t):205===n?a(e,t):206===n?u(e,t):207===n?f(e,t):208===n?i(e,t):209===n?s(e,t):210===n?c(e,t):211===n?h(e,t):n>223?-1*(255-n+1):void 0},t.numberCheck=function(e,t){var n=e[t.offset];return n<128||n>=202&&n<=211},t.arrayCheck=function(e,t){return e[t.offset]<160},t.nilCheck=function(e,t){return e[t.offset]===r.NIL},t.indexChangeCheck=function(e,t){return e[t.offset]===r.INDEX_CHANGE}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.END_OF_STRUCTURE=193,t.NIL=192,t.INDEX_CHANGE=212,t.TYPE_ID=213},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){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=(i=s.trys).length>0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0?"?"+r.join("&"):"",h={headers:a},o&&(h.body=o),[4,s[e](""+this.endpoint+t+u,h)];case 1:return[2,i.sent().data]}}))}))},e.prototype.logout=function(){this.token=void 0,a.removeItem("colyseus-auth-token"),this.unregisterPingService()},e.prototype.registerPingService=function(e){var t=this;void 0===e&&(e=15e3),this.unregisterPingService(),this.keepOnlineInterval=setInterval((function(){return t.request("get","/auth")}),e)},e.prototype.unregisterPingService=function(){clearInterval(this.keepOnlineInterval)},e}();t.Auth=c},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2);t.Schema=r.Schema;var i=n(1);t.MapSchema=i.MapSchema;var o=n(0);t.ArraySchema=o.ArraySchema;var s=n(33);t.dumpChanges=s.dumpChanges;var a=n(34);t.Reflection=a.Reflection,t.ReflectionType=a.ReflectionType,t.ReflectionField=a.ReflectionField;var c=n(14);t.type=c.type,t.deprecated=c.deprecated,t.filter=c.filter,t.defineTypes=c.defineTypes,t.Context=c.Context},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2),i=n(0),o=n(1),s=function(){function e(e,t,n){void 0===e&&(e={}),void 0===t&&(t=null),this.changed=!1,this.changes=new Set,this.allChanges=new Set,this.deletedKeys={},this.fieldIndexes=e,this.parent=n,this.parentField=t}return e.prototype.change=function(e,t){void 0===t&&(t=!1);var n=this.fieldIndexes[e],r="number"==typeof n?n:e;t?t&&(this.changed=!0,this.changes.add(r),this.allChanges.delete(r)):(this.changed=!0,this.changes.add(r),this.allChanges.add(r)),this.parent&&this.parent.change(this.parentField)},e.prototype.mapIndex=function(e,t){"object"==typeof e&&(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){"object"==typeof e&&(this.deletedKeys[this.indexMap.get(e)]=!0,this.indexMap.delete(e))},e.prototype.isDeleted=function(e){return void 0!==this.deletedKeys[e]},e.prototype.mapIndexChange=function(e,t){"object"!=typeof e||this.indexChange.has(e)||this.indexChange.set(e,t)},e.prototype.getIndexChange=function(e){return this.indexChange&&this.indexChange.get(e)},e.prototype.deleteIndexChange=function(e){"object"==typeof 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),void 0!==e[n]&&this.change(n)}else for(var s=0,a=Object.keys(e);s0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[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}(this._view,this._offset,e);return this._offset+=e,t},r.prototype._bin=function(e){var t=this._buffer.slice(this._offset,this._offset+e);return this._offset+=e,t},r.prototype._parse=function(){var e,t=this._view.getUint8(this._offset++),n=0,r=0,i=0,o=0;if(t<192)return t<128?t:t<144?this._map(15&t):t<160?this._array(15&t):this._str(31&t);if(t>223)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")},t.default=function(e,t){void 0===t&&(t=0);var n=new r(e,t),i=n._parse();if(n._offset!==e.byteLength)throw new Error(e.byteLength-n._offset+" trailing bytes");return i}},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))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){var t=[],n=[],i=function e(t,n,r){var i=typeof r,o=0,s=0,a=0,c=0,u=0,h=0;if("string"===i){if((u=function(e){for(var t=0,n=0,r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}(r))<32)t.push(160|u),h=1;else if(u<256)t.push(217,u),h=2;else if(u<65536)t.push(218,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("String too long");t.push(219,u>>24,u>>16,u>>8,u),h=5}return n.push({_str:r,_length:u,_offset:t.length}),h+u}if("number"===i)return Math.floor(r)===r&&isFinite(r)?r>=0?r<128?(t.push(r),1):r<256?(t.push(204,r),2):r<65536?(t.push(205,r>>8,r),3):r<4294967296?(t.push(206,r>>24,r>>16,r>>8,r),5):(a=r/Math.pow(2,32)>>0,c=r>>>0,t.push(207,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),9):r>=-32?(t.push(r),1):r>=-128?(t.push(208,r),2):r>=-32768?(t.push(209,r>>8,r),3):r>=-2147483648?(t.push(210,r>>24,r>>16,r>>8,r),5):(a=Math.floor(r/Math.pow(2,32)),c=r>>>0,t.push(211,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),9):(t.push(203),n.push({_float:r,_length:8,_offset:t.length}),9);if("object"===i){if(null===r)return t.push(192),1;if(Array.isArray(r)){if((u=r.length)<16)t.push(144|u),h=1;else if(u<65536)t.push(220,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("Array too large");t.push(221,u>>24,u>>16,u>>8,u),h=5}for(o=0;o>>0,t.push(215,0,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),10}if(r instanceof ArrayBuffer){if((u=r.byteLength)<256)t.push(196,u),h=2;else if(u<65536)t.push(197,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("Buffer too large");t.push(198,u>>24,u>>16,u>>8,u),h=5}return n.push({_bin:r,_length:u,_offset:t.length}),h+u}if("function"==typeof r.toJSON)return e(t,n,r.toJSON());var l=[],p="",d=Object.keys(r);for(o=0,s=d.length;o>8,u),h=3;else{if(!(u<4294967296))throw new Error("Object too large");t.push(223,u>>24,u>>16,u>>8,u),h=5}for(o=0;o0&&(u=n[0]._offset);for(var h,f=0,l=0,p=0,d=t.length;p0){for(var n=0,r=this._enqueuedCalls;n2&&void 0!==arguments[2]?arguments[2]:{};i(this,e),this.url=t,this.protocols=n,this.reconnectEnabled=!0,this.listeners={},this.backoff=o(r.backoff||"exponential",r),this.backoff.onReady=this.onBackoffReady.bind(this),(void 0===r.connect||r.connect)&&this.open()}return r(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";Object.defineProperty(t,"__esModule",{value:!0}),t.createBackoff=function(e,t){return new i(r[e],t)};var r={exponential:function(e,t){return Math.floor(Math.random()*Math.pow(2,e)*t)},fibonacci:function(e,t){if(e>(r=1))for(var n=1,r=2,i=2;i0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[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(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=e.slice();return n.push(t),n}function i(e){if(Array.isArray(e)){for(var t=new Array(e.length),n=0;n=0;h--){var f=c[h],l=t[f];if(!n.hasOwnProperty(f)||void 0===n[f]&&void 0!==l&&!1===Array.isArray(n))o.push({operation:"remove",path:r(s,f)}),u=!0;else{var p=n[f];"object"==typeof l&&null!=l&&"object"==typeof p&&null!=p?e(l,p,o,r(s,f)):l!==p&&o.push({operation:"replace",path:r(s,f),value:p,previousValue:l})}}if(!u&&a.length==c.length)return;for(h=a.length-1;h>=0;h--){f=a[h];if(!t.hasOwnProperty(f)&&void 0!==n[f]){p=n[f];var d=r(s,f);"object"==typeof p&&null!=p&&e({},p,o,d),o.push({operation:"add",path:d,value:p})}}}(e,t,n,[]),n}},function(e,t,n){var r,i;r=this,i=function(){"use strict";var e={};function t(){this.a=0,this.b=0,this.i=0,this.z=new Array(16)}t.prototype.init=function(e,t){var n,r,i=0,o=0;for(n=0;n<16;n++)i=i+(r=e[t+n])&65535,o=o+(16-n)*r&65535,this.z[n]=r;this.a=65535&i,this.b=65535&o,this.i=0},t.prototype.next=function(e){var t=this.z[this.i];this.z[this.i]=e,this.i=this.i+1&15,this.a=this.a-t+e&65535,this.b=this.b-16*t+this.a&65535},t.prototype.value=function(){return(65535&this.a|(65535&this.b)<<16)>>>0};var n="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~".split("").map((function(e){return e.charCodeAt(0)})),r=[-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];function i(e){this.a=e,this.pos=0}function o(){this.a=[]}function s(e){var t,n;for(t=1,n=64;e>=n;t++,n<<=6);return t}function a(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}return i.prototype.haveBytes=function(){return this.posthis.a.length)throw new RangeError("out of bounds");return e},i.prototype.getChar=function(){return String.fromCharCode(this.getByte())},i.prototype.getInt=function(){for(var e,t=0;this.haveBytes()&&(e=r[127&this.getByte()])>=0;)t=(t<<6)+e;return this.pos--,t>>>0},o.prototype.toArray=function(){return this.a},o.prototype.putByte=function(e){this.a.push(255&e)},o.prototype.putChar=function(e){this.putByte(e.charCodeAt(0))},o.prototype.putInt=function(e){var t,r,i=[];if(0!==e){for(t=0;e>0;t++,e>>>=6)i.push(n[63&e]);for(r=t-1;r>=0;r--)this.putByte(i[r])}else this.putChar("0")},o.prototype.putArray=function(e,t,n){for(var r=t;r=0&&O-- >0;){var C,A,S,k,I,M,E;for(k=0,M=y=16*g,E=w+r;M=s(r-I)+s(C)+s(A)+3&&C>_&&(_=C,b=y-I,m=S),g=l[g]}if(_>0){m>0&&(i.putInt(m),i.putChar(":"),i.putArray(n,w,w+m),w+=m),w+=_,i.putInt(_),i.putChar("@"),i.putInt(b),i.putChar(","),b+_-1>h&&(h=b+_-1),_=0;break}if(w+r+16>=c){i.putInt(c-w),i.putChar(":"),i.putArray(n,w,w+c-w),w=c;break}v.next(n[w+r+16]),r++}return wr)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((s+=l)>r)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((!n||!1!==n.verifyChecksum)&&l!==a(d))throw new Error("bad checksum");if(s!==r)throw new Error("generated size does not match predicted size");return d;default:throw new Error("unknown delta operator")}}throw new Error("unterminated delta")},e},e.exports?e.exports=i():r.fossilDelta=i()},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(12),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,t){this.state?(new r.Reflection).decode(e,t):this.state=r.Reflection.decode(e)},e}();t.SchemaSerializer=i},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(12),i=n(1),o=n(0);t.dumpChanges=function e(t){for(var n={},s=t.$changes,a=t._fieldsByIndex||{},c=0,u=Array.from(s.changes);c=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 s=n(14),a=n(2),c=n(0),u=n(1),h=new s.Context,f=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),o([s.type("string",h)],t.prototype,"name",void 0),o([s.type("string",h)],t.prototype,"type",void 0),o([s.type("uint8",h)],t.prototype,"referencedType",void 0),t}(a.Schema);t.ReflectionField=f;var l=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.fields=new c.ArraySchema,t}return i(t,e),o([s.type("uint8",h)],t.prototype,"id",void 0),o([s.type([f],h)],t.prototype,"fields",void 0),t}(a.Schema);t.ReflectionType=l;var p=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.types=new c.ArraySchema,t}return i(t,e),t.encode=function(e){var n=e.constructor,r=new t;r.rootType=n._typeid;var i=function(e,t){for(var n in t){var i=new f;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)},o=n._context.types;for(var s in o){var a=new l;a.id=Number(s),i(a,o[s]._schema)}return r.encodeAll()},t.decode=function(e){var n=new s.Context,r=new t;r.decode(e);var o=r.types.reduce((function(e,t){return e[t.id]=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),t}(a.Schema),e}),{});r.types.forEach((function(e,t){e.fields.forEach((function(t){var r=o[e.id];if(void 0!==t.referencedType){var i=o[t.referencedType];i||(i=t.type.split(":")[1]),0===t.type.indexOf("array")?s.type([i],n)(r.prototype,t.name):0===t.type.indexOf("map")?s.type({map:i},n)(r.prototype,t.name):"ref"===t.type&&s.type(i,n)(r.prototype,t.name)}else s.type(t.type,n)(r.prototype,t.name)}))}));var h=o[r.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 c.ArraySchema:y?new u.MapSchema:d?new p:void 0}}return f},o([s.type([l],h)],t.prototype,"types",void 0),o([s.type("uint8",h)],t.prototype,"rootType",void 0),t}(a.Schema);t.Reflection=p}])})); \ No newline at end of file +/*! colyseus.js@0.13.0-alpha.8 */ +!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()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=15)}([function(e,t,n){"use strict";var r,i=this&&this.__extends||(r=function(e,t){return(r=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])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),o=this&&this.__spreadArrays||function(){for(var e=0,t=0,n=arguments.length;t=e+t-1}));return i.map((function(e){var t=e&&e.$changes;t&&(t.parent.deleteIndex(e),delete t.parent)})),o.forEach((function(e){var t=e&&e.$changes;t&&t.parentField--})),i},t}(Array);t.ArraySchema=s},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function e(t){var n=this;for(var r in void 0===t&&(t={}),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(t){var r;if(t)(r=Object.assign(new e,n)).onAdd=n.onAdd,r.onRemove=n.onRemove,r.onChange=n.onChange;else{var i=new e;for(var o in n)"object"==typeof n[o]?i[o]=n[o].clone():i[o]=n[o]}return r}},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(e){for(var t=0,r=new Map,i=0,o=e;im;_=w>0||A;var C=!1;A&&Array.prototype.splice.call(g,m).forEach((function(t,n){if(t&&t.onRemove)try{t.onRemove()}catch(t){e.onError(t)}if(b.onRemove)try{b.onRemove(t,m+n)}catch(t){e.onError(t)}}));for(var O=0;O0;C=!1;var x=Object.keys(k);for(O=0;O0){for(var n=0;n=400?o:i)(h)},(a=n.body)&&"object"==typeof a&&(f["content-type"]="application/json",a=JSON.stringify(a)),h.withCredentials=!!n.withCredentials,f)h.setRequestHeader(s,f[s]);h.send(a)}))}n.r(t),n.d(t,"send",(function(){return 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(5)),o=n(21),s=n(22),a=n(6),c=n(7),u=r(n(8)),h=r(n(9)),f=function(){function e(e,t){var n=this;this.onJoin=o.createSignal(),this.onStateChange=o.createSignal(),this.onError=o.createSignal(),this.onLeave=o.createSignal(),this.hasJoined=!1,this.onMessageHandlers={},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,t){return console.error("colyseus.js - onError => ("+e+") "+t)})),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){if(!t.hasJoined)return console.error("Room connection was closed unexpectedly ("+e.code+"): "+e.reason),void t.onError.invoke(e.code,e.reason);t.onLeave.invoke(e.code)},this.connection.onerror=function(e){console.warn("Room, onError ("+e.code+"): "+e.reason),t.onError.invoke(e.code,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.onMessage=function(e,t){return this.onMessageHandlers[this.getMessageHandlerKey(e)]=t,this},e.prototype.send=function(e,t){var n,r=[c.Protocol.ROOM_DATA];if("string"==typeof e?u.string(r,e):u.number(r,e),void 0!==t){var o=i.encode(t);(n=new Uint8Array(r.length+o.byteLength)).set(new Uint8Array(r),0),n.set(new Uint8Array(o),r.length)}else n=new Uint8Array(r);this.connection.send(n.buffer)},Object.defineProperty(e.prototype,"state",{get:function(){return this.serializer.getState()},enumerable:!0,configurable:!0}),e.prototype.listen=function(e,t,n){if("schema"!==this.serializerId)return this.serializerId||console.warn("room.Listen() should be called after room.onJoin has been called (DEPRECATION WARNING)"),this.serializer.api.listen(e,t,n);console.error("'"+this.serializerId+"' serializer doesn't support .listen() method here.")},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.onError.clear(),this.onLeave.clear()},e.prototype.onMessageCallback=function(e){var t=Array.from(new Uint8Array(e.data)),n=t[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);"fossil-delta"===this.serializerId||this.rootSchema||(this.serializer=new o),t.length>r&&this.serializer.handshake&&this.serializer.handshake(t,{offset:1}),this.hasJoined=!0,this.onJoin.invoke(),this.connection.send([c.Protocol.JOIN_ROOM])}else if(n===c.Protocol.ERROR){var s={offset:1},u=h.number(t,s),f=h.string(t,s);this.onError.invoke(u,f)}else if(n===c.Protocol.LEAVE_ROOM)this.leave();else if(n===c.Protocol.ROOM_DATA_SCHEMA){(f=new(p=this.serializer.getState().constructor._context.get(t[1]))).decode(t,{offset:2}),this.dispatchMessage(p,f)}else if(n===c.Protocol.ROOM_STATE)t.shift(),this.setState(t);else if(n===c.Protocol.ROOM_STATE_PATCH)t.shift(),this.patch(t);else if(n===c.Protocol.ROOM_DATA){var l={offset:1},p=h.stringCheck(t,l)?h.string(t,l):h.number(t,l);f=t.length>l.offset?i.decode(e.data,l.offset):void 0;this.dispatchMessage(p,f)}},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.prototype.dispatchMessage=function(e,t){var n=this.getMessageHandlerKey(e);this.onMessageHandlers[n]?this.onMessageHandlers[n](t):this.onMessageHandlers["*"]?this.onMessageHandlers[n](e,t):console.warn("onMessage not registered for type '"+e+"'.")},e.prototype.getMessageHandlerKey=function(e){switch(typeof e){case"function":return"$"+e._typeid;case"string":return e;case"number":return"i"+e;default:throw new Error("invalid message type.")}},e}();t.Room=f},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(19)),o=r(n(20));t.decode=i.default,t.encode=o.default},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r={};t.registerSerializer=function(e,t){r[e]=t},t.getSerializer=function(e){return r[e]}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),function(e){e[e.HANDSHAKE=9]="HANDSHAKE",e[e.JOIN_ROOM=10]="JOIN_ROOM",e[e.ERROR=11]="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",e[e.ROOM_DATA_SCHEMA=16]="ROOM_DATA_SCHEMA"}(t.Protocol||(t.Protocol={})),function(e){e[e.MATCHMAKE_NO_HANDLER=4210]="MATCHMAKE_NO_HANDLER",e[e.MATCHMAKE_INVALID_CRITERIA=4211]="MATCHMAKE_INVALID_CRITERIA",e[e.MATCHMAKE_INVALID_ROOM_ID=4212]="MATCHMAKE_INVALID_ROOM_ID",e[e.MATCHMAKE_UNHANDLED=4213]="MATCHMAKE_UNHANDLED",e[e.MATCHMAKE_EXPIRED=4214]="MATCHMAKE_EXPIRED",e[e.AUTH_FAILED=4215]="AUTH_FAILED"}(t.ErrorCode||(t.ErrorCode={})),t.utf8Read=function(e,t){for(var n=e[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[++o])<<6|(63&e[++o])<<0);else r+=String.fromCharCode((31&a)<<6|63&e[++o]);else r+=String.fromCharCode(a)}return r},t.utf8Length=function(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}},function(e,t,n){"use strict";function r(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 i(e,t){e.push(255&t)}function o(e,t){e.push(255&t)}function s(e,t){e.push(255&t),e.push(t>>8&255)}function a(e,t){e.push(255&t),e.push(t>>8&255)}function c(e,t){e.push(255&t),e.push(t>>8&255),e.push(t>>16&255),e.push(t>>24&255)}function u(e,t){var n=t>>24,r=t>>16,i=t>>8,o=t;e.push(255&o),e.push(255&i),e.push(255&r),e.push(255&n)}function h(e,t){var n=Math.floor(t/Math.pow(2,32));u(e,t>>>0),u(e,n)}function f(e,t){var n=t/Math.pow(2,32)>>0;u(e,t>>>0),u(e,n)}Object.defineProperty(t,"__esModule",{value:!0}),t.utf8Write=r,t.int8=i,t.uint8=o,t.int16=s,t.uint16=a,t.int32=c,t.uint32=u,t.int64=h,t.uint64=f,t.float32=function(e,t){v(e,t)},t.float64=function(e,t){y(e,t)};var l=new Int32Array(2),p=new Float32Array(l.buffer),d=new Float64Array(l.buffer);function v(e,t){p[0]=t,c(e,l[0])}function y(e,t){d[0]=t,c(e,l[0]),c(e,l[1])}t.writeFloat32=v,t.writeFloat64=y,t.boolean=function(e,t){return o(e,t?1:0)},t.string=function(e,t){t||(t="");var n=function(e){for(var t=0,n=0,r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}(t),i=0;if(n<32)e.push(160|n),i=1;else if(n<256)e.push(217),o(e,n),i=2;else if(n<65536)e.push(218),a(e,n),i=3;else{if(!(n<4294967296))throw new Error("String too long");e.push(219),u(e,n),i=5}return r(e,e.length,t),i+n},t.number=function e(t,n){return isNaN(n)?e(t,0):isFinite(n)?n!==(0|n)?(t.push(203),y(t,n),9):n>=0?n<128?(o(t,n),1):n<256?(t.push(204),o(t,n),2):n<65536?(t.push(205),a(t,n),3):n<4294967296?(t.push(206),u(t,n),5):(t.push(207),f(t,n),9):n>=-32?(t.push(n),1):n>=-128?(t.push(208),i(t,n),2):n>=-32768?(t.push(209),s(t,n),3):n>=-2147483648?(t.push(210),c(t,n),5):(t.push(211),h(t,n),9):e(t,n>0?Number.MAX_SAFE_INTEGER:-Number.MAX_SAFE_INTEGER)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(10);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){var n=u(e,t);return c(e,t)*Math.pow(2,32)+n}function f(e,t){var n=u(e,t);return u(e,t)*Math.pow(2,32)+n}t.int8=i,t.uint8=o,t.int16=s,t.uint16=a,t.int32=c,t.uint32=u,t.float32=function(e,t){return v(e,t)},t.float64=function(e,t){return y(e,t)},t.int64=h,t.uint64=f;var l=new Int32Array(2),p=new Float32Array(l.buffer),d=new Float64Array(l.buffer);function v(e,t){return l[0]=c(e,t),p[0]}function y(e,t){return l[0]=c(e,t),l[1]=c(e,t),d[0]}t.readFloat32=v,t.readFloat64=y,t.boolean=function(e,t){return o(e,t)>0},t.string=function(e,t){var n,r=e[t.offset++];r<192?n=31&r:217===r?n=o(e,t):218===r?n=a(e,t):219===r&&(n=u(e,t));var i=function(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}(e,t.offset,n);return t.offset+=n,i},t.stringCheck=function(e,t){var n=e[t.offset];return n<192&&n>160||217===n||218===n||219===n},t.number=function(e,t){var n=e[t.offset++];return n<128?n:202===n?v(e,t):203===n?y(e,t):204===n?o(e,t):205===n?a(e,t):206===n?u(e,t):207===n?f(e,t):208===n?i(e,t):209===n?s(e,t):210===n?c(e,t):211===n?h(e,t):n>223?-1*(255-n+1):void 0},t.numberCheck=function(e,t){var n=e[t.offset];return n<128||n>=202&&n<=211},t.arrayCheck=function(e,t){return e[t.offset]<160},t.nilCheck=function(e,t){return e[t.offset]===r.NIL},t.indexChangeCheck=function(e,t){return e[t.offset]===r.INDEX_CHANGE}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.END_OF_STRUCTURE=193,t.NIL=192,t.INDEX_CHANGE=212,t.TYPE_ID=213},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){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},i=this&&this.__generator||function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0?"?"+r.join("&"):"",h={headers:a},o&&(h.body=o),[4,s[e](""+this.endpoint+t+u,h)];case 1:return[2,i.sent().data]}}))}))},e.prototype.logout=function(){this.token=void 0,a.removeItem("colyseus-auth-token"),this.unregisterPingService()},e.prototype.registerPingService=function(e){var t=this;void 0===e&&(e=15e3),this.unregisterPingService(),this.keepOnlineInterval=setInterval((function(){return t.request("get","/auth")}),e)},e.prototype.unregisterPingService=function(){clearInterval(this.keepOnlineInterval)},e}();t.Auth=c},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2);t.Schema=r.Schema;var i=n(1);t.MapSchema=i.MapSchema;var o=n(0);t.ArraySchema=o.ArraySchema;var s=n(35);t.dumpChanges=s.dumpChanges;var a=n(36);t.Reflection=a.Reflection,t.ReflectionType=a.ReflectionType,t.ReflectionField=a.ReflectionField;var c=n(14);t.type=c.type,t.deprecated=c.deprecated,t.filter=c.filter,t.defineTypes=c.defineTypes,t.Context=c.Context},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2),i=n(0),o=n(1),s=function(){function e(e,t,n){void 0===e&&(e={}),void 0===t&&(t=null),this.changed=!1,this.changes=new Set,this.allChanges=new Set,this.deletedKeys={},this.fieldIndexes=e,this.parent=n,this.parentField=t}return e.prototype.change=function(e,t){void 0===t&&(t=!1);var n=this.fieldIndexes[e],r="number"==typeof n?n:e;t?t&&(this.changed=!0,this.changes.add(r),this.allChanges.delete(r)):(this.changed=!0,this.changes.add(r),this.allChanges.add(r)),this.parent&&this.parent.change(this.parentField)},e.prototype.mapIndex=function(e,t){"object"==typeof e&&(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){"object"==typeof e&&(this.deletedKeys[this.indexMap.get(e)]=!0,this.indexMap.delete(e))},e.prototype.isDeleted=function(e){return void 0!==this.deletedKeys[e]},e.prototype.mapIndexChange=function(e,t){"object"!=typeof e||this.indexChange.has(e)||this.indexChange.set(e,t)},e.prototype.getIndexChange=function(e){return this.indexChange&&this.indexChange.get(e)},e.prototype.deleteIndexChange=function(e){"object"==typeof 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),void 0!==e[n]&&this.change(n)}else for(var s=0,a=Object.keys(e);s0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[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}(this._view,this._offset,e);return this._offset+=e,t},r.prototype._bin=function(e){var t=this._buffer.slice(this._offset,this._offset+e);return this._offset+=e,t},r.prototype._parse=function(){var e,t=this._view.getUint8(this._offset++),n=0,r=0,i=0,o=0;if(t<192)return t<128?t:t<144?this._map(15&t):t<160?this._array(15&t):this._str(31&t);if(t>223)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")},t.default=function(e,t){void 0===t&&(t=0);var n=new r(e,t),i=n._parse();if(n._offset!==e.byteLength)throw new Error(e.byteLength-n._offset+" trailing bytes");return i}},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))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){var t=[],n=[],i=function e(t,n,r){var i=typeof r,o=0,s=0,a=0,c=0,u=0,h=0;if("string"===i){if((u=function(e){for(var t=0,n=0,r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}(r))<32)t.push(160|u),h=1;else if(u<256)t.push(217,u),h=2;else if(u<65536)t.push(218,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("String too long");t.push(219,u>>24,u>>16,u>>8,u),h=5}return n.push({_str:r,_length:u,_offset:t.length}),h+u}if("number"===i)return Math.floor(r)===r&&isFinite(r)?r>=0?r<128?(t.push(r),1):r<256?(t.push(204,r),2):r<65536?(t.push(205,r>>8,r),3):r<4294967296?(t.push(206,r>>24,r>>16,r>>8,r),5):(a=r/Math.pow(2,32)>>0,c=r>>>0,t.push(207,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),9):r>=-32?(t.push(r),1):r>=-128?(t.push(208,r),2):r>=-32768?(t.push(209,r>>8,r),3):r>=-2147483648?(t.push(210,r>>24,r>>16,r>>8,r),5):(a=Math.floor(r/Math.pow(2,32)),c=r>>>0,t.push(211,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),9):(t.push(203),n.push({_float:r,_length:8,_offset:t.length}),9);if("object"===i){if(null===r)return t.push(192),1;if(Array.isArray(r)){if((u=r.length)<16)t.push(144|u),h=1;else if(u<65536)t.push(220,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("Array too large");t.push(221,u>>24,u>>16,u>>8,u),h=5}for(o=0;o>>0,t.push(215,0,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),10}if(r instanceof ArrayBuffer){if((u=r.byteLength)<256)t.push(196,u),h=2;else if(u<65536)t.push(197,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("Buffer too large");t.push(198,u>>24,u>>16,u>>8,u),h=5}return n.push({_bin:r,_length:u,_offset:t.length}),h+u}if("function"==typeof r.toJSON)return e(t,n,r.toJSON());var l=[],p="",d=Object.keys(r);for(o=0,s=d.length;o>8,u),h=3;else{if(!(u<4294967296))throw new Error("Object too large");t.push(223,u>>24,u>>16,u>>8,u),h=5}for(o=0;o0&&(u=n[0]._offset);for(var h,f=0,l=0,p=0,d=t.length;p0){for(var n=0,r=this._enqueuedCalls;n2&&void 0!==arguments[2]?arguments[2]:{};i(this,e),this.url=t,this.protocols=n,this.reconnectEnabled=!0,this.listeners={},this.backoff=o(r.backoff||"exponential",r),this.backoff.onReady=this.onBackoffReady.bind(this),(void 0===r.connect||r.connect)&&this.open()}return r(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";Object.defineProperty(t,"__esModule",{value:!0}),t.createBackoff=function(e,t){return new i(r[e],t)};var r={exponential:function(e,t){return Math.floor(Math.random()*Math.pow(2,e)*t)},fibonacci:function(e,t){if(e>(r=1))for(var n=1,r=2,i=2;i0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[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(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=e.slice();return n.push(t),n}function i(e){if(Array.isArray(e)){for(var t=new Array(e.length),n=0;n=0;h--){var f=c[h],l=t[f];if(!n.hasOwnProperty(f)||void 0===n[f]&&void 0!==l&&!1===Array.isArray(n))o.push({operation:"remove",path:r(s,f)}),u=!0;else{var p=n[f];"object"==typeof l&&null!=l&&"object"==typeof p&&null!=p?e(l,p,o,r(s,f)):l!==p&&o.push({operation:"replace",path:r(s,f),value:p,previousValue:l})}}if(!u&&a.length==c.length)return;for(h=a.length-1;h>=0;h--){f=a[h];if(!t.hasOwnProperty(f)&&void 0!==n[f]){p=n[f];var d=r(s,f);"object"==typeof p&&null!=p&&e({},p,o,d),o.push({operation:"add",path:d,value:p})}}}(e,t,n,[]),n}},function(e,t,n){var r,i;r=this,i=function(){"use strict";var e={};function t(){this.a=0,this.b=0,this.i=0,this.z=new Array(16)}t.prototype.init=function(e,t){var n,r,i=0,o=0;for(n=0;n<16;n++)i=i+(r=e[t+n])&65535,o=o+(16-n)*r&65535,this.z[n]=r;this.a=65535&i,this.b=65535&o,this.i=0},t.prototype.next=function(e){var t=this.z[this.i];this.z[this.i]=e,this.i=this.i+1&15,this.a=this.a-t+e&65535,this.b=this.b-16*t+this.a&65535},t.prototype.value=function(){return(65535&this.a|(65535&this.b)<<16)>>>0};var n="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~".split("").map((function(e){return e.charCodeAt(0)})),r=[-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];function i(e){this.a=e,this.pos=0}function o(){this.a=[]}function s(e){var t,n;for(t=1,n=64;e>=n;t++,n<<=6);return t}function a(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}return i.prototype.haveBytes=function(){return this.posthis.a.length)throw new RangeError("out of bounds");return e},i.prototype.getChar=function(){return String.fromCharCode(this.getByte())},i.prototype.getInt=function(){for(var e,t=0;this.haveBytes()&&(e=r[127&this.getByte()])>=0;)t=(t<<6)+e;return this.pos--,t>>>0},o.prototype.toArray=function(){return this.a},o.prototype.putByte=function(e){this.a.push(255&e)},o.prototype.putChar=function(e){this.putByte(e.charCodeAt(0))},o.prototype.putInt=function(e){var t,r,i=[];if(0!==e){for(t=0;e>0;t++,e>>>=6)i.push(n[63&e]);for(r=t-1;r>=0;r--)this.putByte(i[r])}else this.putChar("0")},o.prototype.putArray=function(e,t,n){for(var r=t;r=0&&A-- >0;){var C,O,S,E,I,M,k;for(E=0,M=y=16*g,k=w+r;M=s(r-I)+s(C)+s(O)+3&&C>_&&(_=C,b=y-I,m=S),g=l[g]}if(_>0){m>0&&(i.putInt(m),i.putChar(":"),i.putArray(n,w,w+m),w+=m),w+=_,i.putInt(_),i.putChar("@"),i.putInt(b),i.putChar(","),b+_-1>h&&(h=b+_-1),_=0;break}if(w+r+16>=c){i.putInt(c-w),i.putChar(":"),i.putArray(n,w,w+c-w),w=c;break}v.next(n[w+r+16]),r++}return wr)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((s+=l)>r)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((!n||!1!==n.verifyChecksum)&&l!==a(d))throw new Error("bad checksum");if(s!==r)throw new Error("generated size does not match predicted size");return d;default:throw new Error("unknown delta operator")}}throw new Error("unterminated delta")},e},e.exports?e.exports=i():r.fossilDelta=i()},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(12),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,t){this.state?(new r.Reflection).decode(e,t):this.state=r.Reflection.decode(e)},e}();t.SchemaSerializer=i},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(){this.handlers=[]}return e.prototype.register=function(e,t){return void 0===t&&(t=!1),this.handlers.push(e),this},e.prototype.invoke=function(){for(var e=[],t=0;t=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 s=n(14),a=n(2),c=n(0),u=n(1),h=new s.Context,f=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),o([s.type("string",h)],t.prototype,"name",void 0),o([s.type("string",h)],t.prototype,"type",void 0),o([s.type("uint8",h)],t.prototype,"referencedType",void 0),t}(a.Schema);t.ReflectionField=f;var l=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.fields=new c.ArraySchema,t}return i(t,e),o([s.type("uint8",h)],t.prototype,"id",void 0),o([s.type([f],h)],t.prototype,"fields",void 0),t}(a.Schema);t.ReflectionType=l;var p=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.types=new c.ArraySchema,t}return i(t,e),t.encode=function(e){var n=e.constructor,r=new t;r.rootType=n._typeid;var i=function(e,t){for(var n in t){var i=new f;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)},o=n._context.types;for(var s in o){var a=new l;a.id=Number(s),i(a,o[s]._schema)}return r.encodeAll()},t.decode=function(e){var n=new s.Context,r=new t;r.decode(e);var o=r.types.reduce((function(e,t){return e[t.id]=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),t}(a.Schema),e}),{});r.types.forEach((function(e,t){e.fields.forEach((function(t){var r=o[e.id];if(void 0!==t.referencedType){var i=o[t.referencedType];i||(i=t.type.split(":")[1]),0===t.type.indexOf("array")?s.type([i],n)(r.prototype,t.name):0===t.type.indexOf("map")?s.type({map:i},n)(r.prototype,t.name):"ref"===t.type&&s.type(i,n)(r.prototype,t.name)}else s.type(t.type,n)(r.prototype,t.name)}))}));var h=o[r.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 c.ArraySchema:y?new u.MapSchema:d?new p:void 0}}return f},o([s.type([l],h)],t.prototype,"types",void 0),o([s.type("uint8",h)],t.prototype,"rootType",void 0),t}(a.Schema);t.Reflection=p}])})); \ No newline at end of file diff --git a/package.json b/package.json index 182aecd..1b55a72 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "colyseus.js", - "version": "0.13.0-alpha.7", + "version": "0.13.0-alpha.9", "description": "Multiplayer Game Client for the Browser", "keywords": [ "colyseus", @@ -56,7 +56,7 @@ "ts-loader": "^6.2.1", "ts-node": "^6.0.3", "tslint": "^5.9.1", - "typescript": "~3.5.0", + "typescript": "^3.8.3", "uglify-js": "^2.6.1", "webpack": "^4.41.2", "webpack-cli": "^3.3.10", diff --git a/src/Client.ts b/src/Client.ts index 334334d..6fa5218 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -1,5 +1,6 @@ import { post, get } from "httpie"; +import { ServerError } from './errors/ServerError'; import { Room, RoomAvailable } from './Room'; import { Auth } from './Auth'; import { Push } from './Push'; @@ -63,7 +64,7 @@ export class Client { room.connect(this.buildEndpoint(response.room, { sessionId: room.sessionId })); return new Promise((resolve, reject) => { - const onError = (message) => reject(message); + const onError = (code, message) => reject(new ServerError(code, message)); room.onError.once(onError); room.onJoin.once(() => { diff --git a/src/Protocol.ts b/src/Protocol.ts index 00961cd..91ba32e 100644 --- a/src/Protocol.ts +++ b/src/Protocol.ts @@ -4,7 +4,7 @@ export enum Protocol { // Room-related (10~19) HANDSHAKE = 9, JOIN_ROOM = 10, - JOIN_ERROR = 11, + ERROR = 11, LEAVE_ROOM = 12, ROOM_DATA = 13, ROOM_STATE = 14, @@ -12,6 +12,17 @@ export enum Protocol { ROOM_DATA_SCHEMA = 16, } +export enum ErrorCode { + MATCHMAKE_NO_HANDLER = 4210, + MATCHMAKE_INVALID_CRITERIA = 4211, + MATCHMAKE_INVALID_ROOM_ID = 4212, + MATCHMAKE_UNHANDLED = 4213, + MATCHMAKE_EXPIRED = 4214, + + AUTH_FAILED = 4215, + APPLICATION_ERROR = 4216, +} + export function utf8Read(view: number[], offset: number) { const length = view[offset++]; diff --git a/src/Room.ts b/src/Room.ts index d8a2fdf..02af68d 100644 --- a/src/Room.ts +++ b/src/Room.ts @@ -30,7 +30,7 @@ export class Room { // Public signals public onJoin = createSignal(); public onStateChange = createSignal<(state: State) => void>(); - public onError = createSignal<(message: string) => void>(); + public onError = createSignal<(code: number, message?: string) => void>(); public onLeave = createSignal<(code: number) => void>(); public connection: Connection; @@ -59,7 +59,7 @@ export class Room { this.serializer = new (getSerializer("fossil-delta")); } - this.onError((message) => message && console.error(message)); + this.onError((code, message) => console.error(`colyseus.js - onError => (${code}) ${message}`)); this.onLeave(() => this.removeAllListeners()); } @@ -70,7 +70,7 @@ export class Room { this.connection.onclose = (e: CloseEvent) => { if (!this.hasJoined) { console.error(`Room connection was closed unexpectedly (${e.code}): ${e.reason}`); - this.onError.invoke(e.reason); + this.onError.invoke(e.code, e.reason); return; } @@ -78,7 +78,7 @@ export class Room { }; this.connection.onerror = (e: CloseEvent) => { console.warn(`Room, onError (${e.code}): ${e.reason}`); - this.onError.invoke(e.reason); + this.onError.invoke(e.code, e.reason); }; this.connection.open(); } @@ -206,8 +206,13 @@ export class Room { // acknowledge successfull JOIN_ROOM this.connection.send([Protocol.JOIN_ROOM]); - } else if (code === Protocol.JOIN_ERROR) { - this.onError.invoke(utf8Read(bytes, 1)); + } else if (code === Protocol.ERROR) { + const it: decode.Iterator = { offset: 1 }; + + const code = decode.number(bytes, it); + const message = decode.string(bytes, it); + + this.onError.invoke(code, message); } else if (code === Protocol.LEAVE_ROOM) { this.leave(); diff --git a/src/errors/ServerError.ts b/src/errors/ServerError.ts new file mode 100644 index 0000000..7ec44b8 --- /dev/null +++ b/src/errors/ServerError.ts @@ -0,0 +1,11 @@ + +export class ServerError extends Error { + public code: number; + + constructor(code: number, message: string) { + super(message); + + this.name = "ServerError"; + this.code = code; + } +} diff --git a/src/index.ts b/src/index.ts index e135f17..bf19239 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ import './legacy'; export { Client, JoinOptions } from './Client'; -export { Protocol } from './Protocol'; +export { Protocol, ErrorCode } from './Protocol'; export { Room, RoomAvailable } from './Room'; export { DataChange } from '@gamestdio/state-listener'; export { Auth, Platform, Device } from "./Auth"; From a3ac819f5cf7d7a761538c7839484e2314511024 Mon Sep 17 00:00:00 2001 From: Endel Dreyer Date: Sat, 11 Apr 2020 02:42:09 +0300 Subject: [PATCH 08/11] fixes onMessage type definition to accept string and number. colyseus/colyseus#315 --- dist/colyseus.js | 4 ++-- package.json | 2 +- src/Room.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/colyseus.js b/dist/colyseus.js index 0554e9f..6f643cc 100644 --- a/dist/colyseus.js +++ b/dist/colyseus.js @@ -1,2 +1,2 @@ -/*! colyseus.js@0.13.0-alpha.8 */ -!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()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=15)}([function(e,t,n){"use strict";var r,i=this&&this.__extends||(r=function(e,t){return(r=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])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),o=this&&this.__spreadArrays||function(){for(var e=0,t=0,n=arguments.length;t=e+t-1}));return i.map((function(e){var t=e&&e.$changes;t&&(t.parent.deleteIndex(e),delete t.parent)})),o.forEach((function(e){var t=e&&e.$changes;t&&t.parentField--})),i},t}(Array);t.ArraySchema=s},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function e(t){var n=this;for(var r in void 0===t&&(t={}),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(t){var r;if(t)(r=Object.assign(new e,n)).onAdd=n.onAdd,r.onRemove=n.onRemove,r.onChange=n.onChange;else{var i=new e;for(var o in n)"object"==typeof n[o]?i[o]=n[o].clone():i[o]=n[o]}return r}},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(e){for(var t=0,r=new Map,i=0,o=e;im;_=w>0||A;var C=!1;A&&Array.prototype.splice.call(g,m).forEach((function(t,n){if(t&&t.onRemove)try{t.onRemove()}catch(t){e.onError(t)}if(b.onRemove)try{b.onRemove(t,m+n)}catch(t){e.onError(t)}}));for(var O=0;O0;C=!1;var x=Object.keys(k);for(O=0;O0){for(var n=0;n=400?o:i)(h)},(a=n.body)&&"object"==typeof a&&(f["content-type"]="application/json",a=JSON.stringify(a)),h.withCredentials=!!n.withCredentials,f)h.setRequestHeader(s,f[s]);h.send(a)}))}n.r(t),n.d(t,"send",(function(){return 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(5)),o=n(21),s=n(22),a=n(6),c=n(7),u=r(n(8)),h=r(n(9)),f=function(){function e(e,t){var n=this;this.onJoin=o.createSignal(),this.onStateChange=o.createSignal(),this.onError=o.createSignal(),this.onLeave=o.createSignal(),this.hasJoined=!1,this.onMessageHandlers={},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,t){return console.error("colyseus.js - onError => ("+e+") "+t)})),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){if(!t.hasJoined)return console.error("Room connection was closed unexpectedly ("+e.code+"): "+e.reason),void t.onError.invoke(e.code,e.reason);t.onLeave.invoke(e.code)},this.connection.onerror=function(e){console.warn("Room, onError ("+e.code+"): "+e.reason),t.onError.invoke(e.code,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.onMessage=function(e,t){return this.onMessageHandlers[this.getMessageHandlerKey(e)]=t,this},e.prototype.send=function(e,t){var n,r=[c.Protocol.ROOM_DATA];if("string"==typeof e?u.string(r,e):u.number(r,e),void 0!==t){var o=i.encode(t);(n=new Uint8Array(r.length+o.byteLength)).set(new Uint8Array(r),0),n.set(new Uint8Array(o),r.length)}else n=new Uint8Array(r);this.connection.send(n.buffer)},Object.defineProperty(e.prototype,"state",{get:function(){return this.serializer.getState()},enumerable:!0,configurable:!0}),e.prototype.listen=function(e,t,n){if("schema"!==this.serializerId)return this.serializerId||console.warn("room.Listen() should be called after room.onJoin has been called (DEPRECATION WARNING)"),this.serializer.api.listen(e,t,n);console.error("'"+this.serializerId+"' serializer doesn't support .listen() method here.")},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.onError.clear(),this.onLeave.clear()},e.prototype.onMessageCallback=function(e){var t=Array.from(new Uint8Array(e.data)),n=t[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);"fossil-delta"===this.serializerId||this.rootSchema||(this.serializer=new o),t.length>r&&this.serializer.handshake&&this.serializer.handshake(t,{offset:1}),this.hasJoined=!0,this.onJoin.invoke(),this.connection.send([c.Protocol.JOIN_ROOM])}else if(n===c.Protocol.ERROR){var s={offset:1},u=h.number(t,s),f=h.string(t,s);this.onError.invoke(u,f)}else if(n===c.Protocol.LEAVE_ROOM)this.leave();else if(n===c.Protocol.ROOM_DATA_SCHEMA){(f=new(p=this.serializer.getState().constructor._context.get(t[1]))).decode(t,{offset:2}),this.dispatchMessage(p,f)}else if(n===c.Protocol.ROOM_STATE)t.shift(),this.setState(t);else if(n===c.Protocol.ROOM_STATE_PATCH)t.shift(),this.patch(t);else if(n===c.Protocol.ROOM_DATA){var l={offset:1},p=h.stringCheck(t,l)?h.string(t,l):h.number(t,l);f=t.length>l.offset?i.decode(e.data,l.offset):void 0;this.dispatchMessage(p,f)}},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.prototype.dispatchMessage=function(e,t){var n=this.getMessageHandlerKey(e);this.onMessageHandlers[n]?this.onMessageHandlers[n](t):this.onMessageHandlers["*"]?this.onMessageHandlers[n](e,t):console.warn("onMessage not registered for type '"+e+"'.")},e.prototype.getMessageHandlerKey=function(e){switch(typeof e){case"function":return"$"+e._typeid;case"string":return e;case"number":return"i"+e;default:throw new Error("invalid message type.")}},e}();t.Room=f},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(19)),o=r(n(20));t.decode=i.default,t.encode=o.default},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r={};t.registerSerializer=function(e,t){r[e]=t},t.getSerializer=function(e){return r[e]}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),function(e){e[e.HANDSHAKE=9]="HANDSHAKE",e[e.JOIN_ROOM=10]="JOIN_ROOM",e[e.ERROR=11]="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",e[e.ROOM_DATA_SCHEMA=16]="ROOM_DATA_SCHEMA"}(t.Protocol||(t.Protocol={})),function(e){e[e.MATCHMAKE_NO_HANDLER=4210]="MATCHMAKE_NO_HANDLER",e[e.MATCHMAKE_INVALID_CRITERIA=4211]="MATCHMAKE_INVALID_CRITERIA",e[e.MATCHMAKE_INVALID_ROOM_ID=4212]="MATCHMAKE_INVALID_ROOM_ID",e[e.MATCHMAKE_UNHANDLED=4213]="MATCHMAKE_UNHANDLED",e[e.MATCHMAKE_EXPIRED=4214]="MATCHMAKE_EXPIRED",e[e.AUTH_FAILED=4215]="AUTH_FAILED"}(t.ErrorCode||(t.ErrorCode={})),t.utf8Read=function(e,t){for(var n=e[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[++o])<<6|(63&e[++o])<<0);else r+=String.fromCharCode((31&a)<<6|63&e[++o]);else r+=String.fromCharCode(a)}return r},t.utf8Length=function(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}},function(e,t,n){"use strict";function r(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 i(e,t){e.push(255&t)}function o(e,t){e.push(255&t)}function s(e,t){e.push(255&t),e.push(t>>8&255)}function a(e,t){e.push(255&t),e.push(t>>8&255)}function c(e,t){e.push(255&t),e.push(t>>8&255),e.push(t>>16&255),e.push(t>>24&255)}function u(e,t){var n=t>>24,r=t>>16,i=t>>8,o=t;e.push(255&o),e.push(255&i),e.push(255&r),e.push(255&n)}function h(e,t){var n=Math.floor(t/Math.pow(2,32));u(e,t>>>0),u(e,n)}function f(e,t){var n=t/Math.pow(2,32)>>0;u(e,t>>>0),u(e,n)}Object.defineProperty(t,"__esModule",{value:!0}),t.utf8Write=r,t.int8=i,t.uint8=o,t.int16=s,t.uint16=a,t.int32=c,t.uint32=u,t.int64=h,t.uint64=f,t.float32=function(e,t){v(e,t)},t.float64=function(e,t){y(e,t)};var l=new Int32Array(2),p=new Float32Array(l.buffer),d=new Float64Array(l.buffer);function v(e,t){p[0]=t,c(e,l[0])}function y(e,t){d[0]=t,c(e,l[0]),c(e,l[1])}t.writeFloat32=v,t.writeFloat64=y,t.boolean=function(e,t){return o(e,t?1:0)},t.string=function(e,t){t||(t="");var n=function(e){for(var t=0,n=0,r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}(t),i=0;if(n<32)e.push(160|n),i=1;else if(n<256)e.push(217),o(e,n),i=2;else if(n<65536)e.push(218),a(e,n),i=3;else{if(!(n<4294967296))throw new Error("String too long");e.push(219),u(e,n),i=5}return r(e,e.length,t),i+n},t.number=function e(t,n){return isNaN(n)?e(t,0):isFinite(n)?n!==(0|n)?(t.push(203),y(t,n),9):n>=0?n<128?(o(t,n),1):n<256?(t.push(204),o(t,n),2):n<65536?(t.push(205),a(t,n),3):n<4294967296?(t.push(206),u(t,n),5):(t.push(207),f(t,n),9):n>=-32?(t.push(n),1):n>=-128?(t.push(208),i(t,n),2):n>=-32768?(t.push(209),s(t,n),3):n>=-2147483648?(t.push(210),c(t,n),5):(t.push(211),h(t,n),9):e(t,n>0?Number.MAX_SAFE_INTEGER:-Number.MAX_SAFE_INTEGER)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(10);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){var n=u(e,t);return c(e,t)*Math.pow(2,32)+n}function f(e,t){var n=u(e,t);return u(e,t)*Math.pow(2,32)+n}t.int8=i,t.uint8=o,t.int16=s,t.uint16=a,t.int32=c,t.uint32=u,t.float32=function(e,t){return v(e,t)},t.float64=function(e,t){return y(e,t)},t.int64=h,t.uint64=f;var l=new Int32Array(2),p=new Float32Array(l.buffer),d=new Float64Array(l.buffer);function v(e,t){return l[0]=c(e,t),p[0]}function y(e,t){return l[0]=c(e,t),l[1]=c(e,t),d[0]}t.readFloat32=v,t.readFloat64=y,t.boolean=function(e,t){return o(e,t)>0},t.string=function(e,t){var n,r=e[t.offset++];r<192?n=31&r:217===r?n=o(e,t):218===r?n=a(e,t):219===r&&(n=u(e,t));var i=function(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}(e,t.offset,n);return t.offset+=n,i},t.stringCheck=function(e,t){var n=e[t.offset];return n<192&&n>160||217===n||218===n||219===n},t.number=function(e,t){var n=e[t.offset++];return n<128?n:202===n?v(e,t):203===n?y(e,t):204===n?o(e,t):205===n?a(e,t):206===n?u(e,t):207===n?f(e,t):208===n?i(e,t):209===n?s(e,t):210===n?c(e,t):211===n?h(e,t):n>223?-1*(255-n+1):void 0},t.numberCheck=function(e,t){var n=e[t.offset];return n<128||n>=202&&n<=211},t.arrayCheck=function(e,t){return e[t.offset]<160},t.nilCheck=function(e,t){return e[t.offset]===r.NIL},t.indexChangeCheck=function(e,t){return e[t.offset]===r.INDEX_CHANGE}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.END_OF_STRUCTURE=193,t.NIL=192,t.INDEX_CHANGE=212,t.TYPE_ID=213},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){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},i=this&&this.__generator||function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0?"?"+r.join("&"):"",h={headers:a},o&&(h.body=o),[4,s[e](""+this.endpoint+t+u,h)];case 1:return[2,i.sent().data]}}))}))},e.prototype.logout=function(){this.token=void 0,a.removeItem("colyseus-auth-token"),this.unregisterPingService()},e.prototype.registerPingService=function(e){var t=this;void 0===e&&(e=15e3),this.unregisterPingService(),this.keepOnlineInterval=setInterval((function(){return t.request("get","/auth")}),e)},e.prototype.unregisterPingService=function(){clearInterval(this.keepOnlineInterval)},e}();t.Auth=c},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2);t.Schema=r.Schema;var i=n(1);t.MapSchema=i.MapSchema;var o=n(0);t.ArraySchema=o.ArraySchema;var s=n(35);t.dumpChanges=s.dumpChanges;var a=n(36);t.Reflection=a.Reflection,t.ReflectionType=a.ReflectionType,t.ReflectionField=a.ReflectionField;var c=n(14);t.type=c.type,t.deprecated=c.deprecated,t.filter=c.filter,t.defineTypes=c.defineTypes,t.Context=c.Context},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2),i=n(0),o=n(1),s=function(){function e(e,t,n){void 0===e&&(e={}),void 0===t&&(t=null),this.changed=!1,this.changes=new Set,this.allChanges=new Set,this.deletedKeys={},this.fieldIndexes=e,this.parent=n,this.parentField=t}return e.prototype.change=function(e,t){void 0===t&&(t=!1);var n=this.fieldIndexes[e],r="number"==typeof n?n:e;t?t&&(this.changed=!0,this.changes.add(r),this.allChanges.delete(r)):(this.changed=!0,this.changes.add(r),this.allChanges.add(r)),this.parent&&this.parent.change(this.parentField)},e.prototype.mapIndex=function(e,t){"object"==typeof e&&(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){"object"==typeof e&&(this.deletedKeys[this.indexMap.get(e)]=!0,this.indexMap.delete(e))},e.prototype.isDeleted=function(e){return void 0!==this.deletedKeys[e]},e.prototype.mapIndexChange=function(e,t){"object"!=typeof e||this.indexChange.has(e)||this.indexChange.set(e,t)},e.prototype.getIndexChange=function(e){return this.indexChange&&this.indexChange.get(e)},e.prototype.deleteIndexChange=function(e){"object"==typeof 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),void 0!==e[n]&&this.change(n)}else for(var s=0,a=Object.keys(e);s0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[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}(this._view,this._offset,e);return this._offset+=e,t},r.prototype._bin=function(e){var t=this._buffer.slice(this._offset,this._offset+e);return this._offset+=e,t},r.prototype._parse=function(){var e,t=this._view.getUint8(this._offset++),n=0,r=0,i=0,o=0;if(t<192)return t<128?t:t<144?this._map(15&t):t<160?this._array(15&t):this._str(31&t);if(t>223)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")},t.default=function(e,t){void 0===t&&(t=0);var n=new r(e,t),i=n._parse();if(n._offset!==e.byteLength)throw new Error(e.byteLength-n._offset+" trailing bytes");return i}},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))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){var t=[],n=[],i=function e(t,n,r){var i=typeof r,o=0,s=0,a=0,c=0,u=0,h=0;if("string"===i){if((u=function(e){for(var t=0,n=0,r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}(r))<32)t.push(160|u),h=1;else if(u<256)t.push(217,u),h=2;else if(u<65536)t.push(218,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("String too long");t.push(219,u>>24,u>>16,u>>8,u),h=5}return n.push({_str:r,_length:u,_offset:t.length}),h+u}if("number"===i)return Math.floor(r)===r&&isFinite(r)?r>=0?r<128?(t.push(r),1):r<256?(t.push(204,r),2):r<65536?(t.push(205,r>>8,r),3):r<4294967296?(t.push(206,r>>24,r>>16,r>>8,r),5):(a=r/Math.pow(2,32)>>0,c=r>>>0,t.push(207,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),9):r>=-32?(t.push(r),1):r>=-128?(t.push(208,r),2):r>=-32768?(t.push(209,r>>8,r),3):r>=-2147483648?(t.push(210,r>>24,r>>16,r>>8,r),5):(a=Math.floor(r/Math.pow(2,32)),c=r>>>0,t.push(211,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),9):(t.push(203),n.push({_float:r,_length:8,_offset:t.length}),9);if("object"===i){if(null===r)return t.push(192),1;if(Array.isArray(r)){if((u=r.length)<16)t.push(144|u),h=1;else if(u<65536)t.push(220,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("Array too large");t.push(221,u>>24,u>>16,u>>8,u),h=5}for(o=0;o>>0,t.push(215,0,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),10}if(r instanceof ArrayBuffer){if((u=r.byteLength)<256)t.push(196,u),h=2;else if(u<65536)t.push(197,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("Buffer too large");t.push(198,u>>24,u>>16,u>>8,u),h=5}return n.push({_bin:r,_length:u,_offset:t.length}),h+u}if("function"==typeof r.toJSON)return e(t,n,r.toJSON());var l=[],p="",d=Object.keys(r);for(o=0,s=d.length;o>8,u),h=3;else{if(!(u<4294967296))throw new Error("Object too large");t.push(223,u>>24,u>>16,u>>8,u),h=5}for(o=0;o0&&(u=n[0]._offset);for(var h,f=0,l=0,p=0,d=t.length;p0){for(var n=0,r=this._enqueuedCalls;n2&&void 0!==arguments[2]?arguments[2]:{};i(this,e),this.url=t,this.protocols=n,this.reconnectEnabled=!0,this.listeners={},this.backoff=o(r.backoff||"exponential",r),this.backoff.onReady=this.onBackoffReady.bind(this),(void 0===r.connect||r.connect)&&this.open()}return r(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";Object.defineProperty(t,"__esModule",{value:!0}),t.createBackoff=function(e,t){return new i(r[e],t)};var r={exponential:function(e,t){return Math.floor(Math.random()*Math.pow(2,e)*t)},fibonacci:function(e,t){if(e>(r=1))for(var n=1,r=2,i=2;i0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[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(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=e.slice();return n.push(t),n}function i(e){if(Array.isArray(e)){for(var t=new Array(e.length),n=0;n=0;h--){var f=c[h],l=t[f];if(!n.hasOwnProperty(f)||void 0===n[f]&&void 0!==l&&!1===Array.isArray(n))o.push({operation:"remove",path:r(s,f)}),u=!0;else{var p=n[f];"object"==typeof l&&null!=l&&"object"==typeof p&&null!=p?e(l,p,o,r(s,f)):l!==p&&o.push({operation:"replace",path:r(s,f),value:p,previousValue:l})}}if(!u&&a.length==c.length)return;for(h=a.length-1;h>=0;h--){f=a[h];if(!t.hasOwnProperty(f)&&void 0!==n[f]){p=n[f];var d=r(s,f);"object"==typeof p&&null!=p&&e({},p,o,d),o.push({operation:"add",path:d,value:p})}}}(e,t,n,[]),n}},function(e,t,n){var r,i;r=this,i=function(){"use strict";var e={};function t(){this.a=0,this.b=0,this.i=0,this.z=new Array(16)}t.prototype.init=function(e,t){var n,r,i=0,o=0;for(n=0;n<16;n++)i=i+(r=e[t+n])&65535,o=o+(16-n)*r&65535,this.z[n]=r;this.a=65535&i,this.b=65535&o,this.i=0},t.prototype.next=function(e){var t=this.z[this.i];this.z[this.i]=e,this.i=this.i+1&15,this.a=this.a-t+e&65535,this.b=this.b-16*t+this.a&65535},t.prototype.value=function(){return(65535&this.a|(65535&this.b)<<16)>>>0};var n="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~".split("").map((function(e){return e.charCodeAt(0)})),r=[-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];function i(e){this.a=e,this.pos=0}function o(){this.a=[]}function s(e){var t,n;for(t=1,n=64;e>=n;t++,n<<=6);return t}function a(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}return i.prototype.haveBytes=function(){return this.posthis.a.length)throw new RangeError("out of bounds");return e},i.prototype.getChar=function(){return String.fromCharCode(this.getByte())},i.prototype.getInt=function(){for(var e,t=0;this.haveBytes()&&(e=r[127&this.getByte()])>=0;)t=(t<<6)+e;return this.pos--,t>>>0},o.prototype.toArray=function(){return this.a},o.prototype.putByte=function(e){this.a.push(255&e)},o.prototype.putChar=function(e){this.putByte(e.charCodeAt(0))},o.prototype.putInt=function(e){var t,r,i=[];if(0!==e){for(t=0;e>0;t++,e>>>=6)i.push(n[63&e]);for(r=t-1;r>=0;r--)this.putByte(i[r])}else this.putChar("0")},o.prototype.putArray=function(e,t,n){for(var r=t;r=0&&A-- >0;){var C,O,S,E,I,M,k;for(E=0,M=y=16*g,k=w+r;M=s(r-I)+s(C)+s(O)+3&&C>_&&(_=C,b=y-I,m=S),g=l[g]}if(_>0){m>0&&(i.putInt(m),i.putChar(":"),i.putArray(n,w,w+m),w+=m),w+=_,i.putInt(_),i.putChar("@"),i.putInt(b),i.putChar(","),b+_-1>h&&(h=b+_-1),_=0;break}if(w+r+16>=c){i.putInt(c-w),i.putChar(":"),i.putArray(n,w,w+c-w),w=c;break}v.next(n[w+r+16]),r++}return wr)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((s+=l)>r)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((!n||!1!==n.verifyChecksum)&&l!==a(d))throw new Error("bad checksum");if(s!==r)throw new Error("generated size does not match predicted size");return d;default:throw new Error("unknown delta operator")}}throw new Error("unterminated delta")},e},e.exports?e.exports=i():r.fossilDelta=i()},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(12),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,t){this.state?(new r.Reflection).decode(e,t):this.state=r.Reflection.decode(e)},e}();t.SchemaSerializer=i},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(){this.handlers=[]}return e.prototype.register=function(e,t){return void 0===t&&(t=!1),this.handlers.push(e),this},e.prototype.invoke=function(){for(var e=[],t=0;t=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 s=n(14),a=n(2),c=n(0),u=n(1),h=new s.Context,f=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),o([s.type("string",h)],t.prototype,"name",void 0),o([s.type("string",h)],t.prototype,"type",void 0),o([s.type("uint8",h)],t.prototype,"referencedType",void 0),t}(a.Schema);t.ReflectionField=f;var l=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.fields=new c.ArraySchema,t}return i(t,e),o([s.type("uint8",h)],t.prototype,"id",void 0),o([s.type([f],h)],t.prototype,"fields",void 0),t}(a.Schema);t.ReflectionType=l;var p=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.types=new c.ArraySchema,t}return i(t,e),t.encode=function(e){var n=e.constructor,r=new t;r.rootType=n._typeid;var i=function(e,t){for(var n in t){var i=new f;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)},o=n._context.types;for(var s in o){var a=new l;a.id=Number(s),i(a,o[s]._schema)}return r.encodeAll()},t.decode=function(e){var n=new s.Context,r=new t;r.decode(e);var o=r.types.reduce((function(e,t){return e[t.id]=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),t}(a.Schema),e}),{});r.types.forEach((function(e,t){e.fields.forEach((function(t){var r=o[e.id];if(void 0!==t.referencedType){var i=o[t.referencedType];i||(i=t.type.split(":")[1]),0===t.type.indexOf("array")?s.type([i],n)(r.prototype,t.name):0===t.type.indexOf("map")?s.type({map:i},n)(r.prototype,t.name):"ref"===t.type&&s.type(i,n)(r.prototype,t.name)}else s.type(t.type,n)(r.prototype,t.name)}))}));var h=o[r.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 c.ArraySchema:y?new u.MapSchema:d?new p:void 0}}return f},o([s.type([l],h)],t.prototype,"types",void 0),o([s.type("uint8",h)],t.prototype,"rootType",void 0),t}(a.Schema);t.Reflection=p}])})); \ No newline at end of file +/*! colyseus.js@0.13.0-alpha.10 */ +!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()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=15)}([function(e,t,n){"use strict";var r,i=this&&this.__extends||(r=function(e,t){return(r=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])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),o=this&&this.__spreadArrays||function(){for(var e=0,t=0,n=arguments.length;t=e+t-1}));return i.map((function(e){var t=e&&e.$changes;t&&(t.parent.deleteIndex(e),delete t.parent)})),o.forEach((function(e){var t=e&&e.$changes;t&&t.parentField--})),i},t}(Array);t.ArraySchema=s},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function e(t){var n=this;for(var r in void 0===t&&(t={}),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(t){var r;if(t)(r=Object.assign(new e,n)).onAdd=n.onAdd,r.onRemove=n.onRemove,r.onChange=n.onChange;else{var i=new e;for(var o in n)"object"==typeof n[o]?i[o]=n[o].clone():i[o]=n[o]}return r}},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(e){for(var t=0,r=new Map,i=0,o=e;im;_=w>0||A;var C=!1;A&&Array.prototype.splice.call(g,m).forEach((function(t,n){if(t&&t.onRemove)try{t.onRemove()}catch(t){e.onError(t)}if(b.onRemove)try{b.onRemove(t,m+n)}catch(t){e.onError(t)}}));for(var O=0;O0;C=!1;var x=Object.keys(k);for(O=0;O0){for(var n=0;n=400?o:i)(h)},(a=n.body)&&"object"==typeof a&&(f["content-type"]="application/json",a=JSON.stringify(a)),h.withCredentials=!!n.withCredentials,f)h.setRequestHeader(s,f[s]);h.send(a)}))}n.r(t),n.d(t,"send",(function(){return 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(5)),o=n(21),s=n(22),a=n(6),c=n(7),u=r(n(8)),h=r(n(9)),f=function(){function e(e,t){var n=this;this.onJoin=o.createSignal(),this.onStateChange=o.createSignal(),this.onError=o.createSignal(),this.onLeave=o.createSignal(),this.hasJoined=!1,this.onMessageHandlers={},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,t){return console.error("colyseus.js - onError => ("+e+") "+t)})),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){if(!t.hasJoined)return console.error("Room connection was closed unexpectedly ("+e.code+"): "+e.reason),void t.onError.invoke(e.code,e.reason);t.onLeave.invoke(e.code)},this.connection.onerror=function(e){console.warn("Room, onError ("+e.code+"): "+e.reason),t.onError.invoke(e.code,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.onMessage=function(e,t){return this.onMessageHandlers[this.getMessageHandlerKey(e)]=t,this},e.prototype.send=function(e,t){var n,r=[c.Protocol.ROOM_DATA];if("string"==typeof e?u.string(r,e):u.number(r,e),void 0!==t){var o=i.encode(t);(n=new Uint8Array(r.length+o.byteLength)).set(new Uint8Array(r),0),n.set(new Uint8Array(o),r.length)}else n=new Uint8Array(r);this.connection.send(n.buffer)},Object.defineProperty(e.prototype,"state",{get:function(){return this.serializer.getState()},enumerable:!0,configurable:!0}),e.prototype.listen=function(e,t,n){if("schema"!==this.serializerId)return this.serializerId||console.warn("room.Listen() should be called after room.onJoin has been called (DEPRECATION WARNING)"),this.serializer.api.listen(e,t,n);console.error("'"+this.serializerId+"' serializer doesn't support .listen() method here.")},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.onError.clear(),this.onLeave.clear()},e.prototype.onMessageCallback=function(e){var t=Array.from(new Uint8Array(e.data)),n=t[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);"fossil-delta"===this.serializerId||this.rootSchema||(this.serializer=new o),t.length>r&&this.serializer.handshake&&this.serializer.handshake(t,{offset:1}),this.hasJoined=!0,this.onJoin.invoke(),this.connection.send([c.Protocol.JOIN_ROOM])}else if(n===c.Protocol.ERROR){var s={offset:1},u=h.number(t,s),f=h.string(t,s);this.onError.invoke(u,f)}else if(n===c.Protocol.LEAVE_ROOM)this.leave();else if(n===c.Protocol.ROOM_DATA_SCHEMA){(f=new(p=this.serializer.getState().constructor._context.get(t[1]))).decode(t,{offset:2}),this.dispatchMessage(p,f)}else if(n===c.Protocol.ROOM_STATE)t.shift(),this.setState(t);else if(n===c.Protocol.ROOM_STATE_PATCH)t.shift(),this.patch(t);else if(n===c.Protocol.ROOM_DATA){var l={offset:1},p=h.stringCheck(t,l)?h.string(t,l):h.number(t,l);f=t.length>l.offset?i.decode(e.data,l.offset):void 0;this.dispatchMessage(p,f)}},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.prototype.dispatchMessage=function(e,t){var n=this.getMessageHandlerKey(e);this.onMessageHandlers[n]?this.onMessageHandlers[n](t):this.onMessageHandlers["*"]?this.onMessageHandlers[n](e,t):console.warn("onMessage not registered for type '"+e+"'.")},e.prototype.getMessageHandlerKey=function(e){switch(typeof e){case"function":return"$"+e._typeid;case"string":return e;case"number":return"i"+e;default:throw new Error("invalid message type.")}},e}();t.Room=f},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(19)),o=r(n(20));t.decode=i.default,t.encode=o.default},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r={};t.registerSerializer=function(e,t){r[e]=t},t.getSerializer=function(e){return r[e]}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),function(e){e[e.HANDSHAKE=9]="HANDSHAKE",e[e.JOIN_ROOM=10]="JOIN_ROOM",e[e.ERROR=11]="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",e[e.ROOM_DATA_SCHEMA=16]="ROOM_DATA_SCHEMA"}(t.Protocol||(t.Protocol={})),function(e){e[e.MATCHMAKE_NO_HANDLER=4210]="MATCHMAKE_NO_HANDLER",e[e.MATCHMAKE_INVALID_CRITERIA=4211]="MATCHMAKE_INVALID_CRITERIA",e[e.MATCHMAKE_INVALID_ROOM_ID=4212]="MATCHMAKE_INVALID_ROOM_ID",e[e.MATCHMAKE_UNHANDLED=4213]="MATCHMAKE_UNHANDLED",e[e.MATCHMAKE_EXPIRED=4214]="MATCHMAKE_EXPIRED",e[e.AUTH_FAILED=4215]="AUTH_FAILED",e[e.APPLICATION_ERROR=4216]="APPLICATION_ERROR"}(t.ErrorCode||(t.ErrorCode={})),t.utf8Read=function(e,t){for(var n=e[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[++o])<<6|(63&e[++o])<<0);else r+=String.fromCharCode((31&a)<<6|63&e[++o]);else r+=String.fromCharCode(a)}return r},t.utf8Length=function(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}},function(e,t,n){"use strict";function r(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 i(e,t){e.push(255&t)}function o(e,t){e.push(255&t)}function s(e,t){e.push(255&t),e.push(t>>8&255)}function a(e,t){e.push(255&t),e.push(t>>8&255)}function c(e,t){e.push(255&t),e.push(t>>8&255),e.push(t>>16&255),e.push(t>>24&255)}function u(e,t){var n=t>>24,r=t>>16,i=t>>8,o=t;e.push(255&o),e.push(255&i),e.push(255&r),e.push(255&n)}function h(e,t){var n=Math.floor(t/Math.pow(2,32));u(e,t>>>0),u(e,n)}function f(e,t){var n=t/Math.pow(2,32)>>0;u(e,t>>>0),u(e,n)}Object.defineProperty(t,"__esModule",{value:!0}),t.utf8Write=r,t.int8=i,t.uint8=o,t.int16=s,t.uint16=a,t.int32=c,t.uint32=u,t.int64=h,t.uint64=f,t.float32=function(e,t){v(e,t)},t.float64=function(e,t){y(e,t)};var l=new Int32Array(2),p=new Float32Array(l.buffer),d=new Float64Array(l.buffer);function v(e,t){p[0]=t,c(e,l[0])}function y(e,t){d[0]=t,c(e,l[0]),c(e,l[1])}t.writeFloat32=v,t.writeFloat64=y,t.boolean=function(e,t){return o(e,t?1:0)},t.string=function(e,t){t||(t="");var n=function(e){for(var t=0,n=0,r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}(t),i=0;if(n<32)e.push(160|n),i=1;else if(n<256)e.push(217),o(e,n),i=2;else if(n<65536)e.push(218),a(e,n),i=3;else{if(!(n<4294967296))throw new Error("String too long");e.push(219),u(e,n),i=5}return r(e,e.length,t),i+n},t.number=function e(t,n){return isNaN(n)?e(t,0):isFinite(n)?n!==(0|n)?(t.push(203),y(t,n),9):n>=0?n<128?(o(t,n),1):n<256?(t.push(204),o(t,n),2):n<65536?(t.push(205),a(t,n),3):n<4294967296?(t.push(206),u(t,n),5):(t.push(207),f(t,n),9):n>=-32?(t.push(n),1):n>=-128?(t.push(208),i(t,n),2):n>=-32768?(t.push(209),s(t,n),3):n>=-2147483648?(t.push(210),c(t,n),5):(t.push(211),h(t,n),9):e(t,n>0?Number.MAX_SAFE_INTEGER:-Number.MAX_SAFE_INTEGER)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(10);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){var n=u(e,t);return c(e,t)*Math.pow(2,32)+n}function f(e,t){var n=u(e,t);return u(e,t)*Math.pow(2,32)+n}t.int8=i,t.uint8=o,t.int16=s,t.uint16=a,t.int32=c,t.uint32=u,t.float32=function(e,t){return v(e,t)},t.float64=function(e,t){return y(e,t)},t.int64=h,t.uint64=f;var l=new Int32Array(2),p=new Float32Array(l.buffer),d=new Float64Array(l.buffer);function v(e,t){return l[0]=c(e,t),p[0]}function y(e,t){return l[0]=c(e,t),l[1]=c(e,t),d[0]}t.readFloat32=v,t.readFloat64=y,t.boolean=function(e,t){return o(e,t)>0},t.string=function(e,t){var n,r=e[t.offset++];r<192?n=31&r:217===r?n=o(e,t):218===r?n=a(e,t):219===r&&(n=u(e,t));var i=function(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}(e,t.offset,n);return t.offset+=n,i},t.stringCheck=function(e,t){var n=e[t.offset];return n<192&&n>160||217===n||218===n||219===n},t.number=function(e,t){var n=e[t.offset++];return n<128?n:202===n?v(e,t):203===n?y(e,t):204===n?o(e,t):205===n?a(e,t):206===n?u(e,t):207===n?f(e,t):208===n?i(e,t):209===n?s(e,t):210===n?c(e,t):211===n?h(e,t):n>223?-1*(255-n+1):void 0},t.numberCheck=function(e,t){var n=e[t.offset];return n<128||n>=202&&n<=211},t.arrayCheck=function(e,t){return e[t.offset]<160},t.nilCheck=function(e,t){return e[t.offset]===r.NIL},t.indexChangeCheck=function(e,t){return e[t.offset]===r.INDEX_CHANGE}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.END_OF_STRUCTURE=193,t.NIL=192,t.INDEX_CHANGE=212,t.TYPE_ID=213},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){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},i=this&&this.__generator||function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0?"?"+r.join("&"):"",h={headers:a},o&&(h.body=o),[4,s[e](""+this.endpoint+t+u,h)];case 1:return[2,i.sent().data]}}))}))},e.prototype.logout=function(){this.token=void 0,a.removeItem("colyseus-auth-token"),this.unregisterPingService()},e.prototype.registerPingService=function(e){var t=this;void 0===e&&(e=15e3),this.unregisterPingService(),this.keepOnlineInterval=setInterval((function(){return t.request("get","/auth")}),e)},e.prototype.unregisterPingService=function(){clearInterval(this.keepOnlineInterval)},e}();t.Auth=c},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2);t.Schema=r.Schema;var i=n(1);t.MapSchema=i.MapSchema;var o=n(0);t.ArraySchema=o.ArraySchema;var s=n(35);t.dumpChanges=s.dumpChanges;var a=n(36);t.Reflection=a.Reflection,t.ReflectionType=a.ReflectionType,t.ReflectionField=a.ReflectionField;var c=n(14);t.type=c.type,t.deprecated=c.deprecated,t.filter=c.filter,t.defineTypes=c.defineTypes,t.Context=c.Context},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2),i=n(0),o=n(1),s=function(){function e(e,t,n){void 0===e&&(e={}),void 0===t&&(t=null),this.changed=!1,this.changes=new Set,this.allChanges=new Set,this.deletedKeys={},this.fieldIndexes=e,this.parent=n,this.parentField=t}return e.prototype.change=function(e,t){void 0===t&&(t=!1);var n=this.fieldIndexes[e],r="number"==typeof n?n:e;t?t&&(this.changed=!0,this.changes.add(r),this.allChanges.delete(r)):(this.changed=!0,this.changes.add(r),this.allChanges.add(r)),this.parent&&this.parent.change(this.parentField)},e.prototype.mapIndex=function(e,t){"object"==typeof e&&(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){"object"==typeof e&&(this.deletedKeys[this.indexMap.get(e)]=!0,this.indexMap.delete(e))},e.prototype.isDeleted=function(e){return void 0!==this.deletedKeys[e]},e.prototype.mapIndexChange=function(e,t){"object"!=typeof e||this.indexChange.has(e)||this.indexChange.set(e,t)},e.prototype.getIndexChange=function(e){return this.indexChange&&this.indexChange.get(e)},e.prototype.deleteIndexChange=function(e){"object"==typeof 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),void 0!==e[n]&&this.change(n)}else for(var s=0,a=Object.keys(e);s0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[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}(this._view,this._offset,e);return this._offset+=e,t},r.prototype._bin=function(e){var t=this._buffer.slice(this._offset,this._offset+e);return this._offset+=e,t},r.prototype._parse=function(){var e,t=this._view.getUint8(this._offset++),n=0,r=0,i=0,o=0;if(t<192)return t<128?t:t<144?this._map(15&t):t<160?this._array(15&t):this._str(31&t);if(t>223)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")},t.default=function(e,t){void 0===t&&(t=0);var n=new r(e,t),i=n._parse();if(n._offset!==e.byteLength)throw new Error(e.byteLength-n._offset+" trailing bytes");return i}},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))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){var t=[],n=[],i=function e(t,n,r){var i=typeof r,o=0,s=0,a=0,c=0,u=0,h=0;if("string"===i){if((u=function(e){for(var t=0,n=0,r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}(r))<32)t.push(160|u),h=1;else if(u<256)t.push(217,u),h=2;else if(u<65536)t.push(218,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("String too long");t.push(219,u>>24,u>>16,u>>8,u),h=5}return n.push({_str:r,_length:u,_offset:t.length}),h+u}if("number"===i)return Math.floor(r)===r&&isFinite(r)?r>=0?r<128?(t.push(r),1):r<256?(t.push(204,r),2):r<65536?(t.push(205,r>>8,r),3):r<4294967296?(t.push(206,r>>24,r>>16,r>>8,r),5):(a=r/Math.pow(2,32)>>0,c=r>>>0,t.push(207,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),9):r>=-32?(t.push(r),1):r>=-128?(t.push(208,r),2):r>=-32768?(t.push(209,r>>8,r),3):r>=-2147483648?(t.push(210,r>>24,r>>16,r>>8,r),5):(a=Math.floor(r/Math.pow(2,32)),c=r>>>0,t.push(211,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),9):(t.push(203),n.push({_float:r,_length:8,_offset:t.length}),9);if("object"===i){if(null===r)return t.push(192),1;if(Array.isArray(r)){if((u=r.length)<16)t.push(144|u),h=1;else if(u<65536)t.push(220,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("Array too large");t.push(221,u>>24,u>>16,u>>8,u),h=5}for(o=0;o>>0,t.push(215,0,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),10}if(r instanceof ArrayBuffer){if((u=r.byteLength)<256)t.push(196,u),h=2;else if(u<65536)t.push(197,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("Buffer too large");t.push(198,u>>24,u>>16,u>>8,u),h=5}return n.push({_bin:r,_length:u,_offset:t.length}),h+u}if("function"==typeof r.toJSON)return e(t,n,r.toJSON());var l=[],p="",d=Object.keys(r);for(o=0,s=d.length;o>8,u),h=3;else{if(!(u<4294967296))throw new Error("Object too large");t.push(223,u>>24,u>>16,u>>8,u),h=5}for(o=0;o0&&(u=n[0]._offset);for(var h,f=0,l=0,p=0,d=t.length;p0){for(var n=0,r=this._enqueuedCalls;n2&&void 0!==arguments[2]?arguments[2]:{};i(this,e),this.url=t,this.protocols=n,this.reconnectEnabled=!0,this.listeners={},this.backoff=o(r.backoff||"exponential",r),this.backoff.onReady=this.onBackoffReady.bind(this),(void 0===r.connect||r.connect)&&this.open()}return r(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";Object.defineProperty(t,"__esModule",{value:!0}),t.createBackoff=function(e,t){return new i(r[e],t)};var r={exponential:function(e,t){return Math.floor(Math.random()*Math.pow(2,e)*t)},fibonacci:function(e,t){if(e>(r=1))for(var n=1,r=2,i=2;i0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[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(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=e.slice();return n.push(t),n}function i(e){if(Array.isArray(e)){for(var t=new Array(e.length),n=0;n=0;h--){var f=c[h],l=t[f];if(!n.hasOwnProperty(f)||void 0===n[f]&&void 0!==l&&!1===Array.isArray(n))o.push({operation:"remove",path:r(s,f)}),u=!0;else{var p=n[f];"object"==typeof l&&null!=l&&"object"==typeof p&&null!=p?e(l,p,o,r(s,f)):l!==p&&o.push({operation:"replace",path:r(s,f),value:p,previousValue:l})}}if(!u&&a.length==c.length)return;for(h=a.length-1;h>=0;h--){f=a[h];if(!t.hasOwnProperty(f)&&void 0!==n[f]){p=n[f];var d=r(s,f);"object"==typeof p&&null!=p&&e({},p,o,d),o.push({operation:"add",path:d,value:p})}}}(e,t,n,[]),n}},function(e,t,n){var r,i;r=this,i=function(){"use strict";var e={};function t(){this.a=0,this.b=0,this.i=0,this.z=new Array(16)}t.prototype.init=function(e,t){var n,r,i=0,o=0;for(n=0;n<16;n++)i=i+(r=e[t+n])&65535,o=o+(16-n)*r&65535,this.z[n]=r;this.a=65535&i,this.b=65535&o,this.i=0},t.prototype.next=function(e){var t=this.z[this.i];this.z[this.i]=e,this.i=this.i+1&15,this.a=this.a-t+e&65535,this.b=this.b-16*t+this.a&65535},t.prototype.value=function(){return(65535&this.a|(65535&this.b)<<16)>>>0};var n="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~".split("").map((function(e){return e.charCodeAt(0)})),r=[-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];function i(e){this.a=e,this.pos=0}function o(){this.a=[]}function s(e){var t,n;for(t=1,n=64;e>=n;t++,n<<=6);return t}function a(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}return i.prototype.haveBytes=function(){return this.posthis.a.length)throw new RangeError("out of bounds");return e},i.prototype.getChar=function(){return String.fromCharCode(this.getByte())},i.prototype.getInt=function(){for(var e,t=0;this.haveBytes()&&(e=r[127&this.getByte()])>=0;)t=(t<<6)+e;return this.pos--,t>>>0},o.prototype.toArray=function(){return this.a},o.prototype.putByte=function(e){this.a.push(255&e)},o.prototype.putChar=function(e){this.putByte(e.charCodeAt(0))},o.prototype.putInt=function(e){var t,r,i=[];if(0!==e){for(t=0;e>0;t++,e>>>=6)i.push(n[63&e]);for(r=t-1;r>=0;r--)this.putByte(i[r])}else this.putChar("0")},o.prototype.putArray=function(e,t,n){for(var r=t;r=0&&A-- >0;){var C,O,S,E,I,M,k;for(E=0,M=y=16*g,k=w+r;M=s(r-I)+s(C)+s(O)+3&&C>_&&(_=C,b=y-I,m=S),g=l[g]}if(_>0){m>0&&(i.putInt(m),i.putChar(":"),i.putArray(n,w,w+m),w+=m),w+=_,i.putInt(_),i.putChar("@"),i.putInt(b),i.putChar(","),b+_-1>h&&(h=b+_-1),_=0;break}if(w+r+16>=c){i.putInt(c-w),i.putChar(":"),i.putArray(n,w,w+c-w),w=c;break}v.next(n[w+r+16]),r++}return wr)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((s+=l)>r)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((!n||!1!==n.verifyChecksum)&&l!==a(d))throw new Error("bad checksum");if(s!==r)throw new Error("generated size does not match predicted size");return d;default:throw new Error("unknown delta operator")}}throw new Error("unterminated delta")},e},e.exports?e.exports=i():r.fossilDelta=i()},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(12),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,t){this.state?(new r.Reflection).decode(e,t):this.state=r.Reflection.decode(e)},e}();t.SchemaSerializer=i},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(){this.handlers=[]}return e.prototype.register=function(e,t){return void 0===t&&(t=!1),this.handlers.push(e),this},e.prototype.invoke=function(){for(var e=[],t=0;t=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 s=n(14),a=n(2),c=n(0),u=n(1),h=new s.Context,f=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),o([s.type("string",h)],t.prototype,"name",void 0),o([s.type("string",h)],t.prototype,"type",void 0),o([s.type("uint8",h)],t.prototype,"referencedType",void 0),t}(a.Schema);t.ReflectionField=f;var l=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.fields=new c.ArraySchema,t}return i(t,e),o([s.type("uint8",h)],t.prototype,"id",void 0),o([s.type([f],h)],t.prototype,"fields",void 0),t}(a.Schema);t.ReflectionType=l;var p=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.types=new c.ArraySchema,t}return i(t,e),t.encode=function(e){var n=e.constructor,r=new t;r.rootType=n._typeid;var i=function(e,t){for(var n in t){var i=new f;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)},o=n._context.types;for(var s in o){var a=new l;a.id=Number(s),i(a,o[s]._schema)}return r.encodeAll()},t.decode=function(e){var n=new s.Context,r=new t;r.decode(e);var o=r.types.reduce((function(e,t){return e[t.id]=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),t}(a.Schema),e}),{});r.types.forEach((function(e,t){e.fields.forEach((function(t){var r=o[e.id];if(void 0!==t.referencedType){var i=o[t.referencedType];i||(i=t.type.split(":")[1]),0===t.type.indexOf("array")?s.type([i],n)(r.prototype,t.name):0===t.type.indexOf("map")?s.type({map:i},n)(r.prototype,t.name):"ref"===t.type&&s.type(i,n)(r.prototype,t.name)}else s.type(t.type,n)(r.prototype,t.name)}))}));var h=o[r.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 c.ArraySchema:y?new u.MapSchema:d?new p:void 0}}return f},o([s.type([l],h)],t.prototype,"types",void 0),o([s.type("uint8",h)],t.prototype,"rootType",void 0),t}(a.Schema);t.Reflection=p}])})); \ No newline at end of file diff --git a/package.json b/package.json index 1b55a72..5d13207 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "colyseus.js", - "version": "0.13.0-alpha.9", + "version": "0.13.0-alpha.10", "description": "Multiplayer Game Client for the Browser", "keywords": [ "colyseus", diff --git a/src/Room.ts b/src/Room.ts index 02af68d..64006fb 100644 --- a/src/Room.ts +++ b/src/Room.ts @@ -105,7 +105,7 @@ export class Room { callback: (message: InstanceType) => void ) public onMessage( - type: T, + type: string | number, callback: (message: T) => void ) public onMessage( From 44f41317cb444d4027b7f55ed5697321b799e5e5 Mon Sep 17 00:00:00 2001 From: Endel Dreyer Date: Tue, 21 Apr 2020 22:41:38 +0300 Subject: [PATCH 09/11] fixes receiving wildcard messages. --- dist/index.html | 4 ++-- src/Room.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/index.html b/dist/index.html index 3c26b25..e952da0 100644 --- a/dist/index.html +++ b/dist/index.html @@ -35,8 +35,8 @@ function addListeners (room) { console.log('joined!'); - room.onMessage("*", (message) => { - console.log("*, message =>", message); + room.onMessage("*", (type, message) => { + console.log("received message:", type, "=>", message); }); room.onLeave(function() { diff --git a/src/Room.ts b/src/Room.ts index 64006fb..0acc832 100644 --- a/src/Room.ts +++ b/src/Room.ts @@ -266,7 +266,7 @@ export class Room { this.onMessageHandlers[messageType](message); } else if (this.onMessageHandlers['*']) { - (this.onMessageHandlers[messageType] as any)(type, message); + (this.onMessageHandlers['*'] as any)(type, message); } else { console.warn(`onMessage not registered for type '${type}'.`); From c49b0e0763f9239d107b49889ea7a5d02d7afb59 Mon Sep 17 00:00:00 2001 From: Endel Dreyer Date: Tue, 21 Apr 2020 22:43:28 +0300 Subject: [PATCH 10/11] fixes dist file to work on Web Workers (Construct 3) --- dist/colyseus.dev.js | 6972 ++++++++++++++++++++++-------------------- dist/colyseus.js | 2 +- package.json | 6 +- webpack.config.js | 1 + 4 files changed, 3642 insertions(+), 3339 deletions(-) diff --git a/dist/colyseus.dev.js b/dist/colyseus.dev.js index 836006f..447ea21 100644 --- a/dist/colyseus.dev.js +++ b/dist/colyseus.dev.js @@ -1,4 +1,4 @@ -/*! colyseus.js@0.11.7 */ +/*! colyseus.js@0.13.0-alpha.10 */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); @@ -8,7 +8,7 @@ exports["Colyseus"] = factory(); else root["Colyseus"] = factory(); -})(window, function() { +})(self || this, function() { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; @@ -92,7 +92,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ /******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 12); +/******/ return __webpack_require__(__webpack_require__.s = 15); /******/ }) /************************************************************************/ /******/ ([ @@ -101,6 +101,241 @@ return /******/ (function(modules) { // webpackBootstrap "use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var ArraySchema = /** @class */ (function (_super) { + __extends(ArraySchema, _super); + function ArraySchema() { + var items = []; + for (var _i = 0; _i < arguments.length; _i++) { + items[_i] = arguments[_i]; + } + var _this = _super.apply(this, items) || this; + Object.setPrototypeOf(_this, Object.create(ArraySchema.prototype)); + Object.defineProperties(_this, { + $sorting: { value: undefined, enumerable: false, writable: true }, + $changes: { value: undefined, enumerable: false, writable: true }, + onAdd: { value: undefined, enumerable: false, writable: true }, + onRemove: { value: undefined, enumerable: false, writable: true }, + onChange: { value: undefined, enumerable: false, writable: true }, + triggerAll: { + value: function () { + if (!_this.onAdd) { + return; + } + for (var i = 0; i < _this.length; i++) { + _this.onAdd(_this[i], i); + } + } + }, + toJSON: { + value: function () { + var arr = []; + for (var i = 0; i < _this.length; i++) { + var objAt = _this[i]; + arr.push((typeof (objAt.toJSON) === "function") + ? objAt.toJSON() + : objAt); + } + return arr; + } + }, + clone: { + value: function (isDecoding) { + var cloned; + if (isDecoding) { + cloned = ArraySchema.of.apply(ArraySchema, _this); + cloned.onAdd = _this.onAdd; + cloned.onRemove = _this.onRemove; + cloned.onChange = _this.onChange; + } + else { + cloned = new (ArraySchema.bind.apply(ArraySchema, __spreadArrays([void 0], _this.map(function (item) { + if (typeof (item) === "object") { + return item.clone(); + } + else { + return item; + } + }))))(); + } + return cloned; + } + } + }); + return _this; + } + Object.defineProperty(ArraySchema, Symbol.species, { + get: function () { return ArraySchema; }, + enumerable: true, + configurable: true + }); + ArraySchema.prototype.sort = function (compareFn) { + this.$sorting = true; + _super.prototype.sort.call(this, compareFn); + if (this.$changes) { // allow to .slice() + .sort() + var changes = Array.from(this.$changes.changes); + for (var _i = 0, changes_1 = changes; _i < changes_1.length; _i++) { + var key = changes_1[_i]; + // track index change + var previousIndex = this.$changes.getIndex(this[key]); + if (previousIndex !== undefined) { + this.$changes.mapIndexChange(this[key], previousIndex); + } + this.$changes.mapIndex(this[key], key); + } + } + this.$sorting = false; + return this; + }; + ArraySchema.prototype.filter = function (callbackfn, thisArg) { + var filtered = _super.prototype.filter.call(this, callbackfn); + // TODO: apply removed items on $changes + filtered.$changes = this.$changes; + return filtered; + }; + ArraySchema.prototype.splice = function (start, deleteCount) { + var insert = []; + for (var _i = 2; _i < arguments.length; _i++) { + insert[_i - 2] = arguments[_i]; + } + var removedItems = Array.prototype.splice.apply(this, arguments); + var movedItems = Array.prototype.filter.call(this, function (item, idx) { + return idx >= start + deleteCount - 1; + }); + removedItems.map(function (removedItem) { + var $changes = removedItem && removedItem.$changes; + // If the removed item is a schema we need to update it. + if ($changes) { + $changes.parent.deleteIndex(removedItem); + delete $changes.parent; + } + }); + movedItems.forEach(function (movedItem) { + // If the moved item is a schema we need to update it. + var $changes = movedItem && movedItem.$changes; + if ($changes) { + // Update current index in parent, so subsequent changes in + // this item's properties are correctly reflected. + $changes.parentField--; + } + }); + return removedItems; + }; + return ArraySchema; +}(Array)); +exports.ArraySchema = ArraySchema; +//# sourceMappingURL=ArraySchema.js.map + +/***/ }), +/* 1 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +var MapSchema = /** @class */ (function () { + function MapSchema(obj) { + var _this = this; + if (obj === void 0) { obj = {}; } + for (var key in obj) { + this[key] = obj[key]; + } + Object.defineProperties(this, { + $changes: { value: undefined, enumerable: false, writable: true }, + onAdd: { value: undefined, enumerable: false, writable: true }, + onRemove: { value: undefined, enumerable: false, writable: true }, + onChange: { value: undefined, enumerable: false, writable: true }, + clone: { + value: function (isDecoding) { + var cloned; + if (isDecoding) { + // client-side + cloned = Object.assign(new MapSchema(), _this); + cloned.onAdd = _this.onAdd; + cloned.onRemove = _this.onRemove; + cloned.onChange = _this.onChange; + } + else { + // server-side + var cloned_1 = new MapSchema(); + for (var key in _this) { + if (typeof (_this[key]) === "object") { + cloned_1[key] = _this[key].clone(); + } + else { + cloned_1[key] = _this[key]; + } + } + } + return cloned; + } + }, + triggerAll: { + value: function () { + if (!_this.onAdd) { + return; + } + for (var key in _this) { + _this.onAdd(_this[key], key); + } + } + }, + toJSON: { + value: function () { + var map = {}; + for (var key in _this) { + map[key] = (typeof (_this[key].toJSON) === "function") + ? _this[key].toJSON() + : _this[key]; + } + return map; + } + }, + _indexes: { value: new Map(), enumerable: false, writable: true }, + _updateIndexes: { + value: function (allKeys) { + var index = 0; + var indexes = new Map(); + for (var _i = 0, allKeys_1 = allKeys; _i < allKeys_1.length; _i++) { + var key = allKeys_1[_i]; + indexes.set(key, index++); + } + _this._indexes = indexes; + } + }, + }); + } + return MapSchema; +}()); +exports.MapSchema = MapSchema; +//# sourceMappingURL=MapSchema.js.map + +/***/ }), +/* 2 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || @@ -115,12 +350,13 @@ var __extends = (this && this.__extends) || (function () { }; })(); Object.defineProperty(exports, "__esModule", { value: true }); -var spec_1 = __webpack_require__(9); -var encode = __webpack_require__(31); -var decode = __webpack_require__(32); -var ArraySchema_1 = __webpack_require__(1); -var MapSchema_1 = __webpack_require__(2); -var ChangeTree_1 = __webpack_require__(10); +var spec_1 = __webpack_require__(10); +var encode = __webpack_require__(8); +var decode = __webpack_require__(9); +var ArraySchema_1 = __webpack_require__(0); +var MapSchema_1 = __webpack_require__(1); +var ChangeTree_1 = __webpack_require__(13); +var EventEmitter_1 = __webpack_require__(34); var EncodeSchemaError = /** @class */ (function (_super) { __extends(EncodeSchemaError, _super); function EncodeSchemaError() { @@ -196,6 +432,11 @@ var Schema = /** @class */ (function () { enumerable: false, writable: true }, + $listeners: { + value: {}, + enumerable: false, + writable: true + }, }); var descriptors = this._descriptors; if (descriptors) { @@ -240,6 +481,17 @@ var Schema = /** @class */ (function () { enumerable: true, configurable: true }); + Schema.prototype.listen = function (attr, callback) { + var _this = this; + if (!this.$listeners[attr]) { + this.$listeners[attr] = new EventEmitter_1.EventEmitter(); + } + this.$listeners[attr].register(callback); + // return un-register callback. + return function () { + return _this.$listeners[attr].remove(callback); + }; + }; Schema.prototype.decode = function (bytes, it) { if (it === void 0) { it = { offset: 0 }; } var changes = []; @@ -260,7 +512,6 @@ var Schema = /** @class */ (function () { var _field = "_" + field; var type = schema[field]; var value = void 0; - var change = void 0; // for triggering onChange var hasChange = false; if (!field) { return "continue"; @@ -276,16 +527,16 @@ var Schema = /** @class */ (function () { } else if (Array.isArray(type)) { type = type[0]; - change = []; var valueRef_1 = this_1[_field] || new ArraySchema_1.ArraySchema(); value = valueRef_1.clone(true); var newLength_1 = decode.number(bytes, it); var numChanges = Math.min(decode.number(bytes, it), newLength_1); - hasChange = (numChanges > 0); + var hasRemoval = (value.length > newLength_1); + hasChange = (numChanges > 0) || hasRemoval; // FIXME: this may not be reliable. possibly need to encode this variable during serialization var hasIndexChange = false; // ensure current array has the same length as encoded one - if (value.length > newLength_1) { + if (hasRemoval) { // decrease removed items from number of changes. // no need to iterate through them, as they're going to be removed. Array.prototype.splice.call(value, newLength_1).forEach(function (itemRemoved, i) { @@ -355,7 +606,6 @@ var Schema = /** @class */ (function () { Schema.onError(e); } } - change.push(value[newIndex]); } } else if (type.map) { @@ -448,12 +698,14 @@ var Schema = /** @class */ (function () { } else { value = decodePrimitiveType(type, bytes, it); - hasChange = true; + // FIXME: should not even have encoded if value haven't changed in the first place! + // check FilterTest.ts: "should not trigger `onChange` if field haven't changed" + hasChange = (value !== this_1[_field]); } - if (hasChange && this_1.onChange) { + if (hasChange && (this_1.onChange || this_1.$listeners[field])) { changes.push({ field: field, - value: change || value, + value: value, previousValue: this_1[_field] }); } @@ -465,14 +717,7 @@ var Schema = /** @class */ (function () { if (state_1 === "break") break; } - if (this.onChange && changes.length > 0) { - try { - this.onChange(changes); - } - catch (e) { - Schema.onError(e); - } - } + this._triggerChanges(changes); return this; }; Schema.prototype.encode = function (root, encodeAll, client, bytes) { @@ -489,7 +734,7 @@ var Schema = /** @class */ (function () { var indexes = this._indexes; var fieldsByIndex = this._fieldsByIndex; var filters = this._filters; - var changes = Array.from((encodeAll || client) + var changes = Array.from((encodeAll) // || client ? this.$changes.allChanges : this.$changes.changes).sort(); var _loop_2 = function (i, l) { @@ -526,10 +771,16 @@ var Schema = /** @class */ (function () { } else if (Array.isArray(type)) { var $changes = value.$changes; + if (client && filter) { + // skip if not allowed by custom filter + if (!filter.call(this_2, client, value, root)) { + return "continue"; + } + } encode.number(bytes, fieldIndex); - // total of items in the array + // total number of items in the array encode.number(bytes, value.length); - var arrayChanges = Array.from((encodeAll || client) + var arrayChanges = Array.from((encodeAll) // || client ? $changes.allChanges : $changes.changes) .filter(function (index) { return _this[_field][index] !== undefined; }) @@ -545,12 +796,15 @@ var Schema = /** @class */ (function () { for (var j = 0; j < numChanges; j++) { var index = arrayChanges[j]; var item = this_2[_field][index]; - if (client && filter) { - // skip if not allowed by custom filter - if (!filter.call(this_2, client, item, root)) { - continue; - } - } + /** + * TODO: filter array by items instead of the whole object + */ + // if (client && filter) { + // // skip if not allowed by custom filter + // if (!filter.call(this, client, item, root)) { + // continue; + // } + // } if (isChildSchema) { // is array of Schema encode.number(bytes, index); if (!encodeAll) { @@ -564,21 +818,27 @@ var Schema = /** @class */ (function () { this_2.tryEncodeTypeId(bytes, type[0], item.constructor); item.encode(root, encodeAll, client, bytes); } - else if (item !== undefined) { + else if (item !== undefined) { // is array of primitives encode.number(bytes, index); encodePrimitiveType(type[0], bytes, item, this_2, field); } } - if (!encodeAll) { + if (!encodeAll && !client) { $changes.discard(); } } else if (type.map) { var $changes = value.$changes; + if (client && filter) { + // skip if not allowed by custom filter + if (!filter.call(this_2, client, value, root)) { + return "continue"; + } + } // encode Map of type encode.number(bytes, fieldIndex); // TODO: during `encodeAll`, removed entries are not going to be encoded - var keys = Array.from((encodeAll || client) + var keys = Array.from((encodeAll) // || client ? $changes.allChanges : $changes.changes); encode.number(bytes, keys.length); @@ -592,12 +852,15 @@ var Schema = /** @class */ (function () { var key = keys[i_1]; var item = this_2[_field][key]; var mapItemIndex = undefined; - if (client && filter) { - // skip if not allowed by custom filter - if (!filter.call(this_2, client, item, root)) { - continue; - } - } + /** + * TODO: filter map by items instead of the whole object + */ + // if (client && filter) { + // // skip if not allowed by custom filter + // if (!filter.call(this, client, item, root)) { + // continue; + // } + // } if (encodeAll) { if (item === undefined) { // previously deleted items are skipped during `encodeAll` @@ -644,13 +907,11 @@ var Schema = /** @class */ (function () { encodePrimitiveType(type.map, bytes, item, this_2, field); } } - if (!encodeAll) { + if (!encodeAll && !client) { $changes.discard(); // TODO: track array/map indexes per client (for filtering)? - if (!client) { - // TODO: do not iterate though all MapSchema indexes here. - this_2[_field]._updateIndexes(previousKeys); - } + // TODO: do not iterate though all MapSchema indexes here. + this_2[_field]._updateIndexes(previousKeys); } } else { @@ -701,9 +962,6 @@ var Schema = /** @class */ (function () { return cloned; }; Schema.prototype.triggerAll = function () { - if (!this.onChange) { - return; - } var changes = []; var schema = this._schema; for (var field in schema) { @@ -716,7 +974,7 @@ var Schema = /** @class */ (function () { } } try { - this.onChange(changes); + this._triggerChanges(changes); } catch (e) { Schema.onError(e); @@ -735,9 +993,49 @@ var Schema = /** @class */ (function () { } return obj; }; - Schema.prototype._encodeEndOfStructure = function (instance, root, bytes) { - if (instance !== root) { - bytes.push(spec_1.END_OF_STRUCTURE); + Schema.prototype.discardAllChanges = function () { + var schema = this._schema; + var changes = Array.from(this.$changes.changes); + var fieldsByIndex = this._fieldsByIndex; + for (var index in changes) { + var field = fieldsByIndex[index]; + var type = schema[field]; + var value = this[field]; + // skip unchagned fields + if (value === undefined) { + continue; + } + if (type._schema) { + value.discardAllChanges(); + } + else if (Array.isArray(type)) { + for (var i = 0, l = value.length; i < l; i++) { + var index_1 = value[i]; + var item = this["_" + field][index_1]; + if (typeof (type[0]) !== "string" && item) { // is array of Schema + item.discardAllChanges(); + } + } + value.$changes.discard(); + } + else if (type.map) { + var keys = value; + var mapKeys = Object.keys(this["_" + field]); + for (var i = 0; i < keys.length; i++) { + var key = mapKeys[keys[i]] || keys[i]; + var item = this["_" + field][key]; + if (item instanceof Schema && item) { + item.discardAllChanges(); + } + } + value.$changes.discard(); + } + } + this.$changes.discard(); + }; + Schema.prototype._encodeEndOfStructure = function (instance, root, bytes) { + if (instance !== root) { + bytes.push(spec_1.END_OF_STRUCTURE); } }; Schema.prototype.tryEncodeTypeId = function (bytes, type, targetType) { @@ -756,259 +1054,37 @@ var Schema = /** @class */ (function () { return new type(); } }; - return Schema; -}()); -exports.Schema = Schema; -//# sourceMappingURL=Schema.js.map - -/***/ }), -/* 1 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __spreadArrays = (this && this.__spreadArrays) || function () { - for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; - for (var r = Array(s), k = 0, i = 0; i < il; i++) - for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) - r[k] = a[j]; - return r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var ArraySchema = /** @class */ (function (_super) { - __extends(ArraySchema, _super); - function ArraySchema() { - var items = []; - for (var _i = 0; _i < arguments.length; _i++) { - items[_i] = arguments[_i]; - } - var _this = _super.apply(this, items) || this; - Object.setPrototypeOf(_this, Object.create(ArraySchema.prototype)); - Object.defineProperties(_this, { - $sorting: { value: undefined, enumerable: false, writable: true }, - $changes: { value: undefined, enumerable: false, writable: true }, - onAdd: { value: undefined, enumerable: false, writable: true }, - onRemove: { value: undefined, enumerable: false, writable: true }, - onChange: { value: undefined, enumerable: false, writable: true }, - triggerAll: { - value: function () { - if (!_this.onAdd) { - return; + Schema.prototype._triggerChanges = function (changes) { + if (changes.length > 0) { + for (var i = 0; i < changes.length; i++) { + var change = changes[i]; + var listener = this.$listeners[change.field]; + if (listener) { + try { + listener.invoke(change.value, change.previousValue); } - for (var i = 0; i < _this.length; i++) { - _this.onAdd(_this[i], i); + catch (e) { + Schema.onError(e); } } - }, - toJSON: { - value: function () { - var arr = []; - for (var i = 0; i < _this.length; i++) { - var objAt = _this[i]; - arr.push((typeof (objAt.toJSON) === "function") - ? objAt.toJSON() - : objAt); - } - return arr; + } + if (this.onChange) { + try { + this.onChange(changes); } - }, - clone: { - value: function (isDecoding) { - var cloned; - if (isDecoding) { - cloned = ArraySchema.of.apply(ArraySchema, _this); - cloned.onAdd = _this.onAdd; - cloned.onRemove = _this.onRemove; - cloned.onChange = _this.onChange; - } - else { - cloned = new (ArraySchema.bind.apply(ArraySchema, __spreadArrays([void 0], _this.map(function (item) { - if (typeof (item) === "object") { - return item.clone(); - } - else { - return item; - } - }))))(); - } - return cloned; + catch (e) { + Schema.onError(e); } } - }); - return _this; - } - Object.defineProperty(ArraySchema, Symbol.species, { - get: function () { return ArraySchema; }, - enumerable: true, - configurable: true - }); - ArraySchema.prototype.sort = function (compareFn) { - this.$sorting = true; - _super.prototype.sort.call(this, compareFn); - var changes = Array.from(this.$changes.changes); - for (var _i = 0, changes_1 = changes; _i < changes_1.length; _i++) { - var key = changes_1[_i]; - // track index change - var previousIndex = this.$changes.getIndex(this[key]); - if (previousIndex !== undefined) { - this.$changes.mapIndexChange(this[key], previousIndex); - } - this.$changes.mapIndex(this[key], key); - } - this.$sorting = false; - return this; - }; - ArraySchema.prototype.filter = function (callbackfn, thisArg) { - var filtered = _super.prototype.filter.call(this, callbackfn); - // TODO: apply removed items on $changes - filtered.$changes = this.$changes; - return filtered; - }; - ArraySchema.prototype.splice = function (start, deleteCount) { - var insert = []; - for (var _i = 2; _i < arguments.length; _i++) { - insert[_i - 2] = arguments[_i]; } - var removedItems = Array.prototype.splice.apply(this, arguments); - var movedItems = Array.prototype.filter.call(this, function (item, idx) { - return idx >= start + deleteCount - 1; - }); - removedItems.map(function (removedItem) { - // If the removed item is a schema we need to update it. - if (removedItem && removedItem.$changes) { - removedItem.$changes.parent.deleteIndex(removedItem); - removedItem.$changes.parent.deleteIndexChange(removedItem); - delete removedItem.$changes.parent; - } - }); - movedItems.forEach(function (movedItem) { - // If the moved item is a schema we need to update it. - if (movedItem && movedItem.$changes) { - movedItem.$changes.parentField--; - } - }); - return removedItems; }; - return ArraySchema; -}(Array)); -exports.ArraySchema = ArraySchema; -//# sourceMappingURL=ArraySchema.js.map - -/***/ }), -/* 2 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -Object.defineProperty(exports, "__esModule", { value: true }); -var MapSchema = /** @class */ (function () { - function MapSchema(obj) { - var _this = this; - if (obj === void 0) { obj = {}; } - for (var key in obj) { - this[key] = obj[key]; - } - Object.defineProperties(this, { - $changes: { value: undefined, enumerable: false, writable: true }, - onAdd: { value: undefined, enumerable: false, writable: true }, - onRemove: { value: undefined, enumerable: false, writable: true }, - onChange: { value: undefined, enumerable: false, writable: true }, - clone: { - value: function (isDecoding) { - var cloned; - if (isDecoding) { - // client-side - cloned = Object.assign(new MapSchema(), _this); - cloned.onAdd = _this.onAdd; - cloned.onRemove = _this.onRemove; - cloned.onChange = _this.onChange; - } - else { - // server-side - var cloned_1 = new MapSchema(); - for (var key in _this) { - if (typeof (_this[key]) === "object") { - cloned_1[key] = _this[key].clone(); - } - else { - cloned_1[key] = _this[key]; - } - } - } - return cloned; - } - }, - triggerAll: { - value: function () { - if (!_this.onAdd) { - return; - } - for (var key in _this) { - _this.onAdd(_this[key], key); - } - } - }, - toJSON: { - value: function () { - var map = {}; - for (var key in _this) { - map[key] = (typeof (_this[key].toJSON) === "function") - ? _this[key].toJSON() - : _this[key]; - } - return map; - } - }, - _indexes: { value: new Map(), enumerable: false, writable: true }, - _updateIndexes: { - value: function (allKeys) { - var index = 0; - var indexes = new Map(); - for (var _i = 0, allKeys_1 = allKeys; _i < allKeys_1.length; _i++) { - var key = allKeys_1[_i]; - indexes.set(key, index++); - } - _this._indexes = indexes; - } - }, - }); - } - return MapSchema; + return Schema; }()); -exports.MapSchema = MapSchema; -//# sourceMappingURL=MapSchema.js.map +exports.Schema = Schema; +//# sourceMappingURL=Schema.js.map /***/ }), /* 3 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var decode_1 = __importDefault(__webpack_require__(15)); -var encode_1 = __importDefault(__webpack_require__(16)); -exports.decode = decode_1.default; -exports.encode = encode_1.default; - - -/***/ }), -/* 4 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; @@ -1033,13 +1109,14 @@ function send(method, uri, opts) { var req = new XMLHttpRequest; var headers = opts.headers || {}; - req.timeout = opts.timeout; + // IE compatible + if (opts.timeout) req.timeout = opts.timeout; req.ontimeout = req.onerror = function (err) { err.timeout = err.type == 'timeout'; rej(err); } - req.open(method, uri); + req.open(method, uri.href || uri); req.onload = function () { arr = req.getAllResponseHeaders().trim().split(/[\r\n]+/); @@ -1063,11 +1140,13 @@ function send(method, uri, opts) { (req.status >= 400 ? rej : res)(req); }; - if ((str = opts.body) && /Array|Object/.test(str.constructor)) { + if ((str = opts.body) && typeof str == 'object') { headers['content-type'] = 'application/json'; str = JSON.stringify(str); } + req.withCredentials = !!opts.withCredentials; + for (k in headers) { req.setRequestHeader(k, headers[k]); } @@ -1084,7 +1163,7 @@ var put = send.bind(send, 'PUT'); /***/ }), -/* 5 */ +/* 4 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -1097,21 +1176,23 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", { value: true }); -var msgpack = __importStar(__webpack_require__(3)); -var strong_events_1 = __webpack_require__(17); -var Connection_1 = __webpack_require__(18); +var msgpack = __importStar(__webpack_require__(5)); +var strong_events_1 = __webpack_require__(21); +var Connection_1 = __webpack_require__(22); var Serializer_1 = __webpack_require__(6); var Protocol_1 = __webpack_require__(7); +var encode = __importStar(__webpack_require__(8)); +var decode = __importStar(__webpack_require__(9)); var Room = /** @class */ (function () { function Room(name, rootSchema) { var _this = this; // Public signals this.onJoin = strong_events_1.createSignal(); this.onStateChange = strong_events_1.createSignal(); - this.onMessage = strong_events_1.createSignal(); this.onError = strong_events_1.createSignal(); this.onLeave = strong_events_1.createSignal(); this.hasJoined = false; + this.onMessageHandlers = {}; this.id = null; this.name = name; if (rootSchema) { @@ -1123,7 +1204,7 @@ var Room = /** @class */ (function () { // TODO: remove default serializer. it should arrive only after JOIN_ROOM. this.serializer = new (Serializer_1.getSerializer("fossil-delta")); } - this.onError(function (message) { return console.error(message); }); + this.onError(function (code, message) { return console.error("colyseus.js - onError => (" + code + ") " + message); }); this.onLeave(function () { return _this.removeAllListeners(); }); } Room.prototype.connect = function (endpoint) { @@ -1134,14 +1215,14 @@ var Room = /** @class */ (function () { this.connection.onclose = function (e) { if (!_this.hasJoined) { console.error("Room connection was closed unexpectedly (" + e.code + "): " + e.reason); - _this.onError.invoke(e.reason); + _this.onError.invoke(e.code, e.reason); return; } _this.onLeave.invoke(e.code); }; this.connection.onerror = function (e) { console.warn("Room, onError (" + e.code + "): " + e.reason); - _this.onError.invoke(e.reason); + _this.onError.invoke(e.code, e.reason); }; this.connection.open(); }; @@ -1159,8 +1240,29 @@ var Room = /** @class */ (function () { this.onLeave.invoke(4000); // "consented" code } }; - Room.prototype.send = function (data) { - this.connection.send([Protocol_1.Protocol.ROOM_DATA, data]); + Room.prototype.onMessage = function (type, callback) { + this.onMessageHandlers[this.getMessageHandlerKey(type)] = callback; + return this; + }; + Room.prototype.send = function (type, message) { + var initialBytes = [Protocol_1.Protocol.ROOM_DATA]; + if (typeof (type) === "string") { + encode.string(initialBytes, type); + } + else { + encode.number(initialBytes, type); + } + var arr; + if (message !== undefined) { + var encoded = msgpack.encode(message); + arr = new Uint8Array(initialBytes.length + encoded.byteLength); + arr.set(new Uint8Array(initialBytes), 0); + arr.set(new Uint8Array(encoded), initialBytes.length); + } + else { + arr = new Uint8Array(initialBytes); + } + this.connection.send(arr.buffer); }; Object.defineProperty(Room.prototype, "state", { get: function () { @@ -1173,7 +1275,7 @@ var Room = /** @class */ (function () { // this method is useful only for FossilDeltaSerializer Room.prototype.listen = function (segments, callback, immediate) { if (this.serializerId === "schema") { - console.error("'" + this.serializerId + "' serializer doesn't support .listen() method."); + console.error("'" + this.serializerId + "' serializer doesn't support .listen() method here."); return; } else if (!this.serializerId) { @@ -1192,64 +1294,66 @@ var Room = /** @class */ (function () { } this.onJoin.clear(); this.onStateChange.clear(); - this.onMessage.clear(); this.onError.clear(); this.onLeave.clear(); }; Room.prototype.onMessageCallback = function (event) { - if (!this.previousCode) { - var view = new DataView(event.data); - var code = view.getUint8(0); - if (code === Protocol_1.Protocol.JOIN_ROOM) { - var offset = 1; - this.serializerId = Protocol_1.utf8Read(view, offset); - offset += Protocol_1.utf8Length(this.serializerId); - // get serializer implementation - var serializer = Serializer_1.getSerializer(this.serializerId); - if (!serializer) { - throw new Error("missing serializer: " + this.serializerId); - } - // TODO: remove this check - if (this.serializerId !== "fossil-delta" && !this.rootSchema) { - this.serializer = new serializer(); - } - if (view.buffer.byteLength > offset && this.serializer.handshake) { - var bytes = Array.from(new Uint8Array(view.buffer.slice(offset))); - this.serializer.handshake(bytes); - } - this.hasJoined = true; - this.onJoin.invoke(); - } - else if (code === Protocol_1.Protocol.JOIN_ERROR) { - this.onError.invoke(Protocol_1.utf8Read(view, 1)); - } - else if (code === Protocol_1.Protocol.LEAVE_ROOM) { - this.leave(); + var bytes = Array.from(new Uint8Array(event.data)); + var code = bytes[0]; + if (code === Protocol_1.Protocol.JOIN_ROOM) { + var offset = 1; + this.serializerId = Protocol_1.utf8Read(bytes, offset); + offset += Protocol_1.utf8Length(this.serializerId); + // get serializer implementation + var serializer = Serializer_1.getSerializer(this.serializerId); + if (!serializer) { + throw new Error("missing serializer: " + this.serializerId); } - else if (code === Protocol_1.Protocol.ROOM_DATA_SCHEMA) { - var bytes = Array.from(new Uint8Array(event.data)); - var context_1 = this.serializer.getState().constructor._context; - var type = context_1.get(bytes[1]); - var message = new type(); - message.decode(bytes, { offset: 2 }); - this.onMessage.invoke(message); + // TODO: remove this check + if (this.serializerId !== "fossil-delta" && !this.rootSchema) { + this.serializer = new serializer(); } - else { - this.previousCode = code; + if (bytes.length > offset && this.serializer.handshake) { + this.serializer.handshake(bytes, { offset: 1 }); } + this.hasJoined = true; + this.onJoin.invoke(); + // acknowledge successfull JOIN_ROOM + this.connection.send([Protocol_1.Protocol.JOIN_ROOM]); } - else { - if (this.previousCode === Protocol_1.Protocol.ROOM_STATE) { - // TODO: improve here! - this.setState(Array.from(new Uint8Array(event.data))); - } - else if (this.previousCode === Protocol_1.Protocol.ROOM_STATE_PATCH) { - this.patch(Array.from(new Uint8Array(event.data))); - } - else if (this.previousCode === Protocol_1.Protocol.ROOM_DATA) { - this.onMessage.invoke(msgpack.decode(event.data)); - } - this.previousCode = undefined; + else if (code === Protocol_1.Protocol.ERROR) { + var it_1 = { offset: 1 }; + var code_1 = decode.number(bytes, it_1); + var message = decode.string(bytes, it_1); + this.onError.invoke(code_1, message); + } + else if (code === Protocol_1.Protocol.LEAVE_ROOM) { + this.leave(); + } + else if (code === Protocol_1.Protocol.ROOM_DATA_SCHEMA) { + var context_1 = this.serializer.getState().constructor._context; + var type = context_1.get(bytes[1]); + var message = new type(); + message.decode(bytes, { offset: 2 }); + this.dispatchMessage(type, message); + } + else if (code === Protocol_1.Protocol.ROOM_STATE) { + bytes.shift(); // drop `code` byte + this.setState(bytes); + } + else if (code === Protocol_1.Protocol.ROOM_STATE_PATCH) { + bytes.shift(); // drop `code` byte + this.patch(bytes); + } + else if (code === Protocol_1.Protocol.ROOM_DATA) { + var it_2 = { offset: 1 }; + var type = (decode.stringCheck(bytes, it_2)) + ? decode.string(bytes, it_2) + : decode.number(bytes, it_2); + var message = (bytes.length > it_2.offset) + ? msgpack.decode(event.data, it_2.offset) + : undefined; + this.dispatchMessage(type, message); } }; Room.prototype.setState = function (encodedState) { @@ -1260,11 +1364,50 @@ var Room = /** @class */ (function () { this.serializer.patch(binaryPatch); this.onStateChange.invoke(this.serializer.getState()); }; + Room.prototype.dispatchMessage = function (type, message) { + var messageType = this.getMessageHandlerKey(type); + if (this.onMessageHandlers[messageType]) { + this.onMessageHandlers[messageType](message); + } + else if (this.onMessageHandlers['*']) { + this.onMessageHandlers['*'](type, message); + } + else { + console.warn("onMessage not registered for type '" + type + "'."); + } + }; + Room.prototype.getMessageHandlerKey = function (type) { + switch (typeof (type)) { + // typeof Schema + case "function": return "$" + type._typeid; + // string + case "string": return type; + // number + case "number": return "i" + type; + default: throw new Error("invalid message type."); + } + }; return Room; }()); exports.Room = Room; +/***/ }), +/* 5 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var decode_1 = __importDefault(__webpack_require__(19)); +var encode_1 = __importDefault(__webpack_require__(20)); +exports.decode = decode_1.default; +exports.encode = encode_1.default; + + /***/ }), /* 6 */ /***/ (function(module, exports, __webpack_require__) { @@ -1294,39 +1437,50 @@ Object.defineProperty(exports, "__esModule", { value: true }); var Protocol; (function (Protocol) { // Room-related (10~19) + Protocol[Protocol["HANDSHAKE"] = 9] = "HANDSHAKE"; Protocol[Protocol["JOIN_ROOM"] = 10] = "JOIN_ROOM"; - Protocol[Protocol["JOIN_ERROR"] = 11] = "JOIN_ERROR"; + Protocol[Protocol["ERROR"] = 11] = "ERROR"; Protocol[Protocol["LEAVE_ROOM"] = 12] = "LEAVE_ROOM"; Protocol[Protocol["ROOM_DATA"] = 13] = "ROOM_DATA"; Protocol[Protocol["ROOM_STATE"] = 14] = "ROOM_STATE"; Protocol[Protocol["ROOM_STATE_PATCH"] = 15] = "ROOM_STATE_PATCH"; Protocol[Protocol["ROOM_DATA_SCHEMA"] = 16] = "ROOM_DATA_SCHEMA"; })(Protocol = exports.Protocol || (exports.Protocol = {})); +var ErrorCode; +(function (ErrorCode) { + ErrorCode[ErrorCode["MATCHMAKE_NO_HANDLER"] = 4210] = "MATCHMAKE_NO_HANDLER"; + ErrorCode[ErrorCode["MATCHMAKE_INVALID_CRITERIA"] = 4211] = "MATCHMAKE_INVALID_CRITERIA"; + ErrorCode[ErrorCode["MATCHMAKE_INVALID_ROOM_ID"] = 4212] = "MATCHMAKE_INVALID_ROOM_ID"; + ErrorCode[ErrorCode["MATCHMAKE_UNHANDLED"] = 4213] = "MATCHMAKE_UNHANDLED"; + ErrorCode[ErrorCode["MATCHMAKE_EXPIRED"] = 4214] = "MATCHMAKE_EXPIRED"; + ErrorCode[ErrorCode["AUTH_FAILED"] = 4215] = "AUTH_FAILED"; + ErrorCode[ErrorCode["APPLICATION_ERROR"] = 4216] = "APPLICATION_ERROR"; +})(ErrorCode = exports.ErrorCode || (exports.ErrorCode = {})); function utf8Read(view, offset) { - var length = view.getUint8(offset++); + var length = view[offset++]; var string = '', chr = 0; for (var i = offset, end = offset + length; i < end; i++) { - var byte = view.getUint8(i); + var byte = view[i]; if ((byte & 0x80) === 0x00) { string += String.fromCharCode(byte); continue; } if ((byte & 0xe0) === 0xc0) { string += String.fromCharCode(((byte & 0x1f) << 6) | - (view.getUint8(++i) & 0x3f)); + (view[++i] & 0x3f)); continue; } if ((byte & 0xf0) === 0xe0) { string += String.fromCharCode(((byte & 0x0f) << 12) | - ((view.getUint8(++i) & 0x3f) << 6) | - ((view.getUint8(++i) & 0x3f) << 0)); + ((view[++i] & 0x3f) << 6) | + ((view[++i] & 0x3f) << 0)); continue; } if ((byte & 0xf8) === 0xf0) { chr = ((byte & 0x07) << 18) | - ((view.getUint8(++i) & 0x3f) << 12) | - ((view.getUint8(++i) & 0x3f) << 6) | - ((view.getUint8(++i) & 0x3f) << 0); + ((view[++i] & 0x3f) << 12) | + ((view[++i] & 0x3f) << 6) | + ((view[++i] & 0x3f) << 0); if (chr >= 0x010000) { // surrogate pair chr -= 0x010000; string += String.fromCharCode((chr >>> 10) + 0xD800, (chr & 0x3FF) + 0xDC00); @@ -1373,3211 +1527,3357 @@ exports.utf8Length = utf8Length; "use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; - result["default"] = mod; - return result; -}; +/** + * Copyright (c) 2018 Endel Dreyer + * Copyright (c) 2014 Ion Drive Software Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE + */ Object.defineProperty(exports, "__esModule", { value: true }); -var http = __importStar(__webpack_require__(4)); -var Storage_1 = __webpack_require__(22); -var TOKEN_STORAGE = "colyseus-auth-token"; -var Platform; -(function (Platform) { - Platform["ios"] = "ios"; - Platform["android"] = "android"; -})(Platform = exports.Platform || (exports.Platform = {})); -var Auth = /** @class */ (function () { - function Auth(endpoint) { - var _this = this; - this._id = undefined; - this.username = undefined; - this.displayName = undefined; - this.avatarUrl = undefined; - this.isAnonymous = undefined; - this.email = undefined; - this.lang = undefined; - this.location = undefined; - this.timezone = undefined; - this.metadata = undefined; - this.devices = undefined; - this.facebookId = undefined; - this.twitterId = undefined; - this.googleId = undefined; - this.gameCenterId = undefined; - this.steamId = undefined; - this.friendIds = undefined; - this.blockedUserIds = undefined; - this.createdAt = undefined; - this.updatedAt = undefined; - // auth token - this.token = undefined; - this.endpoint = endpoint.replace("ws", "http"); - Storage_1.getItem(TOKEN_STORAGE, function (token) { return _this.token = token; }); +/** + * msgpack implementation highly based on notepack.io + * https://github.com/darrachequesne/notepack + */ +function utf8Length(str) { + var c = 0, length = 0; + for (var i = 0, l = str.length; i < l; i++) { + c = str.charCodeAt(i); + if (c < 0x80) { + length += 1; + } + else if (c < 0x800) { + length += 2; + } + else if (c < 0xd800 || c >= 0xe000) { + length += 3; + } + else { + i++; + length += 4; + } } - Object.defineProperty(Auth.prototype, "hasToken", { - get: function () { - return !!this.token; - }, - enumerable: true, - configurable: true - }); - Auth.prototype.login = function (options) { - if (options === void 0) { options = {}; } - return __awaiter(this, void 0, void 0, function () { - var queryParams, data, attr; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - queryParams = Object.assign({}, options); - if (this.hasToken) { - queryParams.token = this.token; - } - return [4 /*yield*/, this.request('post', '/auth', queryParams)]; - case 1: - data = _a.sent(); - // set & cache token - this.token = data.token; - Storage_1.setItem(TOKEN_STORAGE, this.token); - for (attr in data) { - if (this.hasOwnProperty(attr)) { - this[attr] = data[attr]; - } - } - this.registerPingService(); - return [2 /*return*/, this]; - } - }); - }); - }; - Auth.prototype.save = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, this.request('put', '/auth', {}, { - username: this.username, - displayName: this.displayName, - avatarUrl: this.avatarUrl, - lang: this.lang, - location: this.location, - timezone: this.timezone, - })]; - case 1: - _a.sent(); - return [2 /*return*/, this]; - } - }); - }); - }; - Auth.prototype.getFriends = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, this.request('get', '/friends/all')]; - case 1: return [2 /*return*/, (_a.sent())]; - } - }); - }); - }; - Auth.prototype.getOnlineFriends = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, this.request('get', '/friends/online')]; - case 1: return [2 /*return*/, (_a.sent())]; - } - }); - }); - }; - Auth.prototype.getFriendRequests = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, this.request('get', '/friends/requests')]; - case 1: return [2 /*return*/, (_a.sent())]; - } - }); - }); - }; - Auth.prototype.sendFriendRequest = function (friendId) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, this.request('post', '/friends/requests', { userId: friendId })]; - case 1: return [2 /*return*/, (_a.sent())]; - } - }); - }); - }; - Auth.prototype.acceptFriendRequest = function (friendId) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, this.request('put', '/friends/requests', { userId: friendId })]; - case 1: return [2 /*return*/, (_a.sent())]; - } - }); - }); - }; - Auth.prototype.declineFriendRequest = function (friendId) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, this.request('del', '/friends/requests', { userId: friendId })]; - case 1: return [2 /*return*/, (_a.sent())]; - } - }); - }); - }; - Auth.prototype.blockUser = function (friendId) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, this.request('post', '/friends/block', { userId: friendId })]; - case 1: return [2 /*return*/, (_a.sent())]; - } - }); - }); - }; - Auth.prototype.unblockUser = function (friendId) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, this.request('put', '/friends/block', { userId: friendId })]; - case 1: return [2 /*return*/, (_a.sent())]; - } - }); - }); - }; - Auth.prototype.request = function (method, segments, query, body, headers) { - if (query === void 0) { query = {}; } - if (headers === void 0) { headers = {}; } - return __awaiter(this, void 0, void 0, function () { - var queryParams, name_1, queryString, opts; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - headers['Accept'] = 'application/json'; - if (this.hasToken) { - headers['Authorization'] = 'Bearer ' + this.token; - } - queryParams = []; - for (name_1 in query) { - queryParams.push(name_1 + "=" + query[name_1]); - } - queryString = (queryParams.length > 0) - ? "?" + queryParams.join("&") - : ''; - opts = { headers: headers }; - if (body) { - opts.body = body; - } - return [4 /*yield*/, http[method]("" + this.endpoint + segments + queryString, opts)]; - case 1: return [2 /*return*/, (_a.sent()).data]; - } - }); - }); - }; - Auth.prototype.logout = function () { - this.token = undefined; - Storage_1.removeItem(TOKEN_STORAGE); - this.unregisterPingService(); - }; - Auth.prototype.registerPingService = function (timeout) { - var _this = this; - if (timeout === void 0) { timeout = 15000; } - this.unregisterPingService(); - this.keepOnlineInterval = setInterval(function () { return _this.request('get', '/auth'); }, timeout); - }; - Auth.prototype.unregisterPingService = function () { - clearInterval(this.keepOnlineInterval); - }; - return Auth; -}()); -exports.Auth = Auth; - - -/***/ }), -/* 9 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -Object.defineProperty(exports, "__esModule", { value: true }); -exports.END_OF_STRUCTURE = 0xc1; // (msgpack spec: never used) -exports.NIL = 0xc0; -exports.INDEX_CHANGE = 0xd4; -exports.TYPE_ID = 0xd5; -//# sourceMappingURL=spec.js.map - -/***/ }), -/* 10 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -Object.defineProperty(exports, "__esModule", { value: true }); -var Schema_1 = __webpack_require__(0); -var ArraySchema_1 = __webpack_require__(1); -var MapSchema_1 = __webpack_require__(2); -var ChangeTree = /** @class */ (function () { - function ChangeTree(indexes, parentField, parent) { - if (indexes === void 0) { indexes = {}; } - if (parentField === void 0) { parentField = null; } - this.changed = false; - this.changes = new Set(); - this.allChanges = new Set(); - this.deletedKeys = {}; - this.fieldIndexes = indexes; - this.parent = parent; - this.parentField = parentField; - } - ChangeTree.prototype.change = function (fieldName, isDelete) { - if (isDelete === void 0) { isDelete = false; } - var fieldIndex = this.fieldIndexes[fieldName]; - var field = (typeof (fieldIndex) === "number") ? fieldIndex : fieldName; - this.changed = true; - this.changes.add(field); - if (!isDelete) { - this.allChanges.add(field); - } - else if (isDelete) { - // discard all-changes for removed items. - this.allChanges.delete(field); - } - if (this.parent) { - this.parent.change(this.parentField); - } - }; - ChangeTree.prototype.mapIndex = function (instance, key) { - if (typeof instance === "object") { - if (!this.indexMap) { - this.indexMap = new Map(); - this.indexChange = new Map(); - } - this.indexMap.set(instance, key); - } - }; - ChangeTree.prototype.getIndex = function (instance) { - return this.indexMap && this.indexMap.get(instance); - }; - ChangeTree.prototype.deleteIndex = function (instance) { - if (typeof instance === "object") { - this.deletedKeys[this.indexMap.get(instance)] = true; - this.indexMap.delete(instance); - } - }; - ChangeTree.prototype.isDeleted = function (key) { - return this.deletedKeys[key] !== undefined; - }; - ChangeTree.prototype.mapIndexChange = function (instance, key) { - if (typeof instance === "object") { - this.indexChange.set(instance, key); + return length; +} +function utf8Write(view, offset, str) { + var c = 0; + for (var i = 0, l = str.length; i < l; i++) { + c = str.charCodeAt(i); + if (c < 0x80) { + view[offset++] = c; } - }; - ChangeTree.prototype.getIndexChange = function (instance) { - return this.indexChange && this.indexChange.get(instance); - }; - ChangeTree.prototype.deleteIndexChange = function (instance) { - if (typeof instance === "object") { - this.indexChange.delete(instance); + else if (c < 0x800) { + view[offset++] = 0xc0 | (c >> 6); + view[offset++] = 0x80 | (c & 0x3f); } - }; - ChangeTree.prototype.changeAll = function (obj) { - if (obj instanceof Schema_1.Schema) { - var schema = obj._schema; - for (var field in schema) { - // ensure ArraySchema and MapSchema already initialized - // on its structure have a valid parent. - if ((obj[field] instanceof Schema_1.Schema || - obj[field] instanceof ArraySchema_1.ArraySchema || - obj[field] instanceof MapSchema_1.MapSchema) && - !obj[field].$changes.parent.parent) { - obj[field].$changes.parent = this; - } - if (obj[field] !== undefined) { - this.change(field); - } - } + else if (c < 0xd800 || c >= 0xe000) { + view[offset++] = 0xe0 | (c >> 12); + view[offset++] = 0x80 | (c >> 6 & 0x3f); + view[offset++] = 0x80 | (c & 0x3f); } else { - var keys = Object.keys(obj); - for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) { - var key = keys_1[_i]; - if (obj[key] !== undefined) { - this.change(key); - } - } - } - }; - ChangeTree.prototype.discard = function () { - this.changed = false; - this.changes.clear(); - this.deletedKeys = {}; - if (this.indexChange) { - this.indexChange.clear(); + i++; + c = 0x10000 + (((c & 0x3ff) << 10) | (str.charCodeAt(i) & 0x3ff)); + view[offset++] = 0xf0 | (c >> 18); + view[offset++] = 0x80 | (c >> 12 & 0x3f); + view[offset++] = 0x80 | (c >> 6 & 0x3f); + view[offset++] = 0x80 | (c & 0x3f); } - }; - return ChangeTree; -}()); -exports.ChangeTree = ChangeTree; -//# sourceMappingURL=ChangeTree.js.map - -/***/ }), -/* 11 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -Object.defineProperty(exports, "__esModule", { value: true }); -var ChangeTree_1 = __webpack_require__(10); -var Schema_1 = __webpack_require__(0); -var Context = /** @class */ (function () { - function Context() { - this.types = {}; - this.schemas = new Map(); } - Context.prototype.has = function (schema) { - return this.schemas.has(schema); - }; - Context.prototype.get = function (typeid) { - return this.types[typeid]; - }; - Context.prototype.add = function (schema) { - schema._typeid = this.schemas.size; - this.types[schema._typeid] = schema; - this.schemas.set(schema, schema._typeid); - }; - return Context; -}()); -exports.Context = Context; -exports.globalContext = new Context(); -/** - * `@type()` decorator for proxies - */ -function type(type, context) { - if (context === void 0) { context = exports.globalContext; } - return function (target, field) { - var constructor = target.constructor; - constructor._context = context; - /* - * static schema - */ - if (!context.has(constructor)) { - context.add(constructor); - // support inheritance - constructor._schema = Object.assign({}, constructor._schema || {}); - constructor._indexes = Object.assign({}, constructor._indexes || {}); - constructor._fieldsByIndex = Object.assign({}, constructor._fieldsByIndex || {}); - constructor._descriptors = Object.assign({}, constructor._descriptors || {}); - constructor._deprecated = Object.assign({}, constructor._deprecated || {}); - } - var index = Object.keys(constructor._schema).length; - constructor._fieldsByIndex[index] = field; - constructor._indexes[field] = index; - constructor._schema[field] = type; - /** - * skip if descriptor already exists for this field (`@deprecated()`) - */ - if (constructor._descriptors[field]) { - return; - } - /** - * TODO: `isSchema` / `isArray` / `isMap` is repeated on many places! - * need to refactor all of them. - */ - var isArray = Array.isArray(type); - var isMap = !isArray && type.map; - var isSchema = (typeof (constructor._schema[field]) === "function"); - var fieldCached = "_" + field; - constructor._descriptors[fieldCached] = { - enumerable: false, - configurable: false, - writable: true, - }; - constructor._descriptors[field] = { - get: function () { - return this[fieldCached]; - }, - set: function (value) { - /** - * Create Proxy for array or map items - */ - if (isArray || isMap) { - value = new Proxy(value, { - get: function (obj, prop) { return obj[prop]; }, - set: function (obj, prop, setValue) { - if (prop !== "length" && prop.indexOf("$") !== 0) { - // ensure new value has a parent - var key = (isArray) ? Number(prop) : String(prop); - if (!obj.$sorting) { - // track index change - var previousIndex = obj.$changes.getIndex(setValue); - if (previousIndex !== undefined) { - obj.$changes.mapIndexChange(setValue, previousIndex); - } - obj.$changes.mapIndex(setValue, key); - } - // if (isMap) { - // obj._indexes.delete(prop); - // } - if (setValue instanceof Schema_1.Schema) { - // new items are flagged with all changes - if (!setValue.$changes.parent) { - setValue.$changes = new ChangeTree_1.ChangeTree(setValue._indexes, key, obj.$changes); - setValue.$changes.changeAll(setValue); - } - } - else { - obj[prop] = setValue; - } - // apply change on ArraySchema / MapSchema - obj.$changes.change(key); - } - else if (setValue !== obj[prop]) { - // console.log("SET NEW LENGTH:", setValue); - // console.log("PREVIOUS LENGTH: ", obj[prop]); - } - obj[prop] = setValue; - return true; - }, - deleteProperty: function (obj, prop) { - var deletedValue = obj[prop]; - if (isMap && deletedValue !== undefined) { - obj.$changes.deleteIndex(deletedValue); - obj.$changes.deleteIndexChange(deletedValue); - if (deletedValue.$changes) { // deletedValue may be a primitive value - delete deletedValue.$changes.parent; - } - // obj._indexes.delete(prop); - } - delete obj[prop]; - var key = (isArray) ? Number(prop) : String(prop); - obj.$changes.change(key, true); - return true; - }, - }); - } - // skip if value is the same as cached. - if (value === this[fieldCached]) { - return; - } - this[fieldCached] = value; - if (isArray) { - // directly assigning an array of items as value. - this.$changes.change(field); - value.$changes = new ChangeTree_1.ChangeTree({}, field, this.$changes); - for (var i = 0; i < value.length; i++) { - if (value[i] instanceof Schema_1.Schema) { - value[i].$changes = new ChangeTree_1.ChangeTree(value[i]._indexes, i, value.$changes); - value[i].$changes.changeAll(value[i]); - } - value.$changes.mapIndex(value[i], i); - value.$changes.change(i); - } - } - else if (isMap) { - // directly assigning a map - value.$changes = new ChangeTree_1.ChangeTree({}, field, this.$changes); - this.$changes.change(field); - for (var key in value) { - if (value[key] instanceof Schema_1.Schema) { - value[key].$changes = new ChangeTree_1.ChangeTree(value[key]._indexes, key, value.$changes); - value[key].$changes.changeAll(value[key]); - } - value.$changes.mapIndex(value[key], key); - value.$changes.change(key); - } - } - else if (isSchema) { - // directly assigning a `Schema` object - // value may be set to null - this.$changes.change(field); - if (value) { - value.$changes = new ChangeTree_1.ChangeTree(value._indexes, field, this.$changes); - value.$changes.changeAll(value); - } - } - else { - // directly assigning a primitive type - this.$changes.change(field); - } - }, - enumerable: true, - configurable: true - }; - }; } -exports.type = type; -/** - * `@filter()` decorator for defining data filters per client - */ -function filter(cb) { - return function (target, field) { - var constructor = target.constructor; - /* - * static filters - */ - if (!constructor._filters) { - constructor._filters = {}; - } - constructor._filters[field] = cb; - }; +exports.utf8Write = utf8Write; +function int8(bytes, value) { + bytes.push(value & 255); } -exports.filter = filter; -/** - * `@deprecated()` flag a field as deprecated. - * The previous `@type()` annotation should remain along with this one. - */ -function deprecated(throws, context) { - if (throws === void 0) { throws = true; } - if (context === void 0) { context = exports.globalContext; } - return function (target, field) { - var constructor = target.constructor; - constructor._deprecated[field] = true; - if (throws) { - constructor._descriptors[field] = { - get: function () { throw new Error(field + " is deprecated."); }, - set: function (value) { }, - enumerable: false, - configurable: true - }; - } - }; +exports.int8 = int8; +; +function uint8(bytes, value) { + bytes.push(value & 255); } -exports.deprecated = deprecated; -function defineTypes(target, fields, context) { - if (context === void 0) { context = exports.globalContext; } - for (var field in fields) { - type(fields[field], context)(target.prototype, field); - } - return target; +exports.uint8 = uint8; +; +function int16(bytes, value) { + bytes.push(value & 255); + bytes.push((value >> 8) & 255); } -exports.defineTypes = defineTypes; -//# sourceMappingURL=annotations.js.map - -/***/ }), -/* 12 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -Object.defineProperty(exports, "__esModule", { value: true }); -__webpack_require__(13); -var Client_1 = __webpack_require__(14); -exports.Client = Client_1.Client; -var Protocol_1 = __webpack_require__(7); -exports.Protocol = Protocol_1.Protocol; -var Room_1 = __webpack_require__(5); -exports.Room = Room_1.Room; -var Auth_1 = __webpack_require__(8); -exports.Auth = Auth_1.Auth; -exports.Platform = Auth_1.Platform; -/* - * Serializers - */ -var FossilDeltaSerializer_1 = __webpack_require__(24); -exports.FossilDeltaSerializer = FossilDeltaSerializer_1.FossilDeltaSerializer; -var SchemaSerializer_1 = __webpack_require__(29); -exports.SchemaSerializer = SchemaSerializer_1.SchemaSerializer; -var Serializer_1 = __webpack_require__(6); -exports.registerSerializer = Serializer_1.registerSerializer; -Serializer_1.registerSerializer('fossil-delta', FossilDeltaSerializer_1.FossilDeltaSerializer); -Serializer_1.registerSerializer('schema', SchemaSerializer_1.SchemaSerializer); - - -/***/ }), -/* 13 */ -/***/ (function(module, exports) { - -// -// Polyfills for legacy environments -// -/* - * Support Android 4.4.x - */ -if (!ArrayBuffer.isView) { - ArrayBuffer.isView = function (a) { - return a !== null && typeof (a) === 'object' && a.buffer instanceof ArrayBuffer; - }; +exports.int16 = int16; +; +function uint16(bytes, value) { + bytes.push(value & 255); + bytes.push((value >> 8) & 255); } - - -/***/ }), -/* 14 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var httpie_1 = __webpack_require__(4); -var Room_1 = __webpack_require__(5); -var Auth_1 = __webpack_require__(8); -var Push_1 = __webpack_require__(23); -var MatchMakeError = /** @class */ (function (_super) { - __extends(MatchMakeError, _super); - function MatchMakeError(message, code) { - var _this = _super.call(this, message) || this; - _this.code = code; - Object.setPrototypeOf(_this, MatchMakeError.prototype); - return _this; - } - return MatchMakeError; -}(Error)); -exports.MatchMakeError = MatchMakeError; -var Client = /** @class */ (function () { - function Client(endpoint) { - if (endpoint === void 0) { endpoint = location.protocol.replace("http", "ws") + "//" + location.hostname + (location.port && ":" + location.port); } - this.endpoint = endpoint; - this.auth = new Auth_1.Auth(this.endpoint); - this.push = new Push_1.Push(this.endpoint); - } - Client.prototype.joinOrCreate = function (roomName, options, rootSchema) { - if (options === void 0) { options = {}; } - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, this.createMatchMakeRequest('joinOrCreate', roomName, options, rootSchema)]; - case 1: return [2 /*return*/, _a.sent()]; - } - }); - }); - }; - Client.prototype.create = function (roomName, options, rootSchema) { - if (options === void 0) { options = {}; } - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, this.createMatchMakeRequest('create', roomName, options, rootSchema)]; - case 1: return [2 /*return*/, _a.sent()]; - } - }); - }); - }; - Client.prototype.join = function (roomName, options, rootSchema) { - if (options === void 0) { options = {}; } - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, this.createMatchMakeRequest('join', roomName, options, rootSchema)]; - case 1: return [2 /*return*/, _a.sent()]; - } - }); - }); - }; - Client.prototype.joinById = function (roomId, options, rootSchema) { - if (options === void 0) { options = {}; } - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, this.createMatchMakeRequest('joinById', roomId, options, rootSchema)]; - case 1: return [2 /*return*/, _a.sent()]; - } - }); - }); - }; - Client.prototype.reconnect = function (roomId, sessionId, rootSchema) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, this.createMatchMakeRequest('joinById', roomId, { sessionId: sessionId }, rootSchema)]; - case 1: return [2 /*return*/, _a.sent()]; - } - }); - }); - }; - Client.prototype.getAvailableRooms = function (roomName) { - if (roomName === void 0) { roomName = ""; } - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = this.endpoint.replace("ws", "http") + "/matchmake/" + roomName; - return [4 /*yield*/, httpie_1.get(url, { headers: { 'Accept': 'application/json' } })]; - case 1: return [2 /*return*/, (_a.sent()).data]; - } - }); - }); - }; - Client.prototype.consumeSeatReservation = function (response, rootSchema) { - return __awaiter(this, void 0, void 0, function () { - var room; - return __generator(this, function (_a) { - room = this.createRoom(response.room.name, rootSchema); - room.id = response.room.roomId; - room.sessionId = response.sessionId; - room.connect(this.buildEndpoint(response.room, { sessionId: room.sessionId })); - return [2 /*return*/, new Promise(function (resolve, reject) { - var onError = function (message) { return reject(message); }; - room.onError.once(onError); - room.onJoin.once(function () { - room.onError.remove(onError); - resolve(room); - }); - })]; - }); - }); - }; - Client.prototype.createMatchMakeRequest = function (method, roomName, options, rootSchema) { - if (options === void 0) { options = {}; } - return __awaiter(this, void 0, void 0, function () { - var url, response; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = this.endpoint.replace("ws", "http") + "/matchmake/" + method + "/" + roomName; - // automatically forward auth token, if present - if (this.auth.hasToken) { - options.token = this.auth.token; - } - return [4 /*yield*/, httpie_1.post(url, { - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - body: JSON.stringify(options) - })]; - case 1: - response = (_a.sent()).data; - if (response.error) { - throw new MatchMakeError(response.error, response.code); - } - return [2 /*return*/, this.consumeSeatReservation(response, rootSchema)]; - } - }); - }); - }; - Client.prototype.createRoom = function (roomName, rootSchema) { - return new Room_1.Room(roomName, rootSchema); - }; - Client.prototype.buildEndpoint = function (room, options) { - if (options === void 0) { options = {}; } - var params = []; - for (var name_1 in options) { - if (!options.hasOwnProperty(name_1)) { - continue; - } - params.push(name_1 + "=" + options[name_1]); - } - return this.endpoint + "/" + room.processId + "/" + room.roomId + "?" + params.join('&'); - }; - return Client; -}()); -exports.Client = Client; - - -/***/ }), -/* 15 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -function Decoder(buffer) { - this._offset = 0; - if (buffer instanceof ArrayBuffer) { - this._buffer = buffer; - this._view = new DataView(this._buffer); - } else if (ArrayBuffer.isView(buffer)) { - this._buffer = buffer.buffer; - this._view = new DataView(this._buffer, buffer.byteOffset, buffer.byteLength); - } else { - throw new Error('Invalid argument'); - } +exports.uint16 = uint16; +; +function int32(bytes, value) { + bytes.push(value & 255); + bytes.push((value >> 8) & 255); + bytes.push((value >> 16) & 255); + bytes.push((value >> 24) & 255); } - -function utf8Read(view, offset, length) { - var string = '', chr = 0; - for (var i = offset, end = offset + length; i < end; i++) { - var byte = view.getUint8(i); - if ((byte & 0x80) === 0x00) { - string += String.fromCharCode(byte); - continue; - } - if ((byte & 0xe0) === 0xc0) { - string += String.fromCharCode( - ((byte & 0x1f) << 6) | - (view.getUint8(++i) & 0x3f) - ); - continue; - } - if ((byte & 0xf0) === 0xe0) { - string += String.fromCharCode( - ((byte & 0x0f) << 12) | - ((view.getUint8(++i) & 0x3f) << 6) | - ((view.getUint8(++i) & 0x3f) << 0) - ); - continue; - } - if ((byte & 0xf8) === 0xf0) { - chr = ((byte & 0x07) << 18) | - ((view.getUint8(++i) & 0x3f) << 12) | - ((view.getUint8(++i) & 0x3f) << 6) | - ((view.getUint8(++i) & 0x3f) << 0); - if (chr >= 0x010000) { // surrogate pair - chr -= 0x010000; - string += String.fromCharCode((chr >>> 10) + 0xD800, (chr & 0x3FF) + 0xDC00); - } else { - string += String.fromCharCode(chr); - } - continue; - } - throw new Error('Invalid byte ' + byte.toString(16)); - } - return string; +exports.int32 = int32; +; +function uint32(bytes, value) { + var b4 = value >> 24; + var b3 = value >> 16; + var b2 = value >> 8; + var b1 = value; + bytes.push(b1 & 255); + bytes.push(b2 & 255); + bytes.push(b3 & 255); + bytes.push(b4 & 255); } - -Decoder.prototype._array = function (length) { - var value = new Array(length); - for (var i = 0; i < length; i++) { - value[i] = this._parse(); - } - return value; -}; - -Decoder.prototype._map = function (length) { - var key = '', value = {}; - for (var i = 0; i < length; i++) { - key = this._parse(); - value[key] = this._parse(); - } - return value; -}; - -Decoder.prototype._str = function (length) { - var value = utf8Read(this._view, this._offset, length); - this._offset += length; - return value; -}; - -Decoder.prototype._bin = function (length) { - var value = this._buffer.slice(this._offset, this._offset + length); - this._offset += length; - return value; -}; - -Decoder.prototype._parse = function () { - var prefix = this._view.getUint8(this._offset++); - var value, length = 0, type = 0, hi = 0, lo = 0; - - if (prefix < 0xc0) { - // positive fixint - if (prefix < 0x80) { - return prefix; - } - // fixmap - if (prefix < 0x90) { - return this._map(prefix & 0x0f); - } - // fixarray - if (prefix < 0xa0) { - return this._array(prefix & 0x0f); +exports.uint32 = uint32; +; +function int64(bytes, value) { + var high = Math.floor(value / Math.pow(2, 32)); + var low = value >>> 0; + uint32(bytes, low); + uint32(bytes, high); +} +exports.int64 = int64; +; +function uint64(bytes, value) { + var high = (value / Math.pow(2, 32)) >> 0; + var low = value >>> 0; + uint32(bytes, low); + uint32(bytes, high); +} +exports.uint64 = uint64; +; +function float32(bytes, value) { + writeFloat32(bytes, value); +} +exports.float32 = float32; +function float64(bytes, value) { + writeFloat64(bytes, value); +} +exports.float64 = float64; +// force little endian to facilitate decoding on multiple implementations +var _isLittleEndian = true; // new Uint16Array(new Uint8Array([1, 0]).buffer)[0] === 1; +var _int32 = new Int32Array(2); +var _float32 = new Float32Array(_int32.buffer); +var _float64 = new Float64Array(_int32.buffer); +function writeFloat32(bytes, value) { + _float32[0] = value; + int32(bytes, _int32[0]); +} +exports.writeFloat32 = writeFloat32; +; +function writeFloat64(bytes, value) { + _float64[0] = value; + int32(bytes, _int32[_isLittleEndian ? 0 : 1]); + int32(bytes, _int32[_isLittleEndian ? 1 : 0]); +} +exports.writeFloat64 = writeFloat64; +; +function boolean(bytes, value) { + return uint8(bytes, value ? 1 : 0); +} +exports.boolean = boolean; +; +function string(bytes, value) { + // encode `null` strings as empty. + if (!value) { + value = ""; } + var length = utf8Length(value); + var size = 0; // fixstr - return this._str(prefix & 0x1f); - } - - // negative fixint - if (prefix > 0xdf) { - return (0xff - prefix + 1) * -1; - } - - switch (prefix) { - // nil - case 0xc0: - return null; - // false - case 0xc2: - return false; - // true - case 0xc3: - return true; - - // bin - case 0xc4: - length = this._view.getUint8(this._offset); - this._offset += 1; - return this._bin(length); - case 0xc5: - length = this._view.getUint16(this._offset); - this._offset += 2; - return this._bin(length); - case 0xc6: - length = this._view.getUint32(this._offset); - this._offset += 4; - return this._bin(length); - - // ext - case 0xc7: - length = this._view.getUint8(this._offset); - type = this._view.getInt8(this._offset + 1); - this._offset += 2; - return [type, this._bin(length)]; - case 0xc8: - length = this._view.getUint16(this._offset); - type = this._view.getInt8(this._offset + 2); - this._offset += 3; - return [type, this._bin(length)]; - case 0xc9: - length = this._view.getUint32(this._offset); - type = this._view.getInt8(this._offset + 4); - this._offset += 5; - return [type, this._bin(length)]; - - // float - case 0xca: - value = this._view.getFloat32(this._offset); - this._offset += 4; - return value; - case 0xcb: - value = this._view.getFloat64(this._offset); - this._offset += 8; - return value; - - // uint - case 0xcc: - value = this._view.getUint8(this._offset); - this._offset += 1; - return value; - case 0xcd: - value = this._view.getUint16(this._offset); - this._offset += 2; - return value; - case 0xce: - value = this._view.getUint32(this._offset); - this._offset += 4; - return value; - case 0xcf: - hi = this._view.getUint32(this._offset) * Math.pow(2, 32); - lo = this._view.getUint32(this._offset + 4); - this._offset += 8; - return hi + lo; - - // int - case 0xd0: - value = this._view.getInt8(this._offset); - this._offset += 1; - return value; - case 0xd1: - value = this._view.getInt16(this._offset); - this._offset += 2; - return value; - case 0xd2: - value = this._view.getInt32(this._offset); - this._offset += 4; - return value; - case 0xd3: - hi = this._view.getInt32(this._offset) * Math.pow(2, 32); - lo = this._view.getUint32(this._offset + 4); - this._offset += 8; - return hi + lo; - - // fixext - case 0xd4: - type = this._view.getInt8(this._offset); - this._offset += 1; - if (type === 0x00) { - this._offset += 1; - return void 0; - } - return [type, this._bin(1)]; - case 0xd5: - type = this._view.getInt8(this._offset); - this._offset += 1; - return [type, this._bin(2)]; - case 0xd6: - type = this._view.getInt8(this._offset); - this._offset += 1; - return [type, this._bin(4)]; - case 0xd7: - type = this._view.getInt8(this._offset); - this._offset += 1; - if (type === 0x00) { - hi = this._view.getInt32(this._offset) * Math.pow(2, 32); - lo = this._view.getUint32(this._offset + 4); - this._offset += 8; - return new Date(hi + lo); - } - return [type, this._bin(8)]; - case 0xd8: - type = this._view.getInt8(this._offset); - this._offset += 1; - return [type, this._bin(16)]; - - // str - case 0xd9: - length = this._view.getUint8(this._offset); - this._offset += 1; - return this._str(length); - case 0xda: - length = this._view.getUint16(this._offset); - this._offset += 2; - return this._str(length); - case 0xdb: - length = this._view.getUint32(this._offset); - this._offset += 4; - return this._str(length); - - // array - case 0xdc: - length = this._view.getUint16(this._offset); - this._offset += 2; - return this._array(length); - case 0xdd: - length = this._view.getUint32(this._offset); - this._offset += 4; - return this._array(length); - - // map - case 0xde: - length = this._view.getUint16(this._offset); - this._offset += 2; - return this._map(length); - case 0xdf: - length = this._view.getUint32(this._offset); - this._offset += 4; - return this._map(length); - } - - throw new Error('Could not parse'); -}; - -function decode(buffer) { - var decoder = new Decoder(buffer); - var value = decoder._parse(); - if (decoder._offset !== buffer.byteLength) { - throw new Error((buffer.byteLength - decoder._offset) + ' trailing bytes'); - } - return value; -} - -module.exports = decode; - - -/***/ }), -/* 16 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -function utf8Write(view, offset, str) { - var c = 0; - for (var i = 0, l = str.length; i < l; i++) { - c = str.charCodeAt(i); - if (c < 0x80) { - view.setUint8(offset++, c); + if (length < 0x20) { + bytes.push(length | 0xa0); + size = 1; + } + // str 8 + else if (length < 0x100) { + bytes.push(0xd9); + uint8(bytes, length); + size = 2; } - else if (c < 0x800) { - view.setUint8(offset++, 0xc0 | (c >> 6)); - view.setUint8(offset++, 0x80 | (c & 0x3f)); + // str 16 + else if (length < 0x10000) { + bytes.push(0xda); + uint16(bytes, length); + size = 3; } - else if (c < 0xd800 || c >= 0xe000) { - view.setUint8(offset++, 0xe0 | (c >> 12)); - view.setUint8(offset++, 0x80 | (c >> 6) & 0x3f); - view.setUint8(offset++, 0x80 | (c & 0x3f)); + // str 32 + else if (length < 0x100000000) { + bytes.push(0xdb); + uint32(bytes, length); + size = 5; } else { - i++; - c = 0x10000 + (((c & 0x3ff) << 10) | (str.charCodeAt(i) & 0x3ff)); - view.setUint8(offset++, 0xf0 | (c >> 18)); - view.setUint8(offset++, 0x80 | (c >> 12) & 0x3f); - view.setUint8(offset++, 0x80 | (c >> 6) & 0x3f); - view.setUint8(offset++, 0x80 | (c & 0x3f)); + throw new Error('String too long'); } - } + utf8Write(bytes, bytes.length, value); + return size + length; } - -function utf8Length(str) { - var c = 0, length = 0; - for (var i = 0, l = str.length; i < l; i++) { - c = str.charCodeAt(i); - if (c < 0x80) { - length += 1; +exports.string = string; +function number(bytes, value) { + if (isNaN(value)) { + return number(bytes, 0); + } + else if (!isFinite(value)) { + return number(bytes, (value > 0) ? Number.MAX_SAFE_INTEGER : -Number.MAX_SAFE_INTEGER); } - else if (c < 0x800) { - length += 2; + else if (value !== (value | 0)) { + bytes.push(0xcb); + writeFloat64(bytes, value); + return 9; + // TODO: encode float 32? + // is it possible to differentiate between float32 / float64 here? + // // float 32 + // bytes.push(0xca); + // writeFloat32(bytes, value); + // return 5; } - else if (c < 0xd800 || c >= 0xe000) { - length += 3; + if (value >= 0) { + // positive fixnum + if (value < 0x80) { + uint8(bytes, value); + return 1; + } + // uint 8 + if (value < 0x100) { + bytes.push(0xcc); + uint8(bytes, value); + return 2; + } + // uint 16 + if (value < 0x10000) { + bytes.push(0xcd); + uint16(bytes, value); + return 3; + } + // uint 32 + if (value < 0x100000000) { + bytes.push(0xce); + uint32(bytes, value); + return 5; + } + // uint 64 + bytes.push(0xcf); + uint64(bytes, value); + return 9; } else { - i++; - length += 4; + // negative fixnum + if (value >= -0x20) { + bytes.push(value); + return 1; + } + // int 8 + if (value >= -0x80) { + bytes.push(0xd0); + int8(bytes, value); + return 2; + } + // int 16 + if (value >= -0x8000) { + bytes.push(0xd1); + int16(bytes, value); + return 3; + } + // int 32 + if (value >= -0x80000000) { + bytes.push(0xd2); + int32(bytes, value); + return 5; + } + // int 64 + bytes.push(0xd3); + int64(bytes, value); + return 9; } - } - return length; } +exports.number = number; +//# sourceMappingURL=encode.js.map -function _encode(bytes, defers, value) { - var type = typeof value, i = 0, l = 0, hi = 0, lo = 0, length = 0, size = 0; +/***/ }), +/* 9 */ +/***/ (function(module, exports, __webpack_require__) { - if (type === 'string') { - length = utf8Length(value); +"use strict"; - // fixstr - if (length < 0x20) { - bytes.push(length | 0xa0); - size = 1; +Object.defineProperty(exports, "__esModule", { value: true }); +var spec_1 = __webpack_require__(10); +function utf8Read(bytes, offset, length) { + var string = '', chr = 0; + for (var i = offset, end = offset + length; i < end; i++) { + var byte = bytes[i]; + if ((byte & 0x80) === 0x00) { + string += String.fromCharCode(byte); + continue; + } + if ((byte & 0xe0) === 0xc0) { + string += String.fromCharCode(((byte & 0x1f) << 6) | + (bytes[++i] & 0x3f)); + continue; + } + if ((byte & 0xf0) === 0xe0) { + string += String.fromCharCode(((byte & 0x0f) << 12) | + ((bytes[++i] & 0x3f) << 6) | + ((bytes[++i] & 0x3f) << 0)); + continue; + } + if ((byte & 0xf8) === 0xf0) { + chr = ((byte & 0x07) << 18) | + ((bytes[++i] & 0x3f) << 12) | + ((bytes[++i] & 0x3f) << 6) | + ((bytes[++i] & 0x3f) << 0); + if (chr >= 0x010000) { // surrogate pair + chr -= 0x010000; + string += String.fromCharCode((chr >>> 10) + 0xD800, (chr & 0x3FF) + 0xDC00); + } + else { + string += String.fromCharCode(chr); + } + continue; + } + throw new Error('Invalid byte ' + byte.toString(16)); + } + return string; +} +function int8(bytes, it) { + return uint8(bytes, it) << 24 >> 24; +} +exports.int8 = int8; +; +function uint8(bytes, it) { + return bytes[it.offset++]; +} +exports.uint8 = uint8; +; +function int16(bytes, it) { + return uint16(bytes, it) << 16 >> 16; +} +exports.int16 = int16; +; +function uint16(bytes, it) { + return bytes[it.offset++] | bytes[it.offset++] << 8; +} +exports.uint16 = uint16; +; +function int32(bytes, it) { + return bytes[it.offset++] | bytes[it.offset++] << 8 | bytes[it.offset++] << 16 | bytes[it.offset++] << 24; +} +exports.int32 = int32; +; +function uint32(bytes, it) { + return int32(bytes, it) >>> 0; +} +exports.uint32 = uint32; +; +function float32(bytes, it) { + return readFloat32(bytes, it); +} +exports.float32 = float32; +function float64(bytes, it) { + return readFloat64(bytes, it); +} +exports.float64 = float64; +function int64(bytes, it) { + var low = uint32(bytes, it); + var high = int32(bytes, it) * Math.pow(2, 32); + return high + low; +} +exports.int64 = int64; +; +function uint64(bytes, it) { + var low = uint32(bytes, it); + var high = uint32(bytes, it) * Math.pow(2, 32); + return high + low; +} +exports.uint64 = uint64; +; +// force little endian to facilitate decoding on multiple implementations +var _isLittleEndian = true; // new Uint16Array(new Uint8Array([1, 0]).buffer)[0] === 1; +var _int32 = new Int32Array(2); +var _float32 = new Float32Array(_int32.buffer); +var _float64 = new Float64Array(_int32.buffer); +function readFloat32(bytes, it) { + _int32[0] = int32(bytes, it); + return _float32[0]; +} +exports.readFloat32 = readFloat32; +; +function readFloat64(bytes, it) { + _int32[_isLittleEndian ? 0 : 1] = int32(bytes, it); + _int32[_isLittleEndian ? 1 : 0] = int32(bytes, it); + return _float64[0]; +} +exports.readFloat64 = readFloat64; +; +function boolean(bytes, it) { + return uint8(bytes, it) > 0; +} +exports.boolean = boolean; +; +function string(bytes, it) { + var prefix = bytes[it.offset++]; + var length; + if (prefix < 0xc0) { + // fixstr + length = prefix & 0x1f; } - // str 8 - else if (length < 0x100) { - bytes.push(0xd9, length); - size = 2; + else if (prefix === 0xd9) { + length = uint8(bytes, it); } - // str 16 - else if (length < 0x10000) { - bytes.push(0xda, length >> 8, length); - size = 3; + else if (prefix === 0xda) { + length = uint16(bytes, it); } - // str 32 - else if (length < 0x100000000) { - bytes.push(0xdb, length >> 24, length >> 16, length >> 8, length); - size = 5; - } else { - throw new Error('String too long'); + else if (prefix === 0xdb) { + length = uint32(bytes, it); } - defers.push({ _str: value, _length: length, _offset: bytes.length }); - return size + length; - } - if (type === 'number') { - // TODO: encode to float 32? - - // float 64 - if (Math.floor(value) !== value || !isFinite(value)) { - bytes.push(0xcb); - defers.push({ _float: value, _length: 8, _offset: bytes.length }); - return 9; + var value = utf8Read(bytes, it.offset, length); + it.offset += length; + return value; +} +exports.string = string; +function stringCheck(bytes, it) { + var prefix = bytes[it.offset]; + return ( + // fixstr + (prefix < 0xc0 && prefix > 0xa0) || + // str 8 + prefix === 0xd9 || + // str 16 + prefix === 0xda || + // str 32 + prefix === 0xdb); +} +exports.stringCheck = stringCheck; +function number(bytes, it) { + var prefix = bytes[it.offset++]; + if (prefix < 0x80) { + // positive fixint + return prefix; } - - if (value >= 0) { - // positive fixnum - if (value < 0x80) { - bytes.push(value); - return 1; - } - // uint 8 - if (value < 0x100) { - bytes.push(0xcc, value); - return 2; - } - // uint 16 - if (value < 0x10000) { - bytes.push(0xcd, value >> 8, value); - return 3; - } - // uint 32 - if (value < 0x100000000) { - bytes.push(0xce, value >> 24, value >> 16, value >> 8, value); - return 5; - } - // uint 64 - hi = (value / Math.pow(2, 32)) >> 0; - lo = value >>> 0; - bytes.push(0xcf, hi >> 24, hi >> 16, hi >> 8, hi, lo >> 24, lo >> 16, lo >> 8, lo); - return 9; - } else { - // negative fixnum - if (value >= -0x20) { - bytes.push(value); - return 1; - } - // int 8 - if (value >= -0x80) { - bytes.push(0xd0, value); - return 2; - } - // int 16 - if (value >= -0x8000) { - bytes.push(0xd1, value >> 8, value); - return 3; - } - // int 32 - if (value >= -0x80000000) { - bytes.push(0xd2, value >> 24, value >> 16, value >> 8, value); - return 5; - } - // int 64 - hi = Math.floor(value / Math.pow(2, 32)); - lo = value >>> 0; - bytes.push(0xd3, hi >> 24, hi >> 16, hi >> 8, hi, lo >> 24, lo >> 16, lo >> 8, lo); - return 9; + else if (prefix === 0xca) { + // float 32 + return readFloat32(bytes, it); } - } - if (type === 'object') { - // nil - if (value === null) { - bytes.push(0xc0); - return 1; + else if (prefix === 0xcb) { + // float 64 + return readFloat64(bytes, it); } - - if (Array.isArray(value)) { - length = value.length; - - // fixarray - if (length < 0x10) { - bytes.push(length | 0x90); - size = 1; - } - // array 16 - else if (length < 0x10000) { - bytes.push(0xdc, length >> 8, length); - size = 3; - } - // array 32 - else if (length < 0x100000000) { - bytes.push(0xdd, length >> 24, length >> 16, length >> 8, length); - size = 5; - } else { - throw new Error('Array too large'); - } - for (i = 0; i < length; i++) { - size += _encode(bytes, defers, value[i]); - } - return size; + else if (prefix === 0xcc) { + // uint 8 + return uint8(bytes, it); } - - // fixext 8 / Date - if (value instanceof Date) { - var time = value.getTime(); - hi = Math.floor(time / Math.pow(2, 32)); - lo = time >>> 0; - bytes.push(0xd7, 0, hi >> 24, hi >> 16, hi >> 8, hi, lo >> 24, lo >> 16, lo >> 8, lo); - return 10; + else if (prefix === 0xcd) { + // uint 16 + return uint16(bytes, it); } - - if (value instanceof ArrayBuffer) { - length = value.byteLength; - - // bin 8 - if (length < 0x100) { - bytes.push(0xc4, length); - size = 2; - } else - // bin 16 - if (length < 0x10000) { - bytes.push(0xc5, length >> 8, length); - size = 3; - } else - // bin 32 - if (length < 0x100000000) { - bytes.push(0xc6, length >> 24, length >> 16, length >> 8, length); - size = 5; - } else { - throw new Error('Buffer too large'); - } - defers.push({ _bin: value, _length: length, _offset: bytes.length }); - return size + length; + else if (prefix === 0xce) { + // uint 32 + return uint32(bytes, it); } - - if (typeof value.toJSON === 'function') { - return _encode(bytes, defers, value.toJSON()); + else if (prefix === 0xcf) { + // uint 64 + return uint64(bytes, it); } - - var keys = [], key = ''; - - var allKeys = Object.keys(value); - for (i = 0, l = allKeys.length; i < l; i++) { - key = allKeys[i]; - if (typeof value[key] !== 'function') { - keys.push(key); - } + else if (prefix === 0xd0) { + // int 8 + return int8(bytes, it); } - length = keys.length; - - // fixmap - if (length < 0x10) { - bytes.push(length | 0x80); - size = 1; + else if (prefix === 0xd1) { + // int 16 + return int16(bytes, it); } - // map 16 - else if (length < 0x10000) { - bytes.push(0xde, length >> 8, length); - size = 3; + else if (prefix === 0xd2) { + // int 32 + return int32(bytes, it); } - // map 32 - else if (length < 0x100000000) { - bytes.push(0xdf, length >> 24, length >> 16, length >> 8, length); - size = 5; - } else { - throw new Error('Object too large'); + else if (prefix === 0xd3) { + // int 64 + return int64(bytes, it); } - - for (i = 0; i < length; i++) { - key = keys[i]; - size += _encode(bytes, defers, key); - size += _encode(bytes, defers, value[key]); + else if (prefix > 0xdf) { + // negative fixint + return (0xff - prefix + 1) * -1; } - return size; - } - // false/true - if (type === 'boolean') { - bytes.push(value ? 0xc3 : 0xc2); - return 1; - } - // fixext 1 / undefined - if (type === 'undefined') { - bytes.push(0xd4, 0, 0); - return 3; - } - throw new Error('Could not encode'); } - -function encode(value) { - var bytes = []; - var defers = []; - var size = _encode(bytes, defers, value); - var buf = new ArrayBuffer(size); - var view = new DataView(buf); - - var deferIndex = 0; - var deferWritten = 0; - var nextOffset = -1; - if (defers.length > 0) { - nextOffset = defers[0]._offset; - } - - var defer, deferLength = 0, offset = 0; - for (var i = 0, l = bytes.length; i < l; i++) { - view.setUint8(deferWritten + i, bytes[i]); - if (i + 1 !== nextOffset) { continue; } - defer = defers[deferIndex]; - deferLength = defer._length; - offset = deferWritten + nextOffset; - if (defer._bin) { - var bin = new Uint8Array(defer._bin); - for (var j = 0; j < deferLength; j++) { - view.setUint8(offset + j, bin[j]); - } - } else if (defer._str) { - utf8Write(view, offset, defer._str); - } else if (defer._float !== undefined) { - view.setFloat64(offset, defer._float); - } - deferIndex++; - deferWritten += deferLength; - if (defers[deferIndex]) { - nextOffset = defers[deferIndex]._offset; - } - } - return buf; +exports.number = number; +; +function numberCheck(bytes, it) { + var prefix = bytes[it.offset]; + // positive fixint - 0x00 - 0x7f + // float 32 - 0xca + // float 64 - 0xcb + // uint 8 - 0xcc + // uint 16 - 0xcd + // uint 32 - 0xce + // uint 64 - 0xcf + // int 8 - 0xd0 + // int 16 - 0xd1 + // int 32 - 0xd2 + // int 64 - 0xd3 + return (prefix < 0x80 || + (prefix >= 0xca && prefix <= 0xd3)); +} +exports.numberCheck = numberCheck; +function arrayCheck(bytes, it) { + return bytes[it.offset] < 0xa0; + // const prefix = bytes[it.offset] ; + // if (prefix < 0xa0) { + // return prefix; + // // array + // } else if (prefix === 0xdc) { + // it.offset += 2; + // } else if (0xdd) { + // it.offset += 4; + // } + // return prefix; +} +exports.arrayCheck = arrayCheck; +function nilCheck(bytes, it) { + return bytes[it.offset] === spec_1.NIL; } +exports.nilCheck = nilCheck; +function indexChangeCheck(bytes, it) { + return bytes[it.offset] === spec_1.INDEX_CHANGE; +} +exports.indexChangeCheck = indexChangeCheck; +//# sourceMappingURL=decode.js.map + +/***/ }), +/* 10 */ +/***/ (function(module, exports, __webpack_require__) { -module.exports = encode; +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.END_OF_STRUCTURE = 0xc1; // (msgpack spec: never used) +exports.NIL = 0xc0; +exports.INDEX_CHANGE = 0xd4; +exports.TYPE_ID = 0xd5; +//# sourceMappingURL=spec.js.map /***/ }), -/* 17 */ +/* 11 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; Object.defineProperty(exports, "__esModule", { value: true }); -var EventEmitter = /** @class */ (function () { - function EventEmitter() { - this.handlers = []; +var http = __importStar(__webpack_require__(3)); +var Storage_1 = __webpack_require__(26); +var TOKEN_STORAGE = "colyseus-auth-token"; +var Platform; +(function (Platform) { + Platform["ios"] = "ios"; + Platform["android"] = "android"; +})(Platform = exports.Platform || (exports.Platform = {})); +var Auth = /** @class */ (function () { + function Auth(endpoint) { + var _this = this; + this._id = undefined; + this.username = undefined; + this.displayName = undefined; + this.avatarUrl = undefined; + this.isAnonymous = undefined; + this.email = undefined; + this.lang = undefined; + this.location = undefined; + this.timezone = undefined; + this.metadata = undefined; + this.devices = undefined; + this.facebookId = undefined; + this.twitterId = undefined; + this.googleId = undefined; + this.gameCenterId = undefined; + this.steamId = undefined; + this.friendIds = undefined; + this.blockedUserIds = undefined; + this.createdAt = undefined; + this.updatedAt = undefined; + // auth token + this.token = undefined; + this.endpoint = endpoint.replace("ws", "http"); + Storage_1.getItem(TOKEN_STORAGE, function (token) { return _this.token = token; }); } - EventEmitter.prototype.register = function (cb, once) { - if (once === void 0) { once = false; } - this.handlers.push(cb); - return this; + Object.defineProperty(Auth.prototype, "hasToken", { + get: function () { + return !!this.token; + }, + enumerable: true, + configurable: true + }); + Auth.prototype.login = function (options) { + if (options === void 0) { options = {}; } + return __awaiter(this, void 0, void 0, function () { + var queryParams, data, attr; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + queryParams = Object.assign({}, options); + if (this.hasToken) { + queryParams.token = this.token; + } + return [4 /*yield*/, this.request('post', '/auth', queryParams)]; + case 1: + data = _a.sent(); + // set & cache token + this.token = data.token; + Storage_1.setItem(TOKEN_STORAGE, this.token); + for (attr in data) { + if (this.hasOwnProperty(attr)) { + this[attr] = data[attr]; + } + } + this.registerPingService(); + return [2 /*return*/, this]; + } + }); + }); }; - EventEmitter.prototype.invoke = function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - this.handlers.forEach(function (handler) { return handler.apply(void 0, args); }); + Auth.prototype.save = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.request('put', '/auth', {}, { + username: this.username, + displayName: this.displayName, + avatarUrl: this.avatarUrl, + lang: this.lang, + location: this.location, + timezone: this.timezone, + })]; + case 1: + _a.sent(); + return [2 /*return*/, this]; + } + }); + }); }; - EventEmitter.prototype.invokeAsync = function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - return Promise.all(this.handlers.map(function (handler) { return handler.apply(void 0, args); })); + Auth.prototype.getFriends = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.request('get', '/friends/all')]; + case 1: return [2 /*return*/, (_a.sent())]; + } + }); + }); }; - EventEmitter.prototype.remove = function (cb) { - var index = this.handlers.indexOf(cb); - this.handlers[index] = this.handlers[this.handlers.length - 1]; - this.handlers.pop(); + Auth.prototype.getOnlineFriends = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.request('get', '/friends/online')]; + case 1: return [2 /*return*/, (_a.sent())]; + } + }); + }); }; - EventEmitter.prototype.clear = function () { - this.handlers = []; + Auth.prototype.getFriendRequests = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.request('get', '/friends/requests')]; + case 1: return [2 /*return*/, (_a.sent())]; + } + }); + }); }; - return EventEmitter; -}()); -exports.EventEmitter = EventEmitter; -function createSignal() { - var emitter = new EventEmitter(); - function register(cb) { - return emitter.register(cb, this === null); - } - ; - register.once = function (cb) { - var callback = function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - cb.apply(void 0, args); - emitter.remove(callback); - }; - emitter.register(callback); + Auth.prototype.sendFriendRequest = function (friendId) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.request('post', '/friends/requests', { userId: friendId })]; + case 1: return [2 /*return*/, (_a.sent())]; + } + }); + }); }; - register.remove = function (cb) { return emitter.remove(cb); }; - register.invoke = function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - return emitter.invoke.apply(emitter, args); + Auth.prototype.acceptFriendRequest = function (friendId) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.request('put', '/friends/requests', { userId: friendId })]; + case 1: return [2 /*return*/, (_a.sent())]; + } + }); + }); }; - register.invokeAsync = function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - return emitter.invokeAsync.apply(emitter, args); + Auth.prototype.declineFriendRequest = function (friendId) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.request('del', '/friends/requests', { userId: friendId })]; + case 1: return [2 /*return*/, (_a.sent())]; + } + }); + }); }; - register.clear = function () { return emitter.clear(); }; - return register; -} -exports.createSignal = createSignal; - - -/***/ }), -/* 18 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); + Auth.prototype.blockUser = function (friendId) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.request('post', '/friends/block', { userId: friendId })]; + case 1: return [2 /*return*/, (_a.sent())]; + } + }); + }); }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + Auth.prototype.unblockUser = function (friendId) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.request('put', '/friends/block', { userId: friendId })]; + case 1: return [2 /*return*/, (_a.sent())]; + } + }); + }); }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; - result["default"] = mod; - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var websocket_1 = __importDefault(__webpack_require__(19)); -var msgpack = __importStar(__webpack_require__(3)); -var Connection = /** @class */ (function (_super) { - __extends(Connection, _super); - function Connection(url, autoConnect) { - if (autoConnect === void 0) { autoConnect = true; } - var _this = _super.call(this, url, undefined, { connect: autoConnect }) || this; - _this._enqueuedCalls = []; - return _this; - } - Connection.prototype.onOpenCallback = function (event) { - _super.prototype.onOpenCallback.call(this); - this.binaryType = 'arraybuffer'; - if (this._enqueuedCalls.length > 0) { - for (var _i = 0, _a = this._enqueuedCalls; _i < _a.length; _i++) { - var _b = _a[_i], method = _b[0], args = _b[1]; - this[method].apply(this, args); - } - // clear enqueued calls. - this._enqueuedCalls = []; - } + Auth.prototype.request = function (method, segments, query, body, headers) { + if (query === void 0) { query = {}; } + if (headers === void 0) { headers = {}; } + return __awaiter(this, void 0, void 0, function () { + var queryParams, name_1, queryString, opts; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + headers['Accept'] = 'application/json'; + if (this.hasToken) { + headers['Authorization'] = 'Bearer ' + this.token; + } + queryParams = []; + for (name_1 in query) { + queryParams.push(name_1 + "=" + query[name_1]); + } + queryString = (queryParams.length > 0) + ? "?" + queryParams.join("&") + : ''; + opts = { headers: headers }; + if (body) { + opts.body = body; + } + return [4 /*yield*/, http[method]("" + this.endpoint + segments + queryString, opts)]; + case 1: return [2 /*return*/, (_a.sent()).data]; + } + }); + }); }; - Connection.prototype.send = function (data) { - if (this.ws.readyState === websocket_1.default.OPEN) { - return _super.prototype.send.call(this, msgpack.encode(data)); - } - else { - // WebSocket not connected. - // Enqueue data to be sent when readyState == OPEN - this._enqueuedCalls.push(['send', [data]]); - } + Auth.prototype.logout = function () { + this.token = undefined; + Storage_1.removeItem(TOKEN_STORAGE); + this.unregisterPingService(); }; - return Connection; -}(websocket_1.default)); -exports.Connection = Connection; - - -/***/ }), -/* 19 */ -/***/ (function(module, exports, __webpack_require__) { + Auth.prototype.registerPingService = function (timeout) { + var _this = this; + if (timeout === void 0) { timeout = 15000; } + this.unregisterPingService(); + this.keepOnlineInterval = setInterval(function () { return _this.request('get', '/auth'); }, timeout); + }; + Auth.prototype.unregisterPingService = function () { + clearInterval(this.keepOnlineInterval); + }; + return Auth; +}()); +exports.Auth = Auth; -"use strict"; -Object.defineProperty(exports,"__esModule",{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i2&&arguments[2]!==undefined?arguments[2]:{};_classCallCheck(this,WebSocketClient);this.url=url;this.protocols=protocols;this.reconnectEnabled=true;this.listeners={};this.backoff=createBackoff(options.backoff||'exponential',options);this.backoff.onReady=this.onBackoffReady.bind(this);if(typeof options.connect==="undefined"||options.connect){this.open();}}_createClass(WebSocketClient,[{key:'open',value:function open(){var reconnect=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;this.isReconnect=reconnect;// keep binaryType used on previous WebSocket connection -var binaryType=this.ws&&this.ws.binaryType;this.ws=new WebSocketImpl(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);if(binaryType){this.ws.binaryType=binaryType;}}/** - * @ignore - */},{key:'onBackoffReady',value:function onBackoffReady(number,delay){// console.log("onBackoffReady", number + ' ' + delay + 'ms'); -this.open(true);}/** - * @ignore - */},{key:'onCloseCallback',value:function onCloseCallback(e){if(!this.isReconnect&&this.listeners['onclose']){this.listeners['onclose'].apply(null,arguments);}if(this.reconnectEnabled&&e.code<3000){this.backoff.backoff();}}/** - * @ignore - */},{key:'onErrorCallback',value:function onErrorCallback(){if(this.listeners['onerror']){this.listeners['onerror'].apply(null,arguments);}}/** - * @ignore - */},{key:'onMessageCallback',value:function onMessageCallback(){if(this.listeners['onmessage']){this.listeners['onmessage'].apply(null,arguments);}}/** - * @ignore - */},{key:'onOpenCallback',value:function onOpenCallback(){if(this.listeners['onopen']){this.listeners['onopen'].apply(null,arguments);}if(this.isReconnect&&this.listeners['onreconnect']){this.listeners['onreconnect'].apply(null,arguments);}this.isReconnect=false;}/** - * The number of bytes of data that have been queued using calls to send() - * but not yet transmitted to the network. This value does not reset to zero - * when the connection is closed; if you keep calling send(), this will - * continue to climb. - * - * @type unsigned long - * @readonly - */},{key:'close',/** - * Closes the WebSocket connection or connection attempt, if any. If the - * connection is already CLOSED, this method does nothing. - * - * @param code A numeric value indicating the status code explaining why the connection is being closed. If this parameter is not specified, a default value of 1000 (indicating a normal "transaction complete" closure) is assumed. See the list of status codes on the CloseEvent page for permitted values. - * @param reason A human-readable string explaining why the connection is closing. This string must be no longer than 123 bytes of UTF-8 text (not characters). - * - * @return void - */value:function close(code,reason){if(typeof code=='undefined'){code=1000;}this.reconnectEnabled=false;this.ws.close(code,reason);}/** - * Transmits data to the server over the WebSocket connection. - * @param data DOMString|ArrayBuffer|Blob - * @return void - */},{key:'send',value:function send(data){this.ws.send(data);}/** - * An event listener to be called when the WebSocket connection's readyState changes to CLOSED. The listener receives a CloseEvent named "close". - * @param listener EventListener - */},{key:'bufferedAmount',get:function get(){return this.ws.bufferedAmount;}/** - * The current state of the connection; this is one of the Ready state constants. - * @type unsigned short - * @readonly - */},{key:'readyState',get:function get(){return this.ws.readyState;}/** - * A string indicating the type of binary data being transmitted by the - * connection. This should be either "blob" if DOM Blob objects are being - * used or "arraybuffer" if ArrayBuffer objects are being used. - * @type DOMString - */},{key:'binaryType',get:function get(){return this.ws.binaryType;},set:function set(binaryType){this.ws.binaryType=binaryType;}/** - * The extensions selected by the server. This is currently only the empty - * string or a list of extensions as negotiated by the connection. - * @type DOMString - */},{key:'extensions',get:function get(){return this.ws.extensions;},set:function set(extensions){this.ws.extensions=extensions;}/** - * A string indicating the name of the sub-protocol the server selected; - * this will be one of the strings specified in the protocols parameter when - * creating the WebSocket object. - * @type DOMString - */},{key:'protocol',get:function get(){return this.ws.protocol;},set:function set(protocol){this.ws.protocol=protocol;}},{key:'onclose',set:function set(listener){this.listeners['onclose']=listener;},get:function get(){return this.listeners['onclose'];}/** - * An event listener to be called when an error occurs. This is a simple event named "error". - * @param listener EventListener - */},{key:'onerror',set:function set(listener){this.listeners['onerror']=listener;},get:function get(){return this.listeners['onerror'];}/** - * An event listener to be called when a message is received from the server. The listener receives a MessageEvent named "message". - * @param listener EventListener - */},{key:'onmessage',set:function set(listener){this.listeners['onmessage']=listener;},get:function get(){return this.listeners['onmessage'];}/** - * An event listener to be called when the WebSocket connection's readyState changes to OPEN; this indicates that the connection is ready to send and receive data. The event is a simple one with the name "open". - * @param listener EventListener - */},{key:'onopen',set:function set(listener){this.listeners['onopen']=listener;},get:function get(){return this.listeners['onopen'];}/** - * @param listener EventListener - */},{key:'onreconnect',set:function set(listener){this.listeners['onreconnect']=listener;},get:function get(){return this.listeners['onreconnect'];}}]);return WebSocketClient;}();/** - * The connection is not yet open. - */WebSocketClient.CONNECTING=WebSocketImpl.CONNECTING;/** - * The connection is open and ready to communicate. - */WebSocketClient.OPEN=WebSocketImpl.OPEN;/** - * The connection is in the process of closing. - */WebSocketClient.CLOSING=WebSocketImpl.CLOSING;/** - * The connection is closed or couldn't be opened. - */WebSocketClient.CLOSED=WebSocketImpl.CLOSED;exports.default=WebSocketClient; /***/ }), -/* 20 */ +/* 12 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -Object.defineProperty(exports,"__esModule",{value:true});exports.createBackoff=createBackoff;var backoff={exponential:function exponential(attempt,delay){return Math.floor(Math.random()*Math.pow(2,attempt)*delay);},fibonacci:function fibonacci(attempt,delay){var current=1;if(attempt>current){var prev=1,current=2;for(var index=2;index 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; Object.defineProperty(exports, "__esModule", { value: true }); -var Push = /** @class */ (function () { - function Push(endpoint) { - this.endpoint = endpoint.replace("ws", "http"); +var ChangeTree_1 = __webpack_require__(13); +var Schema_1 = __webpack_require__(2); +var Context = /** @class */ (function () { + function Context() { + this.types = {}; + this.schemas = new Map(); } - Push.prototype.register = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - this.check(); - return [4 /*yield*/, this.registerServiceWorker()]; - case 1: - _a.sent(); - return [4 /*yield*/, this.requestNotificationPermission()]; - case 2: - _a.sent(); - return [2 /*return*/]; - } - }); - }); + Context.prototype.has = function (schema) { + return this.schemas.has(schema); }; - ; - Push.prototype.registerServiceWorker = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, navigator.serviceWorker.register(this.endpoint + "/push")]; - case 1: return [2 /*return*/, _a.sent()]; - } - }); - }); + Context.prototype.get = function (typeid) { + return this.types[typeid]; }; - Push.prototype.requestNotificationPermission = function () { - return __awaiter(this, void 0, void 0, function () { - var permission; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, window["Notification"].requestPermission()]; - case 1: - permission = _a.sent(); - // value of permission can be 'granted', 'default', 'denied' - // granted: user has accepted the request - // default: user has dismissed the notification permission popup by clicking on x - // denied: user has denied the request. - if (permission !== "granted") { - throw new Error("Permission not granted for Notification"); + Context.prototype.add = function (schema) { + schema._typeid = this.schemas.size; + this.types[schema._typeid] = schema; + this.schemas.set(schema, schema._typeid); + }; + return Context; +}()); +exports.Context = Context; +exports.globalContext = new Context(); +/** + * `@type()` decorator for proxies + */ +function type(type, context) { + if (context === void 0) { context = exports.globalContext; } + return function (target, field) { + var constructor = target.constructor; + constructor._context = context; + /* + * static schema + */ + if (!context.has(constructor)) { + context.add(constructor); + // support inheritance + constructor._schema = Object.assign({}, constructor._schema || {}); + constructor._indexes = Object.assign({}, constructor._indexes || {}); + constructor._fieldsByIndex = Object.assign({}, constructor._fieldsByIndex || {}); + constructor._descriptors = Object.assign({}, constructor._descriptors || {}); + constructor._deprecated = Object.assign({}, constructor._deprecated || {}); + } + var index = Object.keys(constructor._schema).length; + constructor._fieldsByIndex[index] = field; + constructor._indexes[field] = index; + constructor._schema[field] = type; + /** + * skip if descriptor already exists for this field (`@deprecated()`) + */ + if (constructor._descriptors[field]) { + return; + } + /** + * TODO: `isSchema` / `isArray` / `isMap` is repeated on many places! + * need to refactor all of them. + */ + var isArray = Array.isArray(type); + var isMap = !isArray && type.map; + var isSchema = (typeof (constructor._schema[field]) === "function"); + var fieldCached = "_" + field; + constructor._descriptors[fieldCached] = { + enumerable: false, + configurable: false, + writable: true, + }; + constructor._descriptors[field] = { + get: function () { + return this[fieldCached]; + }, + set: function (value) { + /** + * Create Proxy for array or map items + */ + if (isArray || isMap) { + value = new Proxy(value, { + get: function (obj, prop) { return obj[prop]; }, + set: function (obj, prop, setValue) { + if (prop !== "length" && prop.indexOf("$") !== 0) { + // ensure new value has a parent + var key = (isArray) ? Number(prop) : String(prop); + if (!obj.$sorting) { + // track index change + var previousIndex = obj.$changes.getIndex(setValue); + if (previousIndex !== undefined) { + obj.$changes.mapIndexChange(setValue, previousIndex); + } + obj.$changes.mapIndex(setValue, key); + } + // if (isMap) { + // obj._indexes.delete(prop); + // } + if (setValue instanceof Schema_1.Schema) { + // new items are flagged with all changes + if (!setValue.$changes.parent) { + setValue.$changes = new ChangeTree_1.ChangeTree(setValue._indexes, key, obj.$changes); + setValue.$changes.changeAll(setValue); + } + } + else { + obj[prop] = setValue; + } + // apply change on ArraySchema / MapSchema + obj.$changes.change(key); + } + else if (setValue !== obj[prop]) { + // console.log("SET NEW LENGTH:", setValue); + // console.log("PREVIOUS LENGTH: ", obj[prop]); + } + obj[prop] = setValue; + return true; + }, + deleteProperty: function (obj, prop) { + var deletedValue = obj[prop]; + if (isMap && deletedValue !== undefined) { + obj.$changes.deleteIndex(deletedValue); + obj.$changes.deleteIndexChange(deletedValue); + if (deletedValue.$changes) { // deletedValue may be a primitive value + delete deletedValue.$changes.parent; + } + // obj._indexes.delete(prop); + } + delete obj[prop]; + var key = (isArray) ? Number(prop) : String(prop); + obj.$changes.change(key, true); + return true; + }, + }); + } + // skip if value is the same as cached. + if (value === this[fieldCached]) { + return; + } + this[fieldCached] = value; + if (isArray) { + // directly assigning an array of items as value. + this.$changes.change(field); + value.$changes = new ChangeTree_1.ChangeTree({}, field, this.$changes); + for (var i = 0; i < value.length; i++) { + if (value[i] instanceof Schema_1.Schema) { + value[i].$changes = new ChangeTree_1.ChangeTree(value[i]._indexes, i, value.$changes); + value[i].$changes.changeAll(value[i]); } - return [2 /*return*/]; + value.$changes.mapIndex(value[i], i); + value.$changes.change(i); + } + } + else if (isMap) { + // directly assigning a map + value.$changes = new ChangeTree_1.ChangeTree({}, field, this.$changes); + this.$changes.change(field); + for (var key in value) { + if (value[key] instanceof Schema_1.Schema) { + value[key].$changes = new ChangeTree_1.ChangeTree(value[key]._indexes, key, value.$changes); + value[key].$changes.changeAll(value[key]); + } + value.$changes.mapIndex(value[key], key); + value.$changes.change(key); + } + } + else if (isSchema) { + // directly assigning a `Schema` object + // value may be set to null + this.$changes.change(field); + if (value) { + value.$changes = new ChangeTree_1.ChangeTree(value._indexes, field, this.$changes); + value.$changes.changeAll(value); + } } - }); - }); + else { + // directly assigning a primitive type + this.$changes.change(field); + } + }, + enumerable: true, + configurable: true + }; }; - Push.prototype.check = function () { - if (!("serviceWorker" in navigator)) { - throw new Error("No Service Worker support!"); +} +exports.type = type; +/** + * `@filter()` decorator for defining data filters per client + */ +function filter(cb) { + return function (target, field) { + var constructor = target.constructor; + /* + * static filters + */ + if (!constructor._filters) { + constructor._filters = {}; } - if (!("PushManager" in window)) { - throw new Error("No Push API Support!"); + constructor._filters[field] = cb; + }; +} +exports.filter = filter; +/** + * `@deprecated()` flag a field as deprecated. + * The previous `@type()` annotation should remain along with this one. + */ +function deprecated(throws, context) { + if (throws === void 0) { throws = true; } + if (context === void 0) { context = exports.globalContext; } + return function (target, field) { + var constructor = target.constructor; + constructor._deprecated[field] = true; + if (throws) { + constructor._descriptors[field] = { + get: function () { throw new Error(field + " is deprecated."); }, + set: function (value) { }, + enumerable: false, + configurable: true + }; } }; - return Push; -}()); -exports.Push = Push; - - -/***/ }), -/* 24 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; - result["default"] = mod; - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var state_listener_1 = __webpack_require__(25); -var fossilDelta = __importStar(__webpack_require__(28)); -var msgpack = __importStar(__webpack_require__(3)); -var FossilDeltaSerializer = /** @class */ (function () { - function FossilDeltaSerializer() { - this.api = new state_listener_1.StateContainer({}); +} +exports.deprecated = deprecated; +function defineTypes(target, fields, context) { + if (context === void 0) { context = exports.globalContext; } + for (var field in fields) { + type(fields[field], context)(target.prototype, field); } - FossilDeltaSerializer.prototype.getState = function () { - return this.api.state; - }; - FossilDeltaSerializer.prototype.setState = function (encodedState) { - this.previousState = new Uint8Array(encodedState); - this.api.set(msgpack.decode(this.previousState)); - }; - FossilDeltaSerializer.prototype.patch = function (binaryPatch) { - // apply patch - this.previousState = new Uint8Array(fossilDelta.apply(this.previousState, binaryPatch)); - // trigger update callbacks - this.api.set(msgpack.decode(this.previousState)); - }; - FossilDeltaSerializer.prototype.teardown = function () { - this.api.removeAllListeners(); - }; - return FossilDeltaSerializer; -}()); -exports.FossilDeltaSerializer = FossilDeltaSerializer; - + return target; +} +exports.defineTypes = defineTypes; +//# sourceMappingURL=annotations.js.map /***/ }), -/* 25 */ +/* 15 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -var StateContainer_1 = __webpack_require__(26); -exports.StateContainer = StateContainer_1.StateContainer; +__webpack_require__(16); +var Client_1 = __webpack_require__(17); +exports.Client = Client_1.Client; +var Protocol_1 = __webpack_require__(7); +exports.Protocol = Protocol_1.Protocol; +exports.ErrorCode = Protocol_1.ErrorCode; +var Room_1 = __webpack_require__(4); +exports.Room = Room_1.Room; +var Auth_1 = __webpack_require__(11); +exports.Auth = Auth_1.Auth; +exports.Platform = Auth_1.Platform; +/* + * Serializers + */ +var FossilDeltaSerializer_1 = __webpack_require__(28); +exports.FossilDeltaSerializer = FossilDeltaSerializer_1.FossilDeltaSerializer; +var SchemaSerializer_1 = __webpack_require__(33); +exports.SchemaSerializer = SchemaSerializer_1.SchemaSerializer; +var Serializer_1 = __webpack_require__(6); +exports.registerSerializer = Serializer_1.registerSerializer; +Serializer_1.registerSerializer('fossil-delta', FossilDeltaSerializer_1.FossilDeltaSerializer); +Serializer_1.registerSerializer('schema', SchemaSerializer_1.SchemaSerializer); /***/ }), -/* 26 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; +/* 16 */ +/***/ (function(module, exports) { -Object.defineProperty(exports, "__esModule", { value: true }); -var compare_1 = __webpack_require__(27); -var StateContainer = /** @class */ (function () { - function StateContainer(state) { - this.listeners = []; - this.matcherPlaceholders = { - ":id": /^([a-zA-Z0-9\-_]+)$/, - ":number": /^([0-9]+)$/, - ":string": /^(\w+)$/, - ":axis": /^([xyz])$/, - ":*": /(.*)/, - }; - this.state = state; - this.reset(); - } - StateContainer.prototype.set = function (newState) { - var patches = compare_1.compare(this.state, newState); - this.state = newState; - this.checkPatches(patches, this.listeners, this.defaultListener); - return patches; - }; - StateContainer.prototype.registerPlaceholder = function (placeholder, matcher) { - this.matcherPlaceholders[placeholder] = matcher; - }; - StateContainer.prototype.listen = function (segments, callback, immediate) { - var _this = this; - var rules; - if (typeof (segments) === "function") { - rules = []; - callback = segments; - } - else { - rules = segments.split("/"); - } - if (callback.length > 1) { - console.warn(".listen() accepts only one parameter."); - } - var listener = { - callback: callback, - rawRules: rules, - rules: rules.map(function (segment) { - if (typeof (segment) === "string") { - // replace placeholder matchers - return (segment.indexOf(":") === 0) - ? _this.matcherPlaceholders[segment] || _this.matcherPlaceholders[":*"] - : new RegExp("^" + segment + "$"); - } - else { - return segment; - } - }) - }; - if (rules.length === 0) { - this.defaultListener = listener; - } - else { - this.listeners.push(listener); - } - // immediatelly try to trigger this listener. - if (immediate) { - this.checkPatches(compare_1.compare({}, this.state), [listener]); - } - return listener; - }; - StateContainer.prototype.removeListener = function (listener) { - for (var i = this.listeners.length - 1; i >= 0; i--) { - if (this.listeners[i] === listener) { - this.listeners.splice(i, 1); - } - } - }; - StateContainer.prototype.removeAllListeners = function () { - this.reset(); - }; - StateContainer.prototype.checkPatches = function (patches, listeners, defaultListener) { - for (var j = 0, len = listeners.length; j < len; j++) { - var listener = listeners[j]; - for (var i = patches.length - 1; i >= 0; i--) { - var pathVariables = listener && this.getPathVariables(patches[i], listener); - if (pathVariables) { - listener.callback({ - path: pathVariables, - rawPath: patches[i].path, - operation: patches[i].operation, - value: patches[i].value - }); - patches[i].matched = true; - } - } - } - // trigger default listener callback with each unmatched patch - if (defaultListener) { - for (var i = patches.length - 1; i >= 0; i--) { - if (!patches[i].matched) { - defaultListener.callback(patches[i]); - } - } - } - }; - StateContainer.prototype.getPathVariables = function (patch, listener) { - // skip if rules count differ from patch - if (patch.path.length !== listener.rules.length) { - return false; - } - var path = {}; - for (var i = 0, len = listener.rules.length; i < len; i++) { - var matches = patch.path[i].match(listener.rules[i]); - if (!matches || matches.length === 0 || matches.length > 2) { - return false; - } - else if (listener.rawRules[i].substr(0, 1) === ":") { - path[listener.rawRules[i].substr(1)] = matches[1]; - } - } - return path; - }; - StateContainer.prototype.reset = function () { - this.listeners = []; +// +// Polyfills for legacy environments +// +/* + * Support Android 4.4.x + */ +if (!ArrayBuffer.isView) { + ArrayBuffer.isView = function (a) { + return a !== null && typeof (a) === 'object' && a.buffer instanceof ArrayBuffer; }; - return StateContainer; -}()); -exports.StateContainer = StateContainer; +} /***/ }), -/* 27 */ +/* 17 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function compare(tree1, tree2) { - var patches = []; - generate(tree1, tree2, patches, []); - return patches; -} -exports.compare = compare; -function concat(arr, value) { - var newArr = arr.slice(); - newArr.push(value); - return newArr; -} -function objectKeys(obj) { - if (Array.isArray(obj)) { - var keys_1 = new Array(obj.length); - for (var k = 0; k < keys_1.length; k++) { - keys_1[k] = "" + k; - } - return keys_1; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } - if (Object.keys) { - return Object.keys(obj); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var httpie_1 = __webpack_require__(3); +var ServerError_1 = __webpack_require__(18); +var Room_1 = __webpack_require__(4); +var Auth_1 = __webpack_require__(11); +var Push_1 = __webpack_require__(27); +var MatchMakeError = /** @class */ (function (_super) { + __extends(MatchMakeError, _super); + function MatchMakeError(message, code) { + var _this = _super.call(this, message) || this; + _this.code = code; + Object.setPrototypeOf(_this, MatchMakeError.prototype); + return _this; } - var keys = []; - for (var i in obj) { - if (obj.hasOwnProperty(i)) { - keys.push(i); - } + return MatchMakeError; +}(Error)); +exports.MatchMakeError = MatchMakeError; +var Client = /** @class */ (function () { + function Client(endpoint) { + if (endpoint === void 0) { endpoint = location.protocol.replace("http", "ws") + "//" + location.hostname + (location.port && ":" + location.port); } + this.endpoint = endpoint; + this.auth = new Auth_1.Auth(this.endpoint); + this.push = new Push_1.Push(this.endpoint); } - return keys; -} -; -// Dirty check if obj is different from mirror, generate patches and update mirror -function generate(mirror, obj, patches, path) { - var newKeys = objectKeys(obj); - var oldKeys = objectKeys(mirror); - var deleted = false; - for (var t = oldKeys.length - 1; t >= 0; t--) { - var key = oldKeys[t]; - var oldVal = mirror[key]; - if (obj.hasOwnProperty(key) && !(obj[key] === undefined && oldVal !== undefined && Array.isArray(obj) === false)) { - var newVal = obj[key]; - if (typeof oldVal == "object" && oldVal != null && typeof newVal == "object" && newVal != null) { - generate(oldVal, newVal, patches, concat(path, key)); - } - else { - if (oldVal !== newVal) { - patches.push({ - operation: "replace", - path: concat(path, key), - value: newVal, - previousValue: oldVal - }); + Client.prototype.joinOrCreate = function (roomName, options, rootSchema) { + if (options === void 0) { options = {}; } + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.createMatchMakeRequest('joinOrCreate', roomName, options, rootSchema)]; + case 1: return [2 /*return*/, _a.sent()]; } + }); + }); + }; + Client.prototype.create = function (roomName, options, rootSchema) { + if (options === void 0) { options = {}; } + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.createMatchMakeRequest('create', roomName, options, rootSchema)]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + Client.prototype.join = function (roomName, options, rootSchema) { + if (options === void 0) { options = {}; } + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.createMatchMakeRequest('join', roomName, options, rootSchema)]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + Client.prototype.joinById = function (roomId, options, rootSchema) { + if (options === void 0) { options = {}; } + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.createMatchMakeRequest('joinById', roomId, options, rootSchema)]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + Client.prototype.reconnect = function (roomId, sessionId, rootSchema) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.createMatchMakeRequest('joinById', roomId, { sessionId: sessionId }, rootSchema)]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + Client.prototype.getAvailableRooms = function (roomName) { + if (roomName === void 0) { roomName = ""; } + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = this.endpoint.replace("ws", "http") + "/matchmake/" + roomName; + return [4 /*yield*/, httpie_1.get(url, { headers: { 'Accept': 'application/json' } })]; + case 1: return [2 /*return*/, (_a.sent()).data]; + } + }); + }); + }; + Client.prototype.consumeSeatReservation = function (response, rootSchema) { + return __awaiter(this, void 0, void 0, function () { + var room; + return __generator(this, function (_a) { + room = this.createRoom(response.room.name, rootSchema); + room.id = response.room.roomId; + room.sessionId = response.sessionId; + room.connect(this.buildEndpoint(response.room, { sessionId: room.sessionId })); + return [2 /*return*/, new Promise(function (resolve, reject) { + var onError = function (code, message) { return reject(new ServerError_1.ServerError(code, message)); }; + room.onError.once(onError); + room.onJoin.once(function () { + room.onError.remove(onError); + resolve(room); + }); + })]; + }); + }); + }; + Client.prototype.createMatchMakeRequest = function (method, roomName, options, rootSchema) { + if (options === void 0) { options = {}; } + return __awaiter(this, void 0, void 0, function () { + var url, response; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = this.endpoint.replace("ws", "http") + "/matchmake/" + method + "/" + roomName; + // automatically forward auth token, if present + if (this.auth.hasToken) { + options.token = this.auth.token; + } + return [4 /*yield*/, httpie_1.post(url, { + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + body: JSON.stringify(options) + })]; + case 1: + response = (_a.sent()).data; + if (response.error) { + throw new MatchMakeError(response.error, response.code); + } + return [2 /*return*/, this.consumeSeatReservation(response, rootSchema)]; + } + }); + }); + }; + Client.prototype.createRoom = function (roomName, rootSchema) { + return new Room_1.Room(roomName, rootSchema); + }; + Client.prototype.buildEndpoint = function (room, options) { + if (options === void 0) { options = {}; } + var params = []; + for (var name_1 in options) { + if (!options.hasOwnProperty(name_1)) { + continue; } + params.push(name_1 + "=" + options[name_1]); } - else { - patches.push({ operation: "remove", path: concat(path, key) }); - deleted = true; // property has been deleted - } - } - if (!deleted && newKeys.length == oldKeys.length) { - return; - } - for (var t = newKeys.length - 1; t >= 0; t--) { - var key = newKeys[t]; - if (!mirror.hasOwnProperty(key) && obj[key] !== undefined) { - var newVal = obj[key]; - var addPath = concat(path, key); - // compare deeper additions - if (typeof newVal == "object" && newVal != null) { - generate({}, newVal, patches, addPath); - } - patches.push({ operation: "add", path: addPath, value: newVal }); - } - } -} + return this.endpoint + "/" + room.processId + "/" + room.roomId + "?" + params.join('&'); + }; + return Client; +}()); +exports.Client = Client; /***/ }), -/* 28 */ +/* 18 */ /***/ (function(module, exports, __webpack_require__) { -// Fossil SCM delta compression algorithm -// ====================================== -// -// Format: -// http://www.fossil-scm.org/index.html/doc/tip/www/delta_format.wiki -// -// Algorithm: -// http://www.fossil-scm.org/index.html/doc/tip/www/delta_encoder_algorithm.wiki -// -// Original implementation: -// http://www.fossil-scm.org/index.html/artifact/d1b0598adcd650b3551f63b17dfc864e73775c3d -// -// LICENSE -// ------- -// -// Copyright 2014 Dmitry Chestnykh (JavaScript port) -// Copyright 2007 D. Richard Hipp (original C version) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or -// without modification, are permitted provided that the -// following conditions are met: -// -// 1. Redistributions of source code must retain the above -// copyright notice, this list of conditions and the -// following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the -// following disclaimer in the documentation and/or other -// materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS -// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, -// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// The views and conclusions contained in the software and documentation -// are those of the authors and contributors and should not be interpreted -// as representing official policies, either expressed or implied, of anybody -// else. -// -(function(root, factory) { - if ( true && module.exports) module.exports = factory(); - else root.fossilDelta = factory(); -})(this, function() { -'use strict'; - -var fossilDelta = {}; - -// Hash window width in bytes. Must be a power of two. -var NHASH = 16; - -function RollingHash() { - this.a = 0; // hash (16-bit unsigned) - this.b = 0; // values (16-bit unsigned) - this.i = 0; // start of the hash window (16-bit unsigned) - this.z = new Array(NHASH); // the values that have been hashed. -} - -// Initialize the rolling hash using the first NHASH bytes of -// z at the given position. -RollingHash.prototype.init = function(z, pos) { - var a = 0, b = 0, i, x; - for(i = 0; i < NHASH; i++){ - x = z[pos+i]; - a = (a + x) & 0xffff; - b = (b + (NHASH-i)*x) & 0xffff; - this.z[i] = x; - } - this.a = a & 0xffff; - this.b = b & 0xffff; - this.i = 0; -}; +"use strict"; -// Advance the rolling hash by a single byte "c". -RollingHash.prototype.next = function(c) { - var old = this.z[this.i]; - this.z[this.i] = c; - this.i = (this.i+1)&(NHASH-1); - this.a = (this.a - old + c) & 0xffff; - this.b = (this.b - NHASH*old + this.a) & 0xffff; -}; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +var ServerError = /** @class */ (function (_super) { + __extends(ServerError, _super); + function ServerError(code, message) { + var _this = _super.call(this, message) || this; + _this.name = "ServerError"; + _this.code = code; + return _this; + } + return ServerError; +}(Error)); +exports.ServerError = ServerError; -// Return a 32-bit hash value. -RollingHash.prototype.value = function() { - return ((this.a & 0xffff) | (this.b & 0xffff)<<16)>>>0; -}; -var zDigits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~". - split('').map(function (x) { return x.charCodeAt(0); }); +/***/ }), +/* 19 */ +/***/ (function(module, exports, __webpack_require__) { -var zValue = [ - -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 -]; +"use strict"; -// Reader reads bytes, chars, ints from array. -function Reader(array) { - this.a = array; // source array - this.pos = 0; // current position in array +/** + * Copyright (c) 2014 Ion Drive Software Ltd. + * https://github.com/darrachequesne/notepack/ + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +/** + * Patch for Colyseus: + * ------------------- + * + * added `offset` on Decoder constructor, for messages arriving with a code + * before actual msgpack data + */ +function Decoder(buffer, offset) { + this._offset = offset; + if (buffer instanceof ArrayBuffer) { + this._buffer = buffer; + this._view = new DataView(this._buffer); + } + else if (ArrayBuffer.isView(buffer)) { + this._buffer = buffer.buffer; + this._view = new DataView(this._buffer, buffer.byteOffset, buffer.byteLength); + } + else { + throw new Error('Invalid argument'); + } } - -Reader.prototype.haveBytes = function() { - return this.pos < this.a.length; +function utf8Read(view, offset, length) { + var string = '', chr = 0; + for (var i = offset, end = offset + length; i < end; i++) { + var byte = view.getUint8(i); + if ((byte & 0x80) === 0x00) { + string += String.fromCharCode(byte); + continue; + } + if ((byte & 0xe0) === 0xc0) { + string += String.fromCharCode(((byte & 0x1f) << 6) | + (view.getUint8(++i) & 0x3f)); + continue; + } + if ((byte & 0xf0) === 0xe0) { + string += String.fromCharCode(((byte & 0x0f) << 12) | + ((view.getUint8(++i) & 0x3f) << 6) | + ((view.getUint8(++i) & 0x3f) << 0)); + continue; + } + if ((byte & 0xf8) === 0xf0) { + chr = ((byte & 0x07) << 18) | + ((view.getUint8(++i) & 0x3f) << 12) | + ((view.getUint8(++i) & 0x3f) << 6) | + ((view.getUint8(++i) & 0x3f) << 0); + if (chr >= 0x010000) { // surrogate pair + chr -= 0x010000; + string += String.fromCharCode((chr >>> 10) + 0xD800, (chr & 0x3FF) + 0xDC00); + } + else { + string += String.fromCharCode(chr); + } + continue; + } + throw new Error('Invalid byte ' + byte.toString(16)); + } + return string; +} +Decoder.prototype._array = function (length) { + var value = new Array(length); + for (var i = 0; i < length; i++) { + value[i] = this._parse(); + } + return value; }; - -Reader.prototype.getByte = function() { - var b = this.a[this.pos]; - this.pos++; - if (this.pos > this.a.length) throw new RangeError('out of bounds'); - return b; +Decoder.prototype._map = function (length) { + var key = '', value = {}; + for (var i = 0; i < length; i++) { + key = this._parse(); + value[key] = this._parse(); + } + return value; }; - -Reader.prototype.getChar = function() { - return String.fromCharCode(this.getByte()); +Decoder.prototype._str = function (length) { + var value = utf8Read(this._view, this._offset, length); + this._offset += length; + return value; }; - -// Read base64-encoded unsigned integer. -Reader.prototype.getInt = function(){ - var v = 0, c; - while(this.haveBytes() && (c = zValue[0x7f & this.getByte()]) >= 0) { - v = (v<<6) + c; - } - this.pos--; - return v >>> 0; +Decoder.prototype._bin = function (length) { + var value = this._buffer.slice(this._offset, this._offset + length); + this._offset += length; + return value; +}; +Decoder.prototype._parse = function () { + var prefix = this._view.getUint8(this._offset++); + var value, length = 0, type = 0, hi = 0, lo = 0; + if (prefix < 0xc0) { + // positive fixint + if (prefix < 0x80) { + return prefix; + } + // fixmap + if (prefix < 0x90) { + return this._map(prefix & 0x0f); + } + // fixarray + if (prefix < 0xa0) { + return this._array(prefix & 0x0f); + } + // fixstr + return this._str(prefix & 0x1f); + } + // negative fixint + if (prefix > 0xdf) { + return (0xff - prefix + 1) * -1; + } + switch (prefix) { + // nil + case 0xc0: + return null; + // false + case 0xc2: + return false; + // true + case 0xc3: + return true; + // bin + case 0xc4: + length = this._view.getUint8(this._offset); + this._offset += 1; + return this._bin(length); + case 0xc5: + length = this._view.getUint16(this._offset); + this._offset += 2; + return this._bin(length); + case 0xc6: + length = this._view.getUint32(this._offset); + this._offset += 4; + return this._bin(length); + // ext + case 0xc7: + length = this._view.getUint8(this._offset); + type = this._view.getInt8(this._offset + 1); + this._offset += 2; + return [type, this._bin(length)]; + case 0xc8: + length = this._view.getUint16(this._offset); + type = this._view.getInt8(this._offset + 2); + this._offset += 3; + return [type, this._bin(length)]; + case 0xc9: + length = this._view.getUint32(this._offset); + type = this._view.getInt8(this._offset + 4); + this._offset += 5; + return [type, this._bin(length)]; + // float + case 0xca: + value = this._view.getFloat32(this._offset); + this._offset += 4; + return value; + case 0xcb: + value = this._view.getFloat64(this._offset); + this._offset += 8; + return value; + // uint + case 0xcc: + value = this._view.getUint8(this._offset); + this._offset += 1; + return value; + case 0xcd: + value = this._view.getUint16(this._offset); + this._offset += 2; + return value; + case 0xce: + value = this._view.getUint32(this._offset); + this._offset += 4; + return value; + case 0xcf: + hi = this._view.getUint32(this._offset) * Math.pow(2, 32); + lo = this._view.getUint32(this._offset + 4); + this._offset += 8; + return hi + lo; + // int + case 0xd0: + value = this._view.getInt8(this._offset); + this._offset += 1; + return value; + case 0xd1: + value = this._view.getInt16(this._offset); + this._offset += 2; + return value; + case 0xd2: + value = this._view.getInt32(this._offset); + this._offset += 4; + return value; + case 0xd3: + hi = this._view.getInt32(this._offset) * Math.pow(2, 32); + lo = this._view.getUint32(this._offset + 4); + this._offset += 8; + return hi + lo; + // fixext + case 0xd4: + type = this._view.getInt8(this._offset); + this._offset += 1; + if (type === 0x00) { + this._offset += 1; + return void 0; + } + return [type, this._bin(1)]; + case 0xd5: + type = this._view.getInt8(this._offset); + this._offset += 1; + return [type, this._bin(2)]; + case 0xd6: + type = this._view.getInt8(this._offset); + this._offset += 1; + return [type, this._bin(4)]; + case 0xd7: + type = this._view.getInt8(this._offset); + this._offset += 1; + if (type === 0x00) { + hi = this._view.getInt32(this._offset) * Math.pow(2, 32); + lo = this._view.getUint32(this._offset + 4); + this._offset += 8; + return new Date(hi + lo); + } + return [type, this._bin(8)]; + case 0xd8: + type = this._view.getInt8(this._offset); + this._offset += 1; + return [type, this._bin(16)]; + // str + case 0xd9: + length = this._view.getUint8(this._offset); + this._offset += 1; + return this._str(length); + case 0xda: + length = this._view.getUint16(this._offset); + this._offset += 2; + return this._str(length); + case 0xdb: + length = this._view.getUint32(this._offset); + this._offset += 4; + return this._str(length); + // array + case 0xdc: + length = this._view.getUint16(this._offset); + this._offset += 2; + return this._array(length); + case 0xdd: + length = this._view.getUint32(this._offset); + this._offset += 4; + return this._array(length); + // map + case 0xde: + length = this._view.getUint16(this._offset); + this._offset += 2; + return this._map(length); + case 0xdf: + length = this._view.getUint32(this._offset); + this._offset += 4; + return this._map(length); + } + throw new Error('Could not parse'); }; - - -// Write writes an array. -function Writer() { - this.a = []; +function decode(buffer, offset) { + if (offset === void 0) { offset = 0; } + var decoder = new Decoder(buffer, offset); + var value = decoder._parse(); + if (decoder._offset !== buffer.byteLength) { + throw new Error((buffer.byteLength - decoder._offset) + ' trailing bytes'); + } + return value; } +exports.default = decode; -Writer.prototype.toArray = function() { - return this.a; -}; - -Writer.prototype.putByte = function(b) { - this.a.push(b & 0xff); -}; - -// Write an ASCII character (s is a one-char string). -Writer.prototype.putChar = function(s) { - this.putByte(s.charCodeAt(0)); -}; -// Write a base64 unsigned integer. -Writer.prototype.putInt = function(v){ - var i, j, zBuf = []; - if (v === 0) { - this.putChar('0'); - return; - } - for (i = 0; v > 0; i++, v >>>= 6) - zBuf.push(zDigits[v&0x3f]); - for (j = i-1; j >= 0; j--) - this.putByte(zBuf[j]); -}; +/***/ }), +/* 20 */ +/***/ (function(module, exports, __webpack_require__) { -// Copy from array at start to end. -Writer.prototype.putArray = function(a, start, end) { - for (var i = start; i < end; i++) this.a.push(a[i]); -}; +"use strict"; -// Return the number digits in the base64 representation of a positive integer. -function digitCount(v){ - var i, x; - for (i = 1, x = 64; v >= x; i++, x <<= 6){ /* nothing */ } - return i; +/** + * Copyright (c) 2014 Ion Drive Software Ltd. + * https://github.com/darrachequesne/notepack/ + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +function utf8Write(view, offset, str) { + var c = 0; + for (var i = 0, l = str.length; i < l; i++) { + c = str.charCodeAt(i); + if (c < 0x80) { + view.setUint8(offset++, c); + } + else if (c < 0x800) { + view.setUint8(offset++, 0xc0 | (c >> 6)); + view.setUint8(offset++, 0x80 | (c & 0x3f)); + } + else if (c < 0xd800 || c >= 0xe000) { + view.setUint8(offset++, 0xe0 | (c >> 12)); + view.setUint8(offset++, 0x80 | (c >> 6) & 0x3f); + view.setUint8(offset++, 0x80 | (c & 0x3f)); + } + else { + i++; + c = 0x10000 + (((c & 0x3ff) << 10) | (str.charCodeAt(i) & 0x3ff)); + view.setUint8(offset++, 0xf0 | (c >> 18)); + view.setUint8(offset++, 0x80 | (c >> 12) & 0x3f); + view.setUint8(offset++, 0x80 | (c >> 6) & 0x3f); + view.setUint8(offset++, 0x80 | (c & 0x3f)); + } + } } +function utf8Length(str) { + var c = 0, length = 0; + for (var i = 0, l = str.length; i < l; i++) { + c = str.charCodeAt(i); + if (c < 0x80) { + length += 1; + } + else if (c < 0x800) { + length += 2; + } + else if (c < 0xd800 || c >= 0xe000) { + length += 3; + } + else { + i++; + length += 4; + } + } + return length; +} +function _encode(bytes, defers, value) { + var type = typeof value, i = 0, l = 0, hi = 0, lo = 0, length = 0, size = 0; + if (type === 'string') { + length = utf8Length(value); + // fixstr + if (length < 0x20) { + bytes.push(length | 0xa0); + size = 1; + } + // str 8 + else if (length < 0x100) { + bytes.push(0xd9, length); + size = 2; + } + // str 16 + else if (length < 0x10000) { + bytes.push(0xda, length >> 8, length); + size = 3; + } + // str 32 + else if (length < 0x100000000) { + bytes.push(0xdb, length >> 24, length >> 16, length >> 8, length); + size = 5; + } + else { + throw new Error('String too long'); + } + defers.push({ _str: value, _length: length, _offset: bytes.length }); + return size + length; + } + if (type === 'number') { + // TODO: encode to float 32? + // float 64 + if (Math.floor(value) !== value || !isFinite(value)) { + bytes.push(0xcb); + defers.push({ _float: value, _length: 8, _offset: bytes.length }); + return 9; + } + if (value >= 0) { + // positive fixnum + if (value < 0x80) { + bytes.push(value); + return 1; + } + // uint 8 + if (value < 0x100) { + bytes.push(0xcc, value); + return 2; + } + // uint 16 + if (value < 0x10000) { + bytes.push(0xcd, value >> 8, value); + return 3; + } + // uint 32 + if (value < 0x100000000) { + bytes.push(0xce, value >> 24, value >> 16, value >> 8, value); + return 5; + } + // uint 64 + hi = (value / Math.pow(2, 32)) >> 0; + lo = value >>> 0; + bytes.push(0xcf, hi >> 24, hi >> 16, hi >> 8, hi, lo >> 24, lo >> 16, lo >> 8, lo); + return 9; + } + else { + // negative fixnum + if (value >= -0x20) { + bytes.push(value); + return 1; + } + // int 8 + if (value >= -0x80) { + bytes.push(0xd0, value); + return 2; + } + // int 16 + if (value >= -0x8000) { + bytes.push(0xd1, value >> 8, value); + return 3; + } + // int 32 + if (value >= -0x80000000) { + bytes.push(0xd2, value >> 24, value >> 16, value >> 8, value); + return 5; + } + // int 64 + hi = Math.floor(value / Math.pow(2, 32)); + lo = value >>> 0; + bytes.push(0xd3, hi >> 24, hi >> 16, hi >> 8, hi, lo >> 24, lo >> 16, lo >> 8, lo); + return 9; + } + } + if (type === 'object') { + // nil + if (value === null) { + bytes.push(0xc0); + return 1; + } + if (Array.isArray(value)) { + length = value.length; + // fixarray + if (length < 0x10) { + bytes.push(length | 0x90); + size = 1; + } + // array 16 + else if (length < 0x10000) { + bytes.push(0xdc, length >> 8, length); + size = 3; + } + // array 32 + else if (length < 0x100000000) { + bytes.push(0xdd, length >> 24, length >> 16, length >> 8, length); + size = 5; + } + else { + throw new Error('Array too large'); + } + for (i = 0; i < length; i++) { + size += _encode(bytes, defers, value[i]); + } + return size; + } + // fixext 8 / Date + if (value instanceof Date) { + var time = value.getTime(); + hi = Math.floor(time / Math.pow(2, 32)); + lo = time >>> 0; + bytes.push(0xd7, 0, hi >> 24, hi >> 16, hi >> 8, hi, lo >> 24, lo >> 16, lo >> 8, lo); + return 10; + } + if (value instanceof ArrayBuffer) { + length = value.byteLength; + // bin 8 + if (length < 0x100) { + bytes.push(0xc4, length); + size = 2; + } + else + // bin 16 + if (length < 0x10000) { + bytes.push(0xc5, length >> 8, length); + size = 3; + } + else + // bin 32 + if (length < 0x100000000) { + bytes.push(0xc6, length >> 24, length >> 16, length >> 8, length); + size = 5; + } + else { + throw new Error('Buffer too large'); + } + defers.push({ _bin: value, _length: length, _offset: bytes.length }); + return size + length; + } + if (typeof value.toJSON === 'function') { + return _encode(bytes, defers, value.toJSON()); + } + var keys = [], key = ''; + var allKeys = Object.keys(value); + for (i = 0, l = allKeys.length; i < l; i++) { + key = allKeys[i]; + if (typeof value[key] !== 'function') { + keys.push(key); + } + } + length = keys.length; + // fixmap + if (length < 0x10) { + bytes.push(length | 0x80); + size = 1; + } + // map 16 + else if (length < 0x10000) { + bytes.push(0xde, length >> 8, length); + size = 3; + } + // map 32 + else if (length < 0x100000000) { + bytes.push(0xdf, length >> 24, length >> 16, length >> 8, length); + size = 5; + } + else { + throw new Error('Object too large'); + } + for (i = 0; i < length; i++) { + key = keys[i]; + size += _encode(bytes, defers, key); + size += _encode(bytes, defers, value[key]); + } + return size; + } + // false/true + if (type === 'boolean') { + bytes.push(value ? 0xc3 : 0xc2); + return 1; + } + // fixext 1 / undefined + if (type === 'undefined') { + bytes.push(0xd4, 0, 0); + return 3; + } + throw new Error('Could not encode'); +} +function encode(value) { + var bytes = []; + var defers = []; + var size = _encode(bytes, defers, value); + var buf = new ArrayBuffer(size); + var view = new DataView(buf); + var deferIndex = 0; + var deferWritten = 0; + var nextOffset = -1; + if (defers.length > 0) { + nextOffset = defers[0]._offset; + } + var defer, deferLength = 0, offset = 0; + for (var i = 0, l = bytes.length; i < l; i++) { + view.setUint8(deferWritten + i, bytes[i]); + if (i + 1 !== nextOffset) { + continue; + } + defer = defers[deferIndex]; + deferLength = defer._length; + offset = deferWritten + nextOffset; + if (defer._bin) { + var bin = new Uint8Array(defer._bin); + for (var j = 0; j < deferLength; j++) { + view.setUint8(offset + j, bin[j]); + } + } + else if (defer._str) { + utf8Write(view, offset, defer._str); + } + else if (defer._float !== undefined) { + view.setFloat64(offset, defer._float); + } + deferIndex++; + deferWritten += deferLength; + if (defers[deferIndex]) { + nextOffset = defers[deferIndex]._offset; + } + } + return buf; +} +exports.default = encode; -// Return a 32-bit checksum of the array. -function checksum(arr) { - var sum0 = 0, sum1 = 0, sum2 = 0, sum3 = 0, - z = 0, N = arr.length; - //TODO measure if this unrolling is helpful. - while (N >= 16) { - sum0 = sum0 + arr[z+0] | 0; - sum1 = sum1 + arr[z+1] | 0; - sum2 = sum2 + arr[z+2] | 0; - sum3 = sum3 + arr[z+3] | 0; - - sum0 = sum0 + arr[z+4] | 0; - sum1 = sum1 + arr[z+5] | 0; - sum2 = sum2 + arr[z+6] | 0; - sum3 = sum3 + arr[z+7] | 0; - sum0 = sum0 + arr[z+8] | 0; - sum1 = sum1 + arr[z+9] | 0; - sum2 = sum2 + arr[z+10] | 0; - sum3 = sum3 + arr[z+11] | 0; +/***/ }), +/* 21 */ +/***/ (function(module, exports, __webpack_require__) { - sum0 = sum0 + arr[z+12] | 0; - sum1 = sum1 + arr[z+13] | 0; - sum2 = sum2 + arr[z+14] | 0; - sum3 = sum3 + arr[z+15] | 0; +"use strict"; - z += 16; - N -= 16; - } - while (N >= 4) { - sum0 = sum0 + arr[z+0] | 0; - sum1 = sum1 + arr[z+1] | 0; - sum2 = sum2 + arr[z+2] | 0; - sum3 = sum3 + arr[z+3] | 0; - z += 4; - N -= 4; - } - sum3 = (((sum3 + (sum2 << 8) | 0) + (sum1 << 16) | 0) + (sum0 << 24) | 0); - /* jshint -W086 */ - switch (N) { - case 3: sum3 = sum3 + (arr[z+2] << 8) | 0; /* falls through */ - case 2: sum3 = sum3 + (arr[z+1] << 16) | 0; /* falls through */ - case 1: sum3 = sum3 + (arr[z+0] << 24) | 0; /* falls through */ - } - return sum3 >>> 0; +Object.defineProperty(exports, "__esModule", { value: true }); +var EventEmitter = /** @class */ (function () { + function EventEmitter() { + this.handlers = []; + } + EventEmitter.prototype.register = function (cb, once) { + if (once === void 0) { once = false; } + this.handlers.push(cb); + return this; + }; + EventEmitter.prototype.invoke = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + this.handlers.forEach(function (handler) { return handler.apply(void 0, args); }); + }; + EventEmitter.prototype.invokeAsync = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + return Promise.all(this.handlers.map(function (handler) { return handler.apply(void 0, args); })); + }; + EventEmitter.prototype.remove = function (cb) { + var index = this.handlers.indexOf(cb); + this.handlers[index] = this.handlers[this.handlers.length - 1]; + this.handlers.pop(); + }; + EventEmitter.prototype.clear = function () { + this.handlers = []; + }; + return EventEmitter; +}()); +exports.EventEmitter = EventEmitter; +function createSignal() { + var emitter = new EventEmitter(); + function register(cb) { + return emitter.register(cb, this === null); + } + ; + register.once = function (cb) { + var callback = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + cb.apply(void 0, args); + emitter.remove(callback); + }; + emitter.register(callback); + }; + register.remove = function (cb) { return emitter.remove(cb); }; + register.invoke = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + return emitter.invoke.apply(emitter, args); + }; + register.invokeAsync = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + return emitter.invokeAsync.apply(emitter, args); + }; + register.clear = function () { return emitter.clear(); }; + return register; } +exports.createSignal = createSignal; -// Create a new delta from src to out. -fossilDelta.create = function(src, out) { - var zDelta = new Writer(); - var lenOut = out.length; - var lenSrc = src.length; - var i, lastRead = -1; - - zDelta.putInt(lenOut); - zDelta.putChar('\n'); - - // If the source is very small, it means that we have no - // chance of ever doing a copy command. Just output a single - // literal segment for the entire target and exit. - if (lenSrc <= NHASH) { - zDelta.putInt(lenOut); - zDelta.putChar(':'); - zDelta.putArray(out, 0, lenOut); - zDelta.putInt(checksum(out)); - zDelta.putChar(';'); - return zDelta.toArray(); - } - // Compute the hash table used to locate matching sections in the source. - var nHash = Math.ceil(lenSrc / NHASH); - var collide = new Array(nHash); - var landmark = new Array(nHash); - for (i = 0; i < collide.length; i++) collide[i] = -1; - for (i = 0; i < landmark.length; i++) landmark[i] = -1; - var hv, h = new RollingHash(); - for (i = 0; i < lenSrc-NHASH; i += NHASH) { - h.init(src, i); - hv = h.value() % nHash; - collide[i/NHASH] = landmark[hv]; - landmark[hv] = i/NHASH; - } +/***/ }), +/* 22 */ +/***/ (function(module, exports, __webpack_require__) { - var base = 0; - var iSrc, iBlock, bestCnt, bestOfst, bestLitsz; - while (base+NHASH= 0 && (limit--)>0 ) { - // - // The hash window has identified a potential match against - // landmark block iBlock. But we need to investigate further. - // - // Look for a region in zOut that matches zSrc. Anchor the search - // at zSrc[iSrc] and zOut[base+i]. Do not include anything prior to - // zOut[base] or after zOut[outLen] nor anything after zSrc[srcLen]. - // - // Set cnt equal to the length of the match and set ofst so that - // zSrc[ofst] is the first element of the match. litsz is the number - // of characters between zOut[base] and the beginning of the match. - // sz will be the overhead (in bytes) needed to encode the copy - // command. Only generate copy command if the overhead of the - // copy command is less than the amount of literal text to be copied. - // - var cnt, ofst, litsz; - var j, k, x, y; - var sz; +"use strict"; - // Beginning at iSrc, match forwards as far as we can. - // j counts the number of characters that match. - iSrc = iBlock*NHASH; - for (j = 0, x = iSrc, y = base+i; x < lenSrc && y < lenOut; j++, x++, y++) { - if (src[x] !== out[y]) break; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var websocket_1 = __importDefault(__webpack_require__(23)); +var Connection = /** @class */ (function (_super) { + __extends(Connection, _super); + function Connection(url, autoConnect) { + if (autoConnect === void 0) { autoConnect = true; } + var _this = _super.call(this, url, undefined, { connect: autoConnect }) || this; + _this._enqueuedCalls = []; + return _this; + } + Connection.prototype.onOpenCallback = function (event) { + _super.prototype.onOpenCallback.call(this); + this.binaryType = 'arraybuffer'; + if (this._enqueuedCalls.length > 0) { + for (var _i = 0, _a = this._enqueuedCalls; _i < _a.length; _i++) { + var _b = _a[_i], method = _b[0], args = _b[1]; + this[method].apply(this, args); + } + // clear enqueued calls. + this._enqueuedCalls = []; } - j--; - - // Beginning at iSrc-1, match backwards as far as we can. - // k counts the number of characters that match. - for (k = 1; k < iSrc && k <= i; k++) { - if (src[iSrc-k] !== out[base+i-k]) break; + }; + Connection.prototype.send = function (data) { + if (this.ws.readyState === websocket_1.default.OPEN) { + if (data instanceof ArrayBuffer) { + return _super.prototype.send.call(this, data); + } + else if (Array.isArray(data)) { + return _super.prototype.send.call(this, (new Uint8Array(data)).buffer); + } } - k--; - - // Compute the offset and size of the matching region. - ofst = iSrc-k; - cnt = j+k+1; - litsz = i-k; // Number of bytes of literal text before the copy - // sz will hold the number of bytes needed to encode the "insert" - // command and the copy command, not counting the "insert" text. - sz = digitCount(i-k)+digitCount(cnt)+digitCount(ofst)+3; - if (cnt >= sz && cnt > bestCnt) { - // Remember this match only if it is the best so far and it - // does not increase the file size. - bestCnt = cnt; - bestOfst = iSrc-k; - bestLitsz = litsz; + else { + // WebSocket not connected. + // Enqueue data to be sent when readyState == OPEN + this._enqueuedCalls.push(['send', [data]]); } + }; + return Connection; +}(websocket_1.default)); +exports.Connection = Connection; - // Check the next matching block - iBlock = collide[iBlock]; - } - // We have a copy command that does not cause the delta to be larger - // than a literal insert. So add the copy command to the delta. - if (bestCnt > 0) { - if (bestLitsz > 0) { - // Add an insert command before the copy. - zDelta.putInt(bestLitsz); - zDelta.putChar(':'); - zDelta.putArray(out, base, base+bestLitsz); - base += bestLitsz; - } - base += bestCnt; - zDelta.putInt(bestCnt); - zDelta.putChar('@'); - zDelta.putInt(bestOfst); - zDelta.putChar(','); - if (bestOfst + bestCnt -1 > lastRead) { - lastRead = bestOfst + bestCnt - 1; - } - bestCnt = 0; - break; - } +/***/ }), +/* 23 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; +Object.defineProperty(exports,"__esModule",{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i2&&arguments[2]!==undefined?arguments[2]:{};_classCallCheck(this,WebSocketClient);this.url=url;this.protocols=protocols;this.reconnectEnabled=true;this.listeners={};this.backoff=createBackoff(options.backoff||'exponential',options);this.backoff.onReady=this.onBackoffReady.bind(this);if(typeof options.connect==="undefined"||options.connect){this.open();}}_createClass(WebSocketClient,[{key:'open',value:function open(){var reconnect=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;this.isReconnect=reconnect;// keep binaryType used on previous WebSocket connection +var binaryType=this.ws&&this.ws.binaryType;this.ws=new WebSocketImpl(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);if(binaryType){this.ws.binaryType=binaryType;}}/** + * @ignore + */},{key:'onBackoffReady',value:function onBackoffReady(number,delay){// console.log("onBackoffReady", number + ' ' + delay + 'ms'); +this.open(true);}/** + * @ignore + */},{key:'onCloseCallback',value:function onCloseCallback(e){if(!this.isReconnect&&this.listeners['onclose']){this.listeners['onclose'].apply(null,arguments);}if(this.reconnectEnabled&&e.code<3000){this.backoff.backoff();}}/** + * @ignore + */},{key:'onErrorCallback',value:function onErrorCallback(){if(this.listeners['onerror']){this.listeners['onerror'].apply(null,arguments);}}/** + * @ignore + */},{key:'onMessageCallback',value:function onMessageCallback(){if(this.listeners['onmessage']){this.listeners['onmessage'].apply(null,arguments);}}/** + * @ignore + */},{key:'onOpenCallback',value:function onOpenCallback(){if(this.listeners['onopen']){this.listeners['onopen'].apply(null,arguments);}if(this.isReconnect&&this.listeners['onreconnect']){this.listeners['onreconnect'].apply(null,arguments);}this.isReconnect=false;}/** + * The number of bytes of data that have been queued using calls to send() + * but not yet transmitted to the network. This value does not reset to zero + * when the connection is closed; if you keep calling send(), this will + * continue to climb. + * + * @type unsigned long + * @readonly + */},{key:'close',/** + * Closes the WebSocket connection or connection attempt, if any. If the + * connection is already CLOSED, this method does nothing. + * + * @param code A numeric value indicating the status code explaining why the connection is being closed. If this parameter is not specified, a default value of 1000 (indicating a normal "transaction complete" closure) is assumed. See the list of status codes on the CloseEvent page for permitted values. + * @param reason A human-readable string explaining why the connection is closing. This string must be no longer than 123 bytes of UTF-8 text (not characters). + * + * @return void + */value:function close(code,reason){if(typeof code=='undefined'){code=1000;}this.reconnectEnabled=false;this.ws.close(code,reason);}/** + * Transmits data to the server over the WebSocket connection. + * @param data DOMString|ArrayBuffer|Blob + * @return void + */},{key:'send',value:function send(data){this.ws.send(data);}/** + * An event listener to be called when the WebSocket connection's readyState changes to CLOSED. The listener receives a CloseEvent named "close". + * @param listener EventListener + */},{key:'bufferedAmount',get:function get(){return this.ws.bufferedAmount;}/** + * The current state of the connection; this is one of the Ready state constants. + * @type unsigned short + * @readonly + */},{key:'readyState',get:function get(){return this.ws.readyState;}/** + * A string indicating the type of binary data being transmitted by the + * connection. This should be either "blob" if DOM Blob objects are being + * used or "arraybuffer" if ArrayBuffer objects are being used. + * @type DOMString + */},{key:'binaryType',get:function get(){return this.ws.binaryType;},set:function set(binaryType){this.ws.binaryType=binaryType;}/** + * The extensions selected by the server. This is currently only the empty + * string or a list of extensions as negotiated by the connection. + * @type DOMString + */},{key:'extensions',get:function get(){return this.ws.extensions;},set:function set(extensions){this.ws.extensions=extensions;}/** + * A string indicating the name of the sub-protocol the server selected; + * this will be one of the strings specified in the protocols parameter when + * creating the WebSocket object. + * @type DOMString + */},{key:'protocol',get:function get(){return this.ws.protocol;},set:function set(protocol){this.ws.protocol=protocol;}},{key:'onclose',set:function set(listener){this.listeners['onclose']=listener;},get:function get(){return this.listeners['onclose'];}/** + * An event listener to be called when an error occurs. This is a simple event named "error". + * @param listener EventListener + */},{key:'onerror',set:function set(listener){this.listeners['onerror']=listener;},get:function get(){return this.listeners['onerror'];}/** + * An event listener to be called when a message is received from the server. The listener receives a MessageEvent named "message". + * @param listener EventListener + */},{key:'onmessage',set:function set(listener){this.listeners['onmessage']=listener;},get:function get(){return this.listeners['onmessage'];}/** + * An event listener to be called when the WebSocket connection's readyState changes to OPEN; this indicates that the connection is ready to send and receive data. The event is a simple one with the name "open". + * @param listener EventListener + */},{key:'onopen',set:function set(listener){this.listeners['onopen']=listener;},get:function get(){return this.listeners['onopen'];}/** + * @param listener EventListener + */},{key:'onreconnect',set:function set(listener){this.listeners['onreconnect']=listener;},get:function get(){return this.listeners['onreconnect'];}}]);return WebSocketClient;}();/** + * The connection is not yet open. + */WebSocketClient.CONNECTING=WebSocketImpl.CONNECTING;/** + * The connection is open and ready to communicate. + */WebSocketClient.OPEN=WebSocketImpl.OPEN;/** + * The connection is in the process of closing. + */WebSocketClient.CLOSING=WebSocketImpl.CLOSING;/** + * The connection is closed or couldn't be opened. + */WebSocketClient.CLOSED=WebSocketImpl.CLOSED;exports.default=WebSocketClient; + +/***/ }), +/* 24 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; +Object.defineProperty(exports,"__esModule",{value:true});exports.createBackoff=createBackoff;var backoff={exponential:function exponential(attempt,delay){return Math.floor(Math.random()*Math.pow(2,attempt)*delay);},fibonacci:function fibonacci(attempt,delay){var current=1;if(attempt>current){var prev=1,current=2;for(var index=2;index= lenOut){ - // We have reached the end and have not found any - // matches. Do an "insert" for everything that does not match - zDelta.putInt(lenOut-base); - zDelta.putChar(':'); - zDelta.putArray(out, base, base+lenOut-base); - base = lenOut; - break; - } +/***/ }), +/* 25 */ +/***/ (function(module, exports) { - // Advance the hash by one character. Keep looking for a match. - h.next(out[base+i+NHASH]); - i++; - } - } - // Output a final "insert" record to get all the text at the end of - // the file that does not match anything in the source. - if(base < lenOut) { - zDelta.putInt(lenOut-base); - zDelta.putChar(':'); - zDelta.putArray(out, base, base+lenOut-base); - } - // Output the final checksum record. - zDelta.putInt(checksum(out)); - zDelta.putChar(';'); - return zDelta.toArray(); -}; +/* (ignored) */ -// Return the size (in bytes) of the output from applying a delta. -fossilDelta.outputSize = function(delta){ - var zDelta = new Reader(delta); - var size = zDelta.getInt(); - if (zDelta.getChar() !== '\n') - throw new Error('size integer not terminated by \'\\n\''); - return size; -}; +/***/ }), +/* 26 */ +/***/ (function(module, exports, __webpack_require__) { -// Apply a delta. -fossilDelta.apply = function(src, delta, opts) { - var limit, total = 0; - var zDelta = new Reader(delta); - var lenSrc = src.length; - var lenDelta = delta.length; +"use strict"; - limit = zDelta.getInt(); - if (zDelta.getChar() !== '\n') - throw new Error('size integer not terminated by \'\\n\''); - var zOut = new Writer(); - while(zDelta.haveBytes()) { - var cnt, ofst; - cnt = zDelta.getInt(); +/** + * We do not assign 'storage' to window.localStorage immediatelly for React + * Native compatibility. window.localStorage is not present when this module is + * loaded. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +var storage; +function getStorage() { + if (!storage) { + storage = (typeof (cc) !== 'undefined' && cc.sys && cc.sys.localStorage) + ? cc.sys.localStorage // compatibility with cocos creator + : typeof (window) !== "undefined" && window.localStorage //RN does have window object at this point, but localStorage is not defined + ? window.localStorage // regular browser environment + : { + cache: {}, + setItem: function (key, value) { this.cache[key] = value; }, + getItem: function (key) { this.cache[key]; }, + removeItem: function (key) { delete this.cache[key]; }, + }; + } + return storage; +} +function setItem(key, value) { + getStorage().setItem(key, value); +} +exports.setItem = setItem; +function removeItem(key) { + getStorage().removeItem(key); +} +exports.removeItem = removeItem; +function getItem(key, callback) { + var value = getStorage().getItem(key); + if (typeof (Promise) === 'undefined' || // old browsers + !(value instanceof Promise)) { + // browser has synchronous return + callback(value); + } + else { + // react-native is asynchronous + value.then(function (id) { return callback(id); }); + } +} +exports.getItem = getItem; - switch (zDelta.getChar()) { - case '@': - ofst = zDelta.getInt(); - if (zDelta.haveBytes() && zDelta.getChar() !== ',') - throw new Error('copy command not terminated by \',\''); - total += cnt; - if (total > limit) - throw new Error('copy exceeds output file size'); - if (ofst+cnt > lenSrc) - throw new Error('copy extends past end of input'); - zOut.putArray(src, ofst, ofst+cnt); - break; - case ':': - total += cnt; - if (total > limit) - throw new Error('insert command gives an output larger than predicted'); - if (cnt > lenDelta) - throw new Error('insert count exceeds size of delta'); - zOut.putArray(zDelta.a, zDelta.pos, zDelta.pos+cnt); - zDelta.pos += cnt; - break; +/***/ }), +/* 27 */ +/***/ (function(module, exports, __webpack_require__) { - case ';': - var out = zOut.toArray(); - if ((!opts || opts.verifyChecksum !== false) && cnt !== checksum(out)) - throw new Error('bad checksum'); - if (total !== limit) - throw new Error('generated size does not match predicted size'); - return out; +"use strict"; - default: - throw new Error('unknown delta operator'); +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } - } - throw new Error('unterminated delta'); }; - -return fossilDelta; - -}); +Object.defineProperty(exports, "__esModule", { value: true }); +var Push = /** @class */ (function () { + function Push(endpoint) { + this.endpoint = endpoint.replace("ws", "http"); + } + Push.prototype.register = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + this.check(); + return [4 /*yield*/, this.registerServiceWorker()]; + case 1: + _a.sent(); + return [4 /*yield*/, this.requestNotificationPermission()]; + case 2: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + ; + Push.prototype.registerServiceWorker = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, navigator.serviceWorker.register(this.endpoint + "/push")]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + Push.prototype.requestNotificationPermission = function () { + return __awaiter(this, void 0, void 0, function () { + var permission; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, window["Notification"].requestPermission()]; + case 1: + permission = _a.sent(); + // value of permission can be 'granted', 'default', 'denied' + // granted: user has accepted the request + // default: user has dismissed the notification permission popup by clicking on x + // denied: user has denied the request. + if (permission !== "granted") { + throw new Error("Permission not granted for Notification"); + } + return [2 /*return*/]; + } + }); + }); + }; + Push.prototype.check = function () { + if (!("serviceWorker" in navigator)) { + throw new Error("No Service Worker support!"); + } + if (!("PushManager" in window)) { + throw new Error("No Push API Support!"); + } + }; + return Push; +}()); +exports.Push = Push; /***/ }), -/* 29 */ +/* 28 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; Object.defineProperty(exports, "__esModule", { value: true }); -var schema_1 = __webpack_require__(30); -var SchemaSerializer = /** @class */ (function () { - function SchemaSerializer() { +var state_listener_1 = __webpack_require__(29); +var fossilDelta = __importStar(__webpack_require__(32)); +var msgpack = __importStar(__webpack_require__(5)); +var FossilDeltaSerializer = /** @class */ (function () { + function FossilDeltaSerializer() { + this.api = new state_listener_1.StateContainer({}); } - SchemaSerializer.prototype.setState = function (rawState) { - this.state.decode(rawState); - }; - SchemaSerializer.prototype.getState = function () { - return this.state; + FossilDeltaSerializer.prototype.getState = function () { + return this.api.state; }; - SchemaSerializer.prototype.patch = function (patches) { - this.state.decode(patches); + FossilDeltaSerializer.prototype.setState = function (encodedState) { + this.previousState = new Uint8Array(encodedState); + this.api.set(msgpack.decode(this.previousState)); }; - SchemaSerializer.prototype.teardown = function () { - // this.state.onRemove + FossilDeltaSerializer.prototype.patch = function (binaryPatch) { + // apply patch + this.previousState = new Uint8Array(fossilDelta.apply(this.previousState, binaryPatch)); + // trigger update callbacks + this.api.set(msgpack.decode(this.previousState)); }; - SchemaSerializer.prototype.handshake = function (bytes) { - if (this.state) { - // validate client/server definitinos - var reflection = new schema_1.Reflection(); - reflection.decode(bytes); - } - else { - // initialize reflected state from server - this.state = schema_1.Reflection.decode(bytes); - } + FossilDeltaSerializer.prototype.teardown = function () { + this.api.removeAllListeners(); }; - return SchemaSerializer; + return FossilDeltaSerializer; }()); -exports.SchemaSerializer = SchemaSerializer; +exports.FossilDeltaSerializer = FossilDeltaSerializer; /***/ }), -/* 30 */ +/* 29 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -var Schema_1 = __webpack_require__(0); -exports.Schema = Schema_1.Schema; -var MapSchema_1 = __webpack_require__(2); -exports.MapSchema = MapSchema_1.MapSchema; -var ArraySchema_1 = __webpack_require__(1); -exports.ArraySchema = ArraySchema_1.ArraySchema; -// Reflection -var Reflection_1 = __webpack_require__(33); -exports.Reflection = Reflection_1.Reflection; -exports.ReflectionType = Reflection_1.ReflectionType; -exports.ReflectionField = Reflection_1.ReflectionField; -var annotations_1 = __webpack_require__(11); -// Annotations -exports.type = annotations_1.type; -exports.deprecated = annotations_1.deprecated; -exports.filter = annotations_1.filter; -exports.defineTypes = annotations_1.defineTypes; -// Types -exports.Context = annotations_1.Context; -//# sourceMappingURL=index.js.map +var StateContainer_1 = __webpack_require__(30); +exports.StateContainer = StateContainer_1.StateContainer; + /***/ }), -/* 31 */ +/* 30 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -/** - * Copyright (c) 2018 Endel Dreyer - * Copyright (c) 2014 Ion Drive Software Ltd. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE - */ Object.defineProperty(exports, "__esModule", { value: true }); -/** - * msgpack implementation highly based on notepack.io - * https://github.com/darrachequesne/notepack - */ -function utf8Length(str) { - var c = 0, length = 0; - for (var i = 0, l = str.length; i < l; i++) { - c = str.charCodeAt(i); - if (c < 0x80) { - length += 1; +var compare_1 = __webpack_require__(31); +var StateContainer = /** @class */ (function () { + function StateContainer(state) { + this.listeners = []; + this.matcherPlaceholders = { + ":id": /^([a-zA-Z0-9\-_]+)$/, + ":number": /^([0-9]+)$/, + ":string": /^(\w+)$/, + ":axis": /^([xyz])$/, + ":*": /(.*)/, + }; + this.state = state; + this.reset(); + } + StateContainer.prototype.set = function (newState) { + var patches = compare_1.compare(this.state, newState); + this.state = newState; + this.checkPatches(patches, this.listeners, this.defaultListener); + return patches; + }; + StateContainer.prototype.registerPlaceholder = function (placeholder, matcher) { + this.matcherPlaceholders[placeholder] = matcher; + }; + StateContainer.prototype.listen = function (segments, callback, immediate) { + var _this = this; + var rules; + if (typeof (segments) === "function") { + rules = []; + callback = segments; } - else if (c < 0x800) { - length += 2; + else { + rules = segments.split("/"); } - else if (c < 0xd800 || c >= 0xe000) { - length += 3; + if (callback.length > 1) { + console.warn(".listen() accepts only one parameter."); + } + var listener = { + callback: callback, + rawRules: rules, + rules: rules.map(function (segment) { + if (typeof (segment) === "string") { + // replace placeholder matchers + return (segment.indexOf(":") === 0) + ? _this.matcherPlaceholders[segment] || _this.matcherPlaceholders[":*"] + : new RegExp("^" + segment + "$"); + } + else { + return segment; + } + }) + }; + if (rules.length === 0) { + this.defaultListener = listener; } else { - i++; - length += 4; + this.listeners.push(listener); + } + // immediatelly try to trigger this listener. + if (immediate) { + this.checkPatches(compare_1.compare({}, this.state), [listener]); + } + return listener; + }; + StateContainer.prototype.removeListener = function (listener) { + for (var i = this.listeners.length - 1; i >= 0; i--) { + if (this.listeners[i] === listener) { + this.listeners.splice(i, 1); + } + } + }; + StateContainer.prototype.removeAllListeners = function () { + this.reset(); + }; + StateContainer.prototype.checkPatches = function (patches, listeners, defaultListener) { + for (var j = 0, len = listeners.length; j < len; j++) { + var listener = listeners[j]; + for (var i = patches.length - 1; i >= 0; i--) { + var pathVariables = listener && this.getPathVariables(patches[i], listener); + if (pathVariables) { + listener.callback({ + path: pathVariables, + rawPath: patches[i].path, + operation: patches[i].operation, + value: patches[i].value + }); + patches[i].matched = true; + } + } + } + // trigger default listener callback with each unmatched patch + if (defaultListener) { + for (var i = patches.length - 1; i >= 0; i--) { + if (!patches[i].matched) { + defaultListener.callback(patches[i]); + } + } + } + }; + StateContainer.prototype.getPathVariables = function (patch, listener) { + // skip if rules count differ from patch + if (patch.path.length !== listener.rules.length) { + return false; + } + var path = {}; + for (var i = 0, len = listener.rules.length; i < len; i++) { + var matches = patch.path[i].match(listener.rules[i]); + if (!matches || matches.length === 0 || matches.length > 2) { + return false; + } + else if (listener.rawRules[i].substr(0, 1) === ":") { + path[listener.rawRules[i].substr(1)] = matches[1]; + } + } + return path; + }; + StateContainer.prototype.reset = function () { + this.listeners = []; + }; + return StateContainer; +}()); +exports.StateContainer = StateContainer; + + +/***/ }), +/* 31 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +function compare(tree1, tree2) { + var patches = []; + generate(tree1, tree2, patches, []); + return patches; +} +exports.compare = compare; +function concat(arr, value) { + var newArr = arr.slice(); + newArr.push(value); + return newArr; +} +function objectKeys(obj) { + if (Array.isArray(obj)) { + var keys_1 = new Array(obj.length); + for (var k = 0; k < keys_1.length; k++) { + keys_1[k] = "" + k; + } + return keys_1; + } + if (Object.keys) { + return Object.keys(obj); + } + var keys = []; + for (var i in obj) { + if (obj.hasOwnProperty(i)) { + keys.push(i); } } - return length; + return keys; } -function utf8Write(view, offset, str) { - var c = 0; - for (var i = 0, l = str.length; i < l; i++) { - c = str.charCodeAt(i); - if (c < 0x80) { - view[offset++] = c; - } - else if (c < 0x800) { - view[offset++] = 0xc0 | (c >> 6); - view[offset++] = 0x80 | (c & 0x3f); - } - else if (c < 0xd800 || c >= 0xe000) { - view[offset++] = 0xe0 | (c >> 12); - view[offset++] = 0x80 | (c >> 6 & 0x3f); - view[offset++] = 0x80 | (c & 0x3f); +; +// Dirty check if obj is different from mirror, generate patches and update mirror +function generate(mirror, obj, patches, path) { + var newKeys = objectKeys(obj); + var oldKeys = objectKeys(mirror); + var deleted = false; + for (var t = oldKeys.length - 1; t >= 0; t--) { + var key = oldKeys[t]; + var oldVal = mirror[key]; + if (obj.hasOwnProperty(key) && !(obj[key] === undefined && oldVal !== undefined && Array.isArray(obj) === false)) { + var newVal = obj[key]; + if (typeof oldVal == "object" && oldVal != null && typeof newVal == "object" && newVal != null) { + generate(oldVal, newVal, patches, concat(path, key)); + } + else { + if (oldVal !== newVal) { + patches.push({ + operation: "replace", + path: concat(path, key), + value: newVal, + previousValue: oldVal + }); + } + } } else { - i++; - c = 0x10000 + (((c & 0x3ff) << 10) | (str.charCodeAt(i) & 0x3ff)); - view[offset++] = 0xf0 | (c >> 18); - view[offset++] = 0x80 | (c >> 12 & 0x3f); - view[offset++] = 0x80 | (c >> 6 & 0x3f); - view[offset++] = 0x80 | (c & 0x3f); + patches.push({ operation: "remove", path: concat(path, key) }); + deleted = true; // property has been deleted + } + } + if (!deleted && newKeys.length == oldKeys.length) { + return; + } + for (var t = newKeys.length - 1; t >= 0; t--) { + var key = newKeys[t]; + if (!mirror.hasOwnProperty(key) && obj[key] !== undefined) { + var newVal = obj[key]; + var addPath = concat(path, key); + // compare deeper additions + if (typeof newVal == "object" && newVal != null) { + generate({}, newVal, patches, addPath); + } + patches.push({ operation: "add", path: addPath, value: newVal }); } } } -exports.utf8Write = utf8Write; -function int8(bytes, value) { - bytes.push(value & 255); -} -exports.int8 = int8; -; -function uint8(bytes, value) { - bytes.push(value & 255); -} -exports.uint8 = uint8; -; -function int16(bytes, value) { - bytes.push(value & 255); - bytes.push((value >> 8) & 255); -} -exports.int16 = int16; -; -function uint16(bytes, value) { - bytes.push(value & 255); - bytes.push((value >> 8) & 255); -} -exports.uint16 = uint16; -; -function int32(bytes, value) { - bytes.push(value & 255); - bytes.push((value >> 8) & 255); - bytes.push((value >> 16) & 255); - bytes.push((value >> 24) & 255); -} -exports.int32 = int32; -; -function uint32(bytes, value) { - var b4 = value >> 24; - var b3 = value >> 16; - var b2 = value >> 8; - var b1 = value; - bytes.push(b1 & 255); - bytes.push(b2 & 255); - bytes.push(b3 & 255); - bytes.push(b4 & 255); -} -exports.uint32 = uint32; -; -function int64(bytes, value) { - var high = Math.floor(value / Math.pow(2, 32)); - var low = value >>> 0; - uint32(bytes, low); - uint32(bytes, high); -} -exports.int64 = int64; -; -function uint64(bytes, value) { - var high = (value / Math.pow(2, 32)) >> 0; - var low = value >>> 0; - uint32(bytes, low); - uint32(bytes, high); -} -exports.uint64 = uint64; -; -function float32(bytes, value) { - writeFloat32(bytes, value); -} -exports.float32 = float32; -function float64(bytes, value) { - writeFloat64(bytes, value); + + +/***/ }), +/* 32 */ +/***/ (function(module, exports, __webpack_require__) { + +// Fossil SCM delta compression algorithm +// ====================================== +// +// Format: +// http://www.fossil-scm.org/index.html/doc/tip/www/delta_format.wiki +// +// Algorithm: +// http://www.fossil-scm.org/index.html/doc/tip/www/delta_encoder_algorithm.wiki +// +// Original implementation: +// http://www.fossil-scm.org/index.html/artifact/d1b0598adcd650b3551f63b17dfc864e73775c3d +// +// LICENSE +// ------- +// +// Copyright 2014 Dmitry Chestnykh (JavaScript port) +// Copyright 2007 D. Richard Hipp (original C version) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or +// without modification, are permitted provided that the +// following conditions are met: +// +// 1. Redistributions of source code must retain the above +// copyright notice, this list of conditions and the +// following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the +// following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS +// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// The views and conclusions contained in the software and documentation +// are those of the authors and contributors and should not be interpreted +// as representing official policies, either expressed or implied, of anybody +// else. +// +(function(root, factory) { + if ( true && module.exports) module.exports = factory(); + else root.fossilDelta = factory(); +})(this, function() { +'use strict'; + +var fossilDelta = {}; + +// Hash window width in bytes. Must be a power of two. +var NHASH = 16; + +function RollingHash() { + this.a = 0; // hash (16-bit unsigned) + this.b = 0; // values (16-bit unsigned) + this.i = 0; // start of the hash window (16-bit unsigned) + this.z = new Array(NHASH); // the values that have been hashed. } -exports.float64 = float64; -// force little endian to facilitate decoding on multiple implementations -var _isLittleEndian = true; // new Uint16Array(new Uint8Array([1, 0]).buffer)[0] === 1; -var _int32 = new Int32Array(2); -var _float32 = new Float32Array(_int32.buffer); -var _float64 = new Float64Array(_int32.buffer); -function writeFloat32(bytes, value) { - _float32[0] = value; - int32(bytes, _int32[0]); + +// Initialize the rolling hash using the first NHASH bytes of +// z at the given position. +RollingHash.prototype.init = function(z, pos) { + var a = 0, b = 0, i, x; + for(i = 0; i < NHASH; i++){ + x = z[pos+i]; + a = (a + x) & 0xffff; + b = (b + (NHASH-i)*x) & 0xffff; + this.z[i] = x; + } + this.a = a & 0xffff; + this.b = b & 0xffff; + this.i = 0; +}; + +// Advance the rolling hash by a single byte "c". +RollingHash.prototype.next = function(c) { + var old = this.z[this.i]; + this.z[this.i] = c; + this.i = (this.i+1)&(NHASH-1); + this.a = (this.a - old + c) & 0xffff; + this.b = (this.b - NHASH*old + this.a) & 0xffff; +}; + +// Return a 32-bit hash value. +RollingHash.prototype.value = function() { + return ((this.a & 0xffff) | (this.b & 0xffff)<<16)>>>0; +}; + +var zDigits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~". + split('').map(function (x) { return x.charCodeAt(0); }); + +var zValue = [ + -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 +]; + +// Reader reads bytes, chars, ints from array. +function Reader(array) { + this.a = array; // source array + this.pos = 0; // current position in array } -exports.writeFloat32 = writeFloat32; -; -function writeFloat64(bytes, value) { - _float64[0] = value; - int32(bytes, _int32[_isLittleEndian ? 0 : 1]); - int32(bytes, _int32[_isLittleEndian ? 1 : 0]); + +Reader.prototype.haveBytes = function() { + return this.pos < this.a.length; +}; + +Reader.prototype.getByte = function() { + var b = this.a[this.pos]; + this.pos++; + if (this.pos > this.a.length) throw new RangeError('out of bounds'); + return b; +}; + +Reader.prototype.getChar = function() { + return String.fromCharCode(this.getByte()); +}; + +// Read base64-encoded unsigned integer. +Reader.prototype.getInt = function(){ + var v = 0, c; + while(this.haveBytes() && (c = zValue[0x7f & this.getByte()]) >= 0) { + v = (v<<6) + c; + } + this.pos--; + return v >>> 0; +}; + + +// Write writes an array. +function Writer() { + this.a = []; } -exports.writeFloat64 = writeFloat64; -; -function boolean(bytes, value) { - return uint8(bytes, value ? 1 : 0); + +Writer.prototype.toArray = function() { + return this.a; +}; + +Writer.prototype.putByte = function(b) { + this.a.push(b & 0xff); +}; + +// Write an ASCII character (s is a one-char string). +Writer.prototype.putChar = function(s) { + this.putByte(s.charCodeAt(0)); +}; + +// Write a base64 unsigned integer. +Writer.prototype.putInt = function(v){ + var i, j, zBuf = []; + if (v === 0) { + this.putChar('0'); + return; + } + for (i = 0; v > 0; i++, v >>>= 6) + zBuf.push(zDigits[v&0x3f]); + for (j = i-1; j >= 0; j--) + this.putByte(zBuf[j]); +}; + +// Copy from array at start to end. +Writer.prototype.putArray = function(a, start, end) { + for (var i = start; i < end; i++) this.a.push(a[i]); +}; + +// Return the number digits in the base64 representation of a positive integer. +function digitCount(v){ + var i, x; + for (i = 1, x = 64; v >= x; i++, x <<= 6){ /* nothing */ } + return i; } -exports.boolean = boolean; -; -function string(bytes, value) { - // encode `null` strings as empty. - if (!value) { - value = ""; - } - var length = utf8Length(value); - var size = 0; - // fixstr - if (length < 0x20) { - bytes.push(length | 0xa0); - size = 1; - } - // str 8 - else if (length < 0x100) { - bytes.push(0xd9); - uint8(bytes, length); - size = 2; - } - // str 16 - else if (length < 0x10000) { - bytes.push(0xda); - uint16(bytes, length); - size = 3; - } - // str 32 - else if (length < 0x100000000) { - bytes.push(0xdb); - uint32(bytes, length); - size = 5; - } - else { - throw new Error('String too long'); - } - utf8Write(bytes, bytes.length, value); - return size + length; + +// Return a 32-bit checksum of the array. +function checksum(arr) { + var sum0 = 0, sum1 = 0, sum2 = 0, sum3 = 0, + z = 0, N = arr.length; + //TODO measure if this unrolling is helpful. + while (N >= 16) { + sum0 = sum0 + arr[z+0] | 0; + sum1 = sum1 + arr[z+1] | 0; + sum2 = sum2 + arr[z+2] | 0; + sum3 = sum3 + arr[z+3] | 0; + + sum0 = sum0 + arr[z+4] | 0; + sum1 = sum1 + arr[z+5] | 0; + sum2 = sum2 + arr[z+6] | 0; + sum3 = sum3 + arr[z+7] | 0; + + sum0 = sum0 + arr[z+8] | 0; + sum1 = sum1 + arr[z+9] | 0; + sum2 = sum2 + arr[z+10] | 0; + sum3 = sum3 + arr[z+11] | 0; + + sum0 = sum0 + arr[z+12] | 0; + sum1 = sum1 + arr[z+13] | 0; + sum2 = sum2 + arr[z+14] | 0; + sum3 = sum3 + arr[z+15] | 0; + + z += 16; + N -= 16; + } + while (N >= 4) { + sum0 = sum0 + arr[z+0] | 0; + sum1 = sum1 + arr[z+1] | 0; + sum2 = sum2 + arr[z+2] | 0; + sum3 = sum3 + arr[z+3] | 0; + z += 4; + N -= 4; + } + sum3 = (((sum3 + (sum2 << 8) | 0) + (sum1 << 16) | 0) + (sum0 << 24) | 0); + /* jshint -W086 */ + switch (N) { + case 3: sum3 = sum3 + (arr[z+2] << 8) | 0; /* falls through */ + case 2: sum3 = sum3 + (arr[z+1] << 16) | 0; /* falls through */ + case 1: sum3 = sum3 + (arr[z+0] << 24) | 0; /* falls through */ + } + return sum3 >>> 0; } -exports.string = string; -function number(bytes, value) { - if (isNaN(value)) { - return number(bytes, 0); - } - else if (!isFinite(value)) { - return number(bytes, (value > 0) ? Number.MAX_SAFE_INTEGER : -Number.MAX_SAFE_INTEGER); - } - else if (value !== (value | 0)) { - bytes.push(0xcb); - writeFloat64(bytes, value); - return 9; - // TODO: encode float 32? - // is it possible to differentiate between float32 / float64 here? - // // float 32 - // bytes.push(0xca); - // writeFloat32(bytes, value); - // return 5; - } - if (value >= 0) { - // positive fixnum - if (value < 0x80) { - uint8(bytes, value); - return 1; - } - // uint 8 - if (value < 0x100) { - bytes.push(0xcc); - uint8(bytes, value); - return 2; + +// Create a new delta from src to out. +fossilDelta.create = function(src, out) { + var zDelta = new Writer(); + var lenOut = out.length; + var lenSrc = src.length; + var i, lastRead = -1; + + zDelta.putInt(lenOut); + zDelta.putChar('\n'); + + // If the source is very small, it means that we have no + // chance of ever doing a copy command. Just output a single + // literal segment for the entire target and exit. + if (lenSrc <= NHASH) { + zDelta.putInt(lenOut); + zDelta.putChar(':'); + zDelta.putArray(out, 0, lenOut); + zDelta.putInt(checksum(out)); + zDelta.putChar(';'); + return zDelta.toArray(); + } + + // Compute the hash table used to locate matching sections in the source. + var nHash = Math.ceil(lenSrc / NHASH); + var collide = new Array(nHash); + var landmark = new Array(nHash); + for (i = 0; i < collide.length; i++) collide[i] = -1; + for (i = 0; i < landmark.length; i++) landmark[i] = -1; + var hv, h = new RollingHash(); + for (i = 0; i < lenSrc-NHASH; i += NHASH) { + h.init(src, i); + hv = h.value() % nHash; + collide[i/NHASH] = landmark[hv]; + landmark[hv] = i/NHASH; + } + + var base = 0; + var iSrc, iBlock, bestCnt, bestOfst, bestLitsz; + while (base+NHASH= 0 && (limit--)>0 ) { + // + // The hash window has identified a potential match against + // landmark block iBlock. But we need to investigate further. + // + // Look for a region in zOut that matches zSrc. Anchor the search + // at zSrc[iSrc] and zOut[base+i]. Do not include anything prior to + // zOut[base] or after zOut[outLen] nor anything after zSrc[srcLen]. + // + // Set cnt equal to the length of the match and set ofst so that + // zSrc[ofst] is the first element of the match. litsz is the number + // of characters between zOut[base] and the beginning of the match. + // sz will be the overhead (in bytes) needed to encode the copy + // command. Only generate copy command if the overhead of the + // copy command is less than the amount of literal text to be copied. + // + var cnt, ofst, litsz; + var j, k, x, y; + var sz; + + // Beginning at iSrc, match forwards as far as we can. + // j counts the number of characters that match. + iSrc = iBlock*NHASH; + for (j = 0, x = iSrc, y = base+i; x < lenSrc && y < lenOut; j++, x++, y++) { + if (src[x] !== out[y]) break; } - // uint 16 - if (value < 0x10000) { - bytes.push(0xcd); - uint16(bytes, value); - return 3; + j--; + + // Beginning at iSrc-1, match backwards as far as we can. + // k counts the number of characters that match. + for (k = 1; k < iSrc && k <= i; k++) { + if (src[iSrc-k] !== out[base+i-k]) break; } - // uint 32 - if (value < 0x100000000) { - bytes.push(0xce); - uint32(bytes, value); - return 5; + k--; + + // Compute the offset and size of the matching region. + ofst = iSrc-k; + cnt = j+k+1; + litsz = i-k; // Number of bytes of literal text before the copy + // sz will hold the number of bytes needed to encode the "insert" + // command and the copy command, not counting the "insert" text. + sz = digitCount(i-k)+digitCount(cnt)+digitCount(ofst)+3; + if (cnt >= sz && cnt > bestCnt) { + // Remember this match only if it is the best so far and it + // does not increase the file size. + bestCnt = cnt; + bestOfst = iSrc-k; + bestLitsz = litsz; } - // uint 64 - bytes.push(0xcf); - uint64(bytes, value); - return 9; - } - else { - // negative fixnum - if (value >= -0x20) { - bytes.push(value); - return 1; + + // Check the next matching block + iBlock = collide[iBlock]; + } + + // We have a copy command that does not cause the delta to be larger + // than a literal insert. So add the copy command to the delta. + if (bestCnt > 0) { + if (bestLitsz > 0) { + // Add an insert command before the copy. + zDelta.putInt(bestLitsz); + zDelta.putChar(':'); + zDelta.putArray(out, base, base+bestLitsz); + base += bestLitsz; } - // int 8 - if (value >= -0x80) { - bytes.push(0xd0); - int8(bytes, value); - return 2; + base += bestCnt; + zDelta.putInt(bestCnt); + zDelta.putChar('@'); + zDelta.putInt(bestOfst); + zDelta.putChar(','); + if (bestOfst + bestCnt -1 > lastRead) { + lastRead = bestOfst + bestCnt - 1; } - // int 16 - if (value >= -0x8000) { - bytes.push(0xd1); - int16(bytes, value); - return 3; + bestCnt = 0; + break; + } + + // If we reach this point, it means no match is found so far + if (base+i+NHASH >= lenOut){ + // We have reached the end and have not found any + // matches. Do an "insert" for everything that does not match + zDelta.putInt(lenOut-base); + zDelta.putChar(':'); + zDelta.putArray(out, base, base+lenOut-base); + base = lenOut; + break; + } + + // Advance the hash by one character. Keep looking for a match. + h.next(out[base+i+NHASH]); + i++; + } + } + // Output a final "insert" record to get all the text at the end of + // the file that does not match anything in the source. + if(base < lenOut) { + zDelta.putInt(lenOut-base); + zDelta.putChar(':'); + zDelta.putArray(out, base, base+lenOut-base); + } + // Output the final checksum record. + zDelta.putInt(checksum(out)); + zDelta.putChar(';'); + return zDelta.toArray(); +}; + +// Return the size (in bytes) of the output from applying a delta. +fossilDelta.outputSize = function(delta){ + var zDelta = new Reader(delta); + var size = zDelta.getInt(); + if (zDelta.getChar() !== '\n') + throw new Error('size integer not terminated by \'\\n\''); + return size; +}; + +// Apply a delta. +fossilDelta.apply = function(src, delta, opts) { + var limit, total = 0; + var zDelta = new Reader(delta); + var lenSrc = src.length; + var lenDelta = delta.length; + + limit = zDelta.getInt(); + if (zDelta.getChar() !== '\n') + throw new Error('size integer not terminated by \'\\n\''); + var zOut = new Writer(); + while(zDelta.haveBytes()) { + var cnt, ofst; + cnt = zDelta.getInt(); + + switch (zDelta.getChar()) { + case '@': + ofst = zDelta.getInt(); + if (zDelta.haveBytes() && zDelta.getChar() !== ',') + throw new Error('copy command not terminated by \',\''); + total += cnt; + if (total > limit) + throw new Error('copy exceeds output file size'); + if (ofst+cnt > lenSrc) + throw new Error('copy extends past end of input'); + zOut.putArray(src, ofst, ofst+cnt); + break; + + case ':': + total += cnt; + if (total > limit) + throw new Error('insert command gives an output larger than predicted'); + if (cnt > lenDelta) + throw new Error('insert count exceeds size of delta'); + zOut.putArray(zDelta.a, zDelta.pos, zDelta.pos+cnt); + zDelta.pos += cnt; + break; + + case ';': + var out = zOut.toArray(); + if ((!opts || opts.verifyChecksum !== false) && cnt !== checksum(out)) + throw new Error('bad checksum'); + if (total !== limit) + throw new Error('generated size does not match predicted size'); + return out; + + default: + throw new Error('unknown delta operator'); + } + } + throw new Error('unterminated delta'); +}; + +return fossilDelta; + +}); + + +/***/ }), +/* 33 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +var schema_1 = __webpack_require__(12); +var SchemaSerializer = /** @class */ (function () { + function SchemaSerializer() { + } + SchemaSerializer.prototype.setState = function (rawState) { + this.state.decode(rawState); + }; + SchemaSerializer.prototype.getState = function () { + return this.state; + }; + SchemaSerializer.prototype.patch = function (patches) { + this.state.decode(patches); + }; + SchemaSerializer.prototype.teardown = function () { + // this.state.onRemove + }; + SchemaSerializer.prototype.handshake = function (bytes, it) { + if (this.state) { + // validate client/server definitinos + var reflection = new schema_1.Reflection(); + reflection.decode(bytes, it); } - // int 32 - if (value >= -0x80000000) { - bytes.push(0xd2); - int32(bytes, value); - return 5; + else { + // initialize reflected state from server + this.state = schema_1.Reflection.decode(bytes); } - // int 64 - bytes.push(0xd3); - int64(bytes, value); - return 9; + }; + return SchemaSerializer; +}()); +exports.SchemaSerializer = SchemaSerializer; + + +/***/ }), +/* 34 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +/** + * Extracted from https://www.npmjs.com/package/strong-events + */ +Object.defineProperty(exports, "__esModule", { value: true }); +var EventEmitter = /** @class */ (function () { + function EventEmitter() { + this.handlers = []; } -} -exports.number = number; -//# sourceMappingURL=encode.js.map + EventEmitter.prototype.register = function (cb, once) { + if (once === void 0) { once = false; } + this.handlers.push(cb); + return this; + }; + EventEmitter.prototype.invoke = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + this.handlers.forEach(function (handler) { return handler.apply(void 0, args); }); + }; + EventEmitter.prototype.invokeAsync = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + return Promise.all(this.handlers.map(function (handler) { return handler.apply(void 0, args); })); + }; + EventEmitter.prototype.remove = function (cb) { + var index = this.handlers.indexOf(cb); + this.handlers[index] = this.handlers[this.handlers.length - 1]; + this.handlers.pop(); + }; + EventEmitter.prototype.clear = function () { + this.handlers = []; + }; + return EventEmitter; +}()); +exports.EventEmitter = EventEmitter; +//# sourceMappingURL=EventEmitter.js.map /***/ }), -/* 32 */ +/* 35 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -var spec_1 = __webpack_require__(9); -function utf8Read(bytes, offset, length) { - var string = '', chr = 0; - for (var i = offset, end = offset + length; i < end; i++) { - var byte = bytes[i]; - if ((byte & 0x80) === 0x00) { - string += String.fromCharCode(byte); - continue; - } - if ((byte & 0xe0) === 0xc0) { - string += String.fromCharCode(((byte & 0x1f) << 6) | - (bytes[++i] & 0x3f)); - continue; - } - if ((byte & 0xf0) === 0xe0) { - string += String.fromCharCode(((byte & 0x0f) << 12) | - ((bytes[++i] & 0x3f) << 6) | - ((bytes[++i] & 0x3f) << 0)); - continue; +var _1 = __webpack_require__(12); +var MapSchema_1 = __webpack_require__(1); +var ArraySchema_1 = __webpack_require__(0); +function dumpChanges(schema) { + var dump = {}; + var $changes = schema.$changes; + var fieldsByIndex = schema['_fieldsByIndex'] || {}; + for (var _i = 0, _a = Array.from($changes.changes); _i < _a.length; _i++) { + var fieldIndex = _a[_i]; + var field = fieldsByIndex[fieldIndex] || fieldIndex; + if (schema[field] instanceof MapSchema_1.MapSchema || + schema[field] instanceof ArraySchema_1.ArraySchema || + schema[field] instanceof _1.Schema) { + dump[field] = dumpChanges(schema[field]); } - if ((byte & 0xf8) === 0xf0) { - chr = ((byte & 0x07) << 18) | - ((bytes[++i] & 0x3f) << 12) | - ((bytes[++i] & 0x3f) << 6) | - ((bytes[++i] & 0x3f) << 0); - if (chr >= 0x010000) { // surrogate pair - chr -= 0x010000; - string += String.fromCharCode((chr >>> 10) + 0xD800, (chr & 0x3FF) + 0xDC00); - } - else { - string += String.fromCharCode(chr); - } - continue; + else { + dump[field] = schema[field]; } - throw new Error('Invalid byte ' + byte.toString(16)); - } - return string; -} -function int8(bytes, it) { - return uint8(bytes, it) << 24 >> 24; -} -exports.int8 = int8; -; -function uint8(bytes, it) { - return bytes[it.offset++]; -} -exports.uint8 = uint8; -; -function int16(bytes, it) { - return uint16(bytes, it) << 16 >> 16; -} -exports.int16 = int16; -; -function uint16(bytes, it) { - return bytes[it.offset++] | bytes[it.offset++] << 8; -} -exports.uint16 = uint16; -; -function int32(bytes, it) { - return bytes[it.offset++] | bytes[it.offset++] << 8 | bytes[it.offset++] << 16 | bytes[it.offset++] << 24; -} -exports.int32 = int32; -; -function uint32(bytes, it) { - return int32(bytes, it) >>> 0; -} -exports.uint32 = uint32; -; -function float32(bytes, it) { - return readFloat32(bytes, it); -} -exports.float32 = float32; -function float64(bytes, it) { - return readFloat64(bytes, it); -} -exports.float64 = float64; -function int64(bytes, it) { - var low = uint32(bytes, it); - var high = int32(bytes, it) * Math.pow(2, 32); - return high + low; -} -exports.int64 = int64; -; -function uint64(bytes, it) { - var low = uint32(bytes, it); - var high = uint32(bytes, it) * Math.pow(2, 32); - return high + low; -} -exports.uint64 = uint64; -; -// force little endian to facilitate decoding on multiple implementations -var _isLittleEndian = true; // new Uint16Array(new Uint8Array([1, 0]).buffer)[0] === 1; -var _int32 = new Int32Array(2); -var _float32 = new Float32Array(_int32.buffer); -var _float64 = new Float64Array(_int32.buffer); -function readFloat32(bytes, it) { - _int32[0] = int32(bytes, it); - return _float32[0]; -} -exports.readFloat32 = readFloat32; -; -function readFloat64(bytes, it) { - _int32[_isLittleEndian ? 0 : 1] = int32(bytes, it); - _int32[_isLittleEndian ? 1 : 0] = int32(bytes, it); - return _float64[0]; -} -exports.readFloat64 = readFloat64; -; -function boolean(bytes, it) { - return uint8(bytes, it) > 0; -} -exports.boolean = boolean; -; -function string(bytes, it) { - var prefix = bytes[it.offset++]; - var length; - if (prefix < 0xc0) { - // fixstr - length = prefix & 0x1f; - } - else if (prefix === 0xd9) { - length = uint8(bytes, it); - } - else if (prefix === 0xda) { - length = uint16(bytes, it); - } - else if (prefix === 0xdb) { - length = uint32(bytes, it); - } - var value = utf8Read(bytes, it.offset, length); - it.offset += length; - return value; -} -exports.string = string; -function stringCheck(bytes, it) { - var prefix = bytes[it.offset]; - return ( - // fixstr - (prefix < 0xc0 && prefix > 0xa0) || - // str 8 - prefix === 0xd9 || - // str 16 - prefix === 0xda || - // str 32 - prefix === 0xdb); -} -exports.stringCheck = stringCheck; -function number(bytes, it) { - var prefix = bytes[it.offset++]; - if (prefix < 0x80) { - // positive fixint - return prefix; - } - else if (prefix === 0xca) { - // float 32 - return readFloat32(bytes, it); - } - else if (prefix === 0xcb) { - // float 64 - return readFloat64(bytes, it); - } - else if (prefix === 0xcc) { - // uint 8 - return uint8(bytes, it); - } - else if (prefix === 0xcd) { - // uint 16 - return uint16(bytes, it); - } - else if (prefix === 0xce) { - // uint 32 - return uint32(bytes, it); - } - else if (prefix === 0xcf) { - // uint 64 - return uint64(bytes, it); - } - else if (prefix === 0xd0) { - // int 8 - return int8(bytes, it); - } - else if (prefix === 0xd1) { - // int 16 - return int16(bytes, it); - } - else if (prefix === 0xd2) { - // int 32 - return int32(bytes, it); - } - else if (prefix === 0xd3) { - // int 64 - return int64(bytes, it); - } - else if (prefix > 0xdf) { - // negative fixint - return (0xff - prefix + 1) * -1; } + return dump; } -exports.number = number; -; -function numberCheck(bytes, it) { - var prefix = bytes[it.offset]; - // positive fixint - 0x00 - 0x7f - // float 32 - 0xca - // float 64 - 0xcb - // uint 8 - 0xcc - // uint 16 - 0xcd - // uint 32 - 0xce - // uint 64 - 0xcf - // int 8 - 0xd0 - // int 16 - 0xd1 - // int 32 - 0xd2 - // int 64 - 0xd3 - return (prefix < 0x80 || - (prefix >= 0xca && prefix <= 0xd3)); -} -exports.numberCheck = numberCheck; -function arrayCheck(bytes, it) { - return bytes[it.offset] < 0xa0; - // const prefix = bytes[it.offset] ; - // if (prefix < 0xa0) { - // return prefix; - // // array - // } else if (prefix === 0xdc) { - // it.offset += 2; - // } else if (0xdd) { - // it.offset += 4; - // } - // return prefix; -} -exports.arrayCheck = arrayCheck; -function nilCheck(bytes, it) { - return bytes[it.offset] === spec_1.NIL; -} -exports.nilCheck = nilCheck; -function indexChangeCheck(bytes, it) { - return bytes[it.offset] === spec_1.INDEX_CHANGE; -} -exports.indexChangeCheck = indexChangeCheck; -//# sourceMappingURL=decode.js.map +exports.dumpChanges = dumpChanges; +//# sourceMappingURL=utils.js.map /***/ }), -/* 33 */ +/* 36 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -4602,10 +4902,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); -var annotations_1 = __webpack_require__(11); -var Schema_1 = __webpack_require__(0); -var ArraySchema_1 = __webpack_require__(1); -var MapSchema_1 = __webpack_require__(2); +var annotations_1 = __webpack_require__(14); +var Schema_1 = __webpack_require__(2); +var ArraySchema_1 = __webpack_require__(0); +var MapSchema_1 = __webpack_require__(1); var reflectionContext = new annotations_1.Context(); /** * Reflection diff --git a/dist/colyseus.js b/dist/colyseus.js index 6f643cc..ccaa60e 100644 --- a/dist/colyseus.js +++ b/dist/colyseus.js @@ -1,2 +1,2 @@ /*! colyseus.js@0.13.0-alpha.10 */ -!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()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=15)}([function(e,t,n){"use strict";var r,i=this&&this.__extends||(r=function(e,t){return(r=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])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),o=this&&this.__spreadArrays||function(){for(var e=0,t=0,n=arguments.length;t=e+t-1}));return i.map((function(e){var t=e&&e.$changes;t&&(t.parent.deleteIndex(e),delete t.parent)})),o.forEach((function(e){var t=e&&e.$changes;t&&t.parentField--})),i},t}(Array);t.ArraySchema=s},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function e(t){var n=this;for(var r in void 0===t&&(t={}),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(t){var r;if(t)(r=Object.assign(new e,n)).onAdd=n.onAdd,r.onRemove=n.onRemove,r.onChange=n.onChange;else{var i=new e;for(var o in n)"object"==typeof n[o]?i[o]=n[o].clone():i[o]=n[o]}return r}},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(e){for(var t=0,r=new Map,i=0,o=e;im;_=w>0||A;var C=!1;A&&Array.prototype.splice.call(g,m).forEach((function(t,n){if(t&&t.onRemove)try{t.onRemove()}catch(t){e.onError(t)}if(b.onRemove)try{b.onRemove(t,m+n)}catch(t){e.onError(t)}}));for(var O=0;O0;C=!1;var x=Object.keys(k);for(O=0;O0){for(var n=0;n=400?o:i)(h)},(a=n.body)&&"object"==typeof a&&(f["content-type"]="application/json",a=JSON.stringify(a)),h.withCredentials=!!n.withCredentials,f)h.setRequestHeader(s,f[s]);h.send(a)}))}n.r(t),n.d(t,"send",(function(){return 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(5)),o=n(21),s=n(22),a=n(6),c=n(7),u=r(n(8)),h=r(n(9)),f=function(){function e(e,t){var n=this;this.onJoin=o.createSignal(),this.onStateChange=o.createSignal(),this.onError=o.createSignal(),this.onLeave=o.createSignal(),this.hasJoined=!1,this.onMessageHandlers={},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,t){return console.error("colyseus.js - onError => ("+e+") "+t)})),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){if(!t.hasJoined)return console.error("Room connection was closed unexpectedly ("+e.code+"): "+e.reason),void t.onError.invoke(e.code,e.reason);t.onLeave.invoke(e.code)},this.connection.onerror=function(e){console.warn("Room, onError ("+e.code+"): "+e.reason),t.onError.invoke(e.code,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.onMessage=function(e,t){return this.onMessageHandlers[this.getMessageHandlerKey(e)]=t,this},e.prototype.send=function(e,t){var n,r=[c.Protocol.ROOM_DATA];if("string"==typeof e?u.string(r,e):u.number(r,e),void 0!==t){var o=i.encode(t);(n=new Uint8Array(r.length+o.byteLength)).set(new Uint8Array(r),0),n.set(new Uint8Array(o),r.length)}else n=new Uint8Array(r);this.connection.send(n.buffer)},Object.defineProperty(e.prototype,"state",{get:function(){return this.serializer.getState()},enumerable:!0,configurable:!0}),e.prototype.listen=function(e,t,n){if("schema"!==this.serializerId)return this.serializerId||console.warn("room.Listen() should be called after room.onJoin has been called (DEPRECATION WARNING)"),this.serializer.api.listen(e,t,n);console.error("'"+this.serializerId+"' serializer doesn't support .listen() method here.")},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.onError.clear(),this.onLeave.clear()},e.prototype.onMessageCallback=function(e){var t=Array.from(new Uint8Array(e.data)),n=t[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);"fossil-delta"===this.serializerId||this.rootSchema||(this.serializer=new o),t.length>r&&this.serializer.handshake&&this.serializer.handshake(t,{offset:1}),this.hasJoined=!0,this.onJoin.invoke(),this.connection.send([c.Protocol.JOIN_ROOM])}else if(n===c.Protocol.ERROR){var s={offset:1},u=h.number(t,s),f=h.string(t,s);this.onError.invoke(u,f)}else if(n===c.Protocol.LEAVE_ROOM)this.leave();else if(n===c.Protocol.ROOM_DATA_SCHEMA){(f=new(p=this.serializer.getState().constructor._context.get(t[1]))).decode(t,{offset:2}),this.dispatchMessage(p,f)}else if(n===c.Protocol.ROOM_STATE)t.shift(),this.setState(t);else if(n===c.Protocol.ROOM_STATE_PATCH)t.shift(),this.patch(t);else if(n===c.Protocol.ROOM_DATA){var l={offset:1},p=h.stringCheck(t,l)?h.string(t,l):h.number(t,l);f=t.length>l.offset?i.decode(e.data,l.offset):void 0;this.dispatchMessage(p,f)}},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.prototype.dispatchMessage=function(e,t){var n=this.getMessageHandlerKey(e);this.onMessageHandlers[n]?this.onMessageHandlers[n](t):this.onMessageHandlers["*"]?this.onMessageHandlers[n](e,t):console.warn("onMessage not registered for type '"+e+"'.")},e.prototype.getMessageHandlerKey=function(e){switch(typeof e){case"function":return"$"+e._typeid;case"string":return e;case"number":return"i"+e;default:throw new Error("invalid message type.")}},e}();t.Room=f},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(19)),o=r(n(20));t.decode=i.default,t.encode=o.default},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r={};t.registerSerializer=function(e,t){r[e]=t},t.getSerializer=function(e){return r[e]}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),function(e){e[e.HANDSHAKE=9]="HANDSHAKE",e[e.JOIN_ROOM=10]="JOIN_ROOM",e[e.ERROR=11]="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",e[e.ROOM_DATA_SCHEMA=16]="ROOM_DATA_SCHEMA"}(t.Protocol||(t.Protocol={})),function(e){e[e.MATCHMAKE_NO_HANDLER=4210]="MATCHMAKE_NO_HANDLER",e[e.MATCHMAKE_INVALID_CRITERIA=4211]="MATCHMAKE_INVALID_CRITERIA",e[e.MATCHMAKE_INVALID_ROOM_ID=4212]="MATCHMAKE_INVALID_ROOM_ID",e[e.MATCHMAKE_UNHANDLED=4213]="MATCHMAKE_UNHANDLED",e[e.MATCHMAKE_EXPIRED=4214]="MATCHMAKE_EXPIRED",e[e.AUTH_FAILED=4215]="AUTH_FAILED",e[e.APPLICATION_ERROR=4216]="APPLICATION_ERROR"}(t.ErrorCode||(t.ErrorCode={})),t.utf8Read=function(e,t){for(var n=e[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[++o])<<6|(63&e[++o])<<0);else r+=String.fromCharCode((31&a)<<6|63&e[++o]);else r+=String.fromCharCode(a)}return r},t.utf8Length=function(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}},function(e,t,n){"use strict";function r(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 i(e,t){e.push(255&t)}function o(e,t){e.push(255&t)}function s(e,t){e.push(255&t),e.push(t>>8&255)}function a(e,t){e.push(255&t),e.push(t>>8&255)}function c(e,t){e.push(255&t),e.push(t>>8&255),e.push(t>>16&255),e.push(t>>24&255)}function u(e,t){var n=t>>24,r=t>>16,i=t>>8,o=t;e.push(255&o),e.push(255&i),e.push(255&r),e.push(255&n)}function h(e,t){var n=Math.floor(t/Math.pow(2,32));u(e,t>>>0),u(e,n)}function f(e,t){var n=t/Math.pow(2,32)>>0;u(e,t>>>0),u(e,n)}Object.defineProperty(t,"__esModule",{value:!0}),t.utf8Write=r,t.int8=i,t.uint8=o,t.int16=s,t.uint16=a,t.int32=c,t.uint32=u,t.int64=h,t.uint64=f,t.float32=function(e,t){v(e,t)},t.float64=function(e,t){y(e,t)};var l=new Int32Array(2),p=new Float32Array(l.buffer),d=new Float64Array(l.buffer);function v(e,t){p[0]=t,c(e,l[0])}function y(e,t){d[0]=t,c(e,l[0]),c(e,l[1])}t.writeFloat32=v,t.writeFloat64=y,t.boolean=function(e,t){return o(e,t?1:0)},t.string=function(e,t){t||(t="");var n=function(e){for(var t=0,n=0,r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}(t),i=0;if(n<32)e.push(160|n),i=1;else if(n<256)e.push(217),o(e,n),i=2;else if(n<65536)e.push(218),a(e,n),i=3;else{if(!(n<4294967296))throw new Error("String too long");e.push(219),u(e,n),i=5}return r(e,e.length,t),i+n},t.number=function e(t,n){return isNaN(n)?e(t,0):isFinite(n)?n!==(0|n)?(t.push(203),y(t,n),9):n>=0?n<128?(o(t,n),1):n<256?(t.push(204),o(t,n),2):n<65536?(t.push(205),a(t,n),3):n<4294967296?(t.push(206),u(t,n),5):(t.push(207),f(t,n),9):n>=-32?(t.push(n),1):n>=-128?(t.push(208),i(t,n),2):n>=-32768?(t.push(209),s(t,n),3):n>=-2147483648?(t.push(210),c(t,n),5):(t.push(211),h(t,n),9):e(t,n>0?Number.MAX_SAFE_INTEGER:-Number.MAX_SAFE_INTEGER)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(10);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){var n=u(e,t);return c(e,t)*Math.pow(2,32)+n}function f(e,t){var n=u(e,t);return u(e,t)*Math.pow(2,32)+n}t.int8=i,t.uint8=o,t.int16=s,t.uint16=a,t.int32=c,t.uint32=u,t.float32=function(e,t){return v(e,t)},t.float64=function(e,t){return y(e,t)},t.int64=h,t.uint64=f;var l=new Int32Array(2),p=new Float32Array(l.buffer),d=new Float64Array(l.buffer);function v(e,t){return l[0]=c(e,t),p[0]}function y(e,t){return l[0]=c(e,t),l[1]=c(e,t),d[0]}t.readFloat32=v,t.readFloat64=y,t.boolean=function(e,t){return o(e,t)>0},t.string=function(e,t){var n,r=e[t.offset++];r<192?n=31&r:217===r?n=o(e,t):218===r?n=a(e,t):219===r&&(n=u(e,t));var i=function(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}(e,t.offset,n);return t.offset+=n,i},t.stringCheck=function(e,t){var n=e[t.offset];return n<192&&n>160||217===n||218===n||219===n},t.number=function(e,t){var n=e[t.offset++];return n<128?n:202===n?v(e,t):203===n?y(e,t):204===n?o(e,t):205===n?a(e,t):206===n?u(e,t):207===n?f(e,t):208===n?i(e,t):209===n?s(e,t):210===n?c(e,t):211===n?h(e,t):n>223?-1*(255-n+1):void 0},t.numberCheck=function(e,t){var n=e[t.offset];return n<128||n>=202&&n<=211},t.arrayCheck=function(e,t){return e[t.offset]<160},t.nilCheck=function(e,t){return e[t.offset]===r.NIL},t.indexChangeCheck=function(e,t){return e[t.offset]===r.INDEX_CHANGE}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.END_OF_STRUCTURE=193,t.NIL=192,t.INDEX_CHANGE=212,t.TYPE_ID=213},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){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},i=this&&this.__generator||function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0?"?"+r.join("&"):"",h={headers:a},o&&(h.body=o),[4,s[e](""+this.endpoint+t+u,h)];case 1:return[2,i.sent().data]}}))}))},e.prototype.logout=function(){this.token=void 0,a.removeItem("colyseus-auth-token"),this.unregisterPingService()},e.prototype.registerPingService=function(e){var t=this;void 0===e&&(e=15e3),this.unregisterPingService(),this.keepOnlineInterval=setInterval((function(){return t.request("get","/auth")}),e)},e.prototype.unregisterPingService=function(){clearInterval(this.keepOnlineInterval)},e}();t.Auth=c},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2);t.Schema=r.Schema;var i=n(1);t.MapSchema=i.MapSchema;var o=n(0);t.ArraySchema=o.ArraySchema;var s=n(35);t.dumpChanges=s.dumpChanges;var a=n(36);t.Reflection=a.Reflection,t.ReflectionType=a.ReflectionType,t.ReflectionField=a.ReflectionField;var c=n(14);t.type=c.type,t.deprecated=c.deprecated,t.filter=c.filter,t.defineTypes=c.defineTypes,t.Context=c.Context},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2),i=n(0),o=n(1),s=function(){function e(e,t,n){void 0===e&&(e={}),void 0===t&&(t=null),this.changed=!1,this.changes=new Set,this.allChanges=new Set,this.deletedKeys={},this.fieldIndexes=e,this.parent=n,this.parentField=t}return e.prototype.change=function(e,t){void 0===t&&(t=!1);var n=this.fieldIndexes[e],r="number"==typeof n?n:e;t?t&&(this.changed=!0,this.changes.add(r),this.allChanges.delete(r)):(this.changed=!0,this.changes.add(r),this.allChanges.add(r)),this.parent&&this.parent.change(this.parentField)},e.prototype.mapIndex=function(e,t){"object"==typeof e&&(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){"object"==typeof e&&(this.deletedKeys[this.indexMap.get(e)]=!0,this.indexMap.delete(e))},e.prototype.isDeleted=function(e){return void 0!==this.deletedKeys[e]},e.prototype.mapIndexChange=function(e,t){"object"!=typeof e||this.indexChange.has(e)||this.indexChange.set(e,t)},e.prototype.getIndexChange=function(e){return this.indexChange&&this.indexChange.get(e)},e.prototype.deleteIndexChange=function(e){"object"==typeof 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),void 0!==e[n]&&this.change(n)}else for(var s=0,a=Object.keys(e);s0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[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}(this._view,this._offset,e);return this._offset+=e,t},r.prototype._bin=function(e){var t=this._buffer.slice(this._offset,this._offset+e);return this._offset+=e,t},r.prototype._parse=function(){var e,t=this._view.getUint8(this._offset++),n=0,r=0,i=0,o=0;if(t<192)return t<128?t:t<144?this._map(15&t):t<160?this._array(15&t):this._str(31&t);if(t>223)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")},t.default=function(e,t){void 0===t&&(t=0);var n=new r(e,t),i=n._parse();if(n._offset!==e.byteLength)throw new Error(e.byteLength-n._offset+" trailing bytes");return i}},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))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){var t=[],n=[],i=function e(t,n,r){var i=typeof r,o=0,s=0,a=0,c=0,u=0,h=0;if("string"===i){if((u=function(e){for(var t=0,n=0,r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}(r))<32)t.push(160|u),h=1;else if(u<256)t.push(217,u),h=2;else if(u<65536)t.push(218,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("String too long");t.push(219,u>>24,u>>16,u>>8,u),h=5}return n.push({_str:r,_length:u,_offset:t.length}),h+u}if("number"===i)return Math.floor(r)===r&&isFinite(r)?r>=0?r<128?(t.push(r),1):r<256?(t.push(204,r),2):r<65536?(t.push(205,r>>8,r),3):r<4294967296?(t.push(206,r>>24,r>>16,r>>8,r),5):(a=r/Math.pow(2,32)>>0,c=r>>>0,t.push(207,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),9):r>=-32?(t.push(r),1):r>=-128?(t.push(208,r),2):r>=-32768?(t.push(209,r>>8,r),3):r>=-2147483648?(t.push(210,r>>24,r>>16,r>>8,r),5):(a=Math.floor(r/Math.pow(2,32)),c=r>>>0,t.push(211,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),9):(t.push(203),n.push({_float:r,_length:8,_offset:t.length}),9);if("object"===i){if(null===r)return t.push(192),1;if(Array.isArray(r)){if((u=r.length)<16)t.push(144|u),h=1;else if(u<65536)t.push(220,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("Array too large");t.push(221,u>>24,u>>16,u>>8,u),h=5}for(o=0;o>>0,t.push(215,0,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),10}if(r instanceof ArrayBuffer){if((u=r.byteLength)<256)t.push(196,u),h=2;else if(u<65536)t.push(197,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("Buffer too large");t.push(198,u>>24,u>>16,u>>8,u),h=5}return n.push({_bin:r,_length:u,_offset:t.length}),h+u}if("function"==typeof r.toJSON)return e(t,n,r.toJSON());var l=[],p="",d=Object.keys(r);for(o=0,s=d.length;o>8,u),h=3;else{if(!(u<4294967296))throw new Error("Object too large");t.push(223,u>>24,u>>16,u>>8,u),h=5}for(o=0;o0&&(u=n[0]._offset);for(var h,f=0,l=0,p=0,d=t.length;p0){for(var n=0,r=this._enqueuedCalls;n2&&void 0!==arguments[2]?arguments[2]:{};i(this,e),this.url=t,this.protocols=n,this.reconnectEnabled=!0,this.listeners={},this.backoff=o(r.backoff||"exponential",r),this.backoff.onReady=this.onBackoffReady.bind(this),(void 0===r.connect||r.connect)&&this.open()}return r(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";Object.defineProperty(t,"__esModule",{value:!0}),t.createBackoff=function(e,t){return new i(r[e],t)};var r={exponential:function(e,t){return Math.floor(Math.random()*Math.pow(2,e)*t)},fibonacci:function(e,t){if(e>(r=1))for(var n=1,r=2,i=2;i0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[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(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=e.slice();return n.push(t),n}function i(e){if(Array.isArray(e)){for(var t=new Array(e.length),n=0;n=0;h--){var f=c[h],l=t[f];if(!n.hasOwnProperty(f)||void 0===n[f]&&void 0!==l&&!1===Array.isArray(n))o.push({operation:"remove",path:r(s,f)}),u=!0;else{var p=n[f];"object"==typeof l&&null!=l&&"object"==typeof p&&null!=p?e(l,p,o,r(s,f)):l!==p&&o.push({operation:"replace",path:r(s,f),value:p,previousValue:l})}}if(!u&&a.length==c.length)return;for(h=a.length-1;h>=0;h--){f=a[h];if(!t.hasOwnProperty(f)&&void 0!==n[f]){p=n[f];var d=r(s,f);"object"==typeof p&&null!=p&&e({},p,o,d),o.push({operation:"add",path:d,value:p})}}}(e,t,n,[]),n}},function(e,t,n){var r,i;r=this,i=function(){"use strict";var e={};function t(){this.a=0,this.b=0,this.i=0,this.z=new Array(16)}t.prototype.init=function(e,t){var n,r,i=0,o=0;for(n=0;n<16;n++)i=i+(r=e[t+n])&65535,o=o+(16-n)*r&65535,this.z[n]=r;this.a=65535&i,this.b=65535&o,this.i=0},t.prototype.next=function(e){var t=this.z[this.i];this.z[this.i]=e,this.i=this.i+1&15,this.a=this.a-t+e&65535,this.b=this.b-16*t+this.a&65535},t.prototype.value=function(){return(65535&this.a|(65535&this.b)<<16)>>>0};var n="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~".split("").map((function(e){return e.charCodeAt(0)})),r=[-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];function i(e){this.a=e,this.pos=0}function o(){this.a=[]}function s(e){var t,n;for(t=1,n=64;e>=n;t++,n<<=6);return t}function a(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}return i.prototype.haveBytes=function(){return this.posthis.a.length)throw new RangeError("out of bounds");return e},i.prototype.getChar=function(){return String.fromCharCode(this.getByte())},i.prototype.getInt=function(){for(var e,t=0;this.haveBytes()&&(e=r[127&this.getByte()])>=0;)t=(t<<6)+e;return this.pos--,t>>>0},o.prototype.toArray=function(){return this.a},o.prototype.putByte=function(e){this.a.push(255&e)},o.prototype.putChar=function(e){this.putByte(e.charCodeAt(0))},o.prototype.putInt=function(e){var t,r,i=[];if(0!==e){for(t=0;e>0;t++,e>>>=6)i.push(n[63&e]);for(r=t-1;r>=0;r--)this.putByte(i[r])}else this.putChar("0")},o.prototype.putArray=function(e,t,n){for(var r=t;r=0&&A-- >0;){var C,O,S,E,I,M,k;for(E=0,M=y=16*g,k=w+r;M=s(r-I)+s(C)+s(O)+3&&C>_&&(_=C,b=y-I,m=S),g=l[g]}if(_>0){m>0&&(i.putInt(m),i.putChar(":"),i.putArray(n,w,w+m),w+=m),w+=_,i.putInt(_),i.putChar("@"),i.putInt(b),i.putChar(","),b+_-1>h&&(h=b+_-1),_=0;break}if(w+r+16>=c){i.putInt(c-w),i.putChar(":"),i.putArray(n,w,w+c-w),w=c;break}v.next(n[w+r+16]),r++}return wr)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((s+=l)>r)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((!n||!1!==n.verifyChecksum)&&l!==a(d))throw new Error("bad checksum");if(s!==r)throw new Error("generated size does not match predicted size");return d;default:throw new Error("unknown delta operator")}}throw new Error("unterminated delta")},e},e.exports?e.exports=i():r.fossilDelta=i()},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(12),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,t){this.state?(new r.Reflection).decode(e,t):this.state=r.Reflection.decode(e)},e}();t.SchemaSerializer=i},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(){this.handlers=[]}return e.prototype.register=function(e,t){return void 0===t&&(t=!1),this.handlers.push(e),this},e.prototype.invoke=function(){for(var e=[],t=0;t=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 s=n(14),a=n(2),c=n(0),u=n(1),h=new s.Context,f=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),o([s.type("string",h)],t.prototype,"name",void 0),o([s.type("string",h)],t.prototype,"type",void 0),o([s.type("uint8",h)],t.prototype,"referencedType",void 0),t}(a.Schema);t.ReflectionField=f;var l=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.fields=new c.ArraySchema,t}return i(t,e),o([s.type("uint8",h)],t.prototype,"id",void 0),o([s.type([f],h)],t.prototype,"fields",void 0),t}(a.Schema);t.ReflectionType=l;var p=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.types=new c.ArraySchema,t}return i(t,e),t.encode=function(e){var n=e.constructor,r=new t;r.rootType=n._typeid;var i=function(e,t){for(var n in t){var i=new f;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)},o=n._context.types;for(var s in o){var a=new l;a.id=Number(s),i(a,o[s]._schema)}return r.encodeAll()},t.decode=function(e){var n=new s.Context,r=new t;r.decode(e);var o=r.types.reduce((function(e,t){return e[t.id]=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),t}(a.Schema),e}),{});r.types.forEach((function(e,t){e.fields.forEach((function(t){var r=o[e.id];if(void 0!==t.referencedType){var i=o[t.referencedType];i||(i=t.type.split(":")[1]),0===t.type.indexOf("array")?s.type([i],n)(r.prototype,t.name):0===t.type.indexOf("map")?s.type({map:i},n)(r.prototype,t.name):"ref"===t.type&&s.type(i,n)(r.prototype,t.name)}else s.type(t.type,n)(r.prototype,t.name)}))}));var h=o[r.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 c.ArraySchema:y?new u.MapSchema:d?new p:void 0}}return f},o([s.type([l],h)],t.prototype,"types",void 0),o([s.type("uint8",h)],t.prototype,"rootType",void 0),t}(a.Schema);t.Reflection=p}])})); \ No newline at end of file +!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()}(self||this,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=15)}([function(e,t,n){"use strict";var r,i=this&&this.__extends||(r=function(e,t){return(r=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])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),o=this&&this.__spreadArrays||function(){for(var e=0,t=0,n=arguments.length;t=e+t-1}));return i.map((function(e){var t=e&&e.$changes;t&&(t.parent.deleteIndex(e),delete t.parent)})),o.forEach((function(e){var t=e&&e.$changes;t&&t.parentField--})),i},t}(Array);t.ArraySchema=s},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function e(t){var n=this;for(var r in void 0===t&&(t={}),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(t){var r;if(t)(r=Object.assign(new e,n)).onAdd=n.onAdd,r.onRemove=n.onRemove,r.onChange=n.onChange;else{var i=new e;for(var o in n)"object"==typeof n[o]?i[o]=n[o].clone():i[o]=n[o]}return r}},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(e){for(var t=0,r=new Map,i=0,o=e;im;_=w>0||A;var C=!1;A&&Array.prototype.splice.call(g,m).forEach((function(t,n){if(t&&t.onRemove)try{t.onRemove()}catch(t){e.onError(t)}if(b.onRemove)try{b.onRemove(t,m+n)}catch(t){e.onError(t)}}));for(var O=0;O0;C=!1;var x=Object.keys(k);for(O=0;O0){for(var n=0;n=400?o:i)(h)},(a=n.body)&&"object"==typeof a&&(f["content-type"]="application/json",a=JSON.stringify(a)),h.withCredentials=!!n.withCredentials,f)h.setRequestHeader(s,f[s]);h.send(a)}))}n.r(t),n.d(t,"send",(function(){return 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(5)),o=n(21),s=n(22),a=n(6),c=n(7),u=r(n(8)),h=r(n(9)),f=function(){function e(e,t){var n=this;this.onJoin=o.createSignal(),this.onStateChange=o.createSignal(),this.onError=o.createSignal(),this.onLeave=o.createSignal(),this.hasJoined=!1,this.onMessageHandlers={},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,t){return console.error("colyseus.js - onError => ("+e+") "+t)})),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){if(!t.hasJoined)return console.error("Room connection was closed unexpectedly ("+e.code+"): "+e.reason),void t.onError.invoke(e.code,e.reason);t.onLeave.invoke(e.code)},this.connection.onerror=function(e){console.warn("Room, onError ("+e.code+"): "+e.reason),t.onError.invoke(e.code,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.onMessage=function(e,t){return this.onMessageHandlers[this.getMessageHandlerKey(e)]=t,this},e.prototype.send=function(e,t){var n,r=[c.Protocol.ROOM_DATA];if("string"==typeof e?u.string(r,e):u.number(r,e),void 0!==t){var o=i.encode(t);(n=new Uint8Array(r.length+o.byteLength)).set(new Uint8Array(r),0),n.set(new Uint8Array(o),r.length)}else n=new Uint8Array(r);this.connection.send(n.buffer)},Object.defineProperty(e.prototype,"state",{get:function(){return this.serializer.getState()},enumerable:!0,configurable:!0}),e.prototype.listen=function(e,t,n){if("schema"!==this.serializerId)return this.serializerId||console.warn("room.Listen() should be called after room.onJoin has been called (DEPRECATION WARNING)"),this.serializer.api.listen(e,t,n);console.error("'"+this.serializerId+"' serializer doesn't support .listen() method here.")},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.onError.clear(),this.onLeave.clear()},e.prototype.onMessageCallback=function(e){var t=Array.from(new Uint8Array(e.data)),n=t[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);"fossil-delta"===this.serializerId||this.rootSchema||(this.serializer=new o),t.length>r&&this.serializer.handshake&&this.serializer.handshake(t,{offset:1}),this.hasJoined=!0,this.onJoin.invoke(),this.connection.send([c.Protocol.JOIN_ROOM])}else if(n===c.Protocol.ERROR){var s={offset:1},u=h.number(t,s),f=h.string(t,s);this.onError.invoke(u,f)}else if(n===c.Protocol.LEAVE_ROOM)this.leave();else if(n===c.Protocol.ROOM_DATA_SCHEMA){(f=new(p=this.serializer.getState().constructor._context.get(t[1]))).decode(t,{offset:2}),this.dispatchMessage(p,f)}else if(n===c.Protocol.ROOM_STATE)t.shift(),this.setState(t);else if(n===c.Protocol.ROOM_STATE_PATCH)t.shift(),this.patch(t);else if(n===c.Protocol.ROOM_DATA){var l={offset:1},p=h.stringCheck(t,l)?h.string(t,l):h.number(t,l);f=t.length>l.offset?i.decode(e.data,l.offset):void 0;this.dispatchMessage(p,f)}},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.prototype.dispatchMessage=function(e,t){var n=this.getMessageHandlerKey(e);this.onMessageHandlers[n]?this.onMessageHandlers[n](t):this.onMessageHandlers["*"]?this.onMessageHandlers["*"](e,t):console.warn("onMessage not registered for type '"+e+"'.")},e.prototype.getMessageHandlerKey=function(e){switch(typeof e){case"function":return"$"+e._typeid;case"string":return e;case"number":return"i"+e;default:throw new Error("invalid message type.")}},e}();t.Room=f},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(19)),o=r(n(20));t.decode=i.default,t.encode=o.default},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r={};t.registerSerializer=function(e,t){r[e]=t},t.getSerializer=function(e){return r[e]}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),function(e){e[e.HANDSHAKE=9]="HANDSHAKE",e[e.JOIN_ROOM=10]="JOIN_ROOM",e[e.ERROR=11]="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",e[e.ROOM_DATA_SCHEMA=16]="ROOM_DATA_SCHEMA"}(t.Protocol||(t.Protocol={})),function(e){e[e.MATCHMAKE_NO_HANDLER=4210]="MATCHMAKE_NO_HANDLER",e[e.MATCHMAKE_INVALID_CRITERIA=4211]="MATCHMAKE_INVALID_CRITERIA",e[e.MATCHMAKE_INVALID_ROOM_ID=4212]="MATCHMAKE_INVALID_ROOM_ID",e[e.MATCHMAKE_UNHANDLED=4213]="MATCHMAKE_UNHANDLED",e[e.MATCHMAKE_EXPIRED=4214]="MATCHMAKE_EXPIRED",e[e.AUTH_FAILED=4215]="AUTH_FAILED",e[e.APPLICATION_ERROR=4216]="APPLICATION_ERROR"}(t.ErrorCode||(t.ErrorCode={})),t.utf8Read=function(e,t){for(var n=e[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[++o])<<6|(63&e[++o])<<0);else r+=String.fromCharCode((31&a)<<6|63&e[++o]);else r+=String.fromCharCode(a)}return r},t.utf8Length=function(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}},function(e,t,n){"use strict";function r(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 i(e,t){e.push(255&t)}function o(e,t){e.push(255&t)}function s(e,t){e.push(255&t),e.push(t>>8&255)}function a(e,t){e.push(255&t),e.push(t>>8&255)}function c(e,t){e.push(255&t),e.push(t>>8&255),e.push(t>>16&255),e.push(t>>24&255)}function u(e,t){var n=t>>24,r=t>>16,i=t>>8,o=t;e.push(255&o),e.push(255&i),e.push(255&r),e.push(255&n)}function h(e,t){var n=Math.floor(t/Math.pow(2,32));u(e,t>>>0),u(e,n)}function f(e,t){var n=t/Math.pow(2,32)>>0;u(e,t>>>0),u(e,n)}Object.defineProperty(t,"__esModule",{value:!0}),t.utf8Write=r,t.int8=i,t.uint8=o,t.int16=s,t.uint16=a,t.int32=c,t.uint32=u,t.int64=h,t.uint64=f,t.float32=function(e,t){v(e,t)},t.float64=function(e,t){y(e,t)};var l=new Int32Array(2),p=new Float32Array(l.buffer),d=new Float64Array(l.buffer);function v(e,t){p[0]=t,c(e,l[0])}function y(e,t){d[0]=t,c(e,l[0]),c(e,l[1])}t.writeFloat32=v,t.writeFloat64=y,t.boolean=function(e,t){return o(e,t?1:0)},t.string=function(e,t){t||(t="");var n=function(e){for(var t=0,n=0,r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}(t),i=0;if(n<32)e.push(160|n),i=1;else if(n<256)e.push(217),o(e,n),i=2;else if(n<65536)e.push(218),a(e,n),i=3;else{if(!(n<4294967296))throw new Error("String too long");e.push(219),u(e,n),i=5}return r(e,e.length,t),i+n},t.number=function e(t,n){return isNaN(n)?e(t,0):isFinite(n)?n!==(0|n)?(t.push(203),y(t,n),9):n>=0?n<128?(o(t,n),1):n<256?(t.push(204),o(t,n),2):n<65536?(t.push(205),a(t,n),3):n<4294967296?(t.push(206),u(t,n),5):(t.push(207),f(t,n),9):n>=-32?(t.push(n),1):n>=-128?(t.push(208),i(t,n),2):n>=-32768?(t.push(209),s(t,n),3):n>=-2147483648?(t.push(210),c(t,n),5):(t.push(211),h(t,n),9):e(t,n>0?Number.MAX_SAFE_INTEGER:-Number.MAX_SAFE_INTEGER)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(10);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){var n=u(e,t);return c(e,t)*Math.pow(2,32)+n}function f(e,t){var n=u(e,t);return u(e,t)*Math.pow(2,32)+n}t.int8=i,t.uint8=o,t.int16=s,t.uint16=a,t.int32=c,t.uint32=u,t.float32=function(e,t){return v(e,t)},t.float64=function(e,t){return y(e,t)},t.int64=h,t.uint64=f;var l=new Int32Array(2),p=new Float32Array(l.buffer),d=new Float64Array(l.buffer);function v(e,t){return l[0]=c(e,t),p[0]}function y(e,t){return l[0]=c(e,t),l[1]=c(e,t),d[0]}t.readFloat32=v,t.readFloat64=y,t.boolean=function(e,t){return o(e,t)>0},t.string=function(e,t){var n,r=e[t.offset++];r<192?n=31&r:217===r?n=o(e,t):218===r?n=a(e,t):219===r&&(n=u(e,t));var i=function(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}(e,t.offset,n);return t.offset+=n,i},t.stringCheck=function(e,t){var n=e[t.offset];return n<192&&n>160||217===n||218===n||219===n},t.number=function(e,t){var n=e[t.offset++];return n<128?n:202===n?v(e,t):203===n?y(e,t):204===n?o(e,t):205===n?a(e,t):206===n?u(e,t):207===n?f(e,t):208===n?i(e,t):209===n?s(e,t):210===n?c(e,t):211===n?h(e,t):n>223?-1*(255-n+1):void 0},t.numberCheck=function(e,t){var n=e[t.offset];return n<128||n>=202&&n<=211},t.arrayCheck=function(e,t){return e[t.offset]<160},t.nilCheck=function(e,t){return e[t.offset]===r.NIL},t.indexChangeCheck=function(e,t){return e[t.offset]===r.INDEX_CHANGE}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.END_OF_STRUCTURE=193,t.NIL=192,t.INDEX_CHANGE=212,t.TYPE_ID=213},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){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},i=this&&this.__generator||function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0?"?"+r.join("&"):"",h={headers:a},o&&(h.body=o),[4,s[e](""+this.endpoint+t+u,h)];case 1:return[2,i.sent().data]}}))}))},e.prototype.logout=function(){this.token=void 0,a.removeItem("colyseus-auth-token"),this.unregisterPingService()},e.prototype.registerPingService=function(e){var t=this;void 0===e&&(e=15e3),this.unregisterPingService(),this.keepOnlineInterval=setInterval((function(){return t.request("get","/auth")}),e)},e.prototype.unregisterPingService=function(){clearInterval(this.keepOnlineInterval)},e}();t.Auth=c},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2);t.Schema=r.Schema;var i=n(1);t.MapSchema=i.MapSchema;var o=n(0);t.ArraySchema=o.ArraySchema;var s=n(35);t.dumpChanges=s.dumpChanges;var a=n(36);t.Reflection=a.Reflection,t.ReflectionType=a.ReflectionType,t.ReflectionField=a.ReflectionField;var c=n(14);t.type=c.type,t.deprecated=c.deprecated,t.filter=c.filter,t.defineTypes=c.defineTypes,t.Context=c.Context},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2),i=n(0),o=n(1),s=function(){function e(e,t,n){void 0===e&&(e={}),void 0===t&&(t=null),this.changed=!1,this.changes=new Set,this.allChanges=new Set,this.deletedKeys={},this.fieldIndexes=e,this.parent=n,this.parentField=t}return e.prototype.change=function(e,t){void 0===t&&(t=!1);var n=this.fieldIndexes[e],r="number"==typeof n?n:e;t?t&&(this.changed=!0,this.changes.add(r),this.allChanges.delete(r)):(this.changed=!0,this.changes.add(r),this.allChanges.add(r)),this.parent&&this.parent.change(this.parentField)},e.prototype.mapIndex=function(e,t){"object"==typeof e&&(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){"object"==typeof e&&(this.deletedKeys[this.indexMap.get(e)]=!0,this.indexMap.delete(e))},e.prototype.isDeleted=function(e){return void 0!==this.deletedKeys[e]},e.prototype.mapIndexChange=function(e,t){"object"!=typeof e||this.indexChange.has(e)||this.indexChange.set(e,t)},e.prototype.getIndexChange=function(e){return this.indexChange&&this.indexChange.get(e)},e.prototype.deleteIndexChange=function(e){"object"==typeof 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),void 0!==e[n]&&this.change(n)}else for(var s=0,a=Object.keys(e);s0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[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}(this._view,this._offset,e);return this._offset+=e,t},r.prototype._bin=function(e){var t=this._buffer.slice(this._offset,this._offset+e);return this._offset+=e,t},r.prototype._parse=function(){var e,t=this._view.getUint8(this._offset++),n=0,r=0,i=0,o=0;if(t<192)return t<128?t:t<144?this._map(15&t):t<160?this._array(15&t):this._str(31&t);if(t>223)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")},t.default=function(e,t){void 0===t&&(t=0);var n=new r(e,t),i=n._parse();if(n._offset!==e.byteLength)throw new Error(e.byteLength-n._offset+" trailing bytes");return i}},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))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){var t=[],n=[],i=function e(t,n,r){var i=typeof r,o=0,s=0,a=0,c=0,u=0,h=0;if("string"===i){if((u=function(e){for(var t=0,n=0,r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}(r))<32)t.push(160|u),h=1;else if(u<256)t.push(217,u),h=2;else if(u<65536)t.push(218,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("String too long");t.push(219,u>>24,u>>16,u>>8,u),h=5}return n.push({_str:r,_length:u,_offset:t.length}),h+u}if("number"===i)return Math.floor(r)===r&&isFinite(r)?r>=0?r<128?(t.push(r),1):r<256?(t.push(204,r),2):r<65536?(t.push(205,r>>8,r),3):r<4294967296?(t.push(206,r>>24,r>>16,r>>8,r),5):(a=r/Math.pow(2,32)>>0,c=r>>>0,t.push(207,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),9):r>=-32?(t.push(r),1):r>=-128?(t.push(208,r),2):r>=-32768?(t.push(209,r>>8,r),3):r>=-2147483648?(t.push(210,r>>24,r>>16,r>>8,r),5):(a=Math.floor(r/Math.pow(2,32)),c=r>>>0,t.push(211,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),9):(t.push(203),n.push({_float:r,_length:8,_offset:t.length}),9);if("object"===i){if(null===r)return t.push(192),1;if(Array.isArray(r)){if((u=r.length)<16)t.push(144|u),h=1;else if(u<65536)t.push(220,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("Array too large");t.push(221,u>>24,u>>16,u>>8,u),h=5}for(o=0;o>>0,t.push(215,0,a>>24,a>>16,a>>8,a,c>>24,c>>16,c>>8,c),10}if(r instanceof ArrayBuffer){if((u=r.byteLength)<256)t.push(196,u),h=2;else if(u<65536)t.push(197,u>>8,u),h=3;else{if(!(u<4294967296))throw new Error("Buffer too large");t.push(198,u>>24,u>>16,u>>8,u),h=5}return n.push({_bin:r,_length:u,_offset:t.length}),h+u}if("function"==typeof r.toJSON)return e(t,n,r.toJSON());var l=[],p="",d=Object.keys(r);for(o=0,s=d.length;o>8,u),h=3;else{if(!(u<4294967296))throw new Error("Object too large");t.push(223,u>>24,u>>16,u>>8,u),h=5}for(o=0;o0&&(u=n[0]._offset);for(var h,f=0,l=0,p=0,d=t.length;p0){for(var n=0,r=this._enqueuedCalls;n2&&void 0!==arguments[2]?arguments[2]:{};i(this,e),this.url=t,this.protocols=n,this.reconnectEnabled=!0,this.listeners={},this.backoff=o(r.backoff||"exponential",r),this.backoff.onReady=this.onBackoffReady.bind(this),(void 0===r.connect||r.connect)&&this.open()}return r(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";Object.defineProperty(t,"__esModule",{value:!0}),t.createBackoff=function(e,t){return new i(r[e],t)};var r={exponential:function(e,t){return Math.floor(Math.random()*Math.pow(2,e)*t)},fibonacci:function(e,t){if(e>(r=1))for(var n=1,r=2,i=2;i0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[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(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=e.slice();return n.push(t),n}function i(e){if(Array.isArray(e)){for(var t=new Array(e.length),n=0;n=0;h--){var f=c[h],l=t[f];if(!n.hasOwnProperty(f)||void 0===n[f]&&void 0!==l&&!1===Array.isArray(n))o.push({operation:"remove",path:r(s,f)}),u=!0;else{var p=n[f];"object"==typeof l&&null!=l&&"object"==typeof p&&null!=p?e(l,p,o,r(s,f)):l!==p&&o.push({operation:"replace",path:r(s,f),value:p,previousValue:l})}}if(!u&&a.length==c.length)return;for(h=a.length-1;h>=0;h--){f=a[h];if(!t.hasOwnProperty(f)&&void 0!==n[f]){p=n[f];var d=r(s,f);"object"==typeof p&&null!=p&&e({},p,o,d),o.push({operation:"add",path:d,value:p})}}}(e,t,n,[]),n}},function(e,t,n){var r,i;r=this,i=function(){"use strict";var e={};function t(){this.a=0,this.b=0,this.i=0,this.z=new Array(16)}t.prototype.init=function(e,t){var n,r,i=0,o=0;for(n=0;n<16;n++)i=i+(r=e[t+n])&65535,o=o+(16-n)*r&65535,this.z[n]=r;this.a=65535&i,this.b=65535&o,this.i=0},t.prototype.next=function(e){var t=this.z[this.i];this.z[this.i]=e,this.i=this.i+1&15,this.a=this.a-t+e&65535,this.b=this.b-16*t+this.a&65535},t.prototype.value=function(){return(65535&this.a|(65535&this.b)<<16)>>>0};var n="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~".split("").map((function(e){return e.charCodeAt(0)})),r=[-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];function i(e){this.a=e,this.pos=0}function o(){this.a=[]}function s(e){var t,n;for(t=1,n=64;e>=n;t++,n<<=6);return t}function a(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}return i.prototype.haveBytes=function(){return this.posthis.a.length)throw new RangeError("out of bounds");return e},i.prototype.getChar=function(){return String.fromCharCode(this.getByte())},i.prototype.getInt=function(){for(var e,t=0;this.haveBytes()&&(e=r[127&this.getByte()])>=0;)t=(t<<6)+e;return this.pos--,t>>>0},o.prototype.toArray=function(){return this.a},o.prototype.putByte=function(e){this.a.push(255&e)},o.prototype.putChar=function(e){this.putByte(e.charCodeAt(0))},o.prototype.putInt=function(e){var t,r,i=[];if(0!==e){for(t=0;e>0;t++,e>>>=6)i.push(n[63&e]);for(r=t-1;r>=0;r--)this.putByte(i[r])}else this.putChar("0")},o.prototype.putArray=function(e,t,n){for(var r=t;r=0&&A-- >0;){var C,O,S,E,I,M,k;for(E=0,M=y=16*g,k=w+r;M=s(r-I)+s(C)+s(O)+3&&C>_&&(_=C,b=y-I,m=S),g=l[g]}if(_>0){m>0&&(i.putInt(m),i.putChar(":"),i.putArray(n,w,w+m),w+=m),w+=_,i.putInt(_),i.putChar("@"),i.putInt(b),i.putChar(","),b+_-1>h&&(h=b+_-1),_=0;break}if(w+r+16>=c){i.putInt(c-w),i.putChar(":"),i.putArray(n,w,w+c-w),w=c;break}v.next(n[w+r+16]),r++}return wr)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((s+=l)>r)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((!n||!1!==n.verifyChecksum)&&l!==a(d))throw new Error("bad checksum");if(s!==r)throw new Error("generated size does not match predicted size");return d;default:throw new Error("unknown delta operator")}}throw new Error("unterminated delta")},e},e.exports?e.exports=i():r.fossilDelta=i()},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(12),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,t){this.state?(new r.Reflection).decode(e,t):this.state=r.Reflection.decode(e)},e}();t.SchemaSerializer=i},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(){this.handlers=[]}return e.prototype.register=function(e,t){return void 0===t&&(t=!1),this.handlers.push(e),this},e.prototype.invoke=function(){for(var e=[],t=0;t=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 s=n(14),a=n(2),c=n(0),u=n(1),h=new s.Context,f=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),o([s.type("string",h)],t.prototype,"name",void 0),o([s.type("string",h)],t.prototype,"type",void 0),o([s.type("uint8",h)],t.prototype,"referencedType",void 0),t}(a.Schema);t.ReflectionField=f;var l=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.fields=new c.ArraySchema,t}return i(t,e),o([s.type("uint8",h)],t.prototype,"id",void 0),o([s.type([f],h)],t.prototype,"fields",void 0),t}(a.Schema);t.ReflectionType=l;var p=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.types=new c.ArraySchema,t}return i(t,e),t.encode=function(e){var n=e.constructor,r=new t;r.rootType=n._typeid;var i=function(e,t){for(var n in t){var i=new f;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)},o=n._context.types;for(var s in o){var a=new l;a.id=Number(s),i(a,o[s]._schema)}return r.encodeAll()},t.decode=function(e){var n=new s.Context,r=new t;r.decode(e);var o=r.types.reduce((function(e,t){return e[t.id]=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),t}(a.Schema),e}),{});r.types.forEach((function(e,t){e.fields.forEach((function(t){var r=o[e.id];if(void 0!==t.referencedType){var i=o[t.referencedType];i||(i=t.type.split(":")[1]),0===t.type.indexOf("array")?s.type([i],n)(r.prototype,t.name):0===t.type.indexOf("map")?s.type({map:i},n)(r.prototype,t.name):"ref"===t.type&&s.type(i,n)(r.prototype,t.name)}else s.type(t.type,n)(r.prototype,t.name)}))}));var h=o[r.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 c.ArraySchema:y?new u.MapSchema:d?new p:void 0}}return f},o([s.type([l],h)],t.prototype,"types",void 0),o([s.type("uint8",h)],t.prototype,"rootType",void 0),t}(a.Schema);t.Reflection=p}])})); \ No newline at end of file diff --git a/package.json b/package.json index 5d13207..791acdd 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,8 @@ "scripts": { "test": "mocha test/*.ts --require ts-node/register", "build": "webpack --env.production", + "build-dev": "webpack", + "build-all": "npm run build && npm run build-dev", "watch": "tsc -w", "prepublish": "tsc && npm run build", "tslint": "tslint --project ." @@ -58,8 +60,8 @@ "tslint": "^5.9.1", "typescript": "^3.8.3", "uglify-js": "^2.6.1", - "webpack": "^4.41.2", - "webpack-cli": "^3.3.10", + "webpack": "^4.42.1", + "webpack-cli": "^3.3.11", "ws": "^6.1.2" } } diff --git a/webpack.config.js b/webpack.config.js index 39e25a3..9e381df 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -15,6 +15,7 @@ module.exports = function(options) { ? "colyseus.js" : "colyseus.dev.js", + globalObject: "self || this", // compatibility with Web Workers. libraryTarget: "umd", library: "Colyseus" }, From d1bd377e9a63992d441eb9b3da09076a0a0c1912 Mon Sep 17 00:00:00 2001 From: Endel Dreyer Date: Wed, 22 Apr 2020 16:24:56 +0300 Subject: [PATCH 11/11] bump 0.13.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 791acdd..cf299b9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "colyseus.js", - "version": "0.13.0-alpha.10", + "version": "0.13.0", "description": "Multiplayer Game Client for the Browser", "keywords": [ "colyseus",