@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.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { PoolseConfig, Poolse, Me, Uuid, Conversation, ConversationCreateRequest, Membership, MemberRole, Message, MessageCreateRequest, RealtimeStatus, Attachment, AttachmentUploadInput, PoolseUserProfile, CallRoomStatus, CallParticipant, CameraFacing, CallDeviceKind, CallDevice, LiveKitModule, VoiceStatus, VoiceParticipant, VoiceRoomOptions, IncomingCall, OutgoingCall, CallMedia, LiveCall } from '@poolse/sdk';
3
- export { ApiError, Attachment, AttachmentStatus, AttachmentUploadInput, AttachmentUploadRequest, AttachmentUploadResponse, AuthError, CallEndReason, CallLog, CallLogDisplay, CallLogEntry, CallLogMedia, CallMissedEntry, CallParticipantStatus, Conversation, ConversationCreateRequest, DeviceKind, LiveCall, LiveCallMember, Me, MemberRole, Membership, Message, MessageCreateRequest, MessageType, NetworkError, PoolseConfig, PoolseError, PoolseUserProfile, RateLimitedError, ReadReceiptsState, RealtimeStatus, Uuid, callLogDisplayFor, describeCallLog, formatCallDuration, formatCallLogPreview, isCallLogMessage, isMessageVisibleTo, parseCallLog, parseCallLogBody } from '@poolse/sdk';
3
+ export { ApiError, Attachment, AttachmentStatus, AttachmentUploadInput, AttachmentUploadRequest, AttachmentUploadResponse, AuthError, CallEndReason, CallLog, CallLogDisplay, CallLogEntry, CallLogMedia, CallMissedEntry, CallParticipantStatus, Conversation, ConversationCreateRequest, DeviceKind, LiveCall, LiveCallMember, Me, MemberRole, Membership, Message, MessageCreateRequest, MessageType, NetworkError, PoolseConfig, PoolseError, PoolseUserProfile, RateLimitedError, ReadReceiptsState, RealtimeStatus, RoomSession, Uuid, callLogDisplayFor, describeCallLog, formatCallDuration, formatCallLogPreview, isCallLogMessage, isMessageVisibleTo, parseCallLog, parseCallLogBody } from '@poolse/sdk';
4
4
  import { ReactNode } from 'react';
5
5
 
