@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.
@@ -1276,7 +1276,6 @@ var AMTGatewayManager = class {
1276
1276
  constructor() {
1277
1277
  this.messageHandler = (event) => {
1278
1278
  const data = event.data;
1279
- console.log(`[AMT] SW message received:`, data.type);
1280
1279
  if (data.type === "UDP_PACKET") {
1281
1280
  this.handlePacket(data);
1282
1281
  } else if (data.type === "SOCKET_ERROR") {
@@ -1294,6 +1293,14 @@ var AMTGatewayManager = class {
1294
1293
  this.messageListenerRegistered = true;
1295
1294
  console.log("[AMT] Registered service worker message handler");
1296
1295
  }
1296
+ removeMessageListener() {
1297
+ if (!this.messageListenerRegistered)
1298
+ return;
1299
+ if (this.messageHandler && typeof navigator !== "undefined" && navigator.serviceWorker) {
1300
+ navigator.serviceWorker.removeEventListener("message", this.messageHandler);
1301
+ }
1302
+ this.messageListenerRegistered = false;
1303
+ }
1297
1304
  /**
1298
1305
  * Subscribe via AMT tunnel
1299
1306
  */
@@ -1338,6 +1345,8 @@ var AMTGatewayManager = class {
1338
1345
  this.subscriptions.delete(keyStr);
1339
1346
  this.pendingPackets.delete(subscription.subscriptionId);
1340
1347
  }
1348
+ if (this.subscriptions.size === 0)
1349
+ this.removeMessageListener();
1341
1350
  throw new Error(`Failed to subscribe via AMT: ${error instanceof Error ? error.message : String(error)}`);
1342
1351
  }
1343
1352
  }
@@ -1359,6 +1368,8 @@ var AMTGatewayManager = class {
1359
1368
  } finally {
1360
1369
  this.subscriptions.delete(handle);
1361
1370
  this.pendingPackets.delete(subscription.subscriptionId);
1371
+ if (this.subscriptions.size === 0)
1372
+ this.removeMessageListener();
1362
1373
  }
1363
1374
  }
1364
1375
  /**
@@ -1375,10 +1386,8 @@ var AMTGatewayManager = class {
1375
1386
  if (!subscriptionId)
1376
1387
  return;
1377
1388
  const subscription = this.subscriptions.get(subscriptionId);
1378
- if (!subscription) {
1379
- console.warn(`[AMT] Received packet for unknown subscription: ${subscriptionId}`);
1389
+ if (!subscription)
1380
1390
  return;
1381
- }
1382
1391
  if (!subscription.handshakeComplete) {
1383
1392
  const queue = this.pendingPackets.get(subscriptionId);
1384
1393
  const packetData2 = data;
@@ -1408,20 +1417,15 @@ var AMTGatewayManager = class {
1408
1417
  if (!subscriptionId)
1409
1418
  return;
1410
1419
  const subscription = this.subscriptions.get(subscriptionId);
1411
- if (!subscription) {
1412
- console.warn(`[AMT] Received error for unknown subscription: ${subscriptionId}`);
1420
+ if (!subscription)
1413
1421
  return;
1414
- }
1415
1422
  subscription.config.onError(new Error(error || "Unknown error"));
1416
1423
  }
1417
1424
  /**
1418
1425
  * Cleanup on destroy
1419
1426
  */
1420
1427
  destroy() {
1421
- if (this.messageListenerRegistered && this.messageHandler && typeof navigator !== "undefined" && navigator.serviceWorker) {
1422
- navigator.serviceWorker.removeEventListener("message", this.messageHandler);
1423
- this.messageListenerRegistered = false;
1424
- }
1428
+ this.removeMessageListener();
1425
1429
  const handles = Array.from(this.subscriptions.keys());
1426
1430
  for (const handle of handles) {
1427
1431
  this.unsubscribe(handle).catch((err) => {