@livo-tv/sdk 1.13.0 → 1.13.1-pr.11.736fca1

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/README.md CHANGED
@@ -83,9 +83,9 @@ Regression page: `pnpm example:embed` serves `examples/partner-embed` on `http:/
83
83
 
84
84
  Community (condo) — comments on every video, live Q&A only while a stream or webinar is `preview` / `public`. After the event, Q&A stays closed. Comments stay closed unless the organizer sets `commentsAfterEnd`.
85
85
 
86
- **Theater-only:** native `<LivoPlayer>` does **not** show comments/Q&A unless you pass `showCommunity`. Hosted iframes show the panel by default; hide it with `?community=0` (or `playerUrl(id, { community: false })`).
86
+ **In-player drawers:** native `<LivoPlayer showCommunity>` shows Comments and Q&A as overlay drawers, hidden until the bottom-right buttons (next to the control bar). Hosted iframes are theater-only by default; pass `?community=1` (or `playerUrl(id, { community: true })`) to enable the same drawers. `?community=0` remains a valid hide. Drawers take the full theater when the player is compact, or a right-hand fraction when it is large. Hide closes the whole drawer.
87
87
 
88
- **Custom layout:** mount `<LivoCommunity>` next to a theater-only player, or call `createCommunityClient` / the public HTTP API for a fully custom UI. Pass a public `apiUrl` for viewers (`mode="viewer"`, polls). Pass JWT / `X-Api-Key` headers and `mode="control"` for settings, pin/hide/delete, and Q&A highlight/dismiss/answer. Unregistered posters send `displayName`, optional `picture` URL, and `guestId`. Supply `displayName` (and optional `picture`) to skip the name field; otherwise the composer asks once and stores `livo-community-identity`. Hosted iframes use `?name=` / `?avatar=` when the built-in panel is on.
88
+ **Custom layout:** leave `showCommunity` off (and omit `?community=1`) so in-player buttons stay hidden, then mount `<LivoCommunity>` (optional `type="comment"` / `type="question"`) beside the theater, or call `createCommunityClient` / the public HTTP API. Pass a public `apiUrl` for viewers (`mode="viewer"`, polls). Pass JWT / `X-Api-Key` headers and `mode="control"` for settings, pin/hide/delete, and Q&A highlight/dismiss/answer. Unregistered posters send `displayName`, optional `picture` URL, and `guestId`. Supply `displayName` (and optional `picture`) to skip the name field; otherwise the composer asks once and stores `livo-community-identity`. Hosted iframes use `?name=` / `?avatar=` when the built-in drawers are on.
89
89
 
90
90
  ```tsx
91
91
  import { LivoPlayer } from "@livo-tv/sdk";
@@ -99,6 +99,7 @@ import "@livo-tv/sdk/styles.css";
99
99
  targetKind="stream"
100
100
  targetId={stream.id}
101
101
  flags={stream.community}
102
+ type="comment"
102
103
  mode="viewer"
103
104
  displayName="Ada"
104
105
  picture="https://cdn.example/ada.jpg"
