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

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.
@@ -1464,7 +1464,6 @@ var AMTGatewayManager = class {
1464
1464
  constructor() {
1465
1465
  this.messageHandler = (event) => {
1466
1466
  const data = event.data;
1467
- console.log(`[AMT] SW message received:`, data.type);
1468
1467
  if (data.type === "UDP_PACKET") {
1469
1468
  this.handlePacket(data);
1470
1469
  } else if (data.type === "SOCKET_ERROR") {
@@ -1482,6 +1481,14 @@ var AMTGatewayManager = class {
1482
1481
  this.messageListenerRegistered = true;
1483
1482
  console.log("[AMT] Registered service worker message handler");
1484
1483
  }
1484
+ removeMessageListener() {
1485
+ if (!this.messageListenerRegistered)
1486
+ return;
1487
+ if (this.messageHandler && typeof navigator !== "undefined" && navigator.serviceWorker) {
1488
+ navigator.serviceWorker.removeEventListener("message", this.messageHandler);
1489
+ }
1490
+ this.messageListenerRegistered = false;
1491
+ }
1485
1492
  /**
1486
1493
  * Subscribe via AMT tunnel
1487
1494
  */
@@ -1526,6 +1533,8 @@ var AMTGatewayManager = class {
1526
1533
  this.subscriptions.delete(keyStr);
1527
1534
  this.pendingPackets.delete(subscription.subscriptionId);
1528
1535
  }
1536
+ if (this.subscriptions.size === 0)
1537
+ this.removeMessageListener();
1529
1538
  throw new Error(`Failed to subscribe via AMT: ${error instanceof Error ? error.message : String(error)}`);
1530
1539
  }
1531
1540
  }
@@ -1547,6 +1556,8 @@ var AMTGatewayManager = class {
1547
1556
  } finally {
1548
1557
  this.subscriptions.delete(handle);
1549
1558
  this.pendingPackets.delete(subscription.subscriptionId);
1559
+ if (this.subscriptions.size === 0)
1560
+ this.removeMessageListener();
1550
1561
  }
1551
1562
  }
1552
1563
  /**
@@ -1563,10 +1574,8 @@ var AMTGatewayManager = class {
1563
1574
  if (!subscriptionId)
1564
1575
  return;
1565
1576
  const subscription = this.subscriptions.get(subscriptionId);
1566
- if (!subscription) {
1567
- console.warn(`[AMT] Received packet for unknown subscription: ${subscriptionId}`);
1577
+ if (!subscription)
1568
1578
  return;
1569
- }
1570
1579
  if (!subscription.handshakeComplete) {
1571
1580
  const queue = this.pendingPackets.get(subscriptionId);
1572
1581
  const packetData2 = data;
@@ -1596,20 +1605,15 @@ var AMTGatewayManager = class {
1596
1605
  if (!subscriptionId)
1597
1606
  return;
1598
1607
  const subscription = this.subscriptions.get(subscriptionId);
1599
- if (!subscription) {
1600
- console.warn(`[AMT] Received error for unknown subscription: ${subscriptionId}`);
1608
+ if (!subscription)
1601
1609
  return;
1602
- }
1603
1610
  subscription.config.onError(new Error(error || "Unknown error"));
1604
1611
  }
1605
1612
  /**
1606
1613
  * Cleanup on destroy
1607
1614
  */
1608
1615
  destroy() {
1609
- if (this.messageListenerRegistered && this.messageHandler && typeof navigator !== "undefined" && navigator.serviceWorker) {
1610
- navigator.serviceWorker.removeEventListener("message", this.messageHandler);
1611
- this.messageListenerRegistered = false;
1612
- }
1616
+ this.removeMessageListener();
1613
1617
  const handles = Array.from(this.subscriptions.keys());
1614
1618
  for (const handle of handles) {
1615
1619
  this.unsubscribe(handle).catch((err) => {