6
6
  interface PoolseProviderProps {
@@ -783,6 +783,51 @@ interface UseLiveCall {
783
783
  */
784
784
  declare function useLiveCall(conversationId: string | null): UseLiveCall;
785
785
 
786
+ interface UseRoomOptions {
787
+ /** `livekit-client`, imported by your app: `import * as livekit from 'livekit-client'`. */
788
+ livekit: LiveKitModule;
789
+ }
790
+ interface UseRoom {
791
+ /**
792
+ * The room (or call) running on the conversation right now, whether
793
+ * or not this user is in it — what a "Join" button reads.
794
+ */
795
+ live: ReturnType<typeof useLiveCall>['call'];
796
+ /** User ids in the room at this moment. */
797
+ presentIds: string[];
798
+ /** This user is in (or connecting to) the room. */
799
+ joined: boolean;
800
+ /** Starting or joining is in flight. */
801
+ joining: boolean;
802
+ /**
803
+ * Drop in: starts the conversation's room if none is live, or joins
804
+ * the one that is (a ringing call included). Nobody's phone rings.
805
+ * `video` turns the camera on as you arrive. `{ ring: true }` rings
806
+ * the other members' phones as well — an opt-in for apps where web
807
+ * calls people (a support desk); rooms never ring otherwise.
808
+ */
809
+ join: (media?: 'audio' | 'video', opts?: {
810
+ ring?: boolean;
811
+ }) => Promise<void>;
812
+ /** Leave. The room carries on for whoever is still in it. */
813
+ leave: () => void;
814
+ /** The media side: participants, mic/camera, devices (see `useCallRoom`). */
815
+ media: UseCallRoom;
816
+ error: Error | null;
817
+ }
818
+ /**
819
+ * A conversation's room — Meet-style: anyone in the conversation drops
820
+ * in for voice or video while the chat carries on, and nothing rings.
821
+ *
822
+ * const room = useRoom(conversationId, { livekit });
823
+ * room.live ? <button onClick={() => room.join()}>Join</button>
824
+ * : <button onClick={() => room.join('video')}>Start a video room</button>;
825
+ *
826
+ * The room ends on its own once it has been empty for a short while,
827
+ * and leaves one line in the conversation's history.
828
+ */
829
+ declare function useRoom(conversationId: string | null, opts: UseRoomOptions): UseRoom;
830
+
786
831
  interface UseReadReceipts {
787
832
  /**
788
833
  * Whether this user sees other people's read state. False → show no
@@ -822,4 +867,4 @@ declare function canEditOwnMessage(args: {
822
867
  now?: number;
823
868
  }): boolean;
824
869
 
825
- export { type CallPhase, EDIT_WINDOW_MS, type GroupPosition, PoolseProvider, type PoolseProviderProps, type ReactionMap, type UploadItem, type UploadItemStatus, type UseCallRoom, type UseCallRoomOptions, type UseCalls, type UseLiveCall, type UseReadReceipts, type UseUserState, type UseVoiceRoom, canEditOwnMessage, computeGroupPosition, formatDayLabel, receiptsOf, sameDay, sameGroup, useAttachmentUpload, useAttachmentUrl, useCallRoom, useCalls, useConversation, useConversations, useLiveCall, useMe, useMembers, useMessages, usePoolse, usePresence, useReactions, useReadReceipts, useRealtimeStatus, useThread, useTyping, useUser, useVoiceRoom };
870
+ export { type CallPhase, EDIT_WINDOW_MS, type GroupPosition, PoolseProvider, type PoolseProviderProps, type ReactionMap, type UploadItem, type UploadItemStatus, type UseCallRoom, type UseCallRoomOptions, type UseCalls, type UseLiveCall, type UseReadReceipts, type UseRoom, type UseRoomOptions, type UseUserState, type UseVoiceRoom, canEditOwnMessage, computeGroupPosition, formatDayLabel, receiptsOf, sameDay, sameGroup, useAttachmentUpload, useAttachmentUrl, useCallRoom, useCalls, useConversation, useConversations, useLiveCall, useMe, useMembers, useMessages, usePoolse, usePresence, useReactions, useReadReceipts, useRealtimeStatus, useRoom, useThread, useTyping, useUser, useVoiceRoom };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { PoolseConfig, Poolse, Me, Uuid, Conversation, ConversationCreateRequest, Membership, MemberRole, Message, MessageCreateRequest, RealtimeStatus, Attachment, AttachmentUploadInput, PoolseUserProfile, CallRoomStatus, CallParticipant, CameraFacing, CallDeviceKind, CallDevice, LiveKitModule, VoiceStatus, VoiceParticipant, VoiceRoomOptions, IncomingCall, OutgoingCall, CallMedia, LiveCall } from '@poolse/sdk';
3
- export { ApiError, Attachment, AttachmentStatus, AttachmentUploadInput, AttachmentUploadRequest, AttachmentUploadResponse, AuthError, CallEndReason, CallLog, CallLogDisplay, CallLogEntry, CallLogMedia, CallMissedEntry, CallParticipantStatus, Conversation, ConversationCreateRequest, DeviceKind, LiveCall, LiveCallMember, Me, MemberRole, Membership, Message, MessageCreateRequest, MessageType, NetworkError, PoolseConfig, PoolseError, PoolseUserProfile, RateLimitedError, ReadReceiptsState, RealtimeStatus, Uuid, callLogDisplayFor, describeCallLog, formatCallDuration, formatCallLogPreview, isCallLogMessage, isMessageVisibleTo, parseCallLog, parseCallLogBody } from '@poolse/sdk';
3
+ export { ApiError, Attachment, AttachmentStatus, AttachmentUploadInput, AttachmentUploadRequest, AttachmentUploadResponse, AuthError, CallEndReason, CallLog, CallLogDisplay, CallLogEntry, CallLogMedia, CallMissedEntry, CallParticipantStatus, Conversation, ConversationCreateRequest, DeviceKind, LiveCall, LiveCallMember, Me, MemberRole, Membership, Message, MessageCreateRequest, MessageType, NetworkError, PoolseConfig, PoolseError, PoolseUserProfile, RateLimitedError, ReadReceiptsState, RealtimeStatus, RoomSession, Uuid, callLogDisplayFor, describeCallLog, formatCallDuration, formatCallLogPreview, isCallLogMessage, isMessageVisibleTo, parseCallLog, parseCallLogBody } from '@poolse/sdk';
4
4
  import { ReactNode } from 'react';
5
5
 
6
6
  interface PoolseProviderProps {
@@ -783,6 +783,51 @@ interface UseLiveCall {
783
783
  */
784
784
  declare function useLiveCall(conversationId: string | null): UseLiveCall;
785
785
 
786
+ interface UseRoomOptions {
787
+ /** `livekit-client`, imported by your app: `import * as livekit from 'livekit-client'`. */
788
+ livekit: LiveKitModule;
789
+ }
790
+ interface UseRoom {
791
+ /**
792
+ * The room (or call) running on the conversation right now, whether
793
+ * or not this user is in it — what a "Join" button reads.
794
+ */
795
+ live: ReturnType<typeof useLiveCall>['call'];
796
+ /** User ids in the room at this moment. */
797
+ presentIds: string[];
798
+ /** This user is in (or connecting to) the room. */
799
+ joined: boolean;
800
+ /** Starting or joining is in flight. */
801
+ joining: boolean;
802
+ /**
803
+ * Drop in: starts the conversation's room if none is live, or joins
804
+ * the one that is (a ringing call included). Nobody's phone rings.
805
+ * `video` turns the camera on as you arrive. `{ ring: true }` rings
806
+ * the other members' phones as well — an opt-in for apps where web
807
+ * calls people (a support desk); rooms never ring otherwise.
808
+ */
809
+ join: (media?: 'audio' | 'video', opts?: {
810
+ ring?: boolean;
811
+ }) => Promise<void>;
812
+ /** Leave. The room carries on for whoever is still in it. */
813
+ leave: () => void;
814
+ /** The media side: participants, mic/camera, devices (see `useCallRoom`). */
815
+ media: UseCallRoom;
816
+ error: Error | null;
817
+ }
818
+ /**
819
+ * A conversation's room — Meet-style: anyone in the conversation drops
820
+ * in for voice or video while the chat carries on, and nothing rings.
821
+ *
822
+ * const room = useRoom(conversationId, { livekit });
823
+ * room.live ? <button onClick={() => room.join()}>Join</button>
824
+ * : <button onClick={() => room.join('video')}>Start a video room</button>;
825
+ *
826
+ * The room ends on its own once it has been empty for a short while,
827
+ * and leaves one line in the conversation's history.
828
+ */
829
+ declare function useRoom(conversationId: string | null, opts: UseRoomOptions): UseRoom;
830
+
786
831
  interface UseReadReceipts {
787
832
  /**
788
833
  * Whether this user sees other people's read state. False → show no
@@ -822,4 +867,4 @@ declare function canEditOwnMessage(args: {
822
867
  now?: number;
823
868
  }): boolean;
824
869
 
825
- export { type CallPhase, EDIT_WINDOW_MS, type GroupPosition, PoolseProvider, type PoolseProviderProps, type ReactionMap, type UploadItem, type UploadItemStatus, type UseCallRoom, type UseCallRoomOptions, type UseCalls, type UseLiveCall, type UseReadReceipts, type UseUserState, type UseVoiceRoom, canEditOwnMessage, computeGroupPosition, formatDayLabel, receiptsOf, sameDay, sameGroup, useAttachmentUpload, useAttachmentUrl, useCallRoom, useCalls, useConversation, useConversations, useLiveCall, useMe, useMembers, useMessages, usePoolse, usePresence, useReactions, useReadReceipts, useRealtimeStatus, useThread, useTyping, useUser, useVoiceRoom };
870
+ export { type CallPhase, EDIT_WINDOW_MS, type GroupPosition, PoolseProvider, type PoolseProviderProps, type ReactionMap, type UploadItem, type UploadItemStatus, type UseCallRoom, type UseCallRoomOptions, type UseCalls, type UseLiveCall, type UseReadReceipts, type UseRoom, type UseRoomOptions, type UseUserState, type UseVoiceRoom, canEditOwnMessage, computeGroupPosition, formatDayLabel, receiptsOf, sameDay, sameGroup, useAttachmentUpload, useAttachmentUrl, useCallRoom, useCalls, useConversation, useConversations, useLiveCall, useMe, useMembers, useMessages, usePoolse, usePresence, useReactions, useReadReceipts, useRealtimeStatus, useRoom, useThread, useTyping, useUser, useVoiceRoom };
package/dist/index.js CHANGED
@@ -1666,6 +1666,55 @@ function useLiveCall(conversationId) {
1666
1666
  }, [chat, conversationId, apply, refresh]);
1667
1667
  return { call, participantIds, refresh };
1668
1668
  }
1669
+ function useRoom(conversationId, opts) {
1670
+ const poolse = usePoolse();
1671
+ const { call: live, participantIds } = useLiveCall(conversationId);
1672
+ const media = useCallRoom(conversationId, { livekit: opts.livekit, aloneGraceMs: 0 });
1673
+ const session = useRef(null);
1674
+ const [joining, setJoining] = useState(false);
1675
+ const [error, setError] = useState(null);
1676
+ useEffect(() => {
1677
+ session.current = null;
1678
+ setError(null);
1679
+ }, [conversationId]);
1680
+ const join = useCallback(
1681
+ async (kind = "audio", joinOpts = {}) => {
1682
+ if (!conversationId) return;
1683
+ setJoining(true);
1684
+ setError(null);
1685
+ try {
1686
+ session.current = joinOpts.ring ? await poolse.rooms.ring(conversationId, kind) : await poolse.rooms.start(conversationId, kind);
1687
+ const connected = await media.join();
1688
+ if (!connected) throw new Error("Rooms need the SFU, which this deployment does not have.");
1689
+ if (kind === "video") await media.setCameraEnabled(true);
1690
+ } catch (err) {
1691
+ setError(err instanceof Error ? err : new Error(String(err)));
1692
+ media.leave();
1693
+ } finally {
1694
+ setJoining(false);
1695
+ }
1696
+ },
1697
+ [poolse, conversationId, media]
1698
+ );
1699
+ const leave = useCallback(() => {
1700
+ media.leave();
1701
+ const s = session.current;
1702
+ session.current = null;
1703
+ if (s) void poolse.rooms.leave(s).catch(() => {
1704
+ });
1705
+ }, [poolse, media]);
1706
+ const joined = media.status === "connected" || media.status === "connecting" || joining;
1707
+ return {
1708
+ live,
1709
+ presentIds: participantIds,
1710
+ joined,
1711
+ joining,
1712
+ join,
1713
+ leave,
1714
+ media,
1715
+ error: error ?? media.error
1716
+ };
1717
+ }
1669
1718
  function useReadReceipts() {
1670
1719
  const chat = usePoolse();
1671
1720
  const { me } = useMe();
@@ -1695,6 +1744,6 @@ function canEditOwnMessage(args) {
1695
1744
  return Number.isFinite(sent) && (args.now ?? Date.now()) - sent < EDIT_WINDOW_MS;
1696
1745
  }
1697
1746
 
1698
- export { EDIT_WINDOW_MS, PoolseProvider, canEditOwnMessage, computeGroupPosition, formatDayLabel, receiptsOf, sameDay, sameGroup, useAttachmentUpload, useAttachmentUrl, useCallRoom, useCalls, useConversation, useConversations, useLiveCall, useMe, useMembers, useMessages, usePoolse, usePresence, useReactions, useReadReceipts, useRealtimeStatus, useThread, useTyping, useUser, useVoiceRoom };
1747
+ export { EDIT_WINDOW_MS, PoolseProvider, canEditOwnMessage, computeGroupPosition, formatDayLabel, receiptsOf, sameDay, sameGroup, useAttachmentUpload, useAttachmentUrl, useCallRoom, useCalls, useConversation, useConversations, useLiveCall, useMe, useMembers, useMessages, usePoolse, usePresence, useReactions, useReadReceipts, useRealtimeStatus, useRoom, useThread, useTyping, useUser, useVoiceRoom };
1699
1748
  //# sourceMappingURL=index.js.map
1700
1749
  //# sourceMappingURL=index.js.map