@@ -341,6 +341,18 @@ function canPost(flags, type) {
341
341
  function showQaTab(flags) {
342
342
  return hasQa(flags) && flags.qaEnabled;
343
343
  }
344
+ function communityFeedEnabled(flags, type) {
345
+ switch (type) {
346
+ case "comment":
347
+ return flags.commentsEnabled;
348
+ case "question":
349
+ return showQaTab(flags);
350
+ default: {
351
+ const _never = type;
352
+ return _never;
353
+ }
354
+ }
355
+ }
344
356
 
345
357
  // src/condo/identity.ts
346
358
  var GUEST_STORAGE_KEY = "livo-community-guest-id";
@@ -594,7 +606,8 @@ function LivoCommunity({
594
606
  pollMs = 5e3,
595
607
  labels: labelsProp,
596
608
  className,
597
- onFlagsChange
609
+ onFlagsChange,
610
+ type: lockedType
598
611
  }) {
599
612
  const labels = react.useMemo(() => mergeLabels(labelsProp), [labelsProp]);
600
613
  const client = react.useMemo(
@@ -611,7 +624,7 @@ function LivoCommunity({
611
624
  const guestId = guestIdProp ?? communityGuestId();
612
625
  const suppliedName = sanitizeDisplayName(displayNameProp);
613
626
  const locked = suppliedName.length > 0;
614
- const [tab, setTab] = react.useState("comment");
627
+ const [tab, setTab] = react.useState(lockedType ?? "comment");
615
628
  const [items, setItems] = react.useState([]);
616
629
  const [body, setBody] = react.useState("");
617
630
  const [name, setName] = react.useState(suppliedName);
@@ -645,14 +658,18 @@ function LivoCommunity({
645
658
  setIdentityReady(true);
646
659
  }, [locked, picture, suppliedName]);
647
660
  react.useEffect(() => {
661
+ if (lockedType) {
662
+ setTab(lockedType);
663
+ return;
664
+ }
648
665
  if (!showQaTab(settings) && tab === "question") setTab("comment");
649
- }, [settings, tab]);
666
+ }, [lockedType, settings, tab]);
650
667
  const load = react.useCallback(async () => {
651
668
  const listed = await client.list({
652
- type: showQaTab(settings) ? tab : "comment"
669
+ type: lockedType ?? (showQaTab(settings) ? tab : "comment")
653
670
  });
654
671
  setItems(listed.items);
655
- }, [client, settings, tab]);
672
+ }, [client, lockedType, settings, tab]);
656
673
  react.useEffect(() => {
657
674
  let cancelled = false;
658
675
  const tick = async () => {
@@ -673,7 +690,9 @@ function LivoCommunity({
673
690
  window.clearInterval(id);
674
691
  };
675
692
  }, [load, pollMs]);
676
- const open = tab === "question" ? qaOpen(settings) : commentsOpen(settings);
693
+ const activeType = lockedType ?? tab;
694
+ if (lockedType && !communityFeedEnabled(settings, lockedType)) return null;
695
+ const open = activeType === "question" ? qaOpen(settings) : commentsOpen(settings);
677
696
  const showNameField = identityReady && !locked && editingName;
678
697
  const showPostingAs = identityReady && !editingName && sanitizeDisplayName(name).length > 0;
679
698
  function persistIdentity(nextName, nextPicture) {
@@ -696,12 +715,12 @@ function LivoCommunity({
696
715
  const saved = persistIdentity(displayName, pictureUrl);
697
716
  try {
698
717
  await client.create({
699
- type: tab,
718
+ type: activeType,
700
719
  body: text,
701
720
  displayName,
702
721
  picture: saved?.picture ?? pictureUrl ?? void 0,
703
722
  guestId,
704
- parentId: tab === "comment" ? replyTo ?? void 0 : void 0
723
+ parentId: activeType === "comment" ? replyTo ?? void 0 : void 0
705
724
  });
706
725
  setBody("");
707
726
  setReplyTo(null);
@@ -789,7 +808,7 @@ function LivoCommunity({
789
808
  ] })
790
809
  ] }) : null
791
810
  ] }) : null,
