@colyseus/schema 3.0.0-alpha.22 → 3.0.0-alpha.24

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.
@@ -3510,7 +3510,11 @@ class Encoder {
3510
3510
  }
3511
3511
  if (it.offset > buffer.byteLength) {
3512
3512
  const newSize = getNextPowerOf2(buffer.byteLength * 2);
3513
- console.warn("@colyseus/schema encode buffer overflow. Current buffer size: " + buffer.byteLength + ", encoding offset: " + it.offset + ", new size: " + newSize);
3513
+ console.warn(`@colyseus/schema buffer overflow. Encoded state is higher than default BUFFER_SIZE. Use the following to increase default BUFFER_SIZE:
3514
+
3515
+ import { Encoder } from "@colyseus/schema";
3516
+ Encoder.BUFFER_SIZE = ${Math.round(newSize / 1024)} * 1024; // ${Math.round(newSize / 1024)} KB
3517
+ `);
3514
3518
  //
3515
3519
  // resize buffer and re-encode (TODO: can we avoid re-encoding here?)
3516
3520
  //
@@ -4142,7 +4146,11 @@ function getDecoderStateCallbacks(decoder) {
4142
4146
  }
4143
4147
  else {
4144
4148
  // collection instance not received yet
4145
- context.onInstanceAvailable((ref, existing) => onAdd(ref, prop, callback, immediate && existing));
4149
+ let detachCallback = () => { };
4150
+ context.onInstanceAvailable((ref, existing) => {
4151
+ detachCallback = onAdd(ref, prop, callback, immediate && existing);
4152
+ });
4153
+ return () => detachCallback();
4146
4154
  }
4147
4155
  },
4148
4156
  onChange: function onChange(callback) {
@@ -4217,19 +4225,27 @@ function getDecoderStateCallbacks(decoder) {
4217
4225
  //
4218
4226
  if (context.onInstanceAvailable) {
4219
4227
  // collection instance not received yet
4220
- context.onInstanceAvailable((ref, existing) => onAdd(ref, callback, immediate && existing && !isTriggeringOnAdd));
4228
+ let detachCallback = () => { };
4229
+ context.onInstanceAvailable((ref, existing) => {
4230
+ detachCallback = onAdd(ref, callback, immediate && existing && !isTriggeringOnAdd);
4231
+ });
4232
+ return () => detachCallback();
4221
4233
  }
4222
4234
  else if (context.instance) {
4223
- onAdd(context.instance, callback, immediate && !isTriggeringOnAdd);
4235
+ return onAdd(context.instance, callback, immediate && !isTriggeringOnAdd);
4224
4236
  }
4225
4237
  },
4226
4238
  onRemove: function (callback) {
4227
4239
  if (context.onInstanceAvailable) {
4228
4240
  // collection instance not received yet
4229
- context.onInstanceAvailable((ref) => onRemove(ref, callback));
4241
+ let detachCallback = () => { };
4242
+ context.onInstanceAvailable((ref) => {
4243
+ detachCallback = onRemove(ref, callback);
4244
+ });
4245
+ return () => detachCallback();
4230
4246
  }
4231
4247
  else if (context.instance) {
4232
- onRemove(context.instance, callback);
4248
+ return onRemove(context.instance, callback);
4233
4249
  }
4234
4250
  },
4235
4251
  }, {