@poolse/react 2.27.0 → 2.28.0

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 CHANGED
@@ -1667,6 +1667,55 @@ function useLiveCall(conversationId) {
1667
1667
  }, [chat, conversationId, apply, refresh]);
1668
1668
  return { call, participantIds, refresh };
1669
1669
  }
1670
+ function useRoom(conversationId, opts) {
1671
+ const poolse = usePoolse();
1672
+ const { call: live, participantIds } = useLiveCall(conversationId);
1673
+ const media = useCallRoom(conversationId, { livekit: opts.livekit, aloneGraceMs: 0 });
1674
+ const session = react.useRef(null);
1675
+ const [joining, setJoining] = react.useState(false);
1676
+ const [error, setError] = react.useState(null);
1677
+ react.useEffect(() => {
1678
+ session.current = null;
1679
+ setError(null);
1680
+ }, [conversationId]);
1681
+ const join = react.useCallback(
1682
+ async (kind = "audio", joinOpts = {}) => {
1683
+ if (!conversationId) return;
1684
+ setJoining(true);
1685
+ setError(null);
1686
+ try {
1687
+ session.current = joinOpts.ring ? await poolse.rooms.ring(conversationId, kind) : await poolse.rooms.start(conversationId, kind);
1688
+ const connected = await media.join();
1689
+ if (!connected) throw new Error("Rooms need the SFU, which this deployment does not have.");
1690
+ if (kind === "video") await media.setCameraEnabled(true);
1691
+ } catch (err) {
1692
+ setError(err instanceof Error ? err : new Error(String(err)));
1693
+ media.leave();
1694
+ } finally {
1695
+ setJoining(false);
1696
+ }
1697
+ },
1698
+ [poolse, conversationId, media]
1699
+ );
1700
+ const leave = react.useCallback(() => {
1701
+ media.leave();
1702
+ const s = session.current;
1703
+ session.current = null;
1704
+ if (s) void poolse.rooms.leave(s).catch(() => {
1705
+ });
1706
+ }, [poolse, media]);
1707
+ const joined = media.status === "connected" || media.status === "connecting" || joining;
1708
+ return {
1709
+ live,
1710
+ presentIds: participantIds,
1711
+ joined,
1712
+ joining,
1713
+ join,
1714
+ leave,
1715
+ media,
1716
+ error: error ?? media.error
1717
+ };
1718
+ }
1670
1719
  function useReadReceipts() {
1671
1720
  const chat = usePoolse();
1672
1721
  const { me } = useMe();
@@ -1771,6 +1820,7 @@ exports.usePresence = usePresence;
1771
1820
  exports.useReactions = useReactions;
1772
1821
  exports.useReadReceipts = useReadReceipts;
1773
1822
  exports.useRealtimeStatus = useRealtimeStatus;
1823
+ exports.useRoom = useRoom;
1774
1824
  exports.useThread = useThread;
1775
1825
  exports.useTyping = useTyping;
1776
1826
  exports.useUser = useUser;