792
- showQaTab(settings) ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "livo-condo-tabs", role: "tablist", children: [
811
+ lockedType ? /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "livo-condo-title", children: lockedType === "question" ? labels.qa : labels.comments }) : showQaTab(settings) ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "livo-condo-tabs", role: "tablist", children: [
793
812
  /* @__PURE__ */ jsxRuntime.jsx(
794
813
  "button",
795
814
  {
@@ -814,10 +833,10 @@ function LivoCommunity({
814
833
  /* @__PURE__ */ jsxRuntime.jsx(
815
834
  CommunityMessageScroller,
816
835
  {
817
- followKey: `${tab}:${items.at(-1)?.id ?? "empty"}:${items.length}`,
836
+ followKey: `${activeType}:${items.at(-1)?.id ?? "empty"}:${items.length}`,
818
837
  jumpLabel: labels.jumpToLatest,
819
838
  empty: items.length === 0,
820
- children: items.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "livo-condo-empty", children: tab === "question" ? labels.emptyQuestions : labels.emptyComments }) : items.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
839
+ children: items.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "livo-condo-empty", children: activeType === "question" ? labels.emptyQuestions : labels.emptyComments }) : items.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
821
840
  ItemRow,
822
841
  {
823
842
  item,
@@ -825,7 +844,7 @@ function LivoCommunity({
825
844
  labels,
826
845
  onReply: canPost(settings, "comment") ? setReplyTo : void 0,
827
846
  onPatch: handlePatch,
828
- onUpvote: tab === "question" ? handleUpvote : void 0
847
+ onUpvote: activeType === "question" ? handleUpvote : void 0
829
848
  },
830
849
  item.id
831
850
  ))
@@ -875,7 +894,7 @@ function LivoCommunity({
875
894
  {
876
895
  value: body,
877
896
  onChange: (event) => setBody(event.target.value),
878
- placeholder: tab === "question" ? labels.questionComposer : labels.composer,
897
+ placeholder: activeType === "question" ? labels.questionComposer : labels.composer,
879
898
  required: true,
880
899
  maxLength: 2e3,
881
900
  rows: 3
@@ -884,15 +903,247 @@ function LivoCommunity({
884
903
  /* @__PURE__ */ jsxRuntime.jsx("button", { type: "submit", children: labels.send })
885
904
  ]
886
905
  }
887
- ) : /* @__PURE__ */ jsxRuntime.jsx("p", { className: "livo-condo-closed", role: "status", children: tab === "question" ? labels.qaClosed : labels.closed }),
906
+ ) : /* @__PURE__ */ jsxRuntime.jsx("p", { className: "livo-condo-closed", role: "status", children: activeType === "question" ? labels.qaClosed : labels.closed }),
888
907
  error ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "livo-condo-error", role: "alert", children: error }) : null
889
908
  ] });
890
909
  }
891
910
 
