@colyseus/sdk 0.17.40 → 0.17.42

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 (52) 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 +1 -1
  4. package/build/Auth.mjs +1 -1
  5. package/build/Client.cjs +1 -1
  6. package/build/Client.mjs +1 -1
  7. package/build/Connection.cjs +1 -1
  8. package/build/Connection.mjs +1 -1
  9. package/build/HTTP.cjs +1 -1
  10. package/build/HTTP.mjs +1 -1
  11. package/build/Room.cjs +1 -1
  12. package/build/Room.mjs +1 -1
  13. package/build/Storage.cjs +1 -1
  14. package/build/Storage.mjs +1 -1
  15. package/build/core/nanoevents.cjs +1 -1
  16. package/build/core/nanoevents.mjs +1 -1
  17. package/build/core/signal.cjs +1 -1
  18. package/build/core/signal.mjs +1 -1
  19. package/build/core/utils.cjs +1 -1
  20. package/build/core/utils.mjs +1 -1
  21. package/build/debug.cjs +70 -44
  22. package/build/debug.cjs.map +1 -1
  23. package/build/debug.mjs +70 -44
  24. package/build/debug.mjs.map +1 -1
  25. package/build/errors/Errors.cjs +1 -1
  26. package/build/errors/Errors.mjs +1 -1
  27. package/build/fetchXHR.cjs +1 -1
  28. package/build/fetchXHR.mjs +1 -1
  29. package/build/index.cjs +1 -1
  30. package/build/index.mjs +1 -1
  31. package/build/legacy.cjs +1 -1
  32. package/build/legacy.mjs +1 -1
  33. package/build/serializer/NoneSerializer.cjs +1 -1
  34. package/build/serializer/NoneSerializer.mjs +1 -1
  35. package/build/serializer/SchemaSerializer.cjs +1 -1
  36. package/build/serializer/SchemaSerializer.mjs +1 -1
  37. package/build/serializer/Serializer.cjs +1 -1
  38. package/build/serializer/Serializer.mjs +1 -1
  39. package/build/transport/H3Transport.cjs +70 -21
  40. package/build/transport/H3Transport.cjs.map +1 -1
  41. package/build/transport/H3Transport.d.ts +16 -0
  42. package/build/transport/H3Transport.mjs +69 -23
  43. package/build/transport/H3Transport.mjs.map +1 -1
  44. package/build/transport/WebSocketTransport.cjs +1 -1
  45. package/build/transport/WebSocketTransport.mjs +1 -1
  46. package/dist/colyseus.js +69 -21
  47. package/dist/colyseus.js.map +1 -1
  48. package/dist/debug.js +70 -44
  49. package/dist/debug.js.map +1 -1
  50. package/package.json +4 -4
  51. package/src/debug.ts +69 -43
  52. package/src/transport/H3Transport.ts +74 -24
@@ -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.40
6
+ // colyseus.js@0.17.42
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.40
6
+ // colyseus.js@0.17.42
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.40
6
+ // colyseus.js@0.17.42
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.40
6
+ // colyseus.js@0.17.42
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.40
6
+ // colyseus.js@0.17.42
7
7
  'use strict';
8
8
 
9
9
  require('./legacy.cjs');
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.40
6
+ // colyseus.js@0.17.42
7
7
  import './legacy.mjs';
8
8
  export { Client, ColyseusSDK } from './Client.mjs';
9
9
  export { Room } from './Room.mjs';
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.40
6
+ // colyseus.js@0.17.42
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.40
6
+ // colyseus.js@0.17.42
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.40
6
+ // colyseus.js@0.17.42
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.40
6
+ // colyseus.js@0.17.42
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.40
6
+ // colyseus.js@0.17.42
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.40
6
+ // colyseus.js@0.17.42
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.40
6
+ // colyseus.js@0.17.42
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.40
6
+ // colyseus.js@0.17.42
7
7
  const serializers = {};
