@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
@@ -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.41
6
+ // colyseus.js@0.18.0
7
7
  'use strict';
8
8
 
9
9
  class ServerError extends Error {
@@ -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.41
6
+ // colyseus.js@0.18.0
7
7
  class ServerError extends Error {
8
8
  code;
9
9
  headers;
@@ -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.41
6
+ // colyseus.js@0.18.0
7
7
  'use strict';
8
8
 
9
9
  var tslib = require('tslib');
@@ -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.41
6
+ // colyseus.js@0.18.0
7
7
  /**
8
8
  * Minimal fetch-compatible wrapper around XMLHttpRequest.
9
9
  * Used as an automatic fallback when globalThis.fetch is unavailable
package/build/index.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.41
6
+ // colyseus.js@0.18.0
7
7
  'use strict';
8
8
 
9
9
  require('./legacy.cjs');
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import './legacy';\n\nexport { ColyseusSDK, Client, type JoinOptions, type EndpointSettings, type ClientOptions, type ISeatReservation as SeatReservation } from './Client.ts';\nexport { type FetchFn } from './HTTP.ts';\nexport { Room, type RoomAvailable } from './Room.ts';\nexport { Auth, type AuthSettings, type PopupSettings, type AuthResponse, type UserDataResponse, type ForgotPasswordResponse, type AuthData } from \"./Auth.ts\";\nexport { ServerError, AbortError, MatchMakeError } from './errors/Errors.ts';\nexport { CloseCode, ErrorCode, Protocol } from '@colyseus/shared-types'; // convenience re-export / backwards compatibility\nexport type { InferRoomConstructor } from './core/utils.ts';\n\n/*\n * Serializers\n */\nimport { SchemaSerializer, getStateCallbacks } from \"./serializer/SchemaSerializer.ts\";\nimport { NoneSerializer } from \"./serializer/NoneSerializer.ts\";\nimport { registerSerializer } from './serializer/Serializer.ts';\nexport { Callbacks } from \"@colyseus/schema\";\n\nexport { registerSerializer, SchemaSerializer, getStateCallbacks };\nregisterSerializer('schema', SchemaSerializer);\nregisterSerializer('none', NoneSerializer);\n"],"names":["registerSerializer","SchemaSerializer","NoneSerializer"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBAA,6BAAkB,CAAC,QAAQ,EAAEC,iCAAgB,CAAC;AAC9CD,6BAAkB,CAAC,MAAM,EAAEE,6BAAc,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import './legacy.ts';\n\nexport { ColyseusSDK, Client, type JoinOptions, type EndpointSettings, type ClientOptions, type ISeatReservation as SeatReservation } from './Client.ts';\nexport { type FetchFn } from './HTTP.ts';\nexport { Room, type RoomAvailable } from './Room.ts';\nexport { Auth, type AuthSettings, type PopupSettings, type AuthResponse, type UserDataResponse, type ForgotPasswordResponse, type AuthData } from \"./Auth.ts\";\nexport { ServerError, AbortError, MatchMakeError } from './errors/Errors.ts';\nexport { CloseCode, ErrorCode, Protocol } from '@colyseus/shared-types'; // convenience re-export / backwards compatibility\nexport type { InferRoomConstructor } from './core/utils.ts';\n\n/*\n * Serializers\n */\nimport { SchemaSerializer, getStateCallbacks } from \"./serializer/SchemaSerializer.ts\";\nimport { NoneSerializer } from \"./serializer/NoneSerializer.ts\";\nimport { registerSerializer } from './serializer/Serializer.ts';\nexport { Callbacks } from \"@colyseus/schema\";\n\nexport { registerSerializer, SchemaSerializer, getStateCallbacks };\nregisterSerializer('schema', SchemaSerializer);\nregisterSerializer('none', NoneSerializer);\n"],"names":["registerSerializer","SchemaSerializer","NoneSerializer"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBAA,6BAAkB,CAAC,QAAQ,EAAEC,iCAAgB,CAAC;AAC9CD,6BAAkB,CAAC,MAAM,EAAEE,6BAAc,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/build/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import './legacy';
1
+ import './legacy.ts';
2
2
  export { ColyseusSDK, Client, type JoinOptions, type EndpointSettings, type ClientOptions, type ISeatReservation as SeatReservation } from './Client.ts';
3
3
  export { type FetchFn } from './HTTP.ts';
4
4
  export { Room, type RoomAvailable } from './Room.ts';
package/build/index.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.41
6
+ // colyseus.js@0.18.0
7
7
  import './legacy.mjs';
8
8
  export { Client, ColyseusSDK } from './Client.mjs';
9
9
  export { Room } from './Room.mjs';
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import './legacy';\n\nexport { ColyseusSDK, Client, type JoinOptions, type EndpointSettings, type ClientOptions, type ISeatReservation as SeatReservation } from './Client.ts';\nexport { type FetchFn } from './HTTP.ts';\nexport { Room, type RoomAvailable } from './Room.ts';\nexport { Auth, type AuthSettings, type PopupSettings, type AuthResponse, type UserDataResponse, type ForgotPasswordResponse, type AuthData } from \"./Auth.ts\";\nexport { ServerError, AbortError, MatchMakeError } from './errors/Errors.ts';\nexport { CloseCode, ErrorCode, Protocol } from '@colyseus/shared-types'; // convenience re-export / backwards compatibility\nexport type { InferRoomConstructor } from './core/utils.ts';\n\n/*\n * Serializers\n */\nimport { SchemaSerializer, getStateCallbacks } from \"./serializer/SchemaSerializer.ts\";\nimport { NoneSerializer } from \"./serializer/NoneSerializer.ts\";\nimport { registerSerializer } from './serializer/Serializer.ts';\nexport { Callbacks } from \"@colyseus/schema\";\n\nexport { registerSerializer, SchemaSerializer, getStateCallbacks };\nregisterSerializer('schema', SchemaSerializer);\nregisterSerializer('none', NoneSerializer);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAmBA,kBAAkB,CAAC,QAAQ,EAAE,gBAAgB,CAAC;AAC9C,kBAAkB,CAAC,MAAM,EAAE,cAAc,CAAC;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import './legacy.ts';\n\nexport { ColyseusSDK, Client, type JoinOptions, type EndpointSettings, type ClientOptions, type ISeatReservation as SeatReservation } from './Client.ts';\nexport { type FetchFn } from './HTTP.ts';\nexport { Room, type RoomAvailable } from './Room.ts';\nexport { Auth, type AuthSettings, type PopupSettings, type AuthResponse, type UserDataResponse, type ForgotPasswordResponse, type AuthData } from \"./Auth.ts\";\nexport { ServerError, AbortError, MatchMakeError } from './errors/Errors.ts';\nexport { CloseCode, ErrorCode, Protocol } from '@colyseus/shared-types'; // convenience re-export / backwards compatibility\nexport type { InferRoomConstructor } from './core/utils.ts';\n\n/*\n * Serializers\n */\nimport { SchemaSerializer, getStateCallbacks } from \"./serializer/SchemaSerializer.ts\";\nimport { NoneSerializer } from \"./serializer/NoneSerializer.ts\";\nimport { registerSerializer } from './serializer/Serializer.ts';\nexport { Callbacks } from \"@colyseus/schema\";\n\nexport { registerSerializer, SchemaSerializer, getStateCallbacks };\nregisterSerializer('schema', SchemaSerializer);\nregisterSerializer('none', NoneSerializer);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAmBA,kBAAkB,CAAC,QAAQ,EAAE,gBAAgB,CAAC;AAC9C,kBAAkB,CAAC,MAAM,EAAE,cAAc,CAAC;;;;"}
@@ -0,0 +1,47 @@
1
+ // Copyright (c) 2026 Endel Dreyer.
2
+ //
3
+ // This software is released under the MIT License.
4
+ // https://opensource.org/license/MIT
5
+ //
6
+ // colyseus.js@0.18.0
7
+ 'use strict';
8
+
9
+ var sharedTypes = require('@colyseus/shared-types');
10
+
11
+ /** @internal */
12
+ class ClientInputHandleImpl {
13
+ constructor(host, data, encoder) {
14
+ this._scratch = new Uint8Array(2048);
15
+ this._host = host;
16
+ this.data = data;
17
+ this._encoder = encoder;
18
+ }
19
+ get mode() { return this._encoder.mode; }
20
+ reset() { this._encoder.reset(); }
21
+ send() {
22
+ const conn = this._host.connection;
23
+ if (!(conn === null || conn === void 0 ? void 0 : conn.isOpen))
24
+ return;
25
+ const bytes = this._encoder.encode();
26
+ if (bytes.length === 0)
27
+ return;
28
+ const total = 1 + bytes.length;
29
+ if (total > this._scratch.byteLength) {
30
+ this._scratch = new Uint8Array(Math.max(total, this._scratch.byteLength * 2));
31
+ }
32
+ this._scratch[0] = this._encoder.mode === "reliable"
33
+ ? sharedTypes.Protocol.ROOM_INPUT_RELIABLE
34
+ : sharedTypes.Protocol.ROOM_INPUT_UNRELIABLE;
35
+ this._scratch.set(bytes, 1);
36
+ const framed = this._scratch.subarray(0, total);
37
+ if (this._encoder.mode === "reliable") {
38
+ conn.send(framed);
39
+ }
40
+ else {
41
+ conn.sendUnreliable(framed);
42
+ }
43
+ }
44
+ }
45
+
46
+ exports.ClientInputHandleImpl = ClientInputHandleImpl;
47
+ //# sourceMappingURL=InputHandle.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InputHandle.cjs","sources":["../../src/input/InputHandle.ts"],"sourcesContent":["import { InputEncoder, type InputEncoderOptions, type InputMode } from '@colyseus/schema/input';\nimport { Protocol } from '@colyseus/shared-types';\n\nimport type { Connection } from '../Connection.ts';\n\n/**\n * Minimal structural type the input handle needs from its host (Room). Lets\n * us decouple from the full `Room` class so this module stays import-cycle\n * free, while still picking up the latest `connection` after a reconnect.\n *\n * @internal\n */\nexport interface InputHandleHost {\n connection?: Connection;\n}\n\n/**\n * Options accepted by `Room.input()`. Extends {@link InputEncoderOptions}\n * (mode / historySize / delta / buffer) with a `type` field for the schema\n * constructor.\n *\n * Recommended for rollback netcode: `{ mode: \"unreliable\", delta: true,\n * historySize: 4 }` — small redundant deltas, idempotent across drops via\n * absolute-value wire ops.\n *\n * `I` is intentionally unconstrained: pinning it to `Schema` from this\n * SDK's copy of `@colyseus/schema` would reject user-side schemas coming\n * from a different copy of the package (npm hoisting, multi-version\n * installs). Runtime calls duck-type via the encoder, so a structural\n * match is enough.\n */\nexport interface ClientInputOptions<I = any> extends InputEncoderOptions {\n /**\n * Schema constructor for the input. Required when server-sent reflection\n * isn't available (which is the default today). Once handshake-time input\n * reflection lands, `type` becomes optional.\n */\n type?: new () => I;\n}\n\n/**\n * Per-room input handle returned by `Room.input()`. Mutate {@link data}\n * to stage the next input, then call {@link send} to encode and transmit on\n * the channel chosen at construction (reliable or unreliable).\n *\n * @example\n * ```typescript\n * const input = conn.input({ type: MoveInput, mode: \"unreliable\" });\n * input.data.vx = 10;\n * input.data.vy = 20;\n * input.send();\n * ```\n */\nexport interface ClientInputHandle<I = any> {\n /** Mutable schema instance — mutate, then call {@link send}. */\n readonly data: I;\n /** Wire mode this handle was constructed with. */\n readonly mode: InputMode;\n /**\n * Encode the staged input and send it. Routes to the reliable or\n * unreliable channel based on {@link mode}.\n *\n * No-op when the connection isn't open, or — in reliable + delta mode —\n * when nothing changed since the last send.\n */\n send(): void;\n /**\n * Reset encoder state. Drops the unreliable ring buffer; re-marks every\n * populated field as dirty in delta mode (next send emits a full\n * snapshot). Useful on scene transitions or after reconnection.\n */\n reset(): void;\n}\n\n/** @internal */\nexport class ClientInputHandleImpl<I = any> implements ClientInputHandle<I> {\n public readonly data: I;\n private _host: InputHandleHost;\n private _encoder: InputEncoder<any>;\n private _scratch: Uint8Array = new Uint8Array(2048);\n\n constructor(host: InputHandleHost, data: I, encoder: InputEncoder<any>) {\n this._host = host;\n this.data = data;\n this._encoder = encoder;\n }\n\n get mode(): InputMode { return this._encoder.mode; }\n\n reset(): void { this._encoder.reset(); }\n\n send(): void {\n const conn = this._host.connection;\n if (!conn?.isOpen) return;\n\n const bytes = this._encoder.encode();\n if (bytes.length === 0) return;\n\n const total = 1 + bytes.length;\n if (total > this._scratch.byteLength) {\n this._scratch = new Uint8Array(Math.max(total, this._scratch.byteLength * 2));\n }\n this._scratch[0] = this._encoder.mode === \"reliable\"\n ? Protocol.ROOM_INPUT_RELIABLE\n : Protocol.ROOM_INPUT_UNRELIABLE;\n this._scratch.set(bytes, 1);\n\n const framed = this._scratch.subarray(0, total);\n if (this._encoder.mode === \"reliable\") {\n conn.send(framed);\n } else {\n conn.sendUnreliable(framed);\n }\n }\n}\n"],"names":["Protocol"],"mappings":";;;;;;;;;;AA0EA;MACa,qBAAqB,CAAA;AAMhC,IAAA,WAAA,CAAY,IAAqB,EA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C,QAAQ,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC;QAC/C,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,UAAU,EAAE;AACrC,YAAA,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;QACnB;aAAO;AACL,YAAA,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC;QAC7B;IACF;AACD;;;;"}
@@ -0,0 +1,79 @@
1
+ import { InputEncoder, type InputEncoderOptions, type InputMode } from '@colyseus/schema/input';
2
+ import type { Connection } from '../Connection.ts';
3
+ /**
4
+ * Minimal structural type the input handle needs from its host (Room). Lets
5
+ * us decouple from the full `Room` class so this module stays import-cycle
6
+ * free, while still picking up the latest `connection` after a reconnect.
7
+ *
8
+ * @internal
9
+ */
10
+ export interface InputHandleHost {
11
+ connection?: Connection;
12
+ }
13
+ /**
14
+ * Options accepted by `Room.input()`. Extends {@link InputEncoderOptions}
15
+ * (mode / historySize / delta / buffer) with a `type` field for the schema
16
+ * constructor.
17
+ *
18
+ * Recommended for rollback netcode: `{ mode: "unreliable", delta: true,
19
+ * historySize: 4 }` — small redundant deltas, idempotent across drops via
20
+ * absolute-value wire ops.
21
+ *
22
+ * `I` is intentionally unconstrained: pinning it to `Schema` from this
23
+ * SDK's copy of `@colyseus/schema` would reject user-side schemas coming
24
+ * from a different copy of the package (npm hoisting, multi-version
25
+ * installs). Runtime calls duck-type via the encoder, so a structural
26
+ * match is enough.
27
+ */
28
+ export interface ClientInputOptions<I = any> extends InputEncoderOptions {
29
+ /**
30
+ * Schema constructor for the input. Required when server-sent reflection
31
+ * isn't available (which is the default today). Once handshake-time input
32
+ * reflection lands, `type` becomes optional.
33
+ */
34
+ type?: new () => I;
35
+ }
36
+ /**
37
+ * Per-room input handle returned by `Room.input()`. Mutate {@link data}
38
+ * to stage the next input, then call {@link send} to encode and transmit on
39
+ * the channel chosen at construction (reliable or unreliable).
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * const input = conn.input({ type: MoveInput, mode: "unreliable" });
44
+ * input.data.vx = 10;
45
+ * input.data.vy = 20;
46
+ * input.send();
47
+ * ```
48
+ */
49
+ export interface ClientInputHandle<I = any> {
50
+ /** Mutable schema instance — mutate, then call {@link send}. */
51
+ readonly data: I;
52
+ /** Wire mode this handle was constructed with. */
53
+ readonly mode: InputMode;
54
+ /**
55
+ * Encode the staged input and send it. Routes to the reliable or
56
+ * unreliable channel based on {@link mode}.
57
+ *
58
+ * No-op when the connection isn't open, or — in reliable + delta mode —
59
+ * when nothing changed since the last send.
60
+ */
61
+ send(): void;
62
+ /**
63
+ * Reset encoder state. Drops the unreliable ring buffer; re-marks every
64
+ * populated field as dirty in delta mode (next send emits a full
65
+ * snapshot). Useful on scene transitions or after reconnection.
66
+ */
67
+ reset(): void;
68
+ }
69
+ /** @internal */
70
+ export declare class ClientInputHandleImpl<I = any> implements ClientInputHandle<I> {
71
+ readonly data: I;
72
+ private _host;
73
+ private _encoder;
74
+ private _scratch;
75
+ constructor(host: InputHandleHost, data: I, encoder: InputEncoder<any>);
76
+ get mode(): InputMode;
77
+ reset(): void;
78
+ send(): void;
79
+ }
@@ -0,0 +1,48 @@
1
+ // Copyright (c) 2026 Endel Dreyer.
2
+ //
3
+ // This software is released under the MIT License.
4
+ // https://opensource.org/license/MIT
5
+ //
6
+ // colyseus.js@0.18.0
7
+ import { Protocol } from '@colyseus/shared-types';
8
+
9
+ /** @internal */
10
+ class ClientInputHandleImpl {
11
+ data;
12
+ _host;
13
+ _encoder;
14
+ _scratch = new Uint8Array(2048);
15
+ constructor(host, data, encoder) {
16
+ this._host = host;
17
+ this.data = data;
18
+ this._encoder = encoder;
19
+ }
20
+ get mode() { return this._encoder.mode; }
21
+ reset() { this._encoder.reset(); }
22
+ send() {
23
+ const conn = this._host.connection;
24
+ if (!conn?.isOpen)
25
+ return;
26
+ const bytes = this._encoder.encode();
27
+ if (bytes.length === 0)
28
+ return;
29
+ const total = 1 + bytes.length;
30
+ if (total > this._scratch.byteLength) {
31
+ this._scratch = new Uint8Array(Math.max(total, this._scratch.byteLength * 2));
32
+ }
33
+ this._scratch[0] = this._encoder.mode === "reliable"
34
+ ? Protocol.ROOM_INPUT_RELIABLE
35
+ : Protocol.ROOM_INPUT_UNRELIABLE;
36
+ this._scratch.set(bytes, 1);
37
+ const framed = this._scratch.subarray(0, total);
38
+ if (this._encoder.mode === "reliable") {
39
+ conn.send(framed);
40
+ }
41
+ else {
42
+ conn.sendUnreliable(framed);
43
+ }
44
+ }
45
+ }
46
+
47
+ export { ClientInputHandleImpl };
48
+ //# sourceMappingURL=InputHandle.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InputHandle.mjs","sources":["../../src/input/InputHandle.ts"],"sourcesContent":["import { InputEncoder, type InputEncoderOptions, type InputMode } from '@colyseus/schema/input';\nimport { Protocol } from '@colyseus/shared-types';\n\nimport type { Connection } from '../Connection.ts';\n\n/**\n * Minimal structural type the input handle needs from its host (Room). Lets\n * us decouple from the full `Room` class so this module stays import-cycle\n * free, while still picking up the latest `connection` after a reconnect.\n *\n * @internal\n */\nexport interface InputHandleHost {\n connection?: Connection;\n}\n\n/**\n * Options accepted by `Room.input()`. Extends {@link InputEncoderOptions}\n * (mode / historySize / delta / buffer) with a `type` field for the schema\n * constructor.\n *\n * Recommended for rollback netcode: `{ mode: \"unreliable\", delta: true,\n * historySize: 4 }` — small redundant deltas, idempotent across drops via\n * absolute-value wire ops.\n *\n * `I` is intentionally unconstrained: pinning it to `Schema` from this\n * SDK's copy of `@colyseus/schema` would reject user-side schemas coming\n * from a different copy of the package (npm hoisting, multi-version\n * installs). Runtime calls duck-type via the encoder, so a structural\n * match is enough.\n */\nexport interface ClientInputOptions<I = any> extends InputEncoderOptions {\n /**\n * Schema constructor for the input. Required when server-sent reflection\n * isn't available (which is the default today). Once handshake-time input\n * reflection lands, `type` becomes optional.\n */\n type?: new () => I;\n}\n\n/**\n * Per-room input handle returned by `Room.input()`. Mutate {@link data}\n * to stage the next input, then call {@link send} to encode and transmit on\n * the channel chosen at construction (reliable or unreliable).\n *\n * @example\n * ```typescript\n * const input = conn.input({ type: MoveInput, mode: \"unreliable\" });\n * input.data.vx = 10;\n * input.data.vy = 20;\n * input.send();\n * ```\n */\nexport interface ClientInputHandle<I = any> {\n /** Mutable schema instance — mutate, then call {@link send}. */\n readonly data: I;\n /** Wire mode this handle was constructed with. */\n readonly mode: InputMode;\n /**\n * Encode the staged input and send it. Routes to the reliable or\n * unreliable channel based on {@link mode}.\n *\n * No-op when the connection isn't open, or — in reliable + delta mode —\n * when nothing changed since the last send.\n */\n send(): void;\n /**\n * Reset encoder state. Drops the unreliable ring buffer; re-marks every\n * populated field as dirty in delta mode (next send emits a full\n * snapshot). Useful on scene transitions or after reconnection.\n */\n reset(): void;\n}\n\n/** @internal */\nexport class ClientInputHandleImpl<I = any> implements ClientInputHandle<I> {\n public readonly data: I;\n private _host: InputHandleHost;\n private _encoder: InputEncoder<any>;\n private _scratch: Uint8Array = new Uint8Array(2048);\n\n constructor(host: InputHandleHost, data: I, encoder: InputEncoder<any>) {\n this._host = host;\n this.data = data;\n this._encoder = encoder;\n }\n\n get mode(): InputMode { return this._encoder.mode; }\n\n reset(): void { this._encoder.reset(); }\n\n send(): void {\n const conn = this._host.connection;\n if (!conn?.isOpen) return;\n\n const bytes = this._encoder.encode();\n if (bytes.length === 0) return;\n\n const total = 1 + bytes.length;\n if (total > this._scratch.byteLength) {\n this._scratch = new Uint8Array(Math.max(total, this._scratch.byteLength * 2));\n }\n this._scratch[0] = this._encoder.mode === \"reliable\"\n ? Protocol.ROOM_INPUT_RELIABLE\n : Protocol.ROOM_INPUT_UNRELIABLE;\n this._scratch.set(bytes, 1);\n\n const framed = this._scratch.subarray(0, total);\n if (this._encoder.mode === \"reliable\") {\n conn.send(framed);\n } else {\n conn.sendUnreliable(framed);\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;AA0EA;MACa,qBAAqB,CAAA;AAChB,IAAA,IAAI;AACZ,IAAA,KAA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,CAAC;QAC/C,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,UAAU,EAAE;AACrC,YAAA,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;QACnB;aAAO;AACL,YAAA,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC;QAC7B;IACF;AACD;;;;"}
package/build/legacy.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.41
6
+ // colyseus.js@0.18.0
7
7
  'use strict';
8
8
 
9
9
  //
package/build/legacy.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.41
6
+ // colyseus.js@0.18.0
7
7
  //
8
8
  // Polyfills for legacy environments
9
9
  //
@@ -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.41
6
+ // colyseus.js@0.18.0
7
7
  'use strict';
8
8
 
9
9
  class NoneSerializer {
@@ -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.41
6
+ // colyseus.js@0.18.0
7
7
  class NoneSerializer {
8
8
  setState(rawState) { }
9
9
  getState() { return null; }
@@ -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.41
6
+ // colyseus.js@0.18.0
7
7
  'use strict';
8
8
 
9
9
  var schema = require('@colyseus/schema');
@@ -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.41
6
+ // colyseus.js@0.18.0
7
7
  import { getDecoderStateCallbacks, Reflection, Decoder } from '@colyseus/schema';
8
8
 
9
9
  //
@@ -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.41
6
+ // colyseus.js@0.18.0
7
7
  'use strict';
8
8
 
9
9
  const serializers = {};
@@ -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.41
6
+ // colyseus.js@0.18.0
7
7
  const serializers = {};
8
8
  function registerSerializer(id, serializer) {
9
9
  serializers[id] = serializer;
@@ -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.41
6
+ // colyseus.js@0.18.0
7
7
  'use strict';
8
8
 
9
9
  var tslib = require('tslib');
@@ -1 +1 @@
1
- {"version":3,"file":"H3Transport.cjs","sources":["../../src/transport/H3Transport.ts"],"sourcesContent":["import { encode, decode, type Iterator } from '@colyseus/schema';\nimport type { ITransport, ITransportEventMap } from \"./ITransport.ts\";\n\nexport class H3TransportTransport implements ITransport {\n wt: WebTransport;\n isOpen: boolean = false;\n events: ITransportEventMap;\n\n reader: ReadableStreamDefaultReader;\n writer: WritableStreamDefaultWriter;\n\n unreliableReader: ReadableStreamDefaultReader<Uint8Array>;\n unreliableWriter: WritableStreamDefaultWriter<Uint8Array>;\n\n private lengthPrefixBuffer = new Uint8Array(9); // 9 bytes is the maximum length of a length prefix\n\n constructor(events: ITransportEventMap) {\n this.events = events;\n }\n\n public connect(url: string, options: any = {}) {\n const wtOpts: WebTransportOptions = options.fingerprint && ({\n // requireUnreliable: true,\n // congestionControl: \"default\", // \"low-latency\" || \"throughput\"\n\n serverCertificateHashes: [{\n algorithm: 'sha-256',\n value: new Uint8Array(options.fingerprint).buffer\n }]\n }) || undefined;\n\n this.wt = new WebTransport(url, wtOpts);\n\n this.wt.ready.then((e) => {\n console.log(\"WebTransport ready!\", e)\n this.isOpen = true;\n\n this.unreliableReader = this.wt.datagrams.readable.getReader();\n this.unreliableWriter = this.wt.datagrams.writable.getWriter();\n\n const incomingBidi = this.wt.incomingBidirectionalStreams.getReader();\n incomingBidi.read().then((stream) => {\n this.reader = stream.value.readable.getReader();\n this.writer = stream.value.writable.getWriter();\n\n // immediately write room/sessionId for establishing the room connection\n this.sendSeatReservation(options.roomId, options.sessionId, options.reconnectionToken, options.skipHandshake);\n\n // start reading incoming data\n this.readIncomingData();\n this.readIncomingUnreliableData();\n\n }).catch((e) => {\n console.error(\"failed to read incoming stream\", e);\n console.error(\"TODO: close the connection\");\n });\n\n // this.events.onopen(e);\n }).catch((e: WebTransportCloseInfo) => {\n // this.events.onerror(e);\n // this.events.onclose({ code: e.closeCode, reason: e.reason });\n console.log(\"WebTransport not ready!\", e)\n this._close();\n });\n\n this.wt.closed.then((e: WebTransportCloseInfo) => {\n console.log(\"WebTransport closed w/ success\", e)\n this.events.onclose({ code: e.closeCode, reason: e.reason });\n\n }).catch((e: WebTransportCloseInfo) => {\n console.log(\"WebTransport closed w/ error\", e)\n this.events.onerror(e);\n this.events.onclose({ code: e.closeCode, reason: e.reason });\n }).finally(() => {\n this._close();\n });\n }\n\n public send(data: Buffer | Uint8Array): void {\n const prefixLength = encode.number(this.lengthPrefixBuffer as any, data.length, { offset: 0 });\n const dataWithPrefixedLength = new Uint8Array(prefixLength + data.length);\n dataWithPrefixedLength.set(this.lengthPrefixBuffer.subarray(0, prefixLength), 0);\n dataWithPrefixedLength.set(data, prefixLength);\n this.writer.write(dataWithPrefixedLength);\n }\n\n public sendUnreliable(data: Buffer | Uint8Array): void {\n const prefixLength = encode.number(this.lengthPrefixBuffer as any, data.length, { offset: 0 });\n const dataWithPrefixedLength = new Uint8Array(prefixLength + data.length);\n dataWithPrefixedLength.set(this.lengthPrefixBuffer.subarray(0, prefixLength), 0);\n dataWithPrefixedLength.set(data, prefixLength);\n this.unreliableWriter.write(dataWithPrefixedLength);\n }\n\n public close(code?: number, reason?: string) {\n try {\n this.wt.close({ closeCode: code, reason: reason });\n } catch (e) {\n console.error(e);\n }\n }\n\n protected async readIncomingData() {\n let result: ReadableStreamReadResult<Uint8Array>;\n\n while (this.isOpen) {\n try {\n result = await this.reader.read();\n\n //\n // a single read may contain multiple messages\n // each message is prefixed with its length\n //\n\n const messages = result.value;\n const it: Iterator = { offset: 0 };\n do {\n //\n // QUESTION: should we buffer the message in case it's not fully read?\n //\n\n const length = decode.number(messages as any, it);\n this.events.onmessage({ data: messages.subarray(it.offset, it.offset + length) });\n it.offset += length;\n } while (it.offset < messages.length);\n\n } catch (e) {\n if (e.message.indexOf(\"session is closed\") === -1) {\n console.error(\"H3Transport: failed to read incoming data\", e);\n }\n break;\n }\n\n if (result.done) {\n break;\n }\n }\n }\n\n protected async readIncomingUnreliableData() {\n let result: ReadableStreamReadResult<Uint8Array>;\n\n while (this.isOpen) {\n try {\n result = await this.unreliableReader.read();\n\n //\n // a single read may contain multiple messages\n // each message is prefixed with its length\n //\n\n const messages = result.value;\n const it: Iterator = { offset: 0 };\n do {\n //\n // QUESTION: should we buffer the message in case it's not fully read?\n //\n\n const length = decode.number(messages as any, it);\n this.events.onmessage({ data: messages.subarray(it.offset, it.offset + length) });\n it.offset += length;\n } while (it.offset < messages.length);\n\n } catch (e) {\n if (e.message.indexOf(\"session is closed\") === -1) {\n console.error(\"H3Transport: failed to read incoming data\", e);\n }\n break;\n }\n\n if (result.done) {\n break;\n }\n }\n }\n\n protected sendSeatReservation (roomId: string, sessionId: string, reconnectionToken?: string, skipHandshake?: boolean) {\n const it: Iterator = { offset: 0 };\n const bytes: number[] = [];\n\n encode.string(bytes, roomId, it);\n encode.string(bytes, sessionId, it);\n\n if (reconnectionToken) {\n encode.string(bytes, reconnectionToken, it);\n }\n\n if (skipHandshake) {\n encode.boolean(bytes, 1, it);\n }\n\n this.writer.write(new Uint8Array(bytes).buffer);\n }\n\n protected _close() {\n this.isOpen = false;\n }\n\n}\n"],"names":["encode","decode"],"mappings":";;;;;;;;;;;MAGa,oBAAoB,CAAA;AAa7B,IAAA,WAAA,CAAY,M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E,CAAC,EAAE,EAAE,CAAC;QAChC;AAEA,QAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC;IACnD;IAEU,MAAM,GAAA;AACZ,QAAA,IAAI,CAAC,MAAM,GAAG,KAAK;IACvB;AAEH;;;;"}
1
+ {"version":3,"file":"H3Transport.cjs","sources":["../../src/transport/H3Transport.ts"],"sourcesContent":["import { encode, decode, type Iterator } from '@colyseus/schema';\nimport type { ITransport, ITransportEventMap } from \"./ITransport.ts\";\n\nexport class H3TransportTransport implements ITransport {\n wt: WebTransport;\n isOpen: boolean = false;\n events: ITransportEventMap;\n\n reader: ReadableStreamDefaultReader;\n writer: WritableStreamDefaultWriter;\n\n unreliableReader: ReadableStreamDefaultReader<Uint8Array>;\n unreliableWriter: WritableStreamDefaultWriter<Uint8Array>;\n\n private lengthPrefixBuffer = new Uint8Array(9); // 9 bytes is the maximum length of a length prefix\n\n constructor(events: ITransportEventMap) {\n this.events = events;\n }\n\n public connect(url: string, options: any = {}) {\n const wtOpts: WebTransportOptions = options.fingerprint && ({\n // requireUnreliable: true,\n // congestionControl: \"default\", // \"low-latency\" || \"throughput\"\n\n serverCertificateHashes: [{\n algorithm: 'sha-256',\n value: new Uint8Array(options.fingerprint).buffer\n }]\n }) || undefined;\n\n this.wt = new WebTransport(url, wtOpts);\n\n this.wt.ready.then((e) => {\n console.log(\"WebTransport ready!\", e)\n this.isOpen = true;\n\n this.unreliableReader = this.wt.datagrams.readable.getReader();\n this.unreliableWriter = this.wt.datagrams.writable.getWriter();\n\n const incomingBidi = this.wt.incomingBidirectionalStreams.getReader();\n incomingBidi.read().then((stream) => {\n this.reader = stream.value.readable.getReader();\n this.writer = stream.value.writable.getWriter();\n\n // immediately write room/sessionId for establishing the room connection\n this.sendSeatReservation(options.roomId, options.sessionId, options.reconnectionToken, options.skipHandshake);\n\n // start reading incoming data\n this.readIncomingData();\n this.readIncomingUnreliableData();\n\n }).catch((e) => {\n console.error(\"failed to read incoming stream\", e);\n console.error(\"TODO: close the connection\");\n });\n\n // this.events.onopen(e);\n }).catch((e: WebTransportCloseInfo) => {\n // this.events.onerror(e);\n // this.events.onclose({ code: e.closeCode, reason: e.reason });\n console.log(\"WebTransport not ready!\", e)\n this._close();\n });\n\n this.wt.closed.then((e: WebTransportCloseInfo) => {\n console.log(\"WebTransport closed w/ success\", e)\n this.events.onclose({ code: e.closeCode, reason: e.reason });\n\n }).catch((e: WebTransportCloseInfo) => {\n console.log(\"WebTransport closed w/ error\", e)\n this.events.onerror(e);\n this.events.onclose({ code: e.closeCode, reason: e.reason });\n }).finally(() => {\n this._close();\n });\n }\n\n public send(data: Buffer | Uint8Array): void {\n const prefixLength = encode.number(this.lengthPrefixBuffer as any, data.length, { offset: 0 });\n const dataWithPrefixedLength = new Uint8Array(prefixLength + data.length);\n dataWithPrefixedLength.set(this.lengthPrefixBuffer.subarray(0, prefixLength), 0);\n dataWithPrefixedLength.set(data, prefixLength);\n this.writer.write(dataWithPrefixedLength);\n }\n\n public sendUnreliable(data: Buffer | Uint8Array): void {\n const prefixLength = encode.number(this.lengthPrefixBuffer as any, data.length, { offset: 0 });\n const dataWithPrefixedLength = new Uint8Array(prefixLength + data.length);\n dataWithPrefixedLength.set(this.lengthPrefixBuffer.subarray(0, prefixLength), 0);\n dataWithPrefixedLength.set(data, prefixLength);\n this.unreliableWriter.write(dataWithPrefixedLength);\n }\n\n public close(code?: number, reason?: string) {\n try {\n this.wt.close({ closeCode: code, reason: reason });\n } catch (e) {\n console.error(e);\n }\n }\n\n protected async readIncomingData() {\n let result: ReadableStreamReadResult<Uint8Array>;\n\n while (this.isOpen) {\n try {\n result = await this.reader.read();\n\n //\n // a single read may contain multiple messages\n // each message is prefixed with its length\n //\n\n const messages = result.value;\n const it: Iterator = { offset: 0 };\n do {\n //\n // QUESTION: should we buffer the message in case it's not fully read?\n //\n\n const length = decode.number(messages as any, it);\n this.events.onmessage({ data: messages.subarray(it.offset, it.offset + length) });\n it.offset += length;\n } while (it.offset < messages.length);\n\n } catch (e: any) {\n if (e.message.indexOf(\"session is closed\") === -1) {\n console.error(\"H3Transport: failed to read incoming data\", e);\n }\n break;\n }\n\n if (result.done) {\n break;\n }\n }\n }\n\n protected async readIncomingUnreliableData() {\n let result: ReadableStreamReadResult<Uint8Array>;\n\n while (this.isOpen) {\n try {\n result = await this.unreliableReader.read();\n\n //\n // a single read may contain multiple messages\n // each message is prefixed with its length\n //\n\n const messages = result.value;\n const it: Iterator = { offset: 0 };\n do {\n //\n // QUESTION: should we buffer the message in case it's not fully read?\n //\n\n const length = decode.number(messages as any, it);\n this.events.onmessage({ data: messages.subarray(it.offset, it.offset + length) });\n it.offset += length;\n } while (it.offset < messages.length);\n\n } catch (e: any) {\n if (e.message.indexOf(\"session is closed\") === -1) {\n console.error(\"H3Transport: failed to read incoming data\", e);\n }\n break;\n }\n\n if (result.done) {\n break;\n }\n }\n }\n\n protected sendSeatReservation (roomId: string, sessionId: string, reconnectionToken?: string, skipHandshake?: boolean) {\n const it: Iterator = { offset: 0 };\n const bytes: number[] = [];\n\n encode.string(bytes, roomId, it);\n encode.string(bytes, sessionId, it);\n\n if (reconnectionToken) {\n encode.string(bytes, reconnectionToken, it);\n }\n\n if (skipHandshake) {\n encode.boolean(bytes, 1, it);\n }\n\n this.writer.write(new Uint8Array(bytes).buffer);\n }\n\n protected _close() {\n this.isOpen = false;\n }\n\n}\n"],"names":["encode","decode"],"mappings":";;;;;;;;;;;MAGa,oBAAoB,CAAA;AAa7B,IAAA,WAAA,CAAY,MAA0B,EAAA;QAXtC,IAAA,CAAA,MAAM,GAAY,KAAK;QASf,IAAA,CAAA,kBAAkB,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;AAG3C,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM;IACxB;AAEO,IAAA,OAAO,CAAC,GAAW,EAAE,OAAA,GAAe,EAAE,EAAA;AACzC,QAAA,MAAM,MAAM,GA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.
4
4
  // https://opensource.org/license/MIT
5
5
  //
6
- // colyseus.js@0.17.41
6
+ // colyseus.js@0.18.0
7
7
  import { encode, decode } from '@colyseus/schema';
8
8
 
9
9
  class H3TransportTransport {
@@ -1 +1 @@
1
- {"version":3,"file":"H3Transport.mjs","sources":["../../src/transport/H3Transport.ts"],"sourcesContent":["import { encode, decode, type Iterator } from '@colyseus/schema';\nimport type { ITransport, ITransportEventMap } from \"./ITransport.ts\";\n\nexport class H3TransportTransport implements ITransport {\n wt: WebTransport;\n isOpen: boolean = false;\n events: ITransportEventMap;\n\n reader: ReadableStreamDefaultReader;\n writer: WritableStreamDefaultWriter;\n\n unreliableReader: ReadableStreamDefaultReader<Uint8Array>;\n unreliableWriter: WritableStreamDefaultWriter<Uint8Array>;\n\n private lengthPrefixBuffer = new Uint8Array(9); // 9 bytes is the maximum length of a length prefix\n\n constructor(events: ITransportEventMap) {\n this.events = events;\n }\n\n public connect(url: string, options: any = {}) {\n const wtOpts: WebTransportOptions = options.fingerprint && ({\n // requireUnreliable: true,\n // congestionControl: \"default\", // \"low-latency\" || \"throughput\"\n\n serverCertificateHashes: [{\n algorithm: 'sha-256',\n value: new Uint8Array(options.fingerprint).buffer\n }]\n }) || undefined;\n\n this.wt = new WebTransport(url, wtOpts);\n\n this.wt.ready.then((e) => {\n console.log(\"WebTransport ready!\", e)\n this.isOpen = true;\n\n this.unreliableReader = this.wt.datagrams.readable.getReader();\n this.unreliableWriter = this.wt.datagrams.writable.getWriter();\n\n const incomingBidi = this.wt.incomingBidirectionalStreams.getReader();\n incomingBidi.read().then((stream) => {\n this.reader = stream.value.readable.getReader();\n this.writer = stream.value.writable.getWriter();\n\n // immediately write room/sessionId for establishing the room connection\n this.sendSeatReservation(options.roomId, options.sessionId, options.reconnectionToken, options.skipHandshake);\n\n // start reading incoming data\n this.readIncomingData();\n this.readIncomingUnreliableData();\n\n }).catch((e) => {\n console.error(\"failed to read incoming stream\", e);\n console.error(\"TODO: close the connection\");\n });\n\n // this.events.onopen(e);\n }).catch((e: WebTransportCloseInfo) => {\n // this.events.onerror(e);\n // this.events.onclose({ code: e.closeCode, reason: e.reason });\n console.log(\"WebTransport not ready!\", e)\n this._close();\n });\n\n this.wt.closed.then((e: WebTransportCloseInfo) => {\n console.log(\"WebTransport closed w/ success\", e)\n this.events.onclose({ code: e.closeCode, reason: e.reason });\n\n }).catch((e: WebTransportCloseInfo) => {\n console.log(\"WebTransport closed w/ error\", e)\n this.events.onerror(e);\n this.events.onclose({ code: e.closeCode, reason: e.reason });\n }).finally(() => {\n this._close();\n });\n }\n\n public send(data: Buffer | Uint8Array): void {\n const prefixLength = encode.number(this.lengthPrefixBuffer as any, data.length, { offset: 0 });\n const dataWithPrefixedLength = new Uint8Array(prefixLength + data.length);\n dataWithPrefixedLength.set(this.lengthPrefixBuffer.subarray(0, prefixLength), 0);\n dataWithPrefixedLength.set(data, prefixLength);\n this.writer.write(dataWithPrefixedLength);\n }\n\n public sendUnreliable(data: Buffer | Uint8Array): void {\n const prefixLength = encode.number(this.lengthPrefixBuffer as any, data.length, { offset: 0 });\n const dataWithPrefixedLength = new Uint8Array(prefixLength + data.length);\n dataWithPrefixedLength.set(this.lengthPrefixBuffer.subarray(0, prefixLength), 0);\n dataWithPrefixedLength.set(data, prefixLength);\n this.unreliableWriter.write(dataWithPrefixedLength);\n }\n\n public close(code?: number, reason?: string) {\n try {\n this.wt.close({ closeCode: code, reason: reason });\n } catch (e) {\n console.error(e);\n }\n }\n\n protected async readIncomingData() {\n let result: ReadableStreamReadResult<Uint8Array>;\n\n while (this.isOpen) {\n try {\n result = await this.reader.read();\n\n //\n // a single read may contain multiple messages\n // each message is prefixed with its length\n //\n\n const messages = result.value;\n const it: Iterator = { offset: 0 };\n do {\n //\n // QUESTION: should we buffer the message in case it's not fully read?\n //\n\n const length = decode.number(messages as any, it);\n this.events.onmessage({ data: messages.subarray(it.offset, it.offset + length) });\n it.offset += length;\n } while (it.offset < messages.length);\n\n } catch (e) {\n if (e.message.indexOf(\"session is closed\") === -1) {\n console.error(\"H3Transport: failed to read incoming data\", e);\n }\n break;\n }\n\n if (result.done) {\n break;\n }\n }\n }\n\n protected async readIncomingUnreliableData() {\n let result: ReadableStreamReadResult<Uint8Array>;\n\n while (this.isOpen) {\n try {\n result = await this.unreliableReader.read();\n\n //\n // a single read may contain multiple messages\n // each message is prefixed with its length\n //\n\n const messages = result.value;\n const it: Iterator = { offset: 0 };\n do {\n //\n // QUESTION: should we buffer the message in case it's not fully read?\n //\n\n const length = decode.number(messages as any, it);\n this.events.onmessage({ data: messages.subarray(it.offset, it.offset + length) });\n it.offset += length;\n } while (it.offset < messages.length);\n\n } catch (e) {\n if (e.message.indexOf(\"session is closed\") === -1) {\n console.error(\"H3Transport: failed to read incoming data\", e);\n }\n break;\n }\n\n if (result.done) {\n break;\n }\n }\n }\n\n protected sendSeatReservation (roomId: string, sessionId: string, reconnectionToken?: string, skipHandshake?: boolean) {\n const it: Iterator = { offset: 0 };\n const bytes: number[] = [];\n\n encode.string(bytes, roomId, it);\n encode.string(bytes, sessionId, it);\n\n if (reconnectionToken) {\n encode.string(bytes, reconnectionToken, it);\n }\n\n if (skipHandshake) {\n encode.boolean(bytes, 1, it);\n }\n\n this.writer.write(new Uint8Array(bytes).buffer);\n }\n\n protected _close() {\n this.isOpen = false;\n }\n\n}\n"],"names":[],"mappings":";;;;;;;;MAGa,oBAAoB,CAAA;AAC7B,IAAA,EAAE;IACF,MAAM,GAAY,KAAK;AACvB,IAAA,MAAM;AAEN,IAAA,MAAM;AACN,IAAA,MAAM;AAEN,IAAA,gBAAgB;AAChB,IAAA,gBAAgB;IAER,kBAAkB,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;AAE/C,IAAA,WAAA,CAAY,MAA0B,EAAA;AAClC,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM;IACxB;AAEO,IAAA,OAAO,CAAC,GAAW,EAAE,OAAA,GAAe,EAAE,EAAA;AACzC,QAAA,MAAM,MAAM,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yseus/schema';\nimport type { ITransport, ITransportEventMap } from \"./ITransport.ts\";\n\nexport class H3TransportTransport implements ITransport {\n wt: WebTransport;\n isOpen: boolean = false;\n events: ITransportEventMap;\n\n reader: ReadableStreamDefaultReader;\n writer: WritableStreamDefaultWriter;\n\n unreliableReader: ReadableStreamDefaultReader<Uint8Array>;\n unreliableWriter: WritableStreamDefaultWriter<Uint8Array>;\n\n private lengthPrefixBuffer = new Uint8Array(9); // 9 bytes is the maximum length of a length prefix\n\n constructor(events: ITransportEventMap) {\n this.events = events;\n }\n\n public connect(url: string, options: any = {}) {\n const wtOpts: WebTransportOptions = options.fingerprint && ({\n // requireUnreliable: true,\n // congestionControl: \"default\", // \"low-latency\" || \"throughput\"\n\n serverCertificateHashes: [{\n algorithm: 'sha-256',\n value: new Uint8Array(options.fingerprint).buffer\n }]\n }) || undefined;\n\n this.wt = new WebTransport(url, wtOpts);\n\n this.wt.ready.then((e) => {\n console.log(\"WebTransport ready!\", e)\n this.isOpen = true;\n\n this.unreliableReader = this.wt.datagrams.readable.getReader();\n this.unreliableWriter = this.wt.datagrams.writable.getWriter();\n\n const incomingBidi = this.wt.incomingBidirectionalStreams.getReader();\n incomingBidi.read().then((stream) => {\n this.reader = stream.value.readable.getReader();\n this.writer = stream.value.writable.getWriter();\n\n // immediately write room/sessionId for establishing the room connection\n this.sendSeatReservation(options.roomId, options.sessionId, options.reconnectionToken, options.skipHandshake);\n\n // start reading incoming data\n this.readIncomingData();\n this.readIncomingUnreliableData();\n\n }).catch((e) => {\n console.error(\"failed to read incoming stream\", e);\n console.error(\"TODO: close the connection\");\n });\n\n // this.events.onopen(e);\n }).catch((e: WebTransportCloseInfo) => {\n // this.events.onerror(e);\n // this.events.onclose({ code: e.closeCode, reason: e.reason });\n console.log(\"WebTransport not ready!\", e)\n this._close();\n });\n\n this.wt.closed.then((e: WebTransportCloseInfo) => {\n console.log(\"WebTransport closed w/ success\", e)\n this.events.onclose({ code: e.closeCode, reason: e.reason });\n\n }).catch((e: WebTransportCloseInfo) => {\n console.log(\"WebTransport closed w/ error\", e)\n this.events.onerror(e);\n this.events.onclose({ code: e.closeCode, reason: e.reason });\n }).finally(() => {\n this._close();\n });\n }\n\n public send(data: Buffer | Uint8Array): void {\n const prefixLength = encode.number(this.lengthPrefixBuffer as any, data.length, { offset: 0 });\n const dataWithPrefixedLength = new Uint8Array(prefixLength + data.length);\n dataWithPrefixedLength.set(this.lengthPrefixBuffer.subarray(0, prefixLength), 0);\n dataWithPrefixedLength.set(data, prefixLength);\n this.writer.write(dataWithPrefixedLength);\n }\n\n public sendUnreliable(data: Buffer | Uint8Array): void {\n const prefixLength = encode.number(this.lengthPrefixBuffer as any, data.length, { offset: 0 });\n const dataWithPrefixedLength = new Uint8Array(prefixLength + data.length);\n dataWithPrefixedLength.set(this.lengthPrefixBuffer.subarray(0, prefixLength), 0);\n dataWithPrefixedLength.set(data, prefixLength);\n this.unreliableWriter.write(dataWithPrefixedLength);\n }\n\n public close(code?: number, reason?: string) {\n try {\n this.wt.close({ closeCode: code, reason: reason });\n } catch (e) {\n console.error(e);\n }\n }\n\n protected async readIncomingData() {\n let result: ReadableStreamReadResult<Uint8Array>;\n\n while (this.isOpen) {\n try {\n result = await this.reader.read();\n\n //\n // a single read may contain multiple messages\n // each message is prefixed with its length\n //\n\n const messages = result.value;\n const it: Iterator = { offset: 0 };\n do {\n //\n // QUESTION: should we buffer the message in case it's not fully read?\n //\n\n const length = decode.number(messages as any, it);\n this.events.onmessage({ data: messages.subarray(it.offset, it.offset + length) });\n it.offset += length;\n } while (it.offset < messages.length);\n\n } catch (e: any) {\n if (e.message.indexOf(\"session is closed\") === -1) {\n console.error(\"H3Transport: failed to read incoming data\", e);\n }\n break;\n }\n\n if (result.done) {\n break;\n }\n }\n }\n\n protected async readIncomingUnreliableData() {\n let result: ReadableStreamReadResult<Uint8Array>;\n\n while (this.isOpen) {\n try {\n result = await this.unreliableReader.read();\n\n //\n // a single read may contain multiple messages\n // each message is prefixed with its length\n //\n\n const messages = result.value;\n const it: Iterator = { offset: 0 };\n do {\n //\n // QUESTION: should we buffer the message in case it's not fully read?\n //\n\n const length = decode.number(messages as any, it);\n this.events.onmessage({ data: messages.subarray(it.offset, it.offset + length) });\n it.offset += length;\n } while (it.offset < messages.length);\n\n } catch (e: any) {\n if (e.message.indexOf(\"session is closed\") === -1) {\n console.error(\"H3Transport: failed to read incoming data\", e);\n }\n break;\n }\n\n if (result.done) {\n break;\n }\n }\n }\n\n protected sendSeatReservation (roomId: string, sessionId: string, reconnectionToken?: string, skipHandshake?: boolean) {\n const it: Iterator = { offset: 0 };\n const bytes: number[] = [];\n\n encode.string(bytes, roomId, it);\n encode.string(bytes, sessionId, it);\n\n if (reconnectionToken) {\n encode.string(bytes, reconnectionToken, it);\n }\n\n if (skipHandshake) {\n encode.boolean(bytes, 1, it);\n }\n\n this.writer.write(new Uint8Array(bytes).buffer);\n }\n\n protected _close() {\n this.isOpen = false;\n }\n\n}\n"],"names":[],"mappings":";;;;;;;;MAGa,oBAAoB,CAAA;AAC7B,IAAA,EAAE;IACF,MAAM,GAAY,KAAK;AACvB,IAAA,MAAM;AAEN,IAAA,MAAM;AACN,IAAA,MAAM;AAEN,IAAA,gBAAgB;AAChB,IAAA,gBAAgB;IAER,kBAAkB,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;AAE/C,IAAA,WAAA,CAAY,MAA0B,EAAA;AAClC,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM;IACxB;AAEO,IAAA,OAAO,CAAC,GAAW,EAAE,OAAA,GAAe,EAAE,EAAA;AACzC,QAAA,MAAM,MAAM,GAAwB,OAAO,CAAC,WAAW,KAAK;;;AAIxD,YAAA,uBAAuB,EAAE,CAAC;AACtB,oBAAA,SAAS,EAAE,SAAS;oBACpB,KAAK,EAAE,IAAI,UAAU,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;iBAC9C;SACJ,CAAC,IAAI,SAAS;QAEf,IAAI,CAAC,EAAE,GAAG,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A,IAAI,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,EAAE;AAC/C,oBAAA,OAAO,CAAC,KAAK,CAAC,2CAA2C,EAAE,CAAC,CAAC;gBACjE;gBACA;YACJ;AAEA,YAAA,IAAI,MAAM,CAAC,IAAI,EAAE;gBACb;YACJ;QACJ;IACJ;AAEU,IAAA,mBAAmB,CAAE,MAAc,EAAE,SAAiB,EAAE,iBAA0B,EAAE,aAAuB,EAAA;AACjH,QAAA,MAAM,EAAE,GAAa,EAAE,MAAM,EAAE,CAAC,EAAE;QAClC,MAAM,KAAK,GAAa,EAAE;QAE1B,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC;QAChC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,CAAC;QAEnC,IAAI,iBAAiB,EAAE;YACnB,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,iBAAiB,EAAE,EAAE,CAAC;QAC/C;QAEA,IAAI,aAAa,EAAE;YACf,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC;AAEA,QAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC;IACnD;IAEU,MAAM,GAAA;AACZ,QAAA,IAAI,CAAC,MAAM,GAAG,KAAK;IACvB;AAEH;;;;"}
@@ -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.41
6
+ // colyseus.js@0.18.0
7
7
  'use strict';
8
8
 
9
9
  var NodeWebSocket = require('ws');
@@ -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.41
6
+ // colyseus.js@0.18.0
7
7
  import NodeWebSocket from 'ws';
8
8
  import { CloseCode } from '@colyseus/shared-types';
9
9