@phpsandbox/sdk 0.0.19 → 0.0.20

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.
@@ -3002,6 +3002,7 @@ var PHPSandbox = (() => {
3002
3002
  this.closed = false;
3003
3003
  this.disposables = new NamedDisposable();
3004
3004
  this.connectPromise = null;
3005
+ this.pingIntervalStarted = false;
3005
3006
  // Connection health monitoring
3006
3007
  this.connectionStats = {
3007
3008
  connectTime: 0,
@@ -3080,7 +3081,25 @@ var PHPSandbox = (() => {
3080
3081
  throw new Error("Unexpected message type: " + typeof ev.data);
3081
3082
  }
3082
3083
  ev.data.arrayBuffer().then((buffer) => {
3083
- this.handleRawMessage(decode(buffer));
3084
+ if (buffer.byteLength === 0) {
3085
+ this.log("warn", "Ignoring empty WebSocket frame");
3086
+ return;
3087
+ }
3088
+ try {
3089
+ this.handleRawMessage(decode(buffer));
3090
+ } catch (error) {
3091
+ this.connectionStats.totalErrors++;
3092
+ this.log("error", "Failed to decode WebSocket frame", {
3093
+ error: error instanceof Error ? error.message : String(error),
3094
+ byteLength: buffer.byteLength
3095
+ });
3096
+ this.eventEmitter.emit("transport.error", {
3097
+ type: "message_decode_error",
3098
+ error,
3099
+ rawMessage: buffer,
3100
+ timestamp: Date.now()
3101
+ });
3102
+ }
3084
3103
  });
3085
3104
  };
3086
3105
  this.rws.addEventListener("message", onMessage);
@@ -3725,6 +3744,10 @@ var PHPSandbox = (() => {
3725
3744
  return this.connectPromise;
3726
3745
  };
3727
3746
  startPeriodicPing_fn = function() {
3747
+ if (this.pingIntervalStarted || this.closed) {
3748
+ return;
3749
+ }
3750
+ this.pingIntervalStarted = true;
3728
3751
  this.disposables.add("pingInterval", () => {
3729
3752
  const interval = setInterval(async () => {
3730
3753
  try {
@@ -3748,6 +3771,7 @@ var PHPSandbox = (() => {
3748
3771
  return {
3749
3772
  dispose: () => {
3750
3773
  clearInterval(interval);
3774
+ this.pingIntervalStarted = false;
3751
3775
  }
3752
3776
  };
3753
3777
  });