@colyseus/sdk 0.17.41 → 0.18.0

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.
Files changed (73) hide show
  1. package/build/3rd_party/discord.cjs +1 -1
  2. package/build/3rd_party/discord.mjs +1 -1
  3. package/build/Auth.cjs +16 -2
  4. package/build/Auth.cjs.map +1 -1
  5. package/build/Auth.mjs +16 -2
  6. package/build/Auth.mjs.map +1 -1
  7. package/build/Client.cjs +1 -1
  8. package/build/Client.mjs +1 -1
  9. package/build/Connection.cjs +1 -1
  10. package/build/Connection.mjs +1 -1
  11. package/build/HTTP.cjs +1 -1
  12. package/build/HTTP.mjs +1 -1
  13. package/build/Room.cjs +231 -46
  14. package/build/Room.cjs.map +1 -1
  15. package/build/Room.d.ts +62 -2
  16. package/build/Room.mjs +229 -44
  17. package/build/Room.mjs.map +1 -1
  18. package/build/Storage.cjs +1 -1
  19. package/build/Storage.mjs +1 -1
  20. package/build/core/nanoevents.cjs +1 -1
  21. package/build/core/nanoevents.mjs +1 -1
  22. package/build/core/signal.cjs +1 -1
  23. package/build/core/signal.cjs.map +1 -1
  24. package/build/core/signal.mjs +1 -1
  25. package/build/core/signal.mjs.map +1 -1
  26. package/build/core/utils.cjs +1 -1
  27. package/build/core/utils.mjs +1 -1
  28. package/build/debug.cjs +1 -1
  29. package/build/debug.cjs.map +1 -1
  30. package/build/debug.mjs +1 -1
  31. package/build/debug.mjs.map +1 -1
  32. package/build/errors/Errors.cjs +1 -1
  33. package/build/errors/Errors.mjs +1 -1
  34. package/build/fetchXHR.cjs +1 -1
  35. package/build/fetchXHR.mjs +1 -1
  36. package/build/index.cjs +1 -1
  37. package/build/index.cjs.map +1 -1
  38. package/build/index.d.ts +1 -1
  39. package/build/index.mjs +1 -1
  40. package/build/index.mjs.map +1 -1
  41. package/build/input/InputHandle.cjs +47 -0
  42. package/build/input/InputHandle.cjs.map +1 -0
  43. package/build/input/InputHandle.d.ts +79 -0
  44. package/build/input/InputHandle.mjs +48 -0
  45. package/build/input/InputHandle.mjs.map +1 -0
  46. package/build/legacy.cjs +1 -1
  47. package/build/legacy.mjs +1 -1
  48. package/build/serializer/NoneSerializer.cjs +1 -1
  49. package/build/serializer/NoneSerializer.mjs +1 -1
  50. package/build/serializer/SchemaSerializer.cjs +1 -1
  51. package/build/serializer/SchemaSerializer.mjs +1 -1
  52. package/build/serializer/Serializer.cjs +1 -1
  53. package/build/serializer/Serializer.mjs +1 -1
  54. package/build/transport/H3Transport.cjs +1 -1
  55. package/build/transport/H3Transport.cjs.map +1 -1
  56. package/build/transport/H3Transport.mjs +1 -1
  57. package/build/transport/H3Transport.mjs.map +1 -1
  58. package/build/transport/WebSocketTransport.cjs +1 -1
  59. package/build/transport/WebSocketTransport.mjs +1 -1
  60. package/dist/colyseus.js +13152 -1885
  61. package/dist/colyseus.js.map +1 -1
  62. package/dist/debug.js +1 -1
  63. package/dist/debug.js.map +1 -1
  64. package/package.json +11 -8
  65. package/src/Auth.ts +11 -1
  66. package/src/Room.ts +294 -48
  67. package/src/core/signal.ts +1 -1
  68. package/src/debug.ts +8 -8
  69. package/src/index.ts +1 -1
  70. package/src/input/InputHandle.ts +115 -0
  71. package/src/transport/H3Transport.ts +2 -2
  72. package/build/serializer/FossilDeltaSerializer.d.ts +0 -0
  73. package/src/serializer/FossilDeltaSerializer.ts +0 -39
package/build/Room.cjs CHANGED
@@ -3,13 +3,15 @@
3
3
  // This software is released under the MIT License.
4
4
  // https://opensource.org/license/MIT
5
5
  //
6
- // colyseus.js@0.17.41
6
+ // colyseus.js@0.18.0
7
7
  'use strict';
8
8
 
9
9
  var tslib = require('tslib');
10
10
  var sharedTypes = require('@colyseus/shared-types');
11
11
  var schema = require('@colyseus/schema');
12
- var msgpackr = require('@colyseus/msgpackr');
12
+ var input = require('@colyseus/schema/input');
13
+ var InputHandle = require('./input/InputHandle.cjs');
14
+ var msgpackr = require('msgpackr');
13
15
  var Connection = require('./Connection.cjs');
14
16
  var Serializer = require('./serializer/Serializer.cjs');
15
17
  var nanoevents = require('./core/nanoevents.cjs');
@@ -17,9 +19,10 @@ var signal = require('./core/signal.cjs');
17
19
  var SchemaSerializer = require('./serializer/SchemaSerializer.cjs');
18
20
  var utils = require('./core/utils.cjs');
19
21
 
