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