@colyseus/sdk 0.17.17 → 0.17.19

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 (55) 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 +3 -4
  6. package/build/Client.cjs.map +1 -1
  7. package/build/Client.mjs +2 -3
  8. package/build/Client.mjs.map +1 -1
  9. package/build/Connection.cjs +1 -1
  10. package/build/Connection.mjs +1 -1
  11. package/build/HTTP.cjs +1 -1
  12. package/build/HTTP.mjs +1 -1
  13. package/build/Protocol.cjs +1 -1
  14. package/build/Protocol.mjs +1 -1
  15. package/build/Room.cjs +20 -18
  16. package/build/Room.cjs.map +1 -1
  17. package/build/Room.d.ts +6 -5
  18. package/build/Room.mjs +8 -6
  19. package/build/Room.mjs.map +1 -1
  20. package/build/Storage.cjs +1 -1
  21. package/build/Storage.mjs +1 -1
  22. package/build/core/nanoevents.cjs +1 -1
  23. package/build/core/nanoevents.mjs +1 -1
  24. package/build/core/signal.cjs +1 -1
  25. package/build/core/signal.mjs +1 -1
  26. package/build/core/utils.cjs +1 -1
  27. package/build/core/utils.mjs +1 -1
  28. package/build/debug.cjs +1 -1
  29. package/build/debug.mjs +1 -1
  30. package/build/errors/Errors.cjs +1 -1
  31. package/build/errors/Errors.mjs +1 -1
  32. package/build/index.cjs +1 -1
  33. package/build/index.mjs +1 -1
  34. package/build/legacy.cjs +1 -1
  35. package/build/legacy.mjs +1 -1
  36. package/build/serializer/NoneSerializer.cjs +1 -1
  37. package/build/serializer/NoneSerializer.mjs +1 -1
  38. package/build/serializer/SchemaSerializer.cjs +1 -1
  39. package/build/serializer/SchemaSerializer.mjs +1 -1
  40. package/build/serializer/Serializer.cjs +1 -1
  41. package/build/serializer/Serializer.mjs +1 -1
  42. package/build/transport/H3Transport.cjs +1 -1
  43. package/build/transport/H3Transport.mjs +1 -1
  44. package/build/transport/WebSocketTransport.cjs +1 -1
  45. package/build/transport/WebSocketTransport.mjs +1 -1
  46. package/dist/colyseus-cocos-creator.js +10 -33
  47. package/dist/colyseus-cocos-creator.js.map +1 -1
  48. package/dist/colyseus.js +10 -33
  49. package/dist/colyseus.js.map +1 -1
  50. package/dist/debug.js +22 -45
  51. package/dist/debug.js.map +1 -1
  52. package/package.json +3 -3
  53. package/src/Client.ts +1 -3
  54. package/src/Room.ts +18 -14
  55. package/src/Protocol.ts +0 -25
