@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/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.16
6
+ // colyseus.js@0.17.18
7
7
  (function (sharedTypes, schema, msgpackr, NodeWebSocket) {
8
8
  'use strict';
9
9
 
@@ -411,10 +411,16 @@
411
411
  };
412
412
 
413
413
  class ServerError extends Error {
414
- constructor(code, message) {
414
+ constructor(code, message, opts) {
415
415
  super(message);
416
416
  this.name = "ServerError";
417
417
  this.code = code;
418
+ if (opts) {
419
+ this.headers = opts.headers;
420
+ this.status = opts.status;
421
+ this.response = opts.response;
422
+ this.data = opts.data;
423
+ }
418
424
  }
419
425
  }
420
426
  class AbortError extends Error {
@@ -423,6 +429,14 @@
423
429
  this.name = "AbortError";
424
430
  }
425
431
  }
432
+ class MatchMakeError extends Error {
433
+ constructor(message, code) {
434
+ super(message);
435
+ this.code = code;
436
+ this.name = "MatchMakeError";
437
+ Object.setPrototypeOf(this, MatchMakeError.prototype);
438
+ }
439
+ }
426
440
 
427
441
  class H3TransportTransport {
428
442
  constructor(events) {
@@ -1305,7 +1319,7 @@
1305
1319
  }
1306
1320
  executeRequest(method, path, requestOptions) {
1307
1321
  return __awaiter(this, void 0, void 0, function* () {
1308
- var _a;
1322
+ var _a, _b, _c;
1309
1323
  //
1310
1324
  // FIXME: if FormData is provided, merging "baseOptions.body" with
1311
1325
  // "options.body" will not work as intended
@@ -1340,9 +1354,9 @@
1340
1354
  body,
1341
1355
  method });
1342
1356
  const url = getURLWithQueryParams(this.sdk['getHttpEndpoint'](path.toString()), mergedOptions);
1343
- let response;
1357
+ let raw;
1344
1358
  try {
1345
- response = yield fetch(url, mergedOptions);
1359
+ raw = yield fetch(url, mergedOptions);
1346
1360
  }
1347
1361
  catch (err) {
1348
1362
  // If it's an AbortError, re-throw as-is
@@ -1351,35 +1365,36 @@
1351
1365
  }
1352
1366
  // Re-throw with network error code at top level (e.g. ECONNREFUSED)
1353
1367
  const networkError = new ServerError(((_a = err.cause) === null || _a === void 0 ? void 0 : _a.code) || err.code, err.message);
1368
+ networkError.response = raw;
1354
1369
  networkError.cause = err.cause;
1355
1370
  throw networkError;
1356
1371
  }
1357
- const contentType = response.headers.get("content-type");
1372
+ const contentType = raw.headers.get("content-type");
1358
1373
  let data;
1359
- let error = null;
1360
1374
  // TODO: improve content-type detection here!
1361
1375
  if (contentType === null || contentType === void 0 ? void 0 : contentType.indexOf("json")) {
1362
- data = yield response.json();
1376
+ data = yield raw.json();
1363
1377
  }
1364
1378
  else if (contentType === null || contentType === void 0 ? void 0 : contentType.indexOf("text")) {
1365
- data = yield response.text();
1379
+ data = yield raw.text();
1366
1380
  }
1367
1381
  else {
1368
- data = yield response.blob();
1382
+ data = yield raw.blob();
1369
1383
  }
1370
- if (!response.ok) {
1371
- // TODO: throw error here?!
1372
- error = data;
1373
- data = null;
1384
+ if (!raw.ok) {
1385
+ throw new ServerError((_b = data.code) !== null && _b !== void 0 ? _b : raw.status, (_c = data.message) !== null && _c !== void 0 ? _c : raw.statusText, {
1386
+ headers: raw.headers,
1387
+ status: raw.status,
1388
+ response: raw,
1389
+ data
1390
+ });
1374
1391
  }
1375
1392
  return {
1376
- ok: response.ok,
1377
- headers: response.headers,
1393
+ raw,
1378
1394
  data,
1379
- error,
1380
- status: response.status,
1381
- statusText: response.statusText,
1382
- response,
1395
+ headers: raw.headers,
1396
+ status: raw.status,
1397
+ statusText: raw.statusText,
1383
1398
  };
1384
1399
  });
1385
1400
  }
@@ -1657,14 +1672,6 @@
1657
1672
  }
1658
1673
 
1659
1674
  var _a;
1660
- class MatchMakeError extends Error {
1661
- constructor(message, code) {
1662
- super(message);
1663
- this.code = code;
1664
- this.name = "MatchMakeError";
1665
- Object.setPrototypeOf(this, MatchMakeError.prototype);
1666
- }
1667
- }
1668
1675
  // - React Native does not provide `window.location`
1669
1676
  // - Cocos Creator (Native) does not provide `window.location.hostname`
1670
1677
  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")
@@ -1844,24 +1851,27 @@
1844
1851
  }
1845
1852
  createMatchMakeRequest(method_1, roomName_1) {
1846
1853
  return __awaiter(this, arguments, void 0, function* (method, roomName, options = {}, rootSchema) {
1847
- const httpResponse = yield this.http.post(`/matchmake/${method}/${roomName}`, {
1848
- headers: {
1849
- 'Accept': 'application/json',
1850
- 'Content-Type': 'application/json'
1851
- },
1852
- body: options
1853
- });
1854
- // Handle HTTP error responses
1855
- if (!httpResponse.ok) {
1856
- // @ts-ignore
1857
- throw new MatchMakeError(httpResponse.error.message || httpResponse.error, httpResponse.error.code || httpResponse.status);
1854
+ try {
1855
+ const httpResponse = yield this.http.post(`/matchmake/${method}/${roomName}`, {
1856
+ headers: {
1857
+ 'Accept': 'application/json',
1858
+ 'Content-Type': 'application/json'
1859
+ },
1860
+ body: options
1861
+ });
1862
+ const response = httpResponse.data;
1863
+ // forward reconnection token during "reconnect" methods.
1864
+ if (method === "reconnect") {
1865
+ response.reconnectionToken = options.reconnectionToken;
1866
+ }
1867
+ return yield this.consumeSeatReservation(response, rootSchema);
1858
1868
  }
1859
- const response = httpResponse.data;
1860
- // forward reconnection token during "reconnect" methods.
1861
- if (method === "reconnect") {
1862
- response.reconnectionToken = options.reconnectionToken;
1869
+ catch (error) {
1870
+ if (error instanceof ServerError) {
1871
+ throw new MatchMakeError(error.message, error.code);
1872
+ }
1873
+ throw error;
1863
1874
  }
1864
- return yield this.consumeSeatReservation(response, rootSchema);
1865
1875
  });
1866
1876
  }
1867
1877
  createRoom(roomName, rootSchema) {