8
8
  function registerSerializer(id, serializer) {
9
9
  serializers[id] = serializer;
@@ -3,16 +3,76 @@
3
3
  // This software is released under the MIT License.
4
4
  // https://opensource.org/license/MIT
5
5
  //
6
- // colyseus.js@0.17.40
6
+ // colyseus.js@0.17.42
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
+ }
12
70
  class H3TransportTransport {
13
71
  constructor(events) {
14
72
  this.isOpen = false;
15
73
  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();
16
76
  this.events = events;
17
77
  }
18
78
  connect(url, options = {}) {
@@ -92,17 +152,11 @@ class H3TransportTransport {
92
152
  //
93
153
  // a single read may contain multiple messages
94
154
  // each message is prefixed with its length
155
+ // a read may also deliver a partial frame; buffer across reads
95
156
  //
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);
157
+ for (const frame of this.reliableReassembler.push(result.value)) {
158
+ this.events.onmessage({ data: frame });
159
+ }
106
160
  }
107
161
  catch (e) {
108
162
  if (e.message.indexOf("session is closed") === -1) {
@@ -125,17 +179,11 @@ class H3TransportTransport {
125
179
  //
126
180
  // a single read may contain multiple messages
127
181
  // each message is prefixed with its length
182
+ // a read may also deliver a partial frame; buffer across reads
128
183
  //
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);
184
+ for (const frame of this.unreliableReassembler.push(result.value)) {
185
+ this.events.onmessage({ data: frame });
186
+ }
139
187
  }
140
188
  catch (e) {
141
189
  if (e.message.indexOf("session is closed") === -1) {
@@ -167,5 +215,6 @@ class H3TransportTransport {
167
215
  }
168
216
  }
169
217
 
218
+ exports.FrameReassembler = FrameReassembler;
170
219
  exports.H3TransportTransport = H3TransportTransport;
171
220
  //# 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\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,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,M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":["../../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,GAAiB,EAAE;QAC/B,IAAI,MAAM,GAAG,CAAC;AAEd,QAAA,OAAO,MAAM,GAAG,KAAK,CAAC,UAAU,EAAE;AAC9B,YAAA,MAAM,EAAE,GAAa,EAAE,MAAM,EAAE;AAC/B,YAAA,IAAI,MAAc;AAElB,YAAA,IAAI;gBACA,MAAM,GAAGA,aAAM,CAAC,MAAM,CAAC,KAAY,EAAE,EAAE,CAAC;YAC5C;YAAE,OAAO,CAAC,EAAE;;gBAER,IAAI,KAAK,CAAC,UAAU,GAAG,MAAM,IAAI,uBAAuB,EAAE;oBAAE;gBAAO;AACnE,gBAAA,MAAM,CAAC;YACX;AAEA,YAAA,MAAM,QAAQ,GAAG,EAAE,CAAC,MAAM,GAAG,MAAM;AACnC,YAAA,IAAI,QAAQ,GAAG,KAAK,CAAC,U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,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,4 +1,18 @@
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
+ }
2
16
  export declare class H3TransportTransport implements ITransport {
3
17
  wt: WebTransport;
4
18
  isOpen: boolean;
@@ -8,6 +22,8 @@ export declare class H3TransportTransport implements ITransport {
8
22
  unreliableReader: ReadableStreamDefaultReader<Uint8Array>;
9
23
  unreliableWriter: WritableStreamDefaultWriter<Uint8Array>;
10
24
  private lengthPrefixBuffer;
25
+ private reliableReassembler;
26
+ private unreliableReassembler;
11
27
  constructor(events: ITransportEventMap);
12
28
  connect(url: string, options?: any): void;
13
29
  send(data: Buffer | Uint8Array): void;
@@ -3,9 +3,65 @@
3
3
  // This software is released under the MIT License.
4
4
  // https://opensource.org/license/MIT
5
5
  //
6
- // colyseus.js@0.17.40
7
- import { encode, decode } from '@colyseus/schema';
6
+ // colyseus.js@0.17.42
7
+ import { decode, encode } from '@colyseus/schema';
8
8
 
9
+ // 9 bytes is the maximum length of a variable-length integer prefix
10
+ const MAX_LENGTH_PREFIX_BYTES = 9;
11
+ /**
12
+ * Reassembles length-prefixed frames from arbitrary byte chunks.
13
+ *
14
+ * A single WebTransport `reader.read()` may:
15
+ * - deliver multiple whole frames in one chunk
16
+ * - split a frame (or its length prefix) across multiple chunks
17
+ *
18
+ * This reassembler buffers partial data across reads so each dispatched
19
+ * frame is exactly one complete message.
20
+ */
21
+ class FrameReassembler {
22
+ pending = new Uint8Array(0);
23
+ push(chunk) {
24
+ if (!chunk || chunk.byteLength === 0) {
25
+ return [];
26
+ }
27
+ const bytes = (this.pending.byteLength === 0)
28
+ ? chunk
29
+ : concatBytes(this.pending, chunk);
30
+ const frames = [];
31
+ let offset = 0;
32
+ while (offset < bytes.byteLength) {
33
+ const it = { offset };
34
+ let length;
35
+ try {
36
+ length = decode.number(bytes, it);
37
+ }
38
+ catch (e) {
39
+ // length prefix is incomplete — wait for more bytes
40
+ if (bytes.byteLength - offset <= MAX_LENGTH_PREFIX_BYTES) {
41
+ break;
42
+ }
43
+ throw e;
44
+ }
45
+ const frameEnd = it.offset + length;
46
+ if (frameEnd > bytes.byteLength) {
47
+ // payload is incomplete — wait for more bytes
48
+ break;
49
+ }
50
+ frames.push(bytes.subarray(it.offset, frameEnd));
51
+ offset = frameEnd;
52
+ }
53
+ this.pending = (offset < bytes.byteLength)
54
+ ? bytes.slice(offset)
55
+ : new Uint8Array(0);
56
+ return frames;
57
+ }
58
+ }
59
+ function concatBytes(a, b) {
60
+ const out = new Uint8Array(a.byteLength + b.byteLength);
61
+ out.set(a, 0);
62
+ out.set(b, a.byteLength);
63
+ return out;
64
+ }
9
65
  class H3TransportTransport {
10
66
  wt;
11
67
  isOpen = false;
@@ -15,6 +71,8 @@ class H3TransportTransport {
15
71
  unreliableReader;
16
72
  unreliableWriter;
17
73
  lengthPrefixBuffer = new Uint8Array(9); // 9 bytes is the maximum length of a length prefix
74
+ reliableReassembler = new FrameReassembler();
75
+ unreliableReassembler = new FrameReassembler();
18
76
  constructor(events) {
19
77
  this.events = events;
20
78
  }
@@ -94,17 +152,11 @@ class H3TransportTransport {
94
152
  //
95
153
  // a single read may contain multiple messages
96
154
  // each message is prefixed with its length
155
+ // a read may also deliver a partial frame; buffer across reads
97
156
  //
98
- const messages = result.value;
99
- const it = { offset: 0 };
100
- do {
101
- //
102
- // QUESTION: should we buffer the message in case it's not fully read?
103
- //
104
- const length = decode.number(messages, it);
105
- this.events.onmessage({ data: messages.subarray(it.offset, it.offset + length) });
106
- it.offset += length;
107
- } while (it.offset < messages.length);
157
+ for (const frame of this.reliableReassembler.push(result.value)) {
158
+ this.events.onmessage({ data: frame });
159
+ }
108
160
  }
109
161
  catch (e) {
110
162
  if (e.message.indexOf("session is closed") === -1) {
@@ -125,17 +177,11 @@ class H3TransportTransport {
125
177
  //
126
178
  // a single read may contain multiple messages
127
179
  // each message is prefixed with its length
180
+ // a read may also deliver a partial frame; buffer across reads
128
181
  //
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 = 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);
182
+ for (const frame of this.unreliableReassembler.push(result.value)) {
183
+ this.events.onmessage({ data: frame });
184
+ }
139
185
  }
140
186
  catch (e) {
141
187
  if (e.message.indexOf("session is closed") === -1) {
@@ -166,5 +212,5 @@ class H3TransportTransport {
166
212
  }
167
213
  }
168
214
 
169
- export { H3TransportTransport };
215
+ export { FrameReassembler, H3TransportTransport };
170
216
  //# sourceMappingURL=H3Transport.mjs.map
@@ -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,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,I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,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;;;;"}
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\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":[],"mappings":";;;;;;;;AAGA;AACA,MAAM,uBAAuB,GAAG,CAAC;A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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.40
6
+ // colyseus.js@0.17.42
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.40
6
+ // colyseus.js@0.17.42
7
7
  import NodeWebSocket from 'ws';
8
8
  import { CloseCode } from '@colyseus/shared-types';
9
9