@colyseus/sdk 0.17.24 → 0.17.26

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 (53) 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 +1 -1
  6. package/build/Client.mjs +1 -1
  7. package/build/Connection.cjs +7 -3
  8. package/build/Connection.cjs.map +1 -1
  9. package/build/Connection.mjs +7 -3
  10. package/build/Connection.mjs.map +1 -1
  11. package/build/HTTP.bkp.d.ts +103 -0
  12. package/build/HTTP.cjs +1 -1
  13. package/build/HTTP.mjs +1 -1
  14. package/build/Room.cjs +16 -10
  15. package/build/Room.cjs.map +1 -1
  16. package/build/Room.mjs +16 -10
  17. package/build/Room.mjs.map +1 -1
  18. package/build/Storage.cjs +1 -1
  19. package/build/Storage.mjs +1 -1
  20. package/build/core/nanoevents.cjs +1 -1
  21. package/build/core/nanoevents.mjs +1 -1
  22. package/build/core/signal.cjs +1 -1
  23. package/build/core/signal.mjs +1 -1
  24. package/build/core/utils.cjs +1 -1
  25. package/build/core/utils.mjs +1 -1
  26. package/build/debug.cjs +1 -1
  27. package/build/debug.mjs +1 -1
  28. package/build/errors/Errors.cjs +1 -1
  29. package/build/errors/Errors.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-cocos-creator.js +61 -17
  45. package/dist/colyseus-cocos-creator.js.map +1 -1
  46. package/dist/colyseus.d.ts +3969 -0
  47. package/dist/colyseus.js +61 -17
  48. package/dist/colyseus.js.map +1 -1
  49. package/dist/debug.js +22 -12
  50. package/dist/debug.js.map +1 -1
  51. package/package.json +8 -8
  52. package/src/Connection.ts +8 -2
  53. package/src/Room.ts +16 -8
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.24 - @colyseus/schema 4.0.5
6
+ // colyseus.js@0.17.26 - @colyseus/schema 4.0.8
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) :
@@ -115,6 +115,7 @@
115
115
  CONSENTED: 4e3,
116
116
  SERVER_SHUTDOWN: 4001,
117
117
  WITH_ERROR: 4002,
118
+ FAILED_TO_RECONNECT: 4003,
118
119
  MAY_TRY_RECONNECT: 4010
119
120
  };
120
121
 
@@ -1092,7 +1093,11 @@
1092
1093
  });
1093
1094
  }
1094
1095
  }
1095
- constructor[Symbol.metadata] = metadata;
1096
+ Object.defineProperty(constructor, Symbol.metadata, {
1097
+ value: metadata,
1098
+ writable: false,
1099
+ configurable: true
1100
+ });
1096
1101
  return metadata;
1097
1102
  },
1098
1103
  isValidInstance(klass) {
@@ -3714,7 +3719,12 @@
3714
3719
  }
3715
3720
  else if (value['type'] !== undefined && Schema.is(value['type'])) {
3716
3721
  // Direct Schema type: Type → new Type()
3717
- defaultValues[fieldName] = new value['type']();
3722
+ if (!value['type'].prototype.initialize || value['type'].prototype.initialize.length === 0) {
3723
+ // only auto-initialize Schema instances if:
3724
+ // - they don't have an initialize method
3725
+ // - or initialize method doesn't accept any parameters
3726
+ defaultValues[fieldName] = new value['type']();
3727
+ }
3718
3728
  }
3719
3729
  }
3720
3730
  else {
@@ -3724,7 +3734,12 @@
3724
3734
  else if (typeof (value) === "function") {
3725
3735
  if (Schema.is(value)) {
3726
3736
  // Direct Schema type: Type → new Type()
3727
- defaultValues[fieldName] = new value();
3737
+ if (!value.prototype.initialize || value.prototype.initialize.length === 0) {
3738
+ // only auto-initialize Schema instances if:
3739
+ // - they don't have an initialize method
3740
+ // - or initialize method doesn't accept any parameters
3741
+ defaultValues[fieldName] = new value();
3742
+ }
3728
3743
  fields[fieldName] = getNormalizedType(value);
3729
3744
  }
3730
3745
  else {
@@ -3751,13 +3766,32 @@
3751
3766
  }
3752
3767
  return defaults;
3753
3768
  };
3769
+ const getParentProps = (props) => {
3770
+ const fieldNames = Object.keys(fields);
3771
+ const parentProps = {};
3772
+ for (const key in props) {
3773
+ if (!fieldNames.includes(key)) {
3774
+ parentProps[key] = props[key];
3775
+ }
3776
+ }
3777
+ return parentProps;
3778
+ };
3754
3779
  /** @codegen-ignore */
3755
3780
  const klass = Metadata.setFields(class extends inherits {
3756
3781
  constructor(...args) {
3757
- super(Object.assign({}, getDefaultValues(), args[0] || {}));
3758
3782
  // call initialize method
3759
3783
  if (methods.initialize && typeof methods.initialize === 'function') {
3760
- methods.initialize.apply(this, args);
3784
+ super(Object.assign({}, getDefaultValues(), getParentProps(args[0] || {})));
3785
+ /**
3786
+ * only call initialize() in the current class, not the parent ones.
3787
+ * see "should not call initialize automatically when creating an instance of inherited Schema"
3788
+ */
3789
+ if (new.target === klass) {
3790
+ methods.initialize.apply(this, args);
3791
+ }
3792
+ }
3793
+ else {
3794
+ super(Object.assign({}, getDefaultValues(), args[0] || {}));
3761
3795
  }
3762
3796
  }
3763
3797
  }, fields);
@@ -8383,8 +8417,12 @@
8383
8417
  this.transport.sendUnreliable(data);
8384
8418
  }