package/dist/debug.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.17
6
+ // colyseus.js@0.17.19
7
7
  (function (sharedTypes, schema, msgpackr, NodeWebSocket) {
8
8
  'use strict';
9
9
 
@@ -706,32 +706,6 @@
706
706
  }
707
707
  _Connection__offlineListener = new WeakMap();
708
708
 
709
- // Use codes between 0~127 for lesser throughput (1 byte)
710
- var Protocol;
711
- (function (Protocol) {
712
- // Room-related (10~19)
713
- Protocol[Protocol["HANDSHAKE"] = 9] = "HANDSHAKE";
714
- Protocol[Protocol["JOIN_ROOM"] = 10] = "JOIN_ROOM";
715
- Protocol[Protocol["ERROR"] = 11] = "ERROR";
716
- Protocol[Protocol["LEAVE_ROOM"] = 12] = "LEAVE_ROOM";
717
- Protocol[Protocol["ROOM_DATA"] = 13] = "ROOM_DATA";
718
- Protocol[Protocol["ROOM_STATE"] = 14] = "ROOM_STATE";
719
- Protocol[Protocol["ROOM_STATE_PATCH"] = 15] = "ROOM_STATE_PATCH";
720
- Protocol[Protocol["ROOM_DATA_SCHEMA"] = 16] = "ROOM_DATA_SCHEMA";
721
- Protocol[Protocol["ROOM_DATA_BYTES"] = 17] = "ROOM_DATA_BYTES";
722
- Protocol[Protocol["PING"] = 18] = "PING";
723
- })(Protocol || (Protocol = {}));
724
- var ErrorCode;
725
- (function (ErrorCode) {
726
- ErrorCode[ErrorCode["MATCHMAKE_NO_HANDLER"] = 520] = "MATCHMAKE_NO_HANDLER";
727
- ErrorCode[ErrorCode["MATCHMAKE_INVALID_CRITERIA"] = 521] = "MATCHMAKE_INVALID_CRITERIA";
728
- ErrorCode[ErrorCode["MATCHMAKE_INVALID_ROOM_ID"] = 522] = "MATCHMAKE_INVALID_ROOM_ID";
729
- ErrorCode[ErrorCode["MATCHMAKE_UNHANDLED"] = 523] = "MATCHMAKE_UNHANDLED";
730
- ErrorCode[ErrorCode["MATCHMAKE_EXPIRED"] = 524] = "MATCHMAKE_EXPIRED";
731
- ErrorCode[ErrorCode["AUTH_FAILED"] = 525] = "AUTH_FAILED";
732
- ErrorCode[ErrorCode["APPLICATION_ERROR"] = 526] = "APPLICATION_ERROR";
733
- })(ErrorCode || (ErrorCode = {}));
734
-
735
709
  const serializers = {};
736
710
  function registerSerializer(id, serializer) {
737
711
  serializers[id] = serializer;
@@ -911,8 +885,11 @@
911
885
  // msgpackr workaround: force buffer to be created.
912
886
  this.packr.encode(undefined);
913
887
  if (rootSchema) {
914
- this.serializer = new (getSerializer("schema"));
915
- this.serializer.state = new rootSchema();
888
+ const serializer = new (getSerializer("schema"));
889
+ this.serializer = serializer;
890
+ const state = new rootSchema();
891
+ serializer.state = state;
892
+ serializer.decoder = new schema.Decoder(state);
916
893
  }
917
894
  this.onLeave(() => this.removeAllListeners());
918
895
  }
@@ -961,7 +938,7 @@
961
938
  this.onLeave((code) => resolve(code));
962
939
  if (this.connection) {
963
940
  if (consented) {
964
- this.packr.buffer[0] = Protocol.LEAVE_ROOM;
941
+ this.packr.buffer[0] = sharedTypes.Protocol.LEAVE_ROOM;
965
942
  this.connection.send(this.packr.buffer.subarray(0, 1));
966
943
  }
967
944
  else {
@@ -984,12 +961,12 @@
984
961
  }
985
962
  __classPrivateFieldSet(this, _Room_lastPingTime, now(), "f");
986
963
  __classPrivateFieldSet(this, _Room_pingCallback, callback, "f");
987
- this.packr.buffer[0] = Protocol.PING;
964
+ this.packr.buffer[0] = sharedTypes.Protocol.PING;
988
965
  this.connection.send(this.packr.buffer.subarray(0, 1));
989
966
  }
990
967
  send(messageType, payload) {
991
968
  const it = { offset: 1 };
992
- this.packr.buffer[0] = Protocol.ROOM_DATA;
969
+ this.packr.buffer[0] = sharedTypes.Protocol.ROOM_DATA;
993
970
  if (typeof (messageType) === "string") {
994
971
  schema.encode.string(this.packr.buffer, messageType, it);
995
972
  }
@@ -1015,7 +992,7 @@
1015
992
  return;
1016
993
  }
1017
994
  const it = { offset: 1 };
1018
- this.packr.buffer[0] = Protocol.ROOM_DATA;
995
+ this.packr.buffer[0] = sharedTypes.Protocol.ROOM_DATA;
1019
996
  if (typeof (type) === "string") {
1020
997
  schema.encode.string(this.packr.buffer, type, it);
1021
998
  }
@@ -1031,7 +1008,7 @@
1031
1008
  }
