@colyseus/sdk 0.17.42 → 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.
- package/build/3rd_party/discord.cjs +1 -1
- package/build/3rd_party/discord.mjs +1 -1
- package/build/Auth.cjs +16 -2
- package/build/Auth.cjs.map +1 -1
- package/build/Auth.mjs +16 -2
- package/build/Auth.mjs.map +1 -1
- package/build/Client.cjs +1 -1
- package/build/Client.mjs +1 -1
- package/build/Connection.cjs +1 -1
- package/build/Connection.mjs +1 -1
- package/build/HTTP.cjs +1 -1
- package/build/HTTP.mjs +1 -1
- package/build/Room.cjs +231 -46
- package/build/Room.cjs.map +1 -1
- package/build/Room.d.ts +62 -2
- package/build/Room.mjs +229 -44
- package/build/Room.mjs.map +1 -1
- package/build/Storage.cjs +1 -1
- package/build/Storage.mjs +1 -1
- package/build/core/nanoevents.cjs +1 -1
- package/build/core/nanoevents.mjs +1 -1
- package/build/core/signal.cjs +1 -1
- package/build/core/signal.cjs.map +1 -1
- package/build/core/signal.mjs +1 -1
- package/build/core/signal.mjs.map +1 -1
- package/build/core/utils.cjs +1 -1
- package/build/core/utils.mjs +1 -1
- package/build/debug.cjs +1 -1
- package/build/debug.cjs.map +1 -1
- package/build/debug.mjs +1 -1
- package/build/debug.mjs.map +1 -1
- package/build/errors/Errors.cjs +1 -1
- package/build/errors/Errors.mjs +1 -1
- package/build/fetchXHR.cjs +1 -1
- package/build/fetchXHR.mjs +1 -1
- package/build/index.cjs +1 -1
- package/build/index.cjs.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.mjs +1 -1
- package/build/index.mjs.map +1 -1
- package/build/input/InputHandle.cjs +47 -0
- package/build/input/InputHandle.cjs.map +1 -0
- package/build/input/InputHandle.d.ts +79 -0
- package/build/input/InputHandle.mjs +48 -0
- package/build/input/InputHandle.mjs.map +1 -0
- package/build/legacy.cjs +1 -1
- package/build/legacy.mjs +1 -1
- package/build/serializer/NoneSerializer.cjs +1 -1
- package/build/serializer/NoneSerializer.mjs +1 -1
- package/build/serializer/SchemaSerializer.cjs +1 -1
- package/build/serializer/SchemaSerializer.mjs +1 -1
- package/build/serializer/Serializer.cjs +1 -1
- package/build/serializer/Serializer.mjs +1 -1
- package/build/transport/H3Transport.cjs +21 -70
- package/build/transport/H3Transport.cjs.map +1 -1
- package/build/transport/H3Transport.d.ts +0 -16
- package/build/transport/H3Transport.mjs +23 -69
- package/build/transport/H3Transport.mjs.map +1 -1
- package/build/transport/WebSocketTransport.cjs +1 -1
- package/build/transport/WebSocketTransport.mjs +1 -1
- package/dist/colyseus.js +13172 -1953
- package/dist/colyseus.js.map +1 -1
- package/dist/debug.js +1 -1
- package/dist/debug.js.map +1 -1
- package/package.json +11 -8
- package/src/Auth.ts +11 -1
- package/src/Room.ts +294 -48
- package/src/core/signal.ts +1 -1
- package/src/debug.ts +8 -8
- package/src/index.ts +1 -1
- package/src/input/InputHandle.ts +115 -0
- package/src/transport/H3Transport.ts +26 -76
- package/build/serializer/FossilDeltaSerializer.d.ts +0 -0
- package/src/serializer/FossilDeltaSerializer.ts +0 -39
package/build/errors/Errors.cjs
CHANGED
package/build/errors/Errors.mjs
CHANGED
package/build/fetchXHR.cjs
CHANGED
package/build/fetchXHR.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.
|
|
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
package/build/index.cjs.map
CHANGED
|
@@ -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
package/build/index.mjs.map
CHANGED
|
@@ -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,EAAE,IAAO,EAAE,OAA0B,EAAA;AAF9D,QAAA,IAAA,CAAA,QAAQ,GAAe,IAAI,UAAU,CAAC,IAAI,CAAC;AAGjD,QAAA,IAAI,CAAC,KAAK,GAAG,IAAI;AACjB,QAAA,IAAI,CAAC,IAAI,GAAG,IAAI;AAChB,QAAA,IAAI,CAAC,QAAQ,GAAG,OAAO;IACzB;IAEA,IAAI,IAAI,GAAA,EAAgB,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAEnD,KAAK,GAAA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';
|
|
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,KAAK;AACL,IAAA,QAAQ;AACR,IAAA,QAAQ,GAAe,IAAI,UAAU,CAAC,IAAI,CAAC;AAEnD,IAAA,WAAA,CAAY,IAAqB,EAAE,IAAO,EAAE,OAA0B,EAAA;AACpE,QAAA,IAAI,CAAC,KAAK,GAAG,IAAI;AACjB,QAAA,IAAI,CAAC,IAAI,GAAG,IAAI;AAChB,QAAA,IAAI,CAAC,QAAQ,GAAG,OAAO;IACzB;IAEA,IAAI,IAAI,GAAA,EAAgB,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAEnD,KAAK,GAAA,EAAW,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAEvC,IAAI,GAAA;AACF,QAAA,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU;QAClC,IAAI,CAAC,IAAI,EAAE,MAAM;YAAE;QAEnB,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;AACpC,QAAA,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE;AAExB,QAAA,MAAM,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM;QAC9B,IAAI,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE;YACpC,IAAI,CAAC,QAAQ,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;QAC/E;AACA,QAAA,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK;cACtC,QAAQ,CAAC;AACX,cAAE,QAAQ,CAAC,qBAAqB;QAClC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC;AAE3B,QAAA,MAAM,MAAM,GAAG,IAAI,CAAC,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;;;;"}
|
package/build/legacy.cjs
CHANGED
package/build/legacy.mjs
CHANGED
|
@@ -3,76 +3,16 @@
|
|
|
3
3
|
// This software is released under the MIT License.
|
|
4
4
|
// https://opensource.org/license/MIT
|
|
5
5
|
//
|
|
6
|
-
// colyseus.js@0.
|
|
6
|
+
// colyseus.js@0.18.0
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
9
|
var tslib = require('tslib');
|
|
10
10
|
var schema = require('@colyseus/schema');
|
|
11
11
|
|
|
12
|
-
// 9 bytes is the maximum length of a variable-length integer prefix
|
|
13
|
-
const MAX_LENGTH_PREFIX_BYTES = 9;
|
|
14
|
-
/**
|
|
15
|
-
* Reassembles length-prefixed frames from arbitrary byte chunks.
|
|
16
|
-
*
|
|
17
|
-
* A single WebTransport `reader.read()` may:
|
|
18
|
-
* - deliver multiple whole frames in one chunk
|
|
19
|
-
* - split a frame (or its length prefix) across multiple chunks
|
|
20
|
-
*
|
|
21
|
-
* This reassembler buffers partial data across reads so each dispatched
|
|
22
|
-
* frame is exactly one complete message.
|
|
23
|
-
*/
|
|
24
|
-
class FrameReassembler {
|
|
25
|
-
constructor() {
|
|
26
|
-
this.pending = new Uint8Array(0);
|
|
27
|
-
}
|
|
28
|
-
push(chunk) {
|
|
29
|
-
if (!chunk || chunk.byteLength === 0) {
|
|
30
|
-
return [];
|
|
31
|
-
}
|
|
32
|
-
const bytes = (this.pending.byteLength === 0)
|
|
33
|
-
? chunk
|
|
34
|
-
: concatBytes(this.pending, chunk);
|
|
35
|
-
const frames = [];
|
|
36
|
-
let offset = 0;
|
|
37
|
-
while (offset < bytes.byteLength) {
|
|
38
|
-
const it = { offset };
|
|
39
|
-
let length;
|
|
40
|
-
try {
|
|
41
|
-
length = schema.decode.number(bytes, it);
|
|
42
|
-
}
|
|
43
|
-
catch (e) {
|
|
44
|
-
// length prefix is incomplete — wait for more bytes
|
|
45
|
-
if (bytes.byteLength - offset <= MAX_LENGTH_PREFIX_BYTES) {
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
throw e;
|
|
49
|
-
}
|
|
50
|
-
const frameEnd = it.offset + length;
|
|
51
|
-
if (frameEnd > bytes.byteLength) {
|
|
52
|
-
// payload is incomplete — wait for more bytes
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
frames.push(bytes.subarray(it.offset, frameEnd));
|
|
56
|
-
offset = frameEnd;
|
|
57
|
-
}
|
|
58
|
-
this.pending = (offset < bytes.byteLength)
|
|
59
|
-
? bytes.slice(offset)
|
|
60
|
-
: new Uint8Array(0);
|
|
61
|
-
return frames;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
function concatBytes(a, b) {
|
|
65
|
-
const out = new Uint8Array(a.byteLength + b.byteLength);
|
|
66
|
-
out.set(a, 0);
|
|
67
|
-
out.set(b, a.byteLength);
|
|
68
|
-
return out;
|
|
69
|
-
}
|
|
70
12
|
class H3TransportTransport {
|
|
71
13
|
constructor(events) {
|
|
72
14
|
this.isOpen = false;
|
|
73
15
|
this.lengthPrefixBuffer = new Uint8Array(9); // 9 bytes is the maximum length of a length prefix
|
|
74
|
-
this.reliableReassembler = new FrameReassembler();
|
|
75
|
-
this.unreliableReassembler = new FrameReassembler();
|
|
76
16
|
this.events = events;
|
|
77
17
|
}
|
|
78
18
|
connect(url, options = {}) {
|
|
@@ -152,11 +92,17 @@ class H3TransportTransport {
|
|
|
152
92
|
//
|
|
153
93
|
// a single read may contain multiple messages
|
|
154
94
|
// each message is prefixed with its length
|
|
155
|
-
// a read may also deliver a partial frame; buffer across reads
|
|
156
95
|
//
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
96
|
+
const messages = result.value;
|
|
97
|
+
const it = { offset: 0 };
|
|
98
|
+
do {
|
|
99
|
+
//
|
|
100
|
+
// QUESTION: should we buffer the message in case it's not fully read?
|
|
101
|
+
//
|
|
102
|
+
const length = schema.decode.number(messages, it);
|
|
103
|
+
this.events.onmessage({ data: messages.subarray(it.offset, it.offset + length) });
|
|
104
|
+
it.offset += length;
|
|
105
|
+
} while (it.offset < messages.length);
|
|
160
106
|
}
|
|
161
107
|
catch (e) {
|
|
162
108
|
if (e.message.indexOf("session is closed") === -1) {
|
|
@@ -179,11 +125,17 @@ class H3TransportTransport {
|
|
|
179
125
|
//
|
|
180
126
|
// a single read may contain multiple messages
|
|
181
127
|
// each message is prefixed with its length
|
|
182
|
-
// a read may also deliver a partial frame; buffer across reads
|
|
183
128
|
//
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
129
|
+
const messages = result.value;
|
|
130
|
+
const it = { offset: 0 };
|
|
131
|
+
do {
|
|
132
|
+
//
|
|
133
|
+
// QUESTION: should we buffer the message in case it's not fully read?
|
|
134
|
+
//
|
|
135
|
+
const length = schema.decode.number(messages, it);
|
|
136
|
+
this.events.onmessage({ data: messages.subarray(it.offset, it.offset + length) });
|
|
137
|
+
it.offset += length;
|
|
138
|
+
} while (it.offset < messages.length);
|
|
187
139
|
}
|
|
188
140
|
catch (e) {
|
|
189
141
|
if (e.message.indexOf("session is closed") === -1) {
|
|
@@ -215,6 +167,5 @@ class H3TransportTransport {
|
|
|
215
167
|
}
|
|
216
168
|
}
|
|
217
169
|
|
|
218
|
-
exports.FrameReassembler = FrameReassembler;
|
|
219
170
|
exports.H3TransportTransport = H3TransportTransport;
|
|
220
171
|
//# sourceMappingURL=H3Transport.cjs.map
|
|
@@ -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\n// 9 bytes is the maximum length of a variable-length integer prefix\nconst MAX_LENGTH_PREFIX_BYTES = 9;\n\n/**\n * Reassembles length-prefixed frames from arbitrary byte chunks.\n *\n * A single WebTransport `reader.read()` may:\n * - deliver multiple whole frames in one chunk\n * - split a frame (or its length prefix) across multiple chunks\n *\n * This reassembler buffers partial data across reads so each dispatched\n * frame is exactly one complete message.\n */\nexport class FrameReassembler {\n private pending: Uint8Array = new Uint8Array(0);\n\n push(chunk: Uint8Array | undefined): Uint8Array[] {\n if (!chunk || chunk.byteLength === 0) { return []; }\n\n const bytes = (this.pending.byteLength === 0)\n ? chunk\n : concatBytes(this.pending, chunk);\n\n const frames: Uint8Array[] = [];\n let offset = 0;\n\n while (offset < bytes.byteLength) {\n const it: Iterator = { offset };\n let length: number;\n\n try {\n length = decode.number(bytes as any, it);\n } catch (e) {\n // length prefix is incomplete — wait for more bytes\n if (bytes.byteLength - offset <= MAX_LENGTH_PREFIX_BYTES) { break; }\n throw e;\n }\n\n const frameEnd = it.offset + length;\n if (frameEnd > bytes.byteLength) {\n // payload is incomplete — wait for more bytes\n break;\n }\n\n frames.push(bytes.subarray(it.offset, frameEnd));\n offset = frameEnd;\n }\n\n this.pending = (offset < bytes.byteLength)\n ? bytes.slice(offset)\n : new Uint8Array(0);\n\n return frames;\n }\n}\n\nfunction concatBytes(a: Uint8Array, b: Uint8Array): Uint8Array {\n const out = new Uint8Array(a.byteLength + b.byteLength);\n out.set(a, 0);\n out.set(b, a.byteLength);\n return out;\n}\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 private reliableReassembler = new FrameReassembler();\n private unreliableReassembler = new FrameReassembler();\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 // a read may also deliver a partial frame; buffer across reads\n //\n for (const frame of this.reliableReassembler.push(result.value)) {\n this.events.onmessage({ data: frame });\n }\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 // a read may also deliver a partial frame; buffer across reads\n //\n for (const frame of this.unreliableReassembler.push(result.value)) {\n this.events.onmessage({ data: frame });\n }\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":["decode","encode"],"mappings":";;;;;;;;;;;AAGA;AACA,MAAM,uBAAuB,GAAG,CAAC;AAEjC;;;;;;;;;AASG;MACU,gBAAgB,CAAA;AAA7B,IAAA,WAAA,GAAA;AACY,QAAA,IAAA,CAAA,OAAO,GAAe,IAAI,UAAU,CAAC,CAAC,CAAC;IAwCnD;AAtCI,IAAA,IAAI,CAAC,KAA6B,EAAA;QAC9B,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,UAAU,KAAK,CAAC,EAAE;AAAE,YAAA,OAAO,EAAE;QAAE;QAEnD,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,KAAK,CAAC;AACxC,cAAE;cACA,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC;QAEtC,MAAM,MAAM,G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O,CAAC,EAAE;AACR,oBAAA,IAAI,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,EAAE;AAC/C,wBAAA,OAAO,CAAC,KAAK,CAAC,2CAA2C,EAAE,CAAC,CAAC;oBACjE;oBACA;gBACJ;AAEA,gBAAA,IAAI,MAAM,CAAC,IAAI,EAAE;oBACb;gBACJ;YACJ;QACJ,CAAC,CAAA;AAAA,IAAA;AAES,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;QAE1BA,aAAM,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC;QAChCA,aAAM,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,CAAC;QAEnC,IAAI,iBAAiB,EAAE;YACnBA,aAAM,CAAC,MAAM,CAAC,KAAK,EAAE,iBAAiB,EAAE,EAAE,CAAC;QAC/C;QAEA,IAAI,aAAa,EAAE;YACfA,aAAM,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;;;;;"}
|
|
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,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,IAAI,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC;QAEvC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,KAAI;AACrB,YAAA,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,CAAC,CAAC;AACrC,YAAA,IAAI,CAAC,MAAM,GAAG,IAAI;AAElB,YAAA,IAAI,C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ACJ;YACJ;QACJ,CAAC,CAAA;AAAA,IAAA;AAES,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;QAE1BD,aAAM,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC;QAChCA,aAAM,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,CAAC;QAEnC,IAAI,iBAAiB,EAAE;YACnBA,aAAM,CAAC,MAAM,CAAC,KAAK,EAAE,iBAAiB,EAAE,EAAE,CAAC;QAC/C;QAEA,IAAI,aAAa,EAAE;YACfA,aAAM,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;;;;"}
|
|
@@ -1,18 +1,4 @@
|
|
|
1
1
|
import type { ITransport, ITransportEventMap } from "./ITransport.ts";
|
|
2
|
-
/**
|
|
3
|
-
* Reassembles length-prefixed frames from arbitrary byte chunks.
|
|
4
|
-
*
|
|
5
|
-
* A single WebTransport `reader.read()` may:
|
|
6
|
-
* - deliver multiple whole frames in one chunk
|
|
7
|
-
* - split a frame (or its length prefix) across multiple chunks
|
|
8
|
-
*
|
|
9
|
-
* This reassembler buffers partial data across reads so each dispatched
|
|
10
|
-
* frame is exactly one complete message.
|
|
11
|
-
*/
|
|
12
|
-
export declare class FrameReassembler {
|
|
13
|
-
private pending;
|
|
14
|
-
push(chunk: Uint8Array | undefined): Uint8Array[];
|
|
15
|
-
}
|
|
16
2
|
export declare class H3TransportTransport implements ITransport {
|
|
17
3
|
wt: WebTransport;
|
|
18
4
|
isOpen: boolean;
|
|
@@ -22,8 +8,6 @@ export declare class H3TransportTransport implements ITransport {
|
|
|
22
8
|
unreliableReader: ReadableStreamDefaultReader<Uint8Array>;
|
|
23
9
|
unreliableWriter: WritableStreamDefaultWriter<Uint8Array>;
|
|
24
10
|
private lengthPrefixBuffer;
|
|
25
|
-
private reliableReassembler;
|
|
26
|
-
private unreliableReassembler;
|
|
27
11
|
constructor(events: ITransportEventMap);
|
|
28
12
|
connect(url: string, options?: any): void;
|
|
29
13
|
send(data: Buffer | Uint8Array): void;
|