@colyseus/core 0.16.0-preview.36 → 0.16.0-preview.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/Protocol.js +5 -0
- package/build/Protocol.js.map +2 -2
- package/build/Protocol.mjs +5 -0
- package/build/Protocol.mjs.map +2 -2
- package/build/Room.d.ts +3 -2
- package/build/Room.js +65 -25
- package/build/Room.js.map +2 -2
- package/build/Room.mjs +65 -25
- package/build/Room.mjs.map +2 -2
- package/package.json +3 -3
package/build/Protocol.js
CHANGED
|
@@ -70,6 +70,11 @@ const getMessageBytes = {
|
|
|
70
70
|
packr.buffer[it.offset++] = Buffer.byteLength(serializerId, "utf8");
|
|
71
71
|
import_schema.encode.utf8Write(packr.buffer, serializerId, it);
|
|
72
72
|
let handshakeLength = handshake?.byteLength || 0;
|
|
73
|
+
if (handshakeLength > packr.buffer.byteLength - it.offset) {
|
|
74
|
+
const newBuffer = Buffer.allocUnsafe(it.offset + handshakeLength);
|
|
75
|
+
packr.buffer.copy(newBuffer);
|
|
76
|
+
packr.useBuffer(newBuffer);
|
|
77
|
+
}
|
|
73
78
|
if (handshakeLength > 0) {
|
|
74
79
|
handshake.copy(packr.buffer, it.offset, 0, handshakeLength);
|
|
75
80
|
}
|
package/build/Protocol.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/Protocol.ts"],
|
|
4
|
-
"sourcesContent": ["import { pack, Packr } from '@colyseus/msgpackr';\nimport { encode, Iterator } from '@colyseus/schema';\n\n// Colyseus protocol codes range between 0~100\nexport enum Protocol {\n // Room-related (10~19)\n JOIN_ROOM = 10,\n ERROR = 11,\n LEAVE_ROOM = 12,\n ROOM_DATA = 13,\n ROOM_STATE = 14,\n ROOM_STATE_PATCH = 15,\n // ROOM_DATA_SCHEMA = 16, // DEPRECATED: used to send schema instances via room.send()\n ROOM_DATA_BYTES = 17,\n\n // WebSocket close codes (https://github.com/Luka967/websocket-close-codes)\n WS_CLOSE_NORMAL = 1000,\n WS_CLOSE_GOING_AWAY = 1001,\n\n // WebSocket error codes\n WS_CLOSE_CONSENTED = 4000,\n WS_CLOSE_WITH_ERROR = 4002,\n WS_CLOSE_DEVMODE_RESTART = 4010,\n\n WS_SERVER_DISCONNECT = 4201,\n WS_TOO_MANY_CLIENTS = 4202,\n}\n\nexport enum ErrorCode {\n // MatchMaking Error Codes\n MATCHMAKE_NO_HANDLER = 4210,\n MATCHMAKE_INVALID_CRITERIA = 4211,\n MATCHMAKE_INVALID_ROOM_ID = 4212,\n MATCHMAKE_UNHANDLED = 4213, // generic exception during onCreate/onJoin\n MATCHMAKE_EXPIRED = 4214, // generic exception during onCreate/onJoin\n\n AUTH_FAILED = 4215,\n APPLICATION_ERROR = 4216,\n\n INVALID_PAYLOAD = 4217,\n}\n\n// Inter-process communication protocol\nexport enum IpcProtocol {\n SUCCESS = 0,\n ERROR = 1,\n TIMEOUT = 2,\n}\n\n\nconst packr = new Packr();\n\n// msgpackr workaround: initialize buffer\npackr.encode(undefined);\n\nexport const getMessageBytes = {\n [Protocol.JOIN_ROOM]: (reconnectionToken: string, serializerId: string, handshake?: Buffer) => {\n const it: Iterator = { offset: 1 };\n packr.buffer[0] = Protocol.JOIN_ROOM;\n\n packr.buffer[it.offset++] = Buffer.byteLength(reconnectionToken, \"utf8\");\n encode.utf8Write(packr.buffer, reconnectionToken, it);\n\n packr.buffer[it.offset++] = Buffer.byteLength(serializerId, \"utf8\");\n encode.utf8Write(packr.buffer, serializerId, it);\n\n let handshakeLength = handshake?.byteLength || 0;\n if (handshakeLength > 0) {\n handshake.copy(packr.buffer, it.offset, 0, handshakeLength);\n }\n\n return packr.buffer.subarray(0, it.offset + handshakeLength);\n },\n\n [Protocol.ERROR]: (code: number, message: string = '') => {\n const it: Iterator = { offset: 1 };\n packr.buffer[0] = Protocol.ERROR;\n\n encode.number(packr.buffer, code, it);\n encode.string(packr.buffer, message, it);\n\n return packr.buffer.subarray(0, it.offset);\n },\n\n [Protocol.ROOM_STATE]: (bytes: number[]) => {\n return [Protocol.ROOM_STATE, ...bytes];\n },\n\n raw: (code: Protocol, type: string | number, message?: any, rawMessage?: Uint8Array | Buffer) => {\n const it: Iterator = { offset: 1 };\n packr.buffer[0] = code;\n\n if (typeof (type) === 'string') {\n encode.string(packr.buffer, type as string, it);\n\n } else {\n encode.number(packr.buffer, type, it);\n }\n\n if (message !== undefined) {\n // force to encode from offset\n packr.position = 0;\n\n //\n // TODO: remove this after issue is fixed https://github.com/kriszyp/msgpackr/issues/139\n //\n // - This check is only required when running integration tests.\n // (colyseus.js' usage of msgpackr/buffer is conflicting)\n //\n if (process.env.NODE_ENV !== \"production\") {\n packr.useBuffer(packr.buffer);\n }\n\n // pack message into the same packr.buffer\n const endOfBufferOffset = packr.pack(message, 2048 + it.offset).byteLength;\n // 2048 = RESERVE_START_SPACE\n return packr.buffer.subarray(0, endOfBufferOffset);\n\n } else if (rawMessage !== undefined) {\n\n // copy raw message into packr.buffer\n packr.buffer.set(rawMessage, it.offset);\n return packr.buffer.subarray(0, it.offset + rawMessage.byteLength);\n\n } else {\n return packr.buffer.subarray(0, it.offset);\n }\n },\n\n};\n\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA4B;AAC5B,oBAAiC;AAG1B,IAAK,WAAL,kBAAKA,cAAL;AAEL,EAAAA,oBAAA,eAAY,MAAZ;AACA,EAAAA,oBAAA,WAAQ,MAAR;AACA,EAAAA,oBAAA,gBAAa,MAAb;AACA,EAAAA,oBAAA,eAAY,MAAZ;AACA,EAAAA,oBAAA,gBAAa,MAAb;AACA,EAAAA,oBAAA,sBAAmB,MAAnB;AAEA,EAAAA,oBAAA,qBAAkB,MAAlB;AAGA,EAAAA,oBAAA,qBAAkB,OAAlB;AACA,EAAAA,oBAAA,yBAAsB,QAAtB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/schema';\n\n// Colyseus protocol codes range between 0~100\nexport enum Protocol {\n // Room-related (10~19)\n JOIN_ROOM = 10,\n ERROR = 11,\n LEAVE_ROOM = 12,\n ROOM_DATA = 13,\n ROOM_STATE = 14,\n ROOM_STATE_PATCH = 15,\n // ROOM_DATA_SCHEMA = 16, // DEPRECATED: used to send schema instances via room.send()\n ROOM_DATA_BYTES = 17,\n\n // WebSocket close codes (https://github.com/Luka967/websocket-close-codes)\n WS_CLOSE_NORMAL = 1000,\n WS_CLOSE_GOING_AWAY = 1001,\n\n // WebSocket error codes\n WS_CLOSE_CONSENTED = 4000,\n WS_CLOSE_WITH_ERROR = 4002,\n WS_CLOSE_DEVMODE_RESTART = 4010,\n\n WS_SERVER_DISCONNECT = 4201,\n WS_TOO_MANY_CLIENTS = 4202,\n}\n\nexport enum ErrorCode {\n // MatchMaking Error Codes\n MATCHMAKE_NO_HANDLER = 4210,\n MATCHMAKE_INVALID_CRITERIA = 4211,\n MATCHMAKE_INVALID_ROOM_ID = 4212,\n MATCHMAKE_UNHANDLED = 4213, // generic exception during onCreate/onJoin\n MATCHMAKE_EXPIRED = 4214, // generic exception during onCreate/onJoin\n\n AUTH_FAILED = 4215,\n APPLICATION_ERROR = 4216,\n\n INVALID_PAYLOAD = 4217,\n}\n\n// Inter-process communication protocol\nexport enum IpcProtocol {\n SUCCESS = 0,\n ERROR = 1,\n TIMEOUT = 2,\n}\n\n\nconst packr = new Packr();\n\n// msgpackr workaround: initialize buffer\npackr.encode(undefined);\n\nexport const getMessageBytes = {\n [Protocol.JOIN_ROOM]: (reconnectionToken: string, serializerId: string, handshake?: Buffer) => {\n const it: Iterator = { offset: 1 };\n packr.buffer[0] = Protocol.JOIN_ROOM;\n\n packr.buffer[it.offset++] = Buffer.byteLength(reconnectionToken, \"utf8\");\n encode.utf8Write(packr.buffer, reconnectionToken, it);\n\n packr.buffer[it.offset++] = Buffer.byteLength(serializerId, \"utf8\");\n encode.utf8Write(packr.buffer, serializerId, it);\n\n let handshakeLength = handshake?.byteLength || 0;\n\n // check if buffer needs to be resized\n // (TODO: refactor me!)\n if (handshakeLength > packr.buffer.byteLength - it.offset) {\n const newBuffer = Buffer.allocUnsafe(it.offset + handshakeLength);\n (packr.buffer as Buffer).copy(newBuffer);\n packr.useBuffer(newBuffer);\n }\n\n if (handshakeLength > 0) {\n handshake.copy(packr.buffer, it.offset, 0, handshakeLength);\n }\n\n return packr.buffer.subarray(0, it.offset + handshakeLength);\n },\n\n [Protocol.ERROR]: (code: number, message: string = '') => {\n const it: Iterator = { offset: 1 };\n packr.buffer[0] = Protocol.ERROR;\n\n encode.number(packr.buffer, code, it);\n encode.string(packr.buffer, message, it);\n\n return packr.buffer.subarray(0, it.offset);\n },\n\n [Protocol.ROOM_STATE]: (bytes: number[]) => {\n return [Protocol.ROOM_STATE, ...bytes];\n },\n\n raw: (code: Protocol, type: string | number, message?: any, rawMessage?: Uint8Array | Buffer) => {\n const it: Iterator = { offset: 1 };\n packr.buffer[0] = code;\n\n if (typeof (type) === 'string') {\n encode.string(packr.buffer, type as string, it);\n\n } else {\n encode.number(packr.buffer, type, it);\n }\n\n if (message !== undefined) {\n // force to encode from offset\n packr.position = 0;\n\n //\n // TODO: remove this after issue is fixed https://github.com/kriszyp/msgpackr/issues/139\n //\n // - This check is only required when running integration tests.\n // (colyseus.js' usage of msgpackr/buffer is conflicting)\n //\n if (process.env.NODE_ENV !== \"production\") {\n packr.useBuffer(packr.buffer);\n }\n\n // pack message into the same packr.buffer\n const endOfBufferOffset = packr.pack(message, 2048 + it.offset).byteLength;\n // 2048 = RESERVE_START_SPACE\n return packr.buffer.subarray(0, endOfBufferOffset);\n\n } else if (rawMessage !== undefined) {\n\n // copy raw message into packr.buffer\n packr.buffer.set(rawMessage, it.offset);\n return packr.buffer.subarray(0, it.offset + rawMessage.byteLength);\n\n } else {\n return packr.buffer.subarray(0, it.offset);\n }\n },\n\n};\n\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;A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AgB,EAAE;AAAA,IAEhD,OAAO;AACL,2BAAO,OAAO,MAAM,QAAQ,MAAM,EAAE;AAAA,IACtC;AAEA,QAAI,YAAY,QAAW;AAEzB,YAAM,WAAW;AAQjB,UAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,cAAM,UAAU,MAAM,MAAM;AAAA,MAC9B;AAGA,YAAM,oBAAoB,MAAM,KAAK,SAAS,OAAO,GAAG,MAAM,EAAE;AAEhE,aAAO,MAAM,OAAO,SAAS,GAAG,iBAAiB;AAAA,IAEnD,WAAW,eAAe,QAAW;AAGnC,YAAM,OAAO,IAAI,YAAY,GAAG,MAAM;AACtC,aAAO,MAAM,OAAO,SAAS,GAAG,GAAG,SAAS,WAAW,UAAU;AAAA,IAEnE,OAAO;AACL,aAAO,MAAM,OAAO,SAAS,GAAG,GAAG,MAAM;AAAA,IAC3C;AAAA,EACF;AAEF;",
|
|
6
6
|
"names": ["Protocol", "ErrorCode", "IpcProtocol"]
|
|
7
7
|
}
|
package/build/Protocol.mjs
CHANGED
|
@@ -46,6 +46,11 @@ var getMessageBytes = {
|
|
|
46
46
|
packr.buffer[it.offset++] = Buffer.byteLength(serializerId, "utf8");
|
|
47
47
|
encode.utf8Write(packr.buffer, serializerId, it);
|
|
48
48
|
let handshakeLength = handshake?.byteLength || 0;
|
|
49
|
+
if (handshakeLength > packr.buffer.byteLength - it.offset) {
|
|
50
|
+
const newBuffer = Buffer.allocUnsafe(it.offset + handshakeLength);
|
|
51
|
+
packr.buffer.copy(newBuffer);
|
|
52
|
+
packr.useBuffer(newBuffer);
|
|
53
|
+
}
|
|
49
54
|
if (handshakeLength > 0) {
|
|
50
55
|
handshake.copy(packr.buffer, it.offset, 0, handshakeLength);
|
|
51
56
|
}
|
package/build/Protocol.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/Protocol.ts"],
|
|
4
|
-
"sourcesContent": ["import { pack, Packr } from '@colyseus/msgpackr';\nimport { encode, Iterator } from '@colyseus/schema';\n\n// Colyseus protocol codes range between 0~100\nexport enum Protocol {\n // Room-related (10~19)\n JOIN_ROOM = 10,\n ERROR = 11,\n LEAVE_ROOM = 12,\n ROOM_DATA = 13,\n ROOM_STATE = 14,\n ROOM_STATE_PATCH = 15,\n // ROOM_DATA_SCHEMA = 16, // DEPRECATED: used to send schema instances via room.send()\n ROOM_DATA_BYTES = 17,\n\n // WebSocket close codes (https://github.com/Luka967/websocket-close-codes)\n WS_CLOSE_NORMAL = 1000,\n WS_CLOSE_GOING_AWAY = 1001,\n\n // WebSocket error codes\n WS_CLOSE_CONSENTED = 4000,\n WS_CLOSE_WITH_ERROR = 4002,\n WS_CLOSE_DEVMODE_RESTART = 4010,\n\n WS_SERVER_DISCONNECT = 4201,\n WS_TOO_MANY_CLIENTS = 4202,\n}\n\nexport enum ErrorCode {\n // MatchMaking Error Codes\n MATCHMAKE_NO_HANDLER = 4210,\n MATCHMAKE_INVALID_CRITERIA = 4211,\n MATCHMAKE_INVALID_ROOM_ID = 4212,\n MATCHMAKE_UNHANDLED = 4213, // generic exception during onCreate/onJoin\n MATCHMAKE_EXPIRED = 4214, // generic exception during onCreate/onJoin\n\n AUTH_FAILED = 4215,\n APPLICATION_ERROR = 4216,\n\n INVALID_PAYLOAD = 4217,\n}\n\n// Inter-process communication protocol\nexport enum IpcProtocol {\n SUCCESS = 0,\n ERROR = 1,\n TIMEOUT = 2,\n}\n\n\nconst packr = new Packr();\n\n// msgpackr workaround: initialize buffer\npackr.encode(undefined);\n\nexport const getMessageBytes = {\n [Protocol.JOIN_ROOM]: (reconnectionToken: string, serializerId: string, handshake?: Buffer) => {\n const it: Iterator = { offset: 1 };\n packr.buffer[0] = Protocol.JOIN_ROOM;\n\n packr.buffer[it.offset++] = Buffer.byteLength(reconnectionToken, \"utf8\");\n encode.utf8Write(packr.buffer, reconnectionToken, it);\n\n packr.buffer[it.offset++] = Buffer.byteLength(serializerId, \"utf8\");\n encode.utf8Write(packr.buffer, serializerId, it);\n\n let handshakeLength = handshake?.byteLength || 0;\n if (handshakeLength > 0) {\n handshake.copy(packr.buffer, it.offset, 0, handshakeLength);\n }\n\n return packr.buffer.subarray(0, it.offset + handshakeLength);\n },\n\n [Protocol.ERROR]: (code: number, message: string = '') => {\n const it: Iterator = { offset: 1 };\n packr.buffer[0] = Protocol.ERROR;\n\n encode.number(packr.buffer, code, it);\n encode.string(packr.buffer, message, it);\n\n return packr.buffer.subarray(0, it.offset);\n },\n\n [Protocol.ROOM_STATE]: (bytes: number[]) => {\n return [Protocol.ROOM_STATE, ...bytes];\n },\n\n raw: (code: Protocol, type: string | number, message?: any, rawMessage?: Uint8Array | Buffer) => {\n const it: Iterator = { offset: 1 };\n packr.buffer[0] = code;\n\n if (typeof (type) === 'string') {\n encode.string(packr.buffer, type as string, it);\n\n } else {\n encode.number(packr.buffer, type, it);\n }\n\n if (message !== undefined) {\n // force to encode from offset\n packr.position = 0;\n\n //\n // TODO: remove this after issue is fixed https://github.com/kriszyp/msgpackr/issues/139\n //\n // - This check is only required when running integration tests.\n // (colyseus.js' usage of msgpackr/buffer is conflicting)\n //\n if (process.env.NODE_ENV !== \"production\") {\n packr.useBuffer(packr.buffer);\n }\n\n // pack message into the same packr.buffer\n const endOfBufferOffset = packr.pack(message, 2048 + it.offset).byteLength;\n // 2048 = RESERVE_START_SPACE\n return packr.buffer.subarray(0, endOfBufferOffset);\n\n } else if (rawMessage !== undefined) {\n\n // copy raw message into packr.buffer\n packr.buffer.set(rawMessage, it.offset);\n return packr.buffer.subarray(0, it.offset + rawMessage.byteLength);\n\n } else {\n return packr.buffer.subarray(0, it.offset);\n }\n },\n\n};\n\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAe,aAAa;AAC5B,SAAS,cAAwB;AAG1B,IAAK,WAAL,kBAAKA,cAAL;AAEL,EAAAA,oBAAA,eAAY,MAAZ;AACA,EAAAA,oBAAA,WAAQ,MAAR;AACA,EAAAA,o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AAE;AAEpD,UAAM,OAAO,GAAG,QAAQ,IAAI,OAAO,WAAW,cAAc,MAAM;AAClE,WAAO,UAAU,MAAM,QAAQ,cAAc,EAAE;AAE/C,QAAI,kBAAkB,WAAW,cAAc;
|
|
4
|
+
"sourcesContent": ["import { pack, Packr } from '@colyseus/msgpackr';\nimport { encode, Iterator } from '@colyseus/schema';\n\n// Colyseus protocol codes range between 0~100\nexport enum Protocol {\n // Room-related (10~19)\n JOIN_ROOM = 10,\n ERROR = 11,\n LEAVE_ROOM = 12,\n ROOM_DATA = 13,\n ROOM_STATE = 14,\n ROOM_STATE_PATCH = 15,\n // ROOM_DATA_SCHEMA = 16, // DEPRECATED: used to send schema instances via room.send()\n ROOM_DATA_BYTES = 17,\n\n // WebSocket close codes (https://github.com/Luka967/websocket-close-codes)\n WS_CLOSE_NORMAL = 1000,\n WS_CLOSE_GOING_AWAY = 1001,\n\n // WebSocket error codes\n WS_CLOSE_CONSENTED = 4000,\n WS_CLOSE_WITH_ERROR = 4002,\n WS_CLOSE_DEVMODE_RESTART = 4010,\n\n WS_SERVER_DISCONNECT = 4201,\n WS_TOO_MANY_CLIENTS = 4202,\n}\n\nexport enum ErrorCode {\n // MatchMaking Error Codes\n MATCHMAKE_NO_HANDLER = 4210,\n MATCHMAKE_INVALID_CRITERIA = 4211,\n MATCHMAKE_INVALID_ROOM_ID = 4212,\n MATCHMAKE_UNHANDLED = 4213, // generic exception during onCreate/onJoin\n MATCHMAKE_EXPIRED = 4214, // generic exception during onCreate/onJoin\n\n AUTH_FAILED = 4215,\n APPLICATION_ERROR = 4216,\n\n INVALID_PAYLOAD = 4217,\n}\n\n// Inter-process communication protocol\nexport enum IpcProtocol {\n SUCCESS = 0,\n ERROR = 1,\n TIMEOUT = 2,\n}\n\n\nconst packr = new Packr();\n\n// msgpackr workaround: initialize buffer\npackr.encode(undefined);\n\nexport const getMessageBytes = {\n [Protocol.JOIN_ROOM]: (reconnectionToken: string, serializerId: string, handshake?: Buffer) => {\n const it: Iterator = { offset: 1 };\n packr.buffer[0] = Protocol.JOIN_ROOM;\n\n packr.buffer[it.offset++] = Buffer.byteLength(reconnectionToken, \"utf8\");\n encode.utf8Write(packr.buffer, reconnectionToken, it);\n\n packr.buffer[it.offset++] = Buffer.byteLength(serializerId, \"utf8\");\n encode.utf8Write(packr.buffer, serializerId, it);\n\n let handshakeLength = handshake?.byteLength || 0;\n\n // check if buffer needs to be resized\n // (TODO: refactor me!)\n if (handshakeLength > packr.buffer.byteLength - it.offset) {\n const newBuffer = Buffer.allocUnsafe(it.offset + handshakeLength);\n (packr.buffer as Buffer).copy(newBuffer);\n packr.useBuffer(newBuffer);\n }\n\n if (handshakeLength > 0) {\n handshake.copy(packr.buffer, it.offset, 0, handshakeLength);\n }\n\n return packr.buffer.subarray(0, it.offset + handshakeLength);\n },\n\n [Protocol.ERROR]: (code: number, message: string = '') => {\n const it: Iterator = { offset: 1 };\n packr.buffer[0] = Protocol.ERROR;\n\n encode.number(packr.buffer, code, it);\n encode.string(packr.buffer, message, it);\n\n return packr.buffer.subarray(0, it.offset);\n },\n\n [Protocol.ROOM_STATE]: (bytes: number[]) => {\n return [Protocol.ROOM_STATE, ...bytes];\n },\n\n raw: (code: Protocol, type: string | number, message?: any, rawMessage?: Uint8Array | Buffer) => {\n const it: Iterator = { offset: 1 };\n packr.buffer[0] = code;\n\n if (typeof (type) === 'string') {\n encode.string(packr.buffer, type as string, it);\n\n } else {\n encode.number(packr.buffer, type, it);\n }\n\n if (message !== undefined) {\n // force to encode from offset\n packr.position = 0;\n\n //\n // TODO: remove this after issue is fixed https://github.com/kriszyp/msgpackr/issues/139\n //\n // - This check is only required when running integration tests.\n // (colyseus.js' usage of msgpackr/buffer is conflicting)\n //\n if (process.env.NODE_ENV !== \"production\") {\n packr.useBuffer(packr.buffer);\n }\n\n // pack message into the same packr.buffer\n const endOfBufferOffset = packr.pack(message, 2048 + it.offset).byteLength;\n // 2048 = RESERVE_START_SPACE\n return packr.buffer.subarray(0, endOfBufferOffset);\n\n } else if (rawMessage !== undefined) {\n\n // copy raw message into packr.buffer\n packr.buffer.set(rawMessage, it.offset);\n return packr.buffer.subarray(0, it.offset + rawMessage.byteLength);\n\n } else {\n return packr.buffer.subarray(0, it.offset);\n }\n },\n\n};\n\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAe,aAAa;AAC5B,SAAS,cAAwB;AAG1B,IAAK,WAAL,kBAAKA,cAAL;AAEL,EAAAA,oBAAA,eAAY,MAAZ;AACA,EAAAA,oBAAA,WAAQ,MAAR;AACA,EAAAA,oBAAA,gBAAa,MAAb;AACA,EAAAA,oBAAA,eAAY,MAAZ;AACA,EAAAA,oBAAA,gBAAa,MAAb;AACA,EAAAA,oBAAA,sBAAmB,MAAnB;AAEA,EAAAA,oBAAA,qBAAkB,MAAlB;AAGA,EAAAA,oBAAA,qBAAkB,OAAlB;AACA,EAAAA,oBAAA,yBAAsB,QAAtB;AAGA,EAAAA,oBAAA,wBAAqB,OAArB;AACA,EAAAA,oBAAA,yBAAsB,QAAtB;AACA,EAAAA,oBAAA,8BAA2B,QAA3B;AAEA,EAAAA,oBAAA,0BAAuB,QAAvB;AACA,EAAAA,oBAAA,yBAAsB,QAAtB;AArBU,SAAAA;AAAA,GAAA;AAwBL,IAAK,YAAL,kBAAKC,eAAL;AAEL,EAAAA,sBAAA,0BAAuB,QAAvB;AACA,EAAAA,sBAAA,gCAA6B,QAA7B;AACA,EAAAA,sBAAA,+BAA4B,QAA5B;AACA,EAAAA,sBAAA,yBAAsB,QAAtB;AACA,EAAAA,sBAAA,uBAAoB,QAApB;AAEA,EAAAA,sBAAA,iBAAc,QAAd;AACA,EAAAA,sBAAA,uBAAoB,QAApB;AAEA,EAAAA,sBAAA,qBAAkB,QAAlB;AAXU,SAAAA;AAAA,GAAA;AAeL,IAAK,cAAL,kBAAKC,iBAAL;AACL,EAAAA,0BAAA,aAAU,KAAV;AACA,EAAAA,0BAAA,WAAQ,KAAR;AACA,EAAAA,0BAAA,aAAU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MAAuB,SAAe,eAAqC;AAC/F,UAAM,KAAe,EAAE,QAAQ,EAAE;AACjC,UAAM,OAAO,CAAC,IAAI;AAElB,QAAI,OAAQ,SAAU,UAAU;AAC9B,aAAO,OAAO,MAAM,QAAQ,MAAgB,EAAE;AAAA,IAEhD,OAAO;AACL,aAAO,OAAO,MAAM,QAAQ,MAAM,EAAE;AAAA,IACtC;AAEA,QAAI,YAAY,QAAW;AAEzB,YAAM,WAAW;AAQjB,UAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,cAAM,UAAU,MAAM,MAAM;AAAA,MAC9B;AAGA,YAAM,oBAAoB,MAAM,KAAK,SAAS,OAAO,GAAG,MAAM,EAAE;AAEhE,aAAO,MAAM,OAAO,SAAS,GAAG,iBAAiB;AAAA,IAEnD,WAAW,eAAe,QAAW;AAGnC,YAAM,OAAO,IAAI,YAAY,GAAG,MAAM;AACtC,aAAO,MAAM,OAAO,SAAS,GAAG,GAAG,SAAS,WAAW,UAAU;AAAA,IAEnE,OAAO;AACL,aAAO,MAAM,OAAO,SAAS,GAAG,GAAG,MAAM;AAAA,IAC3C;AAAA,EACF;AAEF;",
|
|
6
6
|
"names": ["Protocol", "ErrorCode", "IpcProtocol"]
|
|
7
7
|
}
|
package/build/Room.d.ts
CHANGED
|
@@ -94,9 +94,7 @@ export declare abstract class Room<State extends object = any, Metadata = any, U
|
|
|
94
94
|
private _afterNextPatchQueue;
|
|
95
95
|
private _simulationInterval;
|
|
96
96
|
private _internalState;
|
|
97
|
-
private _locked;
|
|
98
97
|
private _lockedExplicitly;
|
|
99
|
-
private _maxClientsReached;
|
|
100
98
|
private _autoDisposeTimeout;
|
|
101
99
|
constructor();
|
|
102
100
|
/**
|
|
@@ -205,6 +203,9 @@ export declare abstract class Room<State extends object = any, Metadata = any, U
|
|
|
205
203
|
* @deprecated Use `.patchRate=` instead.
|
|
206
204
|
*/
|
|
207
205
|
setPatchRate(milliseconds: number | null): void;
|
|
206
|
+
/**
|
|
207
|
+
* @deprecated Use `.state =` instead.
|
|
208
|
+
*/
|
|
208
209
|
setState(newState: State): void;
|
|
209
210
|
setSerializer(serializer: Serializer<State>): void;
|
|
210
211
|
setMetadata(meta: Partial<Metadata>): Promise<void>;
|
package/build/Room.js
CHANGED
|
@@ -71,6 +71,7 @@ class Room {
|
|
|
71
71
|
* the room will be unlocked as soon as a client disconnects from it.
|
|
72
72
|
*/
|
|
73
73
|
this.maxClients = Infinity;
|
|
74
|
+
this.#_maxClientsReached = false;
|
|
74
75
|
/**
|
|
75
76
|
* Automatically dispose the room when last client disconnects.
|
|
76
77
|
*
|
|
@@ -113,9 +114,8 @@ class Room {
|
|
|
113
114
|
this._serializer = noneSerializer;
|
|
114
115
|
this._afterNextPatchQueue = [];
|
|
115
116
|
this._internalState = 0 /* CREATING */;
|
|
116
|
-
this._locked = false;
|
|
117
117
|
this._lockedExplicitly = false;
|
|
118
|
-
this
|
|
118
|
+
this.#_locked = false;
|
|
119
119
|
this._events.once("dispose", () => {
|
|
120
120
|
this._dispose().catch((e) => (0, import_Debug.debugAndPrintError)(`onDispose error: ${e && e.stack || e.message || e || "promise rejected"}`)).finally(() => this._events.emit("disconnect"));
|
|
121
121
|
});
|
|
@@ -131,7 +131,7 @@ class Room {
|
|
|
131
131
|
* @readonly
|
|
132
132
|
*/
|
|
133
133
|
get locked() {
|
|
134
|
-
return this
|
|
134
|
+
return this.#_locked;
|
|
135
135
|
}
|
|
136
136
|
get metadata() {
|
|
137
137
|
return this.listing.metadata;
|
|
@@ -139,20 +139,60 @@ class Room {
|
|
|
139
139
|
#_roomId;
|
|
140
140
|
#_roomName;
|
|
141
141
|
#_onLeaveConcurrent;
|
|
142
|
+
#_maxClientsReached;
|
|
143
|
+
#_maxClients;
|
|
142
144
|
#_autoDispose;
|
|
143
145
|
#_patchRate;
|
|
144
146
|
#_patchInterval;
|
|
147
|
+
#_state;
|
|
148
|
+
#_locked;
|
|
145
149
|
/**
|
|
146
150
|
* This method is called by the MatchMaker before onCreate()
|
|
147
151
|
* @internal
|
|
148
152
|
*/
|
|
149
153
|
__init() {
|
|
150
|
-
|
|
151
|
-
this.setState(this.state);
|
|
152
|
-
}
|
|
154
|
+
this.#_state = this.state;
|
|
153
155
|
this.#_autoDispose = this.autoDispose;
|
|
154
156
|
this.#_patchRate = this.patchRate;
|
|
157
|
+
this.#_maxClients = this.maxClients;
|
|
155
158
|
Object.defineProperties(this, {
|
|
159
|
+
state: {
|
|
160
|
+
enumerable: true,
|
|
161
|
+
get: () => this.#_state,
|
|
162
|
+
set: (newState) => {
|
|
163
|
+
if (newState[import_schema.$changes] !== void 0) {
|
|
164
|
+
this.setSerializer(new import_SchemaSerializer.SchemaSerializer());
|
|
165
|
+
} else if ("_definition" in newState) {
|
|
166
|
+
throw new Error("@colyseus/schema v2 compatibility currently missing (reach out if you need it)");
|
|
167
|
+
} else if (import_schema.$changes === void 0) {
|
|
168
|
+
throw new Error("Multiple @colyseus/schema versions detected. Please make sure you don't have multiple versions of @colyseus/schema installed.");
|
|
169
|
+
}
|
|
170
|
+
this._serializer.reset(newState);
|
|
171
|
+
this.#_state = newState;
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
maxClients: {
|
|
175
|
+
enumerable: true,
|
|
176
|
+
get: () => this.#_maxClients,
|
|
177
|
+
set: (value) => {
|
|
178
|
+
this.#_maxClients = value;
|
|
179
|
+
if (this._internalState === 1 /* CREATED */) {
|
|
180
|
+
const hasReachedMaxClients = this.hasReachedMaxClients();
|
|
181
|
+
if (!this._lockedExplicitly && this.#_maxClientsReached && !hasReachedMaxClients) {
|
|
182
|
+
this.#_maxClientsReached = false;
|
|
183
|
+
this.#_locked = false;
|
|
184
|
+
this.listing.locked = false;
|
|
185
|
+
}
|
|
186
|
+
if (hasReachedMaxClients) {
|
|
187
|
+
this.#_maxClientsReached = true;
|
|
188
|
+
this.#_locked = true;
|
|
189
|
+
this.listing.locked = true;
|
|
190
|
+
}
|
|
191
|
+
this.listing.maxClients = value;
|
|
192
|
+
this.listing.save();
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
},
|
|
156
196
|
autoDispose: {
|
|
157
197
|
enumerable: true,
|
|
158
198
|
get: () => this.#_autoDispose,
|
|
@@ -179,7 +219,11 @@ class Room {
|
|
|
179
219
|
}
|
|
180
220
|
});
|
|
181
221
|
this.patchRate = this.#_patchRate;
|
|
222
|
+
if (this.#_state) {
|
|
223
|
+
this.state = this.#_state;
|
|
224
|
+
}
|
|
182
225
|
this.resetAutoDisposeTimeout(this.seatReservationTime);
|
|
226
|
+
this.clock.start();
|
|
183
227
|
}
|
|
184
228
|
/**
|
|
185
229
|
* The name of the room you provided as first argument for `gameServer.define()`.
|
|
@@ -312,14 +356,10 @@ class Room {
|
|
|
312
356
|
setPatchRate(milliseconds) {
|
|
313
357
|
this.patchRate = milliseconds;
|
|
314
358
|
}
|
|
359
|
+
/**
|
|
360
|
+
* @deprecated Use `.state =` instead.
|
|
361
|
+
*/
|
|
315
362
|
setState(newState) {
|
|
316
|
-
this.clock.start();
|
|
317
|
-
if (newState[import_schema.$changes] !== void 0) {
|
|
318
|
-
this.setSerializer(new import_SchemaSerializer.SchemaSerializer());
|
|
319
|
-
} else if (import_schema.$changes === void 0) {
|
|
320
|
-
throw new Error("@colyseus/schema v2 compatibility currently missing (reach out if you need it)");
|
|
321
|
-
}
|
|
322
|
-
this._serializer.reset(newState);
|
|
323
363
|
this.state = newState;
|
|
324
364
|
}
|
|
325
365
|
setSerializer(serializer) {
|
|
@@ -356,12 +396,12 @@ class Room {
|
|
|
356
396
|
*/
|
|
357
397
|
async lock() {
|
|
358
398
|
this._lockedExplicitly = arguments[0] === void 0;
|
|
359
|
-
if (this
|
|
399
|
+
if (this.#_locked) {
|
|
360
400
|
return;
|
|
361
401
|
}
|
|
362
|
-
this
|
|
402
|
+
this.#_locked = true;
|
|
363
403
|
await this.listing.updateOne({
|
|
364
|
-
$set: { locked: this
|
|
404
|
+
$set: { locked: this.#_locked }
|
|
365
405
|
});
|
|
366
406
|
this._events.emit("lock");
|
|
367
407
|
}
|
|
@@ -372,12 +412,12 @@ class Room {
|
|
|
372
412
|
if (arguments[0] === void 0) {
|
|
373
413
|
this._lockedExplicitly = false;
|
|
374
414
|
}
|
|
375
|
-
if (!this
|
|
415
|
+
if (!this.#_locked) {
|
|
376
416
|
return;
|
|
377
417
|
}
|
|
378
|
-
this
|
|
418
|
+
this.#_locked = false;
|
|
379
419
|
await this.listing.updateOne({
|
|
380
|
-
$set: { locked: this
|
|
420
|
+
$set: { locked: this.#_locked }
|
|
381
421
|
});
|
|
382
422
|
this._events.emit("unlock");
|
|
383
423
|
}
|
|
@@ -770,13 +810,13 @@ class Room {
|
|
|
770
810
|
}
|
|
771
811
|
}
|
|
772
812
|
async _incrementClientCount() {
|
|
773
|
-
if (!this
|
|
774
|
-
this
|
|
813
|
+
if (!this.#_locked && this.hasReachedMaxClients()) {
|
|
814
|
+
this.#_maxClientsReached = true;
|
|
775
815
|
this.lock.call(this, true);
|
|
776
816
|
}
|
|
777
817
|
await this.listing.updateOne({
|
|
778
818
|
$inc: { clients: 1 },
|
|
779
|
-
$set: { locked: this
|
|
819
|
+
$set: { locked: this.#_locked }
|
|
780
820
|
});
|
|
781
821
|
}
|
|
782
822
|
async _decrementClientCount() {
|
|
@@ -785,13 +825,13 @@ class Room {
|
|
|
785
825
|
return true;
|
|
786
826
|
}
|
|
787
827
|
if (!willDispose) {
|
|
788
|
-
if (this
|
|
789
|
-
this
|
|
828
|
+
if (this.#_maxClientsReached && !this._lockedExplicitly) {
|
|
829
|
+
this.#_maxClientsReached = false;
|
|
790
830
|
this.unlock.call(this, true);
|
|
791
831
|
}
|
|
792
832
|
await this.listing.updateOne({
|
|
793
833
|
$inc: { clients: -1 },
|
|
794
|
-
$set: { locked: this
|
|
834
|
+
$set: { locked: this.#_locked }
|
|
795
835
|
});
|
|
796
836
|
}
|
|
797
837
|
return willDispose;
|
package/build/Room.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/Room.ts"],
|
|
4
|
-
"sourcesContent": ["import { unpack } from '@colyseus/msgpackr';\nimport { decode, Iterator, $changes } from '@colyseus/schema';\n\nimport Clock from '@colyseus/timer';\nimport { EventEmitter } from 'events';\nimport { logger } from './Logger.js';\n\nimport { Presence } from './presence/Presence.js';\n\nimport { NoneSerializer } from './serializer/NoneSerializer.js';\nimport { SchemaSerializer } from './serializer/SchemaSerializer.js';\nimport { Serializer } from './serializer/Serializer.js';\n\nimport { ErrorCode, getMessageBytes, Protocol } from './Protocol';\nimport { Deferred, generateId, wrapTryCatch } from './utils/Utils.js';\nimport { isDevMode } from './utils/DevMode.js';\n\nimport { debugAndPrintError, debugMatchMaking, debugMessage } from './Debug.js';\nimport { RoomCache } from './matchmaker/driver/api.js';\nimport { ServerError } from './errors/ServerError.js';\nimport { AuthContext, Client, ClientPrivate, ClientArray, ClientState, ISendOptions } from './Transport';\nimport { OnAuthException, OnCreateException, OnDisposeException, OnJoinException, OnLeaveException, OnMessageException, RoomException, SimulationIntervalException, TimedEventException } from './errors/RoomExceptions.js';\n\nconst DEFAULT_PATCH_RATE = 1000 / 20; // 20fps (50ms)\nconst DEFAULT_SIMULATION_INTERVAL = 1000 / 60; // 60fps (16.66ms)\nconst noneSerializer = new NoneSerializer();\n\nexport const DEFAULT_SEAT_RESERVATION_TIME = Number(process.env.COLYSEUS_SEAT_RESERVATION_TIME || 15);\n\nexport type SimulationCallback = (deltaTime: number) => void;\n\nexport interface IBroadcastOptions extends ISendOptions {\n except?: Client | Client[];\n}\n\nexport enum RoomInternalState {\n CREATING = 0,\n CREATED = 1,\n DISPOSING = 2,\n}\n\nexport type ExtractUserData<T> = T extends ClientArray<infer U> ? U : never;\nexport type ExtractAuthData<T> = T extends ClientArray<infer _, infer U> ? U : never;\n\n/**\n * A Room class is meant to implement a game session, and/or serve as the communication channel\n * between a group of clients.\n *\n * - Rooms are created on demand during matchmaking by default\n * - Room classes must be exposed using `.define()`\n */\nexport abstract class Room<State extends object= any, Metadata= any, UserData = any, AuthData = any> {\n\n /**\n * This property will change on these situations:\n * - The maximum number of allowed clients has been reached (`maxClients`)\n * - You manually locked, or unlocked the room using lock() or `unlock()`.\n *\n * @readonly\n */\n public get locked() {\n return this._locked;\n }\n\n public get metadata() {\n return this.listing.metadata;\n }\n\n public listing: RoomCache<Metadata>;\n\n /**\n * Timing events tied to the room instance.\n * Intervals and timeouts are cleared when the room is disposed.\n */\n public clock: Clock = new Clock();\n\n #_roomId: string;\n #_roomName: string;\n #_onLeaveConcurrent: number = 0; // number of onLeave calls in progress\n\n /**\n * Maximum number of clients allowed to connect into the room. When room reaches this limit,\n * it is locked automatically. Unless the room was explicitly locked by you via `lock()` method,\n * the room will be unlocked as soon as a client disconnects from it.\n */\n public maxClients: number = Infinity;\n\n /**\n * Automatically dispose the room when last client disconnects.\n *\n * @default true\n */\n public autoDispose: boolean = true;\n #_autoDispose: boolean;\n\n /**\n * Frequency to send the room state to connected clients, in milliseconds.\n *\n * @default 50ms (20fps)\n */\n public patchRate: number = DEFAULT_PATCH_RATE;\n #_patchRate: number;\n #_patchInterval: NodeJS.Timeout;\n\n /**\n * The state instance you provided to `setState()`.\n */\n public state: State;\n\n /**\n * The presence instance. Check Presence API for more details.\n *\n * @see {@link https://docs.colyseus.io/colyseus/server/presence/|Presence API}\n */\n public presence: Presence;\n\n /**\n * The array of connected clients.\n *\n * @see {@link https://docs.colyseus.io/colyseus/server/room/#client|Client instance}\n */\n public clients: ClientArray<UserData, AuthData> = new ClientArray();\n\n /** @internal */\n public _events = new EventEmitter();\n\n // seat reservation & reconnection\n protected seatReservationTime: number = DEFAULT_SEAT_RESERVATION_TIME;\n protected reservedSeats: { [sessionId: string]: [any, any, boolean?, boolean?] } = {};\n protected reservedSeatTimeouts: { [sessionId: string]: NodeJS.Timeout } = {};\n\n protected _reconnections: { [reconnectionToken: string]: [string, Deferred] } = {};\n private _reconnectingSessionId = new Map<string, string>();\n\n private onMessageHandlers: {\n [id: string]: {\n callback: (...args: any[]) => void,\n validate?: (data: unknown) => any,\n }\n } = {\n '__no_message_handler': {\n callback: (client: Client, messageType: string, _: unknown) => {\n const errorMessage = `onMessage for \"${messageType}\" not registered.`;\n debugAndPrintError(errorMessage);\n\n if (isDevMode) {\n // send error code to client in development mode\n client.error(ErrorCode.INVALID_PAYLOAD, errorMessage);\n\n } else {\n // immediately close the connection in production\n client.leave(Protocol.WS_CLOSE_WITH_ERROR, errorMessage);\n }\n }\n }\n };\n\n private _serializer: Serializer<State> = noneSerializer;\n private _afterNextPatchQueue: Array<[string | Client, IArguments]> = [];\n\n private _simulationInterval: NodeJS.Timeout;\n\n private _internalState: RoomInternalState = RoomInternalState.CREATING;\n private _locked: boolean = false;\n private _lockedExplicitly: boolean = false;\n private _maxClientsReached: boolean = false;\n\n // this timeout prevents rooms that are created by one process, but no client\n // ever had success joining into it on the specified interval.\n private _autoDisposeTimeout: NodeJS.Timeout;\n\n constructor() {\n this._events.once('dispose', () => {\n this._dispose()\n .catch((e) => debugAndPrintError(`onDispose error: ${(e && e.stack || e.message || e || 'promise rejected')}`))\n .finally(() => this._events.emit('disconnect'));\n });\n\n /**\n * If `onUncaughtException` is defined, it will automatically catch exceptions\n */\n if (this.onUncaughtException !== undefined) {\n this.#registerUncaughtExceptionHandlers();\n }\n }\n\n /**\n * This method is called by the MatchMaker before onCreate()\n * @internal\n */\n protected __init() {\n if (this.state) {\n this.setState(this.state);\n }\n\n this.#_autoDispose = this.autoDispose;\n this.#_patchRate = this.patchRate;\n\n Object.defineProperties(this, {\n autoDispose: {\n enumerable: true,\n get: () => this.#_autoDispose,\n set: (value: boolean) => {\n if (\n value !== this.#_autoDispose &&\n this._internalState !== RoomInternalState.DISPOSING\n ) {\n this.#_autoDispose = value;\n this.resetAutoDisposeTimeout();\n }\n },\n },\n\n patchRate: {\n enumerable: true,\n get: () => this.#_patchRate,\n set: (milliseconds: number) => {\n this.#_patchRate = milliseconds;\n // clear previous interval in case called setPatchRate more than once\n if (this.#_patchInterval) {\n clearInterval(this.#_patchInterval);\n this.#_patchInterval = undefined;\n }\n if (milliseconds !== null && milliseconds !== 0) {\n this.#_patchInterval = setInterval(() => this.broadcastPatch(), milliseconds);\n }\n },\n },\n });\n\n // set patch interval, now with the setter\n this.patchRate = this.#_patchRate;\n\n // set default _autoDisposeTimeout\n this.resetAutoDisposeTimeout(this.seatReservationTime);\n }\n\n /**\n * The name of the room you provided as first argument for `gameServer.define()`.\n *\n * @returns roomName string\n */\n public get roomName() { return this.#_roomName; }\n /**\n * Setting the name of the room. Overwriting this property is restricted.\n *\n * @param roomName\n */\n public set roomName(roomName: string) {\n if (this.#_roomName) {\n // prevent user from setting roomName after it has been defined.\n throw new ServerError(ErrorCode.APPLICATION_ERROR, \"'roomName' cannot be overwritten.\");\n }\n this.#_roomName = roomName;\n }\n\n /**\n * A unique, auto-generated, 9-character-long id of the room.\n * You may replace `this.roomId` during `onCreate()`.\n *\n * @returns roomId string\n */\n public get roomId() { return this.#_roomId; }\n\n /**\n * Setting the roomId, is restricted in room lifetime except upon room creation.\n *\n * @param roomId\n * @returns roomId string\n */\n public set roomId(roomId: string) {\n if (this._internalState !== RoomInternalState.CREATING && !isDevMode) {\n // prevent user from setting roomId after room has been created.\n throw new ServerError(ErrorCode.APPLICATION_ERROR, \"'roomId' can only be overridden upon room creation.\");\n }\n this.#_roomId = roomId;\n }\n\n // Optional abstract methods\n public onBeforePatch?(state: State): void | Promise<any>;\n public onCreate?(options: any): void | Promise<any>;\n public onJoin?(client: Client<UserData, AuthData>, options?: any, auth?: AuthData): void | Promise<any>;\n public onLeave?(client: Client<UserData, AuthData>, consented?: boolean): void | Promise<any>;\n public onDispose?(): void | Promise<any>;\n\n /**\n * Define a custom exception handler.\n * If defined, all lifecycle hooks will be wrapped by try/catch, and the exception will be forwarded to this method.\n *\n * These methods will be wrapped by try/catch:\n * - `onMessage`\n * - `onAuth` / `onJoin` / `onLeave` / `onCreate` / `onDispose`\n * - `clock.setTimeout` / `clock.setInterval`\n * - `setSimulationInterval`\n *\n * (Experimental: this feature is subject to change in the future - we're currently getting feedback to improve it)\n */\n public onUncaughtException?(error: RoomException<this>, methodName: 'onCreate' | 'onAuth' | 'onJoin' | 'onLeave' | 'onDispose' | 'onMessage' | 'setSimulationInterval' | 'setInterval' | 'setTimeout'): void;\n\n public onAuth(\n client: Client<UserData, AuthData>,\n options: any,\n context: AuthContext\n ): any | Promise<any> {\n return true;\n }\n\n static async onAuth(\n token: string,\n options: any,\n context: AuthContext\n ): Promise<unknown> {\n return true;\n }\n\n /**\n * This method is called during graceful shutdown of the server process\n * You may override this method to dispose the room in your own way.\n *\n * Once process reaches room count of 0, the room process will be terminated.\n */\n public onBeforeShutdown() {\n this.disconnect(\n (isDevMode)\n ? Protocol.WS_CLOSE_DEVMODE_RESTART\n : Protocol.WS_CLOSE_CONSENTED\n );\n }\n\n /**\n * devMode: When `devMode` is enabled, `onCacheRoom` method is called during\n * graceful shutdown.\n *\n * Implement this method to return custom data to be cached. `onRestoreRoom`\n * will be called with the data returned by `onCacheRoom`\n */\n public onCacheRoom?(): any;\n\n /**\n * devMode: When `devMode` is enabled, `onRestoreRoom` method is called during\n * process startup, with the data returned by the `onCacheRoom` method.\n */\n public onRestoreRoom?(cached?: any): void;\n\n /**\n * Returns whether the sum of connected clients and reserved seats exceeds maximum number of clients.\n *\n * @returns boolean\n */\n public hasReachedMaxClients(): boolean {\n return (\n (this.clients.length + Object.keys(this.reservedSeats).length) >= this.maxClients ||\n this._internalState === RoomInternalState.DISPOSING\n );\n }\n\n /**\n * Set the number of seconds a room can wait for a client to effectively join the room.\n * You should consider how long your `onAuth()` will have to wait for setting a different seat reservation time.\n * The default value is 15 seconds. You may set the `COLYSEUS_SEAT_RESERVATION_TIME`\n * environment variable if you'd like to change the seat reservation time globally.\n *\n * @default 15 seconds\n *\n * @param seconds - number of seconds.\n * @returns The modified Room object.\n */\n public setSeatReservationTime(seconds: number) {\n this.seatReservationTime = seconds;\n return this;\n }\n\n public hasReservedSeat(sessionId: string, reconnectionToken?: string): boolean {\n const reservedSeat = this.reservedSeats[sessionId];\n\n // seat reservation not found / expired\n if (reservedSeat === undefined) {\n return false;\n }\n\n if (reservedSeat[3]) {\n // reconnection\n return (\n reconnectionToken &&\n this._reconnections[reconnectionToken]?.[0] === sessionId &&\n this._reconnectingSessionId.has(sessionId)\n );\n\n } else {\n // seat reservation not consumed\n return reservedSeat[2] === false;\n }\n }\n\n public checkReconnectionToken(reconnectionToken: string) {\n const sessionId = this._reconnections[reconnectionToken]?.[0];\n const reservedSeat = this.reservedSeats[sessionId];\n\n if (reservedSeat && reservedSeat[3]) {\n this._reconnectingSessionId.set(sessionId, reconnectionToken);\n return sessionId;\n\n } else {\n return undefined;\n }\n }\n\n /**\n * (Optional) Set a simulation interval that can change the state of the game.\n * The simulation interval is your game loop.\n *\n * @default 16.6ms (60fps)\n *\n * @param onTickCallback - You can implement your physics or world updates here!\n * This is a good place to update the room state.\n * @param delay - Interval delay on executing `onTickCallback` in milliseconds.\n */\n public setSimulationInterval(onTickCallback?: SimulationCallback, delay: number = DEFAULT_SIMULATION_INTERVAL): void {\n // clear previous interval in case called setSimulationInterval more than once\n if (this._simulationInterval) { clearInterval(this._simulationInterval); }\n\n if (onTickCallback) {\n if (this.onUncaughtException !== undefined) {\n onTickCallback = wrapTryCatch(onTickCallback, this.onUncaughtException.bind(this), SimulationIntervalException, 'setSimulationInterval');\n }\n\n this._simulationInterval = setInterval(() => {\n this.clock.tick();\n onTickCallback(this.clock.deltaTime);\n }, delay);\n }\n }\n\n /**\n * @deprecated Use `.patchRate=` instead.\n */\n public setPatchRate(milliseconds: number | null): void {\n this.patchRate = milliseconds;\n }\n\n public setState(newState: State) {\n this.clock.start();\n\n if (newState[$changes] !== undefined) {\n this.setSerializer(new SchemaSerializer());\n\n } else if ($changes === undefined) {\n throw new Error(\"@colyseus/schema v2 compatibility currently missing (reach out if you need it)\");\n }\n\n this._serializer.reset(newState);\n\n this.state = newState;\n }\n\n public setSerializer(serializer: Serializer<State>) {\n this._serializer = serializer;\n }\n\n public async setMetadata(meta: Partial<Metadata>) {\n if (!this.listing.metadata) {\n this.listing.metadata = meta as Metadata;\n\n } else {\n for (const field in meta) {\n if (!meta.hasOwnProperty(field)) { continue; }\n this.listing.metadata[field] = meta[field];\n }\n\n // `MongooseDriver` workaround: persit metadata mutations\n if ('markModified' in this.listing) {\n (this.listing as any).markModified('metadata');\n }\n }\n\n if (this._internalState === RoomInternalState.CREATED) {\n await this.listing.save();\n }\n }\n\n public async setPrivate(bool: boolean = true) {\n if (this.listing.private === bool) return;\n\n this.listing.private = bool;\n\n if (this._internalState === RoomInternalState.CREATED) {\n await this.listing.save();\n }\n\n this._events.emit('visibility-change', bool);\n }\n\n /**\n * Locking the room will remove it from the pool of available rooms for new clients to connect to.\n */\n public async lock() {\n // rooms locked internally aren't explicit locks.\n this._lockedExplicitly = (arguments[0] === undefined);\n\n // skip if already locked.\n if (this._locked) { return; }\n\n this._locked = true;\n\n await this.listing.updateOne({\n $set: { locked: this._locked },\n });\n\n this._events.emit('lock');\n }\n\n /**\n * Unlocking the room returns it to the pool of available rooms for new clients to connect to.\n */\n public async unlock() {\n // only internal usage passes arguments to this function.\n if (arguments[0] === undefined) {\n this._lockedExplicitly = false;\n }\n\n // skip if already locked\n if (!this._locked) { return; }\n\n this._locked = false;\n\n await this.listing.updateOne({\n $set: { locked: this._locked },\n });\n\n this._events.emit('unlock');\n }\n\n public send(client: Client, type: string | number, message: any, options?: ISendOptions): void;\n public send(client: Client, messageOrType: any, messageOrOptions?: any | ISendOptions, options?: ISendOptions): void {\n logger.warn('DEPRECATION WARNING: use client.send(...) instead of this.send(client, ...)');\n client.send(messageOrType, messageOrOptions, options);\n }\n\n public broadcast(type: string | number, message?: any, options?: IBroadcastOptions) {\n if (options && options.afterNextPatch) {\n delete options.afterNextPatch;\n this._afterNextPatchQueue.push(['broadcast', arguments]);\n return;\n }\n\n this.broadcastMessageType(type, message, options);\n }\n\n /**\n * Broadcast bytes (UInt8Arrays) to a particular room\n */\n public broadcastBytes(type: string | number, message: Uint8Array, options: IBroadcastOptions) {\n if (options && options.afterNextPatch) {\n delete options.afterNextPatch;\n this._afterNextPatchQueue.push(['broadcastBytes', arguments]);\n return;\n }\n\n this.broadcastMessageType(type as string, message, options);\n }\n\n /**\n * Checks whether mutations have occurred in the state, and broadcast them to all connected clients.\n */\n public broadcastPatch() {\n if (this.onBeforePatch) {\n this.onBeforePatch(this.state);\n }\n\n if (!this._simulationInterval) {\n this.clock.tick();\n }\n\n if (!this.state) {\n return false;\n }\n\n const hasChanges = this._serializer.applyPatches(this.clients, this.state);\n\n // broadcast messages enqueued for \"after patch\"\n this._dequeueAfterPatchMessages();\n\n return hasChanges;\n }\n\n public onMessage<T = any>(\n messageType: '*',\n callback: (client: Client<UserData, AuthData>, type: string | number, message: T) => void\n );\n public onMessage<T = any>(\n messageType: string | number,\n callback: (client: Client<UserData, AuthData>, message: T) => void,\n validate?: (message: unknown) => T,\n );\n public onMessage<T = any>(\n messageType: '*' | string | number,\n callback: (...args: any[]) => void,\n validate?: (message: unknown) => T,\n ) {\n this.onMessageHandlers[messageType] = (this.onUncaughtException !== undefined)\n ? { validate, callback: wrapTryCatch(callback, this.onUncaughtException.bind(this), OnMessageException, 'onMessage', false, messageType) }\n : { validate, callback };\n\n\n // returns a method to unbind the callback\n return () => delete this.onMessageHandlers[messageType];\n }\n\n /**\n * Disconnect all connected clients, and then dispose the room.\n *\n * @param closeCode WebSocket close code (default = 4000, which is a \"consented leave\")\n * @returns Promise<void>\n */\n public disconnect(closeCode: number = Protocol.WS_CLOSE_CONSENTED): Promise<any> {\n // skip if already disposing\n if (this._internalState === RoomInternalState.DISPOSING) {\n return Promise.resolve(`disconnect() ignored: room (${this.roomId}) is already disposing.`);\n\n } else if (this._internalState === RoomInternalState.CREATING) {\n throw new Error(\"cannot disconnect during onCreate()\");\n }\n\n this._internalState = RoomInternalState.DISPOSING;\n this.listing.remove();\n\n this.#_autoDispose = true;\n\n const delayedDisconnection = new Promise<void>((resolve) =>\n this._events.once('disconnect', () => resolve()));\n\n // reject pending reconnections\n for (const [_, reconnection] of Object.values(this._reconnections)) {\n reconnection.reject(new Error(\"disconnecting\"));\n }\n\n let numClients = this.clients.length;\n if (numClients > 0) {\n // clients may have `async onLeave`, room will be disposed after they're fulfilled\n while (numClients--) {\n this._forciblyCloseClient(this.clients[numClients] as Client & ClientPrivate, closeCode);\n }\n\n } else {\n // no clients connected, dispose immediately.\n this._events.emit('dispose');\n }\n\n return delayedDisconnection;\n }\n\n public async ['_onJoin'](client: Client & ClientPrivate, authContext: AuthContext) {\n const sessionId = client.sessionId;\n\n // generate unique private reconnection token\n client.reconnectionToken = generateId();\n\n if (this.reservedSeatTimeouts[sessionId]) {\n clearTimeout(this.reservedSeatTimeouts[sessionId]);\n delete this.reservedSeatTimeouts[sessionId];\n }\n\n // clear auto-dispose timeout.\n if (this._autoDisposeTimeout) {\n clearTimeout(this._autoDisposeTimeout);\n this._autoDisposeTimeout = undefined;\n }\n\n // get seat reservation options and clear it\n const [joinOptions, authData, isConsumed, isWaitingReconnection] = this.reservedSeats[sessionId];\n\n //\n // TODO: remove this check on 1.0.0\n // - the seat reservation is used to keep track of number of clients and their pending seats (see `hasReachedMaxClients`)\n // - when we fully migrate to static onAuth(), the seat reservation can be removed immediately here\n // - if async onAuth() is in use, the seat reservation is removed after onAuth() is fulfilled.\n // - mark reservation as \"consumed\"\n //\n if (isConsumed) {\n throw new ServerError(ErrorCode.MATCHMAKE_EXPIRED, \"already consumed\");\n }\n this.reservedSeats[sessionId][2] = true; // flag seat reservation as \"consumed\"\n debugMatchMaking('consuming seat reservation, sessionId: \\'%s\\'', client.sessionId);\n\n // share \"after next patch queue\" reference with every client.\n client._afterNextPatchQueue = this._afterNextPatchQueue;\n\n // add temporary callback to keep track of disconnections during `onJoin`.\n client.ref['onleave'] = (_) => client.state = ClientState.LEAVING;\n client.ref.once('close', client.ref['onleave']);\n\n if (isWaitingReconnection) {\n const previousReconnectionToken = this._reconnectingSessionId.get(sessionId);\n if (previousReconnectionToken) {\n this.clients.push(client);\n //\n // await for reconnection:\n // (end user may customize the reconnection token at this step)\n //\n await this._reconnections[previousReconnectionToken]?.[1].resolve(client);\n\n } else {\n const errorMessage = (process.env.NODE_ENV === 'production')\n ? \"already consumed\" // trick possible fraudsters...\n : \"bad reconnection token\" // ...or developers\n throw new ServerError(ErrorCode.MATCHMAKE_EXPIRED, errorMessage);\n }\n\n } else {\n try {\n if (authData) {\n client.auth = authData;\n\n } else if (this.onAuth !== Room.prototype.onAuth) {\n try {\n client.auth = await this.onAuth(client, joinOptions, authContext);\n\n if (!client.auth) {\n throw new ServerError(ErrorCode.AUTH_FAILED, 'onAuth failed');\n }\n\n } catch (e) {\n // remove seat reservation\n delete this.reservedSeats[sessionId];\n await this._decrementClientCount();\n throw e;\n }\n }\n\n //\n // On async onAuth, client may have been disconnected.\n //\n if (client.state === ClientState.LEAVING) {\n throw new ServerError(Protocol.WS_CLOSE_GOING_AWAY, 'already disconnected');\n }\n\n this.clients.push(client);\n\n //\n // Flag sessionId as non-enumarable so hasReachedMaxClients() doesn't count it\n // (https://github.com/colyseus/colyseus/issues/726)\n //\n Object.defineProperty(this.reservedSeats, sessionId, {\n value: this.reservedSeats[sessionId],\n enumerable: false,\n });\n\n if (this.onJoin) {\n await this.onJoin(client, joinOptions, client.auth);\n }\n\n // @ts-ignore: client left during `onJoin`, call _onLeave immediately.\n if (client.state === ClientState.LEAVING) {\n throw new Error(\"early_leave\");\n\n } else {\n // remove seat reservation\n delete this.reservedSeats[sessionId];\n\n // emit 'join' to room handler\n this._events.emit('join', client);\n }\n\n } catch (e) {\n await this._onLeave(client, Protocol.WS_CLOSE_GOING_AWAY);\n\n // remove seat reservation\n delete this.reservedSeats[sessionId];\n\n // make sure an error code is provided.\n if (!e.code) {\n e.code = ErrorCode.APPLICATION_ERROR;\n }\n\n throw e;\n }\n }\n\n // state might already be ClientState.LEAVING here\n if (client.state === ClientState.JOINING) {\n client.ref.removeListener('close', client.ref['onleave']);\n\n // only bind _onLeave after onJoin has been successful\n client.ref['onleave'] = this._onLeave.bind(this, client);\n client.ref.once('close', client.ref['onleave']);\n\n // allow client to send messages after onJoin has succeeded.\n client.ref.on('message', this._onMessage.bind(this, client));\n\n // confirm room id that matches the room name requested to join\n client.raw(getMessageBytes[Protocol.JOIN_ROOM](\n client.reconnectionToken,\n this._serializer.id,\n this._serializer.handshake && this._serializer.handshake(),\n ));\n }\n }\n\n /**\n * Allow the specified client to reconnect into the room. Must be used inside `onLeave()` method.\n * If seconds is provided, the reconnection is going to be cancelled after the provided amount of seconds.\n *\n * @param previousClient - The client which is to be waiting until re-connection happens.\n * @param seconds - Timeout period on re-connection in seconds.\n *\n * @returns Deferred<Client> - The differed is a promise like type.\n * This type can forcibly reject the promise by calling `.reject()`.\n */\n public allowReconnection(previousClient: Client, seconds: number | \"manual\"): Deferred<Client> {\n //\n // Return rejected promise if client has never fully JOINED.\n //\n // (having `_enqueuedMessages !== undefined` means that the client has never been at \"ClientState.JOINED\" state)\n //\n if ((previousClient as unknown as ClientPrivate)._enqueuedMessages !== undefined) {\n // @ts-ignore\n return Promise.reject(new Error(\"not joined\"));\n }\n\n if (seconds === undefined) { // TODO: remove this check\n console.warn(\"DEPRECATED: allowReconnection() requires a second argument. Using \\\"manual\\\" mode.\");\n seconds = \"manual\";\n }\n\n if (seconds === \"manual\") {\n seconds = Infinity;\n }\n\n if (this._internalState === RoomInternalState.DISPOSING) {\n // @ts-ignore\n return Promise.reject(new Error(\"disposing\"));\n }\n\n const sessionId = previousClient.sessionId;\n const reconnectionToken = previousClient.reconnectionToken;\n\n this._reserveSeat(sessionId, true, previousClient.auth, seconds, true);\n\n // keep reconnection reference in case the user reconnects into this room.\n const reconnection = new Deferred<Client & ClientPrivate>();\n this._reconnections[reconnectionToken] = [sessionId, reconnection];\n\n if (seconds !== Infinity) {\n // expire seat reservation after timeout\n this.reservedSeatTimeouts[sessionId] = setTimeout(() =>\n reconnection.reject(false), seconds * 1000);\n }\n\n const cleanup = () => {\n delete this._reconnections[reconnectionToken];\n delete this.reservedSeats[sessionId];\n delete this.reservedSeatTimeouts[sessionId];\n this._reconnectingSessionId.delete(sessionId);\n };\n\n reconnection.\n then((newClient) => {\n newClient.auth = previousClient.auth;\n newClient.userData = previousClient.userData;\n previousClient.ref = newClient.ref; // swap \"ref\" for convenience\n previousClient.state = ClientState.RECONNECTED;\n clearTimeout(this.reservedSeatTimeouts[sessionId]);\n cleanup();\n }).\n catch(() => {\n cleanup();\n this.resetAutoDisposeTimeout();\n });\n\n return reconnection;\n }\n\n protected resetAutoDisposeTimeout(timeoutInSeconds: number = 1) {\n clearTimeout(this._autoDisposeTimeout);\n\n if (!this.#_autoDispose) {\n return;\n }\n\n this._autoDisposeTimeout = setTimeout(() => {\n this._autoDisposeTimeout = undefined;\n this._disposeIfEmpty();\n }, timeoutInSeconds * 1000);\n }\n\n private broadcastMessageType(type: number | string, message?: any | Uint8Array, options: IBroadcastOptions = {}) {\n debugMessage(\"broadcast: %O\", message);\n\n const encodedMessage = (message instanceof Uint8Array)\n ? getMessageBytes.raw(Protocol.ROOM_DATA_BYTES, type, undefined, message)\n : getMessageBytes.raw(Protocol.ROOM_DATA, type, message)\n\n const except = (typeof (options.except) !== \"undefined\")\n ? Array.isArray(options.except)\n ? options.except\n : [options.except]\n : undefined;\n\n let numClients = this.clients.length;\n while (numClients--) {\n const client = this.clients[numClients];\n\n if (!except || !except.includes(client)) {\n client.enqueueRaw(encodedMessage);\n }\n }\n }\n\n protected sendFullState(client: Client): void {\n client.raw(this._serializer.getFullState(client));\n }\n\n protected _dequeueAfterPatchMessages() {\n const length = this._afterNextPatchQueue.length;\n\n if (length > 0) {\n for (let i = 0; i < length; i++) {\n const [target, args] = this._afterNextPatchQueue[i];\n\n if (target === \"broadcast\") {\n this.broadcast.apply(this, args);\n\n } else {\n (target as Client).raw.apply(target, args);\n }\n }\n\n // new messages may have been added in the meantime,\n // let's splice the ones that have been processed\n this._afterNextPatchQueue.splice(0, length);\n }\n }\n\n protected async _reserveSeat(\n sessionId: string,\n joinOptions: any = true,\n authData: any = undefined,\n seconds: number = this.seatReservationTime,\n allowReconnection: boolean = false,\n devModeReconnection?: boolean,\n ) {\n if (!allowReconnection && this.hasReachedMaxClients()) {\n return false;\n }\n\n this.reservedSeats[sessionId] = [joinOptions, authData, false, allowReconnection];\n\n if (!allowReconnection) {\n await this._incrementClientCount();\n\n this.reservedSeatTimeouts[sessionId] = setTimeout(async () => {\n delete this.reservedSeats[sessionId];\n delete this.reservedSeatTimeouts[sessionId];\n await this._decrementClientCount();\n }, seconds * 1000);\n\n this.resetAutoDisposeTimeout(seconds);\n }\n\n //\n // isDevMode workaround to allow players to reconnect on devMode\n //\n if (devModeReconnection) {\n this._reconnectingSessionId.set(sessionId, sessionId);\n }\n\n return true;\n }\n\n protected _disposeIfEmpty() {\n const willDispose = (\n this.#_onLeaveConcurrent === 0 && // no \"onLeave\" calls in progress\n this.#_autoDispose &&\n this._autoDisposeTimeout === undefined &&\n this.clients.length === 0 &&\n Object.keys(this.reservedSeats).length === 0\n );\n\n if (willDispose) {\n this._events.emit('dispose');\n }\n\n return willDispose;\n }\n\n protected async _dispose(): Promise<any> {\n this._internalState = RoomInternalState.DISPOSING;\n\n this.listing.remove();\n\n let userReturnData;\n if (this.onDispose) {\n userReturnData = this.onDispose();\n }\n\n if (this.#_patchInterval) {\n clearInterval(this.#_patchInterval);\n this.#_patchInterval = undefined;\n }\n\n if (this._simulationInterval) {\n clearInterval(this._simulationInterval);\n this._simulationInterval = undefined;\n }\n\n if (this._autoDisposeTimeout) {\n clearInterval(this._autoDisposeTimeout);\n this._autoDisposeTimeout = undefined;\n }\n\n // clear all timeouts/intervals + force to stop ticking\n this.clock.clear();\n this.clock.stop();\n\n return await (userReturnData || Promise.resolve());\n }\n\n protected _onMessage(client: Client & ClientPrivate, buffer: Buffer) {\n // skip if client is on LEAVING state.\n if (client.state === ClientState.LEAVING) { return; }\n\n const it: Iterator = { offset: 1 };\n const code = buffer[0];\n\n if (!buffer) {\n debugAndPrintError(`${this.roomName} (${this.roomId}), couldn't decode message: ${buffer}`);\n return;\n }\n\n if (code === Protocol.ROOM_DATA) {\n const messageType = (decode.stringCheck(buffer, it))\n ? decode.string(buffer, it)\n : decode.number(buffer, it);\n const messageTypeHandler = this.onMessageHandlers[messageType];\n\n let message;\n try {\n message = (buffer.byteLength > it.offset)\n ? unpack(buffer.subarray(it.offset, buffer.byteLength))\n : undefined;\n debugMessage(\"received: '%s' -> %j\", messageType, message);\n\n // custom message validation\n if (messageTypeHandler?.validate !== undefined) {\n message = messageTypeHandler.validate(message);\n }\n\n } catch (e) {\n debugAndPrintError(e);\n client.leave(Protocol.WS_CLOSE_WITH_ERROR);\n return;\n }\n\n if (messageTypeHandler) {\n messageTypeHandler.callback(client, message);\n\n } else {\n (this.onMessageHandlers['*'] || this.onMessageHandlers['__no_message_handler']).callback(client, messageType, message);\n }\n\n } else if (code === Protocol.ROOM_DATA_BYTES) {\n const messageType = (decode.stringCheck(buffer, it))\n ? decode.string(buffer, it)\n : decode.number(buffer, it);\n const messageTypeHandler = this.onMessageHandlers[messageType];\n\n let message = buffer.subarray(it.offset, buffer.byteLength);\n debugMessage(\"received: '%s' -> %j\", messageType, message);\n\n // custom message validation\n if (messageTypeHandler?.validate !== undefined) {\n message = messageTypeHandler.validate(message);\n }\n\n if (messageTypeHandler) {\n messageTypeHandler.callback(client, message);\n\n } else {\n (this.onMessageHandlers['*'] || this.onMessageHandlers['__no_message_handler']).callback(client, messageType, message);\n }\n\n } else if (code === Protocol.JOIN_ROOM && client.state === ClientState.JOINING) {\n // join room has been acknowledged by the client\n client.state = ClientState.JOINED;\n client._joinedAt = this.clock.elapsedTime;\n\n // send current state when new client joins the room\n if (this.state) {\n this.sendFullState(client);\n }\n\n // dequeue messages sent before client has joined effectively (on user-defined `onJoin`)\n if (client._enqueuedMessages.length > 0) {\n client._enqueuedMessages.forEach((enqueued) => client.raw(enqueued));\n }\n delete client._enqueuedMessages;\n\n } else if (code === Protocol.LEAVE_ROOM) {\n this._forciblyCloseClient(client, Protocol.WS_CLOSE_CONSENTED);\n }\n\n }\n\n protected _forciblyCloseClient(client: Client & ClientPrivate, closeCode: number) {\n // stop receiving messages from this client\n client.ref.removeAllListeners('message');\n\n // prevent \"onLeave\" from being called twice if player asks to leave\n client.ref.removeListener('close', client.ref['onleave']);\n\n // only effectively close connection when \"onLeave\" is fulfilled\n this._onLeave(client, closeCode).then(() => client.leave(closeCode));\n }\n\n protected async _onLeave(client: Client, code?: number): Promise<any> {\n debugMatchMaking('onLeave, sessionId: \\'%s\\'', client.sessionId);\n\n // call 'onLeave' method only if the client has been successfully accepted.\n client.state = ClientState.LEAVING;\n\n if (!this.clients.delete(client)) {\n // skip if client already left the room\n return;\n }\n\n if (this.onLeave) {\n try {\n this.#_onLeaveConcurrent++;\n await this.onLeave(client, (code === Protocol.WS_CLOSE_CONSENTED));\n\n } catch (e) {\n debugAndPrintError(`onLeave error: ${(e && e.message || e || 'promise rejected')}`);\n\n } finally {\n this.#_onLeaveConcurrent--;\n }\n }\n\n // check for manual \"reconnection\" flow\n if (this._reconnections[client.reconnectionToken]) {\n this._reconnections[client.reconnectionToken][1].catch(async () => {\n await this._onAfterLeave(client);\n });\n\n // @ts-ignore (client.state may be modified at onLeave())\n } else if (client.state !== ClientState.RECONNECTED) {\n await this._onAfterLeave(client);\n }\n }\n\n protected async _onAfterLeave(client: Client) {\n // try to dispose immediately if client reconnection isn't set up.\n const willDispose = await this._decrementClientCount();\n\n // trigger 'leave' only if seat reservation has been fully consumed\n if (this.reservedSeats[client.sessionId] === undefined) {\n this._events.emit('leave', client, willDispose);\n }\n\n }\n\n protected async _incrementClientCount() {\n // lock automatically when maxClients is reached\n if (!this._locked && this.hasReachedMaxClients()) {\n this._maxClientsReached = true;\n this.lock.call(this, true);\n }\n\n await this.listing.updateOne({\n $inc: { clients: 1 },\n $set: { locked: this._locked },\n });\n }\n\n protected async _decrementClientCount() {\n const willDispose = this._disposeIfEmpty();\n\n if (this._internalState === RoomInternalState.DISPOSING) {\n return true;\n }\n\n // unlock if room is available for new connections\n if (!willDispose) {\n if (this._maxClientsReached && !this._lockedExplicitly) {\n this._maxClientsReached = false;\n this.unlock.call(this, true);\n }\n\n // update room listing cache\n await this.listing.updateOne({\n $inc: { clients: -1 },\n $set: { locked: this._locked },\n });\n }\n\n return willDispose;\n }\n\n #registerUncaughtExceptionHandlers() {\n const onUncaughtException = this.onUncaughtException.bind(this);\n const originalSetTimeout = this.clock.setTimeout;\n this.clock.setTimeout = (cb, timeout, ...args) => {\n return originalSetTimeout.call(this.clock, wrapTryCatch(cb, onUncaughtException, TimedEventException, 'setTimeout'), timeout, ...args);\n };\n\n const originalSetInterval = this.clock.setInterval;\n this.clock.setInterval = (cb, timeout, ...args) => {\n return originalSetInterval.call(this.clock, wrapTryCatch(cb, onUncaughtException, TimedEventException, 'setInterval'), timeout, ...args);\n };\n\n if (this.onCreate !== undefined) {\n this.onCreate = wrapTryCatch(this.onCreate.bind(this), onUncaughtException, OnCreateException, 'onCreate', true);\n }\n\n if (this.onAuth !== undefined) {\n this.onAuth = wrapTryCatch(this.onAuth.bind(this), onUncaughtException, OnAuthException, 'onAuth', true);\n }\n\n if (this.onJoin !== undefined) {\n this.onJoin = wrapTryCatch(this.onJoin.bind(this), onUncaughtException, OnJoinException, 'onJoin', true);\n }\n\n if (this.onLeave !== undefined) {\n this.onLeave = wrapTryCatch(this.onLeave.bind(this), onUncaughtException, OnLeaveException, 'onLeave', true);\n }\n\n if (this.onDispose !== undefined) {\n this.onDispose = wrapTryCatch(this.onDispose.bind(this), onUncaughtException, OnDisposeException, 'onDispose');\n }\n }\n\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sB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,EACF;AAEF;",
|
|
4
|
+
"sourcesContent": ["import { unpack } from '@colyseus/msgpackr';\nimport { decode, Iterator, $changes } from '@colyseus/schema';\n\nimport Clock from '@colyseus/timer';\nimport { EventEmitter } from 'events';\nimport { logger } from './Logger.js';\n\nimport { Presence } from './presence/Presence.js';\n\nimport { NoneSerializer } from './serializer/NoneSerializer.js';\nimport { SchemaSerializer } from './serializer/SchemaSerializer.js';\nimport { Serializer } from './serializer/Serializer.js';\n\nimport { ErrorCode, getMessageBytes, Protocol } from './Protocol';\nimport { Deferred, generateId, wrapTryCatch } from './utils/Utils.js';\nimport { isDevMode } from './utils/DevMode.js';\n\nimport { debugAndPrintError, debugMatchMaking, debugMessage } from './Debug.js';\nimport { RoomCache } from './matchmaker/driver/api.js';\nimport { ServerError } from './errors/ServerError.js';\nimport { AuthContext, Client, ClientPrivate, ClientArray, ClientState, ISendOptions } from './Transport';\nimport { OnAuthException, OnCreateException, OnDisposeException, OnJoinException, OnLeaveException, OnMessageException, RoomException, SimulationIntervalException, TimedEventException } from './errors/RoomExceptions.js';\n\nconst DEFAULT_PATCH_RATE = 1000 / 20; // 20fps (50ms)\nconst DEFAULT_SIMULATION_INTERVAL = 1000 / 60; // 60fps (16.66ms)\nconst noneSerializer = new NoneSerializer();\n\nexport const DEFAULT_SEAT_RESERVATION_TIME = Number(process.env.COLYSEUS_SEAT_RESERVATION_TIME || 15);\n\nexport type SimulationCallback = (deltaTime: number) => void;\n\nexport interface IBroadcastOptions extends ISendOptions {\n except?: Client | Client[];\n}\n\nexport enum RoomInternalState {\n CREATING = 0,\n CREATED = 1,\n DISPOSING = 2,\n}\n\nexport type ExtractUserData<T> = T extends ClientArray<infer U> ? U : never;\nexport type ExtractAuthData<T> = T extends ClientArray<infer _, infer U> ? U : never;\n\n/**\n * A Room class is meant to implement a game session, and/or serve as the communication channel\n * between a group of clients.\n *\n * - Rooms are created on demand during matchmaking by default\n * - Room classes must be exposed using `.define()`\n */\nexport abstract class Room<State extends object= any, Metadata= any, UserData = any, AuthData = any> {\n\n /**\n * This property will change on these situations:\n * - The maximum number of allowed clients has been reached (`maxClients`)\n * - You manually locked, or unlocked the room using lock() or `unlock()`.\n *\n * @readonly\n */\n public get locked() {\n return this.#_locked;\n }\n\n public get metadata() {\n return this.listing.metadata;\n }\n\n public listing: RoomCache<Metadata>;\n\n /**\n * Timing events tied to the room instance.\n * Intervals and timeouts are cleared when the room is disposed.\n */\n public clock: Clock = new Clock();\n\n #_roomId: string;\n #_roomName: string;\n #_onLeaveConcurrent: number = 0; // number of onLeave calls in progress\n\n /**\n * Maximum number of clients allowed to connect into the room. When room reaches this limit,\n * it is locked automatically. Unless the room was explicitly locked by you via `lock()` method,\n * the room will be unlocked as soon as a client disconnects from it.\n */\n public maxClients: number = Infinity;\n #_maxClientsReached: boolean = false;\n #_maxClients: number;\n\n /**\n * Automatically dispose the room when last client disconnects.\n *\n * @default true\n */\n public autoDispose: boolean = true;\n #_autoDispose: boolean;\n\n /**\n * Frequency to send the room state to connected clients, in milliseconds.\n *\n * @default 50ms (20fps)\n */\n public patchRate: number = DEFAULT_PATCH_RATE;\n #_patchRate: number;\n #_patchInterval: NodeJS.Timeout;\n\n /**\n * The state instance you provided to `setState()`.\n */\n public state: State;\n #_state: State;\n\n /**\n * The presence instance. Check Presence API for more details.\n *\n * @see {@link https://docs.colyseus.io/colyseus/server/presence/|Presence API}\n */\n public presence: Presence;\n\n /**\n * The array of connected clients.\n *\n * @see {@link https://docs.colyseus.io/colyseus/server/room/#client|Client instance}\n */\n public clients: ClientArray<UserData, AuthData> = new ClientArray();\n\n /** @internal */\n public _events = new EventEmitter();\n\n // seat reservation & reconnection\n protected seatReservationTime: number = DEFAULT_SEAT_RESERVATION_TIME;\n protected reservedSeats: { [sessionId: string]: [any, any, boolean?, boolean?] } = {};\n protected reservedSeatTimeouts: { [sessionId: string]: NodeJS.Timeout } = {};\n\n protected _reconnections: { [reconnectionToken: string]: [string, Deferred] } = {};\n private _reconnectingSessionId = new Map<string, string>();\n\n private onMessageHandlers: {\n [id: string]: {\n callback: (...args: any[]) => void,\n validate?: (data: unknown) => any,\n }\n } = {\n '__no_message_handler': {\n callback: (client: Client, messageType: string, _: unknown) => {\n const errorMessage = `onMessage for \"${messageType}\" not registered.`;\n debugAndPrintError(errorMessage);\n\n if (isDevMode) {\n // send error code to client in development mode\n client.error(ErrorCode.INVALID_PAYLOAD, errorMessage);\n\n } else {\n // immediately close the connection in production\n client.leave(Protocol.WS_CLOSE_WITH_ERROR, errorMessage);\n }\n }\n }\n };\n\n private _serializer: Serializer<State> = noneSerializer;\n private _afterNextPatchQueue: Array<[string | Client, IArguments]> = [];\n\n private _simulationInterval: NodeJS.Timeout;\n\n private _internalState: RoomInternalState = RoomInternalState.CREATING;\n\n private _lockedExplicitly: boolean = false;\n #_locked: boolean = false;\n\n // this timeout prevents rooms that are created by one process, but no client\n // ever had success joining into it on the specified interval.\n private _autoDisposeTimeout: NodeJS.Timeout;\n\n constructor() {\n this._events.once('dispose', () => {\n this._dispose()\n .catch((e) => debugAndPrintError(`onDispose error: ${(e && e.stack || e.message || e || 'promise rejected')}`))\n .finally(() => this._events.emit('disconnect'));\n });\n\n /**\n * If `onUncaughtException` is defined, it will automatically catch exceptions\n */\n if (this.onUncaughtException !== undefined) {\n this.#registerUncaughtExceptionHandlers();\n }\n }\n\n /**\n * This method is called by the MatchMaker before onCreate()\n * @internal\n */\n protected __init() {\n this.#_state = this.state;\n this.#_autoDispose = this.autoDispose;\n this.#_patchRate = this.patchRate;\n this.#_maxClients = this.maxClients;\n\n Object.defineProperties(this, {\n state: {\n enumerable: true,\n get: () => this.#_state,\n set: (newState: State) => {\n if (newState[$changes] !== undefined) {\n this.setSerializer(new SchemaSerializer());\n } else if ('_definition' in newState) {\n throw new Error(\"@colyseus/schema v2 compatibility currently missing (reach out if you need it)\");\n } else if ($changes === undefined) {\n throw new Error(\"Multiple @colyseus/schema versions detected. Please make sure you don't have multiple versions of @colyseus/schema installed.\");\n }\n this._serializer.reset(newState);\n this.#_state = newState;\n },\n },\n\n maxClients: {\n enumerable: true,\n get: () => this.#_maxClients,\n set: (value: number) => {\n this.#_maxClients = value;\n\n if (this._internalState === RoomInternalState.CREATED) {\n const hasReachedMaxClients = this.hasReachedMaxClients();\n\n // unlock room if maxClients has been increased\n if (!this._lockedExplicitly && this.#_maxClientsReached && !hasReachedMaxClients) {\n this.#_maxClientsReached = false;\n this.#_locked = false;\n this.listing.locked = false;\n }\n\n // lock room if maxClients has been decreased\n if (hasReachedMaxClients) {\n this.#_maxClientsReached = true;\n this.#_locked = true;\n this.listing.locked = true;\n }\n\n this.listing.maxClients = value;\n this.listing.save();\n }\n },\n },\n\n autoDispose: {\n enumerable: true,\n get: () => this.#_autoDispose,\n set: (value: boolean) => {\n if (\n value !== this.#_autoDispose &&\n this._internalState !== RoomInternalState.DISPOSING\n ) {\n this.#_autoDispose = value;\n this.resetAutoDisposeTimeout();\n }\n },\n },\n\n patchRate: {\n enumerable: true,\n get: () => this.#_patchRate,\n set: (milliseconds: number) => {\n this.#_patchRate = milliseconds;\n // clear previous interval in case called setPatchRate more than once\n if (this.#_patchInterval) {\n clearInterval(this.#_patchInterval);\n this.#_patchInterval = undefined;\n }\n if (milliseconds !== null && milliseconds !== 0) {\n this.#_patchInterval = setInterval(() => this.broadcastPatch(), milliseconds);\n }\n },\n },\n });\n\n // set patch interval, now with the setter\n this.patchRate = this.#_patchRate;\n\n // set state, now with the setter\n if (this.#_state) {\n this.state = this.#_state;\n }\n\n // set default _autoDisposeTimeout\n this.resetAutoDisposeTimeout(this.seatReservationTime);\n\n this.clock.start();\n }\n\n /**\n * The name of the room you provided as first argument for `gameServer.define()`.\n *\n * @returns roomName string\n */\n public get roomName() { return this.#_roomName; }\n /**\n * Setting the name of the room. Overwriting this property is restricted.\n *\n * @param roomName\n */\n public set roomName(roomName: string) {\n if (this.#_roomName) {\n // prevent user from setting roomName after it has been defined.\n throw new ServerError(ErrorCode.APPLICATION_ERROR, \"'roomName' cannot be overwritten.\");\n }\n this.#_roomName = roomName;\n }\n\n /**\n * A unique, auto-generated, 9-character-long id of the room.\n * You may replace `this.roomId` during `onCreate()`.\n *\n * @returns roomId string\n */\n public get roomId() { return this.#_roomId; }\n\n /**\n * Setting the roomId, is restricted in room lifetime except upon room creation.\n *\n * @param roomId\n * @returns roomId string\n */\n public set roomId(roomId: string) {\n if (this._internalState !== RoomInternalState.CREATING && !isDevMode) {\n // prevent user from setting roomId after room has been created.\n throw new ServerError(ErrorCode.APPLICATION_ERROR, \"'roomId' can only be overridden upon room creation.\");\n }\n this.#_roomId = roomId;\n }\n\n // Optional abstract methods\n public onBeforePatch?(state: State): void | Promise<any>;\n public onCreate?(options: any): void | Promise<any>;\n public onJoin?(client: Client<UserData, AuthData>, options?: any, auth?: AuthData): void | Promise<any>;\n public onLeave?(client: Client<UserData, AuthData>, consented?: boolean): void | Promise<any>;\n public onDispose?(): void | Promise<any>;\n\n /**\n * Define a custom exception handler.\n * If defined, all lifecycle hooks will be wrapped by try/catch, and the exception will be forwarded to this method.\n *\n * These methods will be wrapped by try/catch:\n * - `onMessage`\n * - `onAuth` / `onJoin` / `onLeave` / `onCreate` / `onDispose`\n * - `clock.setTimeout` / `clock.setInterval`\n * - `setSimulationInterval`\n *\n * (Experimental: this feature is subject to change in the future - we're currently getting feedback to improve it)\n */\n public onUncaughtException?(error: RoomException<this>, methodName: 'onCreate' | 'onAuth' | 'onJoin' | 'onLeave' | 'onDispose' | 'onMessage' | 'setSimulationInterval' | 'setInterval' | 'setTimeout'): void;\n\n public onAuth(\n client: Client<UserData, AuthData>,\n options: any,\n context: AuthContext\n ): any | Promise<any> {\n return true;\n }\n\n static async onAuth(\n token: string,\n options: any,\n context: AuthContext\n ): Promise<unknown> {\n return true;\n }\n\n /**\n * This method is called during graceful shutdown of the server process\n * You may override this method to dispose the room in your own way.\n *\n * Once process reaches room count of 0, the room process will be terminated.\n */\n public onBeforeShutdown() {\n this.disconnect(\n (isDevMode)\n ? Protocol.WS_CLOSE_DEVMODE_RESTART\n : Protocol.WS_CLOSE_CONSENTED\n );\n }\n\n /**\n * devMode: When `devMode` is enabled, `onCacheRoom` method is called during\n * graceful shutdown.\n *\n * Implement this method to return custom data to be cached. `onRestoreRoom`\n * will be called with the data returned by `onCacheRoom`\n */\n public onCacheRoom?(): any;\n\n /**\n * devMode: When `devMode` is enabled, `onRestoreRoom` method is called during\n * process startup, with the data returned by the `onCacheRoom` method.\n */\n public onRestoreRoom?(cached?: any): void;\n\n /**\n * Returns whether the sum of connected clients and reserved seats exceeds maximum number of clients.\n *\n * @returns boolean\n */\n public hasReachedMaxClients(): boolean {\n return (\n (this.clients.length + Object.keys(this.reservedSeats).length) >= this.maxClients ||\n this._internalState === RoomInternalState.DISPOSING\n );\n }\n\n /**\n * Set the number of seconds a room can wait for a client to effectively join the room.\n * You should consider how long your `onAuth()` will have to wait for setting a different seat reservation time.\n * The default value is 15 seconds. You may set the `COLYSEUS_SEAT_RESERVATION_TIME`\n * environment variable if you'd like to change the seat reservation time globally.\n *\n * @default 15 seconds\n *\n * @param seconds - number of seconds.\n * @returns The modified Room object.\n */\n public setSeatReservationTime(seconds: number) {\n this.seatReservationTime = seconds;\n return this;\n }\n\n public hasReservedSeat(sessionId: string, reconnectionToken?: string): boolean {\n const reservedSeat = this.reservedSeats[sessionId];\n\n // seat reservation not found / expired\n if (reservedSeat === undefined) {\n return false;\n }\n\n if (reservedSeat[3]) {\n // reconnection\n return (\n reconnectionToken &&\n this._reconnections[reconnectionToken]?.[0] === sessionId &&\n this._reconnectingSessionId.has(sessionId)\n );\n\n } else {\n // seat reservation not consumed\n return reservedSeat[2] === false;\n }\n }\n\n public checkReconnectionToken(reconnectionToken: string) {\n const sessionId = this._reconnections[reconnectionToken]?.[0];\n const reservedSeat = this.reservedSeats[sessionId];\n\n if (reservedSeat && reservedSeat[3]) {\n this._reconnectingSessionId.set(sessionId, reconnectionToken);\n return sessionId;\n\n } else {\n return undefined;\n }\n }\n\n /**\n * (Optional) Set a simulation interval that can change the state of the game.\n * The simulation interval is your game loop.\n *\n * @default 16.6ms (60fps)\n *\n * @param onTickCallback - You can implement your physics or world updates here!\n * This is a good place to update the room state.\n * @param delay - Interval delay on executing `onTickCallback` in milliseconds.\n */\n public setSimulationInterval(onTickCallback?: SimulationCallback, delay: number = DEFAULT_SIMULATION_INTERVAL): void {\n // clear previous interval in case called setSimulationInterval more than once\n if (this._simulationInterval) { clearInterval(this._simulationInterval); }\n\n if (onTickCallback) {\n if (this.onUncaughtException !== undefined) {\n onTickCallback = wrapTryCatch(onTickCallback, this.onUncaughtException.bind(this), SimulationIntervalException, 'setSimulationInterval');\n }\n\n this._simulationInterval = setInterval(() => {\n this.clock.tick();\n onTickCallback(this.clock.deltaTime);\n }, delay);\n }\n }\n\n /**\n * @deprecated Use `.patchRate=` instead.\n */\n public setPatchRate(milliseconds: number | null): void {\n this.patchRate = milliseconds;\n }\n\n /**\n * @deprecated Use `.state =` instead.\n */\n public setState(newState: State) {\n this.state = newState;\n }\n\n public setSerializer(serializer: Serializer<State>) {\n this._serializer = serializer;\n }\n\n public async setMetadata(meta: Partial<Metadata>) {\n if (!this.listing.metadata) {\n this.listing.metadata = meta as Metadata;\n\n } else {\n for (const field in meta) {\n if (!meta.hasOwnProperty(field)) { continue; }\n this.listing.metadata[field] = meta[field];\n }\n\n // `MongooseDriver` workaround: persit metadata mutations\n if ('markModified' in this.listing) {\n (this.listing as any).markModified('metadata');\n }\n }\n\n if (this._internalState === RoomInternalState.CREATED) {\n await this.listing.save();\n }\n }\n\n public async setPrivate(bool: boolean = true) {\n if (this.listing.private === bool) return;\n\n this.listing.private = bool;\n\n if (this._internalState === RoomInternalState.CREATED) {\n await this.listing.save();\n }\n\n this._events.emit('visibility-change', bool);\n }\n\n /**\n * Locking the room will remove it from the pool of available rooms for new clients to connect to.\n */\n public async lock() {\n // rooms locked internally aren't explicit locks.\n this._lockedExplicitly = (arguments[0] === undefined);\n\n // skip if already locked.\n if (this.#_locked) { return; }\n\n this.#_locked = true;\n\n await this.listing.updateOne({\n $set: { locked: this.#_locked },\n });\n\n this._events.emit('lock');\n }\n\n /**\n * Unlocking the room returns it to the pool of available rooms for new clients to connect to.\n */\n public async unlock() {\n // only internal usage passes arguments to this function.\n if (arguments[0] === undefined) {\n this._lockedExplicitly = false;\n }\n\n // skip if already locked\n if (!this.#_locked) { return; }\n\n this.#_locked = false;\n\n await this.listing.updateOne({\n $set: { locked: this.#_locked },\n });\n\n this._events.emit('unlock');\n }\n\n public send(client: Client, type: string | number, message: any, options?: ISendOptions): void;\n public send(client: Client, messageOrType: any, messageOrOptions?: any | ISendOptions, options?: ISendOptions): void {\n logger.warn('DEPRECATION WARNING: use client.send(...) instead of this.send(client, ...)');\n client.send(messageOrType, messageOrOptions, options);\n }\n\n public broadcast(type: string | number, message?: any, options?: IBroadcastOptions) {\n if (options && options.afterNextPatch) {\n delete options.afterNextPatch;\n this._afterNextPatchQueue.push(['broadcast', arguments]);\n return;\n }\n\n this.broadcastMessageType(type, message, options);\n }\n\n /**\n * Broadcast bytes (UInt8Arrays) to a particular room\n */\n public broadcastBytes(type: string | number, message: Uint8Array, options: IBroadcastOptions) {\n if (options && options.afterNextPatch) {\n delete options.afterNextPatch;\n this._afterNextPatchQueue.push(['broadcastBytes', arguments]);\n return;\n }\n\n this.broadcastMessageType(type as string, message, options);\n }\n\n /**\n * Checks whether mutations have occurred in the state, and broadcast them to all connected clients.\n */\n public broadcastPatch() {\n if (this.onBeforePatch) {\n this.onBeforePatch(this.state);\n }\n\n if (!this._simulationInterval) {\n this.clock.tick();\n }\n\n if (!this.state) {\n return false;\n }\n\n const hasChanges = this._serializer.applyPatches(this.clients, this.state);\n\n // broadcast messages enqueued for \"after patch\"\n this._dequeueAfterPatchMessages();\n\n return hasChanges;\n }\n\n public onMessage<T = any>(\n messageType: '*',\n callback: (client: Client<UserData, AuthData>, type: string | number, message: T) => void\n );\n public onMessage<T = any>(\n messageType: string | number,\n callback: (client: Client<UserData, AuthData>, message: T) => void,\n validate?: (message: unknown) => T,\n );\n public onMessage<T = any>(\n messageType: '*' | string | number,\n callback: (...args: any[]) => void,\n validate?: (message: unknown) => T,\n ) {\n this.onMessageHandlers[messageType] = (this.onUncaughtException !== undefined)\n ? { validate, callback: wrapTryCatch(callback, this.onUncaughtException.bind(this), OnMessageException, 'onMessage', false, messageType) }\n : { validate, callback };\n\n\n // returns a method to unbind the callback\n return () => delete this.onMessageHandlers[messageType];\n }\n\n /**\n * Disconnect all connected clients, and then dispose the room.\n *\n * @param closeCode WebSocket close code (default = 4000, which is a \"consented leave\")\n * @returns Promise<void>\n */\n public disconnect(closeCode: number = Protocol.WS_CLOSE_CONSENTED): Promise<any> {\n // skip if already disposing\n if (this._internalState === RoomInternalState.DISPOSING) {\n return Promise.resolve(`disconnect() ignored: room (${this.roomId}) is already disposing.`);\n\n } else if (this._internalState === RoomInternalState.CREATING) {\n throw new Error(\"cannot disconnect during onCreate()\");\n }\n\n this._internalState = RoomInternalState.DISPOSING;\n this.listing.remove();\n\n this.#_autoDispose = true;\n\n const delayedDisconnection = new Promise<void>((resolve) =>\n this._events.once('disconnect', () => resolve()));\n\n // reject pending reconnections\n for (const [_, reconnection] of Object.values(this._reconnections)) {\n reconnection.reject(new Error(\"disconnecting\"));\n }\n\n let numClients = this.clients.length;\n if (numClients > 0) {\n // clients may have `async onLeave`, room will be disposed after they're fulfilled\n while (numClients--) {\n this._forciblyCloseClient(this.clients[numClients] as Client & ClientPrivate, closeCode);\n }\n\n } else {\n // no clients connected, dispose immediately.\n this._events.emit('dispose');\n }\n\n return delayedDisconnection;\n }\n\n public async ['_onJoin'](client: Client & ClientPrivate, authContext: AuthContext) {\n const sessionId = client.sessionId;\n\n // generate unique private reconnection token\n client.reconnectionToken = generateId();\n\n if (this.reservedSeatTimeouts[sessionId]) {\n clearTimeout(this.reservedSeatTimeouts[sessionId]);\n delete this.reservedSeatTimeouts[sessionId];\n }\n\n // clear auto-dispose timeout.\n if (this._autoDisposeTimeout) {\n clearTimeout(this._autoDisposeTimeout);\n this._autoDisposeTimeout = undefined;\n }\n\n // get seat reservation options and clear it\n const [joinOptions, authData, isConsumed, isWaitingReconnection] = this.reservedSeats[sessionId];\n\n //\n // TODO: remove this check on 1.0.0\n // - the seat reservation is used to keep track of number of clients and their pending seats (see `hasReachedMaxClients`)\n // - when we fully migrate to static onAuth(), the seat reservation can be removed immediately here\n // - if async onAuth() is in use, the seat reservation is removed after onAuth() is fulfilled.\n // - mark reservation as \"consumed\"\n //\n if (isConsumed) {\n throw new ServerError(ErrorCode.MATCHMAKE_EXPIRED, \"already consumed\");\n }\n this.reservedSeats[sessionId][2] = true; // flag seat reservation as \"consumed\"\n debugMatchMaking('consuming seat reservation, sessionId: \\'%s\\'', client.sessionId);\n\n // share \"after next patch queue\" reference with every client.\n client._afterNextPatchQueue = this._afterNextPatchQueue;\n\n // add temporary callback to keep track of disconnections during `onJoin`.\n client.ref['onleave'] = (_) => client.state = ClientState.LEAVING;\n client.ref.once('close', client.ref['onleave']);\n\n if (isWaitingReconnection) {\n const previousReconnectionToken = this._reconnectingSessionId.get(sessionId);\n if (previousReconnectionToken) {\n this.clients.push(client);\n //\n // await for reconnection:\n // (end user may customize the reconnection token at this step)\n //\n await this._reconnections[previousReconnectionToken]?.[1].resolve(client);\n\n } else {\n const errorMessage = (process.env.NODE_ENV === 'production')\n ? \"already consumed\" // trick possible fraudsters...\n : \"bad reconnection token\" // ...or developers\n throw new ServerError(ErrorCode.MATCHMAKE_EXPIRED, errorMessage);\n }\n\n } else {\n try {\n if (authData) {\n client.auth = authData;\n\n } else if (this.onAuth !== Room.prototype.onAuth) {\n try {\n client.auth = await this.onAuth(client, joinOptions, authContext);\n\n if (!client.auth) {\n throw new ServerError(ErrorCode.AUTH_FAILED, 'onAuth failed');\n }\n\n } catch (e) {\n // remove seat reservation\n delete this.reservedSeats[sessionId];\n await this._decrementClientCount();\n throw e;\n }\n }\n\n //\n // On async onAuth, client may have been disconnected.\n //\n if (client.state === ClientState.LEAVING) {\n throw new ServerError(Protocol.WS_CLOSE_GOING_AWAY, 'already disconnected');\n }\n\n this.clients.push(client);\n\n //\n // Flag sessionId as non-enumarable so hasReachedMaxClients() doesn't count it\n // (https://github.com/colyseus/colyseus/issues/726)\n //\n Object.defineProperty(this.reservedSeats, sessionId, {\n value: this.reservedSeats[sessionId],\n enumerable: false,\n });\n\n if (this.onJoin) {\n await this.onJoin(client, joinOptions, client.auth);\n }\n\n // @ts-ignore: client left during `onJoin`, call _onLeave immediately.\n if (client.state === ClientState.LEAVING) {\n throw new Error(\"early_leave\");\n\n } else {\n // remove seat reservation\n delete this.reservedSeats[sessionId];\n\n // emit 'join' to room handler\n this._events.emit('join', client);\n }\n\n } catch (e) {\n await this._onLeave(client, Protocol.WS_CLOSE_GOING_AWAY);\n\n // remove seat reservation\n delete this.reservedSeats[sessionId];\n\n // make sure an error code is provided.\n if (!e.code) {\n e.code = ErrorCode.APPLICATION_ERROR;\n }\n\n throw e;\n }\n }\n\n // state might already be ClientState.LEAVING here\n if (client.state === ClientState.JOINING) {\n client.ref.removeListener('close', client.ref['onleave']);\n\n // only bind _onLeave after onJoin has been successful\n client.ref['onleave'] = this._onLeave.bind(this, client);\n client.ref.once('close', client.ref['onleave']);\n\n // allow client to send messages after onJoin has succeeded.\n client.ref.on('message', this._onMessage.bind(this, client));\n\n // confirm room id that matches the room name requested to join\n client.raw(getMessageBytes[Protocol.JOIN_ROOM](\n client.reconnectionToken,\n this._serializer.id,\n this._serializer.handshake && this._serializer.handshake(),\n ));\n }\n }\n\n /**\n * Allow the specified client to reconnect into the room. Must be used inside `onLeave()` method.\n * If seconds is provided, the reconnection is going to be cancelled after the provided amount of seconds.\n *\n * @param previousClient - The client which is to be waiting until re-connection happens.\n * @param seconds - Timeout period on re-connection in seconds.\n *\n * @returns Deferred<Client> - The differed is a promise like type.\n * This type can forcibly reject the promise by calling `.reject()`.\n */\n public allowReconnection(previousClient: Client, seconds: number | \"manual\"): Deferred<Client> {\n //\n // Return rejected promise if client has never fully JOINED.\n //\n // (having `_enqueuedMessages !== undefined` means that the client has never been at \"ClientState.JOINED\" state)\n //\n if ((previousClient as unknown as ClientPrivate)._enqueuedMessages !== undefined) {\n // @ts-ignore\n return Promise.reject(new Error(\"not joined\"));\n }\n\n if (seconds === undefined) { // TODO: remove this check\n console.warn(\"DEPRECATED: allowReconnection() requires a second argument. Using \\\"manual\\\" mode.\");\n seconds = \"manual\";\n }\n\n if (seconds === \"manual\") {\n seconds = Infinity;\n }\n\n if (this._internalState === RoomInternalState.DISPOSING) {\n // @ts-ignore\n return Promise.reject(new Error(\"disposing\"));\n }\n\n const sessionId = previousClient.sessionId;\n const reconnectionToken = previousClient.reconnectionToken;\n\n this._reserveSeat(sessionId, true, previousClient.auth, seconds, true);\n\n // keep reconnection reference in case the user reconnects into this room.\n const reconnection = new Deferred<Client & ClientPrivate>();\n this._reconnections[reconnectionToken] = [sessionId, reconnection];\n\n if (seconds !== Infinity) {\n // expire seat reservation after timeout\n this.reservedSeatTimeouts[sessionId] = setTimeout(() =>\n reconnection.reject(false), seconds * 1000);\n }\n\n const cleanup = () => {\n delete this._reconnections[reconnectionToken];\n delete this.reservedSeats[sessionId];\n delete this.reservedSeatTimeouts[sessionId];\n this._reconnectingSessionId.delete(sessionId);\n };\n\n reconnection.\n then((newClient) => {\n newClient.auth = previousClient.auth;\n newClient.userData = previousClient.userData;\n previousClient.ref = newClient.ref; // swap \"ref\" for convenience\n previousClient.state = ClientState.RECONNECTED;\n clearTimeout(this.reservedSeatTimeouts[sessionId]);\n cleanup();\n }).\n catch(() => {\n cleanup();\n this.resetAutoDisposeTimeout();\n });\n\n return reconnection;\n }\n\n protected resetAutoDisposeTimeout(timeoutInSeconds: number = 1) {\n clearTimeout(this._autoDisposeTimeout);\n\n if (!this.#_autoDispose) {\n return;\n }\n\n this._autoDisposeTimeout = setTimeout(() => {\n this._autoDisposeTimeout = undefined;\n this._disposeIfEmpty();\n }, timeoutInSeconds * 1000);\n }\n\n private broadcastMessageType(type: number | string, message?: any | Uint8Array, options: IBroadcastOptions = {}) {\n debugMessage(\"broadcast: %O\", message);\n\n const encodedMessage = (message instanceof Uint8Array)\n ? getMessageBytes.raw(Protocol.ROOM_DATA_BYTES, type, undefined, message)\n : getMessageBytes.raw(Protocol.ROOM_DATA, type, message)\n\n const except = (typeof (options.except) !== \"undefined\")\n ? Array.isArray(options.except)\n ? options.except\n : [options.except]\n : undefined;\n\n let numClients = this.clients.length;\n while (numClients--) {\n const client = this.clients[numClients];\n\n if (!except || !except.includes(client)) {\n client.enqueueRaw(encodedMessage);\n }\n }\n }\n\n protected sendFullState(client: Client): void {\n client.raw(this._serializer.getFullState(client));\n }\n\n protected _dequeueAfterPatchMessages() {\n const length = this._afterNextPatchQueue.length;\n\n if (length > 0) {\n for (let i = 0; i < length; i++) {\n const [target, args] = this._afterNextPatchQueue[i];\n\n if (target === \"broadcast\") {\n this.broadcast.apply(this, args);\n\n } else {\n (target as Client).raw.apply(target, args);\n }\n }\n\n // new messages may have been added in the meantime,\n // let's splice the ones that have been processed\n this._afterNextPatchQueue.splice(0, length);\n }\n }\n\n protected async _reserveSeat(\n sessionId: string,\n joinOptions: any = true,\n authData: any = undefined,\n seconds: number = this.seatReservationTime,\n allowReconnection: boolean = false,\n devModeReconnection?: boolean,\n ) {\n if (!allowReconnection && this.hasReachedMaxClients()) {\n return false;\n }\n\n this.reservedSeats[sessionId] = [joinOptions, authData, false, allowReconnection];\n\n if (!allowReconnection) {\n await this._incrementClientCount();\n\n this.reservedSeatTimeouts[sessionId] = setTimeout(async () => {\n delete this.reservedSeats[sessionId];\n delete this.reservedSeatTimeouts[sessionId];\n await this._decrementClientCount();\n }, seconds * 1000);\n\n this.resetAutoDisposeTimeout(seconds);\n }\n\n //\n // isDevMode workaround to allow players to reconnect on devMode\n //\n if (devModeReconnection) {\n this._reconnectingSessionId.set(sessionId, sessionId);\n }\n\n return true;\n }\n\n protected _disposeIfEmpty() {\n const willDispose = (\n this.#_onLeaveConcurrent === 0 && // no \"onLeave\" calls in progress\n this.#_autoDispose &&\n this._autoDisposeTimeout === undefined &&\n this.clients.length === 0 &&\n Object.keys(this.reservedSeats).length === 0\n );\n\n if (willDispose) {\n this._events.emit('dispose');\n }\n\n return willDispose;\n }\n\n protected async _dispose(): Promise<any> {\n this._internalState = RoomInternalState.DISPOSING;\n\n this.listing.remove();\n\n let userReturnData;\n if (this.onDispose) {\n userReturnData = this.onDispose();\n }\n\n if (this.#_patchInterval) {\n clearInterval(this.#_patchInterval);\n this.#_patchInterval = undefined;\n }\n\n if (this._simulationInterval) {\n clearInterval(this._simulationInterval);\n this._simulationInterval = undefined;\n }\n\n if (this._autoDisposeTimeout) {\n clearInterval(this._autoDisposeTimeout);\n this._autoDisposeTimeout = undefined;\n }\n\n // clear all timeouts/intervals + force to stop ticking\n this.clock.clear();\n this.clock.stop();\n\n return await (userReturnData || Promise.resolve());\n }\n\n protected _onMessage(client: Client & ClientPrivate, buffer: Buffer) {\n // skip if client is on LEAVING state.\n if (client.state === ClientState.LEAVING) { return; }\n\n const it: Iterator = { offset: 1 };\n const code = buffer[0];\n\n if (!buffer) {\n debugAndPrintError(`${this.roomName} (${this.roomId}), couldn't decode message: ${buffer}`);\n return;\n }\n\n if (code === Protocol.ROOM_DATA) {\n const messageType = (decode.stringCheck(buffer, it))\n ? decode.string(buffer, it)\n : decode.number(buffer, it);\n const messageTypeHandler = this.onMessageHandlers[messageType];\n\n let message;\n try {\n message = (buffer.byteLength > it.offset)\n ? unpack(buffer.subarray(it.offset, buffer.byteLength))\n : undefined;\n debugMessage(\"received: '%s' -> %j\", messageType, message);\n\n // custom message validation\n if (messageTypeHandler?.validate !== undefined) {\n message = messageTypeHandler.validate(message);\n }\n\n } catch (e) {\n debugAndPrintError(e);\n client.leave(Protocol.WS_CLOSE_WITH_ERROR);\n return;\n }\n\n if (messageTypeHandler) {\n messageTypeHandler.callback(client, message);\n\n } else {\n (this.onMessageHandlers['*'] || this.onMessageHandlers['__no_message_handler']).callback(client, messageType, message);\n }\n\n } else if (code === Protocol.ROOM_DATA_BYTES) {\n const messageType = (decode.stringCheck(buffer, it))\n ? decode.string(buffer, it)\n : decode.number(buffer, it);\n const messageTypeHandler = this.onMessageHandlers[messageType];\n\n let message = buffer.subarray(it.offset, buffer.byteLength);\n debugMessage(\"received: '%s' -> %j\", messageType, message);\n\n // custom message validation\n if (messageTypeHandler?.validate !== undefined) {\n message = messageTypeHandler.validate(message);\n }\n\n if (messageTypeHandler) {\n messageTypeHandler.callback(client, message);\n\n } else {\n (this.onMessageHandlers['*'] || this.onMessageHandlers['__no_message_handler']).callback(client, messageType, message);\n }\n\n } else if (code === Protocol.JOIN_ROOM && client.state === ClientState.JOINING) {\n // join room has been acknowledged by the client\n client.state = ClientState.JOINED;\n client._joinedAt = this.clock.elapsedTime;\n\n // send current state when new client joins the room\n if (this.state) {\n this.sendFullState(client);\n }\n\n // dequeue messages sent before client has joined effectively (on user-defined `onJoin`)\n if (client._enqueuedMessages.length > 0) {\n client._enqueuedMessages.forEach((enqueued) => client.raw(enqueued));\n }\n delete client._enqueuedMessages;\n\n } else if (code === Protocol.LEAVE_ROOM) {\n this._forciblyCloseClient(client, Protocol.WS_CLOSE_CONSENTED);\n }\n\n }\n\n protected _forciblyCloseClient(client: Client & ClientPrivate, closeCode: number) {\n // stop receiving messages from this client\n client.ref.removeAllListeners('message');\n\n // prevent \"onLeave\" from being called twice if player asks to leave\n client.ref.removeListener('close', client.ref['onleave']);\n\n // only effectively close connection when \"onLeave\" is fulfilled\n this._onLeave(client, closeCode).then(() => client.leave(closeCode));\n }\n\n protected async _onLeave(client: Client, code?: number): Promise<any> {\n debugMatchMaking('onLeave, sessionId: \\'%s\\'', client.sessionId);\n\n // call 'onLeave' method only if the client has been successfully accepted.\n client.state = ClientState.LEAVING;\n\n if (!this.clients.delete(client)) {\n // skip if client already left the room\n return;\n }\n\n if (this.onLeave) {\n try {\n this.#_onLeaveConcurrent++;\n await this.onLeave(client, (code === Protocol.WS_CLOSE_CONSENTED));\n\n } catch (e) {\n debugAndPrintError(`onLeave error: ${(e && e.message || e || 'promise rejected')}`);\n\n } finally {\n this.#_onLeaveConcurrent--;\n }\n }\n\n // check for manual \"reconnection\" flow\n if (this._reconnections[client.reconnectionToken]) {\n this._reconnections[client.reconnectionToken][1].catch(async () => {\n await this._onAfterLeave(client);\n });\n\n // @ts-ignore (client.state may be modified at onLeave())\n } else if (client.state !== ClientState.RECONNECTED) {\n await this._onAfterLeave(client);\n }\n }\n\n protected async _onAfterLeave(client: Client) {\n // try to dispose immediately if client reconnection isn't set up.\n const willDispose = await this._decrementClientCount();\n\n // trigger 'leave' only if seat reservation has been fully consumed\n if (this.reservedSeats[client.sessionId] === undefined) {\n this._events.emit('leave', client, willDispose);\n }\n\n }\n\n protected async _incrementClientCount() {\n // lock automatically when maxClients is reached\n if (!this.#_locked && this.hasReachedMaxClients()) {\n this.#_maxClientsReached = true;\n this.lock.call(this, true);\n }\n\n await this.listing.updateOne({\n $inc: { clients: 1 },\n $set: { locked: this.#_locked },\n });\n }\n\n protected async _decrementClientCount() {\n const willDispose = this._disposeIfEmpty();\n\n if (this._internalState === RoomInternalState.DISPOSING) {\n return true;\n }\n\n // unlock if room is available for new connections\n if (!willDispose) {\n if (this.#_maxClientsReached && !this._lockedExplicitly) {\n this.#_maxClientsReached = false;\n this.unlock.call(this, true);\n }\n\n // update room listing cache\n await this.listing.updateOne({\n $inc: { clients: -1 },\n $set: { locked: this.#_locked },\n });\n }\n\n return willDispose;\n }\n\n #registerUncaughtExceptionHandlers() {\n const onUncaughtException = this.onUncaughtException.bind(this);\n const originalSetTimeout = this.clock.setTimeout;\n this.clock.setTimeout = (cb, timeout, ...args) => {\n return originalSetTimeout.call(this.clock, wrapTryCatch(cb, onUncaughtException, TimedEventException, 'setTimeout'), timeout, ...args);\n };\n\n const originalSetInterval = this.clock.setInterval;\n this.clock.setInterval = (cb, timeout, ...args) => {\n return originalSetInterval.call(this.clock, wrapTryCatch(cb, onUncaughtException, TimedEventException, 'setInterval'), timeout, ...args);\n };\n\n if (this.onCreate !== undefined) {\n this.onCreate = wrapTryCatch(this.onCreate.bind(this), onUncaughtException, OnCreateException, 'onCreate', true);\n }\n\n if (this.onAuth !== undefined) {\n this.onAuth = wrapTryCatch(this.onAuth.bind(this), onUncaughtException, OnAuthException, 'onAuth', true);\n }\n\n if (this.onJoin !== undefined) {\n this.onJoin = wrapTryCatch(this.onJoin.bind(this), onUncaughtException, OnJoinException, 'onJoin', true);\n }\n\n if (this.onLeave !== undefined) {\n this.onLeave = wrapTryCatch(this.onLeave.bind(this), onUncaughtException, OnLeaveException, 'onLeave', true);\n }\n\n if (this.onDispose !== undefined) {\n this.onDispose = wrapTryCatch(this.onDispose.bind(this), onUncaughtException, OnDisposeException, 'onDispose');\n }\n }\n\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAuB;AACvB,oBAA2C;AAE3C,mBAAkB;AAClB,oBAA6B;AAC7B,oBAAuB;AAIvB,4BAA+B;AAC/B,8BAAiC;AAGjC,sBAAqD;AACrD,mBAAmD;AACnD,qBAA0B;AAE1B,mBAAmE;AAEnE,yBAA4B;AAC5B,uBAA2F;AAC3F,4BAA+L;AAE/L,MAAM,qBAAqB,MAAO;AAClC,MAAM,8BAA8B,MAAO;AAC3C,MAAM,iBAAiB,IAAI,qCAAe;AAEnC,MAAM,gCAAgC,OAAO,QAAQ,IAAI,kCAAkC,EAAE;AAQ7F,IAAK,oBAAL,kBAAKA,uBAAL;AACL,EAAAA,sCAAA,cAAW,KAAX;AACA,EAAAA,sCAAA,aAAU,KAAV;AACA,EAAAA,sCAAA,eAAY,KAAZ;AAHU,SAAAA;AAAA,GAAA;AAgBL,MAAe,KAA+E;AAAA,EA2HnG,cAAc;AApGd;AAAA;AAAA;AAAA;AAAA,SAAO,QAAe,IAAI,aAAAC,QA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U,2BAAa,KAAK,QAAQ,KAAK,IAAI,GAAG,qBAAqB,wCAAkB,WAAW,IAAI;AAAA,IAC7G;AAEA,QAAI,KAAK,cAAc,QAAW;AAChC,WAAK,gBAAY,2BAAa,KAAK,UAAU,KAAK,IAAI,GAAG,qBAAqB,0CAAoB,WAAW;AAAA,IAC/G;AAAA,EACF;AAEF;",
|
|
6
6
|
"names": ["RoomInternalState", "Clock"]
|
|
7
7
|
}
|
package/build/Room.mjs
CHANGED
|
@@ -38,6 +38,7 @@ var Room = class _Room {
|
|
|
38
38
|
* the room will be unlocked as soon as a client disconnects from it.
|
|
39
39
|
*/
|
|
40
40
|
this.maxClients = Infinity;
|
|
41
|
+
this.#_maxClientsReached = false;
|
|
41
42
|
/**
|
|
42
43
|
* Automatically dispose the room when last client disconnects.
|
|
43
44
|
*
|
|
@@ -80,9 +81,8 @@ var Room = class _Room {
|
|
|
80
81
|
this._serializer = noneSerializer;
|
|
81
82
|
this._afterNextPatchQueue = [];
|
|
82
83
|
this._internalState = 0 /* CREATING */;
|
|
83
|
-
this._locked = false;
|
|
84
84
|
this._lockedExplicitly = false;
|
|
85
|
-
this
|
|
85
|
+
this.#_locked = false;
|
|
86
86
|
this._events.once("dispose", () => {
|
|
87
87
|
this._dispose().catch((e) => debugAndPrintError(`onDispose error: ${e && e.stack || e.message || e || "promise rejected"}`)).finally(() => this._events.emit("disconnect"));
|
|
88
88
|
});
|
|
@@ -98,7 +98,7 @@ var Room = class _Room {
|
|
|
98
98
|
* @readonly
|
|
99
99
|
*/
|
|
100
100
|
get locked() {
|
|
101
|
-
return this
|
|
101
|
+
return this.#_locked;
|
|
102
102
|
}
|
|
103
103
|
get metadata() {
|
|
104
104
|
return this.listing.metadata;
|
|
@@ -106,20 +106,60 @@ var Room = class _Room {
|
|
|
106
106
|
#_roomId;
|
|
107
107
|
#_roomName;
|
|
108
108
|
#_onLeaveConcurrent;
|
|
109
|
+
#_maxClientsReached;
|
|
110
|
+
#_maxClients;
|
|
109
111
|
#_autoDispose;
|
|
110
112
|
#_patchRate;
|
|
111
113
|
#_patchInterval;
|
|
114
|
+
#_state;
|
|
115
|
+
#_locked;
|
|
112
116
|
/**
|
|
113
117
|
* This method is called by the MatchMaker before onCreate()
|
|
114
118
|
* @internal
|
|
115
119
|
*/
|
|
116
120
|
__init() {
|
|
117
|
-
|
|
118
|
-
this.setState(this.state);
|
|
119
|
-
}
|
|
121
|
+
this.#_state = this.state;
|
|
120
122
|
this.#_autoDispose = this.autoDispose;
|
|
121
123
|
this.#_patchRate = this.patchRate;
|
|
124
|
+
this.#_maxClients = this.maxClients;
|
|
122
125
|
Object.defineProperties(this, {
|
|
126
|
+
state: {
|
|
127
|
+
enumerable: true,
|
|
128
|
+
get: () => this.#_state,
|
|
129
|
+
set: (newState) => {
|
|
130
|
+
if (newState[$changes] !== void 0) {
|
|
131
|
+
this.setSerializer(new SchemaSerializer());
|
|
132
|
+
} else if ("_definition" in newState) {
|
|
133
|
+
throw new Error("@colyseus/schema v2 compatibility currently missing (reach out if you need it)");
|
|
134
|
+
} else if ($changes === void 0) {
|
|
135
|
+
throw new Error("Multiple @colyseus/schema versions detected. Please make sure you don't have multiple versions of @colyseus/schema installed.");
|
|
136
|
+
}
|
|
137
|
+
this._serializer.reset(newState);
|
|
138
|
+
this.#_state = newState;
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
maxClients: {
|
|
142
|
+
enumerable: true,
|
|
143
|
+
get: () => this.#_maxClients,
|
|
144
|
+
set: (value) => {
|
|
145
|
+
this.#_maxClients = value;
|
|
146
|
+
if (this._internalState === 1 /* CREATED */) {
|
|
147
|
+
const hasReachedMaxClients = this.hasReachedMaxClients();
|
|
148
|
+
if (!this._lockedExplicitly && this.#_maxClientsReached && !hasReachedMaxClients) {
|
|
149
|
+
this.#_maxClientsReached = false;
|
|
150
|
+
this.#_locked = false;
|
|
151
|
+
this.listing.locked = false;
|
|
152
|
+
}
|
|
153
|
+
if (hasReachedMaxClients) {
|
|
154
|
+
this.#_maxClientsReached = true;
|
|
155
|
+
this.#_locked = true;
|
|
156
|
+
this.listing.locked = true;
|
|
157
|
+
}
|
|
158
|
+
this.listing.maxClients = value;
|
|
159
|
+
this.listing.save();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
},
|
|
123
163
|
autoDispose: {
|
|
124
164
|
enumerable: true,
|
|
125
165
|
get: () => this.#_autoDispose,
|
|
@@ -146,7 +186,11 @@ var Room = class _Room {
|
|
|
146
186
|
}
|
|
147
187
|
});
|
|
148
188
|
this.patchRate = this.#_patchRate;
|
|
189
|
+
if (this.#_state) {
|
|
190
|
+
this.state = this.#_state;
|
|
191
|
+
}
|
|
149
192
|
this.resetAutoDisposeTimeout(this.seatReservationTime);
|
|
193
|
+
this.clock.start();
|
|
150
194
|
}
|
|
151
195
|
/**
|
|
152
196
|
* The name of the room you provided as first argument for `gameServer.define()`.
|
|
@@ -279,14 +323,10 @@ var Room = class _Room {
|
|
|
279
323
|
setPatchRate(milliseconds) {
|
|
280
324
|
this.patchRate = milliseconds;
|
|
281
325
|
}
|
|
326
|
+
/**
|
|
327
|
+
* @deprecated Use `.state =` instead.
|
|
328
|
+
*/
|
|
282
329
|
setState(newState) {
|
|
283
|
-
this.clock.start();
|
|
284
|
-
if (newState[$changes] !== void 0) {
|
|
285
|
-
this.setSerializer(new SchemaSerializer());
|
|
286
|
-
} else if ($changes === void 0) {
|
|
287
|
-
throw new Error("@colyseus/schema v2 compatibility currently missing (reach out if you need it)");
|
|
288
|
-
}
|
|
289
|
-
this._serializer.reset(newState);
|
|
290
330
|
this.state = newState;
|
|
291
331
|
}
|
|
292
332
|
setSerializer(serializer) {
|
|
@@ -323,12 +363,12 @@ var Room = class _Room {
|
|
|
323
363
|
*/
|
|
324
364
|
async lock() {
|
|
325
365
|
this._lockedExplicitly = arguments[0] === void 0;
|
|
326
|
-
if (this
|
|
366
|
+
if (this.#_locked) {
|
|
327
367
|
return;
|
|
328
368
|
}
|
|
329
|
-
this
|
|
369
|
+
this.#_locked = true;
|
|
330
370
|
await this.listing.updateOne({
|
|
331
|
-
$set: { locked: this
|
|
371
|
+
$set: { locked: this.#_locked }
|
|
332
372
|
});
|
|
333
373
|
this._events.emit("lock");
|
|
334
374
|
}
|
|
@@ -339,12 +379,12 @@ var Room = class _Room {
|
|
|
339
379
|
if (arguments[0] === void 0) {
|
|
340
380
|
this._lockedExplicitly = false;
|
|
341
381
|
}
|
|
342
|
-
if (!this
|
|
382
|
+
if (!this.#_locked) {
|
|
343
383
|
return;
|
|
344
384
|
}
|
|
345
|
-
this
|
|
385
|
+
this.#_locked = false;
|
|
346
386
|
await this.listing.updateOne({
|
|
347
|
-
$set: { locked: this
|
|
387
|
+
$set: { locked: this.#_locked }
|
|
348
388
|
});
|
|
349
389
|
this._events.emit("unlock");
|
|
350
390
|
}
|
|
@@ -737,13 +777,13 @@ var Room = class _Room {
|
|
|
737
777
|
}
|
|
738
778
|
}
|
|
739
779
|
async _incrementClientCount() {
|
|
740
|
-
if (!this
|
|
741
|
-
this
|
|
780
|
+
if (!this.#_locked && this.hasReachedMaxClients()) {
|
|
781
|
+
this.#_maxClientsReached = true;
|
|
742
782
|
this.lock.call(this, true);
|
|
743
783
|
}
|
|
744
784
|
await this.listing.updateOne({
|
|
745
785
|
$inc: { clients: 1 },
|
|
746
|
-
$set: { locked: this
|
|
786
|
+
$set: { locked: this.#_locked }
|
|
747
787
|
});
|
|
748
788
|
}
|
|
749
789
|
async _decrementClientCount() {
|
|
@@ -752,13 +792,13 @@ var Room = class _Room {
|
|
|
752
792
|
return true;
|
|
753
793
|
}
|
|
754
794
|
if (!willDispose) {
|
|
755
|
-
if (this
|
|
756
|
-
this
|
|
795
|
+
if (this.#_maxClientsReached && !this._lockedExplicitly) {
|
|
796
|
+
this.#_maxClientsReached = false;
|
|
757
797
|
this.unlock.call(this, true);
|
|
758
798
|
}
|
|
759
799
|
await this.listing.updateOne({
|
|
760
800
|
$inc: { clients: -1 },
|
|
761
|
-
$set: { locked: this
|
|
801
|
+
$set: { locked: this.#_locked }
|
|
762
802
|
});
|
|
763
803
|
}
|
|
764
804
|
return willDispose;
|
package/build/Room.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/Room.ts"],
|
|
4
|
-
"sourcesContent": ["import { unpack } from '@colyseus/msgpackr';\nimport { decode, Iterator, $changes } from '@colyseus/schema';\n\nimport Clock from '@colyseus/timer';\nimport { EventEmitter } from 'events';\nimport { logger } from './Logger.js';\n\nimport { Presence } from './presence/Presence.js';\n\nimport { NoneSerializer } from './serializer/NoneSerializer.js';\nimport { SchemaSerializer } from './serializer/SchemaSerializer.js';\nimport { Serializer } from './serializer/Serializer.js';\n\nimport { ErrorCode, getMessageBytes, Protocol } from './Protocol';\nimport { Deferred, generateId, wrapTryCatch } from './utils/Utils.js';\nimport { isDevMode } from './utils/DevMode.js';\n\nimport { debugAndPrintError, debugMatchMaking, debugMessage } from './Debug.js';\nimport { RoomCache } from './matchmaker/driver/api.js';\nimport { ServerError } from './errors/ServerError.js';\nimport { AuthContext, Client, ClientPrivate, ClientArray, ClientState, ISendOptions } from './Transport';\nimport { OnAuthException, OnCreateException, OnDisposeException, OnJoinException, OnLeaveException, OnMessageException, RoomException, SimulationIntervalException, TimedEventException } from './errors/RoomExceptions.js';\n\nconst DEFAULT_PATCH_RATE = 1000 / 20; // 20fps (50ms)\nconst DEFAULT_SIMULATION_INTERVAL = 1000 / 60; // 60fps (16.66ms)\nconst noneSerializer = new NoneSerializer();\n\nexport const DEFAULT_SEAT_RESERVATION_TIME = Number(process.env.COLYSEUS_SEAT_RESERVATION_TIME || 15);\n\nexport type SimulationCallback = (deltaTime: number) => void;\n\nexport interface IBroadcastOptions extends ISendOptions {\n except?: Client | Client[];\n}\n\nexport enum RoomInternalState {\n CREATING = 0,\n CREATED = 1,\n DISPOSING = 2,\n}\n\nexport type ExtractUserData<T> = T extends ClientArray<infer U> ? U : never;\nexport type ExtractAuthData<T> = T extends ClientArray<infer _, infer U> ? U : never;\n\n/**\n * A Room class is meant to implement a game session, and/or serve as the communication channel\n * between a group of clients.\n *\n * - Rooms are created on demand during matchmaking by default\n * - Room classes must be exposed using `.define()`\n */\nexport abstract class Room<State extends object= any, Metadata= any, UserData = any, AuthData = any> {\n\n /**\n * This property will change on these situations:\n * - The maximum number of allowed clients has been reached (`maxClients`)\n * - You manually locked, or unlocked the room using lock() or `unlock()`.\n *\n * @readonly\n */\n public get locked() {\n return this._locked;\n }\n\n public get metadata() {\n return this.listing.metadata;\n }\n\n public listing: RoomCache<Metadata>;\n\n /**\n * Timing events tied to the room instance.\n * Intervals and timeouts are cleared when the room is disposed.\n */\n public clock: Clock = new Clock();\n\n #_roomId: string;\n #_roomName: string;\n #_onLeaveConcurrent: number = 0; // number of onLeave calls in progress\n\n /**\n * Maximum number of clients allowed to connect into the room. When room reaches this limit,\n * it is locked automatically. Unless the room was explicitly locked by you via `lock()` method,\n * the room will be unlocked as soon as a client disconnects from it.\n */\n public maxClients: number = Infinity;\n\n /**\n * Automatically dispose the room when last client disconnects.\n *\n * @default true\n */\n public autoDispose: boolean = true;\n #_autoDispose: boolean;\n\n /**\n * Frequency to send the room state to connected clients, in milliseconds.\n *\n * @default 50ms (20fps)\n */\n public patchRate: number = DEFAULT_PATCH_RATE;\n #_patchRate: number;\n #_patchInterval: NodeJS.Timeout;\n\n /**\n * The state instance you provided to `setState()`.\n */\n public state: State;\n\n /**\n * The presence instance. Check Presence API for more details.\n *\n * @see {@link https://docs.colyseus.io/colyseus/server/presence/|Presence API}\n */\n public presence: Presence;\n\n /**\n * The array of connected clients.\n *\n * @see {@link https://docs.colyseus.io/colyseus/server/room/#client|Client instance}\n */\n public clients: ClientArray<UserData, AuthData> = new ClientArray();\n\n /** @internal */\n public _events = new EventEmitter();\n\n // seat reservation & reconnection\n protected seatReservationTime: number = DEFAULT_SEAT_RESERVATION_TIME;\n protected reservedSeats: { [sessionId: string]: [any, any, boolean?, boolean?] } = {};\n protected reservedSeatTimeouts: { [sessionId: string]: NodeJS.Timeout } = {};\n\n protected _reconnections: { [reconnectionToken: string]: [string, Deferred] } = {};\n private _reconnectingSessionId = new Map<string, string>();\n\n private onMessageHandlers: {\n [id: string]: {\n callback: (...args: any[]) => void,\n validate?: (data: unknown) => any,\n }\n } = {\n '__no_message_handler': {\n callback: (client: Client, messageType: string, _: unknown) => {\n const errorMessage = `onMessage for \"${messageType}\" not registered.`;\n debugAndPrintError(errorMessage);\n\n if (isDevMode) {\n // send error code to client in development mode\n client.error(ErrorCode.INVALID_PAYLOAD, errorMessage);\n\n } else {\n // immediately close the connection in production\n client.leave(Protocol.WS_CLOSE_WITH_ERROR, errorMessage);\n }\n }\n }\n };\n\n private _serializer: Serializer<State> = noneSerializer;\n private _afterNextPatchQueue: Array<[string | Client, IArguments]> = [];\n\n private _simulationInterval: NodeJS.Timeout;\n\n private _internalState: RoomInternalState = RoomInternalState.CREATING;\n private _locked: boolean = false;\n private _lockedExplicitly: boolean = false;\n private _maxClientsReached: boolean = false;\n\n // this timeout prevents rooms that are created by one process, but no client\n // ever had success joining into it on the specified interval.\n private _autoDisposeTimeout: NodeJS.Timeout;\n\n constructor() {\n this._events.once('dispose', () => {\n this._dispose()\n .catch((e) => debugAndPrintError(`onDispose error: ${(e && e.stack || e.message || e || 'promise rejected')}`))\n .finally(() => this._events.emit('disconnect'));\n });\n\n /**\n * If `onUncaughtException` is defined, it will automatically catch exceptions\n */\n if (this.onUncaughtException !== undefined) {\n this.#registerUncaughtExceptionHandlers();\n }\n }\n\n /**\n * This method is called by the MatchMaker before onCreate()\n * @internal\n */\n protected __init() {\n if (this.state) {\n this.setState(this.state);\n }\n\n this.#_autoDispose = this.autoDispose;\n this.#_patchRate = this.patchRate;\n\n Object.defineProperties(this, {\n autoDispose: {\n enumerable: true,\n get: () => this.#_autoDispose,\n set: (value: boolean) => {\n if (\n value !== this.#_autoDispose &&\n this._internalState !== RoomInternalState.DISPOSING\n ) {\n this.#_autoDispose = value;\n this.resetAutoDisposeTimeout();\n }\n },\n },\n\n patchRate: {\n enumerable: true,\n get: () => this.#_patchRate,\n set: (milliseconds: number) => {\n this.#_patchRate = milliseconds;\n // clear previous interval in case called setPatchRate more than once\n if (this.#_patchInterval) {\n clearInterval(this.#_patchInterval);\n this.#_patchInterval = undefined;\n }\n if (milliseconds !== null && milliseconds !== 0) {\n this.#_patchInterval = setInterval(() => this.broadcastPatch(), milliseconds);\n }\n },\n },\n });\n\n // set patch interval, now with the setter\n this.patchRate = this.#_patchRate;\n\n // set default _autoDisposeTimeout\n this.resetAutoDisposeTimeout(this.seatReservationTime);\n }\n\n /**\n * The name of the room you provided as first argument for `gameServer.define()`.\n *\n * @returns roomName string\n */\n public get roomName() { return this.#_roomName; }\n /**\n * Setting the name of the room. Overwriting this property is restricted.\n *\n * @param roomName\n */\n public set roomName(roomName: string) {\n if (this.#_roomName) {\n // prevent user from setting roomName after it has been defined.\n throw new ServerError(ErrorCode.APPLICATION_ERROR, \"'roomName' cannot be overwritten.\");\n }\n this.#_roomName = roomName;\n }\n\n /**\n * A unique, auto-generated, 9-character-long id of the room.\n * You may replace `this.roomId` during `onCreate()`.\n *\n * @returns roomId string\n */\n public get roomId() { return this.#_roomId; }\n\n /**\n * Setting the roomId, is restricted in room lifetime except upon room creation.\n *\n * @param roomId\n * @returns roomId string\n */\n public set roomId(roomId: string) {\n if (this._internalState !== RoomInternalState.CREATING && !isDevMode) {\n // prevent user from setting roomId after room has been created.\n throw new ServerError(ErrorCode.APPLICATION_ERROR, \"'roomId' can only be overridden upon room creation.\");\n }\n this.#_roomId = roomId;\n }\n\n // Optional abstract methods\n public onBeforePatch?(state: State): void | Promise<any>;\n public onCreate?(options: any): void | Promise<any>;\n public onJoin?(client: Client<UserData, AuthData>, options?: any, auth?: AuthData): void | Promise<any>;\n public onLeave?(client: Client<UserData, AuthData>, consented?: boolean): void | Promise<any>;\n public onDispose?(): void | Promise<any>;\n\n /**\n * Define a custom exception handler.\n * If defined, all lifecycle hooks will be wrapped by try/catch, and the exception will be forwarded to this method.\n *\n * These methods will be wrapped by try/catch:\n * - `onMessage`\n * - `onAuth` / `onJoin` / `onLeave` / `onCreate` / `onDispose`\n * - `clock.setTimeout` / `clock.setInterval`\n * - `setSimulationInterval`\n *\n * (Experimental: this feature is subject to change in the future - we're currently getting feedback to improve it)\n */\n public onUncaughtException?(error: RoomException<this>, methodName: 'onCreate' | 'onAuth' | 'onJoin' | 'onLeave' | 'onDispose' | 'onMessage' | 'setSimulationInterval' | 'setInterval' | 'setTimeout'): void;\n\n public onAuth(\n client: Client<UserData, AuthData>,\n options: any,\n context: AuthContext\n ): any | Promise<any> {\n return true;\n }\n\n static async onAuth(\n token: string,\n options: any,\n context: AuthContext\n ): Promise<unknown> {\n return true;\n }\n\n /**\n * This method is called during graceful shutdown of the server process\n * You may override this method to dispose the room in your own way.\n *\n * Once process reaches room count of 0, the room process will be terminated.\n */\n public onBeforeShutdown() {\n this.disconnect(\n (isDevMode)\n ? Protocol.WS_CLOSE_DEVMODE_RESTART\n : Protocol.WS_CLOSE_CONSENTED\n );\n }\n\n /**\n * devMode: When `devMode` is enabled, `onCacheRoom` method is called during\n * graceful shutdown.\n *\n * Implement this method to return custom data to be cached. `onRestoreRoom`\n * will be called with the data returned by `onCacheRoom`\n */\n public onCacheRoom?(): any;\n\n /**\n * devMode: When `devMode` is enabled, `onRestoreRoom` method is called during\n * process startup, with the data returned by the `onCacheRoom` method.\n */\n public onRestoreRoom?(cached?: any): void;\n\n /**\n * Returns whether the sum of connected clients and reserved seats exceeds maximum number of clients.\n *\n * @returns boolean\n */\n public hasReachedMaxClients(): boolean {\n return (\n (this.clients.length + Object.keys(this.reservedSeats).length) >= this.maxClients ||\n this._internalState === RoomInternalState.DISPOSING\n );\n }\n\n /**\n * Set the number of seconds a room can wait for a client to effectively join the room.\n * You should consider how long your `onAuth()` will have to wait for setting a different seat reservation time.\n * The default value is 15 seconds. You may set the `COLYSEUS_SEAT_RESERVATION_TIME`\n * environment variable if you'd like to change the seat reservation time globally.\n *\n * @default 15 seconds\n *\n * @param seconds - number of seconds.\n * @returns The modified Room object.\n */\n public setSeatReservationTime(seconds: number) {\n this.seatReservationTime = seconds;\n return this;\n }\n\n public hasReservedSeat(sessionId: string, reconnectionToken?: string): boolean {\n const reservedSeat = this.reservedSeats[sessionId];\n\n // seat reservation not found / expired\n if (reservedSeat === undefined) {\n return false;\n }\n\n if (reservedSeat[3]) {\n // reconnection\n return (\n reconnectionToken &&\n this._reconnections[reconnectionToken]?.[0] === sessionId &&\n this._reconnectingSessionId.has(sessionId)\n );\n\n } else {\n // seat reservation not consumed\n return reservedSeat[2] === false;\n }\n }\n\n public checkReconnectionToken(reconnectionToken: string) {\n const sessionId = this._reconnections[reconnectionToken]?.[0];\n const reservedSeat = this.reservedSeats[sessionId];\n\n if (reservedSeat && reservedSeat[3]) {\n this._reconnectingSessionId.set(sessionId, reconnectionToken);\n return sessionId;\n\n } else {\n return undefined;\n }\n }\n\n /**\n * (Optional) Set a simulation interval that can change the state of the game.\n * The simulation interval is your game loop.\n *\n * @default 16.6ms (60fps)\n *\n * @param onTickCallback - You can implement your physics or world updates here!\n * This is a good place to update the room state.\n * @param delay - Interval delay on executing `onTickCallback` in milliseconds.\n */\n public setSimulationInterval(onTickCallback?: SimulationCallback, delay: number = DEFAULT_SIMULATION_INTERVAL): void {\n // clear previous interval in case called setSimulationInterval more than once\n if (this._simulationInterval) { clearInterval(this._simulationInterval); }\n\n if (onTickCallback) {\n if (this.onUncaughtException !== undefined) {\n onTickCallback = wrapTryCatch(onTickCallback, this.onUncaughtException.bind(this), SimulationIntervalException, 'setSimulationInterval');\n }\n\n this._simulationInterval = setInterval(() => {\n this.clock.tick();\n onTickCallback(this.clock.deltaTime);\n }, delay);\n }\n }\n\n /**\n * @deprecated Use `.patchRate=` instead.\n */\n public setPatchRate(milliseconds: number | null): void {\n this.patchRate = milliseconds;\n }\n\n public setState(newState: State) {\n this.clock.start();\n\n if (newState[$changes] !== undefined) {\n this.setSerializer(new SchemaSerializer());\n\n } else if ($changes === undefined) {\n throw new Error(\"@colyseus/schema v2 compatibility currently missing (reach out if you need it)\");\n }\n\n this._serializer.reset(newState);\n\n this.state = newState;\n }\n\n public setSerializer(serializer: Serializer<State>) {\n this._serializer = serializer;\n }\n\n public async setMetadata(meta: Partial<Metadata>) {\n if (!this.listing.metadata) {\n this.listing.metadata = meta as Metadata;\n\n } else {\n for (const field in meta) {\n if (!meta.hasOwnProperty(field)) { continue; }\n this.listing.metadata[field] = meta[field];\n }\n\n // `MongooseDriver` workaround: persit metadata mutations\n if ('markModified' in this.listing) {\n (this.listing as any).markModified('metadata');\n }\n }\n\n if (this._internalState === RoomInternalState.CREATED) {\n await this.listing.save();\n }\n }\n\n public async setPrivate(bool: boolean = true) {\n if (this.listing.private === bool) return;\n\n this.listing.private = bool;\n\n if (this._internalState === RoomInternalState.CREATED) {\n await this.listing.save();\n }\n\n this._events.emit('visibility-change', bool);\n }\n\n /**\n * Locking the room will remove it from the pool of available rooms for new clients to connect to.\n */\n public async lock() {\n // rooms locked internally aren't explicit locks.\n this._lockedExplicitly = (arguments[0] === undefined);\n\n // skip if already locked.\n if (this._locked) { return; }\n\n this._locked = true;\n\n await this.listing.updateOne({\n $set: { locked: this._locked },\n });\n\n this._events.emit('lock');\n }\n\n /**\n * Unlocking the room returns it to the pool of available rooms for new clients to connect to.\n */\n public async unlock() {\n // only internal usage passes arguments to this function.\n if (arguments[0] === undefined) {\n this._lockedExplicitly = false;\n }\n\n // skip if already locked\n if (!this._locked) { return; }\n\n this._locked = false;\n\n await this.listing.updateOne({\n $set: { locked: this._locked },\n });\n\n this._events.emit('unlock');\n }\n\n public send(client: Client, type: string | number, message: any, options?: ISendOptions): void;\n public send(client: Client, messageOrType: any, messageOrOptions?: any | ISendOptions, options?: ISendOptions): void {\n logger.warn('DEPRECATION WARNING: use client.send(...) instead of this.send(client, ...)');\n client.send(messageOrType, messageOrOptions, options);\n }\n\n public broadcast(type: string | number, message?: any, options?: IBroadcastOptions) {\n if (options && options.afterNextPatch) {\n delete options.afterNextPatch;\n this._afterNextPatchQueue.push(['broadcast', arguments]);\n return;\n }\n\n this.broadcastMessageType(type, message, options);\n }\n\n /**\n * Broadcast bytes (UInt8Arrays) to a particular room\n */\n public broadcastBytes(type: string | number, message: Uint8Array, options: IBroadcastOptions) {\n if (options && options.afterNextPatch) {\n delete options.afterNextPatch;\n this._afterNextPatchQueue.push(['broadcastBytes', arguments]);\n return;\n }\n\n this.broadcastMessageType(type as string, message, options);\n }\n\n /**\n * Checks whether mutations have occurred in the state, and broadcast them to all connected clients.\n */\n public broadcastPatch() {\n if (this.onBeforePatch) {\n this.onBeforePatch(this.state);\n }\n\n if (!this._simulationInterval) {\n this.clock.tick();\n }\n\n if (!this.state) {\n return false;\n }\n\n const hasChanges = this._serializer.applyPatches(this.clients, this.state);\n\n // broadcast messages enqueued for \"after patch\"\n this._dequeueAfterPatchMessages();\n\n return hasChanges;\n }\n\n public onMessage<T = any>(\n messageType: '*',\n callback: (client: Client<UserData, AuthData>, type: string | number, message: T) => void\n );\n public onMessage<T = any>(\n messageType: string | number,\n callback: (client: Client<UserData, AuthData>, message: T) => void,\n validate?: (message: unknown) => T,\n );\n public onMessage<T = any>(\n messageType: '*' | string | number,\n callback: (...args: any[]) => void,\n validate?: (message: unknown) => T,\n ) {\n this.onMessageHandlers[messageType] = (this.onUncaughtException !== undefined)\n ? { validate, callback: wrapTryCatch(callback, this.onUncaughtException.bind(this), OnMessageException, 'onMessage', false, messageType) }\n : { validate, callback };\n\n\n // returns a method to unbind the callback\n return () => delete this.onMessageHandlers[messageType];\n }\n\n /**\n * Disconnect all connected clients, and then dispose the room.\n *\n * @param closeCode WebSocket close code (default = 4000, which is a \"consented leave\")\n * @returns Promise<void>\n */\n public disconnect(closeCode: number = Protocol.WS_CLOSE_CONSENTED): Promise<any> {\n // skip if already disposing\n if (this._internalState === RoomInternalState.DISPOSING) {\n return Promise.resolve(`disconnect() ignored: room (${this.roomId}) is already disposing.`);\n\n } else if (this._internalState === RoomInternalState.CREATING) {\n throw new Error(\"cannot disconnect during onCreate()\");\n }\n\n this._internalState = RoomInternalState.DISPOSING;\n this.listing.remove();\n\n this.#_autoDispose = true;\n\n const delayedDisconnection = new Promise<void>((resolve) =>\n this._events.once('disconnect', () => resolve()));\n\n // reject pending reconnections\n for (const [_, reconnection] of Object.values(this._reconnections)) {\n reconnection.reject(new Error(\"disconnecting\"));\n }\n\n let numClients = this.clients.length;\n if (numClients > 0) {\n // clients may have `async onLeave`, room will be disposed after they're fulfilled\n while (numClients--) {\n this._forciblyCloseClient(this.clients[numClients] as Client & ClientPrivate, closeCode);\n }\n\n } else {\n // no clients connected, dispose immediately.\n this._events.emit('dispose');\n }\n\n return delayedDisconnection;\n }\n\n public async ['_onJoin'](client: Client & ClientPrivate, authContext: AuthContext) {\n const sessionId = client.sessionId;\n\n // generate unique private reconnection token\n client.reconnectionToken = generateId();\n\n if (this.reservedSeatTimeouts[sessionId]) {\n clearTimeout(this.reservedSeatTimeouts[sessionId]);\n delete this.reservedSeatTimeouts[sessionId];\n }\n\n // clear auto-dispose timeout.\n if (this._autoDisposeTimeout) {\n clearTimeout(this._autoDisposeTimeout);\n this._autoDisposeTimeout = undefined;\n }\n\n // get seat reservation options and clear it\n const [joinOptions, authData, isConsumed, isWaitingReconnection] = this.reservedSeats[sessionId];\n\n //\n // TODO: remove this check on 1.0.0\n // - the seat reservation is used to keep track of number of clients and their pending seats (see `hasReachedMaxClients`)\n // - when we fully migrate to static onAuth(), the seat reservation can be removed immediately here\n // - if async onAuth() is in use, the seat reservation is removed after onAuth() is fulfilled.\n // - mark reservation as \"consumed\"\n //\n if (isConsumed) {\n throw new ServerError(ErrorCode.MATCHMAKE_EXPIRED, \"already consumed\");\n }\n this.reservedSeats[sessionId][2] = true; // flag seat reservation as \"consumed\"\n debugMatchMaking('consuming seat reservation, sessionId: \\'%s\\'', client.sessionId);\n\n // share \"after next patch queue\" reference with every client.\n client._afterNextPatchQueue = this._afterNextPatchQueue;\n\n // add temporary callback to keep track of disconnections during `onJoin`.\n client.ref['onleave'] = (_) => client.state = ClientState.LEAVING;\n client.ref.once('close', client.ref['onleave']);\n\n if (isWaitingReconnection) {\n const previousReconnectionToken = this._reconnectingSessionId.get(sessionId);\n if (previousReconnectionToken) {\n this.clients.push(client);\n //\n // await for reconnection:\n // (end user may customize the reconnection token at this step)\n //\n await this._reconnections[previousReconnectionToken]?.[1].resolve(client);\n\n } else {\n const errorMessage = (process.env.NODE_ENV === 'production')\n ? \"already consumed\" // trick possible fraudsters...\n : \"bad reconnection token\" // ...or developers\n throw new ServerError(ErrorCode.MATCHMAKE_EXPIRED, errorMessage);\n }\n\n } else {\n try {\n if (authData) {\n client.auth = authData;\n\n } else if (this.onAuth !== Room.prototype.onAuth) {\n try {\n client.auth = await this.onAuth(client, joinOptions, authContext);\n\n if (!client.auth) {\n throw new ServerError(ErrorCode.AUTH_FAILED, 'onAuth failed');\n }\n\n } catch (e) {\n // remove seat reservation\n delete this.reservedSeats[sessionId];\n await this._decrementClientCount();\n throw e;\n }\n }\n\n //\n // On async onAuth, client may have been disconnected.\n //\n if (client.state === ClientState.LEAVING) {\n throw new ServerError(Protocol.WS_CLOSE_GOING_AWAY, 'already disconnected');\n }\n\n this.clients.push(client);\n\n //\n // Flag sessionId as non-enumarable so hasReachedMaxClients() doesn't count it\n // (https://github.com/colyseus/colyseus/issues/726)\n //\n Object.defineProperty(this.reservedSeats, sessionId, {\n value: this.reservedSeats[sessionId],\n enumerable: false,\n });\n\n if (this.onJoin) {\n await this.onJoin(client, joinOptions, client.auth);\n }\n\n // @ts-ignore: client left during `onJoin`, call _onLeave immediately.\n if (client.state === ClientState.LEAVING) {\n throw new Error(\"early_leave\");\n\n } else {\n // remove seat reservation\n delete this.reservedSeats[sessionId];\n\n // emit 'join' to room handler\n this._events.emit('join', client);\n }\n\n } catch (e) {\n await this._onLeave(client, Protocol.WS_CLOSE_GOING_AWAY);\n\n // remove seat reservation\n delete this.reservedSeats[sessionId];\n\n // make sure an error code is provided.\n if (!e.code) {\n e.code = ErrorCode.APPLICATION_ERROR;\n }\n\n throw e;\n }\n }\n\n // state might already be ClientState.LEAVING here\n if (client.state === ClientState.JOINING) {\n client.ref.removeListener('close', client.ref['onleave']);\n\n // only bind _onLeave after onJoin has been successful\n client.ref['onleave'] = this._onLeave.bind(this, client);\n client.ref.once('close', client.ref['onleave']);\n\n // allow client to send messages after onJoin has succeeded.\n client.ref.on('message', this._onMessage.bind(this, client));\n\n // confirm room id that matches the room name requested to join\n client.raw(getMessageBytes[Protocol.JOIN_ROOM](\n client.reconnectionToken,\n this._serializer.id,\n this._serializer.handshake && this._serializer.handshake(),\n ));\n }\n }\n\n /**\n * Allow the specified client to reconnect into the room. Must be used inside `onLeave()` method.\n * If seconds is provided, the reconnection is going to be cancelled after the provided amount of seconds.\n *\n * @param previousClient - The client which is to be waiting until re-connection happens.\n * @param seconds - Timeout period on re-connection in seconds.\n *\n * @returns Deferred<Client> - The differed is a promise like type.\n * This type can forcibly reject the promise by calling `.reject()`.\n */\n public allowReconnection(previousClient: Client, seconds: number | \"manual\"): Deferred<Client> {\n //\n // Return rejected promise if client has never fully JOINED.\n //\n // (having `_enqueuedMessages !== undefined` means that the client has never been at \"ClientState.JOINED\" state)\n //\n if ((previousClient as unknown as ClientPrivate)._enqueuedMessages !== undefined) {\n // @ts-ignore\n return Promise.reject(new Error(\"not joined\"));\n }\n\n if (seconds === undefined) { // TODO: remove this check\n console.warn(\"DEPRECATED: allowReconnection() requires a second argument. Using \\\"manual\\\" mode.\");\n seconds = \"manual\";\n }\n\n if (seconds === \"manual\") {\n seconds = Infinity;\n }\n\n if (this._internalState === RoomInternalState.DISPOSING) {\n // @ts-ignore\n return Promise.reject(new Error(\"disposing\"));\n }\n\n const sessionId = previousClient.sessionId;\n const reconnectionToken = previousClient.reconnectionToken;\n\n this._reserveSeat(sessionId, true, previousClient.auth, seconds, true);\n\n // keep reconnection reference in case the user reconnects into this room.\n const reconnection = new Deferred<Client & ClientPrivate>();\n this._reconnections[reconnectionToken] = [sessionId, reconnection];\n\n if (seconds !== Infinity) {\n // expire seat reservation after timeout\n this.reservedSeatTimeouts[sessionId] = setTimeout(() =>\n reconnection.reject(false), seconds * 1000);\n }\n\n const cleanup = () => {\n delete this._reconnections[reconnectionToken];\n delete this.reservedSeats[sessionId];\n delete this.reservedSeatTimeouts[sessionId];\n this._reconnectingSessionId.delete(sessionId);\n };\n\n reconnection.\n then((newClient) => {\n newClient.auth = previousClient.auth;\n newClient.userData = previousClient.userData;\n previousClient.ref = newClient.ref; // swap \"ref\" for convenience\n previousClient.state = ClientState.RECONNECTED;\n clearTimeout(this.reservedSeatTimeouts[sessionId]);\n cleanup();\n }).\n catch(() => {\n cleanup();\n this.resetAutoDisposeTimeout();\n });\n\n return reconnection;\n }\n\n protected resetAutoDisposeTimeout(timeoutInSeconds: number = 1) {\n clearTimeout(this._autoDisposeTimeout);\n\n if (!this.#_autoDispose) {\n return;\n }\n\n this._autoDisposeTimeout = setTimeout(() => {\n this._autoDisposeTimeout = undefined;\n this._disposeIfEmpty();\n }, timeoutInSeconds * 1000);\n }\n\n private broadcastMessageType(type: number | string, message?: any | Uint8Array, options: IBroadcastOptions = {}) {\n debugMessage(\"broadcast: %O\", message);\n\n const encodedMessage = (message instanceof Uint8Array)\n ? getMessageBytes.raw(Protocol.ROOM_DATA_BYTES, type, undefined, message)\n : getMessageBytes.raw(Protocol.ROOM_DATA, type, message)\n\n const except = (typeof (options.except) !== \"undefined\")\n ? Array.isArray(options.except)\n ? options.except\n : [options.except]\n : undefined;\n\n let numClients = this.clients.length;\n while (numClients--) {\n const client = this.clients[numClients];\n\n if (!except || !except.includes(client)) {\n client.enqueueRaw(encodedMessage);\n }\n }\n }\n\n protected sendFullState(client: Client): void {\n client.raw(this._serializer.getFullState(client));\n }\n\n protected _dequeueAfterPatchMessages() {\n const length = this._afterNextPatchQueue.length;\n\n if (length > 0) {\n for (let i = 0; i < length; i++) {\n const [target, args] = this._afterNextPatchQueue[i];\n\n if (target === \"broadcast\") {\n this.broadcast.apply(this, args);\n\n } else {\n (target as Client).raw.apply(target, args);\n }\n }\n\n // new messages may have been added in the meantime,\n // let's splice the ones that have been processed\n this._afterNextPatchQueue.splice(0, length);\n }\n }\n\n protected async _reserveSeat(\n sessionId: string,\n joinOptions: any = true,\n authData: any = undefined,\n seconds: number = this.seatReservationTime,\n allowReconnection: boolean = false,\n devModeReconnection?: boolean,\n ) {\n if (!allowReconnection && this.hasReachedMaxClients()) {\n return false;\n }\n\n this.reservedSeats[sessionId] = [joinOptions, authData, false, allowReconnection];\n\n if (!allowReconnection) {\n await this._incrementClientCount();\n\n this.reservedSeatTimeouts[sessionId] = setTimeout(async () => {\n delete this.reservedSeats[sessionId];\n delete this.reservedSeatTimeouts[sessionId];\n await this._decrementClientCount();\n }, seconds * 1000);\n\n this.resetAutoDisposeTimeout(seconds);\n }\n\n //\n // isDevMode workaround to allow players to reconnect on devMode\n //\n if (devModeReconnection) {\n this._reconnectingSessionId.set(sessionId, sessionId);\n }\n\n return true;\n }\n\n protected _disposeIfEmpty() {\n const willDispose = (\n this.#_onLeaveConcurrent === 0 && // no \"onLeave\" calls in progress\n this.#_autoDispose &&\n this._autoDisposeTimeout === undefined &&\n this.clients.length === 0 &&\n Object.keys(this.reservedSeats).length === 0\n );\n\n if (willDispose) {\n this._events.emit('dispose');\n }\n\n return willDispose;\n }\n\n protected async _dispose(): Promise<any> {\n this._internalState = RoomInternalState.DISPOSING;\n\n this.listing.remove();\n\n let userReturnData;\n if (this.onDispose) {\n userReturnData = this.onDispose();\n }\n\n if (this.#_patchInterval) {\n clearInterval(this.#_patchInterval);\n this.#_patchInterval = undefined;\n }\n\n if (this._simulationInterval) {\n clearInterval(this._simulationInterval);\n this._simulationInterval = undefined;\n }\n\n if (this._autoDisposeTimeout) {\n clearInterval(this._autoDisposeTimeout);\n this._autoDisposeTimeout = undefined;\n }\n\n // clear all timeouts/intervals + force to stop ticking\n this.clock.clear();\n this.clock.stop();\n\n return await (userReturnData || Promise.resolve());\n }\n\n protected _onMessage(client: Client & ClientPrivate, buffer: Buffer) {\n // skip if client is on LEAVING state.\n if (client.state === ClientState.LEAVING) { return; }\n\n const it: Iterator = { offset: 1 };\n const code = buffer[0];\n\n if (!buffer) {\n debugAndPrintError(`${this.roomName} (${this.roomId}), couldn't decode message: ${buffer}`);\n return;\n }\n\n if (code === Protocol.ROOM_DATA) {\n const messageType = (decode.stringCheck(buffer, it))\n ? decode.string(buffer, it)\n : decode.number(buffer, it);\n const messageTypeHandler = this.onMessageHandlers[messageType];\n\n let message;\n try {\n message = (buffer.byteLength > it.offset)\n ? unpack(buffer.subarray(it.offset, buffer.byteLength))\n : undefined;\n debugMessage(\"received: '%s' -> %j\", messageType, message);\n\n // custom message validation\n if (messageTypeHandler?.validate !== undefined) {\n message = messageTypeHandler.validate(message);\n }\n\n } catch (e) {\n debugAndPrintError(e);\n client.leave(Protocol.WS_CLOSE_WITH_ERROR);\n return;\n }\n\n if (messageTypeHandler) {\n messageTypeHandler.callback(client, message);\n\n } else {\n (this.onMessageHandlers['*'] || this.onMessageHandlers['__no_message_handler']).callback(client, messageType, message);\n }\n\n } else if (code === Protocol.ROOM_DATA_BYTES) {\n const messageType = (decode.stringCheck(buffer, it))\n ? decode.string(buffer, it)\n : decode.number(buffer, it);\n const messageTypeHandler = this.onMessageHandlers[messageType];\n\n let message = buffer.subarray(it.offset, buffer.byteLength);\n debugMessage(\"received: '%s' -> %j\", messageType, message);\n\n // custom message validation\n if (messageTypeHandler?.validate !== undefined) {\n message = messageTypeHandler.validate(message);\n }\n\n if (messageTypeHandler) {\n messageTypeHandler.callback(client, message);\n\n } else {\n (this.onMessageHandlers['*'] || this.onMessageHandlers['__no_message_handler']).callback(client, messageType, message);\n }\n\n } else if (code === Protocol.JOIN_ROOM && client.state === ClientState.JOINING) {\n // join room has been acknowledged by the client\n client.state = ClientState.JOINED;\n client._joinedAt = this.clock.elapsedTime;\n\n // send current state when new client joins the room\n if (this.state) {\n this.sendFullState(client);\n }\n\n // dequeue messages sent before client has joined effectively (on user-defined `onJoin`)\n if (client._enqueuedMessages.length > 0) {\n client._enqueuedMessages.forEach((enqueued) => client.raw(enqueued));\n }\n delete client._enqueuedMessages;\n\n } else if (code === Protocol.LEAVE_ROOM) {\n this._forciblyCloseClient(client, Protocol.WS_CLOSE_CONSENTED);\n }\n\n }\n\n protected _forciblyCloseClient(client: Client & ClientPrivate, closeCode: number) {\n // stop receiving messages from this client\n client.ref.removeAllListeners('message');\n\n // prevent \"onLeave\" from being called twice if player asks to leave\n client.ref.removeListener('close', client.ref['onleave']);\n\n // only effectively close connection when \"onLeave\" is fulfilled\n this._onLeave(client, closeCode).then(() => client.leave(closeCode));\n }\n\n protected async _onLeave(client: Client, code?: number): Promise<any> {\n debugMatchMaking('onLeave, sessionId: \\'%s\\'', client.sessionId);\n\n // call 'onLeave' method only if the client has been successfully accepted.\n client.state = ClientState.LEAVING;\n\n if (!this.clients.delete(client)) {\n // skip if client already left the room\n return;\n }\n\n if (this.onLeave) {\n try {\n this.#_onLeaveConcurrent++;\n await this.onLeave(client, (code === Protocol.WS_CLOSE_CONSENTED));\n\n } catch (e) {\n debugAndPrintError(`onLeave error: ${(e && e.message || e || 'promise rejected')}`);\n\n } finally {\n this.#_onLeaveConcurrent--;\n }\n }\n\n // check for manual \"reconnection\" flow\n if (this._reconnections[client.reconnectionToken]) {\n this._reconnections[client.reconnectionToken][1].catch(async () => {\n await this._onAfterLeave(client);\n });\n\n // @ts-ignore (client.state may be modified at onLeave())\n } else if (client.state !== ClientState.RECONNECTED) {\n await this._onAfterLeave(client);\n }\n }\n\n protected async _onAfterLeave(client: Client) {\n // try to dispose immediately if client reconnection isn't set up.\n const willDispose = await this._decrementClientCount();\n\n // trigger 'leave' only if seat reservation has been fully consumed\n if (this.reservedSeats[client.sessionId] === undefined) {\n this._events.emit('leave', client, willDispose);\n }\n\n }\n\n protected async _incrementClientCount() {\n // lock automatically when maxClients is reached\n if (!this._locked && this.hasReachedMaxClients()) {\n this._maxClientsReached = true;\n this.lock.call(this, true);\n }\n\n await this.listing.updateOne({\n $inc: { clients: 1 },\n $set: { locked: this._locked },\n });\n }\n\n protected async _decrementClientCount() {\n const willDispose = this._disposeIfEmpty();\n\n if (this._internalState === RoomInternalState.DISPOSING) {\n return true;\n }\n\n // unlock if room is available for new connections\n if (!willDispose) {\n if (this._maxClientsReached && !this._lockedExplicitly) {\n this._maxClientsReached = false;\n this.unlock.call(this, true);\n }\n\n // update room listing cache\n await this.listing.updateOne({\n $inc: { clients: -1 },\n $set: { locked: this._locked },\n });\n }\n\n return willDispose;\n }\n\n #registerUncaughtExceptionHandlers() {\n const onUncaughtException = this.onUncaughtException.bind(this);\n const originalSetTimeout = this.clock.setTimeout;\n this.clock.setTimeout = (cb, timeout, ...args) => {\n return originalSetTimeout.call(this.clock, wrapTryCatch(cb, onUncaughtException, TimedEventException, 'setTimeout'), timeout, ...args);\n };\n\n const originalSetInterval = this.clock.setInterval;\n this.clock.setInterval = (cb, timeout, ...args) => {\n return originalSetInterval.call(this.clock, wrapTryCatch(cb, onUncaughtException, TimedEventException, 'setInterval'), timeout, ...args);\n };\n\n if (this.onCreate !== undefined) {\n this.onCreate = wrapTryCatch(this.onCreate.bind(this), onUncaughtException, OnCreateException, 'onCreate', true);\n }\n\n if (this.onAuth !== undefined) {\n this.onAuth = wrapTryCatch(this.onAuth.bind(this), onUncaughtException, OnAuthException, 'onAuth', true);\n }\n\n if (this.onJoin !== undefined) {\n this.onJoin = wrapTryCatch(this.onJoin.bind(this), onUncaughtException, OnJoinException, 'onJoin', true);\n }\n\n if (this.onLeave !== undefined) {\n this.onLeave = wrapTryCatch(this.onLeave.bind(this), onUncaughtException, OnLeaveException, 'onLeave', true);\n }\n\n if (this.onDispose !== undefined) {\n this.onDispose = wrapTryCatch(this.onDispose.bind(this), onUncaughtException,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AAK,IAAI,GAAG,qBAAqB,kBAAkB,WAAW,IAAI;AAAA,IAC7G;AAEA,QAAI,KAAK,cAAc,QAAW;AAChC,WAAK,YAAY,aAAa,KAAK,UAAU,KAAK,IAAI,GAAG,qBAAqB,oBAAoB,WAAW;AAAA,IAC/G;AAAA,EACF;AAEF;",
|
|
4
|
+
"sourcesContent": ["import { unpack } from '@colyseus/msgpackr';\nimport { decode, Iterator, $changes } from '@colyseus/schema';\n\nimport Clock from '@colyseus/timer';\nimport { EventEmitter } from 'events';\nimport { logger } from './Logger.js';\n\nimport { Presence } from './presence/Presence.js';\n\nimport { NoneSerializer } from './serializer/NoneSerializer.js';\nimport { SchemaSerializer } from './serializer/SchemaSerializer.js';\nimport { Serializer } from './serializer/Serializer.js';\n\nimport { ErrorCode, getMessageBytes, Protocol } from './Protocol';\nimport { Deferred, generateId, wrapTryCatch } from './utils/Utils.js';\nimport { isDevMode } from './utils/DevMode.js';\n\nimport { debugAndPrintError, debugMatchMaking, debugMessage } from './Debug.js';\nimport { RoomCache } from './matchmaker/driver/api.js';\nimport { ServerError } from './errors/ServerError.js';\nimport { AuthContext, Client, ClientPrivate, ClientArray, ClientState, ISendOptions } from './Transport';\nimport { OnAuthException, OnCreateException, OnDisposeException, OnJoinException, OnLeaveException, OnMessageException, RoomException, SimulationIntervalException, TimedEventException } from './errors/RoomExceptions.js';\n\nconst DEFAULT_PATCH_RATE = 1000 / 20; // 20fps (50ms)\nconst DEFAULT_SIMULATION_INTERVAL = 1000 / 60; // 60fps (16.66ms)\nconst noneSerializer = new NoneSerializer();\n\nexport const DEFAULT_SEAT_RESERVATION_TIME = Number(process.env.COLYSEUS_SEAT_RESERVATION_TIME || 15);\n\nexport type SimulationCallback = (deltaTime: number) => void;\n\nexport interface IBroadcastOptions extends ISendOptions {\n except?: Client | Client[];\n}\n\nexport enum RoomInternalState {\n CREATING = 0,\n CREATED = 1,\n DISPOSING = 2,\n}\n\nexport type ExtractUserData<T> = T extends ClientArray<infer U> ? U : never;\nexport type ExtractAuthData<T> = T extends ClientArray<infer _, infer U> ? U : never;\n\n/**\n * A Room class is meant to implement a game session, and/or serve as the communication channel\n * between a group of clients.\n *\n * - Rooms are created on demand during matchmaking by default\n * - Room classes must be exposed using `.define()`\n */\nexport abstract class Room<State extends object= any, Metadata= any, UserData = any, AuthData = any> {\n\n /**\n * This property will change on these situations:\n * - The maximum number of allowed clients has been reached (`maxClients`)\n * - You manually locked, or unlocked the room using lock() or `unlock()`.\n *\n * @readonly\n */\n public get locked() {\n return this.#_locked;\n }\n\n public get metadata() {\n return this.listing.metadata;\n }\n\n public listing: RoomCache<Metadata>;\n\n /**\n * Timing events tied to the room instance.\n * Intervals and timeouts are cleared when the room is disposed.\n */\n public clock: Clock = new Clock();\n\n #_roomId: string;\n #_roomName: string;\n #_onLeaveConcurrent: number = 0; // number of onLeave calls in progress\n\n /**\n * Maximum number of clients allowed to connect into the room. When room reaches this limit,\n * it is locked automatically. Unless the room was explicitly locked by you via `lock()` method,\n * the room will be unlocked as soon as a client disconnects from it.\n */\n public maxClients: number = Infinity;\n #_maxClientsReached: boolean = false;\n #_maxClients: number;\n\n /**\n * Automatically dispose the room when last client disconnects.\n *\n * @default true\n */\n public autoDispose: boolean = true;\n #_autoDispose: boolean;\n\n /**\n * Frequency to send the room state to connected clients, in milliseconds.\n *\n * @default 50ms (20fps)\n */\n public patchRate: number = DEFAULT_PATCH_RATE;\n #_patchRate: number;\n #_patchInterval: NodeJS.Timeout;\n\n /**\n * The state instance you provided to `setState()`.\n */\n public state: State;\n #_state: State;\n\n /**\n * The presence instance. Check Presence API for more details.\n *\n * @see {@link https://docs.colyseus.io/colyseus/server/presence/|Presence API}\n */\n public presence: Presence;\n\n /**\n * The array of connected clients.\n *\n * @see {@link https://docs.colyseus.io/colyseus/server/room/#client|Client instance}\n */\n public clients: ClientArray<UserData, AuthData> = new ClientArray();\n\n /** @internal */\n public _events = new EventEmitter();\n\n // seat reservation & reconnection\n protected seatReservationTime: number = DEFAULT_SEAT_RESERVATION_TIME;\n protected reservedSeats: { [sessionId: string]: [any, any, boolean?, boolean?] } = {};\n protected reservedSeatTimeouts: { [sessionId: string]: NodeJS.Timeout } = {};\n\n protected _reconnections: { [reconnectionToken: string]: [string, Deferred] } = {};\n private _reconnectingSessionId = new Map<string, string>();\n\n private onMessageHandlers: {\n [id: string]: {\n callback: (...args: any[]) => void,\n validate?: (data: unknown) => any,\n }\n } = {\n '__no_message_handler': {\n callback: (client: Client, messageType: string, _: unknown) => {\n const errorMessage = `onMessage for \"${messageType}\" not registered.`;\n debugAndPrintError(errorMessage);\n\n if (isDevMode) {\n // send error code to client in development mode\n client.error(ErrorCode.INVALID_PAYLOAD, errorMessage);\n\n } else {\n // immediately close the connection in production\n client.leave(Protocol.WS_CLOSE_WITH_ERROR, errorMessage);\n }\n }\n }\n };\n\n private _serializer: Serializer<State> = noneSerializer;\n private _afterNextPatchQueue: Array<[string | Client, IArguments]> = [];\n\n private _simulationInterval: NodeJS.Timeout;\n\n private _internalState: RoomInternalState = RoomInternalState.CREATING;\n\n private _lockedExplicitly: boolean = false;\n #_locked: boolean = false;\n\n // this timeout prevents rooms that are created by one process, but no client\n // ever had success joining into it on the specified interval.\n private _autoDisposeTimeout: NodeJS.Timeout;\n\n constructor() {\n this._events.once('dispose', () => {\n this._dispose()\n .catch((e) => debugAndPrintError(`onDispose error: ${(e && e.stack || e.message || e || 'promise rejected')}`))\n .finally(() => this._events.emit('disconnect'));\n });\n\n /**\n * If `onUncaughtException` is defined, it will automatically catch exceptions\n */\n if (this.onUncaughtException !== undefined) {\n this.#registerUncaughtExceptionHandlers();\n }\n }\n\n /**\n * This method is called by the MatchMaker before onCreate()\n * @internal\n */\n protected __init() {\n this.#_state = this.state;\n this.#_autoDispose = this.autoDispose;\n this.#_patchRate = this.patchRate;\n this.#_maxClients = this.maxClients;\n\n Object.defineProperties(this, {\n state: {\n enumerable: true,\n get: () => this.#_state,\n set: (newState: State) => {\n if (newState[$changes] !== undefined) {\n this.setSerializer(new SchemaSerializer());\n } else if ('_definition' in newState) {\n throw new Error(\"@colyseus/schema v2 compatibility currently missing (reach out if you need it)\");\n } else if ($changes === undefined) {\n throw new Error(\"Multiple @colyseus/schema versions detected. Please make sure you don't have multiple versions of @colyseus/schema installed.\");\n }\n this._serializer.reset(newState);\n this.#_state = newState;\n },\n },\n\n maxClients: {\n enumerable: true,\n get: () => this.#_maxClients,\n set: (value: number) => {\n this.#_maxClients = value;\n\n if (this._internalState === RoomInternalState.CREATED) {\n const hasReachedMaxClients = this.hasReachedMaxClients();\n\n // unlock room if maxClients has been increased\n if (!this._lockedExplicitly && this.#_maxClientsReached && !hasReachedMaxClients) {\n this.#_maxClientsReached = false;\n this.#_locked = false;\n this.listing.locked = false;\n }\n\n // lock room if maxClients has been decreased\n if (hasReachedMaxClients) {\n this.#_maxClientsReached = true;\n this.#_locked = true;\n this.listing.locked = true;\n }\n\n this.listing.maxClients = value;\n this.listing.save();\n }\n },\n },\n\n autoDispose: {\n enumerable: true,\n get: () => this.#_autoDispose,\n set: (value: boolean) => {\n if (\n value !== this.#_autoDispose &&\n this._internalState !== RoomInternalState.DISPOSING\n ) {\n this.#_autoDispose = value;\n this.resetAutoDisposeTimeout();\n }\n },\n },\n\n patchRate: {\n enumerable: true,\n get: () => this.#_patchRate,\n set: (milliseconds: number) => {\n this.#_patchRate = milliseconds;\n // clear previous interval in case called setPatchRate more than once\n if (this.#_patchInterval) {\n clearInterval(this.#_patchInterval);\n this.#_patchInterval = undefined;\n }\n if (milliseconds !== null && milliseconds !== 0) {\n this.#_patchInterval = setInterval(() => this.broadcastPatch(), milliseconds);\n }\n },\n },\n });\n\n // set patch interval, now with the setter\n this.patchRate = this.#_patchRate;\n\n // set state, now with the setter\n if (this.#_state) {\n this.state = this.#_state;\n }\n\n // set default _autoDisposeTimeout\n this.resetAutoDisposeTimeout(this.seatReservationTime);\n\n this.clock.start();\n }\n\n /**\n * The name of the room you provided as first argument for `gameServer.define()`.\n *\n * @returns roomName string\n */\n public get roomName() { return this.#_roomName; }\n /**\n * Setting the name of the room. Overwriting this property is restricted.\n *\n * @param roomName\n */\n public set roomName(roomName: string) {\n if (this.#_roomName) {\n // prevent user from setting roomName after it has been defined.\n throw new ServerError(ErrorCode.APPLICATION_ERROR, \"'roomName' cannot be overwritten.\");\n }\n this.#_roomName = roomName;\n }\n\n /**\n * A unique, auto-generated, 9-character-long id of the room.\n * You may replace `this.roomId` during `onCreate()`.\n *\n * @returns roomId string\n */\n public get roomId() { return this.#_roomId; }\n\n /**\n * Setting the roomId, is restricted in room lifetime except upon room creation.\n *\n * @param roomId\n * @returns roomId string\n */\n public set roomId(roomId: string) {\n if (this._internalState !== RoomInternalState.CREATING && !isDevMode) {\n // prevent user from setting roomId after room has been created.\n throw new ServerError(ErrorCode.APPLICATION_ERROR, \"'roomId' can only be overridden upon room creation.\");\n }\n this.#_roomId = roomId;\n }\n\n // Optional abstract methods\n public onBeforePatch?(state: State): void | Promise<any>;\n public onCreate?(options: any): void | Promise<any>;\n public onJoin?(client: Client<UserData, AuthData>, options?: any, auth?: AuthData): void | Promise<any>;\n public onLeave?(client: Client<UserData, AuthData>, consented?: boolean): void | Promise<any>;\n public onDispose?(): void | Promise<any>;\n\n /**\n * Define a custom exception handler.\n * If defined, all lifecycle hooks will be wrapped by try/catch, and the exception will be forwarded to this method.\n *\n * These methods will be wrapped by try/catch:\n * - `onMessage`\n * - `onAuth` / `onJoin` / `onLeave` / `onCreate` / `onDispose`\n * - `clock.setTimeout` / `clock.setInterval`\n * - `setSimulationInterval`\n *\n * (Experimental: this feature is subject to change in the future - we're currently getting feedback to improve it)\n */\n public onUncaughtException?(error: RoomException<this>, methodName: 'onCreate' | 'onAuth' | 'onJoin' | 'onLeave' | 'onDispose' | 'onMessage' | 'setSimulationInterval' | 'setInterval' | 'setTimeout'): void;\n\n public onAuth(\n client: Client<UserData, AuthData>,\n options: any,\n context: AuthContext\n ): any | Promise<any> {\n return true;\n }\n\n static async onAuth(\n token: string,\n options: any,\n context: AuthContext\n ): Promise<unknown> {\n return true;\n }\n\n /**\n * This method is called during graceful shutdown of the server process\n * You may override this method to dispose the room in your own way.\n *\n * Once process reaches room count of 0, the room process will be terminated.\n */\n public onBeforeShutdown() {\n this.disconnect(\n (isDevMode)\n ? Protocol.WS_CLOSE_DEVMODE_RESTART\n : Protocol.WS_CLOSE_CONSENTED\n );\n }\n\n /**\n * devMode: When `devMode` is enabled, `onCacheRoom` method is called during\n * graceful shutdown.\n *\n * Implement this method to return custom data to be cached. `onRestoreRoom`\n * will be called with the data returned by `onCacheRoom`\n */\n public onCacheRoom?(): any;\n\n /**\n * devMode: When `devMode` is enabled, `onRestoreRoom` method is called during\n * process startup, with the data returned by the `onCacheRoom` method.\n */\n public onRestoreRoom?(cached?: any): void;\n\n /**\n * Returns whether the sum of connected clients and reserved seats exceeds maximum number of clients.\n *\n * @returns boolean\n */\n public hasReachedMaxClients(): boolean {\n return (\n (this.clients.length + Object.keys(this.reservedSeats).length) >= this.maxClients ||\n this._internalState === RoomInternalState.DISPOSING\n );\n }\n\n /**\n * Set the number of seconds a room can wait for a client to effectively join the room.\n * You should consider how long your `onAuth()` will have to wait for setting a different seat reservation time.\n * The default value is 15 seconds. You may set the `COLYSEUS_SEAT_RESERVATION_TIME`\n * environment variable if you'd like to change the seat reservation time globally.\n *\n * @default 15 seconds\n *\n * @param seconds - number of seconds.\n * @returns The modified Room object.\n */\n public setSeatReservationTime(seconds: number) {\n this.seatReservationTime = seconds;\n return this;\n }\n\n public hasReservedSeat(sessionId: string, reconnectionToken?: string): boolean {\n const reservedSeat = this.reservedSeats[sessionId];\n\n // seat reservation not found / expired\n if (reservedSeat === undefined) {\n return false;\n }\n\n if (reservedSeat[3]) {\n // reconnection\n return (\n reconnectionToken &&\n this._reconnections[reconnectionToken]?.[0] === sessionId &&\n this._reconnectingSessionId.has(sessionId)\n );\n\n } else {\n // seat reservation not consumed\n return reservedSeat[2] === false;\n }\n }\n\n public checkReconnectionToken(reconnectionToken: string) {\n const sessionId = this._reconnections[reconnectionToken]?.[0];\n const reservedSeat = this.reservedSeats[sessionId];\n\n if (reservedSeat && reservedSeat[3]) {\n this._reconnectingSessionId.set(sessionId, reconnectionToken);\n return sessionId;\n\n } else {\n return undefined;\n }\n }\n\n /**\n * (Optional) Set a simulation interval that can change the state of the game.\n * The simulation interval is your game loop.\n *\n * @default 16.6ms (60fps)\n *\n * @param onTickCallback - You can implement your physics or world updates here!\n * This is a good place to update the room state.\n * @param delay - Interval delay on executing `onTickCallback` in milliseconds.\n */\n public setSimulationInterval(onTickCallback?: SimulationCallback, delay: number = DEFAULT_SIMULATION_INTERVAL): void {\n // clear previous interval in case called setSimulationInterval more than once\n if (this._simulationInterval) { clearInterval(this._simulationInterval); }\n\n if (onTickCallback) {\n if (this.onUncaughtException !== undefined) {\n onTickCallback = wrapTryCatch(onTickCallback, this.onUncaughtException.bind(this), SimulationIntervalException, 'setSimulationInterval');\n }\n\n this._simulationInterval = setInterval(() => {\n this.clock.tick();\n onTickCallback(this.clock.deltaTime);\n }, delay);\n }\n }\n\n /**\n * @deprecated Use `.patchRate=` instead.\n */\n public setPatchRate(milliseconds: number | null): void {\n this.patchRate = milliseconds;\n }\n\n /**\n * @deprecated Use `.state =` instead.\n */\n public setState(newState: State) {\n this.state = newState;\n }\n\n public setSerializer(serializer: Serializer<State>) {\n this._serializer = serializer;\n }\n\n public async setMetadata(meta: Partial<Metadata>) {\n if (!this.listing.metadata) {\n this.listing.metadata = meta as Metadata;\n\n } else {\n for (const field in meta) {\n if (!meta.hasOwnProperty(field)) { continue; }\n this.listing.metadata[field] = meta[field];\n }\n\n // `MongooseDriver` workaround: persit metadata mutations\n if ('markModified' in this.listing) {\n (this.listing as any).markModified('metadata');\n }\n }\n\n if (this._internalState === RoomInternalState.CREATED) {\n await this.listing.save();\n }\n }\n\n public async setPrivate(bool: boolean = true) {\n if (this.listing.private === bool) return;\n\n this.listing.private = bool;\n\n if (this._internalState === RoomInternalState.CREATED) {\n await this.listing.save();\n }\n\n this._events.emit('visibility-change', bool);\n }\n\n /**\n * Locking the room will remove it from the pool of available rooms for new clients to connect to.\n */\n public async lock() {\n // rooms locked internally aren't explicit locks.\n this._lockedExplicitly = (arguments[0] === undefined);\n\n // skip if already locked.\n if (this.#_locked) { return; }\n\n this.#_locked = true;\n\n await this.listing.updateOne({\n $set: { locked: this.#_locked },\n });\n\n this._events.emit('lock');\n }\n\n /**\n * Unlocking the room returns it to the pool of available rooms for new clients to connect to.\n */\n public async unlock() {\n // only internal usage passes arguments to this function.\n if (arguments[0] === undefined) {\n this._lockedExplicitly = false;\n }\n\n // skip if already locked\n if (!this.#_locked) { return; }\n\n this.#_locked = false;\n\n await this.listing.updateOne({\n $set: { locked: this.#_locked },\n });\n\n this._events.emit('unlock');\n }\n\n public send(client: Client, type: string | number, message: any, options?: ISendOptions): void;\n public send(client: Client, messageOrType: any, messageOrOptions?: any | ISendOptions, options?: ISendOptions): void {\n logger.warn('DEPRECATION WARNING: use client.send(...) instead of this.send(client, ...)');\n client.send(messageOrType, messageOrOptions, options);\n }\n\n public broadcast(type: string | number, message?: any, options?: IBroadcastOptions) {\n if (options && options.afterNextPatch) {\n delete options.afterNextPatch;\n this._afterNextPatchQueue.push(['broadcast', arguments]);\n return;\n }\n\n this.broadcastMessageType(type, message, options);\n }\n\n /**\n * Broadcast bytes (UInt8Arrays) to a particular room\n */\n public broadcastBytes(type: string | number, message: Uint8Array, options: IBroadcastOptions) {\n if (options && options.afterNextPatch) {\n delete options.afterNextPatch;\n this._afterNextPatchQueue.push(['broadcastBytes', arguments]);\n return;\n }\n\n this.broadcastMessageType(type as string, message, options);\n }\n\n /**\n * Checks whether mutations have occurred in the state, and broadcast them to all connected clients.\n */\n public broadcastPatch() {\n if (this.onBeforePatch) {\n this.onBeforePatch(this.state);\n }\n\n if (!this._simulationInterval) {\n this.clock.tick();\n }\n\n if (!this.state) {\n return false;\n }\n\n const hasChanges = this._serializer.applyPatches(this.clients, this.state);\n\n // broadcast messages enqueued for \"after patch\"\n this._dequeueAfterPatchMessages();\n\n return hasChanges;\n }\n\n public onMessage<T = any>(\n messageType: '*',\n callback: (client: Client<UserData, AuthData>, type: string | number, message: T) => void\n );\n public onMessage<T = any>(\n messageType: string | number,\n callback: (client: Client<UserData, AuthData>, message: T) => void,\n validate?: (message: unknown) => T,\n );\n public onMessage<T = any>(\n messageType: '*' | string | number,\n callback: (...args: any[]) => void,\n validate?: (message: unknown) => T,\n ) {\n this.onMessageHandlers[messageType] = (this.onUncaughtException !== undefined)\n ? { validate, callback: wrapTryCatch(callback, this.onUncaughtException.bind(this), OnMessageException, 'onMessage', false, messageType) }\n : { validate, callback };\n\n\n // returns a method to unbind the callback\n return () => delete this.onMessageHandlers[messageType];\n }\n\n /**\n * Disconnect all connected clients, and then dispose the room.\n *\n * @param closeCode WebSocket close code (default = 4000, which is a \"consented leave\")\n * @returns Promise<void>\n */\n public disconnect(closeCode: number = Protocol.WS_CLOSE_CONSENTED): Promise<any> {\n // skip if already disposing\n if (this._internalState === RoomInternalState.DISPOSING) {\n return Promise.resolve(`disconnect() ignored: room (${this.roomId}) is already disposing.`);\n\n } else if (this._internalState === RoomInternalState.CREATING) {\n throw new Error(\"cannot disconnect during onCreate()\");\n }\n\n this._internalState = RoomInternalState.DISPOSING;\n this.listing.remove();\n\n this.#_autoDispose = true;\n\n const delayedDisconnection = new Promise<void>((resolve) =>\n this._events.once('disconnect', () => resolve()));\n\n // reject pending reconnections\n for (const [_, reconnection] of Object.values(this._reconnections)) {\n reconnection.reject(new Error(\"disconnecting\"));\n }\n\n let numClients = this.clients.length;\n if (numClients > 0) {\n // clients may have `async onLeave`, room will be disposed after they're fulfilled\n while (numClients--) {\n this._forciblyCloseClient(this.clients[numClients] as Client & ClientPrivate, closeCode);\n }\n\n } else {\n // no clients connected, dispose immediately.\n this._events.emit('dispose');\n }\n\n return delayedDisconnection;\n }\n\n public async ['_onJoin'](client: Client & ClientPrivate, authContext: AuthContext) {\n const sessionId = client.sessionId;\n\n // generate unique private reconnection token\n client.reconnectionToken = generateId();\n\n if (this.reservedSeatTimeouts[sessionId]) {\n clearTimeout(this.reservedSeatTimeouts[sessionId]);\n delete this.reservedSeatTimeouts[sessionId];\n }\n\n // clear auto-dispose timeout.\n if (this._autoDisposeTimeout) {\n clearTimeout(this._autoDisposeTimeout);\n this._autoDisposeTimeout = undefined;\n }\n\n // get seat reservation options and clear it\n const [joinOptions, authData, isConsumed, isWaitingReconnection] = this.reservedSeats[sessionId];\n\n //\n // TODO: remove this check on 1.0.0\n // - the seat reservation is used to keep track of number of clients and their pending seats (see `hasReachedMaxClients`)\n // - when we fully migrate to static onAuth(), the seat reservation can be removed immediately here\n // - if async onAuth() is in use, the seat reservation is removed after onAuth() is fulfilled.\n // - mark reservation as \"consumed\"\n //\n if (isConsumed) {\n throw new ServerError(ErrorCode.MATCHMAKE_EXPIRED, \"already consumed\");\n }\n this.reservedSeats[sessionId][2] = true; // flag seat reservation as \"consumed\"\n debugMatchMaking('consuming seat reservation, sessionId: \\'%s\\'', client.sessionId);\n\n // share \"after next patch queue\" reference with every client.\n client._afterNextPatchQueue = this._afterNextPatchQueue;\n\n // add temporary callback to keep track of disconnections during `onJoin`.\n client.ref['onleave'] = (_) => client.state = ClientState.LEAVING;\n client.ref.once('close', client.ref['onleave']);\n\n if (isWaitingReconnection) {\n const previousReconnectionToken = this._reconnectingSessionId.get(sessionId);\n if (previousReconnectionToken) {\n this.clients.push(client);\n //\n // await for reconnection:\n // (end user may customize the reconnection token at this step)\n //\n await this._reconnections[previousReconnectionToken]?.[1].resolve(client);\n\n } else {\n const errorMessage = (process.env.NODE_ENV === 'production')\n ? \"already consumed\" // trick possible fraudsters...\n : \"bad reconnection token\" // ...or developers\n throw new ServerError(ErrorCode.MATCHMAKE_EXPIRED, errorMessage);\n }\n\n } else {\n try {\n if (authData) {\n client.auth = authData;\n\n } else if (this.onAuth !== Room.prototype.onAuth) {\n try {\n client.auth = await this.onAuth(client, joinOptions, authContext);\n\n if (!client.auth) {\n throw new ServerError(ErrorCode.AUTH_FAILED, 'onAuth failed');\n }\n\n } catch (e) {\n // remove seat reservation\n delete this.reservedSeats[sessionId];\n await this._decrementClientCount();\n throw e;\n }\n }\n\n //\n // On async onAuth, client may have been disconnected.\n //\n if (client.state === ClientState.LEAVING) {\n throw new ServerError(Protocol.WS_CLOSE_GOING_AWAY, 'already disconnected');\n }\n\n this.clients.push(client);\n\n //\n // Flag sessionId as non-enumarable so hasReachedMaxClients() doesn't count it\n // (https://github.com/colyseus/colyseus/issues/726)\n //\n Object.defineProperty(this.reservedSeats, sessionId, {\n value: this.reservedSeats[sessionId],\n enumerable: false,\n });\n\n if (this.onJoin) {\n await this.onJoin(client, joinOptions, client.auth);\n }\n\n // @ts-ignore: client left during `onJoin`, call _onLeave immediately.\n if (client.state === ClientState.LEAVING) {\n throw new Error(\"early_leave\");\n\n } else {\n // remove seat reservation\n delete this.reservedSeats[sessionId];\n\n // emit 'join' to room handler\n this._events.emit('join', client);\n }\n\n } catch (e) {\n await this._onLeave(client, Protocol.WS_CLOSE_GOING_AWAY);\n\n // remove seat reservation\n delete this.reservedSeats[sessionId];\n\n // make sure an error code is provided.\n if (!e.code) {\n e.code = ErrorCode.APPLICATION_ERROR;\n }\n\n throw e;\n }\n }\n\n // state might already be ClientState.LEAVING here\n if (client.state === ClientState.JOINING) {\n client.ref.removeListener('close', client.ref['onleave']);\n\n // only bind _onLeave after onJoin has been successful\n client.ref['onleave'] = this._onLeave.bind(this, client);\n client.ref.once('close', client.ref['onleave']);\n\n // allow client to send messages after onJoin has succeeded.\n client.ref.on('message', this._onMessage.bind(this, client));\n\n // confirm room id that matches the room name requested to join\n client.raw(getMessageBytes[Protocol.JOIN_ROOM](\n client.reconnectionToken,\n this._serializer.id,\n this._serializer.handshake && this._serializer.handshake(),\n ));\n }\n }\n\n /**\n * Allow the specified client to reconnect into the room. Must be used inside `onLeave()` method.\n * If seconds is provided, the reconnection is going to be cancelled after the provided amount of seconds.\n *\n * @param previousClient - The client which is to be waiting until re-connection happens.\n * @param seconds - Timeout period on re-connection in seconds.\n *\n * @returns Deferred<Client> - The differed is a promise like type.\n * This type can forcibly reject the promise by calling `.reject()`.\n */\n public allowReconnection(previousClient: Client, seconds: number | \"manual\"): Deferred<Client> {\n //\n // Return rejected promise if client has never fully JOINED.\n //\n // (having `_enqueuedMessages !== undefined` means that the client has never been at \"ClientState.JOINED\" state)\n //\n if ((previousClient as unknown as ClientPrivate)._enqueuedMessages !== undefined) {\n // @ts-ignore\n return Promise.reject(new Error(\"not joined\"));\n }\n\n if (seconds === undefined) { // TODO: remove this check\n console.warn(\"DEPRECATED: allowReconnection() requires a second argument. Using \\\"manual\\\" mode.\");\n seconds = \"manual\";\n }\n\n if (seconds === \"manual\") {\n seconds = Infinity;\n }\n\n if (this._internalState === RoomInternalState.DISPOSING) {\n // @ts-ignore\n return Promise.reject(new Error(\"disposing\"));\n }\n\n const sessionId = previousClient.sessionId;\n const reconnectionToken = previousClient.reconnectionToken;\n\n this._reserveSeat(sessionId, true, previousClient.auth, seconds, true);\n\n // keep reconnection reference in case the user reconnects into this room.\n const reconnection = new Deferred<Client & ClientPrivate>();\n this._reconnections[reconnectionToken] = [sessionId, reconnection];\n\n if (seconds !== Infinity) {\n // expire seat reservation after timeout\n this.reservedSeatTimeouts[sessionId] = setTimeout(() =>\n reconnection.reject(false), seconds * 1000);\n }\n\n const cleanup = () => {\n delete this._reconnections[reconnectionToken];\n delete this.reservedSeats[sessionId];\n delete this.reservedSeatTimeouts[sessionId];\n this._reconnectingSessionId.delete(sessionId);\n };\n\n reconnection.\n then((newClient) => {\n newClient.auth = previousClient.auth;\n newClient.userData = previousClient.userData;\n previousClient.ref = newClient.ref; // swap \"ref\" for convenience\n previousClient.state = ClientState.RECONNECTED;\n clearTimeout(this.reservedSeatTimeouts[sessionId]);\n cleanup();\n }).\n catch(() => {\n cleanup();\n this.resetAutoDisposeTimeout();\n });\n\n return reconnection;\n }\n\n protected resetAutoDisposeTimeout(timeoutInSeconds: number = 1) {\n clearTimeout(this._autoDisposeTimeout);\n\n if (!this.#_autoDispose) {\n return;\n }\n\n this._autoDisposeTimeout = setTimeout(() => {\n this._autoDisposeTimeout = undefined;\n this._disposeIfEmpty();\n }, timeoutInSeconds * 1000);\n }\n\n private broadcastMessageType(type: number | string, message?: any | Uint8Array, options: IBroadcastOptions = {}) {\n debugMessage(\"broadcast: %O\", message);\n\n const encodedMessage = (message instanceof Uint8Array)\n ? getMessageBytes.raw(Protocol.ROOM_DATA_BYTES, type, undefined, message)\n : getMessageBytes.raw(Protocol.ROOM_DATA, type, message)\n\n const except = (typeof (options.except) !== \"undefined\")\n ? Array.isArray(options.except)\n ? options.except\n : [options.except]\n : undefined;\n\n let numClients = this.clients.length;\n while (numClients--) {\n const client = this.clients[numClients];\n\n if (!except || !except.includes(client)) {\n client.enqueueRaw(encodedMessage);\n }\n }\n }\n\n protected sendFullState(client: Client): void {\n client.raw(this._serializer.getFullState(client));\n }\n\n protected _dequeueAfterPatchMessages() {\n const length = this._afterNextPatchQueue.length;\n\n if (length > 0) {\n for (let i = 0; i < length; i++) {\n const [target, args] = this._afterNextPatchQueue[i];\n\n if (target === \"broadcast\") {\n this.broadcast.apply(this, args);\n\n } else {\n (target as Client).raw.apply(target, args);\n }\n }\n\n // new messages may have been added in the meantime,\n // let's splice the ones that have been processed\n this._afterNextPatchQueue.splice(0, length);\n }\n }\n\n protected async _reserveSeat(\n sessionId: string,\n joinOptions: any = true,\n authData: any = undefined,\n seconds: number = this.seatReservationTime,\n allowReconnection: boolean = false,\n devModeReconnection?: boolean,\n ) {\n if (!allowReconnection && this.hasReachedMaxClients()) {\n return false;\n }\n\n this.reservedSeats[sessionId] = [joinOptions, authData, false, allowReconnection];\n\n if (!allowReconnection) {\n await this._incrementClientCount();\n\n this.reservedSeatTimeouts[sessionId] = setTimeout(async () => {\n delete this.reservedSeats[sessionId];\n delete this.reservedSeatTimeouts[sessionId];\n await this._decrementClientCount();\n }, seconds * 1000);\n\n this.resetAutoDisposeTimeout(seconds);\n }\n\n //\n // isDevMode workaround to allow players to reconnect on devMode\n //\n if (devModeReconnection) {\n this._reconnectingSessionId.set(sessionId, sessionId);\n }\n\n return true;\n }\n\n protected _disposeIfEmpty() {\n const willDispose = (\n this.#_onLeaveConcurrent === 0 && // no \"onLeave\" calls in progress\n this.#_autoDispose &&\n this._autoDisposeTimeout === undefined &&\n this.clients.length === 0 &&\n Object.keys(this.reservedSeats).length === 0\n );\n\n if (willDispose) {\n this._events.emit('dispose');\n }\n\n return willDispose;\n }\n\n protected async _dispose(): Promise<any> {\n this._internalState = RoomInternalState.DISPOSING;\n\n this.listing.remove();\n\n let userReturnData;\n if (this.onDispose) {\n userReturnData = this.onDispose();\n }\n\n if (this.#_patchInterval) {\n clearInterval(this.#_patchInterval);\n this.#_patchInterval = undefined;\n }\n\n if (this._simulationInterval) {\n clearInterval(this._simulationInterval);\n this._simulationInterval = undefined;\n }\n\n if (this._autoDisposeTimeout) {\n clearInterval(this._autoDisposeTimeout);\n this._autoDisposeTimeout = undefined;\n }\n\n // clear all timeouts/intervals + force to stop ticking\n this.clock.clear();\n this.clock.stop();\n\n return await (userReturnData || Promise.resolve());\n }\n\n protected _onMessage(client: Client & ClientPrivate, buffer: Buffer) {\n // skip if client is on LEAVING state.\n if (client.state === ClientState.LEAVING) { return; }\n\n const it: Iterator = { offset: 1 };\n const code = buffer[0];\n\n if (!buffer) {\n debugAndPrintError(`${this.roomName} (${this.roomId}), couldn't decode message: ${buffer}`);\n return;\n }\n\n if (code === Protocol.ROOM_DATA) {\n const messageType = (decode.stringCheck(buffer, it))\n ? decode.string(buffer, it)\n : decode.number(buffer, it);\n const messageTypeHandler = this.onMessageHandlers[messageType];\n\n let message;\n try {\n message = (buffer.byteLength > it.offset)\n ? unpack(buffer.subarray(it.offset, buffer.byteLength))\n : undefined;\n debugMessage(\"received: '%s' -> %j\", messageType, message);\n\n // custom message validation\n if (messageTypeHandler?.validate !== undefined) {\n message = messageTypeHandler.validate(message);\n }\n\n } catch (e) {\n debugAndPrintError(e);\n client.leave(Protocol.WS_CLOSE_WITH_ERROR);\n return;\n }\n\n if (messageTypeHandler) {\n messageTypeHandler.callback(client, message);\n\n } else {\n (this.onMessageHandlers['*'] || this.onMessageHandlers['__no_message_handler']).callback(client, messageType, message);\n }\n\n } else if (code === Protocol.ROOM_DATA_BYTES) {\n const messageType = (decode.stringCheck(buffer, it))\n ? decode.string(buffer, it)\n : decode.number(buffer, it);\n const messageTypeHandler = this.onMessageHandlers[messageType];\n\n let message = buffer.subarray(it.offset, buffer.byteLength);\n debugMessage(\"received: '%s' -> %j\", messageType, message);\n\n // custom message validation\n if (messageTypeHandler?.validate !== undefined) {\n message = messageTypeHandler.validate(message);\n }\n\n if (messageTypeHandler) {\n messageTypeHandler.callback(client, message);\n\n } else {\n (this.onMessageHandlers['*'] || this.onMessageHandlers['__no_message_handler']).callback(client, messageType, message);\n }\n\n } else if (code === Protocol.JOIN_ROOM && client.state === ClientState.JOINING) {\n // join room has been acknowledged by the client\n client.state = ClientState.JOINED;\n client._joinedAt = this.clock.elapsedTime;\n\n // send current state when new client joins the room\n if (this.state) {\n this.sendFullState(client);\n }\n\n // dequeue messages sent before client has joined effectively (on user-defined `onJoin`)\n if (client._enqueuedMessages.length > 0) {\n client._enqueuedMessages.forEach((enqueued) => client.raw(enqueued));\n }\n delete client._enqueuedMessages;\n\n } else if (code === Protocol.LEAVE_ROOM) {\n this._forciblyCloseClient(client, Protocol.WS_CLOSE_CONSENTED);\n }\n\n }\n\n protected _forciblyCloseClient(client: Client & ClientPrivate, closeCode: number) {\n // stop receiving messages from this client\n client.ref.removeAllListeners('message');\n\n // prevent \"onLeave\" from being called twice if player asks to leave\n client.ref.removeListener('close', client.ref['onleave']);\n\n // only effectively close connection when \"onLeave\" is fulfilled\n this._onLeave(client, closeCode).then(() => client.leave(closeCode));\n }\n\n protected async _onLeave(client: Client, code?: number): Promise<any> {\n debugMatchMaking('onLeave, sessionId: \\'%s\\'', client.sessionId);\n\n // call 'onLeave' method only if the client has been successfully accepted.\n client.state = ClientState.LEAVING;\n\n if (!this.clients.delete(client)) {\n // skip if client already left the room\n return;\n }\n\n if (this.onLeave) {\n try {\n this.#_onLeaveConcurrent++;\n await this.onLeave(client, (code === Protocol.WS_CLOSE_CONSENTED));\n\n } catch (e) {\n debugAndPrintError(`onLeave error: ${(e && e.message || e || 'promise rejected')}`);\n\n } finally {\n this.#_onLeaveConcurrent--;\n }\n }\n\n // check for manual \"reconnection\" flow\n if (this._reconnections[client.reconnectionToken]) {\n this._reconnections[client.reconnectionToken][1].catch(async () => {\n await this._onAfterLeave(client);\n });\n\n // @ts-ignore (client.state may be modified at onLeave())\n } else if (client.state !== ClientState.RECONNECTED) {\n await this._onAfterLeave(client);\n }\n }\n\n protected async _onAfterLeave(client: Client) {\n // try to dispose immediately if client reconnection isn't set up.\n const willDispose = await this._decrementClientCount();\n\n // trigger 'leave' only if seat reservation has been fully consumed\n if (this.reservedSeats[client.sessionId] === undefined) {\n this._events.emit('leave', client, willDispose);\n }\n\n }\n\n protected async _incrementClientCount() {\n // lock automatically when maxClients is reached\n if (!this.#_locked && this.hasReachedMaxClients()) {\n this.#_maxClientsReached = true;\n this.lock.call(this, true);\n }\n\n await this.listing.updateOne({\n $inc: { clients: 1 },\n $set: { locked: this.#_locked },\n });\n }\n\n protected async _decrementClientCount() {\n const willDispose = this._disposeIfEmpty();\n\n if (this._internalState === RoomInternalState.DISPOSING) {\n return true;\n }\n\n // unlock if room is available for new connections\n if (!willDispose) {\n if (this.#_maxClientsReached && !this._lockedExplicitly) {\n this.#_maxClientsReached = false;\n this.unlock.call(this, true);\n }\n\n // update room listing cache\n await this.listing.updateOne({\n $inc: { clients: -1 },\n $set: { locked: this.#_locked },\n });\n }\n\n return willDispose;\n }\n\n #registerUncaughtExceptionHandlers() {\n const onUncaughtException = this.onUncaughtException.bind(this);\n const originalSetTimeout = this.clock.setTimeout;\n this.clock.setTimeout = (cb, timeout, ...args) => {\n return originalSetTimeout.call(this.clock, wrapTryCatch(cb, onUncaughtException, TimedEventException, 'setTimeout'), timeout, ...args);\n };\n\n const originalSetInterval = this.clock.setInterval;\n this.clock.setInterval = (cb, timeout, ...args) => {\n return originalSetInterval.call(this.clock, wrapTryCatch(cb, onUncaughtException, TimedEventException, 'setInterval'), timeout, ...args);\n };\n\n if (this.onCreate !== undefined) {\n this.onCreate = wrapTryCatch(this.onCreate.bind(this), onUncaughtException, OnCreateException, 'onCreate', true);\n }\n\n if (this.onAuth !== undefined) {\n this.onAuth = wrapTryCatch(this.onAuth.bind(this), onUncaughtException, OnAuthException, 'onAuth', true);\n }\n\n if (this.onJoin !== undefined) {\n this.onJoin = wrapTryCatch(this.onJoin.bind(this), onUncaughtException, OnJoinException, 'onJoin', true);\n }\n\n if (this.onLeave !== undefined) {\n this.onLeave = wrapTryCatch(this.onLeave.bind(this), onUncaughtException, OnLeaveException, 'onLeave', true);\n }\n\n if (this.onDispose !== undefined) {\n this.onDispose = wrapTryCatch(this.onDispose.bind(this), onUncaughtException, OnDisposeException, 'onDispose');\n }\n }\n\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,cAAc;AACvB,SAAS,QAAkB,gBAAgB;AAE3C,OAAO,WAAW;AAClB,SAAS,oBAAoB;AAC7B,SAAS,cAAc;AAIvB,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AAGjC,SAAS,WAAW,iBAAiB,gBAAgB;AACrD,SAAS,UAAU,YAAY,oBAAoB;AACnD,SAAS,iBAAiB;AAE1B,SAAS,oBAAoB,kBAAkB,oBAAoB;AAEnE,SAAS,mBAAmB;AAC5B,SAA6C,aAAa,mBAAiC;AAC3F,SAAS,iBAAiB,mBAAmB,oBAAoB,iBAAiB,kBAAkB,oBAAmC,6BAA6B,2BAA2B;AAE/L,IAAM,qBAAqB,MAAO;AAClC,IAAM,8BAA8B,MAAO;AAC3C,IAAM,iBAAiB,IAAI,eAAe;AAEnC,I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KAAK,IAAI,GAAG,qBAAqB,iBAAiB,UAAU,IAAI;AAAA,IACzG;AAEA,QAAI,KAAK,WAAW,QAAW;AAC7B,WAAK,SAAS,aAAa,KAAK,OAAO,KAAK,IAAI,GAAG,qBAAqB,iBAAiB,UAAU,IAAI;AAAA,IACzG;AAEA,QAAI,KAAK,YAAY,QAAW;AAC9B,WAAK,UAAU,aAAa,KAAK,QAAQ,KAAK,IAAI,GAAG,qBAAqB,kBAAkB,WAAW,IAAI;AAAA,IAC7G;AAEA,QAAI,KAAK,cAAc,QAAW;AAChC,WAAK,YAAY,aAAa,KAAK,UAAU,KAAK,IAAI,GAAG,qBAAqB,oBAAoB,WAAW;AAAA,IAC/G;AAAA,EACF;AAEF;",
|
|
6
6
|
"names": ["RoomInternalState"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colyseus/core",
|
|
3
|
-
"version": "0.16.0-preview.
|
|
3
|
+
"version": "0.16.0-preview.37",
|
|
4
4
|
"description": "Multiplayer Framework for Node.js.",
|
|
5
5
|
"input": "./src/index.ts",
|
|
6
6
|
"main": "./build/index.js",
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
"node": ">= 18.x"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@colyseus/timer": "^1.0.
|
|
40
|
+
"@colyseus/timer": "^1.0.1",
|
|
41
41
|
"@colyseus/msgpackr": "^1.10.3",
|
|
42
42
|
"debug": "^4.3.4",
|
|
43
43
|
"nanoid": "^2.0.0",
|
|
44
|
-
"@colyseus/greeting-banner": "^2.0.
|
|
44
|
+
"@colyseus/greeting-banner": "^2.0.5"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/nanoid": "^2.0.0"
|