
--- client/views/pages/subPage/FeedBack.vue
+++ client/views/pages/subPage/FeedBack.vue
... | ... | @@ -79,6 +79,8 @@ |
79 | 79 |
import dayjs from 'dayjs'; |
80 | 80 |
import relativeTime from 'dayjs/plugin/relativeTime'; |
81 | 81 |
import 'dayjs/locale/ko'; // 한국어 locale 불러오기 |
82 |
+import SockJS from 'sockjs-client'; |
|
83 |
+import { Client } from '@stomp/stompjs'; |
|
82 | 84 |
|
83 | 85 |
dayjs.extend(relativeTime); |
84 | 86 |
dayjs.locale('ko'); |
... | ... | @@ -163,6 +165,9 @@ |
163 | 165 |
], |
164 | 166 |
|
165 | 167 |
replyText: '', |
168 |
+ socket: null, |
|
169 |
+ stompClient: null, |
|
170 |
+ connectedRoomId: null, |
|
166 | 171 |
|
167 | 172 |
}; |
168 | 173 |
}, |
... | ... | @@ -178,18 +183,31 @@ |
178 | 183 |
// } |
179 | 184 |
// }, |
180 | 185 |
async submitReply() { |
181 |
- if (!this.replyText.trim()) return; |
|
182 |
- try { |
|
183 |
- await axios.post(`/api/feedback/${this.replyingFeedbackId}/reply`, { |
|
184 |
- reply: this.replyText |
|
186 |
+ // if (!this.replyText.trim()) return; |
|
187 |
+ // try { |
|
188 |
+ // await axios.post(`/api/feedback/${this.replyingFeedbackId}/reply`, { |
|
189 |
+ // reply: this.replyText |
|
190 |
+ // }); |
|
191 |
+ // alert('회신이 전송되었습니다.'); |
|
192 |
+ // this.replyText = ''; |
|
193 |
+ // this.selectedFeedback = null; |
|
194 |
+ // this.replyingFeedbackId = null; |
|
195 |
+ // } catch (err) { |
|
196 |
+ // console.error('회신 실패:', err); |
|
197 |
+ // } |
|
198 |
+ if (!this.replyText.trim() || !this.stompClient) return; |
|
199 |
+ |
|
200 |
+ const msg = { |
|
201 |
+ chatRoomId: this.selectedFeedback.chatRoomId, |
|
202 |
+ senderId: this.getMemId, |
|
203 |
+ msgContent: this.replyText, |
|
204 |
+ }; |
|
205 |
+ |
|
206 |
+ this.stompClient.publish({ |
|
207 |
+ destination: "/pub/chat.sendMessage", |
|
208 |
+ body: JSON.stringify(msg) |
|
185 | 209 |
}); |
186 |
- alert('회신이 전송되었습니다.'); |
|
187 | 210 |
this.replyText = ''; |
188 |
- this.selectedFeedback = null; |
|
189 |
- this.replyingFeedbackId = null; |
|
190 |
- } catch (err) { |
|
191 |
- console.error('회신 실패:', err); |
|
192 |
- } |
|
193 | 211 |
}, |
194 | 212 |
|
195 | 213 |
replyTo(feedback) { |
... | ... | @@ -246,11 +264,38 @@ |
246 | 264 |
})); |
247 | 265 |
|
248 | 266 |
this.replyTo(feedback); |
267 |
+ this.connectToChatRoom(feedback.chatRoomId); |
|
249 | 268 |
}) |
250 | 269 |
.catch(error => { |
251 | 270 |
console.error('채팅 조회 실패: ', error); |
252 | 271 |
}) |
253 | 272 |
}, |
273 |
+ connectToChatRoom(roomId) { |
|
274 |
+ if (this.stompClient && this.connectedRoomId === roomId) return; |
|
275 |
+ |
|
276 |
+ const socket = new SockJS('http://localhost:10911/ws'); |
|
277 |
+ |
|
278 |
+ const client = new Client({ |
|
279 |
+ webSocketFactory: () => socket, |
|
280 |
+ onConnect: () => { |
|
281 |
+ client.subscribe(`/sub/chat.room.${roomId}`, (message) => { |
|
282 |
+ const msg = JSON.parse(message.body); |
|
283 |
+ this.feedbackChatList.push({ |
|
284 |
+ id: msg.chatMsgId, |
|
285 |
+ user: msg.senderName, |
|
286 |
+ content: msg.msgContent, |
|
287 |
+ time: dayjs().fromNow() |
|
288 |
+ }); |
|
289 |
+ }); |
|
290 |
+ |
|
291 |
+ // 연결 완료 시점에만 설정 |
|
292 |
+ this.stompClient = client; |
|
293 |
+ this.connectedRoomId = roomId; |
|
294 |
+ }, |
|
295 |
+ }); |
|
296 |
+ |
|
297 |
+ client.activate(); |
|
298 |
+ }, |
|
254 | 299 |
}, |
255 | 300 |
watch: {}, |
256 | 301 |
computed: { |
--- package-lock.json
+++ package-lock.json
... | ... | @@ -7,6 +7,7 @@ |
7 | 7 |
"dependencies": { |
8 | 8 |
"@babel/cli": "7.19.3", |
9 | 9 |
"@babel/core": "7.19.3", |
10 |
+ "@stomp/stompjs": "^7.1.1", |
|
10 | 11 |
"axios": "^1.10.0", |
11 | 12 |
"babel-loader": "8.2.5", |
12 | 13 |
"css-loader": "6.7.1", |
... | ... | @@ -17,6 +18,7 @@ |
17 | 18 |
"fs": "0.0.1-security", |
18 | 19 |
"new-line": "^1.1.1", |
19 | 20 |
"pg": "8.8.0", |
21 |
+ "sockjs-client": "^1.6.1", |
|
20 | 22 |
"url-loader": "4.1.1", |
21 | 23 |
"vue": "3.5.13", |
22 | 24 |
"vue-loader": "^17.0.0", |
... | ... | @@ -415,6 +417,12 @@ |
415 | 417 |
"engines": { |
416 | 418 |
"node": "^12.13.0 || ^14.15.0 || >=16.0.0" |
417 | 419 |
} |
420 |
+ }, |
|
421 |
+ "node_modules/@stomp/stompjs": { |
|
422 |
+ "version": "7.1.1", |
|
423 |
+ "resolved": "https://registry.npmjs.org/@stomp/stompjs/-/stompjs-7.1.1.tgz", |
|
424 |
+ "integrity": "sha512-chcDs6YkAnKp1FqzwhGvh3i7v0+/ytzqWdKYw6XzINEKAzke/iD00dNgFPWSZEqktHOK+C1gSzXhLkLbARIaZw==", |
|
425 |
+ "license": "Apache-2.0" |
|
418 | 426 |
}, |
419 | 427 |
"node_modules/@tootallnate/once": { |
420 | 428 |
"version": "2.0.0", |
... | ... | @@ -2078,6 +2086,15 @@ |
2078 | 2086 |
"node": ">=0.8.x" |
2079 | 2087 |
} |
2080 | 2088 |
}, |
2089 |
+ "node_modules/eventsource": { |
|
2090 |
+ "version": "2.0.2", |
|
2091 |
+ "resolved": "https://registry.npmjs.org/eventsource/-/eventsource-2.0.2.tgz", |
|
2092 |
+ "integrity": "sha512-IzUmBGPR3+oUG9dUeXynyNmf91/3zUSJg1lCktzKw47OXuhco54U3r9B7O4XX+Rb1Itm9OZ2b0RkTs10bICOxA==", |
|
2093 |
+ "license": "MIT", |
|
2094 |
+ "engines": { |
|
2095 |
+ "node": ">=12.0.0" |
|
2096 |
+ } |
|
2097 |
+ }, |
|
2081 | 2098 |
"node_modules/express": { |
2082 | 2099 |
"version": "4.18.1", |
2083 | 2100 |
"resolved": "https://registry.npmjs.org/express/-/express-4.18.1.tgz", |
... | ... | @@ -2193,6 +2210,18 @@ |
2193 | 2210 |
"license": "MIT", |
2194 | 2211 |
"engines": { |
2195 | 2212 |
"node": ">= 4.9.1" |
2213 |
+ } |
|
2214 |
+ }, |
|
2215 |
+ "node_modules/faye-websocket": { |
|
2216 |
+ "version": "0.11.4", |
|
2217 |
+ "resolved": "https://registry.npmjs.org/faye-websocket/-/faye-websocket-0.11.4.tgz", |
|
2218 |
+ "integrity": "sha512-CzbClwlXAuiRQAlUyfqPgvPoNKTckTPGfwZV4ZdAhVcP2lh9KUxJg2b5GkE7XbjKQ3YJnQ9z6D9ntLAlB+tP8g==", |
|
2219 |
+ "license": "Apache-2.0", |
|
2220 |
+ "dependencies": { |
|
2221 |
+ "websocket-driver": ">=0.5.1" |
|
2222 |
+ }, |
|
2223 |
+ "engines": { |
|
2224 |
+ "node": ">=0.8.0" |
|
2196 | 2225 |
} |
2197 | 2226 |
}, |
2198 | 2227 |
"node_modules/file-loader": { |
... | ... | @@ -2795,6 +2824,12 @@ |
2795 | 2824 |
"engines": { |
2796 | 2825 |
"node": ">= 0.8" |
2797 | 2826 |
} |
2827 |
+ }, |
|
2828 |
+ "node_modules/http-parser-js": { |
|
2829 |
+ "version": "0.5.10", |
|
2830 |
+ "resolved": "https://registry.npmjs.org/http-parser-js/-/http-parser-js-0.5.10.tgz", |
|
2831 |
+ "integrity": "sha512-Pysuw9XpUq5dVc/2SMHpuTY01RFl8fttgcyunjL7eEMhGM3cI4eOmiCycJDVCo/7O7ClfQD3SaI6ftDzqOXYMA==", |
|
2832 |
+ "license": "MIT" |
|
2798 | 2833 |
}, |
2799 | 2834 |
"node_modules/http-proxy-agent": { |
2800 | 2835 |
"version": "5.0.0", |
... | ... | @@ -4562,6 +4597,12 @@ |
4562 | 4597 |
"url": "https://github.com/sponsors/ljharb" |
4563 | 4598 |
} |
4564 | 4599 |
}, |
4600 |
+ "node_modules/querystringify": { |
|
4601 |
+ "version": "2.2.0", |
|
4602 |
+ "resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz", |
|
4603 |
+ "integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==", |
|
4604 |
+ "license": "MIT" |
|
4605 |
+ }, |
|
4565 | 4606 |
"node_modules/quick-lru": { |
4566 | 4607 |
"version": "4.0.1", |
4567 | 4608 |
"resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-4.0.1.tgz", |
... | ... | @@ -4761,6 +4802,12 @@ |
4761 | 4802 |
"engines": { |
4762 | 4803 |
"node": ">=0.10.0" |
4763 | 4804 |
} |
4805 |
+ }, |
|
4806 |
+ "node_modules/requires-port": { |
|
4807 |
+ "version": "1.0.0", |
|
4808 |
+ "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", |
|
4809 |
+ "integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==", |
|
4810 |
+ "license": "MIT" |
|
4764 | 4811 |
}, |
4765 | 4812 |
"node_modules/resolve": { |
4766 | 4813 |
"version": "1.22.10", |
... | ... | @@ -5166,6 +5213,34 @@ |
5166 | 5213 |
"engines": { |
5167 | 5214 |
"node": ">= 6.0.0", |
5168 | 5215 |
"npm": ">= 3.0.0" |
5216 |
+ } |
|
5217 |
+ }, |
|
5218 |
+ "node_modules/sockjs-client": { |
|
5219 |
+ "version": "1.6.1", |
|
5220 |
+ "resolved": "https://registry.npmjs.org/sockjs-client/-/sockjs-client-1.6.1.tgz", |
|
5221 |
+ "integrity": "sha512-2g0tjOR+fRs0amxENLi/q5TiJTqY+WXFOzb5UwXndlK6TO3U/mirZznpx6w34HVMoc3g7cY24yC/ZMIYnDlfkw==", |
|
5222 |
+ "license": "MIT", |
|
5223 |
+ "dependencies": { |
|
5224 |
+ "debug": "^3.2.7", |
|
5225 |
+ "eventsource": "^2.0.2", |
|
5226 |
+ "faye-websocket": "^0.11.4", |
|
5227 |
+ "inherits": "^2.0.4", |
|
5228 |
+ "url-parse": "^1.5.10" |
|
5229 |
+ }, |
|
5230 |
+ "engines": { |
|
5231 |
+ "node": ">=12" |
|
5232 |
+ }, |
|
5233 |
+ "funding": { |
|
5234 |
+ "url": "https://tidelift.com/funding/github/npm/sockjs-client" |
|
5235 |
+ } |
|
5236 |
+ }, |
|
5237 |
+ "node_modules/sockjs-client/node_modules/debug": { |
|
5238 |
+ "version": "3.2.7", |
|
5239 |
+ "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", |
|
5240 |
+ "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", |
|
5241 |
+ "license": "MIT", |
|
5242 |
+ "dependencies": { |
|
5243 |
+ "ms": "^2.1.1" |
|
5169 | 5244 |
} |
5170 | 5245 |
}, |
5171 | 5246 |
"node_modules/socks": { |
... | ... | @@ -5773,6 +5848,16 @@ |
5773 | 5848 |
"url": "https://opencollective.com/webpack" |
5774 | 5849 |
} |
5775 | 5850 |
}, |
5851 |
+ "node_modules/url-parse": { |
|
5852 |
+ "version": "1.5.10", |
|
5853 |
+ "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.10.tgz", |
|
5854 |
+ "integrity": "sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==", |
|
5855 |
+ "license": "MIT", |
|
5856 |
+ "dependencies": { |
|
5857 |
+ "querystringify": "^2.1.1", |
|
5858 |
+ "requires-port": "^1.0.0" |
|
5859 |
+ } |
|
5860 |
+ }, |
|
5776 | 5861 |
"node_modules/util-deprecate": { |
5777 | 5862 |
"version": "1.0.2", |
5778 | 5863 |
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", |
... | ... | @@ -6095,6 +6180,29 @@ |
6095 | 6180 |
"url": "https://opencollective.com/webpack" |
6096 | 6181 |
} |
6097 | 6182 |
}, |
6183 |
+ "node_modules/websocket-driver": { |
|
6184 |
+ "version": "0.7.4", |
|
6185 |
+ "resolved": "https://registry.npmjs.org/websocket-driver/-/websocket-driver-0.7.4.tgz", |
|
6186 |
+ "integrity": "sha512-b17KeDIQVjvb0ssuSDF2cYXSg2iztliJ4B9WdsuB6J952qCPKmnVq4DyW5motImXHDC1cBT/1UezrJVsKw5zjg==", |
|
6187 |
+ "license": "Apache-2.0", |
|
6188 |
+ "dependencies": { |
|
6189 |
+ "http-parser-js": ">=0.5.1", |
|
6190 |
+ "safe-buffer": ">=5.1.0", |
|
6191 |
+ "websocket-extensions": ">=0.1.1" |
|
6192 |
+ }, |
|
6193 |
+ "engines": { |
|
6194 |
+ "node": ">=0.8.0" |
|
6195 |
+ } |
|
6196 |
+ }, |
|
6197 |
+ "node_modules/websocket-extensions": { |
|
6198 |
+ "version": "0.1.4", |
|
6199 |
+ "resolved": "https://registry.npmjs.org/websocket-extensions/-/websocket-extensions-0.1.4.tgz", |
|
6200 |
+ "integrity": "sha512-OqedPIGOfsDlo31UNwYbCFMSaO9m9G/0faIHj5/dZFDMFqPTcx6UwqyOy3COEaEOg/9VsGIpdqn62W5KhoKSpg==", |
|
6201 |
+ "license": "Apache-2.0", |
|
6202 |
+ "engines": { |
|
6203 |
+ "node": ">=0.8.0" |
|
6204 |
+ } |
|
6205 |
+ }, |
|
6098 | 6206 |
"node_modules/which": { |
6099 | 6207 |
"version": "2.0.2", |
6100 | 6208 |
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", |
--- package.json
+++ package.json
... | ... | @@ -2,6 +2,7 @@ |
2 | 2 |
"dependencies": { |
3 | 3 |
"@babel/cli": "7.19.3", |
4 | 4 |
"@babel/core": "7.19.3", |
5 |
+ "@stomp/stompjs": "^7.1.1", |
|
5 | 6 |
"axios": "^1.10.0", |
6 | 7 |
"babel-loader": "8.2.5", |
7 | 8 |
"css-loader": "6.7.1", |
... | ... | @@ -12,6 +13,7 @@ |
12 | 13 |
"fs": "0.0.1-security", |
13 | 14 |
"new-line": "^1.1.1", |
14 | 15 |
"pg": "8.8.0", |
16 |
+ "sockjs-client": "^1.6.1", |
|
15 | 17 |
"url-loader": "4.1.1", |
16 | 18 |
"vue": "3.5.13", |
17 | 19 |
"vue-loader": "^17.0.0", |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?