@emeryld/rrroutes-client 2.7.10 → 2.7.12
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.cjs +153 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +163 -24
- package/dist/index.mjs.map +1 -1
- package/dist/sockets/socket.client.context.client.d.ts +1 -1
- package/dist/sockets/socket.client.context.connection.d.ts +28 -0
- package/dist/sockets/socket.client.context.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1578,10 +1578,10 @@ var React3 = __toESM(require("react"), 1);
|
|
|
1578
1578
|
|
|
1579
1579
|
// src/sockets/socket.client.context.client.ts
|
|
1580
1580
|
var React = __toESM(require("react"), 1);
|
|
1581
|
-
var SocketCtx = React.createContext(
|
|
1581
|
+
var SocketCtx = React.createContext(void 0);
|
|
1582
1582
|
function useSocketClient() {
|
|
1583
1583
|
const ctx = React.useContext(SocketCtx);
|
|
1584
|
-
if (!ctx) {
|
|
1584
|
+
if (typeof ctx === "undefined" || !ctx) {
|
|
1585
1585
|
return null;
|
|
1586
1586
|
}
|
|
1587
1587
|
return ctx;
|
|
@@ -1596,7 +1596,8 @@ function useSocketConnection(args) {
|
|
|
1596
1596
|
onMessage,
|
|
1597
1597
|
onCleanup,
|
|
1598
1598
|
autoJoin = true,
|
|
1599
|
-
autoLeave = true
|
|
1599
|
+
autoLeave = true,
|
|
1600
|
+
debug
|
|
1600
1601
|
} = args;
|
|
1601
1602
|
const client = useSocketClient();
|
|
1602
1603
|
const normalizedRooms = React2.useMemo(
|
|
@@ -1607,6 +1608,57 @@ function useSocketConnection(args) {
|
|
|
1607
1608
|
() => normalizedRooms.join(""),
|
|
1608
1609
|
[normalizedRooms]
|
|
1609
1610
|
);
|
|
1611
|
+
const joinMetaKey = React2.useMemo(
|
|
1612
|
+
() => JSON.stringify(args.joinMeta ?? null),
|
|
1613
|
+
[args.joinMeta]
|
|
1614
|
+
);
|
|
1615
|
+
const leaveMetaKey = React2.useMemo(
|
|
1616
|
+
() => JSON.stringify(args.leaveMeta ?? null),
|
|
1617
|
+
[args.leaveMeta]
|
|
1618
|
+
);
|
|
1619
|
+
const missingClientWarnedRef = React2.useRef(false);
|
|
1620
|
+
const onMessageRef = React2.useRef(onMessage);
|
|
1621
|
+
const onCleanupRef = React2.useRef(onCleanup);
|
|
1622
|
+
const joinMetaRef = React2.useRef(args.joinMeta);
|
|
1623
|
+
const leaveMetaRef = React2.useRef(args.leaveMeta);
|
|
1624
|
+
const debugRef = React2.useRef(debug);
|
|
1625
|
+
React2.useEffect(() => {
|
|
1626
|
+
onMessageRef.current = onMessage;
|
|
1627
|
+
}, [onMessage]);
|
|
1628
|
+
React2.useEffect(() => {
|
|
1629
|
+
onCleanupRef.current = onCleanup;
|
|
1630
|
+
}, [onCleanup]);
|
|
1631
|
+
React2.useEffect(() => {
|
|
1632
|
+
joinMetaRef.current = args.joinMeta;
|
|
1633
|
+
}, [args.joinMeta]);
|
|
1634
|
+
React2.useEffect(() => {
|
|
1635
|
+
leaveMetaRef.current = args.leaveMeta;
|
|
1636
|
+
}, [args.leaveMeta]);
|
|
1637
|
+
React2.useEffect(() => {
|
|
1638
|
+
debugRef.current = debug;
|
|
1639
|
+
}, [debug]);
|
|
1640
|
+
const emitDebug = React2.useCallback(
|
|
1641
|
+
(event2) => {
|
|
1642
|
+
const dbg3 = debugRef.current;
|
|
1643
|
+
if (!dbg3?.enabled) return;
|
|
1644
|
+
if (dbg3[event2.type] === false) return;
|
|
1645
|
+
const logger = dbg3.logger;
|
|
1646
|
+
if (logger) {
|
|
1647
|
+
try {
|
|
1648
|
+
logger(event2);
|
|
1649
|
+
} catch (error) {
|
|
1650
|
+
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
1651
|
+
console.warn("[socket] useSocketConnection debug logger threw", error);
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
return;
|
|
1655
|
+
}
|
|
1656
|
+
if (typeof console !== "undefined" && typeof console.log === "function") {
|
|
1657
|
+
console.log("[socket] useSocketConnection", event2);
|
|
1658
|
+
}
|
|
1659
|
+
},
|
|
1660
|
+
[]
|
|
1661
|
+
);
|
|
1610
1662
|
const reportAsyncError = React2.useCallback(
|
|
1611
1663
|
(phase, error) => {
|
|
1612
1664
|
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
@@ -1616,28 +1668,115 @@ function useSocketConnection(args) {
|
|
|
1616
1668
|
[]
|
|
1617
1669
|
);
|
|
1618
1670
|
React2.useEffect(() => {
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1671
|
+
emitDebug({
|
|
1672
|
+
type: "lifecycle",
|
|
1673
|
+
phase: "effect_start",
|
|
1674
|
+
event,
|
|
1675
|
+
rooms: normalizedRooms,
|
|
1676
|
+
autoJoin,
|
|
1677
|
+
autoLeave
|
|
1678
|
+
});
|
|
1679
|
+
if (!client) {
|
|
1680
|
+
emitDebug({
|
|
1681
|
+
type: "lifecycle",
|
|
1682
|
+
phase: "client_missing",
|
|
1683
|
+
event,
|
|
1684
|
+
rooms: normalizedRooms,
|
|
1685
|
+
autoJoin,
|
|
1686
|
+
autoLeave
|
|
1687
|
+
});
|
|
1688
|
+
if (debugRef.current?.throwIfClientMissing) {
|
|
1689
|
+
throw new Error(
|
|
1690
|
+
`useSocketConnection("${event}") missing SocketClient. Wrap with <SocketProvider>.`
|
|
1691
|
+
);
|
|
1692
|
+
}
|
|
1693
|
+
if (debugRef.current?.warnIfClientMissing && !missingClientWarnedRef.current && typeof console !== "undefined" && typeof console.warn === "function") {
|
|
1694
|
+
missingClientWarnedRef.current = true;
|
|
1695
|
+
console.warn(
|
|
1696
|
+
`[socket] useSocketConnection("${event}") skipped because SocketClient is null.`
|
|
1697
|
+
);
|
|
1698
|
+
}
|
|
1699
|
+
return;
|
|
1700
|
+
}
|
|
1701
|
+
missingClientWarnedRef.current = false;
|
|
1702
|
+
emitDebug({ type: "subscription", phase: "register", event });
|
|
1703
|
+
if (autoJoin && normalizedRooms.length > 0) {
|
|
1704
|
+
emitDebug({
|
|
1705
|
+
type: "room",
|
|
1706
|
+
phase: "join_attempt",
|
|
1707
|
+
rooms: normalizedRooms
|
|
1708
|
+
});
|
|
1709
|
+
void client.joinRooms(normalizedRooms, joinMetaRef.current).then(() => {
|
|
1710
|
+
emitDebug({ type: "room", phase: "join_ok", rooms: normalizedRooms });
|
|
1711
|
+
}).catch((error) => {
|
|
1712
|
+
emitDebug({
|
|
1713
|
+
type: "room",
|
|
1714
|
+
phase: "join_error",
|
|
1715
|
+
rooms: normalizedRooms,
|
|
1716
|
+
err: String(error)
|
|
1717
|
+
});
|
|
1718
|
+
reportAsyncError("joinRooms", error);
|
|
1719
|
+
});
|
|
1720
|
+
} else {
|
|
1721
|
+
emitDebug({
|
|
1722
|
+
type: "room",
|
|
1723
|
+
phase: "join_skip",
|
|
1724
|
+
rooms: normalizedRooms,
|
|
1725
|
+
reason: autoJoin ? "no_rooms" : "auto_disabled"
|
|
1726
|
+
});
|
|
1727
|
+
}
|
|
1622
1728
|
const unsubscribe = client.on(event, (payload, meta) => {
|
|
1623
|
-
|
|
1729
|
+
emitDebug({ type: "subscription", phase: "message", event });
|
|
1730
|
+
onMessageRef.current(payload, meta);
|
|
1624
1731
|
});
|
|
1625
1732
|
return () => {
|
|
1733
|
+
emitDebug({ type: "subscription", phase: "unregister", event });
|
|
1626
1734
|
unsubscribe();
|
|
1627
|
-
if (autoLeave && normalizedRooms.length > 0)
|
|
1628
|
-
|
|
1629
|
-
|
|
1735
|
+
if (autoLeave && normalizedRooms.length > 0) {
|
|
1736
|
+
emitDebug({
|
|
1737
|
+
type: "room",
|
|
1738
|
+
phase: "leave_attempt",
|
|
1739
|
+
rooms: normalizedRooms
|
|
1740
|
+
});
|
|
1741
|
+
void client.leaveRooms(normalizedRooms, leaveMetaRef.current).then(() => {
|
|
1742
|
+
emitDebug({ type: "room", phase: "leave_ok", rooms: normalizedRooms });
|
|
1743
|
+
}).catch((error) => {
|
|
1744
|
+
emitDebug({
|
|
1745
|
+
type: "room",
|
|
1746
|
+
phase: "leave_error",
|
|
1747
|
+
rooms: normalizedRooms,
|
|
1748
|
+
err: String(error)
|
|
1749
|
+
});
|
|
1750
|
+
reportAsyncError("leaveRooms", error);
|
|
1751
|
+
});
|
|
1752
|
+
} else {
|
|
1753
|
+
emitDebug({
|
|
1754
|
+
type: "room",
|
|
1755
|
+
phase: "leave_skip",
|
|
1756
|
+
rooms: normalizedRooms,
|
|
1757
|
+
reason: autoLeave ? "no_rooms" : "auto_disabled"
|
|
1758
|
+
});
|
|
1759
|
+
}
|
|
1760
|
+
if (onCleanupRef.current) onCleanupRef.current();
|
|
1761
|
+
emitDebug({
|
|
1762
|
+
type: "lifecycle",
|
|
1763
|
+
phase: "effect_cleanup",
|
|
1764
|
+
event,
|
|
1765
|
+
rooms: normalizedRooms,
|
|
1766
|
+
autoJoin,
|
|
1767
|
+
autoLeave
|
|
1768
|
+
});
|
|
1630
1769
|
};
|
|
1631
1770
|
}, [
|
|
1632
1771
|
client,
|
|
1633
1772
|
event,
|
|
1634
|
-
onMessage,
|
|
1635
|
-
onCleanup,
|
|
1636
1773
|
autoJoin,
|
|
1637
1774
|
autoLeave,
|
|
1775
|
+
emitDebug,
|
|
1638
1776
|
reportAsyncError,
|
|
1639
|
-
|
|
1640
|
-
|
|
1777
|
+
normalizedRoomsKey,
|
|
1778
|
+
joinMetaKey,
|
|
1779
|
+
leaveMetaKey
|
|
1641
1780
|
]);
|
|
1642
1781
|
}
|
|
1643
1782
|
|