@sawport/react-sdk 1.3.0-alpha.1 → 1.3.0-alpha.2

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.js CHANGED
@@ -106672,16 +106672,12 @@ const FilePreview = memo(function({ file, onRemove }) {
106672
106672
  }, [file, onRemove]);
106673
106673
  return preview;
106674
106674
  });
106675
- function ChatWidgetScreen({
106676
- welcome_message,
106677
- callUtilsRef,
106678
- company,
106679
- isOngoingChat
106680
- }) {
106675
+ function ChatWidgetScreen({ welcome_message, company, isOngoingChat }) {
106681
106676
  var _a, _b, _c, _d, _e, _f, _g;
106682
106677
  const { dataRef, setChatClose, chatInit, chatClose } = useChatStore();
106683
106678
  const { socket: socket2 } = useSocket();
106684
106679
  const timeoutRef = useRef$1(null);
106680
+ const audioRef = useRef$1(new Audio());
106685
106681
  const [{ pdfModal, selectedPdfURL }, setPDFstate] = useState({
106686
106682
  pdfModal: false,
106687
106683
  selectedPdfURL: ""
@@ -106725,25 +106721,32 @@ function ChatWidgetScreen({
106725
106721
  [`message.new.${(_a2 = dataRef == null ? void 0 : dataRef.wait) == null ? void 0 : _a2.conversation.id}`]: async ({
106726
106722
  message
106727
106723
  }) => {
106728
- var _a3, _b3, _c3, _d3, _e3, _f2, _g2, _h;
106724
+ var _a3, _b3, _c3, _d3, _e3, _f2, _g2;
106729
106725
  const sender = ((_a3 = message.user) == null ? void 0 : _a3.id) || message.user;
106730
106726
  const customer = dataRef == null ? void 0 : dataRef.customer;
106731
106727
  const isSender = ((_b3 = customer == null ? void 0 : customer.user) == null ? void 0 : _b3.id) === (((_c3 = message.user) == null ? void 0 : _c3.id) || message.user);
106732
106728
  message.isSender = isSender;
106733
- if (!isSender)
106734
- (_d3 = callUtilsRef.current) == null ? void 0 : _d3.playSound(
106735
- messageSound,
106736
- (sound) => sound.loop = false
106737
- );
106729
+ if (!isSender) {
106730
+ try {
106731
+ const audio = audioRef.current;
106732
+ audio.src = messageSound;
106733
+ audio.loop = false;
106734
+ audio.play().catch((err) => {
106735
+ console.warn("Message sound autoplay prevented:", err);
106736
+ });
106737
+ } catch (err) {
106738
+ console.error("Error playing message sound:", err);
106739
+ }
106740
+ }
106738
106741
  setState((s2) => {
106739
106742
  s2.data.data.unshift(message);
106740
106743
  return s2;
106741
106744
  });
106742
- if (sender !== ((_e3 = customer == null ? void 0 : customer.user) == null ? void 0 : _e3.id)) {
106745
+ if (sender !== ((_d3 = customer == null ? void 0 : customer.user) == null ? void 0 : _d3.id)) {
106743
106746
  t.emit("agent-joined", message.user);
106744
106747
  }
106745
106748
  if (!isSender) {
106746
- readConversation((_g2 = (_f2 = dataRef == null ? void 0 : dataRef.wait) == null ? void 0 : _f2.conversation) == null ? void 0 : _g2.id, (_h = message.user) == null ? void 0 : _h.id);
106749
+ readConversation((_f2 = (_e3 = dataRef == null ? void 0 : dataRef.wait) == null ? void 0 : _e3.conversation) == null ? void 0 : _f2.id, (_g2 = message.user) == null ? void 0 : _g2.id);
106747
106750
  }
106748
106751
  },
106749
106752
  [`message.updated.${(_b2 = dataRef == null ? void 0 : dataRef.wait) == null ? void 0 : _b2.conversation.id}`]: async ({
@@ -120726,7 +120729,7 @@ const VideoChat = ({
120726
120729
  ]
120727
120730
  }
120728
120731
  ),
120729
- useGrid ? /* @__PURE__ */ jsx(VideoGrid, { participants }) : /* @__PURE__ */ jsxs(Fragment, { children: [
120732
+ useGrid ? /* @__PURE__ */ jsx(VideoGrid, { participants, userId }) : /* @__PURE__ */ jsxs(Fragment, { children: [
120730
120733
  /* @__PURE__ */ jsx(RemoteVideo, { remoteParticipant }),
120731
120734
  /* @__PURE__ */ jsx(LocalVideo, { localParticipant, screenShared })
120732
120735
  ] }),
@@ -120807,7 +120810,7 @@ const LocalVideo = ({ localParticipant, screenShared }) => {
120807
120810
  playsInline: true
120808
120811
  }
120809
120812
  ),
120810
- localParticipant && /* @__PURE__ */ jsx("span", { className: "absolute bottom-2 left-2 text-white text-xs bg-black/40 px-2 py-1 rounded z-10", children: getParticipantDisplayName(localParticipant) || "You" })
120813
+ localParticipant && /* @__PURE__ */ jsx("span", { className: "absolute bottom-2 left-2 text-white text-xs bg-black/40 px-2 py-1 rounded z-10", children: "You" })
120811
120814
  ] });
120812
120815
  };
120813
120816
  const VideoOffCard = ({ className, style: style2 }) => /* @__PURE__ */ jsx(
@@ -120827,7 +120830,8 @@ const ActionBtn = ({ children, ...props }) => /* @__PURE__ */ jsx(
120827
120830
  children
120828
120831
  }
120829
120832
  );
120830
- const VideoGrid = ({ participants }) => {
120833
+ const VideoGrid = ({ participants, userId }) => {
120834
+ var _a;
120831
120835
  const agent = participants.find((p2) => p2.user.user_type === "agent");
120832
120836
  const others = participants.filter((p2) => p2.user.user_type !== "agent");
120833
120837
  if (participants.length === 4) {
@@ -120843,8 +120847,15 @@ const VideoGrid = ({ participants }) => {
120843
120847
  padding: "0px"
120844
120848
  },
120845
120849
  children: participants.slice(0, 4).map((participant) => {
120846
- var _a;
120847
- return /* @__PURE__ */ jsx(VideoTile, { participant }, (_a = participant == null ? void 0 : participant.user) == null ? void 0 : _a.id);
120850
+ var _a2, _b;
120851
+ return /* @__PURE__ */ jsx(
120852
+ VideoTile,
120853
+ {
120854
+ participant,
120855
+ isLocal: ((_a2 = participant == null ? void 0 : participant.user) == null ? void 0 : _a2.id) === String(userId)
120856
+ },
120857
+ (_b = participant == null ? void 0 : participant.user) == null ? void 0 : _b.id
120858
+ );
120848
120859
  })
120849
120860
  }
120850
120861
  );
@@ -120859,7 +120870,7 @@ const VideoGrid = ({ participants }) => {
120859
120870
  padding: "0px"
120860
120871
  },
120861
120872
  children: [
120862
- agent && /* @__PURE__ */ jsx("div", { style: { flex: "1", minWidth: 0 }, children: /* @__PURE__ */ jsx(VideoTile, { participant: agent }) }),
120873
+ agent && /* @__PURE__ */ jsx("div", { style: { flex: "1", minWidth: 0 }, children: /* @__PURE__ */ jsx(VideoTile, { participant: agent, isLocal: ((_a = agent == null ? void 0 : agent.user) == null ? void 0 : _a.id) === String(userId) }) }),
120863
120874
  others.length > 0 && /* @__PURE__ */ jsx(
120864
120875
  "div",
120865
120876
  {
@@ -120871,8 +120882,14 @@ const VideoGrid = ({ participants }) => {
120871
120882
  gap: "0px"
120872
120883
  },
120873
120884
  children: others.map((participant) => {
120874
- var _a;
120875
- return /* @__PURE__ */ jsx("div", { style: { flex: "1", minHeight: 0 }, children: /* @__PURE__ */ jsx(VideoTile, { participant }) }, (_a = participant.user) == null ? void 0 : _a.id);
120885
+ var _a2, _b;
120886
+ return /* @__PURE__ */ jsx("div", { style: { flex: "1", minHeight: 0 }, children: /* @__PURE__ */ jsx(
120887
+ VideoTile,
120888
+ {
120889
+ participant,
120890
+ isLocal: ((_a2 = participant == null ? void 0 : participant.user) == null ? void 0 : _a2.id) === String(userId)
120891
+ }
120892
+ ) }, (_b = participant.user) == null ? void 0 : _b.id);
120876
120893
  })
120877
120894
  }
120878
120895
  ),
@@ -120886,8 +120903,15 @@ const VideoGrid = ({ participants }) => {
120886
120903
  gridAutoRows: "1fr"
120887
120904
  },
120888
120905
  children: participants.slice(0, 4).map((participant) => {
120889
- var _a;
120890
- return /* @__PURE__ */ jsx(VideoTile, { participant }, (_a = participant.user) == null ? void 0 : _a.id);
120906
+ var _a2, _b;
120907
+ return /* @__PURE__ */ jsx(
120908
+ VideoTile,
120909
+ {
120910
+ participant,
120911
+ isLocal: ((_a2 = participant == null ? void 0 : participant.user) == null ? void 0 : _a2.id) === String(userId)
120912
+ },
120913
+ (_b = participant.user) == null ? void 0 : _b.id
120914
+ );
120891
120915
  })
120892
120916
  }
120893
120917
  )
@@ -120895,7 +120919,7 @@ const VideoGrid = ({ participants }) => {
120895
120919
  }
120896
120920
  );
120897
120921
  };
120898
- const VideoTile = ({ participant }) => {
120922
+ const VideoTile = ({ participant, isLocal: isLocal2 }) => {
120899
120923
  const ref2 = useRef$1(null);
120900
120924
  useEffect(() => {
120901
120925
  if (ref2.current && (participant == null ? void 0 : participant.stream)) {
@@ -120907,7 +120931,7 @@ const VideoTile = ({ participant }) => {
120907
120931
  return /* @__PURE__ */ jsxs("div", { className: "relative rounded overflow-hidden bg-black", style: { height: "100%" }, children: [
120908
120932
  !(participant == null ? void 0 : participant.videoOn) && !(participant == null ? void 0 : participant.screenSharing) && /* @__PURE__ */ jsx(VideoOffCard, { className: "border-0" }),
120909
120933
  /* @__PURE__ */ jsx("video", { ref: ref2, autoPlay: true, playsInline: true, className: "w-full h-full object-cover" }),
120910
- /* @__PURE__ */ jsx("span", { className: "absolute bottom-2 left-2 text-white text-xs bg-black/40 px-2 py-1 rounded", children: getParticipantDisplayName(participant) })
120934
+ /* @__PURE__ */ jsx("span", { className: "absolute bottom-2 left-2 text-white text-xs bg-black/40 px-2 py-1 rounded", children: isLocal2 ? "You" : getParticipantDisplayName(participant) })
120911
120935
  ] });
120912
120936
  };
120913
120937
  const IncomingVideoCallModal = memo(
@@ -127179,7 +127203,6 @@ const WidgetFormDisplay = memo(
127179
127203
  companyUser,
127180
127204
  setIsScheduling,
127181
127205
  company,
127182
- callUtilsRef,
127183
127206
  customer
127184
127207
  }
127185
127208
  ) }),
@@ -127196,7 +127219,6 @@ const ChatMode = memo(
127196
127219
  companyUser,
127197
127220
  setIsScheduling,
127198
127221
  company,
127199
- callUtilsRef,
127200
127222
  customer
127201
127223
  }) => {
127202
127224
  var _a, _b;
@@ -127241,10 +127263,10 @@ const ChatMode = memo(
127241
127263
  options: (company == null ? void 0 : company.options) || {},
127242
127264
  customer
127243
127265
  }
127244
- ) : /* @__PURE__ */ jsx(ChatScreen, { callUtilsRef, company, isOngoingChat });
127266
+ ) : /* @__PURE__ */ jsx(ChatScreen, { company, isOngoingChat });
127245
127267
  }
127246
127268
  );
127247
- const ChatScreen = memo(({ company, callUtilsRef, isOngoingChat }) => {
127269
+ const ChatScreen = memo(({ company, isOngoingChat }) => {
127248
127270
  var _a, _b, _c;
127249
127271
  const { dataRef, setHasVerifiedFace } = useChatStore();
127250
127272
  const hasVerifiedFace = (_b = (_a = dataRef == null ? void 0 : dataRef.wait) == null ? void 0 : _a.conversation) == null ? void 0 : _b.hasVerifiedFace;
@@ -127266,7 +127288,6 @@ const ChatScreen = memo(({ company, callUtilsRef, isOngoingChat }) => {
127266
127288
  ChatWidgetScreen$1,
127267
127289
  {
127268
127290
  welcome_message: company == null ? void 0 : company.welcome_message,
127269
- callUtilsRef,
127270
127291
  company,
127271
127292
  isOngoingChat
127272
127293
  }