@daeryun/dr_components 0.8.46 → 0.8.48
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/asset/images/daeryuntalk/close.svg +2 -2
- package/dist/asset/images/daeryuntalk/time.svg +2 -2
- package/dist/asset/images/daeryuntalk/viewer/zoom-out.svg +2 -4
- package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/components/Daeryuntalk/ChatButton.jsx +5 -2
- package/dist/components/Daeryuntalk/ChatButton.tsx +5 -2
- package/dist/components/Daeryuntalk/ChatConversation.d.ts +2 -0
- package/dist/components/Daeryuntalk/ChatConversation.jsx +22 -63
- package/dist/components/Daeryuntalk/ChatConversation.tsx +42 -79
- package/dist/components/Daeryuntalk/ChatConversationItem/ChatConversationHeader.d.ts +11 -0
- package/dist/components/Daeryuntalk/ChatConversationItem/ChatConversationHeader.jsx +27 -0
- package/dist/components/Daeryuntalk/ChatConversationItem/ChatConversationHeader.tsx +57 -0
- package/dist/components/Daeryuntalk/ChatHomeView.d.ts +3 -2
- package/dist/components/Daeryuntalk/ChatHomeView.jsx +59 -181
- package/dist/components/Daeryuntalk/ChatHomeView.tsx +102 -206
- package/dist/components/Daeryuntalk/ChatItem/ChatFile.jsx +15 -14
- package/dist/components/Daeryuntalk/ChatItem/ChatFile.tsx +15 -14
- package/dist/components/Daeryuntalk/ChatItem/ChatLoading.d.ts +3 -0
- package/dist/components/Daeryuntalk/ChatItem/ChatLoading.jsx +11 -0
- package/dist/components/Daeryuntalk/ChatItem/ChatLoading.tsx +21 -0
- package/dist/components/Daeryuntalk/ChatItem/ChatWrapper.jsx +4 -4
- package/dist/components/Daeryuntalk/ChatItem/ChatWrapper.tsx +4 -4
- package/dist/components/Daeryuntalk/ChatItem/RichText.jsx +2 -1
- package/dist/components/Daeryuntalk/ChatItem/RichText.tsx +2 -1
- package/dist/components/Daeryuntalk/ChatItem/TimeWrapper.d.ts +9 -0
- package/dist/components/Daeryuntalk/ChatItem/TimeWrapper.jsx +9 -0
- package/dist/components/Daeryuntalk/ChatItem/TimeWrapper.tsx +20 -0
- package/dist/components/Daeryuntalk/ChatItem/WorkFlowClickData.jsx +3 -3
- package/dist/components/Daeryuntalk/ChatItem/WorkFlowClickData.tsx +3 -3
- package/dist/components/Daeryuntalk/ChatItem/WorkFlowImg.jsx +2 -2
- package/dist/components/Daeryuntalk/ChatItem/WorkFlowImg.tsx +2 -2
- package/dist/components/Daeryuntalk/ChatMessage.d.ts +1 -0
- package/dist/components/Daeryuntalk/ChatMessage.jsx +31 -36
- package/dist/components/Daeryuntalk/ChatMessage.tsx +34 -38
- package/dist/components/Daeryuntalk/ChatObject/FieldWorkObject.jsx +2 -2
- package/dist/components/Daeryuntalk/ChatObject/FieldWorkObject.tsx +2 -2
- package/dist/components/Daeryuntalk/ChatObject/ObjectBack.jsx +1 -1
- package/dist/components/Daeryuntalk/ChatObject/ObjectBack.tsx +1 -1
- package/dist/components/Daeryuntalk/ChatObject/ObjectButton.jsx +6 -23
- package/dist/components/Daeryuntalk/ChatObject/ObjectButton.tsx +6 -23
- package/dist/components/Daeryuntalk/ChatWidget.jsx +60 -23
- package/dist/components/Daeryuntalk/ChatWidget.tsx +72 -34
- package/dist/components/Daeryuntalk/DaeryuntalkContext.d.ts +2 -2
- package/dist/components/Daeryuntalk/DaeryuntalkContext.jsx +2 -2
- package/dist/components/Daeryuntalk/DaeryuntalkContext.tsx +5 -5
- package/dist/components/Daeryuntalk/DateSeparator.jsx +2 -2
- package/dist/components/Daeryuntalk/DateSeparator.tsx +2 -2
- package/dist/components/Daeryuntalk/FixedErrorBox.d.ts +7 -0
- package/dist/components/Daeryuntalk/FixedErrorBox.jsx +33 -0
- package/dist/components/Daeryuntalk/FixedErrorBox.tsx +73 -0
- package/dist/components/Daeryuntalk/History/AuthForm.d.ts +3 -1
- package/dist/components/Daeryuntalk/History/AuthForm.jsx +15 -45
- package/dist/components/Daeryuntalk/History/AuthForm.tsx +21 -53
- package/dist/components/Daeryuntalk/HistoryView.d.ts +4 -0
- package/dist/components/Daeryuntalk/HistoryView.jsx +17 -40
- package/dist/components/Daeryuntalk/HistoryView.tsx +36 -48
- package/dist/components/Daeryuntalk/HomeView.d.ts +12 -0
- package/dist/components/Daeryuntalk/HomeView.jsx +102 -0
- package/dist/components/Daeryuntalk/HomeView.tsx +150 -0
- package/dist/components/Daeryuntalk/NavigationFooter.jsx +17 -10
- package/dist/components/Daeryuntalk/NavigationFooter.tsx +22 -12
- package/dist/components/Daeryuntalk/NoticeMessage.jsx +7 -7
- package/dist/components/Daeryuntalk/NoticeMessage.tsx +7 -7
- package/dist/components/Daeryuntalk/Toast/ToastRender.jsx +1 -1
- package/dist/components/Daeryuntalk/Toast/ToastRender.tsx +2 -2
- package/dist/components/Daeryuntalk/Viewer/ImageViewer.d.ts +6 -0
- package/dist/components/Daeryuntalk/Viewer/ImageViewer.jsx +18 -90
- package/dist/components/Daeryuntalk/Viewer/ImageViewer.tsx +49 -135
- package/dist/components/Daeryuntalk/Viewer/MobileViewer.d.ts +16 -0
- package/dist/components/Daeryuntalk/Viewer/MobileViewer.jsx +66 -0
- package/dist/components/Daeryuntalk/Viewer/MobileViewer.tsx +121 -0
- package/dist/components/Daeryuntalk/Viewer/TbPcViewer.d.ts +22 -0
- package/dist/components/Daeryuntalk/Viewer/TbPcViewer.jsx +104 -0
- package/dist/components/Daeryuntalk/Viewer/TbPcViewer.tsx +195 -0
- package/dist/components/Daeryuntalk/_api/daeryuntalk/index.d.ts +4 -3
- package/dist/components/Daeryuntalk/_api/daeryuntalk/index.js +81 -105
- package/dist/components/Daeryuntalk/_api/daeryuntalk/index.ts +105 -121
- package/dist/components/Daeryuntalk/_enums/ask-status.d.ts +7 -0
- package/dist/components/Daeryuntalk/_enums/ask-status.js +14 -0
- package/dist/components/Daeryuntalk/_enums/ask-status.ts +14 -0
- package/dist/components/Daeryuntalk/_enums/error.d.ts +3 -0
- package/dist/components/Daeryuntalk/_enums/error.js +125 -0
- package/dist/components/Daeryuntalk/_enums/error.ts +143 -0
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useChatHandler.d.ts +8 -8
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useChatHandler.js +227 -179
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useChatHandler.ts +261 -185
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useHistoryHandler.d.ts +1 -1
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useHistoryHandler.js +54 -18
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useHistoryHandler.ts +68 -15
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useSocketEventHandler.d.ts +2 -2
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useSocketEventHandler.js +8 -7
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useSocketEventHandler.ts +13 -6
- package/dist/components/Daeryuntalk/_hooks/view/useChatSocketState.d.ts +2 -0
- package/dist/components/Daeryuntalk/_hooks/{talkprovider → view}/useChatSocketState.js +7 -1
- package/dist/components/Daeryuntalk/_hooks/{talkprovider → view}/useChatSocketState.ts +13 -1
- package/dist/components/Daeryuntalk/_hooks/view/useHistoryView.d.ts +26 -0
- package/dist/components/Daeryuntalk/_hooks/view/useHistoryView.js +72 -0
- package/dist/components/Daeryuntalk/_hooks/view/useHistoryView.ts +93 -0
- package/dist/components/Daeryuntalk/_hooks/view/useHomeView.d.ts +16 -0
- package/dist/components/Daeryuntalk/_hooks/view/useHomeView.js +61 -0
- package/dist/components/Daeryuntalk/_hooks/view/useHomeView.ts +64 -0
- package/dist/components/Daeryuntalk/_lib/utils.d.ts +1 -0
- package/dist/components/Daeryuntalk/_lib/utils.js +27 -0
- package/dist/components/Daeryuntalk/_lib/utils.ts +33 -0
- package/dist/components/Daeryuntalk/_ui/buttons/Button2.jsx +3 -3
- package/dist/components/Daeryuntalk/_ui/buttons/Button2.tsx +3 -3
- package/dist/components/Daeryuntalk/_ui/buttons/Button3.d.ts +10 -0
- package/dist/components/Daeryuntalk/_ui/buttons/Button3.jsx +12 -0
- package/dist/components/Daeryuntalk/_ui/buttons/Button3.tsx +29 -0
- package/dist/components/Daeryuntalk/_ui/inputs/Input2.jsx +2 -1
- package/dist/components/Daeryuntalk/_ui/inputs/Input2.tsx +2 -1
- package/dist/components/Daeryuntalk/index.jsx +1 -1
- package/dist/components/Daeryuntalk/index.tsx +12 -1
- package/dist/components/Seo/SeoStrength.jsx +5 -2
- package/dist/components/Seo/SeoStrength.tsx +5 -2
- package/dist/styles/globals.css +518 -172
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/components/Daeryuntalk/_enums/error_code.d.ts +0 -21
- package/dist/components/Daeryuntalk/_enums/error_code.js +0 -23
- package/dist/components/Daeryuntalk/_enums/error_code.ts +0 -22
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useChatSocketState.d.ts +0 -1
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import React, { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import { Message } from '../_types/message';
|
|
3
|
+
import { PreviewImage, ZOOM_LEVELS } from './ImageViewer';
|
|
4
|
+
import Image from 'next/image';
|
|
5
|
+
import RotateCCWIcon from '../../../asset/images/daeryuntalk/viewer/rotate.svg';
|
|
6
|
+
import ZoomOutIcon from '../../../asset/images/daeryuntalk/viewer/zoom-out.svg';
|
|
7
|
+
import ZoomInIcon from '../../../asset/images/daeryuntalk/viewer/zoom-in.svg';
|
|
8
|
+
import DownloadIcon from '../../../asset/images/daeryuntalk/download.svg';
|
|
9
|
+
import CloseIcon from '../../../asset/images/daeryuntalk/viewer/close.svg';
|
|
10
|
+
import MoveSwipingIcon from '../../../asset/images/daeryuntalk/viewer/move-button.svg';
|
|
11
|
+
import DaeryunLogoIcon from '../../../asset/images/daeryuntalk/daeryun-logo.svg';
|
|
12
|
+
import { formatDateToKorean } from '../_lib/utils';
|
|
13
|
+
|
|
14
|
+
interface ITbPcViewerProps {
|
|
15
|
+
imageViewerMessage?: Message | null;
|
|
16
|
+
handleDownload: () => void;
|
|
17
|
+
currentIndex: number;
|
|
18
|
+
setCurrentIndex: Dispatch<SetStateAction<number>>;
|
|
19
|
+
rotation: number;
|
|
20
|
+
currentZoom: number;
|
|
21
|
+
currentImage: PreviewImage;
|
|
22
|
+
closeImageViewer?: () => void;
|
|
23
|
+
previewImages: PreviewImage[];
|
|
24
|
+
setRotation: Dispatch<SetStateAction<number>>;
|
|
25
|
+
setZoomLevel: Dispatch<SetStateAction<number>>;
|
|
26
|
+
rotateImage: () => void;
|
|
27
|
+
zoomIn: () => void;
|
|
28
|
+
zoomOut: () => void;
|
|
29
|
+
zoomLevel: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const TbPcViewer = ({
|
|
33
|
+
imageViewerMessage,
|
|
34
|
+
handleDownload,
|
|
35
|
+
currentIndex,
|
|
36
|
+
setCurrentIndex,
|
|
37
|
+
rotation,
|
|
38
|
+
currentZoom,
|
|
39
|
+
currentImage,
|
|
40
|
+
closeImageViewer,
|
|
41
|
+
previewImages,
|
|
42
|
+
setRotation,
|
|
43
|
+
setZoomLevel,
|
|
44
|
+
rotateImage,
|
|
45
|
+
zoomIn,
|
|
46
|
+
zoomOut,
|
|
47
|
+
zoomLevel
|
|
48
|
+
}: ITbPcViewerProps) => {
|
|
49
|
+
return (
|
|
50
|
+
<div className={`hidden xs:block`}>
|
|
51
|
+
<div className={`flex h-[100dvh] flex-col items-center justify-center gap-[60px] px-[88px]`}>
|
|
52
|
+
{/* Main Image + Toolbar */}
|
|
53
|
+
<div className="group relative flex max-h-[80vh] max-w-[90vw] items-center justify-center md2:w-[800px] ">
|
|
54
|
+
{/* 고정된 위치의 좌측 네비게이션 버튼 */}
|
|
55
|
+
{currentIndex > 0 && (
|
|
56
|
+
<button
|
|
57
|
+
onClick={() => setCurrentIndex(prev => prev - 1)}
|
|
58
|
+
className="absolute -left-[68px] top-1/2 z-20 -translate-y-1/2 rotate-180 text-white transition-transform hover:scale-110"
|
|
59
|
+
>
|
|
60
|
+
<MoveSwipingIcon />
|
|
61
|
+
</button>
|
|
62
|
+
)}
|
|
63
|
+
|
|
64
|
+
{/* 고정된 위치의 우측 네비게이션 버튼 */}
|
|
65
|
+
{currentIndex < previewImages.length - 1 && (
|
|
66
|
+
<button
|
|
67
|
+
onClick={() => setCurrentIndex(prev => prev + 1)}
|
|
68
|
+
className="absolute -right-[68px] top-1/2 z-20 -translate-y-1/2 text-white transition-transform hover:scale-110"
|
|
69
|
+
>
|
|
70
|
+
<MoveSwipingIcon />
|
|
71
|
+
</button>
|
|
72
|
+
)}
|
|
73
|
+
|
|
74
|
+
{/* 고정된 위치의 닫기 버튼 */}
|
|
75
|
+
<button
|
|
76
|
+
onClick={closeImageViewer}
|
|
77
|
+
className="absolute right-[20px] top-[20px] z-20 transition-transform hover:scale-110"
|
|
78
|
+
>
|
|
79
|
+
<CloseIcon className="h-6 w-6 text-white" />
|
|
80
|
+
</button>
|
|
81
|
+
|
|
82
|
+
{/* 이미지 컨테이너 */}
|
|
83
|
+
<div
|
|
84
|
+
className={`
|
|
85
|
+
no-scrollbar relative flex h-[500px] w-full min-w-[calc(100dvw-160px)] items-center justify-center overflow-auto rounded-[20px]
|
|
86
|
+
bg-black/10 md2:min-w-[800px]
|
|
87
|
+
`}
|
|
88
|
+
>
|
|
89
|
+
{/*min-w-[320px]*/}
|
|
90
|
+
<div
|
|
91
|
+
className="relative overflow-hidden rounded-[20px]"
|
|
92
|
+
style={{
|
|
93
|
+
transform: `rotate(${rotation}deg) scale(${currentZoom / 100})`,
|
|
94
|
+
transformOrigin: 'center center',
|
|
95
|
+
transition: 'transform 0.2s ease'
|
|
96
|
+
}}
|
|
97
|
+
>
|
|
98
|
+
<Image
|
|
99
|
+
src={currentImage.url}
|
|
100
|
+
alt={currentImage.file.name}
|
|
101
|
+
width={100}
|
|
102
|
+
height={100}
|
|
103
|
+
className="h-auto max-h-[500px] w-full max-w-[684px] object-contain"
|
|
104
|
+
unoptimized
|
|
105
|
+
/>
|
|
106
|
+
</div>
|
|
107
|
+
|
|
108
|
+
{/* Hover Toolbar - 이미지 하단에 고정 */}
|
|
109
|
+
<div className="absolute bottom-0 left-1/2 w-full -translate-x-1/2 opacity-100 transition-opacity duration-300 md2:opacity-0 md2:group-hover:opacity-100">
|
|
110
|
+
<div className="mx-auto flex flex-col items-center justify-between gap-[5px] rounded-b-[20px] bg-black/70 p-[20px] text-white md2:h-[68px] md2:flex-row">
|
|
111
|
+
<div className="flex items-center gap-[20px]">
|
|
112
|
+
<div className={`flex items-center gap-[10px]`}>
|
|
113
|
+
<div className="flex-shrink-0 rounded-full">
|
|
114
|
+
<div className="relative h-full w-full">
|
|
115
|
+
<DaeryunLogoIcon width={28} height={28} />
|
|
116
|
+
</div>
|
|
117
|
+
</div>
|
|
118
|
+
<div className={`dr_talk_subtitle_medium text-drTalkWhite`}>
|
|
119
|
+
법무법인(유한)대륜
|
|
120
|
+
</div>
|
|
121
|
+
</div>
|
|
122
|
+
<div className={`text-drTalkWhite`}>|</div>
|
|
123
|
+
<span className={'dr_talk_body_medium2 text-drTalkWhite'}>
|
|
124
|
+
{formatDateToKorean(imageViewerMessage?.createdAt.toString() || '')}
|
|
125
|
+
</span>
|
|
126
|
+
</div>
|
|
127
|
+
<div className={`flex flex-row gap-[20px]`}>
|
|
128
|
+
<button onClick={rotateImage} className="transition-transform hover:scale-110">
|
|
129
|
+
<RotateCCWIcon />
|
|
130
|
+
</button>
|
|
131
|
+
<button
|
|
132
|
+
onClick={zoomOut}
|
|
133
|
+
disabled={zoomLevel === 0}
|
|
134
|
+
className={`
|
|
135
|
+
${
|
|
136
|
+
zoomLevel === 0
|
|
137
|
+
? 'cursor-not-allowed opacity-50'
|
|
138
|
+
: 'hover:scale-110 hover:opacity-80'
|
|
139
|
+
} transition-all`}
|
|
140
|
+
>
|
|
141
|
+
<ZoomOutIcon />
|
|
142
|
+
</button>
|
|
143
|
+
<button
|
|
144
|
+
onClick={zoomIn}
|
|
145
|
+
disabled={zoomLevel === ZOOM_LEVELS.length - 1}
|
|
146
|
+
className={`${
|
|
147
|
+
zoomLevel === ZOOM_LEVELS.length - 1
|
|
148
|
+
? 'cursor-not-allowed opacity-50'
|
|
149
|
+
: 'hover:scale-110 hover:opacity-80'
|
|
150
|
+
} transition-all`}
|
|
151
|
+
>
|
|
152
|
+
<ZoomInIcon />
|
|
153
|
+
</button>
|
|
154
|
+
<button onClick={handleDownload} className="transition-transform hover:scale-110">
|
|
155
|
+
<DownloadIcon className="bg-transparent text-white" />
|
|
156
|
+
</button>
|
|
157
|
+
</div>
|
|
158
|
+
</div>
|
|
159
|
+
</div>
|
|
160
|
+
{/* Hover Toolbar - 이미지 하단에 끝 */}
|
|
161
|
+
</div>
|
|
162
|
+
</div>
|
|
163
|
+
|
|
164
|
+
{/* Thumbnail Preview - 고정된 위치 */}
|
|
165
|
+
{previewImages.length > 1 && (
|
|
166
|
+
<div className="flex w-full max-w-[90vw] flex-row justify-center gap-[10px] overflow-x-auto px-[20px] md2:w-[830px]">
|
|
167
|
+
{previewImages.map((img, idx) => (
|
|
168
|
+
<div
|
|
169
|
+
key={img.file.fileNumber}
|
|
170
|
+
onClick={() => {
|
|
171
|
+
setCurrentIndex(idx);
|
|
172
|
+
setRotation(0);
|
|
173
|
+
setZoomLevel(3);
|
|
174
|
+
}}
|
|
175
|
+
className={`h-[60px] w-[96px] shrink-0 cursor-pointer overflow-hidden rounded-[10px] border-[1px]
|
|
176
|
+
${idx === currentIndex ? 'border-white' : 'border-transparent opacity-50 hover:opacity-100'}`}
|
|
177
|
+
>
|
|
178
|
+
<Image
|
|
179
|
+
src={img.file.thumbnailUrl}
|
|
180
|
+
alt={img.file.name}
|
|
181
|
+
width={96}
|
|
182
|
+
height={60}
|
|
183
|
+
className="h-full w-full object-cover"
|
|
184
|
+
unoptimized
|
|
185
|
+
/>
|
|
186
|
+
</div>
|
|
187
|
+
))}
|
|
188
|
+
</div>
|
|
189
|
+
)}
|
|
190
|
+
</div>
|
|
191
|
+
</div>
|
|
192
|
+
);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
export default TbPcViewer;
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* 4. 채팅 문의 관리
|
|
9
9
|
*/
|
|
10
10
|
import { IDaeryunTalkResponseWrapper, WebSocketInitDataResponse, IChatInquiryMainDataResponse, ChatInquiryCreateDataResponse, ChatInquiryDetailDataResponse, SendMessageResponse, ChatInquiryMessageListDataResponse, HistoryListResponse, RequestConfirmNumberResponse } from './type/response';
|
|
11
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
11
12
|
export declare const DEFAULT_API_VERSION = "1.0.0";
|
|
12
13
|
export declare const MESSAGE_TYPES: {
|
|
13
14
|
SYSTEM: string;
|
|
@@ -28,7 +29,7 @@ export declare function authenticateUser(centerCode: string, version?: string):
|
|
|
28
29
|
* @returns 연결 URL과 토큰이 포함된 웹소켓 초기화 데이터
|
|
29
30
|
*/
|
|
30
31
|
export declare function initializeWebSocket(version?: string): Promise<IDaeryunTalkResponseWrapper<WebSocketInitDataResponse>>;
|
|
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
|
|
32
|
+
export declare function connectWebSocket(wsUrl: string, token: string, isOpen: boolean, setIsConnected: Dispatch<SetStateAction<boolean | null>>, onMessage?: (event: MessageEvent) => void, onOpen?: (event: Event) => void, onClose?: (event: CloseEvent) => void, onError?: (event: Event) => void): WebSocket;
|
|
32
33
|
/**
|
|
33
34
|
* 채팅 문의 메인 조회
|
|
34
35
|
* @param channelNumber 전달받은 채널
|
|
@@ -67,8 +68,8 @@ export declare function getChatInquiryMessageList(chatInquiryNumber: string, sta
|
|
|
67
68
|
* @param version API 버전 (기본값: 1.0.0)
|
|
68
69
|
* @returns 웹소켓 인스턴스 및 문의 데이터
|
|
69
70
|
*/
|
|
70
|
-
export declare function initializeDaeryuntalk(hashValue: string, onWebSocketConnected?: (socket: WebSocket) => void, onWebSocketMessage?: (event: MessageEvent) => void, version?: string): Promise<{
|
|
71
|
-
inquiryData
|
|
71
|
+
export declare function initializeDaeryuntalk(hashValue: string, isOpen: boolean, setIsConnected: Dispatch<SetStateAction<boolean | null>>, onWebSocketConnected?: (socket: WebSocket) => void, onWebSocketMessage?: (event: MessageEvent) => void, version?: string): Promise<{
|
|
72
|
+
inquiryData: IDaeryunTalkResponseWrapper<IChatInquiryMainDataResponse>;
|
|
72
73
|
socket: WebSocket;
|
|
73
74
|
hashAuth: any;
|
|
74
75
|
}>;
|
|
@@ -47,108 +47,89 @@ export const MESSAGE_TYPES = {
|
|
|
47
47
|
OPERATOR: 'MSP00100004',
|
|
48
48
|
MACRO: 'MSP00100005'
|
|
49
49
|
};
|
|
50
|
+
// 재시도
|
|
51
|
+
function retryable(fn_1) {
|
|
52
|
+
return __awaiter(this, arguments, void 0, function* (fn, maxAttempts = 3, delayMs = 350, label = '') {
|
|
53
|
+
let attempt = 0;
|
|
54
|
+
while (attempt < maxAttempts) {
|
|
55
|
+
try {
|
|
56
|
+
return yield fn();
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
attempt++;
|
|
60
|
+
console.warn(`[재시도] ${label} ${attempt}회 실패`, error);
|
|
61
|
+
if (attempt >= maxAttempts)
|
|
62
|
+
throw new Error(`${label} 최대 재시도 초과`);
|
|
63
|
+
yield new Promise(res => setTimeout(res, delayMs));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
throw new Error(`${label} 실패`);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
50
69
|
/**
|
|
51
70
|
* 쿠키 지원이 포함된 기본 fetch 함수
|
|
52
71
|
*/
|
|
53
72
|
function fetchWithCookies(url_1) {
|
|
54
|
-
return __awaiter(this, arguments, void 0, function* (url, options = {}, version = DEFAULT_API_VERSION
|
|
55
|
-
|
|
56
|
-
var _a;
|
|
73
|
+
return __awaiter(this, arguments, void 0, function* (url, options = {}, version = DEFAULT_API_VERSION) {
|
|
74
|
+
var _a, _b, _c, _d, _e;
|
|
57
75
|
const headers = new Headers(options.headers || {});
|
|
58
|
-
// Content-Type 헤더가 없으면 추가
|
|
59
76
|
if (!headers.has('Content-Type')) {
|
|
60
77
|
headers.set('Content-Type', 'application/json');
|
|
61
78
|
}
|
|
62
79
|
if (typeof window !== 'undefined') {
|
|
63
80
|
const AuthToken = localStorage.getItem('daeryunchatinquirytoken') || '';
|
|
64
|
-
// 로컬스토리지에 존재하면, 헤더에 추가
|
|
65
81
|
if (AuthToken) {
|
|
66
82
|
headers.set('a', AuthToken);
|
|
67
83
|
}
|
|
68
84
|
}
|
|
69
|
-
// 버전 헤더 추가
|
|
70
85
|
headers.set('v', version);
|
|
71
|
-
const
|
|
72
|
-
credentials: 'include', // 요청에 쿠키 포함
|
|
73
|
-
headers: headers
|
|
74
|
-
};
|
|
75
|
-
const mergedOptions = Object.assign(Object.assign(Object.assign({}, defaultOptions), options), { headers });
|
|
76
|
-
console.log(`[API 요청] ${options.method || 'GET'} ${url}`, {
|
|
77
|
-
옵션: mergedOptions,
|
|
78
|
-
본문: mergedOptions.body,
|
|
79
|
-
버전: version
|
|
80
|
-
});
|
|
81
|
-
// 인증 요청인지 확인
|
|
86
|
+
const mergedOptions = Object.assign(Object.assign({ credentials: 'include' }, options), { headers });
|
|
82
87
|
const isAuthRequest = url.includes(ENDPOINTS.AUTHENTICATE);
|
|
83
88
|
try {
|
|
84
89
|
const response = yield fetch(url, mergedOptions);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
catch (parseError) {
|
|
94
|
-
console.error(`[API 오류] ${response.status} ${response.statusText} - 응답 파싱 실패`, parseError);
|
|
95
|
-
// throw new Error(`API 오류: ${response.status} - ${response.statusText}`);
|
|
90
|
+
const contentLength = response.headers.get('content-length');
|
|
91
|
+
const isEmpty = contentLength === '0';
|
|
92
|
+
let data = null;
|
|
93
|
+
try {
|
|
94
|
+
const text = yield response.clone().text();
|
|
95
|
+
if (text && text.trim()) {
|
|
96
|
+
data = JSON.parse(text);
|
|
96
97
|
}
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
console.error(`[API 응답 파싱 실패] ${url}`, err);
|
|
101
|
+
}
|
|
102
|
+
if (!response.ok || (!isAuthRequest && ((_a = data === null || data === void 0 ? void 0 : data.result_info) === null || _a === void 0 ? void 0 : _a.result_type_cd) !== 'OK')) {
|
|
103
|
+
// 실패 응답도 서버에서 온 데이터 그대로 반환
|
|
97
104
|
return {
|
|
98
|
-
result_info: {
|
|
99
|
-
result_type_cd: 'ERROR',
|
|
105
|
+
result_info: (_b = data === null || data === void 0 ? void 0 : data.result_info) !== null && _b !== void 0 ? _b : {
|
|
100
106
|
result_cd: String(response.status),
|
|
101
|
-
|
|
107
|
+
result_type_cd: 'ERROR',
|
|
108
|
+
result_msg: `${response.status} ${response.statusText}`
|
|
102
109
|
},
|
|
103
|
-
data: null
|
|
110
|
+
data: (_c = data === null || data === void 0 ? void 0 : data.data) !== null && _c !== void 0 ? _c : null
|
|
104
111
|
};
|
|
105
112
|
}
|
|
106
|
-
// 응답
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
data = {}
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
try {
|
|
117
|
-
// 응답 텍스트를 먼저 확인하여 비어있는지 검사
|
|
118
|
-
const clonedResponse = response.clone();
|
|
119
|
-
const responseText = yield clonedResponse.text();
|
|
120
|
-
if (!responseText || responseText.trim() === '') {
|
|
121
|
-
console.log(`[API 응답 데이터] ${options.method || 'GET'} ${url} - 빈 응답 본문 (내용 기반 확인)`);
|
|
122
|
-
data = {};
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
// 유효한 JSON인 경우만 파싱
|
|
126
|
-
data = JSON.parse(responseText);
|
|
127
|
-
console.log(`[API 응답 데이터] ${options.method || 'GET'} ${url}`, data);
|
|
128
|
-
// 인증 요청이 아닌 경우, result_info.result_type_cd가 "OK"인지 확인
|
|
129
|
-
if (!isAuthRequest && data.result_info) {
|
|
130
|
-
if (data.result_info.result_type_cd !== 'OK') {
|
|
131
|
-
console.error(`[API 결과 오류] result_type_cd가 OK가 아님:`, data.result_info);
|
|
132
|
-
throw new Error(`API 결과 오류: ${data.result_info.result_msg || '알 수 없는 오류'}`);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
catch (error) {
|
|
138
|
-
console.error(`[API 응답 JSON 파싱 오류] ${options.method || 'GET'} ${url}`, error);
|
|
139
|
-
// 에러 메시지에 'API 결과 오류'가 포함된 경우는 이미 처리된 오류이므로 그대로 전파
|
|
140
|
-
if (error instanceof Error && error.message.includes('API 결과 오류')) {
|
|
141
|
-
throw error;
|
|
142
|
-
}
|
|
143
|
-
// JSON 파싱 오류가 발생해도 요청은 성공했으므로 빈 객체 반환
|
|
144
|
-
data = {};
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return data;
|
|
113
|
+
// 성공 응답 처리 (서버 값 그대로)
|
|
114
|
+
return {
|
|
115
|
+
result_info: (_d = data === null || data === void 0 ? void 0 : data.result_info) !== null && _d !== void 0 ? _d : {
|
|
116
|
+
result_cd: '200',
|
|
117
|
+
result_type_cd: 'OK',
|
|
118
|
+
result_msg: '성공'
|
|
119
|
+
},
|
|
120
|
+
data: (_e = data === null || data === void 0 ? void 0 : data.data) !== null && _e !== void 0 ? _e : {}
|
|
121
|
+
};
|
|
148
122
|
}
|
|
149
123
|
catch (error) {
|
|
150
|
-
console.error(`[API 호출 실패] ${
|
|
151
|
-
|
|
124
|
+
console.error(`[API 호출 실패] ${url}`, error);
|
|
125
|
+
return {
|
|
126
|
+
result_info: {
|
|
127
|
+
result_cd: 'FETCH_ERROR',
|
|
128
|
+
result_type_cd: 'ERROR',
|
|
129
|
+
result_msg: error instanceof Error ? error.message : '알 수 없는 오류'
|
|
130
|
+
},
|
|
131
|
+
data: null
|
|
132
|
+
};
|
|
152
133
|
}
|
|
153
134
|
});
|
|
154
135
|
}
|
|
@@ -221,8 +202,7 @@ export function initializeWebSocket(version) {
|
|
|
221
202
|
let reconnectAttempts = 0;
|
|
222
203
|
const MAX_RECONNECT_ATTEMPTS = 5;
|
|
223
204
|
const RECONNECT_DELAY_MS = 2000;
|
|
224
|
-
export function connectWebSocket(wsUrl, token, onMessage, onOpen, onClose, onError
|
|
225
|
-
) {
|
|
205
|
+
export function connectWebSocket(wsUrl, token, isOpen, setIsConnected, onMessage, onOpen, onClose, onError) {
|
|
226
206
|
// URL에 토큰을 파라미터로 추가
|
|
227
207
|
const connectionUrl = `${wsUrl}?token=${token}`;
|
|
228
208
|
console.log('[웹소켓 연결 시작] 연결 URL:', connectionUrl);
|
|
@@ -248,18 +228,32 @@ export function connectWebSocket(wsUrl, token, onMessage, onOpen, onClose, onErr
|
|
|
248
228
|
onMessage(event.data);
|
|
249
229
|
};
|
|
250
230
|
socket.onclose = (event) => __awaiter(this, void 0, void 0, function* () {
|
|
231
|
+
var _a, _b;
|
|
251
232
|
console.warn('[웹소켓 종료]', event);
|
|
233
|
+
if (!isOpen) {
|
|
234
|
+
console.log('[웹소켓 종료] 채팅창이 닫혀있어 재연결하지 않음');
|
|
235
|
+
if (onClose)
|
|
236
|
+
onClose(event);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
252
239
|
if (reconnectAttempts < MAX_RECONNECT_ATTEMPTS) {
|
|
253
240
|
reconnectAttempts++;
|
|
254
241
|
console.log(`[재연결 시도] ${reconnectAttempts}회... ${RECONNECT_DELAY_MS}ms 후`);
|
|
255
242
|
yield new Promise(res => setTimeout(res, RECONNECT_DELAY_MS));
|
|
256
|
-
|
|
257
|
-
|
|
243
|
+
try {
|
|
244
|
+
// 새로운 initData 요청
|
|
245
|
+
const newInitData = yield initializeWebSocket(); // 직접 구현한 API 요청 함수
|
|
246
|
+
const newSocket = new WebSocket(`${(_a = newInitData === null || newInitData === void 0 ? void 0 : newInitData.data) === null || _a === void 0 ? void 0 : _a.connection_url}?token=${(_b = newInitData === null || newInitData === void 0 ? void 0 : newInitData.data) === null || _b === void 0 ? void 0 : _b.connection_token}`);
|
|
247
|
+
setIsConnected(true);
|
|
248
|
+
// 새 소켓에 핸들러 등록
|
|
249
|
+
setupSocketHandlers(newSocket);
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
setIsConnected(false);
|
|
253
|
+
}
|
|
258
254
|
}
|
|
259
255
|
else {
|
|
260
256
|
console.error('[웹소켓 재연결 실패] 최대 재시도 초과');
|
|
261
|
-
if (onReconnectFail)
|
|
262
|
-
onReconnectFail();
|
|
263
257
|
if (onClose)
|
|
264
258
|
onClose(event);
|
|
265
259
|
}
|
|
@@ -393,24 +387,6 @@ export function getChatInquiryMessageList(chatInquiryNumber, standardDateTime, s
|
|
|
393
387
|
}
|
|
394
388
|
});
|
|
395
389
|
}
|
|
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
|
-
}
|
|
414
390
|
/**
|
|
415
391
|
* Daeryuntalk 초기화 완료 흐름
|
|
416
392
|
* 이 함수는 인증부터 웹소켓 연결까지 완전한 흐름을 처리
|
|
@@ -419,7 +395,7 @@ function retryable(fn_1) {
|
|
|
419
395
|
* @param version API 버전 (기본값: 1.0.0)
|
|
420
396
|
* @returns 웹소켓 인스턴스 및 문의 데이터
|
|
421
397
|
*/
|
|
422
|
-
export function initializeDaeryuntalk(hashValue, onWebSocketConnected, onWebSocketMessage, version) {
|
|
398
|
+
export function initializeDaeryuntalk(hashValue, isOpen, setIsConnected, onWebSocketConnected, onWebSocketMessage, version) {
|
|
423
399
|
return __awaiter(this, void 0, void 0, function* () {
|
|
424
400
|
if (typeof window !== 'undefined' && hashValue) {
|
|
425
401
|
localStorage.removeItem('daeryunchatinquirytoken');
|
|
@@ -428,13 +404,13 @@ export function initializeDaeryuntalk(hashValue, onWebSocketConnected, onWebSock
|
|
|
428
404
|
try {
|
|
429
405
|
console.log('[Daeryuntalk 초기화] 전체 흐름 시작');
|
|
430
406
|
// 1단계: 사용자 인증
|
|
431
|
-
const authResponse = yield retryable(() => authenticateUser(TEST_CENTER_CODE, version), 3,
|
|
407
|
+
const authResponse = yield retryable(() => authenticateUser(TEST_CENTER_CODE, version), 3, 350, '사용자 인증');
|
|
432
408
|
// 2단계: 웹소켓 초기화
|
|
433
|
-
const wsInitData = yield retryable(() => initializeWebSocket(version), 3,
|
|
409
|
+
const wsInitData = yield retryable(() => initializeWebSocket(version), 3, 350, '웹소켓 초기화');
|
|
434
410
|
// 3단계: 웹소켓 연결
|
|
435
411
|
const socket = yield retryable(() => new Promise((resolve, reject) => {
|
|
436
412
|
try {
|
|
437
|
-
const ws = connectWebSocket(wsInitData.data.connection_url, wsInitData.data.connection_token, onWebSocketMessage, () => {
|
|
413
|
+
const ws = connectWebSocket(wsInitData.data.connection_url, wsInitData.data.connection_token, isOpen, setIsConnected, onWebSocketMessage, () => {
|
|
438
414
|
console.log('[웹소켓 연결 성공]');
|
|
439
415
|
onWebSocketConnected === null || onWebSocketConnected === void 0 ? void 0 : onWebSocketConnected(ws);
|
|
440
416
|
resolve(ws);
|
|
@@ -453,7 +429,7 @@ export function initializeDaeryuntalk(hashValue, onWebSocketConnected, onWebSock
|
|
|
453
429
|
hashAuth = yield retryable(() => followupAttend({ token: hashValue }), 2, 1000, '해시 인증');
|
|
454
430
|
}
|
|
455
431
|
// 5단계: 문의 조회
|
|
456
|
-
const chatInquiryData = yield retryable(() => getChatInquiryMain(authResponse.data.channel_number, version), 2,
|
|
432
|
+
const chatInquiryData = yield retryable(() => getChatInquiryMain(authResponse.data.channel_number, version), 2, 350, '채팅 문의 메인 조회');
|
|
457
433
|
console.log('[Daeryuntalk 초기화 완료]');
|
|
458
434
|
return {
|
|
459
435
|
inquiryData: chatInquiryData,
|