@emeryld/rrroutes-client 2.6.4 → 2.6.5

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.
package/dist/index.mjs CHANGED
@@ -1339,63 +1339,93 @@ var SocketClient = class {
1339
1339
  });
1340
1340
  this.logSocketConfigSnapshot("constructor");
1341
1341
  }
1342
- this.onConnect = async () => {
1342
+ this.onConnect = () => {
1343
1343
  if (!this.socket) {
1344
1344
  this.dbg({
1345
1345
  type: "connection",
1346
1346
  phase: "connect_event",
1347
1347
  err: "Socket is null"
1348
1348
  });
1349
- throw new Error("Socket is null in onConnect handler");
1349
+ return;
1350
1350
  }
1351
+ const socket = this.socket;
1351
1352
  this.dbg({
1352
1353
  type: "connection",
1353
1354
  phase: "connect_event",
1354
- id: this.socket.id,
1355
+ id: socket.id,
1355
1356
  details: {
1356
- nsp: this.getNamespace(this.socket)
1357
+ nsp: this.getNamespace(socket)
1357
1358
  }
1358
1359
  });
1359
1360
  this.logSocketConfigSnapshot("connect_event");
1360
- await this.getSysEvent("sys:connect")({
1361
- socket: this.socket,
1362
- client: this
1361
+ void Promise.resolve(
1362
+ this.getSysEvent("sys:connect")({
1363
+ socket,
1364
+ client: this
1365
+ })
1366
+ ).catch((error) => {
1367
+ this.dbg({
1368
+ type: "connection",
1369
+ phase: "connect_event",
1370
+ id: socket.id,
1371
+ err: `sys:connect handler failed: ${this.formatError(error)}`,
1372
+ details: this.getVerboseDetails({
1373
+ nsp: this.getNamespace(socket),
1374
+ rawError: error
1375
+ })
1376
+ });
1363
1377
  });
1364
1378
  };
1365
- this.onReconnect = async (attempt) => {
1379
+ this.onReconnect = (attempt) => {
1366
1380
  if (!this.socket) {
1367
1381
  this.dbg({
1368
1382
  type: "connection",
1369
1383
  phase: "reconnect_event",
1370
1384
  err: "Socket is null"
1371
1385
  });
1372
- throw new Error("Socket is null in onReconnect handler");
1386
+ return;
1373
1387
  }
1388
+ const socket = this.socket;
1374
1389
  this.dbg({
1375
1390
  type: "connection",
1376
1391
  phase: "reconnect_event",
1377
1392
  attempt,
1378
- id: this.socket.id,
1393
+ id: socket.id,
1379
1394
  details: {
1380
- nsp: this.getNamespace(this.socket)
1395
+ nsp: this.getNamespace(socket)
1381
1396
  }
1382
1397
  });
1383
1398
  this.logSocketConfigSnapshot("reconnect_event");
1384
- await this.getSysEvent("sys:reconnect")({
1385
- attempt,
1386
- socket: this.socket,
1387
- client: this
1399
+ void Promise.resolve(
1400
+ this.getSysEvent("sys:reconnect")({
1401
+ attempt,
1402
+ socket,
1403
+ client: this
1404
+ })
1405
+ ).catch((error) => {
1406
+ this.dbg({
1407
+ type: "connection",
1408
+ phase: "reconnect_event",
1409
+ attempt,
1410
+ id: socket.id,
1411
+ err: `sys:reconnect handler failed: ${this.formatError(error)}`,
1412
+ details: this.getVerboseDetails({
1413
+ nsp: this.getNamespace(socket),
1414
+ rawError: error
1415
+ })
1416
+ });
1388
1417
  });
1389
1418
  };
1390
- this.onDisconnect = async (reason) => {
1419
+ this.onDisconnect = (reason) => {
1391
1420
  if (!this.socket) {
1392
1421
  this.dbg({
1393
1422
  type: "connection",
1394
1423
  phase: "disconnect_event",
1395
1424
  err: "Socket is null"
1396
1425
  });
1397
- throw new Error("Socket is null in onDisconnect handler");
1426
+ return;
1398
1427
  }
1428
+ const socket = this.socket;
1399
1429
  this.dbg({
1400
1430
  type: "connection",
1401
1431
  phase: "disconnect_event",
@@ -1405,21 +1435,36 @@ var SocketClient = class {
1405
1435
  }
1406
1436
  });
1407
1437
  this.logSocketConfigSnapshot("disconnect_event");
1408
- await this.getSysEvent("sys:disconnect")({
1409
- reason: String(reason),
1410
- socket: this.socket,
1411
- client: this
1438
+ void Promise.resolve(
1439
+ this.getSysEvent("sys:disconnect")({
1440
+ reason: String(reason),
1441
+ socket,
1442
+ client: this
1443
+ })
1444
+ ).catch((error) => {
1445
+ this.dbg({
1446
+ type: "connection",
1447
+ phase: "disconnect_event",
1448
+ reason: String(reason),
1449
+ id: socket.id,
1450
+ err: `sys:disconnect handler failed: ${this.formatError(error)}`,
1451
+ details: this.getVerboseDetails({
1452
+ roomsTracked: this.roomCounts.size,
1453
+ rawError: error
1454
+ })
1455
+ });
1412
1456
  });
1413
1457
  };
1414
- this.onConnectError = async (err) => {
1458
+ this.onConnectError = (err) => {
1415
1459
  if (!this.socket) {
1416
1460
  this.dbg({
1417
1461
  type: "connection",
1418
1462
  phase: "connect_error_event",
1419
1463
  err: "Socket is null"
1420
1464
  });
1421
- throw new Error("Socket is null in onConnectError handler");
1465
+ return;
1422
1466
  }
1467
+ const socket = this.socket;
1423
1468
  this.dbg({
1424
1469
  type: "connection",
1425
1470
  phase: "connect_error_event",
@@ -1427,21 +1472,34 @@ var SocketClient = class {
1427
1472
  details: this.getVerboseDetails({ rawError: err })
1428
1473
  });
1429
1474
  this.logSocketConfigSnapshot("connect_error_event");
1430
- await this.getSysEvent("sys:connect_error")({
1431
- error: String(err),
1432
- socket: this.socket,
1433
- client: this
1475
+ void Promise.resolve(
1476
+ this.getSysEvent("sys:connect_error")({
1477
+ error: String(err),
1478
+ socket,
1479
+ client: this
1480
+ })
1481
+ ).catch((error) => {
1482
+ this.dbg({
1483
+ type: "connection",
1484
+ phase: "connect_error_event",
1485
+ id: socket.id,
1486
+ err: `sys:connect_error handler failed: ${this.formatError(error)}`,
1487
+ details: this.getVerboseDetails({
1488
+ rawError: error
1489
+ })
1490
+ });
1434
1491
  });
1435
1492
  };
1436
- this.onPong = async (raw) => {
1493
+ this.onPong = (raw) => {
1437
1494
  if (!this.socket) {
1438
1495
  this.dbg({
1439
1496
  type: "heartbeat",
1440
1497
  phase: "pong_recv",
1441
1498
  err: "Socket is null"
1442
1499
  });
1443
- throw new Error("Socket is null in onPong handler");
1500
+ return;
1444
1501
  }
1502
+ const socket = this.socket;
1445
1503
  const parsed = this.config.pongPayload.safeParse(raw);
1446
1504
  if (!parsed.success) {
1447
1505
  this.dbg({
@@ -1458,10 +1516,21 @@ var SocketClient = class {
1458
1516
  phase: "pong_recv",
1459
1517
  payload: validated
1460
1518
  });
1461
- await this.getSysEvent("sys:pong")({
1462
- socket: this.socket,
1463
- payload: validated,
1464
- client: this
1519
+ void Promise.resolve(
1520
+ this.getSysEvent("sys:pong")({
1521
+ socket,
1522
+ payload: validated,
1523
+ client: this
1524
+ })
1525
+ ).catch((error) => {
1526
+ this.dbg({
1527
+ type: "heartbeat",
1528
+ phase: "pong_recv",
1529
+ err: `sys:pong handler failed: ${this.formatError(error)}`,
1530
+ details: this.getVerboseDetails({
1531
+ rawError: error
1532
+ })
1533
+ });
1465
1534
  });
1466
1535
  };
1467
1536
  if (this.socket) {
@@ -1522,6 +1591,15 @@ var SocketClient = class {
1522
1591
  if (!this.debug.verbose) return void 0;
1523
1592
  return details;
1524
1593
  }
1594
+ formatError(error) {
1595
+ if (error instanceof Error) return error.message;
1596
+ if (typeof error === "string") return error;
1597
+ try {
1598
+ return JSON.stringify(error);
1599
+ } catch {
1600
+ return String(error);
1601
+ }
1602
+ }
1525
1603
  getNamespace(socket) {
1526
1604
  if (!socket) return void 0;
1527
1605
  const nsp = socket.nsp;
@@ -1535,7 +1613,13 @@ var SocketClient = class {
1535
1613
  if (!d.logger) return;
1536
1614
  if (!d[e.type]) return;
1537
1615
  if (d.only && "event" in e && !d.only.includes(e.event)) return;
1538
- d.logger(e);
1616
+ try {
1617
+ d.logger(e);
1618
+ } catch (error) {
1619
+ if (this.environment === "development" && typeof console !== "undefined" && typeof console.warn === "function") {
1620
+ console.warn("[socket] debug logger threw", error);
1621
+ }
1622
+ }
1539
1623
  }
1540
1624
  /** internal stats snapshot */
1541
1625
  stats() {
@@ -1634,8 +1718,20 @@ var SocketClient = class {
1634
1718
  payload: dataToSend
1635
1719
  });
1636
1720
  };
1637
- this.hbTimer = setInterval(tick, this.hb.intervalMs);
1638
- tick();
1721
+ const runTick = () => {
1722
+ void tick().catch((error) => {
1723
+ this.dbg({
1724
+ type: "heartbeat",
1725
+ phase: "ping_emit",
1726
+ err: `sys:ping handler failed: ${this.formatError(error)}`,
1727
+ details: this.getVerboseDetails({
1728
+ rawError: error
1729
+ })
1730
+ });
1731
+ });
1732
+ };
1733
+ this.hbTimer = setInterval(runTick, this.hb.intervalMs);
1734
+ runTick();
1639
1735
  }
1640
1736
  /**
1641
1737
  * Public: stop the heartbeat loop.
@@ -1849,7 +1945,18 @@ var SocketClient = class {
1849
1945
  metadata: meta.envelope.metadata
1850
1946
  } : void 0
1851
1947
  });
1852
- handler(data, meta);
1948
+ try {
1949
+ handler(data, meta);
1950
+ } catch (error) {
1951
+ this.dbg({
1952
+ type: "receive",
1953
+ event,
1954
+ err: `handler_failed: ${this.formatError(error)}`,
1955
+ details: this.getVerboseDetails({
1956
+ rawError: error
1957
+ })
1958
+ });
1959
+ }
1853
1960
  };
1854
1961
  const wrappedDispatcher = (envelopeOrRaw) => {
1855
1962
  if (typeof envelopeOrRaw === "object" && envelopeOrRaw !== null && "eventName" in envelopeOrRaw && "sentAt" in envelopeOrRaw && "sentTo" in envelopeOrRaw && "data" in envelopeOrRaw) {
@@ -1860,7 +1967,18 @@ var SocketClient = class {
1860
1967
  event,
1861
1968
  envelope: void 0
1862
1969
  });
1863
- handler(envelopeOrRaw, void 0);
1970
+ try {
1971
+ handler(envelopeOrRaw, void 0);
1972
+ } catch (error) {
1973
+ this.dbg({
1974
+ type: "receive",
1975
+ event,
1976
+ err: `handler_failed: ${this.formatError(error)}`,
1977
+ details: this.getVerboseDetails({
1978
+ rawError: error
1979
+ })
1980
+ });
1981
+ }
1864
1982
  }
1865
1983
  };
1866
1984
  const errorWrapped = (e) => {