1032
1009
  sendBytes(type, bytes) {
1033
1010
  const it = { offset: 1 };
1034
- this.packr.buffer[0] = Protocol.ROOM_DATA_BYTES;
1011
+ this.packr.buffer[0] = sharedTypes.Protocol.ROOM_DATA_BYTES;
1035
1012
  if (typeof (type) === "string") {
1036
1013
  schema.encode.string(this.packr.buffer, type, it);
1037
1014
  }
@@ -1073,7 +1050,7 @@
1073
1050
  const buffer = new Uint8Array(event.data);
1074
1051
  const it = { offset: 1 };
1075
1052
  const code = buffer[0];
1076
- if (code === Protocol.JOIN_ROOM) {
1053
+ if (code === sharedTypes.Protocol.JOIN_ROOM) {
1077
1054
  const reconnectionToken = schema.decode.utf8Read(buffer, it, buffer[it.offset++]);
1078
1055
  this.serializerId = schema.decode.utf8Read(buffer, it, buffer[it.offset++]);
1079
1056
  // Instantiate serializer if not locally available.
@@ -1096,7 +1073,7 @@
1096
1073
  }
1097
1074
  this.reconnectionToken = `${this.roomId}:${reconnectionToken}`;
1098
1075
  // acknowledge successfull JOIN_ROOM
1099
- this.packr.buffer[0] = Protocol.JOIN_ROOM;
1076
+ this.packr.buffer[0] = sharedTypes.Protocol.JOIN_ROOM;
1100
1077
  this.connection.send(this.packr.buffer.subarray(0, 1));
1101
1078
  // Send any enqueued messages that were buffered while disconnected
1102
1079
  if (this.reconnection.enqueuedMessages.length > 0) {
@@ -1107,23 +1084,23 @@
1107
1084
  this.reconnection.enqueuedMessages = [];
1108
1085
  }
1109
1086
  }
1110
- else if (code === Protocol.ERROR) {
1087
+ else if (code === sharedTypes.Protocol.ERROR) {
1111
1088
  const code = schema.decode.number(buffer, it);
1112
1089
  const message = schema.decode.string(buffer, it);
1113
1090
  this.onError.invoke(code, message);
1114
1091
  }
1115
- else if (code === Protocol.LEAVE_ROOM) {
1092
+ else if (code === sharedTypes.Protocol.LEAVE_ROOM) {
1116
1093
  this.leave();
1117
1094
  }
1118
- else if (code === Protocol.ROOM_STATE) {
1095
+ else if (code === sharedTypes.Protocol.ROOM_STATE) {
1119
1096
  this.serializer.setState(buffer, it);
1120
1097
  this.onStateChange.invoke(this.serializer.getState());
1121
1098
  }
1122
- else if (code === Protocol.ROOM_STATE_PATCH) {
1099
+ else if (code === sharedTypes.Protocol.ROOM_STATE_PATCH) {
1123
1100
  this.serializer.patch(buffer, it);
1124
1101
  this.onStateChange.invoke(this.serializer.getState());
1125
1102
  }
1126
- else if (code === Protocol.ROOM_DATA) {
1103
+ else if (code === sharedTypes.Protocol.ROOM_DATA) {
1127
1104
  const type = (schema.decode.stringCheck(buffer, it))
1128
1105
  ? schema.decode.string(buffer, it)
1129
1106
  : schema.decode.number(buffer, it);
@@ -1132,13 +1109,13 @@
1132
1109
  : undefined;
1133
1110
  this.dispatchMessage(type, message);
1134
1111
  }
1135
- else if (code === Protocol.ROOM_DATA_BYTES) {
1112
+ else if (code === sharedTypes.Protocol.ROOM_DATA_BYTES) {
1136
1113
  const type = (schema.decode.stringCheck(buffer, it))
1137
1114
  ? schema.decode.string(buffer, it)
1138
1115
  : schema.decode.number(buffer, it);
1139
1116
  this.dispatchMessage(type, buffer.subarray(it.offset));
1140
1117
  }
1141
- else if (code === Protocol.PING) {
1118
+ else if (code === sharedTypes.Protocol.PING) {
1142
1119
  (_a = __classPrivateFieldGet(this, _Room_pingCallback, "f")) === null || _a === void 0 ? void 0 : _a.call(this, Math.round(now() - __classPrivateFieldGet(this, _Room_lastPingTime, "f")));
1143
1120
  __classPrivateFieldSet(this, _Room_pingCallback, undefined, "f");
1144
1121
  }
@@ -1827,14 +1804,14 @@
1827
1804
  let pingStart = 0;
1828
1805
  conn.events.onopen = () => {
1829
1806
  pingStart = Date.now();
1830
- conn.send(new Uint8Array([Protocol.PING]));
1807
+ conn.send(new Uint8Array([sharedTypes.Protocol.PING]));
1831
1808
  };
1832
1809
  conn.events.onmessage = (_) => {
1833
1810
  latencies.push(Date.now() - pingStart);
1834
1811
  if (latencies.length < pingCount) {
1835
1812
  // Send another ping
1836
1813
  pingStart = Date.now();
1837
- conn.send(new Uint8Array([Protocol.PING]));
1814
+ conn.send(new Uint8Array([sharedTypes.Protocol.PING]));
1838
1815
  }
1839
1816
  else {
1840
1817
  // Done, calculate average and close