8385
8419
  reconnect(queryParams) {
8386
- const queryString = new URLSearchParams(queryParams).toString();
8387
- this.transport.connect(`${this.url}&${queryString}`, this.options);
8420
+ const url = new URL(this.url);
8421
+ // override query params
8422
+ for (const key in queryParams) {
8423
+ url.searchParams.set(key, queryParams[key]);
8424
+ }
8425
+ this.transport.connect(url.toString(), this.options);
8388
8426
  }
8389
8427
  close(code, reason) {
8390
8428
  this.transport.close(code, reason);
@@ -8579,7 +8617,10 @@
8579
8617
  serializer.state = state;
8580
8618
  serializer.decoder = new buildExports.Decoder(state);
8581
8619
  }
8582
- this.onLeave(() => this.removeAllListeners());
8620
+ this.onLeave(() => {
8621
+ this.removeAllListeners();
8622
+ this.destroy();
8623
+ });
8583
8624
  }
8584
8625
  connect(endpoint, options, headers) {
8585
8626
  var _a;
@@ -8601,7 +8642,6 @@
8601
8642
  }
8602
8643
  else {
8603
8644
  this.onLeave.invoke(e.code, e.reason);
8604
- this.destroy();
8605
8645
  }
8606
8646
  };
8607
8647
  this.connection.events.onerror = (e) => {
@@ -8727,6 +8767,8 @@
8727
8767
  this.onStateChange.clear();
8728
8768
  this.onError.clear();
8729
8769
  this.onLeave.clear();
8770
+ this.onReconnect.clear();
8771
+ this.onDrop.clear();
8730
8772
  this.onMessageHandlers.events = {};
8731
8773
  if (this.serializer instanceof SchemaSerializer) {
8732
8774
  // Remove callback references
@@ -8838,6 +8880,7 @@
8838
8880
  handleReconnection() {
8839
8881
  if (Date.now() - this.joinedAtTime < this.reconnection.minUptime) {
8840
8882
  console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x274C)} Room has not been up for long enough for automatic reconnection. (min uptime: ${this.reconnection.minUptime}ms)`); // ❌
8883
+ this.onLeave.invoke(CloseCode.ABNORMAL_CLOSURE, "Room uptime too short for reconnection.");
8841
8884
  return;
8842
8885
  }
8843
8886
  if (!this.reconnection.isReconnecting) {
@@ -8847,6 +8890,13 @@
8847
8890
  this.retryReconnection();
8848
8891
  }
8849
8892
  retryReconnection() {
8893
+ if (this.reconnection.retryCount >= this.reconnection.maxRetries) {
8894
+ // No more retries
8895
+ console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x274C)} ❌ Reconnection failed after ${this.reconnection.maxRetries} attempts.`); // ❌
8896
+ this.reconnection.isReconnecting = false;
8897
+ this.onLeave.invoke(CloseCode.FAILED_TO_RECONNECT, "No more retries. Reconnection failed.");
8898
+ return;
8899
+ }
8850
8900
  this.reconnection.retryCount++;
8851
8901
  const delay = Math.min(this.reconnection.maxDelay, Math.max(this.reconnection.minDelay, this.reconnection.backoff(this.reconnection.retryCount, this.reconnection.delay)));
8852
8902
  console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x023F3)} will retry in ${(delay / 1000).toFixed(1)} seconds...`); // 🔄
@@ -8860,13 +8910,7 @@
8860
8910
  });
8861
8911
  }
8862
8912
  catch (e) {
8863
- console.log(".reconnect() failed", e);
8864
- if (this.reconnection.retryCount < this.reconnection.maxRetries) {
8865
- this.retryReconnection();
8866
- }
8867
- else {
8868
- console.info(`[Colyseus reconnection]: ${String.fromCodePoint(0x274C)} Failed to reconnect. Is your server running? Please check server logs.`); // ❌
8869
- }
8913
+ this.retryReconnection();
8870
8914
  }
8871
8915
  }, delay);
8872
8916
  }