@colyseus/sdk 0.17.16 → 0.17.18

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 (67) 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 +20 -26
  6. package/build/Client.cjs.map +1 -1
  7. package/build/Client.d.ts +0 -4
  8. package/build/Client.mjs +22 -28
  9. package/build/Client.mjs.map +1 -1
  10. package/build/Connection.cjs +1 -1
  11. package/build/Connection.mjs +1 -1
  12. package/build/HTTP.cjs +20 -19
  13. package/build/HTTP.cjs.map +1 -1
  14. package/build/HTTP.d.ts +2 -18
  15. package/build/HTTP.mjs +19 -18
  16. package/build/HTTP.mjs.map +1 -1
  17. package/build/Protocol.cjs +1 -1
  18. package/build/Protocol.mjs +1 -1
  19. package/build/Room.cjs +1 -1
  20. package/build/Room.cjs.map +1 -1
  21. package/build/Room.d.ts +6 -5
  22. package/build/Room.mjs +1 -1
  23. package/build/Room.mjs.map +1 -1
  24. package/build/Storage.cjs +1 -1
  25. package/build/Storage.mjs +1 -1
  26. package/build/core/nanoevents.cjs +1 -1
  27. package/build/core/nanoevents.mjs +1 -1
  28. package/build/core/signal.cjs +1 -1
  29. package/build/core/signal.mjs +1 -1
  30. package/build/core/utils.cjs +1 -1
  31. package/build/core/utils.mjs +1 -1
  32. package/build/debug.cjs +1 -1
  33. package/build/debug.mjs +1 -1
  34. package/build/errors/Errors.cjs +17 -2
  35. package/build/errors/Errors.cjs.map +1 -1
  36. package/build/errors/Errors.d.ts +15 -2
  37. package/build/errors/Errors.mjs +22 -3
  38. package/build/errors/Errors.mjs.map +1 -1
  39. package/build/index.cjs +3 -2
  40. package/build/index.cjs.map +1 -1
  41. package/build/index.d.ts +2 -2
  42. package/build/index.mjs +3 -3
  43. package/build/index.mjs.map +1 -1
  44. package/build/legacy.cjs +1 -1
  45. package/build/legacy.mjs +1 -1
  46. package/build/serializer/NoneSerializer.cjs +1 -1
  47. package/build/serializer/NoneSerializer.mjs +1 -1
  48. package/build/serializer/SchemaSerializer.cjs +1 -1
  49. package/build/serializer/SchemaSerializer.mjs +1 -1
  50. package/build/serializer/Serializer.cjs +1 -1
  51. package/build/serializer/Serializer.mjs +1 -1
  52. package/build/transport/H3Transport.cjs +1 -1
  53. package/build/transport/H3Transport.mjs +1 -1
  54. package/build/transport/WebSocketTransport.cjs +1 -1
  55. package/build/transport/WebSocketTransport.mjs +1 -1
  56. package/dist/colyseus-cocos-creator.js +61 -44
  57. package/dist/colyseus-cocos-creator.js.map +1 -1
  58. package/dist/colyseus.js +61 -44
  59. package/dist/colyseus.js.map +1 -1
  60. package/dist/debug.js +54 -44
  61. package/dist/debug.js.map +1 -1
  62. package/package.json +3 -3
  63. package/src/Client.ts +20 -28
  64. package/src/HTTP.ts +20 -40
  65. package/src/Room.ts +11 -10
  66. package/src/errors/Errors.ts +33 -11
  67. 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.16 - @colyseus/schema 4.0.4
6
+ // colyseus.js@0.17.18 - @colyseus/schema 4.0.4
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) :
@@ -119,10 +119,30 @@
119
119
  };
120
120
 
121
121
  class ServerError extends Error {
122
- constructor(code, message) {
122
+ constructor(code, message, opts) {
123
123
  super(message);
124
124
  this.name = "ServerError";
125
125
  this.code = code;
126
+ if (opts) {
127
+ this.headers = opts.headers;
128
+ this.status = opts.status;
129
+ this.response = opts.response;
130
+ this.data = opts.data;
131
+ }
132
+ }
133
+ }
134
+ class AbortError extends Error {
135
+ constructor(message) {
136
+ super(message);
137
+ this.name = "AbortError";
138
+ }
139
+ }
140
+ class MatchMakeError extends Error {
141
+ constructor(message, code) {
142
+ super(message);
143
+ this.code = code;
144
+ this.name = "MatchMakeError";
145
+ Object.setPrototypeOf(this, MatchMakeError.prototype);
126
146
  }
127
147
  }
128
148
 
@@ -8957,7 +8977,7 @@
8957
8977
  }
8958
8978
  executeRequest(method, path, requestOptions) {
8959
8979
  return __awaiter(this, void 0, void 0, function* () {
8960
- var _a;
8980
+ var _a, _b, _c;
8961
8981
  //
8962
8982
  // FIXME: if FormData is provided, merging "baseOptions.body" with
8963
8983
  // "options.body" will not work as intended
@@ -8992,9 +9012,9 @@
8992
9012
  body,
8993
9013
  method });
8994
9014
  const url = getURLWithQueryParams(this.sdk['getHttpEndpoint'](path.toString()), mergedOptions);
8995
- let response;
9015
+ let raw;
8996
9016
  try {
8997
- response = yield fetch(url, mergedOptions);
9017
+ raw = yield fetch(url, mergedOptions);
8998
9018
  }
8999
9019
  catch (err) {
9000
9020
  // If it's an AbortError, re-throw as-is
@@ -9003,35 +9023,36 @@
9003
9023
  }
9004
9024
  // Re-throw with network error code at top level (e.g. ECONNREFUSED)
9005
9025
  const networkError = new ServerError(((_a = err.cause) === null || _a === void 0 ? void 0 : _a.code) || err.code, err.message);
9026
+ networkError.response = raw;
9006
9027
  networkError.cause = err.cause;
9007
9028
  throw networkError;
9008
9029
  }
