Skip to content

Commit

Permalink
Merge pull request #62 from kkkkkSE/feat/sockjs
Browse files Browse the repository at this point in the history
[feat] 소켓 구독, 연결 해제 시 헤더를 통해 서버로 토큰 및 채팅방 번호 전달
  • Loading branch information
kkkkkSE authored Sep 24, 2023
2 parents 7cc6617 + 3d10de3 commit 21bf1a2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/hooks/useSockJS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import SockJS from 'sockjs-client';

import { CompatClient, Stomp } from '@stomp/stompjs';

import useAccessToken from './useAccessToken';
import useChatRoomStore from './useChatRoomStore';
import useLoginUserStore from './useLoginUserStore';

const useSockJS = (chatRoomId: number) => {
const { accessToken } = useAccessToken();
const [{ userType, profile }] = useLoginUserStore();

const [, store] = useChatRoomStore();
Expand All @@ -25,12 +27,17 @@ const useSockJS = (chatRoomId: number) => {
const newMessage = JSON.parse(response.body);
store.addMessage(newMessage);
},
{},
{
id: `${chatRoomId}`,
Authorization: `Bearer ${accessToken}`,
},
);
});

return (() => {
client.current?.disconnect();
client.current?.disconnect(undefined, {
id: `${chatRoomId}`,
});
});
}, []);

Expand Down

0 comments on commit 21bf1a2

Please sign in to comment.