@realtimexsco/live-chat 1.5.0 → 1.5.1

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
@@ -687,7 +687,7 @@ var init_call_api = __esm({
687
687
  });
688
688
 
689
689
  // src/call/call.types.ts
690
- exports.CALL_MODES = void 0; exports.CALL_STATUS = void 0; var CALL_RING_TIMEOUT_MS, CLIENT_RING_FALLBACK_MS;
690
+ exports.CALL_MODES = void 0; exports.CALL_STATUS = void 0; var CALL_RING_TIMEOUT_MS, CLIENT_RING_FALLBACK_MS, CALL_LOG_EVENT;
691
691
  var init_call_types = __esm({
692
692
  "src/call/call.types.ts"() {
693
693
  exports.CALL_MODES = {
@@ -704,15 +704,22 @@ var init_call_types = __esm({
704
704
  };
705
705
  CALL_RING_TIMEOUT_MS = 4e4;
706
706
  CLIENT_RING_FALLBACK_MS = CALL_RING_TIMEOUT_MS + 5e3;
707
+ CALL_LOG_EVENT = "realtimex:call-log";
707
708
  }
708
709
  });
709
- var ringTimer, clearRingTimer, scheduleRingTimer, idleState; exports.useCallStore = void 0;
710
+ var emitCallLog, ringTimer, clearRingTimer, scheduleRingTimer, idleState; exports.useCallStore = void 0;
710
711
  var init_call_store = __esm({
711
712
  "src/call/call.store.ts"() {
712
713
  init_useStore();
713
714
  init_socket_service2();
714
715
  init_call_api();
715
716
  init_call_types();
717
+ emitCallLog = (entry) => {
718
+ try {
719
+ window.dispatchEvent(new CustomEvent(CALL_LOG_EVENT, { detail: entry }));
720
+ } catch {
721
+ }
722
+ };
716
723
  ringTimer = null;
717
724
  clearRingTimer = () => {
718
725
  if (ringTimer) clearTimeout(ringTimer);
@@ -811,7 +818,13 @@ var init_call_store = __esm({
811
818
  set({ ...idleState });
812
819
  },
813
820
  _receiveIncoming: (payload) => {
814
- if (get().uiStatus !== "idle") return;
821
+ const currentStatus = get().uiStatus;
822
+ if (currentStatus !== "idle") {
823
+ console.warn(
824
+ `[realtimex-call] call_incoming for ${payload.callId} dropped \u2014 local call store is not idle (currently "${currentStatus}", stuck on callId ${get().callId}). If nothing was actually ringing on screen, this is a stuck state from an earlier call \u2014 refreshing the page clears it.`
825
+ );
826
+ return;
827
+ }
815
828
  set({
816
829
  uiStatus: "incoming",
817
830
  callId: payload.callId,
@@ -854,16 +867,37 @@ var init_call_store = __esm({
854
867
  _receiveCancelled: (payload) => {
855
868
  if (get().callId !== payload.callId) return;
856
869
  clearRingTimer();
870
+ const myUserId = exports.useChatStore.getState().loggedUserDetails?._id;
871
+ if (payload.endedBy !== myUserId) {
872
+ emitCallLog({
873
+ conversationId: payload.conversationId,
874
+ mode: payload.mode,
875
+ outcome: "missed",
876
+ durationSeconds: 0
877
+ });
878
+ }
857
879
  set({ ...idleState });
858
880
  },
859
881
  _receiveEnded: (payload) => {
860
882
  if (get().callId !== payload.callId) return;
861
883
  clearRingTimer();
884
+ emitCallLog({
885
+ conversationId: payload.conversationId,
886
+ mode: payload.mode,
887
+ outcome: payload.durationSeconds > 0 ? "completed" : "declined",
888
+ durationSeconds: payload.durationSeconds
889
+ });
862
890
  set({ ...idleState });
863
891
  },
864
892
  _receiveBusy: (payload) => {
865
893
  if (get().callId !== payload.callId) return;
866
894
  clearRingTimer();
895
+ emitCallLog({
896
+ conversationId: payload.conversationId,
897
+ mode: payload.mode,
898
+ outcome: "busy",
899
+ durationSeconds: 0
900
+ });
867
901
  set({ ...idleState, error: "That user is already on another call." });
868
902
  },
869
903
  // Guarded by callId like every other _receive* handler — a late/stale
@@ -872,6 +906,12 @@ var init_call_store = __esm({
872
906
  _receiveMissed: (payload) => {
873
907
  if (get().callId !== payload.callId) return;
874
908
  clearRingTimer();
909
+ emitCallLog({
910
+ conversationId: payload.conversationId,
911
+ mode: payload.mode,
912
+ outcome: "missed",
913
+ durationSeconds: 0
914
+ });
875
915
  set({ ...idleState });
876
916
  }
877
917
  }));
@@ -885,25 +925,33 @@ var init_call_listeners = __esm({
885
925
  init_socket_events_constants();
886
926
  init_call_store();
887
927
  registerCallSocketListeners = (socket) => {
928
+ console.debug("[realtimex-call] registerCallSocketListeners: attached to socket", socket.id);
888
929
  socket.on(SOCKET_EVENTS.CALL_INCOMING, (payload) => {
930
+ console.log("[realtimex-call] call_incoming received:", payload);
889
931
  exports.useCallStore.getState()._receiveIncoming(payload);
890
932
  });
891
933
  socket.on(SOCKET_EVENTS.CALL_ACCEPTED, (payload) => {
934
+ console.log("[realtimex-call] call_accepted received:", payload);
892
935
  exports.useCallStore.getState()._receiveAccepted(payload);
893
936
  });
894
937
  socket.on(SOCKET_EVENTS.CALL_REJECTED, (payload) => {
938
+ console.log("[realtimex-call] call_rejected received:", payload);
895
939
  exports.useCallStore.getState()._receiveRejected(payload);
896
940
  });
897
941
  socket.on(SOCKET_EVENTS.CALL_CANCELLED, (payload) => {
942
+ console.log("[realtimex-call] call_cancelled received:", payload);
898
943
  exports.useCallStore.getState()._receiveCancelled(payload);
899
944
  });
900
945
  socket.on(SOCKET_EVENTS.CALL_ENDED, (payload) => {
946
+ console.log("[realtimex-call] call_ended received:", payload);
901
947
  exports.useCallStore.getState()._receiveEnded(payload);
902
948
  });
903
949
  socket.on(SOCKET_EVENTS.CALL_BUSY, (payload) => {
950
+ console.log("[realtimex-call] call_busy received:", payload);
904
951
  exports.useCallStore.getState()._receiveBusy(payload);
905
952
  });
906
953
  socket.on(SOCKET_EVENTS.CALL_MISSED, (payload) => {
954
+ console.log("[realtimex-call] call_missed received:", payload);
907
955
  exports.useCallStore.getState()._receiveMissed(payload);
908
956
  });
909
957
  };
@@ -6845,6 +6893,18 @@ var installNotificationClickBridge = (options = {}) => {
6845
6893
  };
6846
6894
 
6847
6895
  // src/hooks/useChatController.ts
6896
+ init_call_types();
6897
+ function formatCallLogText(entry) {
6898
+ const label = entry.mode === "video" ? "video" : "voice";
6899
+ if (entry.outcome === "missed") return `Missed ${label} call`;
6900
+ if (entry.outcome === "declined") return `${label === "video" ? "Video" : "Voice"} call declined`;
6901
+ if (entry.outcome === "busy") return `${label === "video" ? "Video" : "Voice"} call \xB7 not answered`;
6902
+ const totalSeconds = Math.max(0, Math.floor(entry.durationSeconds));
6903
+ const minutes = Math.floor(totalSeconds / 60);
6904
+ const seconds = totalSeconds % 60;
6905
+ const duration = `${minutes}:${String(seconds).padStart(2, "0")}`;
6906
+ return `${label === "video" ? "Video" : "Voice"} call \xB7 ${duration}`;
6907
+ }
6848
6908
  function resolveMessageType(content, attachments) {
6849
6909
  if (attachments.length === 0) return "text";
6850
6910
  if (!content.trim() && attachments.length === 1) {
@@ -6902,6 +6962,28 @@ var useChatController = () => {
6902
6962
  );
6903
6963
  }, []);
6904
6964
  const { localMessages, setLocalMessages } = useChatSync();
6965
+ React9.useEffect(() => {
6966
+ const handleCallLog = (event) => {
6967
+ const entry = event.detail;
6968
+ if (!entry?.conversationId) return;
6969
+ const logMessage = {
6970
+ id: `call-log-${Date.now()}-${Math.random().toString(36).slice(2)}`,
6971
+ content: formatCallLogText(entry),
6972
+ sender: "system",
6973
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
6974
+ isOwnMessage: false,
6975
+ isSystemMessage: true,
6976
+ channelId: entry.conversationId,
6977
+ conversationId: entry.conversationId
6978
+ };
6979
+ setLocalMessages((prev) => ({
6980
+ ...prev,
6981
+ [entry.conversationId]: [...prev[entry.conversationId] || [], logMessage]
6982
+ }));
6983
+ };
6984
+ window.addEventListener(CALL_LOG_EVENT, handleCallLog);
6985
+ return () => window.removeEventListener(CALL_LOG_EVENT, handleCallLog);
6986
+ }, [setLocalMessages]);
6905
6987
  const emitDmSend = exports.useChatStore((s) => s.emitDmSend);
6906
6988
  const emitGroupMessageSend2 = exports.useChatStore((s) => s.emitGroupMessageSend);
6907
6989
  const emitMarkAsRead = exports.useChatStore((s) => s.emitMarkAsRead);