@poolse/react-ui 2.14.1 → 2.15.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,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { CallParticipant, CallDevice, CallDeviceKind, Uuid, Message, Conversation, Membership, Attachment, MessageCreateRequest } from '@poolse/sdk';
2
+ import { CallParticipant, CallMedia, LiveKitModule, CallDevice, CallDeviceKind, Uuid, Message, Conversation, Membership, Attachment, MessageCreateRequest } from '@poolse/sdk';
3
3
  import * as react from 'react';
4
- import { SVGProps, ReactElement, ReactNode } from 'react';
4
+ import { ReactNode, SVGProps, ReactElement } from 'react';
5
5
  import { UploadItem, ReactionMap } from '@poolse/react';
6
6
 
7
7
  interface CallVideoGridProps {
@@ -13,6 +13,71 @@ interface CallVideoGridProps {
13
13
  }
14
14
  declare function CallVideoGrid({ participants, labelFor, className, onLocalClick, }: CallVideoGridProps): react_jsx_runtime.JSX.Element | null;
15
15
 
16
+ interface CallInvite {
17
+ /** Ring everyone in a conversation. */
18
+ placeCall: (conversationId: string, media?: CallMedia) => void;
19
+ /** A call is already in flight, so a new one cannot be placed. */
20
+ busy: boolean;
21
+ }
22
+ /**
23
+ * Place a call from anywhere under {@link CallProvider}.
24
+ *
25
+ * const { placeCall, busy } = useCallInvite();
26
+ * <button disabled={busy} onClick={() => placeCall(id, 'video')}>Video</button>
27
+ *
28
+ * Separate from the call surface on purpose. The buttons belong in a
29
+ * conversation header, the surface belongs at the root, and they must
30
+ * share one state machine — see {@link CallProvider} for why that
31
+ * matters more than it sounds.
32
+ */
33
+ declare function useCallInvite(): CallInvite;
34
+ interface CallProviderProps {
35
+ /** The signed-in user's poolse id — the topic calls arrive on. */
36
+ userId: string | null;
37
+ /**
38
+ * `livekit-client`, imported by your app:
39
+ *
40
+ * import * as livekit from 'livekit-client';
41
+ */
42
+ livekit: LiveKitModule;
43
+ /** Resolves a user id to a display label. */
44
+ labelFor?: (userId: string) => string;
45
+ children: ReactNode;
46
+ }
47
+ /**
48
+ * Owns calling for a web app: ringing, answering, media and the call UI.
49
+ *
50
+ * ## Mount it ONCE, at the root
51
+ *
52
+ * Not inside a conversation view, and not behind a route that can
53
+ * unmount. A call arrives on the user's own topic at any moment, and
54
+ * this component is what listens — so anywhere it is not mounted, the
55
+ * app simply cannot be called. Putting it inside a "is a conversation
56
+ * open?" branch means the user is unreachable on the conversation list,
57
+ * which looks exactly like calls being unreliable rather than like a
58
+ * mounting mistake.
59
+ *
60
+ * <CallProvider userId={me.id} livekit={livekit}>
61
+ * <YourApp />
62
+ * </CallProvider>
63
+ *
64
+ * The buttons that place calls live wherever you want them, and reach
65
+ * this through {@link useCallInvite}.
66
+ *
67
+ * ## Two media paths
68
+ *
69
+ * Media rides the SFU when the deployment has one — that is what makes
70
+ * video and the mid-call camera toggle possible. Without one, calls fall
71
+ * back to the peer-to-peer mesh, which carries audio only. The fallback
72
+ * is automatic and silent by design.
73
+ *
74
+ * ## Styling
75
+ *
76
+ * Class-based, and no CSS ships with it. The host owns the look; the
77
+ * class names are stable.
78
+ */
79
+ declare function CallProvider({ userId, livekit, labelFor, children }: CallProviderProps): react_jsx_runtime.JSX.Element;
80
+
16
81
  declare const ICONS: {
17
82
  readonly attachment: {
18
83
  readonly vb: "0 0 24 24";
@@ -909,4 +974,4 @@ declare function usePoolseFonts(enabled?: boolean): void;
909
974
  */
910
975
  declare function PoolseFonts(): null;
911
976
 
912
- export { AttachmentPreview, type AttachmentPreviewProps, Avatar, type AvatarProps, CallControlButton, type CallControlButtonProps, CallDeviceMenu, type CallDeviceMenuProps, CallVideoGrid, type CallVideoGridProps, ChatHeader, type ChatHeaderProps, ConversationList, type ConversationListProps, ConversationView, type ConversationViewProps, EditableMessageBubble, type EditableMessageBubbleProps, GroupDetailsSheet, type GroupDetailsSheetProps, type IconName, type InboxUser, MemberList, type MemberListProps, MentionInput, type MentionInputProps, MessageActions, type MessageActionsProps, MessageBubble, type MessageBubbleProps, MessageComposer, type MessageComposerProps, PoolseFonts, PoolseIcon, type PoolseIconProps, PoolseInbox, type PoolseInboxHandle, type PoolseInboxProps, PoolseLogo, type PoolseLogoProps, type PoolseLogoVariant, ReactionPicker, ReactionStrip, type ReactionStripProps, ThreadView, type ThreadViewProps, TypingIndicator, type TypingIndicatorProps, UploadQueueStrip, UserName, type UserNameProps, UserPickerSheet, type UserPickerSheetProps, useDisplayName, usePoolseFonts };
977
+ export { AttachmentPreview, type AttachmentPreviewProps, Avatar, type AvatarProps, CallControlButton, type CallControlButtonProps, CallDeviceMenu, type CallDeviceMenuProps, type CallInvite, CallProvider, type CallProviderProps, CallVideoGrid, type CallVideoGridProps, ChatHeader, type ChatHeaderProps, ConversationList, type ConversationListProps, ConversationView, type ConversationViewProps, EditableMessageBubble, type EditableMessageBubbleProps, GroupDetailsSheet, type GroupDetailsSheetProps, type IconName, type InboxUser, MemberList, type MemberListProps, MentionInput, type MentionInputProps, MessageActions, type MessageActionsProps, MessageBubble, type MessageBubbleProps, MessageComposer, type MessageComposerProps, PoolseFonts, PoolseIcon, type PoolseIconProps, PoolseInbox, type PoolseInboxHandle, type PoolseInboxProps, PoolseLogo, type PoolseLogoProps, type PoolseLogoVariant, ReactionPicker, ReactionStrip, type ReactionStripProps, ThreadView, type ThreadViewProps, TypingIndicator, type TypingIndicatorProps, UploadQueueStrip, UserName, type UserNameProps, UserPickerSheet, type UserPickerSheetProps, useCallInvite, useDisplayName, usePoolseFonts };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { CallParticipant, CallDevice, CallDeviceKind, Uuid, Message, Conversation, Membership, Attachment, MessageCreateRequest } from '@poolse/sdk';
2
+ import { CallParticipant, CallMedia, LiveKitModule, CallDevice, CallDeviceKind, Uuid, Message, Conversation, Membership, Attachment, MessageCreateRequest } from '@poolse/sdk';
3
3
  import * as react from 'react';
4
- import { SVGProps, ReactElement, ReactNode } from 'react';
4
+ import { ReactNode, SVGProps, ReactElement } from 'react';
5
5
  import { UploadItem, ReactionMap } from '@poolse/react';
6
6
 
7
7
  interface CallVideoGridProps {
@@ -13,6 +13,71 @@ interface CallVideoGridProps {
13
13
  }
14
14
  declare function CallVideoGrid({ participants, labelFor, className, onLocalClick, }: CallVideoGridProps): react_jsx_runtime.JSX.Element | null;
15
15
 
16
+ interface CallInvite {
17
+ /** Ring everyone in a conversation. */
18
+ placeCall: (conversationId: string, media?: CallMedia) => void;
19
+ /** A call is already in flight, so a new one cannot be placed. */
20
+ busy: boolean;
21
+ }
22
+ /**
23
+ * Place a call from anywhere under {@link CallProvider}.
24
+ *
25
+ * const { placeCall, busy } = useCallInvite();
26
+ * <button disabled={busy} onClick={() => placeCall(id, 'video')}>Video</button>
27
+ *
28
+ * Separate from the call surface on purpose. The buttons belong in a
29
+ * conversation header, the surface belongs at the root, and they must
30
+ * share one state machine — see {@link CallProvider} for why that
31
+ * matters more than it sounds.
32
+ */
33
+ declare function useCallInvite(): CallInvite;
34
+ interface CallProviderProps {
35
+ /** The signed-in user's poolse id — the topic calls arrive on. */
36
+ userId: string | null;
37
+ /**
38
+ * `livekit-client`, imported by your app:
39
+ *
40
+ * import * as livekit from 'livekit-client';
41
+ */
42
+ livekit: LiveKitModule;
43
+ /** Resolves a user id to a display label. */
44
+ labelFor?: (userId: string) => string;
45
+ children: ReactNode;
46
+ }
47
+ /**
48
+ * Owns calling for a web app: ringing, answering, media and the call UI.
49
+ *
50
+ * ## Mount it ONCE, at the root
51
+ *
52
+ * Not inside a conversation view, and not behind a route that can
53
+ * unmount. A call arrives on the user's own topic at any moment, and
54
+ * this component is what listens — so anywhere it is not mounted, the
55
+ * app simply cannot be called. Putting it inside a "is a conversation
56
+ * open?" branch means the user is unreachable on the conversation list,
57
+ * which looks exactly like calls being unreliable rather than like a
58
+ * mounting mistake.
59
+ *
60
+ * <CallProvider userId={me.id} livekit={livekit}>
61
+ * <YourApp />
62
+ * </CallProvider>
63
+ *
64
+ * The buttons that place calls live wherever you want them, and reach
65
+ * this through {@link useCallInvite}.
66
+ *
67
+ * ## Two media paths
68
+ *
69
+ * Media rides the SFU when the deployment has one — that is what makes
70
+ * video and the mid-call camera toggle possible. Without one, calls fall
71
+ * back to the peer-to-peer mesh, which carries audio only. The fallback
72
+ * is automatic and silent by design.
73
+ *
74
+ * ## Styling
75
+ *
76
+ * Class-based, and no CSS ships with it. The host owns the look; the
77
+ * class names are stable.
78
+ */
79
+ declare function CallProvider({ userId, livekit, labelFor, children }: CallProviderProps): react_jsx_runtime.JSX.Element;
80
+
16
81
  declare const ICONS: {
17
82
  readonly attachment: {
18
83
  readonly vb: "0 0 24 24";
@@ -909,4 +974,4 @@ declare function usePoolseFonts(enabled?: boolean): void;
909
974
  */
910
975
  declare function PoolseFonts(): null;
911
976
 
912
- export { AttachmentPreview, type AttachmentPreviewProps, Avatar, type AvatarProps, CallControlButton, type CallControlButtonProps, CallDeviceMenu, type CallDeviceMenuProps, CallVideoGrid, type CallVideoGridProps, ChatHeader, type ChatHeaderProps, ConversationList, type ConversationListProps, ConversationView, type ConversationViewProps, EditableMessageBubble, type EditableMessageBubbleProps, GroupDetailsSheet, type GroupDetailsSheetProps, type IconName, type InboxUser, MemberList, type MemberListProps, MentionInput, type MentionInputProps, MessageActions, type MessageActionsProps, MessageBubble, type MessageBubbleProps, MessageComposer, type MessageComposerProps, PoolseFonts, PoolseIcon, type PoolseIconProps, PoolseInbox, type PoolseInboxHandle, type PoolseInboxProps, PoolseLogo, type PoolseLogoProps, type PoolseLogoVariant, ReactionPicker, ReactionStrip, type ReactionStripProps, ThreadView, type ThreadViewProps, TypingIndicator, type TypingIndicatorProps, UploadQueueStrip, UserName, type UserNameProps, UserPickerSheet, type UserPickerSheetProps, useDisplayName, usePoolseFonts };
977
+ export { AttachmentPreview, type AttachmentPreviewProps, Avatar, type AvatarProps, CallControlButton, type CallControlButtonProps, CallDeviceMenu, type CallDeviceMenuProps, type CallInvite, CallProvider, type CallProviderProps, CallVideoGrid, type CallVideoGridProps, ChatHeader, type ChatHeaderProps, ConversationList, type ConversationListProps, ConversationView, type ConversationViewProps, EditableMessageBubble, type EditableMessageBubbleProps, GroupDetailsSheet, type GroupDetailsSheetProps, type IconName, type InboxUser, MemberList, type MemberListProps, MentionInput, type MentionInputProps, MessageActions, type MessageActionsProps, MessageBubble, type MessageBubbleProps, MessageComposer, type MessageComposerProps, PoolseFonts, PoolseIcon, type PoolseIconProps, PoolseInbox, type PoolseInboxHandle, type PoolseInboxProps, PoolseLogo, type PoolseLogoProps, type PoolseLogoVariant, ReactionPicker, ReactionStrip, type ReactionStripProps, ThreadView, type ThreadViewProps, TypingIndicator, type TypingIndicatorProps, UploadQueueStrip, UserName, type UserNameProps, UserPickerSheet, type UserPickerSheetProps, useCallInvite, useDisplayName, usePoolseFonts };
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use client';
2
- import { forwardRef, useState, useRef, useCallback, useImperativeHandle, useEffect, useMemo, Fragment as Fragment$1 } from 'react';
2
+ import { createContext, forwardRef, useState, useRef, useCallback, useImperativeHandle, useEffect, useMemo, Fragment as Fragment$1, useContext } from 'react';
3
3
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
4
- import { useMembers, useAttachmentUpload, useMe, useConversations, useUser, useConversation, usePresence, useMessages, useTyping, useRealtimeStatus, computeGroupPosition, sameDay, formatDayLabel, useReactions, useThread, useAttachmentUrl } from '@poolse/react';
4
+ import { useMembers, useAttachmentUpload, useMe, useConversations, useUser, useConversation, usePresence, useMessages, useTyping, useRealtimeStatus, computeGroupPosition, sameDay, formatDayLabel, useReactions, useThread, useAttachmentUrl, useCalls, useCallRoom, useVoiceRoom } from '@poolse/react';
5
5
  import ReactMarkdown from 'react-markdown';
6
6
  import remarkGfm from 'remark-gfm';
7
7
 
@@ -540,6 +540,275 @@ function kindLabel(kind) {
540
540
  if (kind === "audioinput") return "Microphone";
541
541
  return "Output";
542
542
  }
543
+ var InviteContext = createContext(null);
544
+ function useCallInvite() {
545
+ return useContext(InviteContext) ?? {
546
+ placeCall: () => {
547
+ },
548
+ busy: true
549
+ };
550
+ }
551
+ var CHROME_IDLE_MS = 4500;
552
+ function CallProvider({ userId, livekit, labelFor, children }) {
553
+ const calls = useCalls(userId);
554
+ const label = labelFor ?? ((id) => `User ${id.slice(0, 6)}`);
555
+ const placeCall = useCallback(
556
+ (conversationId, media = "audio") => {
557
+ void calls.call(conversationId, media);
558
+ },
559
+ [calls]
560
+ );
561
+ const invite = { placeCall, busy: calls.phase !== "idle" };
562
+ return /* @__PURE__ */ jsxs(InviteContext.Provider, { value: invite, children: [
563
+ children,
564
+ /* @__PURE__ */ jsx(CallSurface, { calls, livekit, labelFor: label })
565
+ ] });
566
+ }
567
+ function CallSurface({
568
+ calls,
569
+ livekit,
570
+ labelFor
571
+ }) {
572
+ const conversationInCall = calls.phase === "active" ? calls.activeConversationId : null;
573
+ const isVideoCall = calls.media === "video";
574
+ const sfu = useCallRoom(conversationInCall, { livekit, video: isVideoCall });
575
+ const voice = useVoiceRoom(conversationInCall);
576
+ const usingSfu = sfu.sfuAvailable === true;
577
+ const mediaStatus = usingSfu ? sfu.status : voice.status;
578
+ const connected = calls.phase === "active" && mediaStatus === "connected";
579
+ useEffect(() => {
580
+ if (calls.phase !== "active" || !conversationInCall) return;
581
+ let cancelled = false;
582
+ void (async () => {
583
+ const joined = await sfu.join();
584
+ if (cancelled || joined) return;
585
+ await voice.join();
586
+ })();
587
+ return () => {
588
+ cancelled = true;
589
+ };
590
+ }, [calls.phase, conversationInCall]);
591
+ const hangUp = useCallback(() => {
592
+ sfu.leave();
593
+ voice.leave();
594
+ void calls.hangUp();
595
+ }, [sfu, voice, calls]);
596
+ const alone = usingSfu ? sfu.alone : voice.alone;
597
+ const endedOnEmpty = useRef(false);
598
+ if (calls.phase !== "active") endedOnEmpty.current = false;
599
+ useEffect(() => {
600
+ if (!alone || calls.phase !== "active" || endedOnEmpty.current) return;
601
+ endedOnEmpty.current = true;
602
+ hangUp();
603
+ }, [alone, calls.phase, hangUp]);
604
+ const [chromeVisible, setChromeVisible] = useState(true);
605
+ const [lastWake, setLastWake] = useState(0);
606
+ const [menu, setMenu] = useState(null);
607
+ const chromeHides = connected && isVideoCall && menu === null;
608
+ useEffect(() => {
609
+ setChromeVisible(true);
610
+ if (!chromeHides) return;
611
+ const timer = setTimeout(() => setChromeVisible(false), CHROME_IDLE_MS);
612
+ return () => clearTimeout(timer);
613
+ }, [chromeHides, lastWake]);
614
+ const wake = useCallback(() => setLastWake(Date.now()), []);
615
+ const withWake = useCallback(
616
+ (fn) => () => {
617
+ wake();
618
+ fn();
619
+ },
620
+ [wake]
621
+ );
622
+ const micOn = usingSfu ? sfu.micEnabled : !voice.muted;
623
+ const toggleMic = useCallback(() => {
624
+ if (usingSfu) void sfu.toggleMic();
625
+ else voice.toggleMute();
626
+ }, [usingSfu, sfu, voice]);
627
+ const openMenu = useCallback(
628
+ (kind) => {
629
+ sfu.refreshDevices();
630
+ setMenu((current) => current === kind ? null : kind);
631
+ },
632
+ [sfu]
633
+ );
634
+ const duration = useCallDuration(connected);
635
+ if (calls.phase === "idle") return null;
636
+ const ringingIn = calls.phase === "ringing-in";
637
+ const ringingOut = calls.phase === "ringing-out";
638
+ const ended = calls.phase === "declined" || calls.phase === "busy" || calls.phase === "timed-out";
639
+ const others = usingSfu ? sfu.participants.filter((p) => !p.isSelf) : [];
640
+ const peerIds = ringingIn && calls.incoming ? [calls.incoming.callerUserId] : others.length > 0 ? others.map((p) => p.userId) : calls.outgoing?.calleeUserIds ?? [];
641
+ const who = peerIds.length === 0 ? "Call" : peerIds.length <= 2 ? peerIds.map(labelFor).join(", ") : `${labelFor(peerIds[0])} and ${peerIds.length - 1} others`;
642
+ const showStage = connected && usingSfu && sfu.participants.length > 0;
643
+ const error = calls.error ?? (usingSfu ? sfu.error : voice.error);
644
+ const isGroup = others.length > 1;
645
+ return /* @__PURE__ */ jsxs(
646
+ "div",
647
+ {
648
+ className: "callsheet",
649
+ role: "dialog",
650
+ "aria-modal": "true",
651
+ "aria-label": "Call",
652
+ onPointerMove: wake,
653
+ children: [
654
+ /* @__PURE__ */ jsx("div", { className: "callsheet__stage", children: showStage ? /* @__PURE__ */ jsx(
655
+ CallVideoGrid,
656
+ {
657
+ participants: sfu.participants,
658
+ labelFor,
659
+ onLocalClick: sfu.cameraEnabled ? () => void sfu.switchCamera() : void 0
660
+ }
661
+ ) : /* @__PURE__ */ jsx("div", { className: "callsheet__identity", children: /* @__PURE__ */ jsx("span", { className: "callsheet__avatar", "aria-hidden": "true", children: who.slice(0, 1).toUpperCase() }) }) }),
662
+ /* @__PURE__ */ jsxs("header", { className: `callsheet__header${chromeVisible ? "" : " callsheet__header--hidden"}`, children: [
663
+ /* @__PURE__ */ jsx("p", { className: "callsheet__who", children: who }),
664
+ /* @__PURE__ */ jsxs("p", { className: "callsheet__state", children: [
665
+ isGroup && showStage ? `${sfu.participants.length} \xB7 ` : "",
666
+ duration ?? statusLine(calls.phase, mediaStatus)
667
+ ] })
668
+ ] }),
669
+ /* @__PURE__ */ jsxs("div", { className: `callsheet__actions${chromeVisible ? "" : " callsheet__actions--hidden"}`, children: [
670
+ error && /* @__PURE__ */ jsx("p", { className: "callsheet__error", children: error.message }),
671
+ ringingIn ? /* @__PURE__ */ jsxs("div", { className: "callsheet__row", children: [
672
+ /* @__PURE__ */ jsx(
673
+ CallControlButton,
674
+ {
675
+ icon: "phone-off",
676
+ tone: "danger",
677
+ large: true,
678
+ label: "Decline",
679
+ onClick: () => void calls.decline()
680
+ }
681
+ ),
682
+ /* @__PURE__ */ jsx(
683
+ CallControlButton,
684
+ {
685
+ icon: isVideoCall ? "video" : "phone",
686
+ tone: "accept",
687
+ large: true,
688
+ label: "Accept",
689
+ onClick: () => void calls.accept()
690
+ }
691
+ )
692
+ ] }) : ended ? /* @__PURE__ */ jsx("div", { className: "callsheet__row", children: /* @__PURE__ */ jsx(CallControlButton, { icon: "close", label: "Close", onClick: calls.reset }) }) : /* @__PURE__ */ jsxs("div", { className: "callsheet__row", children: [
693
+ /* @__PURE__ */ jsxs("span", { className: "callsheet__control", children: [
694
+ /* @__PURE__ */ jsx(
695
+ CallControlButton,
696
+ {
697
+ icon: micOn ? "mic" : "mic-off",
698
+ active: !micOn,
699
+ label: micOn ? "Mute" : "Unmute",
700
+ onClick: withWake(toggleMic),
701
+ hasMenu: usingSfu && sfu.devices.audioinput.length > 0,
702
+ onMenuClick: withWake(() => openMenu("audioinput"))
703
+ }
704
+ ),
705
+ menu === "audioinput" && /* @__PURE__ */ jsx(
706
+ CallDeviceMenu,
707
+ {
708
+ title: "Microphone",
709
+ devices: sfu.devices.audioinput,
710
+ activeId: sfu.activeDevices.audioinput,
711
+ onSelect: (kind, id) => void sfu.selectDevice(kind, id),
712
+ onClose: () => setMenu(null)
713
+ }
714
+ )
715
+ ] }),
716
+ usingSfu && /* @__PURE__ */ jsxs("span", { className: "callsheet__control", children: [
717
+ /* @__PURE__ */ jsx(
718
+ CallControlButton,
719
+ {
720
+ icon: sfu.cameraEnabled ? "video" : "video-off",
721
+ active: !sfu.cameraEnabled,
722
+ label: "Camera",
723
+ onClick: withWake(() => void sfu.toggleCamera()),
724
+ disabled: sfu.devices.videoinput.length === 0,
725
+ hasMenu: sfu.devices.videoinput.length > 0,
726
+ onMenuClick: withWake(() => openMenu("videoinput"))
727
+ }
728
+ ),
729
+ menu === "videoinput" && /* @__PURE__ */ jsx(
730
+ CallDeviceMenu,
731
+ {
732
+ title: "Camera",
733
+ devices: sfu.devices.videoinput,
734
+ activeId: sfu.activeDevices.videoinput,
735
+ onSelect: (kind, id) => void sfu.selectDevice(kind, id),
736
+ onClose: () => setMenu(null)
737
+ }
738
+ )
739
+ ] }),
740
+ usingSfu && sfu.devices.audiooutput.length > 0 && /* @__PURE__ */ jsxs("span", { className: "callsheet__control", children: [
741
+ /* @__PURE__ */ jsx(
742
+ CallControlButton,
743
+ {
744
+ icon: "speaker",
745
+ label: "Output",
746
+ onClick: withWake(() => openMenu("audiooutput"))
747
+ }
748
+ ),
749
+ menu === "audiooutput" && /* @__PURE__ */ jsx(
750
+ CallDeviceMenu,
751
+ {
752
+ title: "Speaker",
753
+ devices: sfu.devices.audiooutput,
754
+ activeId: sfu.activeDevices.audiooutput,
755
+ onSelect: (kind, id) => void sfu.selectDevice(kind, id),
756
+ onClose: () => setMenu(null)
757
+ }
758
+ )
759
+ ] }),
760
+ /* @__PURE__ */ jsx(
761
+ CallControlButton,
762
+ {
763
+ icon: "phone-off",
764
+ tone: "danger",
765
+ large: true,
766
+ label: ringingOut ? "Cancel" : "Hang up",
767
+ onClick: ringingOut ? () => void calls.cancel() : hangUp
768
+ }
769
+ )
770
+ ] })
771
+ ] })
772
+ ]
773
+ }
774
+ );
775
+ }
776
+ function useCallDuration(connected) {
777
+ const [startedAt, setStartedAt] = useState(null);
778
+ const [, tick] = useState(0);
779
+ useEffect(() => {
780
+ if (!connected) {
781
+ setStartedAt(null);
782
+ return;
783
+ }
784
+ setStartedAt(Date.now());
785
+ const id = setInterval(() => tick((n) => n + 1), 1e3);
786
+ return () => clearInterval(id);
787
+ }, [connected]);
788
+ if (!connected || startedAt === null) return null;
789
+ const total = Math.max(0, Math.floor((Date.now() - startedAt) / 1e3));
790
+ const minutes = Math.floor(total / 60);
791
+ const seconds = total % 60;
792
+ return `${minutes}:${String(seconds).padStart(2, "0")}`;
793
+ }
794
+ function statusLine(phase, mediaStatus) {
795
+ switch (phase) {
796
+ case "ringing-in":
797
+ return "Incoming call\u2026";
798
+ case "ringing-out":
799
+ return "Ringing\u2026";
800
+ case "declined":
801
+ return "Call declined";
802
+ case "busy":
803
+ return "Already on another call";
804
+ case "timed-out":
805
+ return "No answer";
806
+ case "active":
807
+ return mediaStatus === "connected" ? "Connected" : "Connecting\u2026";
808
+ default:
809
+ return "";
810
+ }
811
+ }
543
812
  var FONT_HREF = "https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,400;12..96,600;12..96,800&family=Hanken+Grotesk:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap";
544
813
  var FONT_HREF_PRECONNECT_GOOGLE = "https://fonts.googleapis.com";
545
814
  var FONT_HREF_PRECONNECT_STATIC = "https://fonts.gstatic.com";
@@ -3305,6 +3574,6 @@ function PoolseLogo({
3305
3574
  );
3306
3575
  }
3307
3576
 
3308
- export { AttachmentPreview, Avatar, CallControlButton, CallDeviceMenu, CallVideoGrid, ChatHeader, ConversationList, ConversationView, EditableMessageBubble, GroupDetailsSheet, MemberList, MentionInput, MessageActions, MessageBubble, MessageComposer, PoolseFonts, PoolseIcon, PoolseInbox, PoolseLogo, ReactionPicker, ReactionStrip, ThreadView, TypingIndicator, UploadQueueStrip, UserName, UserPickerSheet, useDisplayName, usePoolseFonts };
3577
+ export { AttachmentPreview, Avatar, CallControlButton, CallDeviceMenu, CallProvider, CallVideoGrid, ChatHeader, ConversationList, ConversationView, EditableMessageBubble, GroupDetailsSheet, MemberList, MentionInput, MessageActions, MessageBubble, MessageComposer, PoolseFonts, PoolseIcon, PoolseInbox, PoolseLogo, ReactionPicker, ReactionStrip, ThreadView, TypingIndicator, UploadQueueStrip, UserName, UserPickerSheet, useCallInvite, useDisplayName, usePoolseFonts };
3309
3578
  //# sourceMappingURL=index.js.map
3310
3579
  //# sourceMappingURL=index.js.map