From 607bd9b4267cdeb23bf45f77cdf3d8339777a024 Mon Sep 17 00:00:00 2001 From: giuseog Date: Fri, 25 Oct 2024 17:37:26 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=95=8C=EB=A6=BC=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84(#88)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 +- src/main.js | 8 +- src/views/body/chat/Chat.vue | 18 +++-- src/views/navigation/Navigation.vue | 113 +++++++++++++++++++++++++--- 4 files changed, 124 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 71cdb9d..3ff6328 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "stompjs": "^2.3.3", "vue": "^3.5.11", "vue-router": "^4.4.5", - "vue-stomp": "^0.0.5" + "vue-stomp": "^0.0.5", + "vue-toastification": "^2.0.0-rc.5" }, "devDependencies": { "@vitejs/plugin-vue": "^5.1.4", diff --git a/src/main.js b/src/main.js index 3d21669..bb1bdb9 100644 --- a/src/main.js +++ b/src/main.js @@ -5,9 +5,12 @@ import './assets/css/reset.css'; import App from './App.vue' import router from './router' import BootstrapVue3 from 'bootstrap-vue-3' +import Toast from "vue-toastification"; import 'bootstrap/dist/css/bootstrap.css'; import 'bootstrap-vue-3/dist/bootstrap-vue-3.css'; +import "vue-toastification/dist/index.css"; +import { POSITION } from 'vue-toastification'; const app = createApp(App); const pinia = createPinia(); @@ -15,5 +18,8 @@ const pinia = createPinia(); app.use(router) app.use(BootstrapVue3) app.use(pinia); - +app.use(Toast, { + position: POSITION.BOTTOM_RIGHT, + timeout: 5000 +}); app.mount('#app') diff --git a/src/views/body/chat/Chat.vue b/src/views/body/chat/Chat.vue index a7866c7..db1f26a 100644 --- a/src/views/body/chat/Chat.vue +++ b/src/views/body/chat/Chat.vue @@ -181,12 +181,22 @@ const socket = new SockJS('http://localhost:8080/ws-stomp'); stompClient.value = Stomp.over(socket); + const token = localStorage.getItem('jwtToken'); // 예시로 로컬 스토리지에서 가져옴 + + // 헤더에 Authorization 추가 + const headers = {}; + if (token) { + headers['Authorization'] = 'Bearer ' + token; + } console.log("connect에서의 roomId: " + room.roomId); - stompClient.value.connect({}, (frame) => { + // stompClient.value.connect({}, (frame) => { + stompClient.value.connect(headers, (frame) => { console.log('Connected: ' + frame); console.log('roomid value: ' + room.roomId); + + // send to chatting room stompClient.value.subscribe(`/sub/${room.roomId}`, (message) => { showMessage(JSON.parse(message.body)); }); @@ -205,7 +215,6 @@ try { console.log("Fetching message rooms..."); - console.log("Fetching에서의 roomId: " + room.roomId); const response = await axios.get(`http://localhost:8080/api/v1/chat/${room.roomId}` , { headers: { @@ -253,9 +262,6 @@ type: 'TALK' }; - console.log("stompClient is alive?" + stompClient); - console.log('Sending message:', JSON.stringify(sendMessage)); - try { await stompClient.value.send(`/pub/message/${roomId.value}`, {}, JSON.stringify(sendMessage)); messageInput.value = ''; @@ -297,8 +303,6 @@ }); }; - - // 컴포넌트가 마운트될 때 데이터 가져오기 onMounted(async () => { console.log("Component is mounted. Now fetching chat rooms..."); diff --git a/src/views/navigation/Navigation.vue b/src/views/navigation/Navigation.vue index 432ca58..c68d019 100644 --- a/src/views/navigation/Navigation.vue +++ b/src/views/navigation/Navigation.vue @@ -105,10 +105,14 @@ - - - message - + + +
+ + message + + {{ chatCount }} +
@@ -134,11 +138,15 @@