@colyseus/sdk 0.17.13 → 0.17.14
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 +1 -1
- package/build/Connection.mjs +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 +7 -7
- package/build/Room.cjs.map +1 -1
- package/build/Room.mjs +2 -2
- 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 +1 -1
- package/build/debug.mjs +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 +1 -1
- package/build/transport/WebSocketTransport.mjs +1 -1
- package/dist/colyseus-cocos-creator.js +67 -38
- package/dist/colyseus-cocos-creator.js.map +1 -1
- package/dist/colyseus.js +67 -38
- package/dist/colyseus.js.map +1 -1
- package/dist/debug.js +9 -20
- package/dist/debug.js.map +1 -1
- package/package.json +3 -3
- package/src/Client.ts +2 -2
- package/src/Room.ts +1 -2
- package/src/errors/Errors.ts +0 -11
- package/src/index.ts +2 -2
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.14 - @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
|
+
DEVMODE_RESTART: 4010
|
|
119
|
+
};
|
|
120
|
+
|
|
95
121
|
class ServerError extends Error {
|
|
96
122
|
constructor(code, message) {
|
|
97
123
|
super(message);
|
|
@@ -8330,7 +8356,7 @@
|
|
|
8330
8356
|
}
|
|
8331
8357
|
|
|
8332
8358
|
// Use codes between 0~127 for lesser throughput (1 byte)
|
|
8333
|
-
|
|
8359
|
+
var Protocol;
|
|
8334
8360
|
(function (Protocol) {
|
|
8335
8361
|
// Room-related (10~19)
|
|
8336
8362
|
Protocol[Protocol["HANDSHAKE"] = 9] = "HANDSHAKE";
|
|
@@ -8343,8 +8369,8 @@
|
|
|
8343
8369
|
Protocol[Protocol["ROOM_DATA_SCHEMA"] = 16] = "ROOM_DATA_SCHEMA";
|
|
8344
8370
|
Protocol[Protocol["ROOM_DATA_BYTES"] = 17] = "ROOM_DATA_BYTES";
|
|
8345
8371
|
Protocol[Protocol["PING"] = 18] = "PING";
|
|
8346
|
-
})(
|
|
8347
|
-
|
|
8372
|
+
})(Protocol || (Protocol = {}));
|
|
8373
|
+
var ErrorCode;
|
|
8348
8374
|
(function (ErrorCode) {
|
|
8349
8375
|
ErrorCode[ErrorCode["MATCHMAKE_NO_HANDLER"] = 520] = "MATCHMAKE_NO_HANDLER";
|
|
8350
8376
|
ErrorCode[ErrorCode["MATCHMAKE_INVALID_CRITERIA"] = 521] = "MATCHMAKE_INVALID_CRITERIA";
|
|
@@ -8353,7 +8379,7 @@
|
|
|
8353
8379
|
ErrorCode[ErrorCode["MATCHMAKE_EXPIRED"] = 524] = "MATCHMAKE_EXPIRED";
|
|
8354
8380
|
ErrorCode[ErrorCode["AUTH_FAILED"] = 525] = "AUTH_FAILED";
|
|
8355
8381
|
ErrorCode[ErrorCode["APPLICATION_ERROR"] = 526] = "APPLICATION_ERROR";
|
|
8356
|
-
})(
|
|
8382
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
8357
8383
|
|
|
8358
8384
|
const serializers = {};
|
|
8359
8385
|
function registerSerializer(id, serializer) {
|
|
@@ -8550,10 +8576,10 @@
|
|
|
8550
8576
|
this.onError.invoke(e.code, e.reason);
|
|
8551
8577
|
return;
|
|
8552
8578
|
}
|
|
8553
|
-
if (e.code ===
|
|
8554
|
-
e.code ===
|
|
8555
|
-
e.code ===
|
|
8556
|
-
e.code ===
|
|
8579
|
+
if (e.code === CloseCode.NO_STATUS_RECEIVED ||
|
|
8580
|
+
e.code === CloseCode.ABNORMAL_CLOSURE ||
|
|
8581
|
+
e.code === CloseCode.GOING_AWAY ||
|
|
8582
|
+
e.code === CloseCode.DEVMODE_RESTART) {
|
|
8557
8583
|
this.onDrop.invoke(e.code, e.reason);
|
|
8558
8584
|
this.handleReconnection();
|
|
8559
8585
|
}
|
|
@@ -8586,7 +8612,7 @@
|
|
|
8586
8612
|
this.onLeave((code) => resolve(code));
|
|
8587
8613
|
if (this.connection) {
|
|
8588
8614
|
if (consented) {
|
|
8589
|
-
this.packr.buffer[0] =
|
|
8615
|
+
this.packr.buffer[0] = Protocol.LEAVE_ROOM;
|
|
8590
8616
|
this.connection.send(this.packr.buffer.subarray(0, 1));
|
|
8591
8617
|
}
|
|
8592
8618
|
else {
|
|
@@ -8594,7 +8620,7 @@
|
|
|
8594
8620
|
}
|
|
8595
8621
|
}
|
|
8596
8622
|
else {
|
|
8597
|
-
this.onLeave.invoke(
|
|
8623
|
+
this.onLeave.invoke(CloseCode.CONSENTED);
|
|
8598
8624
|
}
|
|
8599
8625
|
});
|
|
8600
8626
|
}
|
|
@@ -8604,12 +8630,12 @@
|
|
|
8604
8630
|
ping(callback) {
|
|
8605
8631
|
__classPrivateFieldSet(this, _Room_lastPingTime, now(), "f");
|
|
8606
8632
|
__classPrivateFieldSet(this, _Room_pingCallback, callback, "f");
|
|
8607
|
-
this.packr.buffer[0] =
|
|
8633
|
+
this.packr.buffer[0] = Protocol.PING;
|
|
8608
8634
|
this.connection.send(this.packr.buffer.subarray(0, 1));
|
|
8609
8635
|
}
|
|
8610
8636
|
send(messageType, payload) {
|
|
8611
8637
|
const it = { offset: 1 };
|
|
8612
|
-
this.packr.buffer[0] =
|
|
8638
|
+
this.packr.buffer[0] = Protocol.ROOM_DATA;
|
|
8613
8639
|
if (typeof (messageType) === "string") {
|
|
8614
8640
|
umdExports.encode.string(this.packr.buffer, messageType, it);
|
|
8615
8641
|
}
|
|
@@ -8635,7 +8661,7 @@
|
|
|
8635
8661
|
return;
|
|
8636
8662
|
}
|
|
8637
8663
|
const it = { offset: 1 };
|
|
8638
|
-
this.packr.buffer[0] =
|
|
8664
|
+
this.packr.buffer[0] = Protocol.ROOM_DATA;
|
|
8639
8665
|
if (typeof (type) === "string") {
|
|
8640
8666
|
umdExports.encode.string(this.packr.buffer, type, it);
|
|
8641
8667
|
}
|
|
@@ -8651,7 +8677,7 @@
|
|
|
8651
8677
|
}
|
|
8652
8678
|
sendBytes(type, bytes) {
|
|
8653
8679
|
const it = { offset: 1 };
|
|
8654
|
-
this.packr.buffer[0] =
|
|
8680
|
+
this.packr.buffer[0] = Protocol.ROOM_DATA_BYTES;
|
|
8655
8681
|
if (typeof (type) === "string") {
|
|
8656
8682
|
umdExports.encode.string(this.packr.buffer, type, it);
|
|
8657
8683
|
}
|
|
@@ -8693,7 +8719,7 @@
|
|
|
8693
8719
|
const buffer = new Uint8Array(event.data);
|
|
8694
8720
|
const it = { offset: 1 };
|
|
8695
8721
|
const code = buffer[0];
|
|
8696
|
-
if (code ===
|
|
8722
|
+
if (code === Protocol.JOIN_ROOM) {
|
|
8697
8723
|
const reconnectionToken = umdExports.decode.utf8Read(buffer, it, buffer[it.offset++]);
|
|
8698
8724
|
this.serializerId = umdExports.decode.utf8Read(buffer, it, buffer[it.offset++]);
|
|
8699
8725
|
// Instantiate serializer if not locally available.
|
|
@@ -8716,7 +8742,7 @@
|
|
|
8716
8742
|
}
|
|
8717
8743
|
this.reconnectionToken = `${this.roomId}:${reconnectionToken}`;
|
|
8718
8744
|
// acknowledge successfull JOIN_ROOM
|
|
8719
|
-
this.packr.buffer[0] =
|
|
8745
|
+
this.packr.buffer[0] = Protocol.JOIN_ROOM;
|
|
8720
8746
|
this.connection.send(this.packr.buffer.subarray(0, 1));
|
|
8721
8747
|
// Send any enqueued messages that were buffered while disconnected
|
|
8722
8748
|
if (this.reconnection.enqueuedMessages.length > 0) {
|
|
@@ -8727,23 +8753,23 @@
|
|
|
8727
8753
|
this.reconnection.enqueuedMessages = [];
|
|
8728
8754
|
}
|
|
8729
8755
|
}
|
|
8730
|
-
else if (code ===
|
|
8756
|
+
else if (code === Protocol.ERROR) {
|
|
8731
8757
|
const code = umdExports.decode.number(buffer, it);
|
|
8732
8758
|
const message = umdExports.decode.string(buffer, it);
|
|
8733
8759
|
this.onError.invoke(code, message);
|
|
8734
8760
|
}
|
|
8735
|
-
else if (code ===
|
|
8761
|
+
else if (code === Protocol.LEAVE_ROOM) {
|
|
8736
8762
|
this.leave();
|
|
8737
8763
|
}
|
|
8738
|
-
else if (code ===
|
|
8764
|
+
else if (code === Protocol.ROOM_STATE) {
|
|
8739
8765
|
this.serializer.setState(buffer, it);
|
|
8740
8766
|
this.onStateChange.invoke(this.serializer.getState());
|
|
8741
8767
|
}
|
|
8742
|
-
else if (code ===
|
|
8768
|
+
else if (code === Protocol.ROOM_STATE_PATCH) {
|
|
8743
8769
|
this.serializer.patch(buffer, it);
|
|
8744
8770
|
this.onStateChange.invoke(this.serializer.getState());
|
|
8745
8771
|
}
|
|
8746
|
-
else if (code ===
|
|
8772
|
+
else if (code === Protocol.ROOM_DATA) {
|
|
8747
8773
|
const type = (umdExports.decode.stringCheck(buffer, it))
|
|
8748
8774
|
? umdExports.decode.string(buffer, it)
|
|
8749
8775
|
: umdExports.decode.number(buffer, it);
|
|
@@ -8752,13 +8778,13 @@
|
|
|
8752
8778
|
: undefined;
|
|
8753
8779
|
this.dispatchMessage(type, message);
|
|
8754
8780
|
}
|
|
8755
|
-
else if (code ===
|
|
8781
|
+
else if (code === Protocol.ROOM_DATA_BYTES) {
|
|
8756
8782
|
const type = (umdExports.decode.stringCheck(buffer, it))
|
|
8757
8783
|
? umdExports.decode.string(buffer, it)
|
|
8758
8784
|
: umdExports.decode.number(buffer, it);
|
|
8759
8785
|
this.dispatchMessage(type, buffer.subarray(it.offset));
|
|
8760
8786
|
}
|
|
8761
|
-
else if (code ===
|
|
8787
|
+
else if (code === Protocol.PING) {
|
|
8762
8788
|
(_a = __classPrivateFieldGet(this, _Room_pingCallback, "f")) === null || _a === void 0 ? void 0 : _a.call(this, now() - __classPrivateFieldGet(this, _Room_lastPingTime, "f"));
|
|
8763
8789
|
__classPrivateFieldSet(this, _Room_pingCallback, undefined, "f");
|
|
8764
8790
|
}
|
|
@@ -9432,14 +9458,14 @@
|
|
|
9432
9458
|
let pingStart = 0;
|
|
9433
9459
|
conn.events.onopen = () => {
|
|
9434
9460
|
pingStart = Date.now();
|
|
9435
|
-
conn.send(new Uint8Array([
|
|
9461
|
+
conn.send(new Uint8Array([Protocol.PING]));
|
|
9436
9462
|
};
|
|
9437
9463
|
conn.events.onmessage = (_) => {
|
|
9438
9464
|
latencies.push(Date.now() - pingStart);
|
|
9439
9465
|
if (latencies.length < pingCount) {
|
|
9440
9466
|
// Send another ping
|
|
9441
9467
|
pingStart = Date.now();
|
|
9442
|
-
conn.send(new Uint8Array([
|
|
9468
|
+
conn.send(new Uint8Array([Protocol.PING]));
|
|
9443
9469
|
}
|
|
9444
9470
|
else {
|
|
9445
9471
|
// Done, calculate average and close
|
|
@@ -9449,7 +9475,7 @@
|
|
|
9449
9475
|
}
|
|
9450
9476
|
};
|
|
9451
9477
|
conn.events.onerror = (event) => {
|
|
9452
|
-
reject(new ServerError(
|
|
9478
|
+
reject(new ServerError(CloseCode.ABNORMAL_CLOSURE, `Failed to get latency: ${event.message}`));
|
|
9453
9479
|
};
|
|
9454
9480
|
conn.connect(this.getHttpEndpoint());
|
|
9455
9481
|
});
|
|
@@ -9543,8 +9569,11 @@
|
|
|
9543
9569
|
exports.Auth = Auth;
|
|
9544
9570
|
exports.Callbacks = umdExports.Callbacks;
|
|
9545
9571
|
exports.Client = Client;
|
|
9572
|
+
exports.CloseCode = CloseCode;
|
|
9546
9573
|
exports.ColyseusSDK = ColyseusSDK;
|
|
9574
|
+
exports.ErrorCode = ErrorCode$1;
|
|
9547
9575
|
exports.MatchMakeError = MatchMakeError;
|
|
9576
|
+
exports.Protocol = Protocol$1;
|
|
9548
9577
|
exports.Room = Room;
|
|
9549
9578
|
exports.SchemaSerializer = SchemaSerializer;
|
|
9550
9579
|
exports.ServerError = ServerError;
|