911
+ // node_modules/.pnpm/lucide-react@0.560.0_react@19.2.8/node_modules/lucide-react/dist/esm/shared/src/utils.js
912
+ var toKebabCase = (string) => string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
913
+ var toCamelCase = (string) => string.replace(
914
+ /^([A-Z])|[\s-_]+(\w)/g,
915
+ (match, p1, p2) => p2 ? p2.toUpperCase() : p1.toLowerCase()
916
+ );
917
+ var toPascalCase = (string) => {
918
+ const camelCase = toCamelCase(string);
919
+ return camelCase.charAt(0).toUpperCase() + camelCase.slice(1);
920
+ };
921
+ var mergeClasses = (...classes) => classes.filter((className, index, array) => {
922
+ return Boolean(className) && className.trim() !== "" && array.indexOf(className) === index;
923
+ }).join(" ").trim();
924
+ var hasA11yProp = (props) => {
925
+ for (const prop in props) {
926
+ if (prop.startsWith("aria-") || prop === "role" || prop === "title") {
927
+ return true;
928
+ }
929
+ }
930
+ };
931
+
932
+ // node_modules/.pnpm/lucide-react@0.560.0_react@19.2.8/node_modules/lucide-react/dist/esm/defaultAttributes.js
933
+ var defaultAttributes = {
934
+ xmlns: "http://www.w3.org/2000/svg",
935
+ width: 24,
936
+ height: 24,
937
+ viewBox: "0 0 24 24",
938
+ fill: "none",
939
+ stroke: "currentColor",
940
+ strokeWidth: 2,
941
+ strokeLinecap: "round",
942
+ strokeLinejoin: "round"
943
+ };
944
+
945
+ // node_modules/.pnpm/lucide-react@0.560.0_react@19.2.8/node_modules/lucide-react/dist/esm/Icon.js
946
+ var Icon = react.forwardRef(
947
+ ({
948
+ color = "currentColor",
949
+ size = 24,
950
+ strokeWidth = 2,
951
+ absoluteStrokeWidth,
952
+ className = "",
953
+ children,
954
+ iconNode,
955
+ ...rest
956
+ }, ref) => react.createElement(
957
+ "svg",
958
+ {
959
+ ref,
960
+ ...defaultAttributes,
961
+ width: size,
962
+ height: size,
963
+ stroke: color,
964
+ strokeWidth: absoluteStrokeWidth ? Number(strokeWidth) * 24 / Number(size) : strokeWidth,
965
+ className: mergeClasses("lucide", className),
966
+ ...!children && !hasA11yProp(rest) && { "aria-hidden": "true" },
967
+ ...rest
968
+ },
969
+ [
970
+ ...iconNode.map(([tag, attrs]) => react.createElement(tag, attrs)),
971
+ ...Array.isArray(children) ? children : [children]
972
+ ]
973
+ )
974
+ );
975
+
976
+ // node_modules/.pnpm/lucide-react@0.560.0_react@19.2.8/node_modules/lucide-react/dist/esm/createLucideIcon.js
977
+ var createLucideIcon = (iconName, iconNode) => {
978
+ const Component = react.forwardRef(
979
+ ({ className, ...props }, ref) => react.createElement(Icon, {
980
+ ref,
981
+ iconNode,
982
+ className: mergeClasses(
983
+ `lucide-${toKebabCase(toPascalCase(iconName))}`,
984
+ `lucide-${iconName}`,
985
+ className
986
+ ),
987
+ ...props
988
+ })
989
+ );
990
+ Component.displayName = toPascalCase(iconName);
991
+ return Component;
992
+ };
993
+
994
+ // node_modules/.pnpm/lucide-react@0.560.0_react@19.2.8/node_modules/lucide-react/dist/esm/icons/circle-question-mark.js
995
+ var __iconNode = [
996
+ ["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }],
997
+ ["path", { d: "M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3", key: "1u773s" }],
998
+ ["path", { d: "M12 17h.01", key: "p32p05" }]
999
+ ];
1000
+ var CircleQuestionMark = createLucideIcon("circle-question-mark", __iconNode);
1001
+
1002
+ // node_modules/.pnpm/lucide-react@0.560.0_react@19.2.8/node_modules/lucide-react/dist/esm/icons/message-circle.js
1003
+ var __iconNode2 = [
1004
+ [
1005
+ "path",
1006
+ {
1007
+ d: "M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719",
1008
+ key: "1sd12s"
1009
+ }
1010
+ ]
1011
+ ];
1012
+ var MessageCircle = createLucideIcon("message-circle", __iconNode2);
1013
+ var COMPACT_WIDTH_PX = 640;
1014
+ var COMPACT_HEIGHT_PX = 420;
1015
+ function drawerTitle(type, labels) {
1016
+ switch (type) {
1017
+ case "comment":
1018
+ return labels.comments;
1019
+ case "question":
1020
+ return labels.qa;
1021
+ default: {
1022
+ const _never = type;
1023
+ return _never;
1024
+ }
1025
+ }
1026
+ }
1027
+ function useCompactOverlay(ref) {
1028
+ const [compact, setCompact] = react.useState(true);
1029
+ react.useEffect(() => {
1030
+ const el = ref.current;
1031
+ if (!el) return;
1032
+ const update = (width, height) => {
1033
+ setCompact(width < COMPACT_WIDTH_PX || height < COMPACT_HEIGHT_PX);
1034
+ };
1035
+ update(el.clientWidth, el.clientHeight);
1036
+ if (typeof ResizeObserver === "undefined") return;
1037
+ const observer = new ResizeObserver((entries) => {
1038
+ const box = entries[0]?.contentRect;
1039
+ if (!box) return;
1040
+ update(box.width, box.height);
1041
+ });
1042
+ observer.observe(el);
1043
+ return () => observer.disconnect();
1044
+ }, [ref]);
1045
+ return compact;
1046
+ }
1047
+ function LivoCommunityOverlay({
1048
+ className,
1049
+ labels: labelsProp,
1050
+ flags,
1051
+ ...rest
1052
+ }) {
1053
+ const labels = { ...communityLabels, ...labelsProp };
1054
+ const rootRef = react.useRef(null);
1055
+ const compact = useCompactOverlay(rootRef);
1056
+ const [open, setOpen] = react.useState(null);
1057
+ const comments = communityFeedEnabled(flags, "comment");
1058
+ const questions = communityFeedEnabled(flags, "question");
1059
+ if (!comments && !questions) return null;
1060
+ function toggle(type) {
1061
+ setOpen((current) => current === type ? null : type);
1062
+ }
1063
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1064
+ "div",
1065
+ {
1066
+ ref: rootRef,
1067
+ className: ["livo-condo-overlay", className].filter(Boolean).join(" "),
1068
+ "data-compact": compact ? "true" : "false",
1069
+ "data-open": open ?? "off",
1070
+ children: [
1071
+ open ? /* @__PURE__ */ jsxRuntime.jsxs(
1072
+ "div",
1073
+ {
1074
+ className: "livo-condo-drawer",
1075
+ role: "dialog",
1076
+ "aria-modal": "true",
1077
+ "aria-label": drawerTitle(open, labels),
1078
+ children: [
1079
+ /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "livo-condo-drawer__header", children: [
1080
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { children: drawerTitle(open, labels) }),
1081
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: () => setOpen(null), children: labels.hide })
1082
+ ] }),
1083
+ /* @__PURE__ */ jsxRuntime.jsx(
1084
+ LivoCommunity,
1085
+ {
1086
+ ...rest,
1087
+ flags,
1088
+ labels: labelsProp,
1089
+ type: open,
1090
+ className: "livo-condo-drawer__body"
1091
+ }
1092
+ )
1093
+ ]
1094
+ }
1095
+ ) : null,
1096
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "livo-condo-overlay__toggles", children: [
1097
+ comments ? /* @__PURE__ */ jsxRuntime.jsx(
1098
+ "button",
1099
+ {
1100
+ type: "button",
1101
+ "aria-label": labels.comments,
1102
+ "aria-pressed": open === "comment",
1103
+ title: labels.comments,
1104
+ onClick: () => toggle("comment"),
1105
+ children: /* @__PURE__ */ jsxRuntime.jsx(MessageCircle, { "aria-hidden": "true" })
1106
+ }
1107
+ ) : null,
1108
+ questions ? /* @__PURE__ */ jsxRuntime.jsx(
1109
+ "button",
1110
+ {
1111
+ type: "button",
1112
+ "aria-label": labels.qa,
1113
+ "aria-pressed": open === "question",
1114
+ title: labels.qa,
1115
+ onClick: () => toggle("question"),
1116
+ children: /* @__PURE__ */ jsxRuntime.jsx(CircleQuestionMark, { "aria-hidden": "true" })
1117
+ }
1118
+ ) : null
1119
+ ] })
1120
+ ]
1121
+ }
1122
+ );
1123
+ }
1124
+ /*! Bundled license information:
1125
+
1126
+ lucide-react/dist/esm/shared/src/utils.js:
1127
+ lucide-react/dist/esm/defaultAttributes.js:
1128
+ lucide-react/dist/esm/Icon.js:
1129
+ lucide-react/dist/esm/createLucideIcon.js:
1130
+ lucide-react/dist/esm/icons/circle-question-mark.js:
1131
+ lucide-react/dist/esm/icons/message-circle.js:
1132
+ lucide-react/dist/esm/lucide-react.js:
1133
+ (**
1134
+ * @license lucide-react v0.560.0 - ISC
1135
+ *
1136
+ * This source code is licensed under the ISC license.
1137
+ * See the LICENSE file in the root directory of this source tree.
1138
+ *)
1139
+ */
1140
+
892
1141
  exports.CommunityApiError = CommunityApiError;
893
1142
  exports.LivoCommunity = LivoCommunity;
1143
+ exports.LivoCommunityOverlay = LivoCommunityOverlay;
894
1144
  exports.canPost = canPost;
895
1145
  exports.commentsOpen = commentsOpen;
1146
+ exports.communityFeedEnabled = communityFeedEnabled;
896
1147
  exports.communityGuestId = communityGuestId;
897
1148
  exports.communityLabels = communityLabels;
898
1149
  exports.createCommunityClient = createCommunityClient;