@colyseus/sdk 0.17.42 → 0.17.43

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 (48) 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 +39 -10
  6. package/build/Client.cjs.map +1 -1
  7. package/build/Client.d.ts +11 -2
  8. package/build/Client.mjs +38 -10
  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 +1 -1
  13. package/build/HTTP.mjs +1 -1
  14. package/build/Room.cjs +1 -1
  15. package/build/Room.mjs +1 -1
  16. package/build/Storage.cjs +1 -1
  17. package/build/Storage.mjs +1 -1
  18. package/build/core/nanoevents.cjs +1 -1
  19. package/build/core/nanoevents.mjs +1 -1
  20. package/build/core/signal.cjs +1 -1
  21. package/build/core/signal.mjs +1 -1
  22. package/build/core/utils.cjs +1 -1
  23. package/build/core/utils.mjs +1 -1
  24. package/build/debug.cjs +1 -1
  25. package/build/debug.mjs +1 -1
  26. package/build/errors/Errors.cjs +1 -1
  27. package/build/errors/Errors.mjs +1 -1
  28. package/build/fetchXHR.cjs +1 -1
  29. package/build/fetchXHR.mjs +1 -1
  30. package/build/index.cjs +1 -1
  31. package/build/index.mjs +1 -1
  32. package/build/legacy.cjs +1 -1
  33. package/build/legacy.mjs +1 -1
  34. package/build/serializer/NoneSerializer.cjs +1 -1
  35. package/build/serializer/NoneSerializer.mjs +1 -1
  36. package/build/serializer/SchemaSerializer.cjs +1 -1
  37. package/build/serializer/SchemaSerializer.mjs +1 -1
  38. package/build/serializer/Serializer.cjs +1 -1
  39. package/build/serializer/Serializer.mjs +1 -1
  40. package/build/transport/H3Transport.cjs +1 -1
  41. package/build/transport/H3Transport.mjs +1 -1
  42. package/build/transport/WebSocketTransport.cjs +1 -1
  43. package/build/transport/WebSocketTransport.mjs +1 -1
  44. package/dist/colyseus.js +39 -10
  45. package/dist/colyseus.js.map +1 -1
  46. package/dist/debug.js +1 -1
  47. package/package.json +2 -2
  48. package/src/Client.ts +41 -8
package/build/Storage.mjs 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.42
6
+ // colyseus.js@0.17.43
7
7
  /// <reference path="../typings/cocos-creator.d.ts" />
8
8
  /**
9
9
  * We do not assign 'storage' to window.localStorage immediatelly for React
@@ -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.42
6
+ // colyseus.js@0.17.43
7
7
  'use strict';
8
8
 
9
9
  /**
@@ -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.42
6
+ // colyseus.js@0.17.43
7
7
  /**
8
8
  * The MIT License (MIT)
9
9
  *
@@ -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.42
6
+ // colyseus.js@0.17.43
7
7
  'use strict';
8
8
 
9
9
  class EventEmitter {
@@ -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.42
6
+ // colyseus.js@0.17.43
7
7
  class EventEmitter {
8
8
  handlers = [];
9
9
  register(cb, once = false) {
@@ -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.42
6
+ // colyseus.js@0.17.43
7
7
  'use strict';
8
8
 
9
9
  function now() {
@@ -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.42
6
+ // colyseus.js@0.17.43
7
7
  function now() {
8
8
  return typeof (performance) !== 'undefined' ? performance.now() : Date.now();
9
9
  }
package/build/debug.cjs 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.42
6
+ // colyseus.js@0.17.43
7
7
  'use strict';
8
8
 
9
9
  var Client = require('./Client.cjs');
package/build/debug.mjs 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.42
6
+ // colyseus.js@0.17.43
7
7
  import { Client } from './Client.mjs';
8
8
  import { CloseCode } from '@colyseus/shared-types';
9
9
 
@@ -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.42
6
+ // colyseus.js@0.17.43
7
7
  'use strict';
8
8
 
9
9
  class ServerError extends Error {
@@ -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.42
6
+ // colyseus.js@0.17.43
7
7
  class ServerError extends Error {
8
8
  code;
9
9
  headers;
@@ -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.42
6
+ // colyseus.js@0.17.43
7
7
  'use strict';
8
8
 
9
9
  var tslib = require('tslib');
@@ -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.42
6
+ // colyseus.js@0.17.43
7
7
  /**
8
8
  * Minimal fetch-compatible wrapper around XMLHttpRequest.
9
9
  * Used as an automatic fallback when globalThis.fetch is unavailable
package/build/index.cjs 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.42
6
+ // colyseus.js@0.17.43
7
7
  'use strict';
8
8
 
9
9
  require('./legacy.cjs');
package/build/index.mjs 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.42
6
+ // colyseus.js@0.17.43
7
7
  import './legacy.mjs';
8
8
  export { Client, ColyseusSDK } from './Client.mjs';
9
9
  export { Room } from './Room.mjs';
package/build/legacy.cjs 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.42
6
+ // colyseus.js@0.17.43
7
7
  'use strict';
8
8
 
9
9
  //
package/build/legacy.mjs 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.42
6
+ // colyseus.js@0.17.43
7
7
  //
8
8
  // Polyfills for legacy environments
9
9
  //
@@ -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.42
6
+ // colyseus.js@0.17.43
7
7
  'use strict';
8
8
 
9
9
  class NoneSerializer {
@@ -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.42
6
+ // colyseus.js@0.17.43
7
7
  class NoneSerializer {
8
8
  setState(rawState) { }
9
9
  getState() { return null; }
@@ -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.42
6
+ // colyseus.js@0.17.43
7
7
  'use strict';
8
8
 
9
9
  var schema = require('@colyseus/schema');
@@ -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.42
6
+ // colyseus.js@0.17.43
7
7
  import { getDecoderStateCallbacks, Reflection, Decoder } from '@colyseus/schema';
8
8
 
9
9
  //
@@ -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.42
6
+ // colyseus.js@0.17.43
7
7
  'use strict';
8
8
 
9
9
  const serializers = {};
@@ -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.42
6
+ // colyseus.js@0.17.43
7
7
  const serializers = {};
8
8
  function registerSerializer(id, serializer) {
9
9
  serializers[id] = serializer;
@@ -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.42
6
+ // colyseus.js@0.17.43
7
7
  'use strict';
8
8
 
9
9
  var tslib = require('tslib');
@@ -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.42
6
+ // colyseus.js@0.17.43
7
7
  import { decode, encode } from '@colyseus/schema';
8
8
 
9
9
  // 9 bytes is the maximum length of a variable-length integer prefix
@@ -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.42
6
+ // colyseus.js@0.17.43
7
7
  'use strict';
8
8
 
9
9
  var NodeWebSocket = require('ws');
@@ -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.42
6
+ // colyseus.js@0.17.43
7
7
  import NodeWebSocket from 'ws';
8
8
  import { CloseCode } from '@colyseus/shared-types';
9
9
 
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.42 - @colyseus/schema 4.0.13
6
+ // colyseus.js@0.17.43 - @colyseus/schema 4.0.13
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) :
@@ -9582,7 +9582,7 @@
9582
9582
  * Select the endpoint with the lowest latency.
9583
9583
  * @param endpoints Array of endpoints to select from.
9584
9584
  * @param options Client options.
9585
- * @param latencyOptions Latency measurement options (protocol, pingCount).
9585
+ * @param latencyOptions Latency measurement options (protocol, pingCount, timeout) — forwarded to each {@link getLatency} call.
9586
9586
  * @returns The client with the lowest latency.
9587
9587
  */