20
- var _Room_lastPingTime, _Room_pingCallback;
22
+ var _Room_instances, _Room_lastPingTime, _Room_pingCallback, _Room_nextRequestId, _Room_pendingRequests, _Room_inputHandle, _Room_inputCtorFromReflection, _Room_request, _Room_rejectAllPending;
21
23
  class Room {
22
24
  constructor(name, rootSchema) {
25
+ _Room_instances.add(this);
23
26
  // Public signals
24
27
  this.onStateChange = signal.createSignal();
25
28
  this.onError = signal.createSignal();
@@ -45,10 +48,33 @@ class Room {
45
48
  this.onMessageHandlers = nanoevents.createNanoEvents();
46
49
  _Room_lastPingTime.set(this, 0);
47
50
  _Room_pingCallback.set(this, undefined);
51
+ /**
52
+ * Default time (ms) a `room.request()` / `room.send(..., callback)` waits
53
+ * for a reply before rejecting. Override per-call with the `timeout`
54
+ * option. Tune globally by assigning to this field after joining.
55
+ */
56
+ this.requestTimeout = 10000;
57
+ /** Monotonic id correlating a {@link Protocol.ROOM_REQUEST} with its reply. @internal */
58
+ _Room_nextRequestId.set(this, 0);
59
+ /** In-flight requests awaiting a {@link Protocol.ROOM_RESPONSE}. @internal */
60
+ _Room_pendingRequests.set(this, new Map());
61
+ _Room_inputHandle.set(this, void 0);
62
+ /**
63
+ * Schema constructor recovered via Reflection from the server's
64
+ * handshake (the `INPUT_REFLECTION` tagged section). Populated on JOIN
65
+ * when the server room called `defineInput()`; falls back to `undefined`
66
+ * otherwise. Survives reconnects that skip the handshake — the field is
67
+ * set on the original join and never cleared.
68
+ *
69
+ * Typed as `new () => any` (not `Schema`) on purpose — pinning to this
70
+ * SDK's Schema type would clash with user instances coming from a
71
+ * different copy of `@colyseus/schema` under multi-version installs.
72
+ * @internal
73
+ */
74
+ _Room_inputCtorFromReflection.set(this, void 0);
48
75
  this.name = name;
49
76
  this.packr = new msgpackr.Packr();
50
- // msgpackr workaround: force buffer to be created.
51
- this.packr.encode(undefined);
77
+ this.sharedBuffer = new Uint8Array(8192);
52
78
  if (rootSchema) {
53
79
  const serializer = new (Serializer.getSerializer("schema"));
54
80
  this.serializer = serializer;
@@ -67,6 +93,8 @@ class Room {
67
93
  this.connection.events.onmessage = this.onMessageCallback.bind(this);
68
94
  this.connection.events.onclose = (e) => {
69
95
  var _a;
96
+ // the in-flight requests can't be answered on a closed socket
97
+ tslib.__classPrivateFieldGet(this, _Room_instances, "m", _Room_rejectAllPending).call(this, "connection closed before a response was received.");
70
98
  if (this.joinedAtTime === 0) {
71
99
  (_a = console.warn) === null || _a === void 0 ? void 0 : _a.call(console, `Room connection was closed unexpectedly (${e.code}): ${e.reason}`);
72
100
  this.onError.invoke(e.code, e.reason);
@@ -105,8 +133,8 @@ class Room {
105
133
  this.onLeave((code) => resolve(code));
106
134
  if (this.connection) {
107
135
  if (consented) {
108
- this.packr.buffer[0] = sharedTypes.Protocol.LEAVE_ROOM;
109
- this.connection.send(this.packr.buffer.subarray(0, 1));
136
+ this.sharedBuffer[0] = sharedTypes.Protocol.LEAVE_ROOM;
137
+ this.connection.send(this.sharedBuffer.subarray(0, 1));
110
138
  }
111
139
  else {
112
140
  this.connection.close();
@@ -128,23 +156,35 @@ class Room {
128
156
  }
129
157
  tslib.__classPrivateFieldSet(this, _Room_lastPingTime, utils.now(), "f");
130
158
  tslib.__classPrivateFieldSet(this, _Room_pingCallback, callback, "f");
131
- this.packr.buffer[0] = sharedTypes.Protocol.PING;
132
- this.connection.send(this.packr.buffer.subarray(0, 1));
159
+ this.sharedBuffer[0] = sharedTypes.Protocol.PING;
160
+ this.connection.send(this.sharedBuffer.subarray(0, 1));
133
161
  }
134
- send(messageType, payload) {
162
+ send(messageType, payload, callback) {
163
+ // Request/response form: defer to `request()` and adapt to a
164
+ // (response, error) callback.
165
+ if (callback !== undefined) {
166
+ tslib.__classPrivateFieldGet(this, _Room_instances, "m", _Room_request).call(this, messageType, payload, this.requestTimeout).then((response) => callback(response, undefined), (error) => callback(undefined, error));
167
+ return;
168
+ }
135
169
  const it = { offset: 1 };
136
- this.packr.buffer[0] = sharedTypes.Protocol.ROOM_DATA;
170
+ this.sharedBuffer[0] = sharedTypes.Protocol.ROOM_DATA;
137
171
  if (typeof (messageType) === "string") {
138
- schema.encode.string(this.packr.buffer, messageType, it);
172
+ schema.encode.string(this.sharedBuffer, messageType, it);
139
173
  }
140
174
  else {
141
- schema.encode.number(this.packr.buffer, messageType, it);
175
+ schema.encode.number(this.sharedBuffer, messageType, it);
176
+ }
177
+ const headerLength = it.offset;
178
+ let data;
179
+ if (payload !== undefined) {
180
+ // Reserve `headerLength` writable bytes at the front of msgpackr's
181
+ // output and prepend the protocol header into them.
182
+ data = this.packr.pack(payload, msgpackr.RESERVE_START_SPACE | headerLength);
183
+ data.set(this.sharedBuffer.subarray(0, headerLength), 0);
184
+ }
185
+ else {
186
+ data = this.sharedBuffer.subarray(0, headerLength);
142
187
  }
143
- // force packr to use beginning of the buffer
144
- this.packr.position = 0;
145
- const data = (payload !== undefined)
146
- ? this.packr.pack(payload, 2048 + it.offset) // 2048 = RESERVE_START_SPACE
147
- : this.packr.buffer.subarray(0, it.offset);
148
188
  // If connection is not open, buffer the message
149
189
  if (!this.connection.isOpen) {
150
190
  enqueueMessage(this, new Uint8Array(data));
@@ -153,51 +193,103 @@ class Room {
153
193
  this.connection.send(data);
154
194
  }
155
195
  }
196
+ request(messageType, payload, options) {
197
+ var _a;
198
+ return tslib.__classPrivateFieldGet(this, _Room_instances, "m", _Room_request).call(this, messageType, payload, (_a = options === null || options === void 0 ? void 0 : options.timeout) !== null && _a !== void 0 ? _a : this.requestTimeout);
199
+ }
156
200
  sendUnreliable(type, message) {
157
201
  // If connection is not open, skip
158
202
  if (!this.connection.isOpen) {
159
203
  return;
160
204
  }
161
205
  const it = { offset: 1 };
162
- this.packr.buffer[0] = sharedTypes.Protocol.ROOM_DATA;
206
+ this.sharedBuffer[0] = sharedTypes.Protocol.ROOM_DATA;
163
207
  if (typeof (type) === "string") {
164
- schema.encode.string(this.packr.buffer, type, it);
208
+ schema.encode.string(this.sharedBuffer, type, it);
165
209
  }
166
210
  else {
167
- schema.encode.number(this.packr.buffer, type, it);
211
+ schema.encode.number(this.sharedBuffer, type, it);
212
+ }
213
+ const headerLength = it.offset;
214
+ let data;
215
+ if (message !== undefined) {
216
+ data = this.packr.pack(message, msgpackr.RESERVE_START_SPACE | headerLength);
217
+ data.set(this.sharedBuffer.subarray(0, headerLength), 0);
218
+ }
219
+ else {
220
+ data = this.sharedBuffer.subarray(0, headerLength);
168
221
  }
169
- // force packr to use beginning of the buffer
170
- this.packr.position = 0;
171
- const data = (message !== undefined)
172
- ? this.packr.pack(message, 2048 + it.offset) // 2048 = RESERVE_START_SPACE
173
- : this.packr.buffer.subarray(0, it.offset);
174
222
  this.connection.sendUnreliable(data);
175
223
  }
176
224
  sendBytes(type, bytes) {
177
225
  const it = { offset: 1 };
178
- this.packr.buffer[0] = sharedTypes.Protocol.ROOM_DATA_BYTES;
226
+ this.sharedBuffer[0] = sharedTypes.Protocol.ROOM_DATA_BYTES;
179
227
  if (typeof (type) === "string") {
180
- schema.encode.string(this.packr.buffer, type, it);
228
+ schema.encode.string(this.sharedBuffer, type, it);
181
229
  }
182
230
  else {
183
- schema.encode.number(this.packr.buffer, type, it);
231
+ schema.encode.number(this.sharedBuffer, type, it);
184
232
  }
185
- // check if buffer needs to be resized
186
- // TODO: can we avoid this?
187
- if (bytes.byteLength + it.offset > this.packr.buffer.byteLength) {
188
- const newBuffer = new Uint8Array(it.offset + bytes.byteLength);
189
- newBuffer.set(this.packr.buffer);
190
- this.packr.useBuffer(newBuffer);
233
+ const headerLength = it.offset;
234
+ // grow the scratch buffer if needed, preserving the header bytes
235
+ if (headerLength + bytes.byteLength > this.sharedBuffer.byteLength) {
236
+ const newBuffer = new Uint8Array(headerLength + bytes.byteLength);
237
+ newBuffer.set(this.sharedBuffer.subarray(0, headerLength));
238
+ this.sharedBuffer = newBuffer;
191
239
  }
192
- this.packr.buffer.set(bytes, it.offset);
240
+ this.sharedBuffer.set(bytes, headerLength);
193
241
  // If connection is not open, buffer the message
194
242
  if (!this.connection.isOpen) {
195
- enqueueMessage(this, this.packr.buffer.subarray(0, it.offset + bytes.byteLength));
243
+ enqueueMessage(this, this.sharedBuffer.subarray(0, headerLength + bytes.byteLength));
196
244
  }
197
245
  else {
198
- this.connection.send(this.packr.buffer.subarray(0, it.offset + bytes.byteLength));
246
+ this.connection.send(this.sharedBuffer.subarray(0, headerLength + bytes.byteLength));
199
247
  }
200
248
  }
249
+ /**
250
+ * Get the per-room input handle. Lazily created on first call and cached;
251
+ * subsequent calls return the same handle (options on later calls are
252
+ * ignored).
253
+ *
254
+ * Schema discovery, in order:
255
+ * 1. `options.type` — explicit constructor (overrides everything).
256
+ * 2. Server-sent reflection from the JOIN handshake — populated when the
257
+ * server room called `defineInput()`. The synthesized class has the
258
+ * same fields as the server's input schema; `instanceof YourInput`
259
+ * won't pass on it.
260
+ *
261
+ * Throws if neither source has produced a constructor.
262
+ *
263
+ * For rollback netcode, prefer `{ mode: "unreliable", delta: true,
264
+ * historySize: 4 }`: tiny per-tick payloads, redundancy across drops,
265
+ * idempotent under reordering.
266
+ *
267
+ * @example
268
+ * ```typescript
269
+ * const conn = await client.joinOrCreate<typeof FpsRoom>("fps");
270
+ * const input = conn.input({ mode: "unreliable" }); // type from server
271
+ * // each simulation tick:
272
+ * input.data.seq++;
273
+ * input.data.vx = vx;
274
+ * input.data.vy = vy;
275
+ * input.send();
276
+ * ```
277
+ */
278
+ input(options) {
279
+ var _a;
280
+ if (tslib.__classPrivateFieldGet(this, _Room_inputHandle, "f")) {
281
+ return tslib.__classPrivateFieldGet(this, _Room_inputHandle, "f");
282
+ }
283
+ const Ctor = ((_a = options === null || options === void 0 ? void 0 : options.type) !== null && _a !== void 0 ? _a : tslib.__classPrivateFieldGet(this, _Room_inputCtorFromReflection, "f"));
284
+ if (!Ctor) {
285
+ throw new Error("conn.input(): no input schema available. The server room must call " +
286
+ "`defineInput(YourInput)`, or you can pass `{ type: YourInput }` explicitly.");
287
+ }
288
+ const instance = new Ctor();
289
+ const encoder = new input.InputEncoder(instance, options);
290
+ tslib.__classPrivateFieldSet(this, _Room_inputHandle, new InputHandle.ClientInputHandleImpl(this, instance, encoder), "f");
291
+ return tslib.__classPrivateFieldGet(this, _Room_inputHandle, "f");
292
+ }
201
293
  get state() {
202
294
  return this.serializer.getState();
203
295
  }
@@ -215,7 +307,7 @@ class Room {
215
307
  }
216
308
  }
217
309
  onMessageCallback(event) {
218
- var _a;
310
+ var _a, _b;
219
311
  const buffer = new Uint8Array(event.data);
220
312
  const it = { offset: 1 };
221
313
  const code = buffer[0];
@@ -227,9 +319,31 @@ class Room {
227
319
  const serializer = Serializer.getSerializer(this.serializerId);
228
320
  this.serializer = new serializer();
229
321
  }
230
- // apply handshake on first join (no need to do this on reconnect)
231
- if (buffer.byteLength > it.offset && this.serializer.handshake) {
232
- this.serializer.handshake(buffer, it);
322
+ // State reflection is length-prefixed (varint). The schema decoder
323
+ // runs `while (offset < bytes.byteLength)` so without a boundary
324
+ // it would read past the state reflection into the trailing
325
+ // tagged-section bytes — see Protocol.ts for the wire layout.
326
+ const stateReflectionLen = schema.decode.number(buffer, it);
327
+ if (stateReflectionLen > 0 && this.serializer.handshake) {
328
+ const stateReflectionEnd = it.offset + stateReflectionLen;
329
+ this.serializer.handshake(buffer.subarray(0, stateReflectionEnd), it);
330
+ it.offset = stateReflectionEnd;
331
+ }
332
+ // Parse trailing tagged sections (forward-compatible: unknown tags
333
+ // are skipped via length). See HandshakeSection in shared-types.
334
+ while (it.offset < buffer.byteLength) {
335
+ const tag = buffer[it.offset++];
336
+ const sectionLen = schema.decode.number(buffer, it);
337
+ const sectionEnd = it.offset + sectionLen;
338
+ if (tag === sharedTypes.HandshakeSection.INPUT_REFLECTION) {
339
+ const inputDecoder = schema.Reflection.decode(buffer.subarray(0, sectionEnd), it);
340
+ // Install schema-builder field descriptors on the
341
+ // reconstructed class so `InputEncoder` can read its
342
+ // `$values` and emit non-empty packets.
343
+ schema.Reflection.makeEncodable(inputDecoder.state.constructor);
344
+ tslib.__classPrivateFieldSet(this, _Room_inputCtorFromReflection, inputDecoder.state.constructor, "f");
345
+ }
346
+ it.offset = sectionEnd;
233
347
  }
234
348
  if (this.joinedAtTime === 0) {
235
349
  this.joinedAtTime = Date.now();
@@ -242,8 +356,8 @@ class Room {
242
356
  }
243
357
  this.reconnectionToken = `${this.roomId}:${reconnectionToken}`;
244
358
  // acknowledge successfull JOIN_ROOM
245
- this.packr.buffer[0] = sharedTypes.Protocol.JOIN_ROOM;
246
- this.connection.send(this.packr.buffer.subarray(0, 1));
359
+ this.sharedBuffer[0] = sharedTypes.Protocol.JOIN_ROOM;
360
+ this.connection.send(this.sharedBuffer.subarray(0, 1));
247
361
  // Send any enqueued messages that were buffered while disconnected
248
362
  if (this.reconnection.enqueuedMessages.length > 0) {
249
363
  for (const message of this.reconnection.enqueuedMessages) {
@@ -284,8 +398,36 @@ class Room {
284
398
  : schema.decode.number(buffer, it);
285
399
  this.dispatchMessage(type, buffer.subarray(it.offset));
286
400
  }
401
+ else if (code === sharedTypes.Protocol.ROOM_RESPONSE) {
402
+ // reply to a pending `request()` / `send(..., callback)`
403
+ const requestId = schema.decode.number(buffer, it);
404
+ const status = buffer[it.offset++];
405
+ const pending = tslib.__classPrivateFieldGet(this, _Room_pendingRequests, "f").get(requestId);
406
+ // already settled (e.g. timed out) or unknown id — ignore
407
+ if (pending !== undefined) {
408
+ tslib.__classPrivateFieldGet(this, _Room_pendingRequests, "f").delete(requestId);
409
+ clearTimeout(pending.timer);
410
+ const payload = (buffer.byteLength > it.offset)
411
+ ? msgpackr.unpack(buffer, { start: it.offset })
412
+ : undefined;
413
+ if (status === sharedTypes.ResponseStatus.OK) {
414
+ pending.resolve(payload);
415
+ }
416
+ else {
417
+ // payload carries { name, message, code } from the server
418
+ const error = new Error((_a = payload === null || payload === void 0 ? void 0 : payload.message) !== null && _a !== void 0 ? _a : "request failed");
419
+ if (payload === null || payload === void 0 ? void 0 : payload.name) {
420
+ error.name = payload.name;
421
+ }
422
+ if ((payload === null || payload === void 0 ? void 0 : payload.code) !== undefined) {
423
+ error.code = payload.code;
424
+ }
425
+ pending.reject(error);
426
+ }
427
+ }
428
+ }
287
429
  else if (code === sharedTypes.Protocol.PING) {
288
- (_a = tslib.__classPrivateFieldGet(this, _Room_pingCallback, "f")) === null || _a === void 0 ? void 0 : _a.call(this, Math.round(utils.now() - tslib.__classPrivateFieldGet(this, _Room_lastPingTime, "f")));
430
+ (_b = tslib.__classPrivateFieldGet(this, _Room_pingCallback, "f")) === null || _b === void 0 ? void 0 : _b.call(this, Math.round(utils.now() - tslib.__classPrivateFieldGet(this, _Room_lastPingTime, "f")));
289
431
  tslib.__classPrivateFieldSet(this, _Room_pingCallback, undefined, "f");
290
432
  }
291
433
  }
@@ -358,7 +500,50 @@ class Room {
358
500
  }, delay);
359
501
  }
360
502
  }
361
- _Room_lastPingTime = new WeakMap(), _Room_pingCallback = new WeakMap();
503
+ _Room_lastPingTime = new WeakMap(), _Room_pingCallback = new WeakMap(), _Room_nextRequestId = new WeakMap(), _Room_pendingRequests = new WeakMap(), _Room_inputHandle = new WeakMap(), _Room_inputCtorFromReflection = new WeakMap(), _Room_instances = new WeakSet(), _Room_request = function _Room_request(messageType, payload, timeoutMs) {
504
+ return new Promise((resolve, reject) => {
505
+ if (!this.connection.isOpen) {
506
+ reject(new Error(`cannot send request "${messageType}": connection is not open.`));
507
+ return;
508
+ }
509
+ const requestId = tslib.__classPrivateFieldGet(this, _Room_nextRequestId, "f");
510
+ tslib.__classPrivateFieldSet(this, _Room_nextRequestId, (tslib.__classPrivateFieldGet(this, _Room_nextRequestId, "f") + 1) >>> 0, "f"); // keep within uint32
511
+ const it = { offset: 1 };
512
+ this.sharedBuffer[0] = sharedTypes.Protocol.ROOM_REQUEST;
513
+ schema.encode.number(this.sharedBuffer, requestId, it);
514
+ if (typeof (messageType) === "string") {
515
+ schema.encode.string(this.sharedBuffer, messageType, it);
516
+ }
517
+ else {
518
+ schema.encode.number(this.sharedBuffer, messageType, it);
519
+ }
520
+ const headerLength = it.offset;
521
+ let data;
522
+ if (payload !== undefined) {
523
+ data = this.packr.pack(payload, msgpackr.RESERVE_START_SPACE | headerLength);
524
+ data.set(this.sharedBuffer.subarray(0, headerLength), 0);
525
+ }
526
+ else {
527
+ data = this.sharedBuffer.subarray(0, headerLength);
528
+ }
529
+ const timer = setTimeout(() => {
530
+ tslib.__classPrivateFieldGet(this, _Room_pendingRequests, "f").delete(requestId);
531
+ reject(new Error(`request "${messageType}" timed out after ${timeoutMs}ms.`));
532
+ }, timeoutMs);
533
+ tslib.__classPrivateFieldGet(this, _Room_pendingRequests, "f").set(requestId, { resolve, reject, timer });
534
+ this.connection.send(data);
535
+ });
536
+ }, _Room_rejectAllPending = function _Room_rejectAllPending(reason) {
537
+ if (tslib.__classPrivateFieldGet(this, _Room_pendingRequests, "f").size === 0) {
538
+ return;
539
+ }
540
+ const error = new Error(reason);
541
+ for (const pending of tslib.__classPrivateFieldGet(this, _Room_pendingRequests, "f").values()) {
542
+ clearTimeout(pending.timer);
543
+ pending.reject(error);
544
+ }
545
+ tslib.__classPrivateFieldGet(this, _Room_pendingRequests, "f").clear();
546
+ };
362
547
  const exponentialBackoff = (attempt, delay) => {
363
548
  return Math.floor(Math.pow(2, attempt) * delay);
364
549
  };
@@ -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 * Whether automatic reconnection is enabled.\n * Set to `false` to disable automatic reconnection entirely.\n * @default true\n */\n enabled: boolean;\n\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 enabled: true,\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(e.code, e.reason);\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(code: number, reason?: string) {\n if (!this.reconnection.enabled) {\n this.onLeave.invoke(code, reason);\n return;\n }\n\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":";;;;;;;;;;;;;;;;;;;;MA6Fa,IAAI,CAAA;IAgDb,WAAA,CAAY,IAAY,EAAE,UAAqC,EAAA;;QApCxD,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,OAAO,EAAE,IAAI;AACb,YAAA,UAAU,EAAE,CAAC;AACb,YAAA,UAAU,EAAE,EAAE;AACd,YAAA,KAAK,EAAE,GAAG;AACV,YAAA,QAAQ,EAAE,GAAG;AACb,YAAA,QAAQ,EAAE,IAAI;AACd,YAAA,SAAS,EAAE,IAAI;AACf,YAAA,OAAO,EAAE,kBAAkB;AAC3B,YAAA,mBAAmB,EAAE,EAAE;AACvB,YAAA,gBAAgB,EAAE,EAAE;AACpB,YAAA,cAAc,EAAE,KAAK;SACxB;QAES,IAAA,CAAA,YAAY,GAAW,CAAC;QAExB,IAAA,CAAA,iBAAiB,GAAGC,2BAAgB,EAAE;AAIhD,QAAA,kBAAA,CAAA,GAAA,CAAA,IAAA,EAAwB,CAAC,CAAA;AACzB,QAAA,kBAAA,CAAA,GAAA,CAAA,IAAA,EAAuC,SAAS,CAAA;AAG5C,QAAA,IAAI,CAAC,IAAI,GAAG,IAAI;AAEhB,QAAA,IAAI,CAAC,KAAK,GAAG,IAAIC,c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,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC;oBACtB,iBAAiB,EAAE,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,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;;;;"}
1
+ {"version":3,"file":"Room.cjs","sources":["../src/Room.ts"],"sourcesContent":["import { CloseCode, HandshakeSection, Protocol, ResponseStatus, type InferState, type InferInput, type NormalizeRoomType, type ExtractRoomMessages, type ExtractRoomClientMessages, type ExtractMessageType, type ExtractResponseType } from '@colyseus/shared-types';\nimport { decode, Decoder, encode, Iterator, Reflection, Schema } from '@colyseus/schema';\nimport { InputEncoder } from '@colyseus/schema/input';\n\nimport { ClientInputHandleImpl, type ClientInputHandle, type ClientInputOptions } from './input/InputHandle.ts';\nexport { type ClientInputHandle, type ClientInputOptions } from './input/InputHandle.ts';\n\nimport { Packr, unpack, RESERVE_START_SPACE } from '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 * Whether automatic reconnection is enabled.\n * Set to `false` to disable automatic reconnection entirely.\n * @default true\n */\n enabled: boolean;\n\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 enabled: true,\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 protected sharedBuffer: Uint8Array;\n\n #lastPingTime: number = 0;\n #pingCallback?: (ms: number) => void = undefined;\n\n /**\n * Default time (ms) a `room.request()` / `room.send(..., callback)` waits\n * for a reply before rejecting. Override per-call with the `timeout`\n * option. Tune globally by assigning to this field after joining.\n */\n public requestTimeout: number = 10000;\n\n /** Monotonic id correlating a {@link Protocol.ROOM_REQUEST} with its reply. @internal */\n #nextRequestId: number = 0;\n\n /** In-flight requests awaiting a {@link Protocol.ROOM_RESPONSE}. @internal */\n #pendingRequests = new Map<number, {\n resolve: (value: any) => void;\n reject: (reason: any) => void;\n timer: ReturnType<typeof setTimeout>;\n }>();\n\n #inputHandle?: ClientInputHandle<any>;\n /**\n * Schema constructor recovered via Reflection from the server's\n * handshake (the `INPUT_REFLECTION` tagged section). Populated on JOIN\n * when the server room called `defineInput()`; falls back to `undefined`\n * otherwise. Survives reconnects that skip the handshake — the field is\n * set on the original join and never cleared.\n *\n * Typed as `new () => any` (not `Schema`) on purpose — pinning to this\n * SDK's Schema type would clash with user instances coming from a\n * different copy of `@colyseus/schema` under multi-version installs.\n * @internal\n */\n #inputCtorFromReflection?: new () => any;\n\n constructor(name: string, rootSchema?: SchemaConstructor<State>) {\n this.name = name;\n\n this.packr = new Packr();\n this.sharedBuffer = new Uint8Array(8192);\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 // the in-flight requests can't be answered on a closed socket\n this.#rejectAllPending(\"connection closed before a response was received.\");\n\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(e.code, e.reason);\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.sharedBuffer[0] = Protocol.LEAVE_ROOM;\n this.connection.send(this.sharedBuffer.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.sharedBuffer[0] = Protocol.PING;\n this.connection.send(this.sharedBuffer.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 // Request overload: passing a callback turns this into a request/response —\n // the callback receives the value the server handler returns (or an Error).\n public send<MessageType extends keyof ExtractRoomMessages<NormalizeRoomType<T>>>(\n messageType: MessageType,\n payload: ExtractMessageType<ExtractRoomMessages<NormalizeRoomType<T>>[MessageType]>,\n callback: (response: ExtractResponseType<ExtractRoomMessages<NormalizeRoomType<T>>[MessageType]>, error?: Error) => void\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 // Fallback request overload\n public send<Payload = any, Response = any>(\n messageType: [keyof ExtractRoomMessages<NormalizeRoomType<T>>] extends [never] ? (string | number) : never,\n payload: Payload,\n callback: (response: Response, error?: Error) => void\n ): void\n public send(messageType: string | number, payload?: any, callback?: (response: any, error?: Error) => void): void {\n // Request/response form: defer to `request()` and adapt to a\n // (response, error) callback.\n if (callback !== undefined) {\n this.#request(messageType, payload, this.requestTimeout).then(\n (response) => callback(response, undefined),\n (error) => callback(undefined, error),\n );\n return;\n }\n\n const it: Iterator = { offset: 1 };\n this.sharedBuffer[0] = Protocol.ROOM_DATA;\n\n if (typeof(messageType) === \"string\") {\n encode.string(this.sharedBuffer, messageType, it);\n\n } else {\n encode.number(this.sharedBuffer, messageType, it);\n }\n const headerLength = it.offset;\n\n let data: Uint8Array;\n if (payload !== undefined) {\n // Reserve `headerLength` writable bytes at the front of msgpackr's\n // output and prepend the protocol header into them.\n data = this.packr.pack(payload, RESERVE_START_SPACE | headerLength);\n data.set(this.sharedBuffer.subarray(0, headerLength), 0);\n } else {\n data = this.sharedBuffer.subarray(0, headerLength);\n }\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 /**\n * Send a message and await the server's reply. The server answers by\n * returning a value from its matching `onMessage(type, ...)` handler.\n *\n * Rejects if the handler throws, if no handler is registered, if the\n * connection closes first, or if no reply arrives within `timeout`\n * (defaults to {@link Room.requestTimeout}).\n *\n * @example\n * ```typescript\n * const profile = await room.request(\"get-profile\", { id: 42 });\n * ```\n */\n public request<MessageType extends keyof ExtractRoomMessages<NormalizeRoomType<T>>>(\n messageType: MessageType,\n payload?: ExtractMessageType<ExtractRoomMessages<NormalizeRoomType<T>>[MessageType]>,\n options?: { timeout?: number }\n ): Promise<ExtractResponseType<ExtractRoomMessages<NormalizeRoomType<T>>[MessageType]>>\n public request<Payload = any, Response = any>(\n messageType: [keyof ExtractRoomMessages<NormalizeRoomType<T>>] extends [never] ? (string | number) : never,\n payload?: Payload,\n options?: { timeout?: number }\n ): Promise<Response>\n public request(messageType: string | number, payload?: any, options?: { timeout?: number }): Promise<any> {\n return this.#request(messageType, payload, options?.timeout ?? this.requestTimeout);\n }\n\n #request(messageType: string | number, payload: any, timeoutMs: number): Promise<any> {\n return new Promise((resolve, reject) => {\n if (!this.connection.isOpen) {\n reject(new Error(`cannot send request \"${messageType}\": connection is not open.`));\n return;\n }\n\n const requestId = this.#nextRequestId;\n this.#nextRequestId = (this.#nextRequestId + 1) >>> 0; // keep within uint32\n\n const it: Iterator = { offset: 1 };\n this.sharedBuffer[0] = Protocol.ROOM_REQUEST;\n encode.number(this.sharedBuffer, requestId, it);\n\n if (typeof(messageType) === \"string\") {\n encode.string(this.sharedBuffer, messageType, it);\n } else {\n encode.number(this.sharedBuffer, messageType, it);\n }\n const headerLength = it.offset;\n\n let data: Uint8Array;\n if (payload !== undefined) {\n data = this.packr.pack(payload, RESERVE_START_SPACE | headerLength);\n data.set(this.sharedBuffer.subarray(0, headerLength), 0);\n } else {\n data = this.sharedBuffer.subarray(0, headerLength);\n }\n\n const timer = setTimeout(() => {\n this.#pendingRequests.delete(requestId);\n reject(new Error(`request \"${messageType}\" timed out after ${timeoutMs}ms.`));\n }, timeoutMs);\n\n this.#pendingRequests.set(requestId, { resolve, reject, timer });\n this.connection.send(data);\n });\n }\n\n #rejectAllPending(reason: string) {\n if (this.#pendingRequests.size === 0) { return; }\n const error = new Error(reason);\n for (const pending of this.#pendingRequests.values()) {\n clearTimeout(pending.timer);\n pending.reject(error);\n }\n this.#pendingRequests.clear();\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.sharedBuffer[0] = Protocol.ROOM_DATA;\n\n if (typeof(type) === \"string\") {\n encode.string(this.sharedBuffer, type, it);\n\n } else {\n encode.number(this.sharedBuffer, type, it);\n }\n const headerLength = it.offset;\n\n let data: Uint8Array;\n if (message !== undefined) {\n data = this.packr.pack(message, RESERVE_START_SPACE | headerLength);\n data.set(this.sharedBuffer.subarray(0, headerLength), 0);\n } else {\n data = this.sharedBuffer.subarray(0, headerLength);\n }\n\n this.connection.sendUnreliable(data);\n }\n\n public sendBytes(type: string | number, bytes: Uint8Array) {\n const it: Iterator = { offset: 1 };\n this.sharedBuffer[0] = Protocol.ROOM_DATA_BYTES;\n\n if (typeof(type) === \"string\") {\n encode.string(this.sharedBuffer, type, it);\n\n } else {\n encode.number(this.sharedBuffer, type, it);\n }\n const headerLength = it.offset;\n\n // grow the scratch buffer if needed, preserving the header bytes\n if (headerLength + bytes.byteLength > this.sharedBuffer.byteLength) {\n const newBuffer = new Uint8Array(headerLength + bytes.byteLength);\n newBuffer.set(this.sharedBuffer.subarray(0, headerLength));\n this.sharedBuffer = newBuffer;\n }\n\n this.sharedBuffer.set(bytes, headerLength);\n\n // If connection is not open, buffer the message\n if (!this.connection.isOpen) {\n enqueueMessage(this, this.sharedBuffer.subarray(0, headerLength + bytes.byteLength));\n } else {\n this.connection.send(this.sharedBuffer.subarray(0, headerLength + bytes.byteLength));\n }\n\n }\n\n /**\n * Get the per-room input handle. Lazily created on first call and cached;\n * subsequent calls return the same handle (options on later calls are\n * ignored).\n *\n * Schema discovery, in order:\n * 1. `options.type` — explicit constructor (overrides everything).\n * 2. Server-sent reflection from the JOIN handshake — populated when the\n * server room called `defineInput()`. The synthesized class has the\n * same fields as the server's input schema; `instanceof YourInput`\n * won't pass on it.\n *\n * Throws if neither source has produced a constructor.\n *\n * For rollback netcode, prefer `{ mode: \"unreliable\", delta: true,\n * historySize: 4 }`: tiny per-tick payloads, redundancy across drops,\n * idempotent under reordering.\n *\n * @example\n * ```typescript\n * const conn = await client.joinOrCreate<typeof FpsRoom>(\"fps\");\n * const input = conn.input({ mode: \"unreliable\" }); // type from server\n * // each simulation tick:\n * input.data.seq++;\n * input.data.vx = vx;\n * input.data.vy = vy;\n * input.send();\n * ```\n */\n public input<\n I = ([InferInput<T>] extends [never] ? any : InferInput<T>),\n >(options?: ClientInputOptions<I>): ClientInputHandle<I> {\n if (this.#inputHandle) {\n return this.#inputHandle as ClientInputHandle<I>;\n }\n\n const Ctor = (options?.type ?? this.#inputCtorFromReflection) as (new () => I) | undefined;\n if (!Ctor) {\n throw new Error(\n \"conn.input(): no input schema available. The server room must call \" +\n \"`defineInput(YourInput)`, or you can pass `{ type: YourInput }` explicitly.\"\n );\n }\n\n const instance = new Ctor();\n const encoder = new InputEncoder(instance as any, options);\n this.#inputHandle = new ClientInputHandleImpl(this, instance, encoder);\n return this.#inputHandle as ClientInputHandle<I>;\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 // State reflection is length-prefixed (varint). The schema decoder\n // runs `while (offset < bytes.byteLength)` so without a boundary\n // it would read past the state reflection into the trailing\n // tagged-section bytes — see Protocol.ts for the wire layout.\n const stateReflectionLen = decode.number(buffer as Buffer, it);\n if (stateReflectionLen > 0 && this.serializer.handshake) {\n const stateReflectionEnd = it.offset + stateReflectionLen;\n this.serializer.handshake(buffer.subarray(0, stateReflectionEnd), it);\n it.offset = stateReflectionEnd;\n }\n\n // Parse trailing tagged sections (forward-compatible: unknown tags\n // are skipped via length). See HandshakeSection in shared-types.\n while (it.offset < buffer.byteLength) {\n const tag = buffer[it.offset++];\n const sectionLen = decode.number(buffer as Buffer, it);\n const sectionEnd = it.offset + sectionLen;\n\n if (tag === HandshakeSection.INPUT_REFLECTION) {\n const inputDecoder = Reflection.decode(buffer.subarray(0, sectionEnd) as any, it);\n // Install schema-builder field descriptors on the\n // reconstructed class so `InputEncoder` can read its\n // `$values` and emit non-empty packets.\n Reflection.makeEncodable(inputDecoder.state.constructor as any);\n this.#inputCtorFromReflection = inputDecoder.state.constructor as new () => any;\n }\n\n it.offset = sectionEnd;\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.sharedBuffer[0] = Protocol.JOIN_ROOM;\n this.connection.send(this.sharedBuffer.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.ROOM_RESPONSE) {\n // reply to a pending `request()` / `send(..., callback)`\n const requestId = decode.number(buffer as Buffer, it);\n const status = buffer[it.offset++];\n\n const pending = this.#pendingRequests.get(requestId);\n // already settled (e.g. timed out) or unknown id — ignore\n if (pending !== undefined) {\n this.#pendingRequests.delete(requestId);\n clearTimeout(pending.timer);\n\n const payload = (buffer.byteLength > it.offset)\n ? unpack(buffer as Buffer, { start: it.offset })\n : undefined;\n\n if (status === ResponseStatus.OK) {\n pending.resolve(payload);\n } else {\n // payload carries { name, message, code } from the server\n const error: any = new Error(payload?.message ?? \"request failed\");\n if (payload?.name) { error.name = payload.name; }\n if (payload?.code !== undefined) { error.code = payload.code; }\n pending.reject(error);\n }\n }\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(code: number, reason?: string) {\n if (!this.reconnection.enabled) {\n this.onLeave.invoke(code, reason);\n return;\n }\n\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}\n\n\n"],"names":["createSignal","createNanoEvents","Packr","getSerializer","Decoder","Connection","__classPrivateFieldGet","CloseCode","Protocol","__classPrivateFieldSet","now","encode","RESERVE_START_SPACE","InputEncoder","ClientInputHandleImpl","SchemaSerializer","decode","HandshakeSection","Reflection","unpack","ResponseStatus"],"mappings":";;;;;;;;;;;;;;;;;;;;;;MAiGa,IAAI,CAAA;IAiFb,WAAA,CAAY,IAAY,EAAE,UAAqC,EAAA;;;QArExD,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,OAAO,EAAE,IAAI;AACb,YAAA,UAAU,EAAE,CAAC;AACb,YAAA,UAAU,EAAE,EAAE;AACd,YAAA,KAAK,EAAE,GAAG;AACV,YAAA,QAAQ,EAAE,GAAG;AACb,YAAA,QAAQ,EAAE,IAAI;AACd,YAAA,SAAS,EAAE,IAAI;AACf,YAAA,OAAO,EAAE,kBAAkB;AAC3B,YAAA,mBAAmB,EAAE,EAAE;AACvB,YAAA,gBAAgB,EAAE,EAAE;AACpB,YAAA,cAAc,EAAE,KAAK;SACxB;QAES,IAAA,CAAA,YAAY,GAAW,CAAC;QAExB,IAAA,CAAA,iBAAiB,GAAGC,2BAAgB,EAAE;AAKhD,QAAA,kBAAA,CAAA,GAAA,CAAA,IAAA,EAAwB,CAAC,CAAA;AACzB,QAAA,kBAAA,CAAA,GAAA,CAAA,IAAA,EAAuC,SAAS,CAAA;AAEhD;;;;AAIG;QACI,IAAA,CAAA,cAAc,GAAW,KAAK;;AAGrC,QAAA,mBAAA,CAAA,GAAA,CAAA,IAAA,EAAyB,CAAC,CAAA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