@dill-pixel/plugin-colyseus
Version:
Colyseus
1 lines • 341 kB
Source Map (JSON)
{"version":3,"file":"dill-pixel-plugin-colyseus.mjs","sources":["../../../../node_modules/.pnpm/colyseus.js@0.15.28/node_modules/colyseus.js/lib/legacy.js","../../../../node_modules/.pnpm/colyseus.js@0.15.28/node_modules/colyseus.js/lib/errors/ServerError.js","../../../../node_modules/.pnpm/colyseus.js@0.15.28/node_modules/colyseus.js/lib/msgpack/index.js","../../../../node_modules/.pnpm/ws@8.18.2/node_modules/ws/browser.js","../../../../node_modules/.pnpm/colyseus.js@0.15.28/node_modules/colyseus.js/lib/transport/WebSocketTransport.js","../../../../node_modules/.pnpm/colyseus.js@0.15.28/node_modules/colyseus.js/lib/Connection.js","../../../../node_modules/.pnpm/colyseus.js@0.15.28/node_modules/colyseus.js/lib/Protocol.js","../../../../node_modules/.pnpm/colyseus.js@0.15.28/node_modules/colyseus.js/lib/serializer/Serializer.js","../../../../node_modules/.pnpm/colyseus.js@0.15.28/node_modules/colyseus.js/lib/core/nanoevents.js","../../../../node_modules/.pnpm/colyseus.js@0.15.28/node_modules/colyseus.js/lib/core/signal.js","../../../../node_modules/.pnpm/@colyseus+schema@2.0.37/node_modules/@colyseus/schema/build/umd/index.js","../../../../node_modules/.pnpm/colyseus.js@0.15.28/node_modules/colyseus.js/lib/Room.js","../../../../node_modules/.pnpm/httpie@2.0.0-next.13/node_modules/httpie/xhr/index.mjs","../../../../node_modules/.pnpm/colyseus.js@0.15.28/node_modules/colyseus.js/lib/HTTP.js","../../../../node_modules/.pnpm/colyseus.js@0.15.28/node_modules/colyseus.js/lib/Storage.js","../../../../node_modules/.pnpm/colyseus.js@0.15.28/node_modules/colyseus.js/lib/Auth.js","../../../../node_modules/.pnpm/colyseus.js@0.15.28/node_modules/colyseus.js/lib/3rd_party/discord.js","../../../../node_modules/.pnpm/colyseus.js@0.15.28/node_modules/colyseus.js/lib/Client.js","../../../../node_modules/.pnpm/colyseus.js@0.15.28/node_modules/colyseus.js/lib/serializer/SchemaSerializer.js","../../../../node_modules/.pnpm/colyseus.js@0.15.28/node_modules/colyseus.js/lib/serializer/NoneSerializer.js","../../../../node_modules/.pnpm/colyseus.js@0.15.28/node_modules/colyseus.js/lib/index.js","../src/ColyseusPlugin.ts"],"sourcesContent":["//\n// Polyfills for legacy environments\n//\n/*\n * Support Android 4.4.x\n */\nif (!ArrayBuffer.isView) {\n ArrayBuffer.isView = (a) => {\n return a !== null && typeof (a) === 'object' && a.buffer instanceof ArrayBuffer;\n };\n}\n// Define globalThis if not available.\n// https://github.com/colyseus/colyseus.js/issues/86\nif (typeof (globalThis) === \"undefined\" &&\n typeof (window) !== \"undefined\") {\n // @ts-ignore\n window['globalThis'] = window;\n}\n//# sourceMappingURL=legacy.js.map","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.ServerError = exports.CloseCode = void 0;\nvar CloseCode;\n(function (CloseCode) {\n CloseCode[CloseCode[\"CONSENTED\"] = 4000] = \"CONSENTED\";\n CloseCode[CloseCode[\"DEVMODE_RESTART\"] = 4010] = \"DEVMODE_RESTART\";\n})(CloseCode = exports.CloseCode || (exports.CloseCode = {}));\nclass ServerError extends Error {\n constructor(code, message) {\n super(message);\n this.name = \"ServerError\";\n this.code = code;\n }\n}\nexports.ServerError = ServerError;\n//# sourceMappingURL=ServerError.js.map","\"use strict\";\n/**\n * Copyright (c) 2014 Ion Drive Software Ltd.\n * https://github.com/darrachequesne/notepack/\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.decode = exports.encode = void 0;\n/**\n * Patch for Colyseus:\n * -------------------\n * notepack.io@3.0.1\n *\n * added `offset` on Decoder constructor, for messages arriving with a code\n * before actual msgpack data\n */\n//\n// DECODER\n//\nfunction Decoder(buffer, offset) {\n this._offset = offset;\n if (buffer instanceof ArrayBuffer) {\n this._buffer = buffer;\n this._view = new DataView(this._buffer);\n }\n else if (ArrayBuffer.isView(buffer)) {\n this._buffer = buffer.buffer;\n this._view = new DataView(this._buffer, buffer.byteOffset, buffer.byteLength);\n }\n else {\n throw new Error('Invalid argument');\n }\n}\nfunction utf8Read(view, offset, length) {\n var string = '', chr = 0;\n for (var i = offset, end = offset + length; i < end; i++) {\n var byte = view.getUint8(i);\n if ((byte & 0x80) === 0x00) {\n string += String.fromCharCode(byte);\n continue;\n }\n if ((byte & 0xe0) === 0xc0) {\n string += String.fromCharCode(((byte & 0x1f) << 6) |\n (view.getUint8(++i) & 0x3f));\n continue;\n }\n if ((byte & 0xf0) === 0xe0) {\n string += String.fromCharCode(((byte & 0x0f) << 12) |\n ((view.getUint8(++i) & 0x3f) << 6) |\n ((view.getUint8(++i) & 0x3f) << 0));\n continue;\n }\n if ((byte & 0xf8) === 0xf0) {\n chr = ((byte & 0x07) << 18) |\n ((view.getUint8(++i) & 0x3f) << 12) |\n ((view.getUint8(++i) & 0x3f) << 6) |\n ((view.getUint8(++i) & 0x3f) << 0);\n if (chr >= 0x010000) { // surrogate pair\n chr -= 0x010000;\n string += String.fromCharCode((chr >>> 10) + 0xD800, (chr & 0x3FF) + 0xDC00);\n }\n else {\n string += String.fromCharCode(chr);\n }\n continue;\n }\n throw new Error('Invalid byte ' + byte.toString(16));\n }\n return string;\n}\nDecoder.prototype._array = function (length) {\n var value = new Array(length);\n for (var i = 0; i < length; i++) {\n value[i] = this._parse();\n }\n return value;\n};\nDecoder.prototype._map = function (length) {\n var key = '', value = {};\n for (var i = 0; i < length; i++) {\n key = this._parse();\n value[key] = this._parse();\n }\n return value;\n};\nDecoder.prototype._str = function (length) {\n var value = utf8Read(this._view, this._offset, length);\n this._offset += length;\n return value;\n};\nDecoder.prototype._bin = function (length) {\n var value = this._buffer.slice(this._offset, this._offset + length);\n this._offset += length;\n return value;\n};\nDecoder.prototype._parse = function () {\n var prefix = this._view.getUint8(this._offset++);\n var value, length = 0, type = 0, hi = 0, lo = 0;\n if (prefix < 0xc0) {\n // positive fixint\n if (prefix < 0x80) {\n return prefix;\n }\n // fixmap\n if (prefix < 0x90) {\n return this._map(prefix & 0x0f);\n }\n // fixarray\n if (prefix < 0xa0) {\n return this._array(prefix & 0x0f);\n }\n // fixstr\n return this._str(prefix & 0x1f);\n }\n // negative fixint\n if (prefix > 0xdf) {\n return (0xff - prefix + 1) * -1;\n }\n switch (prefix) {\n // nil\n case 0xc0:\n return null;\n // false\n case 0xc2:\n return false;\n // true\n case 0xc3:\n return true;\n // bin\n case 0xc4:\n length = this._view.getUint8(this._offset);\n this._offset += 1;\n return this._bin(length);\n case 0xc5:\n length = this._view.getUint16(this._offset);\n this._offset += 2;\n return this._bin(length);\n case 0xc6:\n length = this._view.getUint32(this._offset);\n this._offset += 4;\n return this._bin(length);\n // ext\n case 0xc7:\n length = this._view.getUint8(this._offset);\n type = this._view.getInt8(this._offset + 1);\n this._offset += 2;\n if (type === -1) {\n // timestamp 96\n var ns = this._view.getUint32(this._offset);\n hi = this._view.getInt32(this._offset + 4);\n lo = this._view.getUint32(this._offset + 8);\n this._offset += 12;\n return new Date((hi * 0x100000000 + lo) * 1e3 + ns / 1e6);\n }\n return [type, this._bin(length)];\n case 0xc8:\n length = this._view.getUint16(this._offset);\n type = this._view.getInt8(this._offset + 2);\n this._offset += 3;\n return [type, this._bin(length)];\n case 0xc9:\n length = this._view.getUint32(this._offset);\n type = this._view.getInt8(this._offset + 4);\n this._offset += 5;\n return [type, this._bin(length)];\n // float\n case 0xca:\n value = this._view.getFloat32(this._offset);\n this._offset += 4;\n return value;\n case 0xcb:\n value = this._view.getFloat64(this._offset);\n this._offset += 8;\n return value;\n // uint\n case 0xcc:\n value = this._view.getUint8(this._offset);\n this._offset += 1;\n return value;\n case 0xcd:\n value = this._view.getUint16(this._offset);\n this._offset += 2;\n return value;\n case 0xce:\n value = this._view.getUint32(this._offset);\n this._offset += 4;\n return value;\n case 0xcf:\n hi = this._view.getUint32(this._offset) * Math.pow(2, 32);\n lo = this._view.getUint32(this._offset + 4);\n this._offset += 8;\n return hi + lo;\n // int\n case 0xd0:\n value = this._view.getInt8(this._offset);\n this._offset += 1;\n return value;\n case 0xd1:\n value = this._view.getInt16(this._offset);\n this._offset += 2;\n return value;\n case 0xd2:\n value = this._view.getInt32(this._offset);\n this._offset += 4;\n return value;\n case 0xd3:\n hi = this._view.getInt32(this._offset) * Math.pow(2, 32);\n lo = this._view.getUint32(this._offset + 4);\n this._offset += 8;\n return hi + lo;\n // fixext\n case 0xd4:\n type = this._view.getInt8(this._offset);\n this._offset += 1;\n if (type === 0x00) {\n // custom encoding for 'undefined' (kept for backward-compatibility)\n this._offset += 1;\n return void 0;\n }\n return [type, this._bin(1)];\n case 0xd5:\n type = this._view.getInt8(this._offset);\n this._offset += 1;\n return [type, this._bin(2)];\n case 0xd6:\n type = this._view.getInt8(this._offset);\n this._offset += 1;\n if (type === -1) {\n // timestamp 32\n value = this._view.getUint32(this._offset);\n this._offset += 4;\n return new Date(value * 1e3);\n }\n return [type, this._bin(4)];\n case 0xd7:\n type = this._view.getInt8(this._offset);\n this._offset += 1;\n if (type === 0x00) {\n // custom date encoding (kept for backward-compatibility)\n hi = this._view.getInt32(this._offset) * Math.pow(2, 32);\n lo = this._view.getUint32(this._offset + 4);\n this._offset += 8;\n return new Date(hi + lo);\n }\n if (type === -1) {\n // timestamp 64\n hi = this._view.getUint32(this._offset);\n lo = this._view.getUint32(this._offset + 4);\n this._offset += 8;\n var s = (hi & 0x3) * 0x100000000 + lo;\n return new Date(s * 1e3 + (hi >>> 2) / 1e6);\n }\n return [type, this._bin(8)];\n case 0xd8:\n type = this._view.getInt8(this._offset);\n this._offset += 1;\n return [type, this._bin(16)];\n // str\n case 0xd9:\n length = this._view.getUint8(this._offset);\n this._offset += 1;\n return this._str(length);\n case 0xda:\n length = this._view.getUint16(this._offset);\n this._offset += 2;\n return this._str(length);\n case 0xdb:\n length = this._view.getUint32(this._offset);\n this._offset += 4;\n return this._str(length);\n // array\n case 0xdc:\n length = this._view.getUint16(this._offset);\n this._offset += 2;\n return this._array(length);\n case 0xdd:\n length = this._view.getUint32(this._offset);\n this._offset += 4;\n return this._array(length);\n // map\n case 0xde:\n length = this._view.getUint16(this._offset);\n this._offset += 2;\n return this._map(length);\n case 0xdf:\n length = this._view.getUint32(this._offset);\n this._offset += 4;\n return this._map(length);\n }\n throw new Error('Could not parse');\n};\nfunction decode(buffer, offset = 0) {\n var decoder = new Decoder(buffer, offset);\n var value = decoder._parse();\n if (decoder._offset !== buffer.byteLength) {\n throw new Error((buffer.byteLength - decoder._offset) + ' trailing bytes');\n }\n return value;\n}\nexports.decode = decode;\n//\n// ENCODER\n//\nvar TIMESTAMP32_MAX_SEC = 0x100000000 - 1; // 32-bit unsigned int\nvar TIMESTAMP64_MAX_SEC = 0x400000000 - 1; // 34-bit unsigned int\nfunction utf8Write(view, offset, str) {\n var c = 0;\n for (var i = 0, l = str.length; i < l; i++) {\n c = str.charCodeAt(i);\n if (c < 0x80) {\n view.setUint8(offset++, c);\n }\n else if (c < 0x800) {\n view.setUint8(offset++, 0xc0 | (c >> 6));\n view.setUint8(offset++, 0x80 | (c & 0x3f));\n }\n else if (c < 0xd800 || c >= 0xe000) {\n view.setUint8(offset++, 0xe0 | (c >> 12));\n view.setUint8(offset++, 0x80 | (c >> 6) & 0x3f);\n view.setUint8(offset++, 0x80 | (c & 0x3f));\n }\n else {\n i++;\n c = 0x10000 + (((c & 0x3ff) << 10) | (str.charCodeAt(i) & 0x3ff));\n view.setUint8(offset++, 0xf0 | (c >> 18));\n view.setUint8(offset++, 0x80 | (c >> 12) & 0x3f);\n view.setUint8(offset++, 0x80 | (c >> 6) & 0x3f);\n view.setUint8(offset++, 0x80 | (c & 0x3f));\n }\n }\n}\nfunction utf8Length(str) {\n var c = 0, length = 0;\n for (var i = 0, l = str.length; i < l; i++) {\n c = str.charCodeAt(i);\n if (c < 0x80) {\n length += 1;\n }\n else if (c < 0x800) {\n length += 2;\n }\n else if (c < 0xd800 || c >= 0xe000) {\n length += 3;\n }\n else {\n i++;\n length += 4;\n }\n }\n return length;\n}\nfunction _encode(bytes, defers, value) {\n var type = typeof value, i = 0, l = 0, hi = 0, lo = 0, length = 0, size = 0;\n if (type === 'string') {\n length = utf8Length(value);\n // fixstr\n if (length < 0x20) {\n bytes.push(length | 0xa0);\n size = 1;\n }\n // str 8\n else if (length < 0x100) {\n bytes.push(0xd9, length);\n size = 2;\n }\n // str 16\n else if (length < 0x10000) {\n bytes.push(0xda, length >> 8, length);\n size = 3;\n }\n // str 32\n else if (length < 0x100000000) {\n bytes.push(0xdb, length >> 24, length >> 16, length >> 8, length);\n size = 5;\n }\n else {\n throw new Error('String too long');\n }\n defers.push({ _str: value, _length: length, _offset: bytes.length });\n return size + length;\n }\n if (type === 'number') {\n // TODO: encode to float 32?\n // float 64\n if (Math.floor(value) !== value || !isFinite(value)) {\n bytes.push(0xcb);\n defers.push({ _float: value, _length: 8, _offset: bytes.length });\n return 9;\n }\n if (value >= 0) {\n // positive fixnum\n if (value < 0x80) {\n bytes.push(value);\n return 1;\n }\n // uint 8\n if (value < 0x100) {\n bytes.push(0xcc, value);\n return 2;\n }\n // uint 16\n if (value < 0x10000) {\n bytes.push(0xcd, value >> 8, value);\n return 3;\n }\n // uint 32\n if (value < 0x100000000) {\n bytes.push(0xce, value >> 24, value >> 16, value >> 8, value);\n return 5;\n }\n // uint 64\n hi = (value / Math.pow(2, 32)) >> 0;\n lo = value >>> 0;\n bytes.push(0xcf, hi >> 24, hi >> 16, hi >> 8, hi, lo >> 24, lo >> 16, lo >> 8, lo);\n return 9;\n }\n else {\n // negative fixnum\n if (value >= -0x20) {\n bytes.push(value);\n return 1;\n }\n // int 8\n if (value >= -0x80) {\n bytes.push(0xd0, value);\n return 2;\n }\n // int 16\n if (value >= -0x8000) {\n bytes.push(0xd1, value >> 8, value);\n return 3;\n }\n // int 32\n if (value >= -0x80000000) {\n bytes.push(0xd2, value >> 24, value >> 16, value >> 8, value);\n return 5;\n }\n // int 64\n hi = Math.floor(value / Math.pow(2, 32));\n lo = value >>> 0;\n bytes.push(0xd3, hi >> 24, hi >> 16, hi >> 8, hi, lo >> 24, lo >> 16, lo >> 8, lo);\n return 9;\n }\n }\n if (type === 'object') {\n // nil\n if (value === null) {\n bytes.push(0xc0);\n return 1;\n }\n if (Array.isArray(value)) {\n length = value.length;\n // fixarray\n if (length < 0x10) {\n bytes.push(length | 0x90);\n size = 1;\n }\n // array 16\n else if (length < 0x10000) {\n bytes.push(0xdc, length >> 8, length);\n size = 3;\n }\n // array 32\n else if (length < 0x100000000) {\n bytes.push(0xdd, length >> 24, length >> 16, length >> 8, length);\n size = 5;\n }\n else {\n throw new Error('Array too large');\n }\n for (i = 0; i < length; i++) {\n size += _encode(bytes, defers, value[i]);\n }\n return size;\n }\n if (value instanceof Date) {\n var ms = value.getTime();\n var s = Math.floor(ms / 1e3);\n var ns = (ms - s * 1e3) * 1e6;\n if (s >= 0 && ns >= 0 && s <= TIMESTAMP64_MAX_SEC) {\n if (ns === 0 && s <= TIMESTAMP32_MAX_SEC) {\n // timestamp 32\n bytes.push(0xd6, 0xff, s >> 24, s >> 16, s >> 8, s);\n return 6;\n }\n else {\n // timestamp 64\n hi = s / 0x100000000;\n lo = s & 0xffffffff;\n bytes.push(0xd7, 0xff, ns >> 22, ns >> 14, ns >> 6, hi, lo >> 24, lo >> 16, lo >> 8, lo);\n return 10;\n }\n }\n else {\n // timestamp 96\n hi = Math.floor(s / 0x100000000);\n lo = s >>> 0;\n bytes.push(0xc7, 0x0c, 0xff, ns >> 24, ns >> 16, ns >> 8, ns, hi >> 24, hi >> 16, hi >> 8, hi, lo >> 24, lo >> 16, lo >> 8, lo);\n return 15;\n }\n }\n if (value instanceof ArrayBuffer) {\n length = value.byteLength;\n // bin 8\n if (length < 0x100) {\n bytes.push(0xc4, length);\n size = 2;\n }\n else \n // bin 16\n if (length < 0x10000) {\n bytes.push(0xc5, length >> 8, length);\n size = 3;\n }\n else \n // bin 32\n if (length < 0x100000000) {\n bytes.push(0xc6, length >> 24, length >> 16, length >> 8, length);\n size = 5;\n }\n else {\n throw new Error('Buffer too large');\n }\n defers.push({ _bin: value, _length: length, _offset: bytes.length });\n return size + length;\n }\n if (typeof value.toJSON === 'function') {\n return _encode(bytes, defers, value.toJSON());\n }\n var keys = [], key = '';\n var allKeys = Object.keys(value);\n for (i = 0, l = allKeys.length; i < l; i++) {\n key = allKeys[i];\n if (value[key] !== undefined && typeof value[key] !== 'function') {\n keys.push(key);\n }\n }\n length = keys.length;\n // fixmap\n if (length < 0x10) {\n bytes.push(length | 0x80);\n size = 1;\n }\n // map 16\n else if (length < 0x10000) {\n bytes.push(0xde, length >> 8, length);\n size = 3;\n }\n // map 32\n else if (length < 0x100000000) {\n bytes.push(0xdf, length >> 24, length >> 16, length >> 8, length);\n size = 5;\n }\n else {\n throw new Error('Object too large');\n }\n for (i = 0; i < length; i++) {\n key = keys[i];\n size += _encode(bytes, defers, key);\n size += _encode(bytes, defers, value[key]);\n }\n return size;\n }\n // false/true\n if (type === 'boolean') {\n bytes.push(value ? 0xc3 : 0xc2);\n return 1;\n }\n if (type === 'undefined') {\n bytes.push(0xc0);\n return 1;\n }\n // custom types like BigInt (typeof value === 'bigint')\n if (typeof value.toJSON === 'function') {\n return _encode(bytes, defers, value.toJSON());\n }\n throw new Error('Could not encode');\n}\nfunction encode(value) {\n var bytes = [];\n var defers = [];\n var size = _encode(bytes, defers, value);\n var buf = new ArrayBuffer(size);\n var view = new DataView(buf);\n var deferIndex = 0;\n var deferWritten = 0;\n var nextOffset = -1;\n if (defers.length > 0) {\n nextOffset = defers[0]._offset;\n }\n var defer, deferLength = 0, offset = 0;\n for (var i = 0, l = bytes.length; i < l; i++) {\n view.setUint8(deferWritten + i, bytes[i]);\n if (i + 1 !== nextOffset) {\n continue;\n }\n defer = defers[deferIndex];\n deferLength = defer._length;\n offset = deferWritten + nextOffset;\n if (defer._bin) {\n var bin = new Uint8Array(defer._bin);\n for (var j = 0; j < deferLength; j++) {\n view.setUint8(offset + j, bin[j]);\n }\n }\n else if (defer._str) {\n utf8Write(view, offset, defer._str);\n }\n else if (defer._float !== undefined) {\n view.setFloat64(offset, defer._float);\n }\n deferIndex++;\n deferWritten += deferLength;\n if (defers[deferIndex]) {\n nextOffset = defers[deferIndex]._offset;\n }\n }\n return buf;\n}\nexports.encode = encode;\n//# sourceMappingURL=index.js.map","'use strict';\n\nmodule.exports = function () {\n throw new Error(\n 'ws does not work in the browser. Browser clients must use the native ' +\n 'WebSocket object'\n );\n};\n","\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.WebSocketTransport = void 0;\nconst ws_1 = __importDefault(require(\"ws\"));\nconst WebSocket = globalThis.WebSocket || ws_1.default;\nclass WebSocketTransport {\n constructor(events) {\n this.events = events;\n }\n send(data) {\n if (data instanceof ArrayBuffer) {\n this.ws.send(data);\n }\n else if (Array.isArray(data)) {\n this.ws.send((new Uint8Array(data)).buffer);\n }\n }\n /**\n * @param url URL to connect to\n * @param headers custom headers to send with the connection (only supported in Node.js. Web Browsers do not allow setting custom headers)\n */\n connect(url, headers) {\n try {\n // Node or Bun environments (supports custom headers)\n this.ws = new WebSocket(url, { headers, protocols: this.protocols });\n }\n catch (e) {\n // browser environment (custom headers not supported)\n this.ws = new WebSocket(url, this.protocols);\n }\n this.ws.binaryType = 'arraybuffer';\n this.ws.onopen = this.events.onopen;\n this.ws.onmessage = this.events.onmessage;\n this.ws.onclose = this.events.onclose;\n this.ws.onerror = this.events.onerror;\n }\n close(code, reason) {\n this.ws.close(code, reason);\n }\n get isOpen() {\n return this.ws.readyState === WebSocket.OPEN;\n }\n}\nexports.WebSocketTransport = WebSocketTransport;\n//# sourceMappingURL=WebSocketTransport.js.map","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.Connection = void 0;\nconst WebSocketTransport_1 = require(\"./transport/WebSocketTransport\");\nclass Connection {\n constructor() {\n this.events = {};\n this.transport = new WebSocketTransport_1.WebSocketTransport(this.events);\n }\n send(data) {\n this.transport.send(data);\n }\n connect(url, options) {\n this.transport.connect(url, options);\n }\n close(code, reason) {\n this.transport.close(code, reason);\n }\n get isOpen() {\n return this.transport.isOpen;\n }\n}\nexports.Connection = Connection;\n//# sourceMappingURL=Connection.js.map","\"use strict\";\n// Use codes between 0~127 for lesser throughput (1 byte)\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.utf8Length = exports.utf8Read = exports.ErrorCode = exports.Protocol = void 0;\nvar Protocol;\n(function (Protocol) {\n // Room-related (10~19)\n Protocol[Protocol[\"HANDSHAKE\"] = 9] = \"HANDSHAKE\";\n Protocol[Protocol[\"JOIN_ROOM\"] = 10] = \"JOIN_ROOM\";\n Protocol[Protocol[\"ERROR\"] = 11] = \"ERROR\";\n Protocol[Protocol[\"LEAVE_ROOM\"] = 12] = \"LEAVE_ROOM\";\n Protocol[Protocol[\"ROOM_DATA\"] = 13] = \"ROOM_DATA\";\n Protocol[Protocol[\"ROOM_STATE\"] = 14] = \"ROOM_STATE\";\n Protocol[Protocol[\"ROOM_STATE_PATCH\"] = 15] = \"ROOM_STATE_PATCH\";\n Protocol[Protocol[\"ROOM_DATA_SCHEMA\"] = 16] = \"ROOM_DATA_SCHEMA\";\n Protocol[Protocol[\"ROOM_DATA_BYTES\"] = 17] = \"ROOM_DATA_BYTES\";\n})(Protocol = exports.Protocol || (exports.Protocol = {}));\nvar ErrorCode;\n(function (ErrorCode) {\n ErrorCode[ErrorCode[\"MATCHMAKE_NO_HANDLER\"] = 4210] = \"MATCHMAKE_NO_HANDLER\";\n ErrorCode[ErrorCode[\"MATCHMAKE_INVALID_CRITERIA\"] = 4211] = \"MATCHMAKE_INVALID_CRITERIA\";\n ErrorCode[ErrorCode[\"MATCHMAKE_INVALID_ROOM_ID\"] = 4212] = \"MATCHMAKE_INVALID_ROOM_ID\";\n ErrorCode[ErrorCode[\"MATCHMAKE_UNHANDLED\"] = 4213] = \"MATCHMAKE_UNHANDLED\";\n ErrorCode[ErrorCode[\"MATCHMAKE_EXPIRED\"] = 4214] = \"MATCHMAKE_EXPIRED\";\n ErrorCode[ErrorCode[\"AUTH_FAILED\"] = 4215] = \"AUTH_FAILED\";\n ErrorCode[ErrorCode[\"APPLICATION_ERROR\"] = 4216] = \"APPLICATION_ERROR\";\n})(ErrorCode = exports.ErrorCode || (exports.ErrorCode = {}));\nfunction utf8Read(view, offset) {\n const length = view[offset++];\n var string = '', chr = 0;\n for (var i = offset, end = offset + length; i < end; i++) {\n var byte = view[i];\n if ((byte & 0x80) === 0x00) {\n string += String.fromCharCode(byte);\n continue;\n }\n if ((byte & 0xe0) === 0xc0) {\n string += String.fromCharCode(((byte & 0x1f) << 6) |\n (view[++i] & 0x3f));\n continue;\n }\n if ((byte & 0xf0) === 0xe0) {\n string += String.fromCharCode(((byte & 0x0f) << 12) |\n ((view[++i] & 0x3f) << 6) |\n ((view[++i] & 0x3f) << 0));\n continue;\n }\n if ((byte & 0xf8) === 0xf0) {\n chr = ((byte & 0x07) << 18) |\n ((view[++i] & 0x3f) << 12) |\n ((view[++i] & 0x3f) << 6) |\n ((view[++i] & 0x3f) << 0);\n if (chr >= 0x010000) { // surrogate pair\n chr -= 0x010000;\n string += String.fromCharCode((chr >>> 10) + 0xD800, (chr & 0x3FF) + 0xDC00);\n }\n else {\n string += String.fromCharCode(chr);\n }\n continue;\n }\n throw new Error('Invalid byte ' + byte.toString(16));\n }\n return string;\n}\nexports.utf8Read = utf8Read;\n// Faster for short strings than Buffer.byteLength\nfunction utf8Length(str = '') {\n let c = 0;\n let length = 0;\n for (let i = 0, l = str.length; i < l; i++) {\n c = str.charCodeAt(i);\n if (c < 0x80) {\n length += 1;\n }\n else if (c < 0x800) {\n length += 2;\n }\n else if (c < 0xd800 || c >= 0xe000) {\n length += 3;\n }\n else {\n i++;\n length += 4;\n }\n }\n return length + 1;\n}\nexports.utf8Length = utf8Length;\n//# sourceMappingURL=Protocol.js.map","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.getSerializer = exports.registerSerializer = void 0;\nconst serializers = {};\nfunction registerSerializer(id, serializer) {\n serializers[id] = serializer;\n}\nexports.registerSerializer = registerSerializer;\nfunction getSerializer(id) {\n const serializer = serializers[id];\n if (!serializer) {\n throw new Error(\"missing serializer: \" + id);\n }\n return serializer;\n}\nexports.getSerializer = getSerializer;\n//# sourceMappingURL=Serializer.js.map","\"use strict\";\n/**\n * The MIT License (MIT)\n *\n * Copyright 2016 Andrey Sitnik <andrey@sitnik.ru>\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of\n * this software and associated documentation files (the \"Software\"), to deal in\n * the Software without restriction, including without limitation the rights to\n * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n * the Software, and to permit persons to whom the Software is furnished to do so,\n * subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n */\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.createNanoEvents = void 0;\nconst createNanoEvents = () => ({\n emit(event, ...args) {\n let callbacks = this.events[event] || [];\n for (let i = 0, length = callbacks.length; i < length; i++) {\n callbacks[i](...args);\n }\n },\n events: {},\n on(event, cb) {\n var _a;\n ((_a = this.events[event]) === null || _a === void 0 ? void 0 : _a.push(cb)) || (this.events[event] = [cb]);\n return () => {\n var _a;\n this.events[event] = (_a = this.events[event]) === null || _a === void 0 ? void 0 : _a.filter(i => cb !== i);\n };\n }\n});\nexports.createNanoEvents = createNanoEvents;\n//# sourceMappingURL=nanoevents.js.map","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.createSignal = exports.EventEmitter = void 0;\nclass EventEmitter {\n constructor() {\n this.handlers = [];\n }\n register(cb, once = false) {\n this.handlers.push(cb);\n return this;\n }\n invoke(...args) {\n this.handlers.forEach((handler) => handler.apply(this, args));\n }\n invokeAsync(...args) {\n return Promise.all(this.handlers.map((handler) => handler.apply(this, args)));\n }\n remove(cb) {\n const index = this.handlers.indexOf(cb);\n this.handlers[index] = this.handlers[this.handlers.length - 1];\n this.handlers.pop();\n }\n clear() {\n this.handlers = [];\n }\n}\nexports.EventEmitter = EventEmitter;\nfunction createSignal() {\n const emitter = new EventEmitter();\n function register(cb) {\n return emitter.register(cb, this === null);\n }\n ;\n register.once = (cb) => {\n const callback = function (...args) {\n cb.apply(this, args);\n emitter.remove(callback);\n };\n emitter.register(callback);\n };\n register.remove = (cb) => emitter.remove(cb);\n register.invoke = (...args) => emitter.invoke(...args);\n register.invokeAsync = (...args) => emitter.invokeAsync(...args);\n register.clear = () => emitter.clear();\n return register;\n}\nexports.createSignal = createSignal;\n//# sourceMappingURL=signal.js.map","(function (global, factory) {\n typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :\n typeof define === 'function' && define.amd ? define(['exports'], factory) :\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.schema = {}));\n})(this, (function (exports) { 'use strict';\n\n /******************************************************************************\r\n Copyright (c) Microsoft Corporation.\r\n\r\n Permission to use, copy, modify, and/or distribute this software for any\r\n purpose with or without fee is hereby granted.\r\n\r\n THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\n REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\n AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\n INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\n LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\n OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\n PERFORMANCE OF THIS SOFTWARE.\r\n ***************************************************************************** */\r\n /* global Reflect, Promise, SuppressedError, Symbol, Iterator */\r\n\r\n var extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n };\r\n\r\n function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n }\r\n\r\n function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n }\r\n\r\n function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n }\r\n\r\n typeof SuppressedError === \"function\" ? SuppressedError : function (error, suppressed, message) {\r\n var e = new Error(message);\r\n return e.name = \"SuppressedError\", e.error = error, e.suppressed = suppressed, e;\r\n };\n\n // export const SWITCH_TO_STRUCTURE = 193; (easily collides with DELETE_AND_ADD + fieldIndex = 2)\n var SWITCH_TO_STRUCTURE = 255; // (decoding collides with DELETE_AND_ADD + fieldIndex = 63)\n var TYPE_ID = 213;\n /**\n * Encoding Schema field operations.\n */\n exports.OPERATION = void 0;\n (function (OPERATION) {\n // add new structure/primitive\n OPERATION[OPERATION[\"ADD\"] = 128] = \"ADD\";\n // replace structure/primitive\n OPERATION[OPERATION[\"REPLACE\"] = 0] = \"REPLACE\";\n // delete field\n OPERATION[OPERATION[\"DELETE\"] = 64] = \"DELETE\";\n // DELETE field, followed by an ADD\n OPERATION[OPERATION[\"DELETE_AND_ADD\"] = 192] = \"DELETE_AND_ADD\";\n // TOUCH is used to determine hierarchy of nested Schema structures during serialization.\n // touches are NOT encoded.\n OPERATION[OPERATION[\"TOUCH\"] = 1] = \"TOUCH\";\n // MapSchema Operations\n OPERATION[OPERATION[\"CLEAR\"] = 10] = \"CLEAR\";\n })(exports.OPERATION || (exports.OPERATION = {}));\n // export enum OPERATION {\n // // add new structure/primitive\n // // (128)\n // ADD = 128, // 10000000,\n // // replace structure/primitive\n // REPLACE = 1,// 00000001\n // // delete field\n // DELETE = 192, // 11000000\n // // DELETE field, followed by an ADD\n // DELETE_AND_ADD = 224, // 11100000\n // // TOUCH is used to determine hierarchy of nested Schema structures during serialization.\n // // touches are NOT encoded.\n // TOUCH = 0, // 00000000\n // // MapSchema Operations\n // CLEAR = 10,\n // }\n\n var ChangeTree = /** @class */ (function () {\n function ChangeTree(ref, parent, root) {\n this.changed = false;\n this.changes = new Map();\n this.allChanges = new Set();\n // cached indexes for filtering\n this.caches = {};\n this.currentCustomOperation = 0;\n this.ref = ref;\n this.setParent(parent, root);\n }\n ChangeTree.prototype.setParent = function (parent, root, parentIndex) {\n var _this = this;\n if (!this.indexes) {\n this.indexes = (this.ref instanceof Schema)\n ? this.ref['_definition'].indexes\n : {};\n }\n this.parent = parent;\n this.parentIndex = parentIndex;\n // avoid setting parents with empty `root`\n if (!root) {\n return;\n }\n this.root = root;\n //\n // assign same parent on child structures\n //\n if (this.ref instanceof Schema) {\n var definition = this.ref['_definition'];\n for (var field in definition.schema) {\n var value = this.ref[field];\n if (value && value['$changes']) {\n var parentIndex_1 = definition.indexes[field];\n value['$changes'].setParent(this.ref, root, parentIndex_1);\n }\n }\n }\n else if (typeof (this.ref) === \"object\") {\n this.ref.forEach(function (value, key) {\n if (value instanceof Schema) {\n var changeTreee = value['$changes'];\n var parentIndex_2 = _this.ref['$changes'].indexes[key];\n changeTreee.setParent(_this.ref, _this.root, parentIndex_2);\n }\n });\n }\n };\n ChangeTree.prototype.operation = function (op) {\n this.changes.set(--this.currentCustomOperation, op);\n };\n ChangeTree.prototype.change = function (fieldName, operation) {\n if (operation === void 0) { operation = exports.OPERATION.ADD; }\n var index = (typeof (fieldName) === \"number\")\n ? fieldName\n : this.indexes[fieldName];\n this.assertValidIndex(index, fieldName);\n var previousChange = this.changes.get(index);\n if (!previousChange ||\n previousChange.op === exports.OPERATION.DELETE ||\n previousChange.op === exports.OPERATION.TOUCH // (mazmorra.io's BattleAction issue)\n ) {\n this.changes.set(index, {\n op: (!previousChange)\n ? operation\n : (previousChange.op === exports.OPERATION.DELETE)\n ? exports.OPERATION.DELETE_AND_ADD\n : operation,\n // : OPERATION.REPLACE,\n index: index\n });\n }\n this.allChanges.add(index);\n this.changed = true;\n this.touchParents();\n };\n ChangeTree.prototype.touch = function (fieldName) {\n var index = (typeof (fieldName) === \"number\")\n ? fieldName\n : this.indexes[fieldName];\n this.assertValidIndex(index, fieldName);\n if (!this.changes.has(index)) {\n this.changes.set(index, { op: exports.OPERATION.TOUCH, index: index });\n }\n this.allChanges.add(index);\n // ensure touch is placed until the $root is found.\n this.touchParents();\n };\n ChangeTree.prototype.touchParents = function () {\n if (this.parent) {\n this.parent['$changes'].touch(this.parentIndex);\n }\n };\n ChangeTree.prototype.getType = function (index) {\n if (this.ref['_definition']) {\n var definition = this.ref['_definition'];\n return definition.schema[definition.fieldsByIndex[index]];\n }\n else {\n var definition = this.parent['_definition'];\n var parentType = definition.schema[definition.fieldsByIndex[this.parentIndex]];\n //\n // Get the child type from parent structure.\n // - [\"string\"] => \"string\"\n // - { map: \"string\" } => \"string\"\n // - { set: \"string\" } => \"string\"\n //\n return Object.values(parentType)[0];\n }\n };\n ChangeTree.prototype.getChildrenFilter = function () {\n var childFilters = this.parent['_definition'].childFilters;\n return childFilters && childFilters[this.parentIndex];\n };\n //\n // used during `.encode()`\n //\n ChangeTree.prototype.getValue = function (index) {\n return this.ref['getByIndex'](index);\n };\n ChangeTree.prototype.delete = function (fieldName) {\n var index = (typeof (fieldName) === \"number\")\n ? fieldName\n : this.indexes[fieldName];\n if (index === undefined) {\n console.warn(\"@colyseus/schema \".concat(this.ref.constructor.name, \": trying to delete non-existing index: \").concat(fieldName, \" (\").concat(index, \")\"));\n return;\n }\n var previousValue = this.getValue(index);\n // console.log(\"$changes.delete =>\", { fieldName, index, previousValue });\n this.changes.set(index, { op: exports.OPERATION.DELETE, index: index });\n this.allChanges.delete(index);\n // delete cache\n delete this.caches[index];\n // remove `root` reference\n if (previousValue && previousValue['$changes']) {\n previousValue['$changes'].parent = undefined;\n }\n this.changed = true;\n this.touchParents();\n };\n ChangeTree.prototype.discard = function (changed, discardAll) {\n var _this = this;\n if (changed === void 0) { changed = false; }\n if (discardAll === void 0) { discardAll = false; }\n //\n // Map, Array, etc:\n // Remove cached key to ensure ADD operations is unsed instead of\n // REPLACE in case same key is used on next patches.\n //\n // TODO: refactor this. this is not relevant for Collection and Set.\n //\n if (!(this.ref instanceof Schema)) {\n this.changes.forEach(function (change) {\n if (change.op === exports.OPERATION.DELETE) {\n var index = _this.ref['getIndex'](change.index);\n delete _this.indexes[index];\n }\n });\n }\n this.changes.clear();\n this.changed = changed;\n if (discardAll) {\n this.allChanges.clear();\n }\n // re-set `currentCustomOperation`\n this.currentCustomOperation = 0;\n };\n /**\n * Recursively discard all changes from this, and child structures.\n */\n ChangeTree.prototype.discardAll = function () {\n var _this = this;\n this.changes.forEach(function (change) {\n var value = _this.getValue(change.index);\n if (value && value['$changes']) {\n value['$changes'].discardAll();\n }\n });\n this.discard();\n };\n // cache(field: number, beginIndex: number, endIndex: number) {\n ChangeTree.prototype.cache = function (field, cachedBytes) {\n this.caches[field] = cachedBytes;\n };\n ChangeTree.prototype.clone = function () {\n return new ChangeTree(this.ref, this.parent, this.root);\n };\n ChangeTree.prototype.ensureRefId = function () {\n // skip if refId is already set.\n if (this.refId !== undefined) {\n return;\n }\n this.refId = this.root.getNextUniqueId();\n };\n ChangeTree.prototype.assertValidIndex = function (index, fieldName) {\n if (index === undefined) {\n throw new Error(\"ChangeTree: missing index for field \\\"\".concat(fieldName, \"\\\"\"));\n }\n };\n return ChangeTree;\n }());\n\n function addCallback($callbacks, op, callback, existing) {\n // initialize list of callbacks\n if (!$callbacks[op]) {\n $callbacks[op] = [];\n }\n $callbacks[op].push(callback);\n //\n // Trigger callback for existing elements\n // - OPERATION.ADD\n // - OPERATION.REPLACE\n //\n existing === null || existing === void 0 ? void 0 : existing.forEach(function (item, key) { return callback(item, key); });\n return function () { return spliceOne($callbacks[op], $callbacks[op].indexOf(callback)); };\n }\n function removeChildRefs(changes) {\n var