9009
- const contentType = response.headers.get("content-type");
9030
+ const contentType = raw.headers.get("content-type");
9010
9031
  let data;
9011
- let error = null;
9012
9032
  // TODO: improve content-type detection here!
9013
9033
  if (contentType === null || contentType === void 0 ? void 0 : contentType.indexOf("json")) {
9014
- data = yield response.json();
9034
+ data = yield raw.json();
9015
9035
  }
9016
9036
  else if (contentType === null || contentType === void 0 ? void 0 : contentType.indexOf("text")) {
9017
- data = yield response.text();
9037
+ data = yield raw.text();
9018
9038
  }
9019
9039
  else {
9020
- data = yield response.blob();
9040
+ data = yield raw.blob();
9021
9041
  }
9022
- if (!response.ok) {
9023
- // TODO: throw error here?!
9024
- error = data;
9025
- data = null;
9042
+ if (!raw.ok) {
9043
+ throw new ServerError((_b = data.code) !== null && _b !== void 0 ? _b : raw.status, (_c = data.message) !== null && _c !== void 0 ? _c : raw.statusText, {
9044
+ headers: raw.headers,
9045
+ status: raw.status,
9046
+ response: raw,
9047
+ data
9048
+ });
9026
9049
  }
9027
9050
  return {
9028
- ok: response.ok,
9029
- headers: response.headers,
9051
+ raw,
9030
9052
  data,
9031
- error,
9032
- status: response.status,
9033
- statusText: response.statusText,
9034
- response,
9053
+ headers: raw.headers,
9054
+ status: raw.status,
9055
+ statusText: raw.statusText,
9035
9056
  };
9036
9057
  });
9037
9058
  }
@@ -9309,14 +9330,6 @@
9309
9330
  }
9310
9331
 
9311
9332
  var _a;
9312
- class MatchMakeError extends Error {
9313
- constructor(message, code) {
9314
- super(message);
9315
- this.code = code;
9316
- this.name = "MatchMakeError";
9317
- Object.setPrototypeOf(this, MatchMakeError.prototype);
9318
- }
9319
- }
9320
9333
  // - React Native does not provide `window.location`
9321
9334
  // - Cocos Creator (Native) does not provide `window.location.hostname`
9322
9335
  const DEFAULT_ENDPOINT = (typeof (window) !== "undefined" && typeof ((_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.hostname) !== "undefined")
@@ -9496,24 +9509,27 @@
9496
9509
  }
9497
9510
  createMatchMakeRequest(method_1, roomName_1) {
9498
9511
  return __awaiter(this, arguments, void 0, function* (method, roomName, options = {}, rootSchema) {
9499
- const httpResponse = yield this.http.post(`/matchmake/${method}/${roomName}`, {
9500
- headers: {
9501
- 'Accept': 'application/json',
9502
- 'Content-Type': 'application/json'
9503
- },
9504
- body: options
9505
- });
9506
- // Handle HTTP error responses
9507
- if (!httpResponse.ok) {
9508
- // @ts-ignore
9509
- throw new MatchMakeError(httpResponse.error.message || httpResponse.error, httpResponse.error.code || httpResponse.status);
9512
+ try {
9513
+ const httpResponse = yield this.http.post(`/matchmake/${method}/${roomName}`, {
9514
+ headers: {
9515
+ 'Accept': 'application/json',
9516
+ 'Content-Type': 'application/json'
9517
+ },
9518
+ body: options
9519
+ });
9520
+ const response = httpResponse.data;
9521
+ // forward reconnection token during "reconnect" methods.
9522
+ if (method === "reconnect") {
9523
+ response.reconnectionToken = options.reconnectionToken;
9524
+ }
9525
+ return yield this.consumeSeatReservation(response, rootSchema);
9510
9526
  }
9511
- const response = httpResponse.data;
9512
- // forward reconnection token during "reconnect" methods.
9513
- if (method === "reconnect") {
9514
- response.reconnectionToken = options.reconnectionToken;
9527
+ catch (error) {
9528
+ if (error instanceof ServerError) {
9529
+ throw new MatchMakeError(error.message, error.code);
9530
+ }
9531
+ throw error;
9515
9532
  }
9516
- return yield this.consumeSeatReservation(response, rootSchema);
9517
9533
  });
9518
9534
  }
9519
9535
  createRoom(roomName, rootSchema) {
@@ -9580,6 +9596,7 @@
9580
9596
  registerSerializer('schema', SchemaSerializer);
9581
9597
  registerSerializer('none', NoneSerializer);
9582
9598
 
9599
+ exports.AbortError = AbortError;
9583
9600
  exports.Auth = Auth;
9584
9601
  exports.Callbacks = buildExports.Callbacks;
9585
9602
  exports.Client = Client;