@blockcast/mmt-container 2.2.0-main.bdefba2a99c2 → 2.2.0-main.c3a95413582c

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.
@@ -8754,6 +8754,7 @@ var AMTGatewayManager = class {
8754
8754
  constructor() {
8755
8755
  this.messageHandler = (event) => {
8756
8756
  const data = event.data;
8757
+ console.log(`[AMT] SW message received:`, data.type);
8757
8758
  if (data.type === "UDP_PACKET") {
8758
8759
  this.handlePacket(data);
8759
8760
  } else if (data.type === "SOCKET_ERROR") {
@@ -8771,14 +8772,6 @@ var AMTGatewayManager = class {
8771
8772
  this.messageListenerRegistered = true;
8772
8773
  console.log("[AMT] Registered service worker message handler");
8773
8774
  }
8774
- removeMessageListener() {
8775
- if (!this.messageListenerRegistered)
8776
- return;
8777
- if (this.messageHandler && typeof navigator !== "undefined" && navigator.serviceWorker) {
8778
- navigator.serviceWorker.removeEventListener("message", this.messageHandler);
8779
- }
8780
- this.messageListenerRegistered = false;
8781
- }
8782
8775
  /**
8783
8776
  * Subscribe via AMT tunnel
8784
8777
  */
@@ -8823,8 +8816,6 @@ var AMTGatewayManager = class {
8823
8816
  this.subscriptions.delete(keyStr);
8824
8817
  this.pendingPackets.delete(subscription.subscriptionId);
8825
8818
  }
8826
- if (this.subscriptions.size === 0)
8827
- this.removeMessageListener();
8828
8819
  throw new Error(`Failed to subscribe via AMT: ${error instanceof Error ? error.message : String(error)}`);
8829
8820
  }
8830
8821
  }
@@ -8846,8 +8837,6 @@ var AMTGatewayManager = class {
8846
8837
  } finally {
8847
8838
  this.subscriptions.delete(handle);
8848
8839
  this.pendingPackets.delete(subscription.subscriptionId);
8849
- if (this.subscriptions.size === 0)
8850
- this.removeMessageListener();
8851
8840
  }
8852
8841
  }
8853
8842
  /**
@@ -8864,8 +8853,10 @@ var AMTGatewayManager = class {
8864
8853
  if (!subscriptionId)
8865
8854
  return;
8866
8855
  const subscription = this.subscriptions.get(subscriptionId);
8867
- if (!subscription)
8856
+ if (!subscription) {
8857
+ console.warn(`[AMT] Received packet for unknown subscription: ${subscriptionId}`);
8868
8858
  return;
8859
+ }
8869
8860
  if (!subscription.handshakeComplete) {
8870
8861
  const queue = this.pendingPackets.get(subscriptionId);
8871
8862
  const packetData2 = data;
@@ -8895,15 +8886,20 @@ var AMTGatewayManager = class {
8895
8886
  if (!subscriptionId)
8896
8887
  return;
8897
8888
  const subscription = this.subscriptions.get(subscriptionId);
8898
- if (!subscription)
8889
+ if (!subscription) {
8890
+ console.warn(`[AMT] Received error for unknown subscription: ${subscriptionId}`);
8899
8891
  return;
8892
+ }
8900
8893
  subscription.config.onError(new Error(error || "Unknown error"));
8901
8894
  }
8902
8895
  /**
8903
8896
  * Cleanup on destroy
8904
8897
  */
8905
8898
  destroy() {
8906
- this.removeMessageListener();
8899
+ if (this.messageListenerRegistered && this.messageHandler && typeof navigator !== "undefined" && navigator.serviceWorker) {
8900
+ navigator.serviceWorker.removeEventListener("message", this.messageHandler);
8901
+ this.messageListenerRegistered = false;
8902
+ }
8907
8903
  const handles = Array.from(this.subscriptions.keys());
8908
8904
  for (const handle of handles) {
8909
8905
  this.unsubscribe(handle).catch((err) => {