@daeryun/dr_components 1.2.18 → 1.2.20
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/cjs/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/components/Daeryuntalk/ChatButton.jsx +1 -1
- package/dist/components/Daeryuntalk/ChatButton.tsx +1 -1
- package/dist/components/Daeryuntalk/ChatWidget.d.ts +1 -0
- package/dist/components/Daeryuntalk/ChatWidget.jsx +114 -31
- package/dist/components/Daeryuntalk/ChatWidget.tsx +120 -37
- package/dist/components/Daeryuntalk/Viewer/TbPcViewer.tsx +0 -9
- package/dist/components/Daeryuntalk/index.jsx +17 -1
- package/dist/components/Daeryuntalk/index.tsx +26 -2
- package/dist/components/DaeryuntalkBackup/ChatButton.d.ts +11 -0
- package/dist/components/DaeryuntalkBackup/ChatButton.jsx +123 -0
- package/dist/components/DaeryuntalkBackup/ChatButton.tsx +157 -0
- package/dist/components/DaeryuntalkBackup/ChatConversation.d.ts +21 -0
- package/dist/components/DaeryuntalkBackup/ChatConversation.jsx +259 -0
- package/dist/components/DaeryuntalkBackup/ChatConversation.tsx +390 -0
- package/dist/components/DaeryuntalkBackup/ChatConversationItem/ChatConversationHeader.d.ts +16 -0
- package/dist/components/DaeryuntalkBackup/ChatConversationItem/ChatConversationHeader.jsx +50 -0
- package/dist/components/DaeryuntalkBackup/ChatConversationItem/ChatConversationHeader.tsx +108 -0
- package/dist/components/DaeryuntalkBackup/ChatHomeView.d.ts +14 -0
- package/dist/components/DaeryuntalkBackup/ChatHomeView.jsx +147 -0
- package/dist/components/DaeryuntalkBackup/ChatHomeView.tsx +262 -0
- package/dist/components/DaeryuntalkBackup/ChatInput.d.ts +8 -0
- package/dist/components/DaeryuntalkBackup/ChatInput.jsx +64 -0
- package/dist/components/DaeryuntalkBackup/ChatInput.tsx +98 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/AgeCheckBox.d.ts +6 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/AgeCheckBox.jsx +19 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/AgeCheckBox.tsx +27 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/ChatFile.d.ts +10 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/ChatFile.jsx +165 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/ChatFile.tsx +244 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/ChatLoading.d.ts +6 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/ChatLoading.jsx +12 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/ChatLoading.tsx +25 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/ChatPrivacyAuth.d.ts +8 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/ChatPrivacyAuth.jsx +100 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/ChatPrivacyAuth.tsx +135 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/ChatWrapper.d.ts +8 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/ChatWrapper.jsx +14 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/ChatWrapper.tsx +26 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/RichText.d.ts +7 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/RichText.jsx +37 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/RichText.tsx +45 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/TimeWrapper.d.ts +9 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/TimeWrapper.jsx +10 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/TimeWrapper.tsx +21 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/TypingComp.d.ts +3 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/TypingComp.jsx +34 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/TypingComp.tsx +43 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/WorkFlowAuthForm.d.ts +8 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/WorkFlowAuthForm.jsx +20 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/WorkFlowAuthForm.tsx +32 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/WorkFlowClickData.d.ts +7 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/WorkFlowClickData.jsx +21 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/WorkFlowClickData.tsx +37 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/WorkFlowImg.d.ts +9 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/WorkFlowImg.jsx +178 -0
- package/dist/components/DaeryuntalkBackup/ChatItem/WorkFlowImg.tsx +233 -0
- package/dist/components/DaeryuntalkBackup/ChatMessage.d.ts +20 -0
- package/dist/components/DaeryuntalkBackup/ChatMessage.jsx +198 -0
- package/dist/components/DaeryuntalkBackup/ChatMessage.tsx +295 -0
- package/dist/components/DaeryuntalkBackup/ChatObject/FieldWorkObject.d.ts +9 -0
- package/dist/components/DaeryuntalkBackup/ChatObject/FieldWorkObject.jsx +39 -0
- package/dist/components/DaeryuntalkBackup/ChatObject/FieldWorkObject.tsx +75 -0
- package/dist/components/DaeryuntalkBackup/ChatObject/ObjectBack.d.ts +7 -0
- package/dist/components/DaeryuntalkBackup/ChatObject/ObjectBack.jsx +20 -0
- package/dist/components/DaeryuntalkBackup/ChatObject/ObjectBack.tsx +39 -0
- package/dist/components/DaeryuntalkBackup/ChatObject/ObjectButton.d.ts +10 -0
- package/dist/components/DaeryuntalkBackup/ChatObject/ObjectButton.jsx +138 -0
- package/dist/components/DaeryuntalkBackup/ChatObject/ObjectButton.tsx +177 -0
- package/dist/components/DaeryuntalkBackup/ChatWidget.d.ts +13 -0
- package/dist/components/DaeryuntalkBackup/ChatWidget.jsx +154 -0
- package/dist/components/DaeryuntalkBackup/ChatWidget.tsx +221 -0
- package/dist/components/DaeryuntalkBackup/DaeryuntalkContext.d.ts +103 -0
- package/dist/components/DaeryuntalkBackup/DaeryuntalkContext.jsx +207 -0
- package/dist/components/DaeryuntalkBackup/DaeryuntalkContext.tsx +350 -0
- package/dist/components/DaeryuntalkBackup/DateSeparator.d.ts +6 -0
- package/dist/components/DaeryuntalkBackup/DateSeparator.jsx +14 -0
- package/dist/components/DaeryuntalkBackup/DateSeparator.tsx +24 -0
- package/dist/components/DaeryuntalkBackup/FixedErrorBox.d.ts +7 -0
- package/dist/components/DaeryuntalkBackup/FixedErrorBox.jsx +34 -0
- package/dist/components/DaeryuntalkBackup/FixedErrorBox.tsx +73 -0
- package/dist/components/DaeryuntalkBackup/History/AuthForm.d.ts +10 -0
- package/dist/components/DaeryuntalkBackup/History/AuthForm.jsx +157 -0
- package/dist/components/DaeryuntalkBackup/History/AuthForm.tsx +206 -0
- package/dist/components/DaeryuntalkBackup/HistoryView.d.ts +19 -0
- package/dist/components/DaeryuntalkBackup/HistoryView.jsx +94 -0
- package/dist/components/DaeryuntalkBackup/HistoryView.tsx +182 -0
- package/dist/components/DaeryuntalkBackup/HomeView.d.ts +12 -0
- package/dist/components/DaeryuntalkBackup/HomeView.jsx +178 -0
- package/dist/components/DaeryuntalkBackup/HomeView.tsx +261 -0
- package/dist/components/DaeryuntalkBackup/NavigationFooter.d.ts +11 -0
- package/dist/components/DaeryuntalkBackup/NavigationFooter.jsx +44 -0
- package/dist/components/DaeryuntalkBackup/NavigationFooter.tsx +98 -0
- package/dist/components/DaeryuntalkBackup/NoticeMessage.d.ts +7 -0
- package/dist/components/DaeryuntalkBackup/NoticeMessage.jsx +40 -0
- package/dist/components/DaeryuntalkBackup/NoticeMessage.tsx +60 -0
- package/dist/components/DaeryuntalkBackup/Tiptap/DisabledInput.d.ts +6 -0
- package/dist/components/DaeryuntalkBackup/Tiptap/DisabledInput.jsx +17 -0
- package/dist/components/DaeryuntalkBackup/Tiptap/DisabledInput.tsx +28 -0
- package/dist/components/DaeryuntalkBackup/Tiptap/Tiptap.d.ts +20 -0
- package/dist/components/DaeryuntalkBackup/Tiptap/Tiptap.jsx +130 -0
- package/dist/components/DaeryuntalkBackup/Tiptap/Tiptap.tsx +181 -0
- package/dist/components/DaeryuntalkBackup/Toast/DaeryuntalkToastProvider.d.ts +23 -0
- package/dist/components/DaeryuntalkBackup/Toast/DaeryuntalkToastProvider.jsx +40 -0
- package/dist/components/DaeryuntalkBackup/Toast/DaeryuntalkToastProvider.tsx +70 -0
- package/dist/components/DaeryuntalkBackup/Toast/Toast.d.ts +11 -0
- package/dist/components/DaeryuntalkBackup/Toast/Toast.jsx +64 -0
- package/dist/components/DaeryuntalkBackup/Toast/Toast.tsx +98 -0
- package/dist/components/DaeryuntalkBackup/Toast/ToastRender.d.ts +1 -0
- package/dist/components/DaeryuntalkBackup/Toast/ToastRender.jsx +22 -0
- package/dist/components/DaeryuntalkBackup/Toast/ToastRender.tsx +30 -0
- package/dist/components/DaeryuntalkBackup/Viewer/ImageViewer.d.ts +9 -0
- package/dist/components/DaeryuntalkBackup/Viewer/ImageViewer.jsx +98 -0
- package/dist/components/DaeryuntalkBackup/Viewer/ImageViewer.tsx +138 -0
- package/dist/components/DaeryuntalkBackup/Viewer/MobileViewer.d.ts +18 -0
- package/dist/components/DaeryuntalkBackup/Viewer/MobileViewer.jsx +104 -0
- package/dist/components/DaeryuntalkBackup/Viewer/MobileViewer.tsx +182 -0
- package/dist/components/DaeryuntalkBackup/Viewer/TbPcViewer.d.ts +24 -0
- package/dist/components/DaeryuntalkBackup/Viewer/TbPcViewer.jsx +141 -0
- package/dist/components/DaeryuntalkBackup/Viewer/TbPcViewer.tsx +278 -0
- package/dist/components/DaeryuntalkBackup/ViewportHandler.d.ts +6 -0
- package/dist/components/DaeryuntalkBackup/ViewportHandler.jsx +25 -0
- package/dist/components/DaeryuntalkBackup/ViewportHandler.tsx +32 -0
- package/dist/components/DaeryuntalkBackup/_api/daeryuntalk/index.d.ts +177 -0
- package/dist/components/DaeryuntalkBackup/_api/daeryuntalk/index.js +801 -0
- package/dist/components/DaeryuntalkBackup/_api/daeryuntalk/index.ts +1097 -0
- package/dist/components/DaeryuntalkBackup/_api/daeryuntalk/type/response.d.ts +131 -0
- package/dist/components/DaeryuntalkBackup/_api/daeryuntalk/type/response.js +1 -0
- package/dist/components/DaeryuntalkBackup/_api/daeryuntalk/type/response.ts +159 -0
- package/dist/components/DaeryuntalkBackup/_api/index.d.ts +6 -0
- package/dist/components/DaeryuntalkBackup/_api/index.js +6 -0
- package/dist/components/DaeryuntalkBackup/_api/index.ts +7 -0
- package/dist/components/DaeryuntalkBackup/_enums/ags_check_status.d.ts +5 -0
- package/dist/components/DaeryuntalkBackup/_enums/ags_check_status.js +9 -0
- package/dist/components/DaeryuntalkBackup/_enums/ags_check_status.ts +9 -0
- package/dist/components/DaeryuntalkBackup/_enums/ask-status.d.ts +13 -0
- package/dist/components/DaeryuntalkBackup/_enums/ask-status.js +25 -0
- package/dist/components/DaeryuntalkBackup/_enums/ask-status.ts +26 -0
- package/dist/components/DaeryuntalkBackup/_enums/error.d.ts +109 -0
- package/dist/components/DaeryuntalkBackup/_enums/error.js +254 -0
- package/dist/components/DaeryuntalkBackup/_enums/error.ts +289 -0
- package/dist/components/DaeryuntalkBackup/_enums/message_type.d.ts +6 -0
- package/dist/components/DaeryuntalkBackup/_enums/message_type.js +13 -0
- package/dist/components/DaeryuntalkBackup/_enums/message_type.ts +13 -0
- package/dist/components/DaeryuntalkBackup/_enums/sender_type.d.ts +8 -0
- package/dist/components/DaeryuntalkBackup/_enums/sender_type.js +16 -0
- package/dist/components/DaeryuntalkBackup/_enums/sender_type.ts +16 -0
- package/dist/components/DaeryuntalkBackup/_enums/socket_type.d.ts +34 -0
- package/dist/components/DaeryuntalkBackup/_enums/socket_type.js +46 -0
- package/dist/components/DaeryuntalkBackup/_enums/socket_type.ts +56 -0
- package/dist/components/DaeryuntalkBackup/_enums/template.d.ts +32 -0
- package/dist/components/DaeryuntalkBackup/_enums/template.js +76 -0
- package/dist/components/DaeryuntalkBackup/_enums/template.ts +81 -0
- package/dist/components/DaeryuntalkBackup/_enums/work_flow_object_expose.d.ts +33 -0
- package/dist/components/DaeryuntalkBackup/_enums/work_flow_object_expose.js +66 -0
- package/dist/components/DaeryuntalkBackup/_enums/work_flow_object_expose.ts +71 -0
- package/dist/components/DaeryuntalkBackup/_hooks/talkprovider/useChatHandler.d.ts +48 -0
- package/dist/components/DaeryuntalkBackup/_hooks/talkprovider/useChatHandler.js +465 -0
- package/dist/components/DaeryuntalkBackup/_hooks/talkprovider/useChatHandler.ts +595 -0
- package/dist/components/DaeryuntalkBackup/_hooks/talkprovider/useFullURL.d.ts +1 -0
- package/dist/components/DaeryuntalkBackup/_hooks/talkprovider/useFullURL.jsx +15 -0
- package/dist/components/DaeryuntalkBackup/_hooks/talkprovider/useFullURL.tsx +17 -0
- package/dist/components/DaeryuntalkBackup/_hooks/talkprovider/useHistoryHandler.d.ts +24 -0
- package/dist/components/DaeryuntalkBackup/_hooks/talkprovider/useHistoryHandler.js +112 -0
- package/dist/components/DaeryuntalkBackup/_hooks/talkprovider/useHistoryHandler.ts +144 -0
- package/dist/components/DaeryuntalkBackup/_hooks/talkprovider/useSocketEventHandler.d.ts +44 -0
- package/dist/components/DaeryuntalkBackup/_hooks/talkprovider/useSocketEventHandler.js +534 -0
- package/dist/components/DaeryuntalkBackup/_hooks/talkprovider/useSocketEventHandler.ts +706 -0
- package/dist/components/DaeryuntalkBackup/_hooks/talkprovider/useViewerHook.d.ts +8 -0
- package/dist/components/DaeryuntalkBackup/_hooks/talkprovider/useViewerHook.js +18 -0
- package/dist/components/DaeryuntalkBackup/_hooks/talkprovider/useViewerHook.ts +23 -0
- package/dist/components/DaeryuntalkBackup/_hooks/talkprovider/useWorkFlow.d.ts +9 -0
- package/dist/components/DaeryuntalkBackup/_hooks/talkprovider/useWorkFlow.js +109 -0
- package/dist/components/DaeryuntalkBackup/_hooks/talkprovider/useWorkFlow.ts +121 -0
- package/dist/components/DaeryuntalkBackup/_hooks/useHoverScrollbar.d.ts +12 -0
- package/dist/components/DaeryuntalkBackup/_hooks/useHoverScrollbar.js +48 -0
- package/dist/components/DaeryuntalkBackup/_hooks/useHoverScrollbar.ts +73 -0
- package/dist/components/DaeryuntalkBackup/_hooks/useScrollShadow.d.ts +7 -0
- package/dist/components/DaeryuntalkBackup/_hooks/useScrollShadow.js +42 -0
- package/dist/components/DaeryuntalkBackup/_hooks/useScrollShadow.ts +52 -0
- package/dist/components/DaeryuntalkBackup/_hooks/useWindowSize.d.ts +6 -0
- package/dist/components/DaeryuntalkBackup/_hooks/useWindowSize.js +20 -0
- package/dist/components/DaeryuntalkBackup/_hooks/useWindowSize.ts +30 -0
- package/dist/components/DaeryuntalkBackup/_hooks/view/useChatSocketState.d.ts +2 -0
- package/dist/components/DaeryuntalkBackup/_hooks/view/useChatSocketState.js +26 -0
- package/dist/components/DaeryuntalkBackup/_hooks/view/useChatSocketState.ts +43 -0
- package/dist/components/DaeryuntalkBackup/_hooks/view/useHistoryView.d.ts +27 -0
- package/dist/components/DaeryuntalkBackup/_hooks/view/useHistoryView.js +80 -0
- package/dist/components/DaeryuntalkBackup/_hooks/view/useHistoryView.ts +101 -0
- package/dist/components/DaeryuntalkBackup/_hooks/view/useHomeView.d.ts +18 -0
- package/dist/components/DaeryuntalkBackup/_hooks/view/useHomeView.js +66 -0
- package/dist/components/DaeryuntalkBackup/_hooks/view/useHomeView.ts +75 -0
- package/dist/components/DaeryuntalkBackup/_lib/index.d.ts +7 -0
- package/dist/components/DaeryuntalkBackup/_lib/index.js +103 -0
- package/dist/components/DaeryuntalkBackup/_lib/index.ts +136 -0
- package/dist/components/DaeryuntalkBackup/_lib/utils.d.ts +17 -0
- package/dist/components/DaeryuntalkBackup/_lib/utils.js +94 -0
- package/dist/components/DaeryuntalkBackup/_lib/utils.ts +119 -0
- package/dist/components/DaeryuntalkBackup/_types/message.d.ts +92 -0
- package/dist/components/DaeryuntalkBackup/_types/message.js +25 -0
- package/dist/components/DaeryuntalkBackup/_types/message.ts +156 -0
- package/dist/components/DaeryuntalkBackup/_types/message_object.d.ts +17 -0
- package/dist/components/DaeryuntalkBackup/_types/message_object.js +1 -0
- package/dist/components/DaeryuntalkBackup/_types/message_object.ts +18 -0
- package/dist/components/DaeryuntalkBackup/_types/socket/workflow.d.ts +15 -0
- package/dist/components/DaeryuntalkBackup/_types/socket/workflow.js +1 -0
- package/dist/components/DaeryuntalkBackup/_types/socket/workflow.ts +15 -0
- package/dist/components/DaeryuntalkBackup/_ui/ShadowBox.d.ts +6 -0
- package/dist/components/DaeryuntalkBackup/_ui/ShadowBox.jsx +5 -0
- package/dist/components/DaeryuntalkBackup/_ui/ShadowBox.tsx +15 -0
- package/dist/components/DaeryuntalkBackup/_ui/buttons/Button1.d.ts +10 -0
- package/dist/components/DaeryuntalkBackup/_ui/buttons/Button1.jsx +12 -0
- package/dist/components/DaeryuntalkBackup/_ui/buttons/Button1.tsx +29 -0
- package/dist/components/DaeryuntalkBackup/_ui/buttons/Button2.d.ts +10 -0
- package/dist/components/DaeryuntalkBackup/_ui/buttons/Button2.jsx +12 -0
- package/dist/components/DaeryuntalkBackup/_ui/buttons/Button2.tsx +29 -0
- package/dist/components/DaeryuntalkBackup/_ui/buttons/Button3.d.ts +10 -0
- package/dist/components/DaeryuntalkBackup/_ui/buttons/Button3.jsx +12 -0
- package/dist/components/DaeryuntalkBackup/_ui/buttons/Button3.tsx +29 -0
- package/dist/components/DaeryuntalkBackup/_ui/buttons/Button4.d.ts +10 -0
- package/dist/components/DaeryuntalkBackup/_ui/buttons/Button4.jsx +12 -0
- package/dist/components/DaeryuntalkBackup/_ui/buttons/Button4.tsx +29 -0
- package/dist/components/DaeryuntalkBackup/_ui/checkboxs/CheckBox1.d.ts +8 -0
- package/dist/components/DaeryuntalkBackup/_ui/checkboxs/CheckBox1.jsx +15 -0
- package/dist/components/DaeryuntalkBackup/_ui/checkboxs/CheckBox1.tsx +38 -0
- package/dist/components/DaeryuntalkBackup/_ui/checkboxs/CheckBox2.d.ts +8 -0
- package/dist/components/DaeryuntalkBackup/_ui/checkboxs/CheckBox2.jsx +21 -0
- package/dist/components/DaeryuntalkBackup/_ui/checkboxs/CheckBox2.tsx +50 -0
- package/dist/components/DaeryuntalkBackup/_ui/inputs/Input1.d.ts +12 -0
- package/dist/components/DaeryuntalkBackup/_ui/inputs/Input1.jsx +9 -0
- package/dist/components/DaeryuntalkBackup/_ui/inputs/Input1.tsx +39 -0
- package/dist/components/DaeryuntalkBackup/_ui/inputs/Input2.d.ts +13 -0
- package/dist/components/DaeryuntalkBackup/_ui/inputs/Input2.jsx +10 -0
- package/dist/components/DaeryuntalkBackup/_ui/inputs/Input2.tsx +43 -0
- package/dist/components/DaeryuntalkBackup/index.d.ts +8 -0
- package/dist/components/DaeryuntalkBackup/index.jsx +190 -0
- package/dist/components/DaeryuntalkBackup/index.tsx +261 -0
- package/dist/components/common/integrate/index.d.ts +1 -1
- package/dist/styles/globals.css +415 -414
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,706 @@
|
|
|
1
|
+
import { Dispatch, MutableRefObject, SetStateAction, useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
authenticateUser,
|
|
5
|
+
getChatInquiryMain,
|
|
6
|
+
getHistoryList,
|
|
7
|
+
initializeDaeryuntalk as apiInitializeDaeryuntalk,
|
|
8
|
+
initializeWebSocket,
|
|
9
|
+
connectWebSocket,
|
|
10
|
+
getChatInquiryMessageList,
|
|
11
|
+
generateChatInquiry,
|
|
12
|
+
getChatInquiryDetailNew
|
|
13
|
+
} from '../../_api/daeryuntalk';
|
|
14
|
+
import { Message } from '../../_types/message';
|
|
15
|
+
import { History, IChatInquiryMainDataResponse } from '../../_api/daeryuntalk/type/response';
|
|
16
|
+
import {
|
|
17
|
+
convertApiMessageObjectToUiMessageObject,
|
|
18
|
+
convertApiMessageToUiMessage,
|
|
19
|
+
convertSocketObjectToUiMessage
|
|
20
|
+
} from '../../_lib';
|
|
21
|
+
import { MessageObject } from '../../_types/message_object';
|
|
22
|
+
import { IInquiryWorkFlowUpdate } from '../../_types/socket/workflow';
|
|
23
|
+
import { MessageSendSocketType, MessageSocketType } from '../../_enums/socket_type';
|
|
24
|
+
import { InquiryStatusEnum } from '../../_enums/ask-status';
|
|
25
|
+
import { useDaeryunTalkToast } from '../../Toast/DaeryuntalkToastProvider';
|
|
26
|
+
import { getErrorMessageMap } from '../../_enums/error';
|
|
27
|
+
import { ViewState } from '../../ChatHomeView';
|
|
28
|
+
import { consoleFn } from '../../_lib/utils';
|
|
29
|
+
import { useFullURL } from './useFullURL';
|
|
30
|
+
import { AgeCheckStatusEnums } from '../../_enums/ags_check_status';
|
|
31
|
+
|
|
32
|
+
interface props {
|
|
33
|
+
setIsConnected: Dispatch<SetStateAction<boolean | null>>;
|
|
34
|
+
setIsLoading: Dispatch<SetStateAction<boolean>>;
|
|
35
|
+
setMessages: Dispatch<SetStateAction<Message[]>>;
|
|
36
|
+
setWorkFlowStack: Dispatch<SetStateAction<string[]>>;
|
|
37
|
+
setMessageObject: Dispatch<SetStateAction<MessageObject | null>>;
|
|
38
|
+
setInquiryMainData: Dispatch<SetStateAction<IChatInquiryMainDataResponse | null>>;
|
|
39
|
+
socketRef: MutableRefObject<WebSocket | null>;
|
|
40
|
+
setInquiryStatus: Dispatch<SetStateAction<string>>;
|
|
41
|
+
setHistoryList: Dispatch<SetStateAction<History[]>>;
|
|
42
|
+
historyList: History[];
|
|
43
|
+
inquiryMainData: IChatInquiryMainDataResponse | null;
|
|
44
|
+
isMobile: boolean;
|
|
45
|
+
setIsAuthenticated: Dispatch<SetStateAction<boolean>>;
|
|
46
|
+
setIsTyping: Dispatch<SetStateAction<boolean>>;
|
|
47
|
+
onClose: () => void;
|
|
48
|
+
centerCode: string;
|
|
49
|
+
setPreviewState: Dispatch<SetStateAction<ViewState>>;
|
|
50
|
+
setIsUserExpried: Dispatch<SetStateAction<boolean>>;
|
|
51
|
+
chatInquiryNumber: string | null;
|
|
52
|
+
setIsNextPage: Dispatch<SetStateAction<boolean | null>>;
|
|
53
|
+
setInitialLoading: Dispatch<SetStateAction<boolean | null>>;
|
|
54
|
+
setChatInquiryNumber: Dispatch<SetStateAction<string | null>>;
|
|
55
|
+
setAgeCheckStatus: Dispatch<SetStateAction<AgeCheckStatusEnums | null>>;
|
|
56
|
+
isOpen: boolean;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const useSocketEventHandler = ({
|
|
60
|
+
setIsConnected,
|
|
61
|
+
setIsLoading,
|
|
62
|
+
setMessages,
|
|
63
|
+
setInquiryMainData,
|
|
64
|
+
socketRef,
|
|
65
|
+
setWorkFlowStack,
|
|
66
|
+
setMessageObject,
|
|
67
|
+
setInquiryStatus,
|
|
68
|
+
setHistoryList,
|
|
69
|
+
historyList,
|
|
70
|
+
inquiryMainData,
|
|
71
|
+
isMobile,
|
|
72
|
+
setIsAuthenticated,
|
|
73
|
+
setIsTyping,
|
|
74
|
+
onClose,
|
|
75
|
+
centerCode,
|
|
76
|
+
setPreviewState,
|
|
77
|
+
setIsUserExpried,
|
|
78
|
+
chatInquiryNumber,
|
|
79
|
+
setIsNextPage,
|
|
80
|
+
setInitialLoading,
|
|
81
|
+
setChatInquiryNumber,
|
|
82
|
+
setAgeCheckStatus,
|
|
83
|
+
isOpen
|
|
84
|
+
}: props) => {
|
|
85
|
+
const typingBlockRef = useRef<NodeJS.Timeout | null>(null);
|
|
86
|
+
const typingTimeoutRef = useRef<NodeJS.Timeout | null>(null);
|
|
87
|
+
const toast = useDaeryunTalkToast();
|
|
88
|
+
const userExpiredRef = useRef(false);
|
|
89
|
+
const fullUrl = useFullURL();
|
|
90
|
+
|
|
91
|
+
// 현재 화면 가시성 상태
|
|
92
|
+
const [isVisible, setIsVisible] = useState(
|
|
93
|
+
typeof document !== 'undefined' ? document.visibilityState === 'visible' : true
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
// 재연결 시도 횟수
|
|
97
|
+
const reconnectCountRef = useRef<number>(0);
|
|
98
|
+
// 최대 재연결 시도 횟수
|
|
99
|
+
const maxReconnectAttempts = 10;
|
|
100
|
+
// 재연결 중인지 여부
|
|
101
|
+
const isSocketReconnectingRef = useRef<boolean>(false);
|
|
102
|
+
// 재연결 시도 딜레이 시간
|
|
103
|
+
const reconnectDelay = 3000;
|
|
104
|
+
|
|
105
|
+
const openTyping = () => {
|
|
106
|
+
setIsTyping(true);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const closeTyping = () => {
|
|
110
|
+
setIsTyping(false);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const chatInquiryNumberRef = useRef(chatInquiryNumber);
|
|
114
|
+
|
|
115
|
+
// 상태가 바뀔 때마다 ref도 갱신
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
chatInquiryNumberRef.current = chatInquiryNumber;
|
|
118
|
+
}, [chatInquiryNumber]);
|
|
119
|
+
consoleFn('chatInquiryNumber', chatInquiryNumber);
|
|
120
|
+
consoleFn('socketRef.current', socketRef.current?.readyState);
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 1. heartbeat
|
|
124
|
+
* - 목적: 사용자의 이탈 여부를 추적하기 위한 주기적 하트비트 전송
|
|
125
|
+
* - 설명: N초 주기로 전송되며, 이탈 판단 로직에 사용됨
|
|
126
|
+
* - 예시:
|
|
127
|
+
* {
|
|
128
|
+
* "type": "heartbeat",
|
|
129
|
+
* "payload": {
|
|
130
|
+
* "chat_inquiry_number": "C3213638792875684353"
|
|
131
|
+
* }
|
|
132
|
+
* }
|
|
133
|
+
*/
|
|
134
|
+
const sendHeartbeat = useCallback(() => {
|
|
135
|
+
const socket = socketRef.current;
|
|
136
|
+
if (socket && socket.readyState === WebSocket.OPEN) {
|
|
137
|
+
socket.send(
|
|
138
|
+
JSON.stringify({
|
|
139
|
+
type: MessageSendSocketType.HEARTBEAT,
|
|
140
|
+
payload: {}
|
|
141
|
+
})
|
|
142
|
+
);
|
|
143
|
+
consoleFn(`[WebSocket] ${MessageSendSocketType.HEARTBEAT} 전송`);
|
|
144
|
+
}
|
|
145
|
+
}, []);
|
|
146
|
+
|
|
147
|
+
const sendInquiryWatching = useCallback((chatInquiryNumber: string) => {
|
|
148
|
+
const socket = socketRef.current;
|
|
149
|
+
if (socket && socket.readyState === WebSocket.OPEN) {
|
|
150
|
+
socket.send(
|
|
151
|
+
JSON.stringify({
|
|
152
|
+
type: MessageSendSocketType.INQUIRY_WATCHING,
|
|
153
|
+
payload: { chat_inquiry_number: chatInquiryNumber }
|
|
154
|
+
})
|
|
155
|
+
);
|
|
156
|
+
consoleFn(`[WebSocket] ${MessageSendSocketType.INQUIRY_WATCHING} 전송`);
|
|
157
|
+
}
|
|
158
|
+
}, []);
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* 2. inquiry.joined
|
|
162
|
+
* - 목적: 특정 문의 세션에 참여를 알림
|
|
163
|
+
* - 설명: 이 요청 이후부터 해당 문의의 메시지 이벤트를 수신 가능
|
|
164
|
+
* - 예시:
|
|
165
|
+
* {
|
|
166
|
+
* "type": "inquiry.joined",
|
|
167
|
+
* "payload": {
|
|
168
|
+
* "chat_inquiry_number": "C3213638792875684353"
|
|
169
|
+
* }
|
|
170
|
+
* }
|
|
171
|
+
*/
|
|
172
|
+
const sendInquiryJoined = useCallback((chatInquiryNumber: string) => {
|
|
173
|
+
const socket = socketRef.current;
|
|
174
|
+
if (socket && socket.readyState === WebSocket.OPEN) {
|
|
175
|
+
socket.send(
|
|
176
|
+
JSON.stringify({
|
|
177
|
+
type: MessageSendSocketType.INQUIRY_JOINED,
|
|
178
|
+
payload: { chat_inquiry_number: chatInquiryNumber }
|
|
179
|
+
})
|
|
180
|
+
);
|
|
181
|
+
consoleFn(`[WebSocket] ${MessageSendSocketType.INQUIRY_JOINED} 전송`);
|
|
182
|
+
}
|
|
183
|
+
}, []);
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* 3. inquiry.left
|
|
187
|
+
* - 목적: 특정 문의 세션에서 이탈을 알림
|
|
188
|
+
* - 설명: 이 요청 이후 해당 문의의 메시지 이벤트는 수신되지 않음
|
|
189
|
+
* - 예시:
|
|
190
|
+
* {
|
|
191
|
+
* "type": "inquiry.left",
|
|
192
|
+
* "payload": {
|
|
193
|
+
* "chat_inquiry_number": "C3213638792875684353"
|
|
194
|
+
* }
|
|
195
|
+
* }
|
|
196
|
+
*/
|
|
197
|
+
const sendInquiryLeft = useCallback((chatInquiryNumber: string) => {
|
|
198
|
+
const socket = socketRef.current;
|
|
199
|
+
if (socket && socket.readyState === WebSocket.OPEN) {
|
|
200
|
+
socket.send(
|
|
201
|
+
JSON.stringify({
|
|
202
|
+
type: MessageSendSocketType.INQUIRY_LEFT,
|
|
203
|
+
payload: { chat_inquiry_number: chatInquiryNumber }
|
|
204
|
+
})
|
|
205
|
+
);
|
|
206
|
+
consoleFn(`[WebSocket] ${MessageSendSocketType.INQUIRY_LEFT} 전송`);
|
|
207
|
+
}
|
|
208
|
+
}, []);
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* 4. history.entered -> 사용 X
|
|
212
|
+
* - 목적: 히스토리 목록 화면 진입 시, 여러 문의의 메시지 이벤트 수신을 요청
|
|
213
|
+
* - 설명: 복수 문의 번호를 등록함으로써 여러 문의에 대한 변경사항을 동시에 수신
|
|
214
|
+
* - 예시:
|
|
215
|
+
* {
|
|
216
|
+
* "type": "history.entered",
|
|
217
|
+
* "payload": {
|
|
218
|
+
* "chat_inquiry_numbers": [
|
|
219
|
+
* "C3213638792875684353",
|
|
220
|
+
* "C3213638792875689999",
|
|
221
|
+
* "C3213638792875777"
|
|
222
|
+
* ]
|
|
223
|
+
* }
|
|
224
|
+
* }
|
|
225
|
+
*/
|
|
226
|
+
const sendHistoryEntered = useCallback((chatInquiryNumbers: string[]) => {
|
|
227
|
+
const socket = socketRef.current;
|
|
228
|
+
if (socket && socket.readyState === WebSocket.OPEN) {
|
|
229
|
+
socket.send(
|
|
230
|
+
JSON.stringify({
|
|
231
|
+
type: MessageSendSocketType.HISTORY_ENTERED,
|
|
232
|
+
payload: { chat_inquiry_numbers: chatInquiryNumbers }
|
|
233
|
+
})
|
|
234
|
+
);
|
|
235
|
+
consoleFn(`[WebSocket] ${MessageSendSocketType.HISTORY_ENTERED} 전송`);
|
|
236
|
+
}
|
|
237
|
+
}, []);
|
|
238
|
+
// -> 사용 X
|
|
239
|
+
const sendHistoryLeft = useCallback((chatInquiryNumbers: string[]) => {
|
|
240
|
+
const socket = socketRef.current;
|
|
241
|
+
if (socket && socket.readyState === WebSocket.OPEN) {
|
|
242
|
+
socket.send(
|
|
243
|
+
JSON.stringify({
|
|
244
|
+
type: MessageSendSocketType.HISTORY_EXITED,
|
|
245
|
+
payload: { chat_inquiry_numbers: chatInquiryNumbers }
|
|
246
|
+
})
|
|
247
|
+
);
|
|
248
|
+
consoleFn(`[WebSocket] ${MessageSendSocketType.HISTORY_EXITED} 전송`);
|
|
249
|
+
}
|
|
250
|
+
}, []);
|
|
251
|
+
|
|
252
|
+
/** 화면 전환 이벤트 (백그라운드 ↔ 포그라운드) */
|
|
253
|
+
useEffect(() => {
|
|
254
|
+
const handleVisibilityChange = () => {
|
|
255
|
+
const visible = document.visibilityState === 'visible';
|
|
256
|
+
setIsVisible(visible);
|
|
257
|
+
|
|
258
|
+
consoleFn('visible', visible);
|
|
259
|
+
if (!isOpen) return;
|
|
260
|
+
if (visible) {
|
|
261
|
+
consoleFn('socketRef.current', socketRef.current);
|
|
262
|
+
consoleFn('화면 켜짐 확인 - 재연결 시도');
|
|
263
|
+
if (!socketRef.current || socketRef.current.readyState !== WebSocket.OPEN) {
|
|
264
|
+
consoleFn('📱 포그라운드 전환 → 재연결 카운트 리셋 후 재시도');
|
|
265
|
+
reconnectCountRef.current = 0; // 카운트 리셋
|
|
266
|
+
reconnectWithNewTokenSocket();
|
|
267
|
+
} else {
|
|
268
|
+
consoleFn('socketRef.current 준비 상태');
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
document.addEventListener('visibilitychange', handleVisibilityChange);
|
|
273
|
+
return () => document.removeEventListener('visibilitychange', handleVisibilityChange);
|
|
274
|
+
}, [isOpen]);
|
|
275
|
+
|
|
276
|
+
const webSocketMessageHandler = useCallback((event: MessageEvent) => {
|
|
277
|
+
consoleFn('[DaeryuntalkContext] 웹소켓 메시지 수신됨');
|
|
278
|
+
try {
|
|
279
|
+
const data = typeof event === 'string' ? JSON.parse(event) : event;
|
|
280
|
+
consoleFn('socket data', data);
|
|
281
|
+
// 메시지 생성
|
|
282
|
+
if (data.type === MessageSocketType.MESSAGE_CREATED && data.payload?.message) {
|
|
283
|
+
const newMessage = convertApiMessageToUiMessage(data.payload.message, 'live');
|
|
284
|
+
setMessages(prev => {
|
|
285
|
+
const isDuplicate = prev.some(msg => msg.messageNumber === newMessage.messageNumber);
|
|
286
|
+
return isDuplicate ? prev : [...prev, newMessage];
|
|
287
|
+
});
|
|
288
|
+
closeTyping();
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (data.type === MessageSocketType.MESSAGE_UPDATED) {
|
|
292
|
+
const newMessage = convertApiMessageToUiMessage(data.payload.message, 'basic');
|
|
293
|
+
setMessages(prev => {
|
|
294
|
+
const index = prev.findIndex(msg => msg.messageNumber === newMessage.messageNumber);
|
|
295
|
+
|
|
296
|
+
if (index !== -1) {
|
|
297
|
+
// 기존 메시지가 있으면 해당 위치에 새 메시지로 교체
|
|
298
|
+
const updated = [...prev];
|
|
299
|
+
updated[index] = newMessage;
|
|
300
|
+
return updated;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// 없으면 새 메시지를 추가
|
|
304
|
+
return [...prev, newMessage];
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
// 메세지 회수됨 -> 이거는 관리자에서는 필요없는듯?
|
|
308
|
+
if (data.type === MessageSocketType.MESSAGE_COLLECTED) {
|
|
309
|
+
// 여기서는
|
|
310
|
+
const payload: {
|
|
311
|
+
chat_inquiry_number: string;
|
|
312
|
+
message_number: string;
|
|
313
|
+
} = data.payload;
|
|
314
|
+
setMessages(prev => prev.filter(fil => fil.messageNumber !== payload.message_number));
|
|
315
|
+
}
|
|
316
|
+
// 안읽음 count
|
|
317
|
+
if (data.type === MessageSocketType.INQUIRY_PREVIEW_UPDATED) {
|
|
318
|
+
const socketData: {
|
|
319
|
+
chat_inquiry_number: string;
|
|
320
|
+
recent_message_content: string;
|
|
321
|
+
recent_message_date_time: string;
|
|
322
|
+
unread_message_count: string;
|
|
323
|
+
} = data?.payload;
|
|
324
|
+
|
|
325
|
+
setHistoryList((prev): History[] =>
|
|
326
|
+
prev.map(item =>
|
|
327
|
+
item.chat_inquiry_number === socketData.chat_inquiry_number
|
|
328
|
+
? ({
|
|
329
|
+
chat_inquiry_number: socketData.chat_inquiry_number,
|
|
330
|
+
customer_name: item.customer_name,
|
|
331
|
+
recent_message_content: socketData.recent_message_content,
|
|
332
|
+
recent_message_date_time: socketData.recent_message_date_time,
|
|
333
|
+
unread_message_count: Number(socketData.unread_message_count)
|
|
334
|
+
} as History)
|
|
335
|
+
: item
|
|
336
|
+
)
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
// 새로운 문의가 생성됨
|
|
340
|
+
if (data.type === MessageSocketType.INQUIRY_OPENED) {
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// 문의 워크플로우 변경됨
|
|
344
|
+
if (data.type === MessageSocketType.INQUIRY_WORKFLOW_UPDATED) {
|
|
345
|
+
const socketPayloadData = data?.payload as IInquiryWorkFlowUpdate;
|
|
346
|
+
// 워크플로우 스택 업데이트
|
|
347
|
+
setWorkFlowStack(socketPayloadData.work_flow_progress_stack);
|
|
348
|
+
// 오브젝트 업데이트
|
|
349
|
+
setMessageObject(convertSocketObjectToUiMessage(data?.payload));
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// 문의가 종료됨
|
|
353
|
+
if (data.type === MessageSocketType.INQUIRY_CLOSED) {
|
|
354
|
+
setInquiryStatus(InquiryStatusEnum.CLOSED);
|
|
355
|
+
}
|
|
356
|
+
// 업무 관리자 배정
|
|
357
|
+
if (data.type === MessageSocketType.INQUIRY_ASSIGNED) {
|
|
358
|
+
const payload: {
|
|
359
|
+
chat_inquiry_number: string;
|
|
360
|
+
operator_number: string;
|
|
361
|
+
} = data.payload;
|
|
362
|
+
}
|
|
363
|
+
// 할당된 상담원이 해제됨
|
|
364
|
+
if (data.type === MessageSocketType.INQUIRY_UNASSIGNED) {
|
|
365
|
+
}
|
|
366
|
+
// 고객 정보가 갱신됨
|
|
367
|
+
if (data.type === MessageSocketType.CUSTOMER_INFO_UPDATED) {
|
|
368
|
+
}
|
|
369
|
+
// 오퍼레이터 타이핑 이벤트
|
|
370
|
+
if (data.type === MessageSocketType.TYPING_STARTED) {
|
|
371
|
+
const payload: {
|
|
372
|
+
chat_inquiry_number: string;
|
|
373
|
+
user_key: string;
|
|
374
|
+
} = data.payload;
|
|
375
|
+
handleTypingStarted();
|
|
376
|
+
}
|
|
377
|
+
if (data.type === MessageSocketType.USER_EXPIRED) {
|
|
378
|
+
setIsUserExpried(true);
|
|
379
|
+
localStorage.removeItem('daeryunchatinquirytoken');
|
|
380
|
+
}
|
|
381
|
+
} catch (error) {
|
|
382
|
+
console.error('[DaeryuntalkContext] 웹소켓 메시지 처리 오류:', error);
|
|
383
|
+
}
|
|
384
|
+
}, []);
|
|
385
|
+
|
|
386
|
+
/** util: 소켓 정리 */
|
|
387
|
+
const cleanupWebSocketInstance = useCallback((socket: WebSocket | null) => {
|
|
388
|
+
if (!socket) return;
|
|
389
|
+
socket.onopen = null;
|
|
390
|
+
socket.onclose = null;
|
|
391
|
+
socket.onmessage = null;
|
|
392
|
+
socket.onerror = null;
|
|
393
|
+
try {
|
|
394
|
+
socket.close();
|
|
395
|
+
} catch {}
|
|
396
|
+
}, []);
|
|
397
|
+
|
|
398
|
+
/** util: 소켓 재연결 (새 토큰 발급 후 재연결) */
|
|
399
|
+
const reconnectWithNewTokenSocket = useCallback(async () => {
|
|
400
|
+
consoleFn('재연결 시도');
|
|
401
|
+
// 화면 꺼진 경우 재연결 X
|
|
402
|
+
if (!isVisible) return;
|
|
403
|
+
|
|
404
|
+
// 재연결 중이면 중복 방지
|
|
405
|
+
if (isSocketReconnectingRef.current) return;
|
|
406
|
+
|
|
407
|
+
try {
|
|
408
|
+
// 최대 시도 횟수 초과 시 종료
|
|
409
|
+
if (reconnectCountRef.current >= maxReconnectAttempts) {
|
|
410
|
+
consoleFn('❌ 재연결 최대 횟수 초과, 더 이상 시도하지 않음');
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
reconnectCountRef.current++;
|
|
415
|
+
consoleFn(`[DaeryuntalkContext] 소켓 재연결 시도 ${reconnectCountRef.current}회...`);
|
|
416
|
+
|
|
417
|
+
// 기존 소켓 정리
|
|
418
|
+
if (socketRef.current) {
|
|
419
|
+
cleanupWebSocketInstance(socketRef.current);
|
|
420
|
+
socketRef.current = null;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
isSocketReconnectingRef.current = true;
|
|
424
|
+
|
|
425
|
+
// 새 토큰 발급
|
|
426
|
+
const wsInitData = await initializeWebSocket();
|
|
427
|
+
|
|
428
|
+
if (wsInitData?.result_info?.result_cd === 'OK' || wsInitData?.result_info?.result_type_cd === 'OK') {
|
|
429
|
+
const socket = connectWebSocket(
|
|
430
|
+
wsInitData.data.connection_url,
|
|
431
|
+
wsInitData.data.connection_token,
|
|
432
|
+
true,
|
|
433
|
+
setIsConnected,
|
|
434
|
+
userExpiredRef,
|
|
435
|
+
webSocketMessageHandler, // onMessage
|
|
436
|
+
() => {
|
|
437
|
+
// onOpen
|
|
438
|
+
consoleFn('[DaeryuntalkContext] 웹소켓 연결 콜백 - 연결 성공');
|
|
439
|
+
setIsConnected(true);
|
|
440
|
+
isSocketReconnectingRef.current = false; // 성공 시 초기화
|
|
441
|
+
setInitialLoading(false);
|
|
442
|
+
if (chatInquiryNumberRef.current) {
|
|
443
|
+
sendInquiryJoined(chatInquiryNumberRef.current || '');
|
|
444
|
+
sendInquiryWatching(chatInquiryNumberRef.current || '');
|
|
445
|
+
}
|
|
446
|
+
},
|
|
447
|
+
() => {
|
|
448
|
+
// onClose
|
|
449
|
+
consoleFn('[DaeryuntalkContext] 웹소켓 연결 콜백 - 연결 종료');
|
|
450
|
+
setIsConnected(false);
|
|
451
|
+
isSocketReconnectingRef.current = false; // 실패 시 초기화
|
|
452
|
+
setTimeout(() => reconnectWithNewTokenSocket(), reconnectDelay);
|
|
453
|
+
},
|
|
454
|
+
event => {
|
|
455
|
+
// onError
|
|
456
|
+
console.error('[DaeryuntalkContext] 웹소켓 오류:', event);
|
|
457
|
+
setIsConnected(false);
|
|
458
|
+
isSocketReconnectingRef.current = false; // 오류 시 초기화
|
|
459
|
+
setTimeout(() => reconnectWithNewTokenSocket(), reconnectDelay);
|
|
460
|
+
}
|
|
461
|
+
);
|
|
462
|
+
socketRef.current = socket;
|
|
463
|
+
|
|
464
|
+
if (chatInquiryNumberRef.current) {
|
|
465
|
+
consoleFn('chatList 실행');
|
|
466
|
+
const chatList = await getChatInquiryMessageList(chatInquiryNumberRef.current || '');
|
|
467
|
+
if (chatList.result_info.result_cd === 'OK' || chatList.result_info.result_type_cd === 'OK') {
|
|
468
|
+
//
|
|
469
|
+
if (chatList.data?.message_list && chatList.data.message_list.length > 0) {
|
|
470
|
+
const uiMessages = chatList.data.message_list
|
|
471
|
+
.sort((a, b) => a.timestamp - b.timestamp)
|
|
472
|
+
.map(item => {
|
|
473
|
+
return convertApiMessageToUiMessage(item, 'basic');
|
|
474
|
+
});
|
|
475
|
+
setMessages(uiMessages);
|
|
476
|
+
consoleFn('[DaeryuntalkContext] 메시지 설정 완료:', uiMessages.length);
|
|
477
|
+
}
|
|
478
|
+
if (chatList.data?.next_page_yn !== null) {
|
|
479
|
+
setIsNextPage(chatList.data.next_page_yn);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
} else {
|
|
483
|
+
// console.log('chatInquiryNumber 없음')
|
|
484
|
+
}
|
|
485
|
+
} else {
|
|
486
|
+
// console.error("❌ 웹소켓 토큰 발급 실패:", wsInitData);
|
|
487
|
+
isSocketReconnectingRef.current = false; // ✅ 토큰 발급 실패도 초기화
|
|
488
|
+
setTimeout(() => reconnectWithNewTokenSocket(), reconnectDelay);
|
|
489
|
+
}
|
|
490
|
+
} catch (error) {
|
|
491
|
+
// console.error('[DaeryuntalkContext] 소켓 재연결 오류:', error);
|
|
492
|
+
isSocketReconnectingRef.current = false; // ✅ 예외 발생 시 초기화
|
|
493
|
+
setTimeout(() => reconnectWithNewTokenSocket(), reconnectDelay);
|
|
494
|
+
}
|
|
495
|
+
}, [cleanupWebSocketInstance, chatInquiryNumber]);
|
|
496
|
+
|
|
497
|
+
const handleTypingStarted = () => {
|
|
498
|
+
openTyping();
|
|
499
|
+
|
|
500
|
+
if (typingTimeoutRef.current) {
|
|
501
|
+
clearTimeout(typingTimeoutRef.current);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// 일정 시간 타이핑 이벤트 없으면 UI 제거
|
|
505
|
+
typingTimeoutRef.current = setTimeout(() => {
|
|
506
|
+
setIsTyping(false);
|
|
507
|
+
}, 3000);
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
// Daeryuntalk API 초기화 메소드
|
|
511
|
+
const initializeDaeryuntalk = useCallback(
|
|
512
|
+
async (hashValue: string | null, isOpen: boolean, centerCode: string, version?: string) => {
|
|
513
|
+
if (userExpiredRef.current) {
|
|
514
|
+
consoleFn('유저 만료 상태로 초기화 X');
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
consoleFn('[DaeryuntalkContext] 초기화 메소드 호출됨', version ? `버전: ${version}` : '기본 버전 사용');
|
|
518
|
+
try {
|
|
519
|
+
// setIsLoading(true);
|
|
520
|
+
// consoleFn('[DaeryuntalkContext] 로딩 상태 설정: true');
|
|
521
|
+
|
|
522
|
+
const { inquiryData, socket, hashAuth, errorCode } = await apiInitializeDaeryuntalk(
|
|
523
|
+
hashValue || '',
|
|
524
|
+
isOpen,
|
|
525
|
+
setIsConnected,
|
|
526
|
+
isMobile,
|
|
527
|
+
centerCode,
|
|
528
|
+
userExpiredRef,
|
|
529
|
+
socket => {
|
|
530
|
+
consoleFn('[DaeryuntalkContext] 웹소켓 연결 콜백 - 연결 성공');
|
|
531
|
+
setIsConnected(true);
|
|
532
|
+
setInitialLoading(true);
|
|
533
|
+
},
|
|
534
|
+
event => {
|
|
535
|
+
// onMessage
|
|
536
|
+
webSocketMessageHandler(event);
|
|
537
|
+
},
|
|
538
|
+
event => {
|
|
539
|
+
// onClose
|
|
540
|
+
consoleFn('[DaeryuntalkContext] 웹소켓 연결 콜백 - 연결 실패');
|
|
541
|
+
setIsConnected(false);
|
|
542
|
+
setTimeout(() => reconnectWithNewTokenSocket(), reconnectDelay);
|
|
543
|
+
},
|
|
544
|
+
event => {
|
|
545
|
+
// onError
|
|
546
|
+
console.error('[DaeryuntalkContext] 웹소켓 오류:', event);
|
|
547
|
+
setIsConnected(false);
|
|
548
|
+
setTimeout(() => reconnectWithNewTokenSocket(), reconnectDelay);
|
|
549
|
+
}
|
|
550
|
+
);
|
|
551
|
+
const response = await getHistoryList({ version });
|
|
552
|
+
if (response.result_info.result_cd === 'OK' || response.result_info.result_type_cd === 'OK') {
|
|
553
|
+
setIsAuthenticated?.(true);
|
|
554
|
+
setHistoryList?.(response.data.chat_inquiry_list ?? []);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
if (errorCode || !inquiryData || !socket) {
|
|
558
|
+
errorCode && toast.error(getErrorMessageMap(errorCode));
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
if (hashValue) {
|
|
562
|
+
if (hashAuth?.result_info?.result_cd === 'OK' || hashAuth?.result_info?.result_type_cd === 'OK') {
|
|
563
|
+
consoleFn('해쉬 인증 완료');
|
|
564
|
+
} else {
|
|
565
|
+
toast.error('링크가 만료되었거나 존재하지 않습니다.');
|
|
566
|
+
setTimeout(() => {
|
|
567
|
+
onClose();
|
|
568
|
+
window.location.href = '/';
|
|
569
|
+
}, 500);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
if (
|
|
574
|
+
!(inquiryData?.result_info?.result_cd === 'OK' || inquiryData?.result_info?.result_type_cd === 'OK')
|
|
575
|
+
) {
|
|
576
|
+
inquiryData && toast.error(getErrorMessageMap(inquiryData));
|
|
577
|
+
return inquiryData;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
let detailResponse = null;
|
|
581
|
+
let chatList = null;
|
|
582
|
+
let chatNumber = '';
|
|
583
|
+
// 기존 문의가 있는 경우
|
|
584
|
+
if (inquiryData.data?.progress_inquiry_number) {
|
|
585
|
+
chatNumber = inquiryData.data?.progress_inquiry_number;
|
|
586
|
+
detailResponse = await getChatInquiryDetailNew(inquiryData.data?.progress_inquiry_number);
|
|
587
|
+
|
|
588
|
+
chatList = await getChatInquiryMessageList(inquiryData.data?.progress_inquiry_number);
|
|
589
|
+
}
|
|
590
|
+
// 기존 문의가 없는 경우
|
|
591
|
+
else {
|
|
592
|
+
// 채팅 생성
|
|
593
|
+
const createResponse = await generateChatInquiry(
|
|
594
|
+
inquiryData.data?.channel_number || '',
|
|
595
|
+
fullUrl,
|
|
596
|
+
centerCode
|
|
597
|
+
);
|
|
598
|
+
if (
|
|
599
|
+
!(
|
|
600
|
+
createResponse.result_info.result_cd === 'OK' ||
|
|
601
|
+
createResponse.result_info.result_type_cd === 'OK'
|
|
602
|
+
)
|
|
603
|
+
) {
|
|
604
|
+
toast.error(getErrorMessageMap(createResponse));
|
|
605
|
+
return createResponse;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
chatNumber = createResponse?.data?.chat_inquiry_number || '';
|
|
609
|
+
// 채팅 상세 조회
|
|
610
|
+
detailResponse = await getChatInquiryDetailNew(chatNumber);
|
|
611
|
+
// 채팅 메시지 리스트 조회
|
|
612
|
+
chatList = await getChatInquiryMessageList(chatNumber);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
if (
|
|
616
|
+
!(
|
|
617
|
+
detailResponse?.result_info?.result_cd === 'OK' ||
|
|
618
|
+
detailResponse?.result_info?.result_type_cd === 'OK'
|
|
619
|
+
)
|
|
620
|
+
) {
|
|
621
|
+
toast.error(getErrorMessageMap(detailResponse));
|
|
622
|
+
return detailResponse;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
if (!(chatList?.result_info?.result_cd === 'OK' || chatList?.result_info?.result_type_cd === 'OK')) {
|
|
626
|
+
toast.error(getErrorMessageMap(chatList));
|
|
627
|
+
return chatList;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
setChatInquiryNumber(chatNumber);
|
|
631
|
+
if (chatList.data.message_list.length > 0) {
|
|
632
|
+
const uiMessages = chatList.data.message_list
|
|
633
|
+
.sort((a, b) => a.timestamp - b.timestamp)
|
|
634
|
+
.map(item => {
|
|
635
|
+
return convertApiMessageToUiMessage(item, 'basic');
|
|
636
|
+
});
|
|
637
|
+
setMessages(uiMessages);
|
|
638
|
+
consoleFn('[DaeryuntalkContext] 메시지 설정 완료:', uiMessages.length);
|
|
639
|
+
}
|
|
640
|
+
if (chatList.data?.next_page_yn !== null) {
|
|
641
|
+
setIsNextPage(chatList.data.next_page_yn);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
// 해당 문의 오브젝트
|
|
645
|
+
if (detailResponse.data?.object_expose_info) {
|
|
646
|
+
const uiObject = convertApiMessageObjectToUiMessageObject(detailResponse.data);
|
|
647
|
+
setMessageObject(uiObject);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// 해당 문의 연령 체크
|
|
651
|
+
if (detailResponse.data?.age_consent_state_code) {
|
|
652
|
+
setAgeCheckStatus(detailResponse.data.age_consent_state_code);
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
// 해당 문의 상태
|
|
656
|
+
if (detailResponse.data?.chat_inquiry_state_code) {
|
|
657
|
+
setInquiryStatus(detailResponse.data.chat_inquiry_state_code);
|
|
658
|
+
}
|
|
659
|
+
// 워크플로우 스택 업데이트
|
|
660
|
+
if (detailResponse.data?.work_flow_progress_stack) {
|
|
661
|
+
setWorkFlowStack(detailResponse.data?.work_flow_progress_stack ?? []);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
setInquiryMainData({ ...inquiryData.data, progress_inquiry_number: chatNumber });
|
|
665
|
+
if (socket) {
|
|
666
|
+
socketRef.current = socket;
|
|
667
|
+
}
|
|
668
|
+
} catch (error) {
|
|
669
|
+
console.error('[DaeryuntalkContext] 초기화 오류:', error);
|
|
670
|
+
} finally {
|
|
671
|
+
consoleFn('[DaeryuntalkContext] 로딩 상태 설정: false');
|
|
672
|
+
// setIsLoading(false);
|
|
673
|
+
}
|
|
674
|
+
},
|
|
675
|
+
[historyList]
|
|
676
|
+
);
|
|
677
|
+
|
|
678
|
+
// C2121045680881362573
|
|
679
|
+
const retryInquiryMain = useCallback(
|
|
680
|
+
async (channelNumber: string) => {
|
|
681
|
+
const result = await getChatInquiryMain(channelNumber || '');
|
|
682
|
+
setInquiryMainData(result.data as IChatInquiryMainDataResponse);
|
|
683
|
+
return result;
|
|
684
|
+
},
|
|
685
|
+
[inquiryMainData]
|
|
686
|
+
);
|
|
687
|
+
const retryInitData = useCallback(async () => {
|
|
688
|
+
const authRes = await authenticateUser(centerCode);
|
|
689
|
+
const result = await getChatInquiryMain(authRes.data.channel_number);
|
|
690
|
+
setInquiryMainData(result.data as IChatInquiryMainDataResponse);
|
|
691
|
+
}, []);
|
|
692
|
+
|
|
693
|
+
return {
|
|
694
|
+
initializeDaeryuntalk,
|
|
695
|
+
|
|
696
|
+
sendInquiryWatching,
|
|
697
|
+
retryInquiryMain,
|
|
698
|
+
retryInitData,
|
|
699
|
+
|
|
700
|
+
sendHeartbeat,
|
|
701
|
+
sendInquiryJoined,
|
|
702
|
+
sendInquiryLeft,
|
|
703
|
+
sendHistoryEntered,
|
|
704
|
+
sendHistoryLeft
|
|
705
|
+
};
|
|
706
|
+
};
|