@daeryun/dr_components 0.8.26 → 0.8.28
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 +29 -14
- package/dist/components/Daeryuntalk/ChatButton.tsx +17 -14
- package/dist/components/Daeryuntalk/ChatHomeView.jsx +42 -11
- package/dist/components/Daeryuntalk/ChatHomeView.tsx +41 -12
- package/dist/components/Daeryuntalk/ChatItem/RichText.jsx +12 -2
- package/dist/components/Daeryuntalk/ChatItem/RichText.tsx +14 -2
- package/dist/components/Daeryuntalk/ChatMessage.jsx +2 -2
- package/dist/components/Daeryuntalk/ChatMessage.tsx +2 -2
- package/dist/components/Daeryuntalk/DaeryuntalkContext.d.ts +2 -1
- package/dist/components/Daeryuntalk/DaeryuntalkContext.jsx +7 -4
- package/dist/components/Daeryuntalk/DaeryuntalkContext.tsx +10 -5
- package/dist/components/Daeryuntalk/_api/daeryuntalk/index.d.ts +1 -11
- package/dist/components/Daeryuntalk/_api/daeryuntalk/index.js +87 -59
- package/dist/components/Daeryuntalk/_api/daeryuntalk/index.ts +100 -61
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useChatHandler.d.ts +3 -1
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useChatHandler.js +7 -4
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useChatHandler.ts +91 -84
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useSocketEventHandler.d.ts +3 -1
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useSocketEventHandler.js +11 -3
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useSocketEventHandler.ts +21 -3
- package/dist/components/Daeryuntalk/_types/message.js +1 -2
- package/dist/components/Daeryuntalk/_types/message.ts +1 -2
- package/dist/styles/globals.css +4 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -16,6 +16,7 @@ import { useScrollShadow } from './_hooks/useScrollShadow';
|
|
|
16
16
|
import ShadowBox from './_ui/ShadowBox';
|
|
17
17
|
import { useDaeryunTalkToast } from './Toast/DaeryuntalkToastProvider';
|
|
18
18
|
import ToastRenderer from './Toast/ToastRender';
|
|
19
|
+
import { getChatInquiryMain } from './_api';
|
|
19
20
|
|
|
20
21
|
type ViewState = 'home' | 'conversation' | 'history';
|
|
21
22
|
|
|
@@ -41,8 +42,10 @@ const ChatHomeView: React.FC<ChatHomeViewProps> = ({ hashValue, setHashValue, is
|
|
|
41
42
|
goGetHistoryList,
|
|
42
43
|
sendHistoryEntered,
|
|
43
44
|
startSelectedChat,
|
|
44
|
-
attendRoomByHistory
|
|
45
|
+
attendRoomByHistory,
|
|
46
|
+
retryInquiryMain
|
|
45
47
|
} = useDaeryuntalk();
|
|
48
|
+
|
|
46
49
|
const [viewState, setViewState] = useState<ViewState>('home');
|
|
47
50
|
const [mainData, setMainData] = useState<IChatInquiryMainDataResponse | null>(null);
|
|
48
51
|
const [isLoading, setIsLoading] = useState(false);
|
|
@@ -53,8 +56,31 @@ const ChatHomeView: React.FC<ChatHomeViewProps> = ({ hashValue, setHashValue, is
|
|
|
53
56
|
const handleStartChat = async () => {
|
|
54
57
|
try {
|
|
55
58
|
setIsLoading(true);
|
|
59
|
+
const res = await retryInquiryMain(mainData?.channel_number || '');
|
|
60
|
+
if (res?.result_info?.result_cd === 'OK' || res?.result_info?.result_type_cd === 'OK') {
|
|
61
|
+
// 여기서 짚어넣고 main
|
|
62
|
+
// 채팅 시작 - 새 문의 생성 또는 기존 문의 조회 처리
|
|
63
|
+
//
|
|
64
|
+
const startRes = await startChat(res?.data?.progress_inquiry_number);
|
|
65
|
+
if (startRes) {
|
|
66
|
+
// 대화 화면으로 전환
|
|
67
|
+
setViewState('conversation');
|
|
68
|
+
} else {
|
|
69
|
+
toast.error('문의 시작에 실패했습니다.');
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
toast.error('채팅문의 시작에 실패했습니다.');
|
|
73
|
+
}
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.error('채팅 시작 실패:', error);
|
|
76
|
+
} finally {
|
|
77
|
+
setIsLoading(false);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
56
80
|
|
|
57
|
-
|
|
81
|
+
const handleHashStartChat = async () => {
|
|
82
|
+
try {
|
|
83
|
+
setIsLoading(true);
|
|
58
84
|
await startChat();
|
|
59
85
|
// 대화 화면으로 전환
|
|
60
86
|
setViewState('conversation');
|
|
@@ -66,32 +92,35 @@ const ChatHomeView: React.FC<ChatHomeViewProps> = ({ hashValue, setHashValue, is
|
|
|
66
92
|
};
|
|
67
93
|
|
|
68
94
|
useEffect(() => {
|
|
69
|
-
if (hashValue && isConnected && inquiryMainData) {
|
|
95
|
+
if (hashValue && isConnected && inquiryMainData && inquiryMainData.channel_number) {
|
|
70
96
|
console.log('해쉬 실행');
|
|
71
|
-
|
|
97
|
+
handleHashStartChat();
|
|
72
98
|
} else {
|
|
73
99
|
console.log('해쉬 실행안함');
|
|
74
100
|
}
|
|
75
101
|
}, [hashValue, isConnected, inquiryMainData]);
|
|
102
|
+
|
|
103
|
+
//
|
|
76
104
|
useEffect(() => {
|
|
77
105
|
checkScroll();
|
|
78
106
|
}, [mainData]);
|
|
79
107
|
|
|
80
|
-
|
|
81
|
-
if (viewState === 'history') {
|
|
82
|
-
goGetHistoryList({});
|
|
83
|
-
}
|
|
84
|
-
}, [viewState]);
|
|
85
|
-
|
|
108
|
+
//
|
|
86
109
|
useEffect(() => {
|
|
87
110
|
if (inquiryMainData) {
|
|
88
111
|
setMainData(inquiryMainData);
|
|
89
112
|
}
|
|
90
113
|
}, [inquiryMainData]);
|
|
91
114
|
|
|
115
|
+
// 히스토리 진입 시
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
if (isAuthenticated && viewState === 'history') {
|
|
118
|
+
goGetHistoryList({});
|
|
119
|
+
}
|
|
120
|
+
}, [viewState, isAuthenticated]);
|
|
121
|
+
// 소켓
|
|
92
122
|
useEffect(() => {
|
|
93
|
-
if (isConnected && isAuthenticated) {
|
|
94
|
-
console.log('history entered', historyList);
|
|
123
|
+
if (isConnected && isAuthenticated && viewState === 'history') {
|
|
95
124
|
sendHistoryEntered(historyList ? historyList.map(item => item.chat_inquiry_number) : []);
|
|
96
125
|
}
|
|
97
126
|
}, [isConnected, isAuthenticated, historyList, viewState]);
|
|
@@ -11,7 +11,9 @@ const RichText = ({ message }) => {
|
|
|
11
11
|
extensions: [
|
|
12
12
|
StarterKit,
|
|
13
13
|
Image,
|
|
14
|
-
Link.configure({
|
|
14
|
+
Link.configure({
|
|
15
|
+
openOnClick: true
|
|
16
|
+
}),
|
|
15
17
|
TextStyle,
|
|
16
18
|
Color.configure({
|
|
17
19
|
types: ['textStyle']
|
|
@@ -20,6 +22,14 @@ const RichText = ({ message }) => {
|
|
|
20
22
|
content: (_a = message.richText) === null || _a === void 0 ? void 0 : _a.structuredData,
|
|
21
23
|
editable: false
|
|
22
24
|
});
|
|
23
|
-
return <
|
|
25
|
+
return (<div className="tiptap prose">
|
|
26
|
+
<EditorContent editor={editor}/>
|
|
27
|
+
<style>{`
|
|
28
|
+
.tiptap a {
|
|
29
|
+
color: #2563eb; /* Tailwind blue-600 */
|
|
30
|
+
text-decoration: underline;
|
|
31
|
+
}
|
|
32
|
+
`}</style>
|
|
33
|
+
</div>);
|
|
24
34
|
};
|
|
25
35
|
export default RichText;
|
|
@@ -16,7 +16,9 @@ const RichText = ({ message }: props) => {
|
|
|
16
16
|
extensions: [
|
|
17
17
|
StarterKit,
|
|
18
18
|
Image,
|
|
19
|
-
Link.configure({
|
|
19
|
+
Link.configure({
|
|
20
|
+
openOnClick: true
|
|
21
|
+
}),
|
|
20
22
|
TextStyle,
|
|
21
23
|
Color.configure({
|
|
22
24
|
types: ['textStyle']
|
|
@@ -26,7 +28,17 @@ const RichText = ({ message }: props) => {
|
|
|
26
28
|
editable: false
|
|
27
29
|
});
|
|
28
30
|
|
|
29
|
-
return
|
|
31
|
+
return (
|
|
32
|
+
<div className="tiptap prose">
|
|
33
|
+
<EditorContent editor={editor} />
|
|
34
|
+
<style>{`
|
|
35
|
+
.tiptap a {
|
|
36
|
+
color: #2563eb; /* Tailwind blue-600 */
|
|
37
|
+
text-decoration: underline;
|
|
38
|
+
}
|
|
39
|
+
`}</style>
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
30
42
|
};
|
|
31
43
|
|
|
32
44
|
export default RichText;
|
|
@@ -51,7 +51,7 @@ const ChatMessage = ({ message, object, handelObjectBack, chatInquiryNumber, wor
|
|
|
51
51
|
const isFile = hasFileArray(message);
|
|
52
52
|
if (isFile) {
|
|
53
53
|
return (<div className={`flex flex-col gap-[10px]`}>
|
|
54
|
-
{isRichForm && (<div className={`flex flex-row items-end gap-[4px]`}>
|
|
54
|
+
{isRichForm && (<div className={`flex flex-row items-end gap-[4px] `}>
|
|
55
55
|
<ChatWrapper isOperator={isOperator}>
|
|
56
56
|
<RichText message={message}/>
|
|
57
57
|
</ChatWrapper>
|
|
@@ -84,7 +84,7 @@ const ChatMessage = ({ message, object, handelObjectBack, chatInquiryNumber, wor
|
|
|
84
84
|
}
|
|
85
85
|
if (isRichForm) {
|
|
86
86
|
return (<div className={`flex flex-row items-end gap-[4px]`}>
|
|
87
|
-
<ChatWrapper isOperator={isOperator}>
|
|
87
|
+
<ChatWrapper isOperator={isOperator} className={`w-[calc(100%-31.25px)]`}>
|
|
88
88
|
<RichText message={message}/>
|
|
89
89
|
</ChatWrapper>
|
|
90
90
|
<div className={`text-[12px] font-[400] text-[#C2C2C2]`}>{time}</div>
|
|
@@ -88,7 +88,7 @@ const ChatMessage: React.FC<ChatMessageProps> = ({
|
|
|
88
88
|
return (
|
|
89
89
|
<div className={`flex flex-col gap-[10px]`}>
|
|
90
90
|
{isRichForm && (
|
|
91
|
-
<div className={`flex flex-row items-end gap-[4px]`}>
|
|
91
|
+
<div className={`flex flex-row items-end gap-[4px] `}>
|
|
92
92
|
<ChatWrapper isOperator={isOperator}>
|
|
93
93
|
<RichText message={message} />
|
|
94
94
|
</ChatWrapper>
|
|
@@ -131,7 +131,7 @@ const ChatMessage: React.FC<ChatMessageProps> = ({
|
|
|
131
131
|
if (isRichForm) {
|
|
132
132
|
return (
|
|
133
133
|
<div className={`flex flex-row items-end gap-[4px]`}>
|
|
134
|
-
<ChatWrapper isOperator={isOperator}>
|
|
134
|
+
<ChatWrapper isOperator={isOperator} className={`w-[calc(100%-31.25px)]`}>
|
|
135
135
|
<RichText message={message} />
|
|
136
136
|
</ChatWrapper>
|
|
137
137
|
<div className={`text-[12px] font-[400] text-[#C2C2C2]`}>{time}</div>
|
|
@@ -11,7 +11,7 @@ type DaeryuntalkContextType = {
|
|
|
11
11
|
isLoading: boolean;
|
|
12
12
|
sendMessage: (htmlContent: string, jsonData: any) => void;
|
|
13
13
|
initializeDaeryuntalk: (hashValue: string, version?: string) => void;
|
|
14
|
-
startChat: () => Promise<
|
|
14
|
+
startChat: (inquiryNumber?: string) => Promise<any>;
|
|
15
15
|
createNewChat: () => void;
|
|
16
16
|
startWorkFlow: (data: {
|
|
17
17
|
chatInquiryNumber: string;
|
|
@@ -70,6 +70,7 @@ type DaeryuntalkContextType = {
|
|
|
70
70
|
startSelectedChat: (chatInquiryNumbers: string) => void;
|
|
71
71
|
sendInquiryJoined: (chatInquiryNumber: string) => void;
|
|
72
72
|
attendRoomByHistory: (chatInquiryNumber: string) => any;
|
|
73
|
+
retryInquiryMain: (channelNumber: string) => any;
|
|
73
74
|
};
|
|
74
75
|
declare const DaeryuntalkContext: React.Context<DaeryuntalkContextType>;
|
|
75
76
|
type DaeryuntalkProviderProps = {
|
|
@@ -52,7 +52,8 @@ const DaeryuntalkContext = createContext({
|
|
|
52
52
|
sendHistoryLeft: () => { },
|
|
53
53
|
startSelectedChat: () => { },
|
|
54
54
|
sendInquiryJoined: () => { },
|
|
55
|
-
attendRoomByHistory: () => { }
|
|
55
|
+
attendRoomByHistory: () => { },
|
|
56
|
+
retryInquiryMain: () => { }
|
|
56
57
|
});
|
|
57
58
|
export const DaeryuntalkProvider = ({ children, propsTel }) => {
|
|
58
59
|
const [inquiryStatus, setInquiryStatus] = useState('');
|
|
@@ -73,7 +74,7 @@ export const DaeryuntalkProvider = ({ children, propsTel }) => {
|
|
|
73
74
|
// 히스토리 리스트
|
|
74
75
|
const [historyList, setHistoryList] = useState([]);
|
|
75
76
|
// 소켓 관련 API + 채팅 시작
|
|
76
|
-
const { initializeDaeryuntalk, sendHeartbeat, sendInquiryJoined, sendInquiryLeft, sendHistoryEntered, sendHistoryLeft, sendInquiryWatching } = useSocketEventHandler({
|
|
77
|
+
const { initializeDaeryuntalk, sendHeartbeat, sendInquiryJoined, sendInquiryLeft, sendHistoryEntered, sendHistoryLeft, sendInquiryWatching, retryInquiryMain } = useSocketEventHandler({
|
|
77
78
|
setIsConnected,
|
|
78
79
|
setIsLoading,
|
|
79
80
|
setMessages,
|
|
@@ -83,7 +84,8 @@ export const DaeryuntalkProvider = ({ children, propsTel }) => {
|
|
|
83
84
|
socketRef: socketRef,
|
|
84
85
|
setInquiryStatus,
|
|
85
86
|
setHistoryList,
|
|
86
|
-
historyList
|
|
87
|
+
historyList,
|
|
88
|
+
inquiryMainData
|
|
87
89
|
});
|
|
88
90
|
// MSG15591497825895676
|
|
89
91
|
// 채팅 관련
|
|
@@ -142,7 +144,8 @@ export const DaeryuntalkProvider = ({ children, propsTel }) => {
|
|
|
142
144
|
sendHistoryLeft,
|
|
143
145
|
startSelectedChat,
|
|
144
146
|
sendInquiryJoined,
|
|
145
|
-
attendRoomByHistory
|
|
147
|
+
attendRoomByHistory,
|
|
148
|
+
retryInquiryMain
|
|
146
149
|
}}>
|
|
147
150
|
{children}
|
|
148
151
|
</DaeryuntalkContext.Provider>);
|
|
@@ -17,7 +17,7 @@ type DaeryuntalkContextType = {
|
|
|
17
17
|
isLoading: boolean;
|
|
18
18
|
sendMessage: (htmlContent: string, jsonData: any) => void;
|
|
19
19
|
initializeDaeryuntalk: (hashValue: string, version?: string) => void;
|
|
20
|
-
startChat: () => Promise<
|
|
20
|
+
startChat: (inquiryNumber?: string) => Promise<any>;
|
|
21
21
|
createNewChat: () => void;
|
|
22
22
|
startWorkFlow: (data: {
|
|
23
23
|
chatInquiryNumber: string;
|
|
@@ -75,6 +75,7 @@ type DaeryuntalkContextType = {
|
|
|
75
75
|
startSelectedChat: (chatInquiryNumbers: string) => void;
|
|
76
76
|
sendInquiryJoined: (chatInquiryNumber: string) => void;
|
|
77
77
|
attendRoomByHistory: (chatInquiryNumber: string) => any;
|
|
78
|
+
retryInquiryMain: (channelNumber: string) => any;
|
|
78
79
|
};
|
|
79
80
|
|
|
80
81
|
// 기본값으로 컨텍스트 생성
|
|
@@ -117,7 +118,8 @@ const DaeryuntalkContext = createContext<DaeryuntalkContextType>({
|
|
|
117
118
|
sendHistoryLeft: () => {},
|
|
118
119
|
startSelectedChat: () => {},
|
|
119
120
|
sendInquiryJoined: () => {},
|
|
120
|
-
attendRoomByHistory: () => {}
|
|
121
|
+
attendRoomByHistory: () => {},
|
|
122
|
+
retryInquiryMain: () => {}
|
|
121
123
|
});
|
|
122
124
|
|
|
123
125
|
// 프로바이더 컴포넌트 생성
|
|
@@ -157,7 +159,8 @@ export const DaeryuntalkProvider: React.FC<DaeryuntalkProviderProps> = ({ childr
|
|
|
157
159
|
sendInquiryLeft,
|
|
158
160
|
sendHistoryEntered,
|
|
159
161
|
sendHistoryLeft,
|
|
160
|
-
sendInquiryWatching
|
|
162
|
+
sendInquiryWatching,
|
|
163
|
+
retryInquiryMain
|
|
161
164
|
} = useSocketEventHandler({
|
|
162
165
|
setIsConnected,
|
|
163
166
|
setIsLoading,
|
|
@@ -168,7 +171,8 @@ export const DaeryuntalkProvider: React.FC<DaeryuntalkProviderProps> = ({ childr
|
|
|
168
171
|
socketRef: socketRef,
|
|
169
172
|
setInquiryStatus,
|
|
170
173
|
setHistoryList,
|
|
171
|
-
historyList
|
|
174
|
+
historyList,
|
|
175
|
+
inquiryMainData
|
|
172
176
|
});
|
|
173
177
|
|
|
174
178
|
// MSG15591497825895676
|
|
@@ -245,7 +249,8 @@ export const DaeryuntalkProvider: React.FC<DaeryuntalkProviderProps> = ({ childr
|
|
|
245
249
|
sendHistoryLeft,
|
|
246
250
|
startSelectedChat,
|
|
247
251
|
sendInquiryJoined,
|
|
248
|
-
attendRoomByHistory
|
|
252
|
+
attendRoomByHistory,
|
|
253
|
+
retryInquiryMain
|
|
249
254
|
}}
|
|
250
255
|
>
|
|
251
256
|
{children}
|
|
@@ -28,17 +28,7 @@ export declare function authenticateUser(centerCode: string, version?: string):
|
|
|
28
28
|
* @returns 연결 URL과 토큰이 포함된 웹소켓 초기화 데이터
|
|
29
29
|
*/
|
|
30
30
|
export declare function initializeWebSocket(version?: string): Promise<IDaeryunTalkResponseWrapper<WebSocketInitDataResponse>>;
|
|
31
|
-
|
|
32
|
-
* 웹소켓 연결
|
|
33
|
-
* @param wsUrl 웹소켓 URL
|
|
34
|
-
* @param token 연결 토큰
|
|
35
|
-
* @param onMessage 메시지 핸들러
|
|
36
|
-
* @param onOpen 연결 열림 핸들러
|
|
37
|
-
* @param onClose 연결 닫힘 핸들러
|
|
38
|
-
* @param onError 오류 핸들러
|
|
39
|
-
* @returns 웹소켓 인스턴스
|
|
40
|
-
*/
|
|
41
|
-
export declare function connectWebSocket(wsUrl: string, token: string, onMessage?: (event: MessageEvent) => void, onOpen?: (event: Event) => void, onClose?: (event: CloseEvent) => void, onError?: (event: Event) => void): WebSocket;
|
|
31
|
+
export declare function connectWebSocket(wsUrl: string, token: string, onMessage?: (event: MessageEvent) => void, onOpen?: (event: Event) => void, onClose?: (event: CloseEvent) => void, onError?: (event: Event) => void, onReconnectFail?: () => void): WebSocket;
|
|
42
32
|
/**
|
|
43
33
|
* 채팅 문의 메인 조회
|
|
44
34
|
* @param channelNumber 전달받은 채널
|
|
@@ -218,41 +218,59 @@ export function initializeWebSocket(version) {
|
|
|
218
218
|
* @param onError 오류 핸들러
|
|
219
219
|
* @returns 웹소켓 인스턴스
|
|
220
220
|
*/
|
|
221
|
-
|
|
221
|
+
let reconnectAttempts = 0;
|
|
222
|
+
const MAX_RECONNECT_ATTEMPTS = 5;
|
|
223
|
+
const RECONNECT_DELAY_MS = 2000;
|
|
224
|
+
export function connectWebSocket(wsUrl, token, onMessage, onOpen, onClose, onError, onReconnectFail // 재연결 실패 후 알림
|
|
225
|
+
) {
|
|
222
226
|
// URL에 토큰을 파라미터로 추가
|
|
223
227
|
const connectionUrl = `${wsUrl}?token=${token}`;
|
|
224
228
|
console.log('[웹소켓 연결 시작] 연결 URL:', connectionUrl);
|
|
225
229
|
try {
|
|
226
230
|
const socket = new WebSocket(connectionUrl);
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
console.log('[웹소켓 메시지 수신]', event.data);
|
|
234
|
-
try {
|
|
235
|
-
const data = JSON.parse(event.data);
|
|
236
|
-
console.log('📩 New Message (parsed):', data);
|
|
237
|
-
}
|
|
238
|
-
catch (err) {
|
|
239
|
-
console.error('[웹소켓] JSON 파싱 오류:', err);
|
|
240
|
-
}
|
|
241
|
-
if (onMessage)
|
|
242
|
-
onMessage(event.data); // event 전체 넘기기 (event.data는 string)
|
|
243
|
-
};
|
|
244
|
-
if (onClose) {
|
|
245
|
-
socket.onclose = event => {
|
|
246
|
-
console.log('[웹소켓 연결 종료] 코드:', event.code, '사유:', event.reason);
|
|
247
|
-
onClose(event);
|
|
231
|
+
const setupSocketHandlers = (socket) => {
|
|
232
|
+
socket.onopen = event => {
|
|
233
|
+
console.log('[웹소켓 연결 성공]');
|
|
234
|
+
reconnectAttempts = 0;
|
|
235
|
+
if (onOpen)
|
|
236
|
+
onOpen(event);
|
|
248
237
|
};
|
|
249
|
-
|
|
250
|
-
|
|
238
|
+
socket.onmessage = event => {
|
|
239
|
+
console.log('[웹소켓 메시지 수신]', event.data);
|
|
240
|
+
try {
|
|
241
|
+
const data = JSON.parse(event.data);
|
|
242
|
+
console.log('📩 New Message (parsed):', data);
|
|
243
|
+
}
|
|
244
|
+
catch (err) {
|
|
245
|
+
console.error('[웹소켓] JSON 파싱 오류:', err);
|
|
246
|
+
}
|
|
247
|
+
if (onMessage)
|
|
248
|
+
onMessage(event.data);
|
|
249
|
+
};
|
|
250
|
+
socket.onclose = (event) => __awaiter(this, void 0, void 0, function* () {
|
|
251
|
+
console.warn('[웹소켓 종료]', event);
|
|
252
|
+
if (reconnectAttempts < MAX_RECONNECT_ATTEMPTS) {
|
|
253
|
+
reconnectAttempts++;
|
|
254
|
+
console.log(`[재연결 시도] ${reconnectAttempts}회... ${RECONNECT_DELAY_MS}ms 후`);
|
|
255
|
+
yield new Promise(res => setTimeout(res, RECONNECT_DELAY_MS));
|
|
256
|
+
socket = new WebSocket(connectionUrl);
|
|
257
|
+
setupSocketHandlers(socket); // 재귀 호출
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
console.error('[웹소켓 재연결 실패] 최대 재시도 초과');
|
|
261
|
+
if (onReconnectFail)
|
|
262
|
+
onReconnectFail();
|
|
263
|
+
if (onClose)
|
|
264
|
+
onClose(event);
|
|
265
|
+
}
|
|
266
|
+
});
|
|
251
267
|
socket.onerror = event => {
|
|
252
268
|
console.error('[웹소켓 오류]', event);
|
|
253
|
-
onError
|
|
269
|
+
if (onError)
|
|
270
|
+
onError(event);
|
|
254
271
|
};
|
|
255
|
-
}
|
|
272
|
+
};
|
|
273
|
+
setupSocketHandlers(socket);
|
|
256
274
|
return socket;
|
|
257
275
|
}
|
|
258
276
|
catch (error) {
|
|
@@ -375,6 +393,24 @@ export function getChatInquiryMessageList(chatInquiryNumber, standardDateTime, s
|
|
|
375
393
|
}
|
|
376
394
|
});
|
|
377
395
|
}
|
|
396
|
+
function retryable(fn_1) {
|
|
397
|
+
return __awaiter(this, arguments, void 0, function* (fn, maxAttempts = 3, delayMs = 1000, label = '') {
|
|
398
|
+
let attempt = 0;
|
|
399
|
+
while (attempt < maxAttempts) {
|
|
400
|
+
try {
|
|
401
|
+
return yield fn();
|
|
402
|
+
}
|
|
403
|
+
catch (error) {
|
|
404
|
+
attempt++;
|
|
405
|
+
console.warn(`[재시도] ${label} ${attempt}회 실패`, error);
|
|
406
|
+
if (attempt >= maxAttempts)
|
|
407
|
+
throw new Error(`${label} 최대 재시도 초과`);
|
|
408
|
+
yield new Promise(res => setTimeout(res, delayMs));
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
throw new Error(`${label} 실패`);
|
|
412
|
+
});
|
|
413
|
+
}
|
|
378
414
|
/**
|
|
379
415
|
* Daeryuntalk 초기화 완료 흐름
|
|
380
416
|
* 이 함수는 인증부터 웹소켓 연결까지 완전한 흐름을 처리
|
|
@@ -387,48 +423,40 @@ export function initializeDaeryuntalk(hashValue, onWebSocketConnected, onWebSock
|
|
|
387
423
|
return __awaiter(this, void 0, void 0, function* () {
|
|
388
424
|
console.log('[Daeryuntalk 초기화 시작] 전체 흐름 실행', version ? `버전: ${version}` : `기본 버전: ${DEFAULT_API_VERSION}`);
|
|
389
425
|
try {
|
|
426
|
+
console.log('[Daeryuntalk 초기화] 전체 흐름 시작');
|
|
390
427
|
// 1단계: 사용자 인증
|
|
391
|
-
|
|
392
|
-
const authResponse = yield authenticateUser(TEST_CENTER_CODE, version);
|
|
393
|
-
console.log('[Daeryuntalk 초기화] 1단계: 사용자 인증 완료');
|
|
428
|
+
const authResponse = yield retryable(() => authenticateUser(TEST_CENTER_CODE, version), 3, 1000, '사용자 인증');
|
|
394
429
|
// 2단계: 웹소켓 초기화
|
|
395
|
-
|
|
396
|
-
const wsInitData = yield initializeWebSocket(version);
|
|
397
|
-
console.log('[Daeryuntalk 초기화] 2단계: 웹소켓 초기화 완료', {
|
|
398
|
-
cnnc_url: wsInitData.data.connection_url,
|
|
399
|
-
token_일부: wsInitData.data.connection_token
|
|
400
|
-
? `${wsInitData.data.connection_token.substring(0, 10)}...`
|
|
401
|
-
: '없음'
|
|
402
|
-
});
|
|
430
|
+
const wsInitData = yield retryable(() => initializeWebSocket(version), 3, 1000, '웹소켓 초기화');
|
|
403
431
|
// 3단계: 웹소켓 연결
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
}
|
|
432
|
+
const socket = yield retryable(() => new Promise((resolve, reject) => {
|
|
433
|
+
try {
|
|
434
|
+
const ws = connectWebSocket(wsInitData.data.connection_url, wsInitData.data.connection_token, onWebSocketMessage, () => {
|
|
435
|
+
console.log('[웹소켓 연결 성공]');
|
|
436
|
+
onWebSocketConnected === null || onWebSocketConnected === void 0 ? void 0 : onWebSocketConnected(ws);
|
|
437
|
+
resolve(ws);
|
|
438
|
+
}, () => { }, event => {
|
|
439
|
+
console.error('[웹소켓 연결 실패]', event);
|
|
440
|
+
reject(new Error('웹소켓 연결 실패'));
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
catch (err) {
|
|
444
|
+
reject(err);
|
|
411
445
|
}
|
|
412
|
-
|
|
413
|
-
//
|
|
414
|
-
|
|
415
|
-
console.log('[DaeryuntalkContext] 로딩 상태 설정: true');
|
|
416
|
-
// 만약 해쉬값이 있으면 이것부터 해여함
|
|
417
|
-
let hashAuth;
|
|
446
|
+
}), 3, 2000, '웹소켓 연결');
|
|
447
|
+
// 4단계: 해시 인증
|
|
448
|
+
let hashAuth = null;
|
|
418
449
|
if (hashValue) {
|
|
419
|
-
hashAuth = yield followupAttend({ token: hashValue });
|
|
450
|
+
hashAuth = yield retryable(() => followupAttend({ token: hashValue }), 2, 1000, '해시 인증');
|
|
420
451
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
console.log('[Daeryuntalk 초기화]
|
|
424
|
-
const chatInquiryData = yield getChatInquiryMain(authResponse.data.channel_number, version);
|
|
425
|
-
console.log('[Daeryuntalk 초기화] 4단계: 채팅 문의 메인 조회 완료', chatInquiryData);
|
|
452
|
+
// 5단계: 문의 조회
|
|
453
|
+
const chatInquiryData = yield retryable(() => getChatInquiryMain(authResponse.data.channel_number, version), 2, 1000, '채팅 문의 메인 조회');
|
|
454
|
+
console.log('[Daeryuntalk 초기화 완료]');
|
|
426
455
|
return {
|
|
427
456
|
inquiryData: chatInquiryData,
|
|
428
|
-
socket
|
|
429
|
-
hashAuth
|
|
457
|
+
socket,
|
|
458
|
+
hashAuth
|
|
430
459
|
};
|
|
431
|
-
console.log('[Daeryuntalk 초기화 완료] 모든 단계 성공');
|
|
432
460
|
}
|
|
433
461
|
catch (error) {
|
|
434
462
|
console.error('[Daeryuntalk 초기화 실패] 오류 발생:', error);
|