@colyseus/sdk 0.17.25 → 0.17.27
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/LICENSE +1 -2
- package/build/3rd_party/discord.cjs +1 -1
- package/build/3rd_party/discord.mjs +1 -1
- package/build/Auth.cjs +1 -1
- package/build/Auth.mjs +1 -1
- package/build/Client.cjs +1 -1
- package/build/Client.mjs +1 -1
- package/build/Connection.cjs +1 -1
- package/build/Connection.mjs +1 -1
- package/build/HTTP.cjs +1 -1
- package/build/HTTP.mjs +1 -1
- package/build/Room.cjs +17 -11
- package/build/Room.cjs.map +1 -1
- package/build/Room.mjs +17 -11
- package/build/Room.mjs.map +1 -1
- package/build/Storage.cjs +1 -1
- package/build/Storage.mjs +1 -1
- package/build/core/nanoevents.cjs +1 -1
- package/build/core/nanoevents.mjs +1 -1
- package/build/core/signal.cjs +1 -1
- package/build/core/signal.mjs +1 -1
- package/build/core/utils.cjs +1 -1
- package/build/core/utils.mjs +1 -1
- package/build/debug.cjs +1 -1
- package/build/debug.mjs +1 -1
- package/build/errors/Errors.cjs +1 -1
- package/build/errors/Errors.mjs +1 -1
- package/build/index.cjs +1 -1
- package/build/index.mjs +1 -1
- package/build/legacy.cjs +1 -1
- package/build/legacy.mjs +1 -1
- package/build/serializer/NoneSerializer.cjs +1 -1
- package/build/serializer/NoneSerializer.mjs +1 -1
- package/build/serializer/SchemaSerializer.cjs +1 -1
- package/build/serializer/SchemaSerializer.mjs +1 -1
- package/build/serializer/Serializer.cjs +1 -1
- package/build/serializer/Serializer.mjs +1 -1
- package/build/transport/H3Transport.cjs +1 -1
- package/build/transport/H3Transport.mjs +1 -1
- package/build/transport/WebSocketTransport.cjs +1 -1
- package/build/transport/WebSocketTransport.mjs +1 -1
- package/dist/colyseus-cocos-creator.js +18 -11
- package/dist/colyseus-cocos-creator.js.map +1 -1
- package/dist/colyseus.js +18 -11
- package/dist/colyseus.js.map +1 -1
- package/dist/debug.js +17 -11
- package/dist/debug.js.map +1 -1
- package/package.json +9 -9
- package/src/Room.ts +17 -9
- package/README.md +0 -27
- package/build/HTTP_bkp.d.ts +0 -18
- package/build/Protocol.cjs +0 -34
- package/build/Protocol.cjs.map +0 -1
- package/build/Protocol.d.ts +0 -21
- package/build/Protocol.mjs +0 -34
- package/build/Protocol.mjs.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright (c) 2015-
|
|
1
|
+
Copyright (c) 2015-2026 Endel Dreyer
|
|
2
2
|
|
|
3
3
|
MIT License:
|
|
4
4
|
|
|
@@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
21
|
THE SOFTWARE.
|
|
22
|
-
|
package/build/Auth.cjs
CHANGED
package/build/Auth.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// This software is released under the MIT License.
|
|
4
4
|
// https://opensource.org/license/MIT
|
|
5
5
|
//
|
|
6
|
-
// colyseus.js@0.17.
|
|
6
|
+
// colyseus.js@0.17.27
|
|
7
7
|
import { getItem, removeItem, setItem } from './Storage.mjs';
|
|
8
8
|
import { createNanoEvents } from './core/nanoevents.mjs';
|
|
9
9
|
|
package/build/Client.cjs
CHANGED
package/build/Client.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// This software is released under the MIT License.
|
|
4
4
|
// https://opensource.org/license/MIT
|
|
5
5
|
//
|
|
6
|
-
// colyseus.js@0.17.
|
|
6
|
+
// colyseus.js@0.17.27
|
|
7
7
|
import { Protocol, CloseCode } from '@colyseus/shared-types';
|
|
8
8
|
import { ServerError, MatchMakeError } from './errors/Errors.mjs';
|
|
9
9
|
import { Room } from './Room.mjs';
|
package/build/Connection.cjs
CHANGED
package/build/Connection.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// This software is released under the MIT License.
|
|
4
4
|
// https://opensource.org/license/MIT
|
|
5
5
|
//
|
|
6
|
-
// colyseus.js@0.17.
|
|
6
|
+
// colyseus.js@0.17.27
|
|
7
7
|
import { H3TransportTransport } from './transport/H3Transport.mjs';
|
|
8
8
|
import { WebSocketTransport } from './transport/WebSocketTransport.mjs';
|
|
9
9
|
import { CloseCode } from '@colyseus/shared-types';
|
package/build/HTTP.cjs
CHANGED
package/build/HTTP.mjs
CHANGED
package/build/Room.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// This software is released under the MIT License.
|
|
4
4
|
// https://opensource.org/license/MIT
|
|
5
5
|
//
|
|
6
|
-
// colyseus.js@0.17.
|
|
6
|
+
// colyseus.js@0.17.27
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
9
|
var tslib = require('tslib');
|
|
@@ -55,7 +55,10 @@ class Room {
|
|
|
55
55
|
serializer.state = state;
|
|
56
56
|
serializer.decoder = new schema.Decoder(state);
|
|
57
57
|
}
|
|
58
|
-
this.onLeave(() =>
|
|
58
|
+
this.onLeave(() => {
|
|
59
|
+
this.removeAllListeners();
|
|
60
|
+
this.destroy();
|
|
61
|
+
});
|
|
59
62
|
}
|
|
60
63
|
connect(endpoint, options, headers) {
|
|
61
64
|
var _a;
|
|
@@ -77,7 +80,6 @@ class Room {
|
|
|
77
80
|
}
|
|
78
81
|
else {
|
|
79
82
|
this.onLeave.invoke(e.code, e.reason);
|
|
80
|
-
this.destroy();
|
|
81
83
|
}
|
|
82
84
|
};
|
|
83
85
|
this.connection.events.onerror = (e) => {
|
|
@@ -94,7 +96,7 @@ class Room {
|
|
|
94
96
|
this.connection.connect(url.origin, Object.assign(Object.assign({}, options), { skipHandshake }));
|
|
95
97
|
}
|
|
96
98
|
else {
|
|
97
|
-
this.connection.connect(`${endpoint}${skipHandshake ? "
|
|
99
|
+
this.connection.connect(`${endpoint}${skipHandshake ? "&skipHandshake=1" : ""}`, headers);
|
|
98
100
|
}
|
|
99
101
|
}
|
|
100
102
|
leave(consented = true) {
|
|
@@ -203,6 +205,8 @@ class Room {
|
|
|
203
205
|
this.onStateChange.clear();
|
|
204
206
|
this.onError.clear();
|
|
205
207
|
this.onLeave.clear();
|
|
208
|
+
this.onReconnect.clear();
|
|
209
|
+
this.onDrop.clear();
|
|
206
210
|
this.onMessageHandlers.events = {};
|
|
207
211
|
if (this.serializer instanceof SchemaSerializer.SchemaSerializer) {
|
|
208
212
|
// Remove callback references
|
|
@@ -314,6 +318,7 @@ class Room {
|
|
|
314
318
|
handleReconnection() {
|
|
315
319
|
if (Date.now() - this.joinedAtTime < this.reconnection.minUptime) {
|
|
316
320
|
console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x274C)} Room has not been up for long enough for automatic reconnection. (min uptime: ${this.reconnection.minUptime}ms)`); // ❌
|
|
321
|
+
this.onLeave.invoke(sharedTypes.CloseCode.ABNORMAL_CLOSURE, "Room uptime too short for reconnection.");
|
|
317
322
|
return;
|
|
318
323
|
}
|
|
319
324
|
if (!this.reconnection.isReconnecting) {
|
|
@@ -323,6 +328,13 @@ class Room {
|
|
|
323
328
|
this.retryReconnection();
|
|
324
329
|
}
|
|
325
330
|
retryReconnection() {
|
|
331
|
+
if (this.reconnection.retryCount >= this.reconnection.maxRetries) {
|
|
332
|
+
// No more retries
|
|
333
|
+
console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x274C)} ❌ Reconnection failed after ${this.reconnection.maxRetries} attempts.`); // ❌
|
|
334
|
+
this.reconnection.isReconnecting = false;
|
|
335
|
+
this.onLeave.invoke(sharedTypes.CloseCode.FAILED_TO_RECONNECT, "No more retries. Reconnection failed.");
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
326
338
|
this.reconnection.retryCount++;
|
|
327
339
|
const delay = Math.min(this.reconnection.maxDelay, Math.max(this.reconnection.minDelay, this.reconnection.backoff(this.reconnection.retryCount, this.reconnection.delay)));
|
|
328
340
|
console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x023F3)} will retry in ${(delay / 1000).toFixed(1)} seconds...`); // 🔄
|
|
@@ -336,13 +348,7 @@ class Room {
|
|
|
336
348
|
});
|
|
337
349
|
}
|
|
338
350
|
catch (e) {
|
|
339
|
-
|
|
340
|
-
if (this.reconnection.retryCount < this.reconnection.maxRetries) {
|
|
341
|
-
this.retryReconnection();
|
|
342
|
-
}
|
|
343
|
-
else {
|
|
344
|
-
console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x274C)} Failed to reconnect. Is your server running? Please check server logs.`); // ❌
|
|
345
|
-
}
|
|
351
|
+
this.retryReconnection();
|
|
346
352
|
}
|
|
347
353
|
}, delay);
|
|
348
354
|
}
|
package/build/Room.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Room.cjs","sources":["../src/Room.ts"],"sourcesContent":["import { CloseCode, Protocol, type InferState, type NormalizeRoomType, type ExtractRoomMessages, type ExtractRoomClientMessages, type ExtractMessageType } from '@colyseus/shared-types';\nimport { decode, Decoder, encode, Iterator, Schema } from '@colyseus/schema';\n\nimport { Packr, unpack } from '@colyseus/msgpackr';\n\nimport { Connection } from './Connection.ts';\nimport { getSerializer, Serializer } from './serializer/Serializer.ts';\n\n// The unused imports here are important for better `.d.ts` file generation\n// (Later merged with `dts-bundle-generator`)\nimport { createNanoEvents } from './core/nanoevents.ts';\nimport { createSignal } from './core/signal.ts';\n\nimport { SchemaConstructor, SchemaSerializer } from './serializer/SchemaSerializer.ts';\n\nimport { now } from './core/utils.ts';\n\n// Infer serializer type based on State: SchemaSerializer for Schema types, Serializer otherwise\nexport type InferSerializer<State> = [State] extends [Schema]\n ? SchemaSerializer<State>\n : Serializer<State>;\n\nexport interface RoomAvailable<Metadata = any> {\n name: string;\n roomId: string;\n clients: number;\n maxClients: number;\n metadata?: Metadata;\n}\n\nexport interface ReconnectionOptions {\n /**\n * The maximum number of reconnection attempts.\n */\n maxRetries: number;\n\n /**\n * The minimum delay between reconnection attempts.\n */\n minDelay: number;\n\n /**\n * The maximum delay between reconnection attempts.\n */\n maxDelay: number;\n\n /**\n * The minimum uptime of the room before reconnection attempts can be made.\n */\n minUptime: number;\n\n /**\n * The current number of reconnection attempts.\n */\n retryCount: number;\n\n /**\n * The initial delay between reconnection attempts.\n */\n delay: number;\n\n /**\n * The function to calculate the delay between reconnection attempts.\n * @param attempt - The current attempt number.\n * @param delay - The initial delay between reconnection attempts.\n * @returns The delay between reconnection attempts.\n */\n backoff: (attempt: number, delay: number) => number;\n\n /**\n * The maximum number of enqueued messages to buffer.\n */\n maxEnqueuedMessages: number;\n\n /**\n * Buffer for messages sent while connection is not open.\n * These messages will be sent once the connection is re-established.\n */\n enqueuedMessages: Array<{ data: Uint8Array }>;\n\n /**\n * Whether the room is currently reconnecting.\n */\n isReconnecting: boolean;\n}\n\nexport class Room<\n T = any,\n State = InferState<T, never>,\n> {\n public roomId: string;\n public sessionId: string;\n public reconnectionToken: string;\n\n public name: string;\n public connection: Connection;\n\n // Public signals\n public onStateChange = createSignal<(state: State) => void>();\n public onError = createSignal<(code: number, message?: string) => void>();\n public onLeave = createSignal<(code: number, reason?: string) => void>();\n\n public onReconnect = createSignal<() => void>();\n public onDrop = createSignal<(code: number, reason?: string) => void>();\n\n protected onJoin = createSignal();\n\n public serializerId: string;\n public serializer: InferSerializer<State>;\n\n // reconnection logic\n public reconnection: ReconnectionOptions = {\n retryCount: 0,\n maxRetries: 15,\n delay: 100,\n minDelay: 100,\n maxDelay: 5000,\n minUptime: 5000,\n backoff: exponentialBackoff,\n maxEnqueuedMessages: 10,\n enqueuedMessages: [],\n isReconnecting: false,\n };\n\n protected joinedAtTime: number = 0;\n\n protected onMessageHandlers = createNanoEvents();\n\n protected packr: Packr;\n\n #lastPingTime: number = 0;\n #pingCallback?: (ms: number) => void = undefined;\n\n constructor(name: string, rootSchema?: SchemaConstructor<State>) {\n this.name = name;\n\n this.packr = new Packr();\n\n // msgpackr workaround: force buffer to be created.\n this.packr.encode(undefined);\n\n if (rootSchema) {\n const serializer: SchemaSerializer = new (getSerializer(\"schema\"));\n this.serializer = serializer;\n\n const state: State = new rootSchema();\n serializer.state = state;\n serializer.decoder = new Decoder(state as Schema);\n }\n\n this.onLeave(() => this.removeAllListeners());\n }\n\n public connect(endpoint: string, options?: any, headers?: any) {\n this.connection = new Connection(options.protocol);\n this.connection.events.onmessage = this.onMessageCallback.bind(this);\n this.connection.events.onclose = (e: CloseEvent) => {\n if (this.joinedAtTime === 0) {\n console.warn?.(`Room connection was closed unexpectedly (${e.code}): ${e.reason}`);\n this.onError.invoke(e.code, e.reason);\n return;\n }\n\n if (\n e.code === CloseCode.NO_STATUS_RECEIVED ||\n e.code === CloseCode.ABNORMAL_CLOSURE ||\n e.code === CloseCode.GOING_AWAY ||\n e.code === CloseCode.MAY_TRY_RECONNECT\n ) {\n this.onDrop.invoke(e.code, e.reason);\n this.handleReconnection();\n\n } else {\n this.onLeave.invoke(e.code, e.reason);\n this.destroy();\n }\n };\n\n this.connection.events.onerror = (e: CloseEvent) => {\n this.onError.invoke(e.code, e.reason);\n };\n\n /**\n * if local serializer has state, it means we don't need to receive the\n * handshake from the server\n */\n const skipHandshake = (this.serializer?.getState() !== undefined);\n\n if (options.protocol === \"h3\") {\n // FIXME: refactor this.\n const url = new URL(endpoint);\n this.connection.connect(url.origin, { ...options, skipHandshake });\n\n } else {\n this.connection.connect(`${endpoint}${skipHandshake ? \"?skipHandshake=1\" : \"\"}`, headers);\n }\n\n }\n\n public leave(consented: boolean = true): Promise<number> {\n return new Promise((resolve) => {\n this.onLeave((code) => resolve(code));\n\n if (this.connection) {\n if (consented) {\n this.packr.buffer[0] = Protocol.LEAVE_ROOM;\n this.connection.send(this.packr.buffer.subarray(0, 1));\n\n } else {\n this.connection.close();\n }\n\n } else {\n this.onLeave.invoke(CloseCode.CONSENTED);\n }\n });\n }\n\n public onMessage<MessageType extends keyof ExtractRoomClientMessages<NormalizeRoomType<T>>>(\n message: MessageType,\n callback: (payload: ExtractRoomClientMessages<NormalizeRoomType<T>>[MessageType]) => void\n ): () => void\n public onMessage<Payload = any>(type: \"*\", callback: (messageType: string | number, payload: Payload) => void): () => void\n // Fallback overload: only available when no typed client messages are defined\n public onMessage<Payload = any>(\n type: [keyof ExtractRoomClientMessages<NormalizeRoomType<T>>] extends [never] ? (string | number) : never,\n callback: (payload: Payload) => void\n ): () => void\n public onMessage(type: '*' | string | number, callback: (...args: any[]) => void) {\n return this.onMessageHandlers.on(this.getMessageHandlerKey(type), callback);\n }\n\n public ping(callback: (ms: number) => void) {\n // skip if connection is not open\n if (!this.connection?.isOpen) {\n return;\n }\n\n this.#lastPingTime = now();\n this.#pingCallback = callback;\n this.packr.buffer[0] = Protocol.PING;\n this.connection.send(this.packr.buffer.subarray(0, 1));\n }\n\n public send<MessageType extends keyof ExtractRoomMessages<NormalizeRoomType<T>>>(\n messageType: MessageType,\n payload?: ExtractMessageType<ExtractRoomMessages<NormalizeRoomType<T>>[MessageType]>\n ): void\n // Fallback overload: only available when no typed messages are defined\n public send<Payload = any>(\n messageType: [keyof ExtractRoomMessages<NormalizeRoomType<T>>] extends [never] ? (string | number) : never,\n payload?: Payload\n ): void\n public send(messageType: string | number, payload?: any): void {\n const it: Iterator = { offset: 1 };\n this.packr.buffer[0] = Protocol.ROOM_DATA;\n\n if (typeof(messageType) === \"string\") {\n encode.string(this.packr.buffer as Buffer, messageType, it);\n\n } else {\n encode.number(this.packr.buffer as Buffer, messageType, it);\n }\n\n // force packr to use beginning of the buffer\n this.packr.position = 0;\n\n const data = (payload !== undefined)\n ? this.packr.pack(payload, 2048 + it.offset) // 2048 = RESERVE_START_SPACE\n : this.packr.buffer.subarray(0, it.offset);\n\n // If connection is not open, buffer the message\n if (!this.connection.isOpen) {\n enqueueMessage(this, new Uint8Array(data));\n } else {\n this.connection.send(data);\n }\n }\n\n public sendUnreliable<T = any>(type: string | number, message?: T): void {\n // If connection is not open, skip\n if (!this.connection.isOpen) { return; }\n\n const it: Iterator = { offset: 1 };\n this.packr.buffer[0] = Protocol.ROOM_DATA;\n\n if (typeof(type) === \"string\") {\n encode.string(this.packr.buffer as Buffer, type, it);\n\n } else {\n encode.number(this.packr.buffer as Buffer, type, it);\n }\n\n // force packr to use beginning of the buffer\n this.packr.position = 0;\n\n const data = (message !== undefined)\n ? this.packr.pack(message, 2048 + it.offset) // 2048 = RESERVE_START_SPACE\n : this.packr.buffer.subarray(0, it.offset);\n\n this.connection.sendUnreliable(data);\n }\n\n public sendBytes(type: string | number, bytes: Uint8Array) {\n const it: Iterator = { offset: 1 };\n this.packr.buffer[0] = Protocol.ROOM_DATA_BYTES;\n\n if (typeof(type) === \"string\") {\n encode.string(this.packr.buffer as Buffer, type, it);\n\n } else {\n encode.number(this.packr.buffer as Buffer, type, it);\n }\n\n // check if buffer needs to be resized\n // TODO: can we avoid this?\n if (bytes.byteLength + it.offset > this.packr.buffer.byteLength) {\n const newBuffer = new Uint8Array(it.offset + bytes.byteLength);\n newBuffer.set(this.packr.buffer);\n this.packr.useBuffer(newBuffer);\n }\n\n this.packr.buffer.set(bytes, it.offset);\n\n // If connection is not open, buffer the message\n if (!this.connection.isOpen) {\n enqueueMessage(this, this.packr.buffer.subarray(0, it.offset + bytes.byteLength));\n } else {\n this.connection.send(this.packr.buffer.subarray(0, it.offset + bytes.byteLength));\n }\n\n }\n\n public get state (): State {\n return this.serializer.getState();\n }\n\n public removeAllListeners() {\n this.onJoin.clear();\n this.onStateChange.clear();\n this.onError.clear();\n this.onLeave.clear();\n this.onMessageHandlers.events = {};\n\n if (this.serializer instanceof SchemaSerializer) {\n // Remove callback references\n this.serializer.decoder.root.callbacks = {};\n }\n }\n\n protected onMessageCallback(event: MessageEvent) {\n const buffer = new Uint8Array(event.data);\n\n const it: Iterator = { offset: 1 };\n const code = buffer[0];\n\n if (code === Protocol.JOIN_ROOM) {\n const reconnectionToken = decode.utf8Read(buffer as Buffer, it, buffer[it.offset++]);\n this.serializerId = decode.utf8Read(buffer as Buffer, it, buffer[it.offset++]);\n\n // Instantiate serializer if not locally available.\n if (!this.serializer) {\n const serializer = getSerializer(this.serializerId);\n this.serializer = new serializer();\n }\n\n // apply handshake on first join (no need to do this on reconnect)\n if (buffer.byteLength > it.offset && this.serializer.handshake) {\n this.serializer.handshake(buffer, it);\n }\n\n if (this.joinedAtTime === 0) {\n this.joinedAtTime = Date.now();\n this.onJoin.invoke();\n\n } else {\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x2705)} reconnection successful!`); // ✅\n this.reconnection.isReconnecting = false;\n this.onReconnect.invoke();\n }\n\n this.reconnectionToken = `${this.roomId}:${reconnectionToken}`;\n\n // acknowledge successfull JOIN_ROOM\n this.packr.buffer[0] = Protocol.JOIN_ROOM;\n this.connection.send(this.packr.buffer.subarray(0, 1));\n\n // Send any enqueued messages that were buffered while disconnected\n if (this.reconnection.enqueuedMessages.length > 0) {\n for (const message of this.reconnection.enqueuedMessages) {\n this.connection.send(message.data);\n }\n // Clear the buffer after sending\n this.reconnection.enqueuedMessages = [];\n }\n\n } else if (code === Protocol.ERROR) {\n const code = decode.number(buffer as Buffer, it);\n const message = decode.string(buffer as Buffer, it);\n\n this.onError.invoke(code, message);\n\n } else if (code === Protocol.LEAVE_ROOM) {\n this.leave();\n\n } else if (code === Protocol.ROOM_STATE) {\n this.serializer.setState(buffer, it);\n this.onStateChange.invoke(this.serializer.getState());\n\n } else if (code === Protocol.ROOM_STATE_PATCH) {\n this.serializer.patch(buffer, it);\n this.onStateChange.invoke(this.serializer.getState());\n\n } else if (code === Protocol.ROOM_DATA) {\n const type = (decode.stringCheck(buffer as Buffer, it))\n ? decode.string(buffer as Buffer, it)\n : decode.number(buffer as Buffer, it);\n\n const message = (buffer.byteLength > it.offset)\n ? unpack(buffer as Buffer, { start: it.offset })\n : undefined;\n\n this.dispatchMessage(type, message);\n\n } else if (code === Protocol.ROOM_DATA_BYTES) {\n const type = (decode.stringCheck(buffer as Buffer, it))\n ? decode.string(buffer as Buffer, it)\n : decode.number(buffer as Buffer, it);\n\n this.dispatchMessage(type, buffer.subarray(it.offset));\n\n } else if (code === Protocol.PING) {\n this.#pingCallback?.(Math.round(now() - this.#lastPingTime));\n this.#pingCallback = undefined;\n }\n }\n\n private dispatchMessage(type: string | number, message: any) {\n const messageType = this.getMessageHandlerKey(type);\n\n if (this.onMessageHandlers.events[messageType]) {\n this.onMessageHandlers.emit(messageType, message);\n\n } else if (this.onMessageHandlers.events['*']) {\n this.onMessageHandlers.emit('*', type, message);\n\n } else if (!messageType.startsWith(\"__\")) { // ignore internal messages\n console.warn?.(`@colyseus/sdk: onMessage() not registered for type '${type}'.`);\n }\n }\n\n private destroy () {\n if (this.serializer) {\n this.serializer.teardown();\n }\n }\n\n private getMessageHandlerKey(type: string | number): string {\n switch (typeof(type)) {\n // string\n case \"string\": return type;\n\n // number\n case \"number\": return `i${type}`;\n\n default: throw new Error(\"invalid message type.\");\n }\n }\n\n private handleReconnection() {\n if (Date.now() - this.joinedAtTime < this.reconnection.minUptime) {\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x274C)} Room has not been up for long enough for automatic reconnection. (min uptime: ${this.reconnection.minUptime}ms)`); // ❌\n return;\n }\n\n if (!this.reconnection.isReconnecting) {\n this.reconnection.retryCount = 0;\n this.reconnection.isReconnecting = true;\n }\n\n this.retryReconnection();\n }\n\n private retryReconnection() {\n this.reconnection.retryCount++;\n\n const delay = Math.min(this.reconnection.maxDelay, Math.max(this.reconnection.minDelay, this.reconnection.backoff(this.reconnection.retryCount, this.reconnection.delay)));\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x023F3)} will retry in ${(delay/1000).toFixed(1)} seconds...`); // 🔄\n\n // Wait before attempting reconnection\n setTimeout(() => {\n try {\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x1F504)} Re-establishing sessionId '${this.sessionId}' with roomId '${this.roomId}'... (attempt ${this.reconnection.retryCount} of ${this.reconnection.maxRetries})`); // 🔄\n this.connection.reconnect({\n reconnectionToken: this.reconnectionToken.split(\":\")[1],\n skipHandshake: true, // we already applied the handshake on first join\n });\n\n } catch (e) {\n console.log(\".reconnect() failed\", e);\n if (this.reconnection.retryCount < this.reconnection.maxRetries) {\n this.retryReconnection();\n } else {\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x274C)} Failed to reconnect. Is your server running? Please check server logs.`); // ❌\n }\n }\n }, delay);\n }\n}\n\nconst exponentialBackoff = (attempt: number, delay: number) => {\n return Math.floor(Math.pow(2, attempt) * delay);\n}\n\nfunction enqueueMessage(room: Room, message: Uint8Array) {\n room.reconnection.enqueuedMessages.push({ data: message });\n if (room.reconnection.enqueuedMessages.length > room.reconnection.maxEnqueuedMessages) {\n room.reconnection.enqueuedMessages.shift();\n }\n}"],"names":["createSignal","createNanoEvents","Packr","getSerializer","Decoder","Connection","CloseCode","Protocol","__classPrivateFieldSet","now","encode","SchemaSerializer","decode","unpack","__classPrivateFieldGet"],"mappings":";;;;;;;;;;;;;;;;;;;;MAsFa,IAAI,CAAA;IA+Cb,WAAA,CAAY,IAAY,EAAE,UAAqC,EAAA;;QAnCxD,IAAA,CAAA,aAAa,GAAGA,mBAAY,EAA0B;QACtD,IAAA,CAAA,OAAO,GAAGA,mBAAY,EAA4C;QAClE,IAAA,CAAA,OAAO,GAAGA,mBAAY,EAA2C;QAEjE,IAAA,CAAA,WAAW,GAAGA,mBAAY,EAAc;QACxC,IAAA,CAAA,MAAM,GAAGA,mBAAY,EAA2C;QAE7D,IAAA,CAAA,MAAM,GAAGA,mBAAY,EAAE;;AAM1B,QAAA,IAAA,CAAA,YAAY,GAAwB;AACvC,YAAA,UAAU,EAAE,CAAC;AACb,YAAA,UAAU,EAAE,EAAE;AACd,YAAA,KAAK,EAAE,GAAG;AACV,YAAA,QAAQ,EAAE,GAAG;AACb,YAAA,QAAQ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AY,CAAC,UAAU,EAAE;oBAC7D,IAAI,CAAC,iBAAiB,EAAE;gBAC5B;qBAAO;AACH,oBAAA,OAAO,CAAC,IAAI,CAAC,CAAA,yBAAA,EAA4B,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA,uEAAA,CAAyE,CAAC,CAAC;gBACpJ;YACJ;QACJ,CAAC,EAAE,KAAK,CAAC;IACb;AACH;;AAED,MAAM,kBAAkB,GAAG,CAAC,OAAe,EAAE,KAAa,KAAI;AAC1D,IAAA,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC;AACnD,CAAC;AAED,SAAS,cAAc,CAAC,IAAU,EAAE,OAAmB,EAAA;AACnD,IAAA,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAC1D,IAAA,IAAI,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,mBAAmB,EAAE;AACnF,QAAA,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,KAAK,EAAE;IAC9C;AACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"Room.cjs","sources":["../src/Room.ts"],"sourcesContent":["import { CloseCode, Protocol, type InferState, type NormalizeRoomType, type ExtractRoomMessages, type ExtractRoomClientMessages, type ExtractMessageType } from '@colyseus/shared-types';\nimport { decode, Decoder, encode, Iterator, Schema } from '@colyseus/schema';\n\nimport { Packr, unpack } from '@colyseus/msgpackr';\n\nimport { Connection } from './Connection.ts';\nimport { getSerializer, Serializer } from './serializer/Serializer.ts';\n\n// The unused imports here are important for better `.d.ts` file generation\n// (Later merged with `dts-bundle-generator`)\nimport { createNanoEvents } from './core/nanoevents.ts';\nimport { createSignal } from './core/signal.ts';\n\nimport { SchemaConstructor, SchemaSerializer } from './serializer/SchemaSerializer.ts';\n\nimport { now } from './core/utils.ts';\n\n// Infer serializer type based on State: SchemaSerializer for Schema types, Serializer otherwise\nexport type InferSerializer<State> = [State] extends [Schema]\n ? SchemaSerializer<State>\n : Serializer<State>;\n\nexport interface RoomAvailable<Metadata = any> {\n name: string;\n roomId: string;\n clients: number;\n maxClients: number;\n metadata?: Metadata;\n}\n\nexport interface ReconnectionOptions {\n /**\n * The maximum number of reconnection attempts.\n */\n maxRetries: number;\n\n /**\n * The minimum delay between reconnection attempts.\n */\n minDelay: number;\n\n /**\n * The maximum delay between reconnection attempts.\n */\n maxDelay: number;\n\n /**\n * The minimum uptime of the room before reconnection attempts can be made.\n */\n minUptime: number;\n\n /**\n * The current number of reconnection attempts.\n */\n retryCount: number;\n\n /**\n * The initial delay between reconnection attempts.\n */\n delay: number;\n\n /**\n * The function to calculate the delay between reconnection attempts.\n * @param attempt - The current attempt number.\n * @param delay - The initial delay between reconnection attempts.\n * @returns The delay between reconnection attempts.\n */\n backoff: (attempt: number, delay: number) => number;\n\n /**\n * The maximum number of enqueued messages to buffer.\n */\n maxEnqueuedMessages: number;\n\n /**\n * Buffer for messages sent while connection is not open.\n * These messages will be sent once the connection is re-established.\n */\n enqueuedMessages: Array<{ data: Uint8Array }>;\n\n /**\n * Whether the room is currently reconnecting.\n */\n isReconnecting: boolean;\n}\n\nexport class Room<\n T = any,\n State = InferState<T, never>,\n> {\n public roomId: string;\n public sessionId: string;\n public reconnectionToken: string;\n\n public name: string;\n public connection: Connection;\n\n // Public signals\n public onStateChange = createSignal<(state: State) => void>();\n public onError = createSignal<(code: number, message?: string) => void>();\n public onLeave = createSignal<(code: number, reason?: string) => void>();\n\n public onReconnect = createSignal<() => void>();\n public onDrop = createSignal<(code: number, reason?: string) => void>();\n\n protected onJoin = createSignal();\n\n public serializerId: string;\n public serializer: InferSerializer<State>;\n\n // reconnection logic\n public reconnection: ReconnectionOptions = {\n retryCount: 0,\n maxRetries: 15,\n delay: 100,\n minDelay: 100,\n maxDelay: 5000,\n minUptime: 5000,\n backoff: exponentialBackoff,\n maxEnqueuedMessages: 10,\n enqueuedMessages: [],\n isReconnecting: false,\n };\n\n protected joinedAtTime: number = 0;\n\n protected onMessageHandlers = createNanoEvents();\n\n protected packr: Packr;\n\n #lastPingTime: number = 0;\n #pingCallback?: (ms: number) => void = undefined;\n\n constructor(name: string, rootSchema?: SchemaConstructor<State>) {\n this.name = name;\n\n this.packr = new Packr();\n\n // msgpackr workaround: force buffer to be created.\n this.packr.encode(undefined);\n\n if (rootSchema) {\n const serializer: SchemaSerializer = new (getSerializer(\"schema\"));\n this.serializer = serializer;\n\n const state: State = new rootSchema();\n serializer.state = state;\n serializer.decoder = new Decoder(state as Schema);\n }\n\n this.onLeave(() => {\n this.removeAllListeners();\n this.destroy();\n });\n }\n\n public connect(endpoint: string, options?: any, headers?: any) {\n this.connection = new Connection(options.protocol);\n this.connection.events.onmessage = this.onMessageCallback.bind(this);\n this.connection.events.onclose = (e: CloseEvent) => {\n if (this.joinedAtTime === 0) {\n console.warn?.(`Room connection was closed unexpectedly (${e.code}): ${e.reason}`);\n this.onError.invoke(e.code, e.reason);\n return;\n }\n\n if (\n e.code === CloseCode.NO_STATUS_RECEIVED ||\n e.code === CloseCode.ABNORMAL_CLOSURE ||\n e.code === CloseCode.GOING_AWAY ||\n e.code === CloseCode.MAY_TRY_RECONNECT\n ) {\n this.onDrop.invoke(e.code, e.reason);\n this.handleReconnection();\n\n } else {\n this.onLeave.invoke(e.code, e.reason);\n }\n };\n\n this.connection.events.onerror = (e: CloseEvent) => {\n this.onError.invoke(e.code, e.reason);\n };\n\n /**\n * if local serializer has state, it means we don't need to receive the\n * handshake from the server\n */\n const skipHandshake = (this.serializer?.getState() !== undefined);\n\n if (options.protocol === \"h3\") {\n // FIXME: refactor this.\n const url = new URL(endpoint);\n this.connection.connect(url.origin, { ...options, skipHandshake });\n\n } else {\n this.connection.connect(`${endpoint}${skipHandshake ? \"&skipHandshake=1\" : \"\"}`, headers);\n }\n\n }\n\n public leave(consented: boolean = true): Promise<number> {\n return new Promise((resolve) => {\n this.onLeave((code) => resolve(code));\n\n if (this.connection) {\n if (consented) {\n this.packr.buffer[0] = Protocol.LEAVE_ROOM;\n this.connection.send(this.packr.buffer.subarray(0, 1));\n\n } else {\n this.connection.close();\n }\n\n } else {\n this.onLeave.invoke(CloseCode.CONSENTED);\n }\n });\n }\n\n public onMessage<MessageType extends keyof ExtractRoomClientMessages<NormalizeRoomType<T>>>(\n message: MessageType,\n callback: (payload: ExtractRoomClientMessages<NormalizeRoomType<T>>[MessageType]) => void\n ): () => void\n public onMessage<Payload = any>(type: \"*\", callback: (messageType: string | number, payload: Payload) => void): () => void\n // Fallback overload: only available when no typed client messages are defined\n public onMessage<Payload = any>(\n type: [keyof ExtractRoomClientMessages<NormalizeRoomType<T>>] extends [never] ? (string | number) : never,\n callback: (payload: Payload) => void\n ): () => void\n public onMessage(type: '*' | string | number, callback: (...args: any[]) => void) {\n return this.onMessageHandlers.on(this.getMessageHandlerKey(type), callback);\n }\n\n public ping(callback: (ms: number) => void) {\n // skip if connection is not open\n if (!this.connection?.isOpen) {\n return;\n }\n\n this.#lastPingTime = now();\n this.#pingCallback = callback;\n this.packr.buffer[0] = Protocol.PING;\n this.connection.send(this.packr.buffer.subarray(0, 1));\n }\n\n public send<MessageType extends keyof ExtractRoomMessages<NormalizeRoomType<T>>>(\n messageType: MessageType,\n payload?: ExtractMessageType<ExtractRoomMessages<NormalizeRoomType<T>>[MessageType]>\n ): void\n // Fallback overload: only available when no typed messages are defined\n public send<Payload = any>(\n messageType: [keyof ExtractRoomMessages<NormalizeRoomType<T>>] extends [never] ? (string | number) : never,\n payload?: Payload\n ): void\n public send(messageType: string | number, payload?: any): void {\n const it: Iterator = { offset: 1 };\n this.packr.buffer[0] = Protocol.ROOM_DATA;\n\n if (typeof(messageType) === \"string\") {\n encode.string(this.packr.buffer as Buffer, messageType, it);\n\n } else {\n encode.number(this.packr.buffer as Buffer, messageType, it);\n }\n\n // force packr to use beginning of the buffer\n this.packr.position = 0;\n\n const data = (payload !== undefined)\n ? this.packr.pack(payload, 2048 + it.offset) // 2048 = RESERVE_START_SPACE\n : this.packr.buffer.subarray(0, it.offset);\n\n // If connection is not open, buffer the message\n if (!this.connection.isOpen) {\n enqueueMessage(this, new Uint8Array(data));\n } else {\n this.connection.send(data);\n }\n }\n\n public sendUnreliable<T = any>(type: string | number, message?: T): void {\n // If connection is not open, skip\n if (!this.connection.isOpen) { return; }\n\n const it: Iterator = { offset: 1 };\n this.packr.buffer[0] = Protocol.ROOM_DATA;\n\n if (typeof(type) === \"string\") {\n encode.string(this.packr.buffer as Buffer, type, it);\n\n } else {\n encode.number(this.packr.buffer as Buffer, type, it);\n }\n\n // force packr to use beginning of the buffer\n this.packr.position = 0;\n\n const data = (message !== undefined)\n ? this.packr.pack(message, 2048 + it.offset) // 2048 = RESERVE_START_SPACE\n : this.packr.buffer.subarray(0, it.offset);\n\n this.connection.sendUnreliable(data);\n }\n\n public sendBytes(type: string | number, bytes: Uint8Array) {\n const it: Iterator = { offset: 1 };\n this.packr.buffer[0] = Protocol.ROOM_DATA_BYTES;\n\n if (typeof(type) === \"string\") {\n encode.string(this.packr.buffer as Buffer, type, it);\n\n } else {\n encode.number(this.packr.buffer as Buffer, type, it);\n }\n\n // check if buffer needs to be resized\n // TODO: can we avoid this?\n if (bytes.byteLength + it.offset > this.packr.buffer.byteLength) {\n const newBuffer = new Uint8Array(it.offset + bytes.byteLength);\n newBuffer.set(this.packr.buffer);\n this.packr.useBuffer(newBuffer);\n }\n\n this.packr.buffer.set(bytes, it.offset);\n\n // If connection is not open, buffer the message\n if (!this.connection.isOpen) {\n enqueueMessage(this, this.packr.buffer.subarray(0, it.offset + bytes.byteLength));\n } else {\n this.connection.send(this.packr.buffer.subarray(0, it.offset + bytes.byteLength));\n }\n\n }\n\n public get state (): State {\n return this.serializer.getState();\n }\n\n public removeAllListeners() {\n this.onJoin.clear();\n this.onStateChange.clear();\n this.onError.clear();\n this.onLeave.clear();\n this.onReconnect.clear();\n this.onDrop.clear();\n this.onMessageHandlers.events = {};\n\n if (this.serializer instanceof SchemaSerializer) {\n // Remove callback references\n this.serializer.decoder.root.callbacks = {};\n }\n }\n\n protected onMessageCallback(event: MessageEvent) {\n const buffer = new Uint8Array(event.data);\n\n const it: Iterator = { offset: 1 };\n const code = buffer[0];\n\n if (code === Protocol.JOIN_ROOM) {\n const reconnectionToken = decode.utf8Read(buffer as Buffer, it, buffer[it.offset++]);\n this.serializerId = decode.utf8Read(buffer as Buffer, it, buffer[it.offset++]);\n\n // Instantiate serializer if not locally available.\n if (!this.serializer) {\n const serializer = getSerializer(this.serializerId);\n this.serializer = new serializer();\n }\n\n // apply handshake on first join (no need to do this on reconnect)\n if (buffer.byteLength > it.offset && this.serializer.handshake) {\n this.serializer.handshake(buffer, it);\n }\n\n if (this.joinedAtTime === 0) {\n this.joinedAtTime = Date.now();\n this.onJoin.invoke();\n\n } else {\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x2705)} reconnection successful!`); // ✅\n this.reconnection.isReconnecting = false;\n this.onReconnect.invoke();\n }\n\n this.reconnectionToken = `${this.roomId}:${reconnectionToken}`;\n\n // acknowledge successfull JOIN_ROOM\n this.packr.buffer[0] = Protocol.JOIN_ROOM;\n this.connection.send(this.packr.buffer.subarray(0, 1));\n\n // Send any enqueued messages that were buffered while disconnected\n if (this.reconnection.enqueuedMessages.length > 0) {\n for (const message of this.reconnection.enqueuedMessages) {\n this.connection.send(message.data);\n }\n // Clear the buffer after sending\n this.reconnection.enqueuedMessages = [];\n }\n\n } else if (code === Protocol.ERROR) {\n const code = decode.number(buffer as Buffer, it);\n const message = decode.string(buffer as Buffer, it);\n\n this.onError.invoke(code, message);\n\n } else if (code === Protocol.LEAVE_ROOM) {\n this.leave();\n\n } else if (code === Protocol.ROOM_STATE) {\n this.serializer.setState(buffer, it);\n this.onStateChange.invoke(this.serializer.getState());\n\n } else if (code === Protocol.ROOM_STATE_PATCH) {\n this.serializer.patch(buffer, it);\n this.onStateChange.invoke(this.serializer.getState());\n\n } else if (code === Protocol.ROOM_DATA) {\n const type = (decode.stringCheck(buffer as Buffer, it))\n ? decode.string(buffer as Buffer, it)\n : decode.number(buffer as Buffer, it);\n\n const message = (buffer.byteLength > it.offset)\n ? unpack(buffer as Buffer, { start: it.offset })\n : undefined;\n\n this.dispatchMessage(type, message);\n\n } else if (code === Protocol.ROOM_DATA_BYTES) {\n const type = (decode.stringCheck(buffer as Buffer, it))\n ? decode.string(buffer as Buffer, it)\n : decode.number(buffer as Buffer, it);\n\n this.dispatchMessage(type, buffer.subarray(it.offset));\n\n } else if (code === Protocol.PING) {\n this.#pingCallback?.(Math.round(now() - this.#lastPingTime));\n this.#pingCallback = undefined;\n }\n }\n\n private dispatchMessage(type: string | number, message: any) {\n const messageType = this.getMessageHandlerKey(type);\n\n if (this.onMessageHandlers.events[messageType]) {\n this.onMessageHandlers.emit(messageType, message);\n\n } else if (this.onMessageHandlers.events['*']) {\n this.onMessageHandlers.emit('*', type, message);\n\n } else if (!messageType.startsWith(\"__\")) { // ignore internal messages\n console.warn?.(`@colyseus/sdk: onMessage() not registered for type '${type}'.`);\n }\n }\n\n private destroy () {\n if (this.serializer) {\n this.serializer.teardown();\n }\n }\n\n private getMessageHandlerKey(type: string | number): string {\n switch (typeof(type)) {\n // string\n case \"string\": return type;\n\n // number\n case \"number\": return `i${type}`;\n\n default: throw new Error(\"invalid message type.\");\n }\n }\n\n private handleReconnection() {\n if (Date.now() - this.joinedAtTime < this.reconnection.minUptime) {\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x274C)} Room has not been up for long enough for automatic reconnection. (min uptime: ${this.reconnection.minUptime}ms)`); // ❌\n this.onLeave.invoke(CloseCode.ABNORMAL_CLOSURE, \"Room uptime too short for reconnection.\");\n return;\n }\n\n if (!this.reconnection.isReconnecting) {\n this.reconnection.retryCount = 0;\n this.reconnection.isReconnecting = true;\n }\n\n this.retryReconnection();\n }\n\n private retryReconnection() {\n if (this.reconnection.retryCount >= this.reconnection.maxRetries) {\n // No more retries\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x274C)} ❌ Reconnection failed after ${this.reconnection.maxRetries} attempts.`); // ❌\n this.reconnection.isReconnecting = false;\n this.onLeave.invoke(CloseCode.FAILED_TO_RECONNECT, \"No more retries. Reconnection failed.\");\n return;\n }\n\n this.reconnection.retryCount++;\n\n const delay = Math.min(this.reconnection.maxDelay, Math.max(this.reconnection.minDelay, this.reconnection.backoff(this.reconnection.retryCount, this.reconnection.delay)));\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x023F3)} will retry in ${(delay/1000).toFixed(1)} seconds...`); // 🔄\n\n // Wait before attempting reconnection\n setTimeout(() => {\n try {\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x1F504)} Re-establishing sessionId '${this.sessionId}' with roomId '${this.roomId}'... (attempt ${this.reconnection.retryCount} of ${this.reconnection.maxRetries})`); // 🔄\n this.connection.reconnect({\n reconnectionToken: this.reconnectionToken.split(\":\")[1],\n skipHandshake: true, // we already applied the handshake on first join\n });\n\n } catch (e) {\n this.retryReconnection();\n }\n }, delay);\n }\n}\n\nconst exponentialBackoff = (attempt: number, delay: number) => {\n return Math.floor(Math.pow(2, attempt) * delay);\n}\n\nfunction enqueueMessage(room: Room, message: Uint8Array) {\n room.reconnection.enqueuedMessages.push({ data: message });\n if (room.reconnection.enqueuedMessages.length > room.reconnection.maxEnqueuedMessages) {\n room.reconnection.enqueuedMessages.shift();\n }\n}"],"names":["createSignal","createNanoEvents","Packr","getSerializer","Decoder","Connection","CloseCode","Protocol","__classPrivateFieldSet","now","encode","SchemaSerializer","decode","unpack","__classPrivateFieldGet"],"mappings":";;;;;;;;;;;;;;;;;;;;MAsFa,IAAI,CAAA;IA+Cb,WAAA,CAAY,IAAY,EAAE,UAAqC,EAAA;;QAnCxD,IAAA,CAAA,aAAa,GAAGA,mBAAY,EAA0B;QACtD,IAAA,CAAA,OAAO,GAAGA,mBA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AAC;AAC1D,IAAA,IAAI,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,mBAAmB,EAAE;AACnF,QAAA,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,KAAK,EAAE;IAC9C;AACJ;;;;"}
|
package/build/Room.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// This software is released under the MIT License.
|
|
4
4
|
// https://opensource.org/license/MIT
|
|
5
5
|
//
|
|
6
|
-
// colyseus.js@0.17.
|
|
6
|
+
// colyseus.js@0.17.27
|
|
7
7
|
import { CloseCode, Protocol } from '@colyseus/shared-types';
|
|
8
8
|
import { Decoder, encode, decode } from '@colyseus/schema';
|
|
9
9
|
import { Packr, unpack } from '@colyseus/msgpackr';
|
|
@@ -59,7 +59,10 @@ class Room {
|
|
|
59
59
|
serializer.state = state;
|
|
60
60
|
serializer.decoder = new Decoder(state);
|
|
61
61
|
}
|
|
62
|
-
this.onLeave(() =>
|
|
62
|
+
this.onLeave(() => {
|
|
63
|
+
this.removeAllListeners();
|
|
64
|
+
this.destroy();
|
|
65
|
+
});
|
|
63
66
|
}
|
|
64
67
|
connect(endpoint, options, headers) {
|
|
65
68
|
this.connection = new Connection(options.protocol);
|
|
@@ -79,7 +82,6 @@ class Room {
|
|
|
79
82
|
}
|
|
80
83
|
else {
|
|
81
84
|
this.onLeave.invoke(e.code, e.reason);
|
|
82
|
-
this.destroy();
|
|
83
85
|
}
|
|
84
86
|
};
|
|
85
87
|
this.connection.events.onerror = (e) => {
|
|
@@ -96,7 +98,7 @@ class Room {
|
|
|
96
98
|
this.connection.connect(url.origin, { ...options, skipHandshake });
|
|
97
99
|
}
|
|
98
100
|
else {
|
|
99
|
-
this.connection.connect(`${endpoint}${skipHandshake ? "
|
|
101
|
+
this.connection.connect(`${endpoint}${skipHandshake ? "&skipHandshake=1" : ""}`, headers);
|
|
100
102
|
}
|
|
101
103
|
}
|
|
102
104
|
leave(consented = true) {
|
|
@@ -204,6 +206,8 @@ class Room {
|
|
|
204
206
|
this.onStateChange.clear();
|
|
205
207
|
this.onError.clear();
|
|
206
208
|
this.onLeave.clear();
|
|
209
|
+
this.onReconnect.clear();
|
|
210
|
+
this.onDrop.clear();
|
|
207
211
|
this.onMessageHandlers.events = {};
|
|
208
212
|
if (this.serializer instanceof SchemaSerializer) {
|
|
209
213
|
// Remove callback references
|
|
@@ -313,6 +317,7 @@ class Room {
|
|
|
313
317
|
handleReconnection() {
|
|
314
318
|
if (Date.now() - this.joinedAtTime < this.reconnection.minUptime) {
|
|
315
319
|
console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x274C)} Room has not been up for long enough for automatic reconnection. (min uptime: ${this.reconnection.minUptime}ms)`); // ❌
|
|
320
|
+
this.onLeave.invoke(CloseCode.ABNORMAL_CLOSURE, "Room uptime too short for reconnection.");
|
|
316
321
|
return;
|
|
317
322
|
}
|
|
318
323
|
if (!this.reconnection.isReconnecting) {
|
|
@@ -322,6 +327,13 @@ class Room {
|
|
|
322
327
|
this.retryReconnection();
|
|
323
328
|
}
|
|
324
329
|
retryReconnection() {
|
|
330
|
+
if (this.reconnection.retryCount >= this.reconnection.maxRetries) {
|
|
331
|
+
// No more retries
|
|
332
|
+
console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x274C)} ❌ Reconnection failed after ${this.reconnection.maxRetries} attempts.`); // ❌
|
|
333
|
+
this.reconnection.isReconnecting = false;
|
|
334
|
+
this.onLeave.invoke(CloseCode.FAILED_TO_RECONNECT, "No more retries. Reconnection failed.");
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
325
337
|
this.reconnection.retryCount++;
|
|
326
338
|
const delay = Math.min(this.reconnection.maxDelay, Math.max(this.reconnection.minDelay, this.reconnection.backoff(this.reconnection.retryCount, this.reconnection.delay)));
|
|
327
339
|
console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x023F3)} will retry in ${(delay / 1000).toFixed(1)} seconds...`); // 🔄
|
|
@@ -335,13 +347,7 @@ class Room {
|
|
|
335
347
|
});
|
|
336
348
|
}
|
|
337
349
|
catch (e) {
|
|
338
|
-
|
|
339
|
-
if (this.reconnection.retryCount < this.reconnection.maxRetries) {
|
|
340
|
-
this.retryReconnection();
|
|
341
|
-
}
|
|
342
|
-
else {
|
|
343
|
-
console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x274C)} Failed to reconnect. Is your server running? Please check server logs.`); // ❌
|
|
344
|
-
}
|
|
350
|
+
this.retryReconnection();
|
|
345
351
|
}
|
|
346
352
|
}, delay);
|
|
347
353
|
}
|
package/build/Room.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Room.mjs","sources":["../src/Room.ts"],"sourcesContent":["import { CloseCode, Protocol, type InferState, type NormalizeRoomType, type ExtractRoomMessages, type ExtractRoomClientMessages, type ExtractMessageType } from '@colyseus/shared-types';\nimport { decode, Decoder, encode, Iterator, Schema } from '@colyseus/schema';\n\nimport { Packr, unpack } from '@colyseus/msgpackr';\n\nimport { Connection } from './Connection.ts';\nimport { getSerializer, Serializer } from './serializer/Serializer.ts';\n\n// The unused imports here are important for better `.d.ts` file generation\n// (Later merged with `dts-bundle-generator`)\nimport { createNanoEvents } from './core/nanoevents.ts';\nimport { createSignal } from './core/signal.ts';\n\nimport { SchemaConstructor, SchemaSerializer } from './serializer/SchemaSerializer.ts';\n\nimport { now } from './core/utils.ts';\n\n// Infer serializer type based on State: SchemaSerializer for Schema types, Serializer otherwise\nexport type InferSerializer<State> = [State] extends [Schema]\n ? SchemaSerializer<State>\n : Serializer<State>;\n\nexport interface RoomAvailable<Metadata = any> {\n name: string;\n roomId: string;\n clients: number;\n maxClients: number;\n metadata?: Metadata;\n}\n\nexport interface ReconnectionOptions {\n /**\n * The maximum number of reconnection attempts.\n */\n maxRetries: number;\n\n /**\n * The minimum delay between reconnection attempts.\n */\n minDelay: number;\n\n /**\n * The maximum delay between reconnection attempts.\n */\n maxDelay: number;\n\n /**\n * The minimum uptime of the room before reconnection attempts can be made.\n */\n minUptime: number;\n\n /**\n * The current number of reconnection attempts.\n */\n retryCount: number;\n\n /**\n * The initial delay between reconnection attempts.\n */\n delay: number;\n\n /**\n * The function to calculate the delay between reconnection attempts.\n * @param attempt - The current attempt number.\n * @param delay - The initial delay between reconnection attempts.\n * @returns The delay between reconnection attempts.\n */\n backoff: (attempt: number, delay: number) => number;\n\n /**\n * The maximum number of enqueued messages to buffer.\n */\n maxEnqueuedMessages: number;\n\n /**\n * Buffer for messages sent while connection is not open.\n * These messages will be sent once the connection is re-established.\n */\n enqueuedMessages: Array<{ data: Uint8Array }>;\n\n /**\n * Whether the room is currently reconnecting.\n */\n isReconnecting: boolean;\n}\n\nexport class Room<\n T = any,\n State = InferState<T, never>,\n> {\n public roomId: string;\n public sessionId: string;\n public reconnectionToken: string;\n\n public name: string;\n public connection: Connection;\n\n // Public signals\n public onStateChange = createSignal<(state: State) => void>();\n public onError = createSignal<(code: number, message?: string) => void>();\n public onLeave = createSignal<(code: number, reason?: string) => void>();\n\n public onReconnect = createSignal<() => void>();\n public onDrop = createSignal<(code: number, reason?: string) => void>();\n\n protected onJoin = createSignal();\n\n public serializerId: string;\n public serializer: InferSerializer<State>;\n\n // reconnection logic\n public reconnection: ReconnectionOptions = {\n retryCount: 0,\n maxRetries: 15,\n delay: 100,\n minDelay: 100,\n maxDelay: 5000,\n minUptime: 5000,\n backoff: exponentialBackoff,\n maxEnqueuedMessages: 10,\n enqueuedMessages: [],\n isReconnecting: false,\n };\n\n protected joinedAtTime: number = 0;\n\n protected onMessageHandlers = createNanoEvents();\n\n protected packr: Packr;\n\n #lastPingTime: number = 0;\n #pingCallback?: (ms: number) => void = undefined;\n\n constructor(name: string, rootSchema?: SchemaConstructor<State>) {\n this.name = name;\n\n this.packr = new Packr();\n\n // msgpackr workaround: force buffer to be created.\n this.packr.encode(undefined);\n\n if (rootSchema) {\n const serializer: SchemaSerializer = new (getSerializer(\"schema\"));\n this.serializer = serializer;\n\n const state: State = new rootSchema();\n serializer.state = state;\n serializer.decoder = new Decoder(state as Schema);\n }\n\n this.onLeave(() => this.removeAllListeners());\n }\n\n public connect(endpoint: string, options?: any, headers?: any) {\n this.connection = new Connection(options.protocol);\n this.connection.events.onmessage = this.onMessageCallback.bind(this);\n this.connection.events.onclose = (e: CloseEvent) => {\n if (this.joinedAtTime === 0) {\n console.warn?.(`Room connection was closed unexpectedly (${e.code}): ${e.reason}`);\n this.onError.invoke(e.code, e.reason);\n return;\n }\n\n if (\n e.code === CloseCode.NO_STATUS_RECEIVED ||\n e.code === CloseCode.ABNORMAL_CLOSURE ||\n e.code === CloseCode.GOING_AWAY ||\n e.code === CloseCode.MAY_TRY_RECONNECT\n ) {\n this.onDrop.invoke(e.code, e.reason);\n this.handleReconnection();\n\n } else {\n this.onLeave.invoke(e.code, e.reason);\n this.destroy();\n }\n };\n\n this.connection.events.onerror = (e: CloseEvent) => {\n this.onError.invoke(e.code, e.reason);\n };\n\n /**\n * if local serializer has state, it means we don't need to receive the\n * handshake from the server\n */\n const skipHandshake = (this.serializer?.getState() !== undefined);\n\n if (options.protocol === \"h3\") {\n // FIXME: refactor this.\n const url = new URL(endpoint);\n this.connection.connect(url.origin, { ...options, skipHandshake });\n\n } else {\n this.connection.connect(`${endpoint}${skipHandshake ? \"?skipHandshake=1\" : \"\"}`, headers);\n }\n\n }\n\n public leave(consented: boolean = true): Promise<number> {\n return new Promise((resolve) => {\n this.onLeave((code) => resolve(code));\n\n if (this.connection) {\n if (consented) {\n this.packr.buffer[0] = Protocol.LEAVE_ROOM;\n this.connection.send(this.packr.buffer.subarray(0, 1));\n\n } else {\n this.connection.close();\n }\n\n } else {\n this.onLeave.invoke(CloseCode.CONSENTED);\n }\n });\n }\n\n public onMessage<MessageType extends keyof ExtractRoomClientMessages<NormalizeRoomType<T>>>(\n message: MessageType,\n callback: (payload: ExtractRoomClientMessages<NormalizeRoomType<T>>[MessageType]) => void\n ): () => void\n public onMessage<Payload = any>(type: \"*\", callback: (messageType: string | number, payload: Payload) => void): () => void\n // Fallback overload: only available when no typed client messages are defined\n public onMessage<Payload = any>(\n type: [keyof ExtractRoomClientMessages<NormalizeRoomType<T>>] extends [never] ? (string | number) : never,\n callback: (payload: Payload) => void\n ): () => void\n public onMessage(type: '*' | string | number, callback: (...args: any[]) => void) {\n return this.onMessageHandlers.on(this.getMessageHandlerKey(type), callback);\n }\n\n public ping(callback: (ms: number) => void) {\n // skip if connection is not open\n if (!this.connection?.isOpen) {\n return;\n }\n\n this.#lastPingTime = now();\n this.#pingCallback = callback;\n this.packr.buffer[0] = Protocol.PING;\n this.connection.send(this.packr.buffer.subarray(0, 1));\n }\n\n public send<MessageType extends keyof ExtractRoomMessages<NormalizeRoomType<T>>>(\n messageType: MessageType,\n payload?: ExtractMessageType<ExtractRoomMessages<NormalizeRoomType<T>>[MessageType]>\n ): void\n // Fallback overload: only available when no typed messages are defined\n public send<Payload = any>(\n messageType: [keyof ExtractRoomMessages<NormalizeRoomType<T>>] extends [never] ? (string | number) : never,\n payload?: Payload\n ): void\n public send(messageType: string | number, payload?: any): void {\n const it: Iterator = { offset: 1 };\n this.packr.buffer[0] = Protocol.ROOM_DATA;\n\n if (typeof(messageType) === \"string\") {\n encode.string(this.packr.buffer as Buffer, messageType, it);\n\n } else {\n encode.number(this.packr.buffer as Buffer, messageType, it);\n }\n\n // force packr to use beginning of the buffer\n this.packr.position = 0;\n\n const data = (payload !== undefined)\n ? this.packr.pack(payload, 2048 + it.offset) // 2048 = RESERVE_START_SPACE\n : this.packr.buffer.subarray(0, it.offset);\n\n // If connection is not open, buffer the message\n if (!this.connection.isOpen) {\n enqueueMessage(this, new Uint8Array(data));\n } else {\n this.connection.send(data);\n }\n }\n\n public sendUnreliable<T = any>(type: string | number, message?: T): void {\n // If connection is not open, skip\n if (!this.connection.isOpen) { return; }\n\n const it: Iterator = { offset: 1 };\n this.packr.buffer[0] = Protocol.ROOM_DATA;\n\n if (typeof(type) === \"string\") {\n encode.string(this.packr.buffer as Buffer, type, it);\n\n } else {\n encode.number(this.packr.buffer as Buffer, type, it);\n }\n\n // force packr to use beginning of the buffer\n this.packr.position = 0;\n\n const data = (message !== undefined)\n ? this.packr.pack(message, 2048 + it.offset) // 2048 = RESERVE_START_SPACE\n : this.packr.buffer.subarray(0, it.offset);\n\n this.connection.sendUnreliable(data);\n }\n\n public sendBytes(type: string | number, bytes: Uint8Array) {\n const it: Iterator = { offset: 1 };\n this.packr.buffer[0] = Protocol.ROOM_DATA_BYTES;\n\n if (typeof(type) === \"string\") {\n encode.string(this.packr.buffer as Buffer, type, it);\n\n } else {\n encode.number(this.packr.buffer as Buffer, type, it);\n }\n\n // check if buffer needs to be resized\n // TODO: can we avoid this?\n if (bytes.byteLength + it.offset > this.packr.buffer.byteLength) {\n const newBuffer = new Uint8Array(it.offset + bytes.byteLength);\n newBuffer.set(this.packr.buffer);\n this.packr.useBuffer(newBuffer);\n }\n\n this.packr.buffer.set(bytes, it.offset);\n\n // If connection is not open, buffer the message\n if (!this.connection.isOpen) {\n enqueueMessage(this, this.packr.buffer.subarray(0, it.offset + bytes.byteLength));\n } else {\n this.connection.send(this.packr.buffer.subarray(0, it.offset + bytes.byteLength));\n }\n\n }\n\n public get state (): State {\n return this.serializer.getState();\n }\n\n public removeAllListeners() {\n this.onJoin.clear();\n this.onStateChange.clear();\n this.onError.clear();\n this.onLeave.clear();\n this.onMessageHandlers.events = {};\n\n if (this.serializer instanceof SchemaSerializer) {\n // Remove callback references\n this.serializer.decoder.root.callbacks = {};\n }\n }\n\n protected onMessageCallback(event: MessageEvent) {\n const buffer = new Uint8Array(event.data);\n\n const it: Iterator = { offset: 1 };\n const code = buffer[0];\n\n if (code === Protocol.JOIN_ROOM) {\n const reconnectionToken = decode.utf8Read(buffer as Buffer, it, buffer[it.offset++]);\n this.serializerId = decode.utf8Read(buffer as Buffer, it, buffer[it.offset++]);\n\n // Instantiate serializer if not locally available.\n if (!this.serializer) {\n const serializer = getSerializer(this.serializerId);\n this.serializer = new serializer();\n }\n\n // apply handshake on first join (no need to do this on reconnect)\n if (buffer.byteLength > it.offset && this.serializer.handshake) {\n this.serializer.handshake(buffer, it);\n }\n\n if (this.joinedAtTime === 0) {\n this.joinedAtTime = Date.now();\n this.onJoin.invoke();\n\n } else {\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x2705)} reconnection successful!`); // ✅\n this.reconnection.isReconnecting = false;\n this.onReconnect.invoke();\n }\n\n this.reconnectionToken = `${this.roomId}:${reconnectionToken}`;\n\n // acknowledge successfull JOIN_ROOM\n this.packr.buffer[0] = Protocol.JOIN_ROOM;\n this.connection.send(this.packr.buffer.subarray(0, 1));\n\n // Send any enqueued messages that were buffered while disconnected\n if (this.reconnection.enqueuedMessages.length > 0) {\n for (const message of this.reconnection.enqueuedMessages) {\n this.connection.send(message.data);\n }\n // Clear the buffer after sending\n this.reconnection.enqueuedMessages = [];\n }\n\n } else if (code === Protocol.ERROR) {\n const code = decode.number(buffer as Buffer, it);\n const message = decode.string(buffer as Buffer, it);\n\n this.onError.invoke(code, message);\n\n } else if (code === Protocol.LEAVE_ROOM) {\n this.leave();\n\n } else if (code === Protocol.ROOM_STATE) {\n this.serializer.setState(buffer, it);\n this.onStateChange.invoke(this.serializer.getState());\n\n } else if (code === Protocol.ROOM_STATE_PATCH) {\n this.serializer.patch(buffer, it);\n this.onStateChange.invoke(this.serializer.getState());\n\n } else if (code === Protocol.ROOM_DATA) {\n const type = (decode.stringCheck(buffer as Buffer, it))\n ? decode.string(buffer as Buffer, it)\n : decode.number(buffer as Buffer, it);\n\n const message = (buffer.byteLength > it.offset)\n ? unpack(buffer as Buffer, { start: it.offset })\n : undefined;\n\n this.dispatchMessage(type, message);\n\n } else if (code === Protocol.ROOM_DATA_BYTES) {\n const type = (decode.stringCheck(buffer as Buffer, it))\n ? decode.string(buffer as Buffer, it)\n : decode.number(buffer as Buffer, it);\n\n this.dispatchMessage(type, buffer.subarray(it.offset));\n\n } else if (code === Protocol.PING) {\n this.#pingCallback?.(Math.round(now() - this.#lastPingTime));\n this.#pingCallback = undefined;\n }\n }\n\n private dispatchMessage(type: string | number, message: any) {\n const messageType = this.getMessageHandlerKey(type);\n\n if (this.onMessageHandlers.events[messageType]) {\n this.onMessageHandlers.emit(messageType, message);\n\n } else if (this.onMessageHandlers.events['*']) {\n this.onMessageHandlers.emit('*', type, message);\n\n } else if (!messageType.startsWith(\"__\")) { // ignore internal messages\n console.warn?.(`@colyseus/sdk: onMessage() not registered for type '${type}'.`);\n }\n }\n\n private destroy () {\n if (this.serializer) {\n this.serializer.teardown();\n }\n }\n\n private getMessageHandlerKey(type: string | number): string {\n switch (typeof(type)) {\n // string\n case \"string\": return type;\n\n // number\n case \"number\": return `i${type}`;\n\n default: throw new Error(\"invalid message type.\");\n }\n }\n\n private handleReconnection() {\n if (Date.now() - this.joinedAtTime < this.reconnection.minUptime) {\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x274C)} Room has not been up for long enough for automatic reconnection. (min uptime: ${this.reconnection.minUptime}ms)`); // ❌\n return;\n }\n\n if (!this.reconnection.isReconnecting) {\n this.reconnection.retryCount = 0;\n this.reconnection.isReconnecting = true;\n }\n\n this.retryReconnection();\n }\n\n private retryReconnection() {\n this.reconnection.retryCount++;\n\n const delay = Math.min(this.reconnection.maxDelay, Math.max(this.reconnection.minDelay, this.reconnection.backoff(this.reconnection.retryCount, this.reconnection.delay)));\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x023F3)} will retry in ${(delay/1000).toFixed(1)} seconds...`); // 🔄\n\n // Wait before attempting reconnection\n setTimeout(() => {\n try {\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x1F504)} Re-establishing sessionId '${this.sessionId}' with roomId '${this.roomId}'... (attempt ${this.reconnection.retryCount} of ${this.reconnection.maxRetries})`); // 🔄\n this.connection.reconnect({\n reconnectionToken: this.reconnectionToken.split(\":\")[1],\n skipHandshake: true, // we already applied the handshake on first join\n });\n\n } catch (e) {\n console.log(\".reconnect() failed\", e);\n if (this.reconnection.retryCount < this.reconnection.maxRetries) {\n this.retryReconnection();\n } else {\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x274C)} Failed to reconnect. Is your server running? Please check server logs.`); // ❌\n }\n }\n }, delay);\n }\n}\n\nconst exponentialBackoff = (attempt: number, delay: number) => {\n return Math.floor(Math.pow(2, attempt) * delay);\n}\n\nfunction enqueueMessage(room: Room, message: Uint8Array) {\n room.reconnection.enqueuedMessages.push({ data: message });\n if (room.reconnection.enqueuedMessages.length > room.reconnection.maxEnqueuedMessages) {\n room.reconnection.enqueuedMessages.shift();\n }\n}"],"names":[],"mappings":";;;;;;;;;;;;;;;;MAsFa,IAAI,CAAA;AAIN,IAAA,MAAM;AACN,IAAA,SAAS;AACT,IAAA,iBAAiB;AAEjB,IAAA,IAAI;AACJ,IAAA,UAAU;;IAGV,aAAa,GAAG,YAAY,EAA0B;IACtD,OAAO,GAAG,YAAY,EAA4C;IAClE,OAAO,GAAG,YAAY,EAA2C;IAEjE,WAAW,GAAG,YAAY,EAAc;IACxC,MAAM,GAAG,YAAY,EAA2C;IAE7D,MAAM,GAAG,YAAY,EAAE;AAE1B,IAAA,YAAY;AACZ,IAAA,UAAU;;AAGV,IAAA,YAAY,GAAwB;AACvC,QAAA,UAAU,EAAE,CAAC;AACb,QAAA,UAAU,EAAE,EAAE;AACd,QAAA,KAAK,EAAE,GAAG;AACV,QAAA,QAAQ,EAAE,GAAG;AACb,QAAA,QAAQ,EAAE,IAAI;AACd,QAAA,SAAS,EAAE,IAAI;AACf,QAAA,OAAO,EAAE,kBAAkB;AAC3B,QAAA,mBAAmB,EAAE,EAAE;AACvB,QAAA,gBAAgB,EAAE,EAAE;AACpB,QAAA,cAAc,EAAE,KAAK;KACxB;IAES,YAAY,GAAW,CAAC;IAExB,iBAAiB,GAAG,gBAAgB,EAAE;AAEtC,IAAA,KAAK;IAEf,aAAa,GAAW,CAAC;IACzB,aAAa,GAA0B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AA,CAAC;YAEN;YAAE,OAAO,CAAC,EAAE;AACR,gBAAA,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,CAAC,CAAC;AACrC,gBAAA,IAAI,IAAI,CAAC,YAAY,CAAC,UAAU,GAAG,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE;oBAC7D,IAAI,CAAC,iBAAiB,EAAE;gBAC5B;qBAAO;AACH,oBAAA,OAAO,CAAC,IAAI,CAAC,CAAA,yBAAA,EAA4B,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA,uEAAA,CAAyE,CAAC,CAAC;gBACpJ;YACJ;QACJ,CAAC,EAAE,KAAK,CAAC;IACb;AACH;AAED,MAAM,kBAAkB,GAAG,CAAC,OAAe,EAAE,KAAa,KAAI;AAC1D,IAAA,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC;AACnD,CAAC;AAED,SAAS,cAAc,CAAC,IAAU,EAAE,OAAmB,EAAA;AACnD,IAAA,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAC1D,IAAA,IAAI,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,mBAAmB,EAAE;AACnF,QAAA,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,KAAK,EAAE;IAC9C;AACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"Room.mjs","sources":["../src/Room.ts"],"sourcesContent":["import { CloseCode, Protocol, type InferState, type NormalizeRoomType, type ExtractRoomMessages, type ExtractRoomClientMessages, type ExtractMessageType } from '@colyseus/shared-types';\nimport { decode, Decoder, encode, Iterator, Schema } from '@colyseus/schema';\n\nimport { Packr, unpack } from '@colyseus/msgpackr';\n\nimport { Connection } from './Connection.ts';\nimport { getSerializer, Serializer } from './serializer/Serializer.ts';\n\n// The unused imports here are important for better `.d.ts` file generation\n// (Later merged with `dts-bundle-generator`)\nimport { createNanoEvents } from './core/nanoevents.ts';\nimport { createSignal } from './core/signal.ts';\n\nimport { SchemaConstructor, SchemaSerializer } from './serializer/SchemaSerializer.ts';\n\nimport { now } from './core/utils.ts';\n\n// Infer serializer type based on State: SchemaSerializer for Schema types, Serializer otherwise\nexport type InferSerializer<State> = [State] extends [Schema]\n ? SchemaSerializer<State>\n : Serializer<State>;\n\nexport interface RoomAvailable<Metadata = any> {\n name: string;\n roomId: string;\n clients: number;\n maxClients: number;\n metadata?: Metadata;\n}\n\nexport interface ReconnectionOptions {\n /**\n * The maximum number of reconnection attempts.\n */\n maxRetries: number;\n\n /**\n * The minimum delay between reconnection attempts.\n */\n minDelay: number;\n\n /**\n * The maximum delay between reconnection attempts.\n */\n maxDelay: number;\n\n /**\n * The minimum uptime of the room before reconnection attempts can be made.\n */\n minUptime: number;\n\n /**\n * The current number of reconnection attempts.\n */\n retryCount: number;\n\n /**\n * The initial delay between reconnection attempts.\n */\n delay: number;\n\n /**\n * The function to calculate the delay between reconnection attempts.\n * @param attempt - The current attempt number.\n * @param delay - The initial delay between reconnection attempts.\n * @returns The delay between reconnection attempts.\n */\n backoff: (attempt: number, delay: number) => number;\n\n /**\n * The maximum number of enqueued messages to buffer.\n */\n maxEnqueuedMessages: number;\n\n /**\n * Buffer for messages sent while connection is not open.\n * These messages will be sent once the connection is re-established.\n */\n enqueuedMessages: Array<{ data: Uint8Array }>;\n\n /**\n * Whether the room is currently reconnecting.\n */\n isReconnecting: boolean;\n}\n\nexport class Room<\n T = any,\n State = InferState<T, never>,\n> {\n public roomId: string;\n public sessionId: string;\n public reconnectionToken: string;\n\n public name: string;\n public connection: Connection;\n\n // Public signals\n public onStateChange = createSignal<(state: State) => void>();\n public onError = createSignal<(code: number, message?: string) => void>();\n public onLeave = createSignal<(code: number, reason?: string) => void>();\n\n public onReconnect = createSignal<() => void>();\n public onDrop = createSignal<(code: number, reason?: string) => void>();\n\n protected onJoin = createSignal();\n\n public serializerId: string;\n public serializer: InferSerializer<State>;\n\n // reconnection logic\n public reconnection: ReconnectionOptions = {\n retryCount: 0,\n maxRetries: 15,\n delay: 100,\n minDelay: 100,\n maxDelay: 5000,\n minUptime: 5000,\n backoff: exponentialBackoff,\n maxEnqueuedMessages: 10,\n enqueuedMessages: [],\n isReconnecting: false,\n };\n\n protected joinedAtTime: number = 0;\n\n protected onMessageHandlers = createNanoEvents();\n\n protected packr: Packr;\n\n #lastPingTime: number = 0;\n #pingCallback?: (ms: number) => void = undefined;\n\n constructor(name: string, rootSchema?: SchemaConstructor<State>) {\n this.name = name;\n\n this.packr = new Packr();\n\n // msgpackr workaround: force buffer to be created.\n this.packr.encode(undefined);\n\n if (rootSchema) {\n const serializer: SchemaSerializer = new (getSerializer(\"schema\"));\n this.serializer = serializer;\n\n const state: State = new rootSchema();\n serializer.state = state;\n serializer.decoder = new Decoder(state as Schema);\n }\n\n this.onLeave(() => {\n this.removeAllListeners();\n this.destroy();\n });\n }\n\n public connect(endpoint: string, options?: any, headers?: any) {\n this.connection = new Connection(options.protocol);\n this.connection.events.onmessage = this.onMessageCallback.bind(this);\n this.connection.events.onclose = (e: CloseEvent) => {\n if (this.joinedAtTime === 0) {\n console.warn?.(`Room connection was closed unexpectedly (${e.code}): ${e.reason}`);\n this.onError.invoke(e.code, e.reason);\n return;\n }\n\n if (\n e.code === CloseCode.NO_STATUS_RECEIVED ||\n e.code === CloseCode.ABNORMAL_CLOSURE ||\n e.code === CloseCode.GOING_AWAY ||\n e.code === CloseCode.MAY_TRY_RECONNECT\n ) {\n this.onDrop.invoke(e.code, e.reason);\n this.handleReconnection();\n\n } else {\n this.onLeave.invoke(e.code, e.reason);\n }\n };\n\n this.connection.events.onerror = (e: CloseEvent) => {\n this.onError.invoke(e.code, e.reason);\n };\n\n /**\n * if local serializer has state, it means we don't need to receive the\n * handshake from the server\n */\n const skipHandshake = (this.serializer?.getState() !== undefined);\n\n if (options.protocol === \"h3\") {\n // FIXME: refactor this.\n const url = new URL(endpoint);\n this.connection.connect(url.origin, { ...options, skipHandshake });\n\n } else {\n this.connection.connect(`${endpoint}${skipHandshake ? \"&skipHandshake=1\" : \"\"}`, headers);\n }\n\n }\n\n public leave(consented: boolean = true): Promise<number> {\n return new Promise((resolve) => {\n this.onLeave((code) => resolve(code));\n\n if (this.connection) {\n if (consented) {\n this.packr.buffer[0] = Protocol.LEAVE_ROOM;\n this.connection.send(this.packr.buffer.subarray(0, 1));\n\n } else {\n this.connection.close();\n }\n\n } else {\n this.onLeave.invoke(CloseCode.CONSENTED);\n }\n });\n }\n\n public onMessage<MessageType extends keyof ExtractRoomClientMessages<NormalizeRoomType<T>>>(\n message: MessageType,\n callback: (payload: ExtractRoomClientMessages<NormalizeRoomType<T>>[MessageType]) => void\n ): () => void\n public onMessage<Payload = any>(type: \"*\", callback: (messageType: string | number, payload: Payload) => void): () => void\n // Fallback overload: only available when no typed client messages are defined\n public onMessage<Payload = any>(\n type: [keyof ExtractRoomClientMessages<NormalizeRoomType<T>>] extends [never] ? (string | number) : never,\n callback: (payload: Payload) => void\n ): () => void\n public onMessage(type: '*' | string | number, callback: (...args: any[]) => void) {\n return this.onMessageHandlers.on(this.getMessageHandlerKey(type), callback);\n }\n\n public ping(callback: (ms: number) => void) {\n // skip if connection is not open\n if (!this.connection?.isOpen) {\n return;\n }\n\n this.#lastPingTime = now();\n this.#pingCallback = callback;\n this.packr.buffer[0] = Protocol.PING;\n this.connection.send(this.packr.buffer.subarray(0, 1));\n }\n\n public send<MessageType extends keyof ExtractRoomMessages<NormalizeRoomType<T>>>(\n messageType: MessageType,\n payload?: ExtractMessageType<ExtractRoomMessages<NormalizeRoomType<T>>[MessageType]>\n ): void\n // Fallback overload: only available when no typed messages are defined\n public send<Payload = any>(\n messageType: [keyof ExtractRoomMessages<NormalizeRoomType<T>>] extends [never] ? (string | number) : never,\n payload?: Payload\n ): void\n public send(messageType: string | number, payload?: any): void {\n const it: Iterator = { offset: 1 };\n this.packr.buffer[0] = Protocol.ROOM_DATA;\n\n if (typeof(messageType) === \"string\") {\n encode.string(this.packr.buffer as Buffer, messageType, it);\n\n } else {\n encode.number(this.packr.buffer as Buffer, messageType, it);\n }\n\n // force packr to use beginning of the buffer\n this.packr.position = 0;\n\n const data = (payload !== undefined)\n ? this.packr.pack(payload, 2048 + it.offset) // 2048 = RESERVE_START_SPACE\n : this.packr.buffer.subarray(0, it.offset);\n\n // If connection is not open, buffer the message\n if (!this.connection.isOpen) {\n enqueueMessage(this, new Uint8Array(data));\n } else {\n this.connection.send(data);\n }\n }\n\n public sendUnreliable<T = any>(type: string | number, message?: T): void {\n // If connection is not open, skip\n if (!this.connection.isOpen) { return; }\n\n const it: Iterator = { offset: 1 };\n this.packr.buffer[0] = Protocol.ROOM_DATA;\n\n if (typeof(type) === \"string\") {\n encode.string(this.packr.buffer as Buffer, type, it);\n\n } else {\n encode.number(this.packr.buffer as Buffer, type, it);\n }\n\n // force packr to use beginning of the buffer\n this.packr.position = 0;\n\n const data = (message !== undefined)\n ? this.packr.pack(message, 2048 + it.offset) // 2048 = RESERVE_START_SPACE\n : this.packr.buffer.subarray(0, it.offset);\n\n this.connection.sendUnreliable(data);\n }\n\n public sendBytes(type: string | number, bytes: Uint8Array) {\n const it: Iterator = { offset: 1 };\n this.packr.buffer[0] = Protocol.ROOM_DATA_BYTES;\n\n if (typeof(type) === \"string\") {\n encode.string(this.packr.buffer as Buffer, type, it);\n\n } else {\n encode.number(this.packr.buffer as Buffer, type, it);\n }\n\n // check if buffer needs to be resized\n // TODO: can we avoid this?\n if (bytes.byteLength + it.offset > this.packr.buffer.byteLength) {\n const newBuffer = new Uint8Array(it.offset + bytes.byteLength);\n newBuffer.set(this.packr.buffer);\n this.packr.useBuffer(newBuffer);\n }\n\n this.packr.buffer.set(bytes, it.offset);\n\n // If connection is not open, buffer the message\n if (!this.connection.isOpen) {\n enqueueMessage(this, this.packr.buffer.subarray(0, it.offset + bytes.byteLength));\n } else {\n this.connection.send(this.packr.buffer.subarray(0, it.offset + bytes.byteLength));\n }\n\n }\n\n public get state (): State {\n return this.serializer.getState();\n }\n\n public removeAllListeners() {\n this.onJoin.clear();\n this.onStateChange.clear();\n this.onError.clear();\n this.onLeave.clear();\n this.onReconnect.clear();\n this.onDrop.clear();\n this.onMessageHandlers.events = {};\n\n if (this.serializer instanceof SchemaSerializer) {\n // Remove callback references\n this.serializer.decoder.root.callbacks = {};\n }\n }\n\n protected onMessageCallback(event: MessageEvent) {\n const buffer = new Uint8Array(event.data);\n\n const it: Iterator = { offset: 1 };\n const code = buffer[0];\n\n if (code === Protocol.JOIN_ROOM) {\n const reconnectionToken = decode.utf8Read(buffer as Buffer, it, buffer[it.offset++]);\n this.serializerId = decode.utf8Read(buffer as Buffer, it, buffer[it.offset++]);\n\n // Instantiate serializer if not locally available.\n if (!this.serializer) {\n const serializer = getSerializer(this.serializerId);\n this.serializer = new serializer();\n }\n\n // apply handshake on first join (no need to do this on reconnect)\n if (buffer.byteLength > it.offset && this.serializer.handshake) {\n this.serializer.handshake(buffer, it);\n }\n\n if (this.joinedAtTime === 0) {\n this.joinedAtTime = Date.now();\n this.onJoin.invoke();\n\n } else {\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x2705)} reconnection successful!`); // ✅\n this.reconnection.isReconnecting = false;\n this.onReconnect.invoke();\n }\n\n this.reconnectionToken = `${this.roomId}:${reconnectionToken}`;\n\n // acknowledge successfull JOIN_ROOM\n this.packr.buffer[0] = Protocol.JOIN_ROOM;\n this.connection.send(this.packr.buffer.subarray(0, 1));\n\n // Send any enqueued messages that were buffered while disconnected\n if (this.reconnection.enqueuedMessages.length > 0) {\n for (const message of this.reconnection.enqueuedMessages) {\n this.connection.send(message.data);\n }\n // Clear the buffer after sending\n this.reconnection.enqueuedMessages = [];\n }\n\n } else if (code === Protocol.ERROR) {\n const code = decode.number(buffer as Buffer, it);\n const message = decode.string(buffer as Buffer, it);\n\n this.onError.invoke(code, message);\n\n } else if (code === Protocol.LEAVE_ROOM) {\n this.leave();\n\n } else if (code === Protocol.ROOM_STATE) {\n this.serializer.setState(buffer, it);\n this.onStateChange.invoke(this.serializer.getState());\n\n } else if (code === Protocol.ROOM_STATE_PATCH) {\n this.serializer.patch(buffer, it);\n this.onStateChange.invoke(this.serializer.getState());\n\n } else if (code === Protocol.ROOM_DATA) {\n const type = (decode.stringCheck(buffer as Buffer, it))\n ? decode.string(buffer as Buffer, it)\n : decode.number(buffer as Buffer, it);\n\n const message = (buffer.byteLength > it.offset)\n ? unpack(buffer as Buffer, { start: it.offset })\n : undefined;\n\n this.dispatchMessage(type, message);\n\n } else if (code === Protocol.ROOM_DATA_BYTES) {\n const type = (decode.stringCheck(buffer as Buffer, it))\n ? decode.string(buffer as Buffer, it)\n : decode.number(buffer as Buffer, it);\n\n this.dispatchMessage(type, buffer.subarray(it.offset));\n\n } else if (code === Protocol.PING) {\n this.#pingCallback?.(Math.round(now() - this.#lastPingTime));\n this.#pingCallback = undefined;\n }\n }\n\n private dispatchMessage(type: string | number, message: any) {\n const messageType = this.getMessageHandlerKey(type);\n\n if (this.onMessageHandlers.events[messageType]) {\n this.onMessageHandlers.emit(messageType, message);\n\n } else if (this.onMessageHandlers.events['*']) {\n this.onMessageHandlers.emit('*', type, message);\n\n } else if (!messageType.startsWith(\"__\")) { // ignore internal messages\n console.warn?.(`@colyseus/sdk: onMessage() not registered for type '${type}'.`);\n }\n }\n\n private destroy () {\n if (this.serializer) {\n this.serializer.teardown();\n }\n }\n\n private getMessageHandlerKey(type: string | number): string {\n switch (typeof(type)) {\n // string\n case \"string\": return type;\n\n // number\n case \"number\": return `i${type}`;\n\n default: throw new Error(\"invalid message type.\");\n }\n }\n\n private handleReconnection() {\n if (Date.now() - this.joinedAtTime < this.reconnection.minUptime) {\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x274C)} Room has not been up for long enough for automatic reconnection. (min uptime: ${this.reconnection.minUptime}ms)`); // ❌\n this.onLeave.invoke(CloseCode.ABNORMAL_CLOSURE, \"Room uptime too short for reconnection.\");\n return;\n }\n\n if (!this.reconnection.isReconnecting) {\n this.reconnection.retryCount = 0;\n this.reconnection.isReconnecting = true;\n }\n\n this.retryReconnection();\n }\n\n private retryReconnection() {\n if (this.reconnection.retryCount >= this.reconnection.maxRetries) {\n // No more retries\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x274C)} ❌ Reconnection failed after ${this.reconnection.maxRetries} attempts.`); // ❌\n this.reconnection.isReconnecting = false;\n this.onLeave.invoke(CloseCode.FAILED_TO_RECONNECT, \"No more retries. Reconnection failed.\");\n return;\n }\n\n this.reconnection.retryCount++;\n\n const delay = Math.min(this.reconnection.maxDelay, Math.max(this.reconnection.minDelay, this.reconnection.backoff(this.reconnection.retryCount, this.reconnection.delay)));\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x023F3)} will retry in ${(delay/1000).toFixed(1)} seconds...`); // 🔄\n\n // Wait before attempting reconnection\n setTimeout(() => {\n try {\n console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x1F504)} Re-establishing sessionId '${this.sessionId}' with roomId '${this.roomId}'... (attempt ${this.reconnection.retryCount} of ${this.reconnection.maxRetries})`); // 🔄\n this.connection.reconnect({\n reconnectionToken: this.reconnectionToken.split(\":\")[1],\n skipHandshake: true, // we already applied the handshake on first join\n });\n\n } catch (e) {\n this.retryReconnection();\n }\n }, delay);\n }\n}\n\nconst exponentialBackoff = (attempt: number, delay: number) => {\n return Math.floor(Math.pow(2, attempt) * delay);\n}\n\nfunction enqueueMessage(room: Room, message: Uint8Array) {\n room.reconnection.enqueuedMessages.push({ data: message });\n if (room.reconnection.enqueuedMessages.length > room.reconnection.maxEnqueuedMessages) {\n room.reconnection.enqueuedMessages.shift();\n }\n}"],"names":[],"mappings":";;;;;;;;;;;;;;;;MAsFa,IAAI,CAAA;AAIN,IAAA,MAAM;AACN,IAAA,SAAS;AACT,IAAA,iBAAiB;AAEjB,IAAA,IA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,GAAG,CAAC,CAAC,CAAC,CAAC;oBACvD,aAAa,EAAE,IAAI;AACtB,iBAAA,CAAC;YAEN;YAAE,OAAO,CAAC,EAAE;gBACR,IAAI,CAAC,iBAAiB,EAAE;YAC5B;QACJ,CAAC,EAAE,KAAK,CAAC;IACb;AACH;AAED,MAAM,kBAAkB,GAAG,CAAC,OAAe,EAAE,KAAa,KAAI;AAC1D,IAAA,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC;AACnD,CAAC;AAED,SAAS,cAAc,CAAC,IAAU,EAAE,OAAmB,EAAA;AACnD,IAAA,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAC1D,IAAA,IAAI,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,mBAAmB,EAAE;AACnF,QAAA,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,KAAK,EAAE;IAC9C;AACJ;;;;"}
|
package/build/Storage.cjs
CHANGED
package/build/Storage.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// This software is released under the MIT License.
|
|
4
4
|
// https://opensource.org/license/MIT
|
|
5
5
|
//
|
|
6
|
-
// colyseus.js@0.17.
|
|
6
|
+
// colyseus.js@0.17.27
|
|
7
7
|
/// <reference path="../typings/cocos-creator.d.ts" />
|
|
8
8
|
/**
|
|
9
9
|
* We do not assign 'storage' to window.localStorage immediatelly for React
|