@colyseus/sdk 0.17.13 → 0.17.15
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 +3 -2
- package/build/Client.cjs.map +1 -1
- package/build/Client.d.ts +1 -1
- package/build/Client.mjs +3 -2
- package/build/Client.mjs.map +1 -1
- package/build/Connection.cjs +30 -1
- package/build/Connection.cjs.map +1 -1
- package/build/Connection.d.ts +1 -0
- package/build/Connection.mjs +27 -1
- package/build/Connection.mjs.map +1 -1
- package/build/HTTP.cjs +1 -1
- package/build/HTTP.mjs +1 -1
- package/build/Protocol.cjs +1 -1
- package/build/Protocol.mjs +1 -1
- package/build/Room.cjs +17 -14
- package/build/Room.cjs.map +1 -1
- package/build/Room.mjs +12 -9
- 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.mjs +1 -1
- package/build/core/utils.cjs +1 -1
- package/build/core/utils.mjs +1 -1
- package/build/debug.cjs +226 -113
- package/build/debug.cjs.map +1 -1
- package/build/debug.mjs +226 -113
- package/build/debug.mjs.map +1 -1
- package/build/errors/Errors.cjs +1 -12
- package/build/errors/Errors.cjs.map +1 -1
- package/build/errors/Errors.d.ts +0 -10
- package/build/errors/Errors.mjs +2 -13
- package/build/errors/Errors.mjs.map +1 -1
- package/build/index.cjs +11 -11
- package/build/index.cjs.map +1 -1
- package/build/index.d.ts +2 -2
- package/build/index.mjs +3 -3
- package/build/index.mjs.map +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 +1 -1
- package/build/transport/H3Transport.mjs +1 -1
- package/build/transport/WebSocketTransport.cjs +16 -5
- package/build/transport/WebSocketTransport.cjs.map +1 -1
- package/build/transport/WebSocketTransport.mjs +16 -5
- package/build/transport/WebSocketTransport.mjs.map +1 -1
- package/dist/colyseus-cocos-creator.js +118 -49
- package/dist/colyseus-cocos-creator.js.map +1 -1
- package/dist/colyseus.js +118 -49
- package/dist/colyseus.js.map +1 -1
- package/dist/debug.js +284 -143
- package/dist/debug.js.map +1 -1
- package/package.json +4 -4
- package/src/Client.ts +2 -2
- package/src/Connection.ts +30 -0
- package/src/Room.ts +13 -10
- package/src/debug.ts +246 -111
- package/src/errors/Errors.ts +0 -11
- package/src/index.ts +2 -2
- package/src/transport/WebSocketTransport.ts +16 -4
|
@@ -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.15 - @colyseus/schema 4.0.1
|
|
7
7
|
// THIS VERSION USES "XMLHttpRequest" INSTEAD OF "fetch" FOR COMPATIBILITY WITH COCOS CREATOR
|
|
8
8
|
(function (global, factory) {
|
|
9
9
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
@@ -82,17 +82,43 @@
|
|
|
82
82
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
83
83
|
};
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
85
|
+
// packages/shared-types/src/Protocol.ts
|
|
86
|
+
var Protocol$1 = {
|
|
87
|
+
// Room-related (10~19)
|
|
88
|
+
JOIN_ROOM: 10,
|
|
89
|
+
ERROR: 11,
|
|
90
|
+
LEAVE_ROOM: 12,
|
|
91
|
+
ROOM_DATA: 13,
|
|
92
|
+
ROOM_STATE: 14,
|
|
93
|
+
ROOM_STATE_PATCH: 15,
|
|
94
|
+
ROOM_DATA_SCHEMA: 16,
|
|
95
|
+
// DEPRECATED: used to send schema instances via room.send()
|
|
96
|
+
ROOM_DATA_BYTES: 17,
|
|
97
|
+
PING: 18
|
|
98
|
+
};
|
|
99
|
+
var ErrorCode$1 = {
|
|
100
|
+
MATCHMAKE_NO_HANDLER: 520,
|
|
101
|
+
MATCHMAKE_INVALID_CRITERIA: 521,
|
|
102
|
+
MATCHMAKE_INVALID_ROOM_ID: 522,
|
|
103
|
+
MATCHMAKE_UNHANDLED: 523,
|
|
104
|
+
// generic exception during onCreate/onJoin
|
|
105
|
+
MATCHMAKE_EXPIRED: 524,
|
|
106
|
+
// generic exception during onCreate/onJoin
|
|
107
|
+
AUTH_FAILED: 525,
|
|
108
|
+
APPLICATION_ERROR: 526,
|
|
109
|
+
INVALID_PAYLOAD: 4217
|
|
110
|
+
};
|
|
111
|
+
var CloseCode = {
|
|
112
|
+
NORMAL_CLOSURE: 1e3,
|
|
113
|
+
GOING_AWAY: 1001,
|
|
114
|
+
NO_STATUS_RECEIVED: 1005,
|
|
115
|
+
ABNORMAL_CLOSURE: 1006,
|
|
116
|
+
CONSENTED: 4e3,
|
|
117
|
+
SERVER_SHUTDOWN: 4001,
|
|
118
|
+
WITH_ERROR: 4002,
|
|
119
|
+
MAY_TRY_RECONNECT: 4010
|
|
120
|
+
};
|
|
121
|
+
|
|
96
122
|
class ServerError extends Error {
|
|
97
123
|
constructor(code, message) {
|
|
98
124
|
super(message);
|
|
@@ -8282,12 +8308,22 @@
|
|
|
8282
8308
|
this.ws = new WebSocket(url, this.protocols);
|
|
8283
8309
|
}
|
|
8284
8310
|
this.ws.binaryType = 'arraybuffer';
|
|
8285
|
-
this.ws.onopen = this.events.onopen;
|
|
8286
|
-
this.ws.onmessage = this.events.onmessage;
|
|
8287
|
-
this.ws.onclose = this.events.onclose;
|
|
8288
|
-
this.ws.onerror = this.events.onerror;
|
|
8311
|
+
this.ws.onopen = (event) => { var _a, _b; return (_b = (_a = this.events).onopen) === null || _b === void 0 ? void 0 : _b.call(_a, event); };
|
|
8312
|
+
this.ws.onmessage = (event) => { var _a, _b; return (_b = (_a = this.events).onmessage) === null || _b === void 0 ? void 0 : _b.call(_a, event); };
|
|
8313
|
+
this.ws.onclose = (event) => { var _a, _b; return (_b = (_a = this.events).onclose) === null || _b === void 0 ? void 0 : _b.call(_a, event); };
|
|
8314
|
+
this.ws.onerror = (event) => { var _a, _b; return (_b = (_a = this.events).onerror) === null || _b === void 0 ? void 0 : _b.call(_a, event); };
|
|
8289
8315
|
}
|
|
8290
8316
|
close(code, reason) {
|
|
8317
|
+
//
|
|
8318
|
+
// trigger the onclose event immediately if the code is MAY_TRY_RECONNECT
|
|
8319
|
+
// when "offline" event is triggered, the close frame is delayed. this
|
|
8320
|
+
// way client can try to reconnect immediately.
|
|
8321
|
+
//
|
|
8322
|
+
if (code === CloseCode.MAY_TRY_RECONNECT && this.events.onclose) {
|
|
8323
|
+
this.ws.onclose = null;
|
|
8324
|
+
this.events.onclose({ code, reason });
|
|
8325
|
+
}
|
|
8326
|
+
// then we close the connection
|
|
8291
8327
|
this.ws.close(code, reason);
|
|
8292
8328
|
}
|
|
8293
8329
|
get isOpen() {
|
|
@@ -8295,9 +8331,23 @@
|
|
|
8295
8331
|
}
|
|
8296
8332
|
}
|
|
8297
8333
|
|
|
8334
|
+
var _Connection__offlineListener;
|
|
8335
|
+
const onOfflineListeners = [];
|
|
8336
|
+
const hasGlobalEventListeners = typeof (addEventListener) === "function" && typeof (removeEventListener) === "function";
|
|
8337
|
+
if (hasGlobalEventListeners) {
|
|
8338
|
+
/**
|
|
8339
|
+
* Detects when the network is offline and closes all connections.
|
|
8340
|
+
* (When switching wifi networks, etc.)
|
|
8341
|
+
*/
|
|
8342
|
+
addEventListener("offline", () => {
|
|
8343
|
+
console.warn(`@colyseus/sdk: 🛑 Network offline. Closing ${onOfflineListeners.length} connection(s)`);
|
|
8344
|
+
onOfflineListeners.forEach((listener) => listener());
|
|
8345
|
+
}, false);
|
|
8346
|
+
}
|
|
8298
8347
|
class Connection {
|
|
8299
8348
|
constructor(protocol) {
|
|
8300
8349
|
this.events = {};
|
|
8350
|
+
_Connection__offlineListener.set(this, (hasGlobalEventListeners) ? () => this.close(CloseCode.MAY_TRY_RECONNECT) : null);
|
|
8301
8351
|
switch (protocol) {
|
|
8302
8352
|
case "h3":
|
|
8303
8353
|
this.transport = new H3TransportTransport(this.events);
|
|
@@ -8308,6 +8358,18 @@
|
|
|
8308
8358
|
}
|
|
8309
8359
|
}
|
|
8310
8360
|
connect(url, options) {
|
|
8361
|
+
if (hasGlobalEventListeners) {
|
|
8362
|
+
const onOpen = this.events.onopen;
|
|
8363
|
+
this.events.onopen = (ev) => {
|
|
8364
|
+
onOfflineListeners.push(__classPrivateFieldGet(this, _Connection__offlineListener, "f"));
|
|
8365
|
+
onOpen === null || onOpen === void 0 ? void 0 : onOpen(ev);
|
|
8366
|
+
};
|
|
8367
|
+
const onClose = this.events.onclose;
|
|
8368
|
+
this.events.onclose = (ev) => {
|
|
8369
|
+
onOfflineListeners.splice(onOfflineListeners.indexOf(__classPrivateFieldGet(this, _Connection__offlineListener, "f")), 1);
|
|
8370
|
+
onClose === null || onClose === void 0 ? void 0 : onClose(ev);
|
|
8371
|
+
};
|
|
8372
|
+
}
|
|
8311
8373
|
this.url = url;
|
|
8312
8374
|
this.options = options;
|
|
8313
8375
|
this.transport.connect(url, options);
|
|
@@ -8329,9 +8391,10 @@
|
|
|
8329
8391
|
return this.transport.isOpen;
|
|
8330
8392
|
}
|
|
8331
8393
|
}
|
|
8394
|
+
_Connection__offlineListener = new WeakMap();
|
|
8332
8395
|
|
|
8333
8396
|
// Use codes between 0~127 for lesser throughput (1 byte)
|
|
8334
|
-
|
|
8397
|
+
var Protocol;
|
|
8335
8398
|
(function (Protocol) {
|
|
8336
8399
|
// Room-related (10~19)
|
|
8337
8400
|
Protocol[Protocol["HANDSHAKE"] = 9] = "HANDSHAKE";
|
|
@@ -8344,8 +8407,8 @@
|
|
|
8344
8407
|
Protocol[Protocol["ROOM_DATA_SCHEMA"] = 16] = "ROOM_DATA_SCHEMA";
|
|
8345
8408
|
Protocol[Protocol["ROOM_DATA_BYTES"] = 17] = "ROOM_DATA_BYTES";
|
|
8346
8409
|
Protocol[Protocol["PING"] = 18] = "PING";
|
|
8347
|
-
})(
|
|
8348
|
-
|
|
8410
|
+
})(Protocol || (Protocol = {}));
|
|
8411
|
+
var ErrorCode;
|
|
8349
8412
|
(function (ErrorCode) {
|
|
8350
8413
|
ErrorCode[ErrorCode["MATCHMAKE_NO_HANDLER"] = 520] = "MATCHMAKE_NO_HANDLER";
|
|
8351
8414
|
ErrorCode[ErrorCode["MATCHMAKE_INVALID_CRITERIA"] = 521] = "MATCHMAKE_INVALID_CRITERIA";
|
|
@@ -8354,7 +8417,7 @@
|
|
|
8354
8417
|
ErrorCode[ErrorCode["MATCHMAKE_EXPIRED"] = 524] = "MATCHMAKE_EXPIRED";
|
|
8355
8418
|
ErrorCode[ErrorCode["AUTH_FAILED"] = 525] = "AUTH_FAILED";
|
|
8356
8419
|
ErrorCode[ErrorCode["APPLICATION_ERROR"] = 526] = "APPLICATION_ERROR";
|
|
8357
|
-
})(
|
|
8420
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
8358
8421
|
|
|
8359
8422
|
const serializers = {};
|
|
8360
8423
|
function registerSerializer(id, serializer) {
|
|
@@ -8515,7 +8578,7 @@
|
|
|
8515
8578
|
// reconnection logic
|
|
8516
8579
|
this.reconnection = {
|
|
8517
8580
|
retryCount: 0,
|
|
8518
|
-
maxRetries:
|
|
8581
|
+
maxRetries: 15,
|
|
8519
8582
|
delay: 100,
|
|
8520
8583
|
minDelay: 100,
|
|
8521
8584
|
maxDelay: 5000,
|
|
@@ -8537,7 +8600,6 @@
|
|
|
8537
8600
|
this.serializer = new (getSerializer("schema"));
|
|
8538
8601
|
this.serializer.state = new rootSchema();
|
|
8539
8602
|
}
|
|
8540
|
-
this.onError((code, message) => { var _a; return (_a = console.warn) === null || _a === void 0 ? void 0 : _a.call(console, `colyseus.js - onError => (${code}) ${message}`); });
|
|
8541
8603
|
this.onLeave(() => this.removeAllListeners());
|
|
8542
8604
|
}
|
|
8543
8605
|
connect(endpoint, options, headers) {
|
|
@@ -8551,10 +8613,10 @@
|
|
|
8551
8613
|
this.onError.invoke(e.code, e.reason);
|
|
8552
8614
|
return;
|
|
8553
8615
|
}
|
|
8554
|
-
if (e.code ===
|
|
8555
|
-
e.code ===
|
|
8556
|
-
e.code ===
|
|
8557
|
-
e.code ===
|
|
8616
|
+
if (e.code === CloseCode.NO_STATUS_RECEIVED ||
|
|
8617
|
+
e.code === CloseCode.ABNORMAL_CLOSURE ||
|
|
8618
|
+
e.code === CloseCode.GOING_AWAY ||
|
|
8619
|
+
e.code === CloseCode.MAY_TRY_RECONNECT) {
|
|
8558
8620
|
this.onDrop.invoke(e.code, e.reason);
|
|
8559
8621
|
this.handleReconnection();
|
|
8560
8622
|
}
|
|
@@ -8564,8 +8626,6 @@
|
|
|
8564
8626
|
}
|
|
8565
8627
|
};
|
|
8566
8628
|
this.connection.events.onerror = (e) => {
|
|
8567
|
-
var _a;
|
|
8568
|
-
(_a = console.warn) === null || _a === void 0 ? void 0 : _a.call(console, `Room, onError (${e.code}): ${e.reason}`);
|
|
8569
8629
|
this.onError.invoke(e.code, e.reason);
|
|
8570
8630
|
};
|
|
8571
8631
|
/**
|
|
@@ -8587,7 +8647,7 @@
|
|
|
8587
8647
|
this.onLeave((code) => resolve(code));
|
|
8588
8648
|
if (this.connection) {
|
|
8589
8649
|
if (consented) {
|
|
8590
|
-
this.packr.buffer[0] =
|
|
8650
|
+
this.packr.buffer[0] = Protocol.LEAVE_ROOM;
|
|
8591
8651
|
this.connection.send(this.packr.buffer.subarray(0, 1));
|
|
8592
8652
|
}
|
|
8593
8653
|
else {
|
|
@@ -8595,7 +8655,7 @@
|
|
|
8595
8655
|
}
|
|
8596
8656
|
}
|
|
8597
8657
|
else {
|
|
8598
|
-
this.onLeave.invoke(
|
|
8658
|
+
this.onLeave.invoke(CloseCode.CONSENTED);
|
|
8599
8659
|
}
|
|
8600
8660
|
});
|
|
8601
8661
|
}
|
|
@@ -8603,14 +8663,19 @@
|
|
|
8603
8663
|
return this.onMessageHandlers.on(this.getMessageHandlerKey(type), callback);
|
|
8604
8664
|
}
|
|
8605
8665
|
ping(callback) {
|
|
8666
|
+
var _a;
|
|
8667
|
+
// skip if connection is not open
|
|
8668
|
+
if (!((_a = this.connection) === null || _a === void 0 ? void 0 : _a.isOpen)) {
|
|
8669
|
+
return;
|
|
8670
|
+
}
|
|
8606
8671
|
__classPrivateFieldSet(this, _Room_lastPingTime, now(), "f");
|
|
8607
8672
|
__classPrivateFieldSet(this, _Room_pingCallback, callback, "f");
|
|
8608
|
-
this.packr.buffer[0] =
|
|
8673
|
+
this.packr.buffer[0] = Protocol.PING;
|
|
8609
8674
|
this.connection.send(this.packr.buffer.subarray(0, 1));
|
|
8610
8675
|
}
|
|
8611
8676
|
send(messageType, payload) {
|
|
8612
8677
|
const it = { offset: 1 };
|
|
8613
|
-
this.packr.buffer[0] =
|
|
8678
|
+
this.packr.buffer[0] = Protocol.ROOM_DATA;
|
|
8614
8679
|
if (typeof (messageType) === "string") {
|
|
8615
8680
|
umdExports.encode.string(this.packr.buffer, messageType, it);
|
|
8616
8681
|
}
|
|
@@ -8636,7 +8701,7 @@
|
|
|
8636
8701
|
return;
|
|
8637
8702
|
}
|
|
8638
8703
|
const it = { offset: 1 };
|
|
8639
|
-
this.packr.buffer[0] =
|
|
8704
|
+
this.packr.buffer[0] = Protocol.ROOM_DATA;
|
|
8640
8705
|
if (typeof (type) === "string") {
|
|
8641
8706
|
umdExports.encode.string(this.packr.buffer, type, it);
|
|
8642
8707
|
}
|
|
@@ -8652,7 +8717,7 @@
|
|
|
8652
8717
|
}
|
|
8653
8718
|
sendBytes(type, bytes) {
|
|
8654
8719
|
const it = { offset: 1 };
|
|
8655
|
-
this.packr.buffer[0] =
|
|
8720
|
+
this.packr.buffer[0] = Protocol.ROOM_DATA_BYTES;
|
|
8656
8721
|
if (typeof (type) === "string") {
|
|
8657
8722
|
umdExports.encode.string(this.packr.buffer, type, it);
|
|
8658
8723
|
}
|
|
@@ -8694,7 +8759,7 @@
|
|
|
8694
8759
|
const buffer = new Uint8Array(event.data);
|
|
8695
8760
|
const it = { offset: 1 };
|
|
8696
8761
|
const code = buffer[0];
|
|
8697
|
-
if (code ===
|
|
8762
|
+
if (code === Protocol.JOIN_ROOM) {
|
|
8698
8763
|
const reconnectionToken = umdExports.decode.utf8Read(buffer, it, buffer[it.offset++]);
|
|
8699
8764
|
this.serializerId = umdExports.decode.utf8Read(buffer, it, buffer[it.offset++]);
|
|
8700
8765
|
// Instantiate serializer if not locally available.
|
|
@@ -8717,7 +8782,7 @@
|
|
|
8717
8782
|
}
|
|
8718
8783
|
this.reconnectionToken = `${this.roomId}:${reconnectionToken}`;
|
|
8719
8784
|
// acknowledge successfull JOIN_ROOM
|
|
8720
|
-
this.packr.buffer[0] =
|
|
8785
|
+
this.packr.buffer[0] = Protocol.JOIN_ROOM;
|
|
8721
8786
|
this.connection.send(this.packr.buffer.subarray(0, 1));
|
|
8722
8787
|
// Send any enqueued messages that were buffered while disconnected
|
|
8723
8788
|
if (this.reconnection.enqueuedMessages.length > 0) {
|
|
@@ -8728,23 +8793,23 @@
|
|
|
8728
8793
|
this.reconnection.enqueuedMessages = [];
|
|
8729
8794
|
}
|
|
8730
8795
|
}
|
|
8731
|
-
else if (code ===
|
|
8796
|
+
else if (code === Protocol.ERROR) {
|
|
8732
8797
|
const code = umdExports.decode.number(buffer, it);
|
|
8733
8798
|
const message = umdExports.decode.string(buffer, it);
|
|
8734
8799
|
this.onError.invoke(code, message);
|
|
8735
8800
|
}
|
|
8736
|
-
else if (code ===
|
|
8801
|
+
else if (code === Protocol.LEAVE_ROOM) {
|
|
8737
8802
|
this.leave();
|
|
8738
8803
|
}
|
|
8739
|
-
else if (code ===
|
|
8804
|
+
else if (code === Protocol.ROOM_STATE) {
|
|
8740
8805
|
this.serializer.setState(buffer, it);
|
|
8741
8806
|
this.onStateChange.invoke(this.serializer.getState());
|
|
8742
8807
|
}
|
|
8743
|
-
else if (code ===
|
|
8808
|
+
else if (code === Protocol.ROOM_STATE_PATCH) {
|
|
8744
8809
|
this.serializer.patch(buffer, it);
|
|
8745
8810
|
this.onStateChange.invoke(this.serializer.getState());
|
|
8746
8811
|
}
|
|
8747
|
-
else if (code ===
|
|
8812
|
+
else if (code === Protocol.ROOM_DATA) {
|
|
8748
8813
|
const type = (umdExports.decode.stringCheck(buffer, it))
|
|
8749
8814
|
? umdExports.decode.string(buffer, it)
|
|
8750
8815
|
: umdExports.decode.number(buffer, it);
|
|
@@ -8753,14 +8818,14 @@
|
|
|
8753
8818
|
: undefined;
|
|
8754
8819
|
this.dispatchMessage(type, message);
|
|
8755
8820
|
}
|
|
8756
|
-
else if (code ===
|
|
8821
|
+
else if (code === Protocol.ROOM_DATA_BYTES) {
|
|
8757
8822
|
const type = (umdExports.decode.stringCheck(buffer, it))
|
|
8758
8823
|
? umdExports.decode.string(buffer, it)
|
|
8759
8824
|
: umdExports.decode.number(buffer, it);
|
|
8760
8825
|
this.dispatchMessage(type, buffer.subarray(it.offset));
|
|
8761
8826
|
}
|
|
8762
|
-
else if (code ===
|
|
8763
|
-
(_a = __classPrivateFieldGet(this, _Room_pingCallback, "f")) === null || _a === void 0 ? void 0 : _a.call(this, now() - __classPrivateFieldGet(this, _Room_lastPingTime, "f"));
|
|
8827
|
+
else if (code === Protocol.PING) {
|
|
8828
|
+
(_a = __classPrivateFieldGet(this, _Room_pingCallback, "f")) === null || _a === void 0 ? void 0 : _a.call(this, Math.round(now() - __classPrivateFieldGet(this, _Room_lastPingTime, "f")));
|
|
8764
8829
|
__classPrivateFieldSet(this, _Room_pingCallback, undefined, "f");
|
|
8765
8830
|
}
|
|
8766
8831
|
}
|
|
@@ -8797,7 +8862,6 @@
|
|
|
8797
8862
|
return;
|
|
8798
8863
|
}
|
|
8799
8864
|
if (!this.reconnection.isReconnecting) {
|
|
8800
|
-
console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x1F504)} Re-establishing connection with roomId '${this.roomId}'...`); // 🔄
|
|
8801
8865
|
this.reconnection.retryCount = 0;
|
|
8802
8866
|
this.reconnection.isReconnecting = true;
|
|
8803
8867
|
}
|
|
@@ -8806,16 +8870,18 @@
|
|
|
8806
8870
|
retryReconnection() {
|
|
8807
8871
|
this.reconnection.retryCount++;
|
|
8808
8872
|
const delay = Math.min(this.reconnection.maxDelay, Math.max(this.reconnection.minDelay, this.reconnection.backoff(this.reconnection.retryCount, this.reconnection.delay)));
|
|
8809
|
-
console.info(`[Colyseus reconnection]: ${String.fromCodePoint(
|
|
8873
|
+
console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x023F3)} will retry in ${(delay / 1000).toFixed(1)} seconds...`); // 🔄
|
|
8810
8874
|
// Wait before attempting reconnection
|
|
8811
8875
|
setTimeout(() => {
|
|
8812
8876
|
try {
|
|
8877
|
+
console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x1F504)} Re-establishing sessionId '${this.sessionId}' with roomId '${this.roomId}'... (attempt ${this.reconnection.retryCount} of ${this.reconnection.maxRetries})`); // 🔄
|
|
8813
8878
|
this.connection.reconnect({
|
|
8814
8879
|
reconnectionToken: this.reconnectionToken.split(":")[1],
|
|
8815
8880
|
skipHandshake: true, // we already applied the handshake on first join
|
|
8816
8881
|
});
|
|
8817
8882
|
}
|
|
8818
8883
|
catch (e) {
|
|
8884
|
+
console.log(".reconnect() failed", e);
|
|
8819
8885
|
if (this.reconnection.retryCount < this.reconnection.maxRetries) {
|
|
8820
8886
|
this.retryReconnection();
|
|
8821
8887
|
}
|
|
@@ -9433,14 +9499,14 @@
|
|
|
9433
9499
|
let pingStart = 0;
|
|
9434
9500
|
conn.events.onopen = () => {
|
|
9435
9501
|
pingStart = Date.now();
|
|
9436
|
-
conn.send(new Uint8Array([
|
|
9502
|
+
conn.send(new Uint8Array([Protocol.PING]));
|
|
9437
9503
|
};
|
|
9438
9504
|
conn.events.onmessage = (_) => {
|
|
9439
9505
|
latencies.push(Date.now() - pingStart);
|
|
9440
9506
|
if (latencies.length < pingCount) {
|
|
9441
9507
|
// Send another ping
|
|
9442
9508
|
pingStart = Date.now();
|
|
9443
|
-
conn.send(new Uint8Array([
|
|
9509
|
+
conn.send(new Uint8Array([Protocol.PING]));
|
|
9444
9510
|
}
|
|
9445
9511
|
else {
|
|
9446
9512
|
// Done, calculate average and close
|
|
@@ -9450,7 +9516,7 @@
|
|
|
9450
9516
|
}
|
|
9451
9517
|
};
|
|
9452
9518
|
conn.events.onerror = (event) => {
|
|
9453
|
-
reject(new ServerError(
|
|
9519
|
+
reject(new ServerError(CloseCode.ABNORMAL_CLOSURE, `Failed to get latency: ${event.message}`));
|
|
9454
9520
|
};
|
|
9455
9521
|
conn.connect(this.getHttpEndpoint());
|
|
9456
9522
|
});
|
|
@@ -9544,8 +9610,11 @@
|
|
|
9544
9610
|
exports.Auth = Auth;
|
|
9545
9611
|
exports.Callbacks = umdExports.Callbacks;
|
|
9546
9612
|
exports.Client = Client;
|
|
9613
|
+
exports.CloseCode = CloseCode;
|
|
9547
9614
|
exports.ColyseusSDK = ColyseusSDK;
|
|
9615
|
+
exports.ErrorCode = ErrorCode$1;
|
|
9548
9616
|
exports.MatchMakeError = MatchMakeError;
|
|
9617
|
+
exports.Protocol = Protocol$1;
|
|
9549
9618
|
exports.Room = Room;
|
|
9550
9619
|
exports.SchemaSerializer = SchemaSerializer;
|
|
9551
9620
|
exports.ServerError = ServerError;
|