9588
9588
  static selectByLatency(endpoints_1, options_1) {
@@ -9661,16 +9661,41 @@
9661
9661
  }
9662
9662
  /**
9663
9663
  * Create a new connection with the server, and measure the latency.
9664
- * @param options Latency measurement options (protocol, pingCount).
9664
+ *
9665
+ * Always settles: resolves with the (average) round-trip time, or rejects on
9666
+ * connection error, server-side close before all pongs arrive, or timeout.
9667
+ *
9668
+ * @param options Latency measurement options (protocol, pingCount, timeout).
9665
9669
  */
9666
9670
  getLatency(options = {}) {
9667
- var _a, _b;
9671
+ var _a, _b, _c;
9668
9672
  const protocol = (_a = options.protocol) !== null && _a !== void 0 ? _a : "ws";
9669
9673
  const pingCount = (_b = options.pingCount) !== null && _b !== void 0 ? _b : 1;
9674
+ const timeout = (_c = options.timeout) !== null && _c !== void 0 ? _c : 1500;
9670
9675
  return new Promise((resolve, reject) => {
9676
+ var _a;
9671
9677
  const conn = new Connection(protocol);
9672
9678
  const latencies = [];
9673
9679
  let pingStart = 0;
9680
+ let settled = false;
9681
+ let timeoutId;
9682
+ // run exactly once — guards against late events after resolve/reject
9683
+ // (e.g. our own conn.close() firing onclose, or a stray onclose/onerror pair)
9684
+ const settle = (run) => {
9685
+ if (settled) {
9686
+ return;
9687
+ }
9688
+ settled = true;
9689
+ clearTimeout(timeoutId);
9690
+ try {
9691
+ conn.close();
9692
+ }
9693
+ catch (e) { /* socket may never have opened */ }
9694
+ run();
9695
+ };
9696
+ const fail = (message) => settle(() => reject(new ServerError(CloseCode.ABNORMAL_CLOSURE, `Failed to get latency: ${message}`)));
9697
+ // bound blackholed/filtered hosts that never fire onopen/onerror within the OS TCP timeout
9698
+ timeoutId = setTimeout(() => fail(`timed out after ${timeout}ms`), timeout);
9674
9699
  conn.events.onopen = () => {
9675
9700
  pingStart = Date.now();
9676
9701
  conn.send(new Uint8Array([Protocol.PING]));
@@ -9684,15 +9709,19 @@
9684
9709
  }
9685
9710
  else {
9686
9711
  // Done, calculate average and close
9687
- conn.close();
9688
9712
  const average = latencies.reduce((sum, l) => sum + l, 0) / latencies.length;
9689
- resolve(average);
9713
+ settle(() => resolve(average));
9690
9714
  }
9691
9715
  };
9692
- conn.events.onerror = (event) => {
9693
- reject(new ServerError(CloseCode.ABNORMAL_CLOSURE, `Failed to get latency: ${event.message}`));
9694
- };
9695
- conn.connect(this.getHttpEndpoint());
9716
+ // server closed the socket before all pongs arrived — fires without onerror on a clean close
9717
+ conn.events.onclose = (event) => fail(`connection closed${(event === null || event === void 0 ? void 0 : event.code) ? ` (${event.code})` : ""}${(event === null || event === void 0 ? void 0 : event.reason) ? `: ${event.reason}` : ""}`);
9718
+ conn.events.onerror = (event) => fail(event.message);
9719
+ try {
9720
+ conn.connect(this.getHttpEndpoint());
9721
+ }
9722
+ catch (e) {
9723
+ fail((_a = e === null || e === void 0 ? void 0 : e.message) !== null && _a !== void 0 ? _a : "failed to connect");
9724
+ }
9696
9725
  });
9697
9726
  }
9698
9727
  createMatchMakeRequest(method_1, roomName_1) {