@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.
- package/build/3rd_party/discord.cjs +1 -1
- package/build/3rd_party/discord.mjs +1 -1
- package/build/Auth.cjs +1 -1
- package/build/Auth.mjs +1 -1
- package/build/Client.cjs +1 -1
- package/build/Client.mjs +1 -1
- package/build/Connection.cjs +1 -1
- package/build/Connection.mjs +1 -1
- package/build/HTTP.cjs +1 -1
- package/build/HTTP.mjs +1 -1
- package/build/Room.cjs +1 -1
- package/build/Room.mjs +1 -1
- package/build/Storage.cjs +1 -1
- package/build/Storage.mjs +1 -1
- package/build/core/nanoevents.cjs +1 -1
- package/build/core/nanoevents.mjs +1 -1
- package/build/core/signal.cjs +1 -1
- package/build/core/signal.mjs +1 -1
- package/build/core/utils.cjs +1 -1
- package/build/core/utils.mjs +1 -1
- package/build/debug.cjs +70 -44
- package/build/debug.cjs.map +1 -1
- package/build/debug.mjs +70 -44
- 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.mjs +1 -1
- package/build/legacy.cjs +1 -1
- package/build/legacy.mjs +1 -1
- package/build/serializer/NoneSerializer.cjs +1 -1
- package/build/serializer/NoneSerializer.mjs +1 -1
- package/build/serializer/SchemaSerializer.cjs +1 -1
- package/build/serializer/SchemaSerializer.mjs +1 -1
- package/build/serializer/Serializer.cjs +1 -1
- package/build/serializer/Serializer.mjs +1 -1
- package/build/transport/H3Transport.cjs +70 -21
- package/build/transport/H3Transport.cjs.map +1 -1
- package/build/transport/H3Transport.d.ts +16 -0
- package/build/transport/H3Transport.mjs +69 -23
- 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 +69 -21
- package/dist/colyseus.js.map +1 -1
- package/dist/debug.js +70 -44
- package/dist/debug.js.map +1 -1
- package/package.json +4 -4
- package/src/debug.ts +69 -43
- package/src/transport/H3Transport.ts +74 -24
package/dist/colyseus.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// This software is released under the MIT License.
|
|
4
4
|
// https://opensource.org/license/MIT
|
|
5
5
|
//
|
|
6
|
-
// colyseus.js@0.17.
|
|
6
|
+
// colyseus.js@0.17.42 - @colyseus/schema 4.0.13
|
|
7
7
|
(function (global, factory) {
|
|
8
8
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
9
9
|
typeof define === 'function' && define.amd ? define('@colyseus/sdk', ['exports'], factory) :
|
|
@@ -8154,10 +8154,70 @@
|
|
|
8154
8154
|
const RESET_BUFFER_MODE = 1024;
|
|
8155
8155
|
const RESERVE_START_SPACE = 2048;
|
|
8156
8156
|
|
|
8157
|
+
// 9 bytes is the maximum length of a variable-length integer prefix
|
|
8158
|
+
const MAX_LENGTH_PREFIX_BYTES = 9;
|
|
8159
|
+
/**
|
|
8160
|
+
* Reassembles length-prefixed frames from arbitrary byte chunks.
|
|
8161
|
+
*
|
|
8162
|
+
* A single WebTransport `reader.read()` may:
|
|
8163
|
+
* - deliver multiple whole frames in one chunk
|
|
8164
|
+
* - split a frame (or its length prefix) across multiple chunks
|
|
8165
|
+
*
|
|
8166
|
+
* This reassembler buffers partial data across reads so each dispatched
|
|
8167
|
+
* frame is exactly one complete message.
|
|
8168
|
+
*/
|
|
8169
|
+
class FrameReassembler {
|
|
8170
|
+
constructor() {
|
|
8171
|
+
this.pending = new Uint8Array(0);
|
|
8172
|
+
}
|
|
8173
|
+
push(chunk) {
|
|
8174
|
+
if (!chunk || chunk.byteLength === 0) {
|
|
8175
|
+
return [];
|
|
8176
|
+
}
|
|
8177
|
+
const bytes = (this.pending.byteLength === 0)
|
|
8178
|
+
? chunk
|
|
8179
|
+
: concatBytes(this.pending, chunk);
|
|
8180
|
+
const frames = [];
|
|
8181
|
+
let offset = 0;
|
|
8182
|
+
while (offset < bytes.byteLength) {
|
|
8183
|
+
const it = { offset };
|
|
8184
|
+
let length;
|
|
8185
|
+
try {
|
|
8186
|
+
length = buildExports.decode.number(bytes, it);
|
|
8187
|
+
}
|
|
8188
|
+
catch (e) {
|
|
8189
|
+
// length prefix is incomplete — wait for more bytes
|
|
8190
|
+
if (bytes.byteLength - offset <= MAX_LENGTH_PREFIX_BYTES) {
|
|
8191
|
+
break;
|
|
8192
|
+
}
|
|
8193
|
+
throw e;
|
|
8194
|
+
}
|
|
8195
|
+
const frameEnd = it.offset + length;
|
|
8196
|
+
if (frameEnd > bytes.byteLength) {
|
|
8197
|
+
// payload is incomplete — wait for more bytes
|
|
8198
|
+
break;
|
|
8199
|
+
}
|
|
8200
|
+
frames.push(bytes.subarray(it.offset, frameEnd));
|
|
8201
|
+
offset = frameEnd;
|
|
8202
|
+
}
|
|
8203
|
+
this.pending = (offset < bytes.byteLength)
|
|
8204
|
+
? bytes.slice(offset)
|
|
8205
|
+
: new Uint8Array(0);
|
|
8206
|
+
return frames;
|
|
8207
|
+
}
|
|
8208
|
+
}
|
|
8209
|
+
function concatBytes(a, b) {
|
|
8210
|
+
const out = new Uint8Array(a.byteLength + b.byteLength);
|
|
8211
|
+
out.set(a, 0);
|
|
8212
|
+
out.set(b, a.byteLength);
|
|
8213
|
+
return out;
|
|
8214
|
+
}
|
|
8157
8215
|
class H3TransportTransport {
|
|
8158
8216
|
constructor(events) {
|
|
8159
8217
|
this.isOpen = false;
|
|
8160
8218
|
this.lengthPrefixBuffer = new Uint8Array(9); // 9 bytes is the maximum length of a length prefix
|
|
8219
|
+
this.reliableReassembler = new FrameReassembler();
|
|
8220
|
+
this.unreliableReassembler = new FrameReassembler();
|
|
8161
8221
|
this.events = events;
|
|
8162
8222
|
}
|
|
8163
8223
|
connect(url, options = {}) {
|
|
@@ -8237,17 +8297,11 @@
|
|
|
8237
8297
|
//
|
|
8238
8298
|
// a single read may contain multiple messages
|
|
8239
8299
|
// each message is prefixed with its length
|
|
8300
|
+
// a read may also deliver a partial frame; buffer across reads
|
|
8240
8301
|
//
|
|
8241
|
-
const
|
|
8242
|
-
|
|
8243
|
-
|
|
8244
|
-
//
|
|
8245
|
-
// QUESTION: should we buffer the message in case it's not fully read?
|
|
8246
|
-
//
|
|
8247
|
-
const length = buildExports.decode.number(messages, it);
|
|
8248
|
-
this.events.onmessage({ data: messages.subarray(it.offset, it.offset + length) });
|
|
8249
|
-
it.offset += length;
|
|
8250
|
-
} while (it.offset < messages.length);
|
|
8302
|
+
for (const frame of this.reliableReassembler.push(result.value)) {
|
|
8303
|
+
this.events.onmessage({ data: frame });
|
|
8304
|
+
}
|
|
8251
8305
|
}
|
|
8252
8306
|
catch (e) {
|
|
8253
8307
|
if (e.message.indexOf("session is closed") === -1) {
|
|
@@ -8270,17 +8324,11 @@
|
|
|
8270
8324
|
//
|
|
8271
8325
|
// a single read may contain multiple messages
|
|
8272
8326
|
// each message is prefixed with its length
|
|
8327
|
+
// a read may also deliver a partial frame; buffer across reads
|
|
8273
8328
|
//
|
|
8274
|
-
const
|
|
8275
|
-
|
|
8276
|
-
|
|
8277
|
-
//
|
|
8278
|
-
// QUESTION: should we buffer the message in case it's not fully read?
|
|
8279
|
-
//
|
|
8280
|
-
const length = buildExports.decode.number(messages, it);
|
|
8281
|
-
this.events.onmessage({ data: messages.subarray(it.offset, it.offset + length) });
|
|
8282
|
-
it.offset += length;
|
|
8283
|
-
} while (it.offset < messages.length);
|
|
8329
|
+
for (const frame of this.unreliableReassembler.push(result.value)) {
|
|
8330
|
+
this.events.onmessage({ data: frame });
|
|
8331
|
+
}
|
|
8284
8332
|
}
|
|
8285
8333
|
catch (e) {
|
|
8286
8334
|
if (e.message.indexOf("session is closed") === -1) {
|