-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from SeWoong-Han/main
feat: 소켓 연결 테스트
- Loading branch information
Showing
8 changed files
with
124 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import styles from './ChatRoom.module.css'; | ||
import * as Stomp from '@stomp/stompjs'; | ||
import { useSelector } from 'react-redux'; | ||
import * as SockJS from 'sockjs-client'; | ||
|
||
function ChatRoom() { | ||
const jwtToken = useSelector(state => state.loginSlice.accessToken); | ||
console.log("jwt token", jwtToken); | ||
// 클라이언트 생성 | ||
const Client = new Stomp.Client({ | ||
// SockJS 엔드포인트 URL | ||
// webSocketFactory: () => new SockJS('http://localhost:8080/ws'), | ||
// webSocketFactory: () => new WebSocket('ws://localhost:8080/ws'), | ||
brokerURL: 'ws://localhost:8080/ws', | ||
// 로그인 자격 정보 | ||
connectHeaders: { | ||
login: "", | ||
passcode: "", | ||
headers: { | ||
Authorization: `Bearer ${jwtToken}`, // JWT를 헤더에 추가 | ||
'content-type': 'text/event-stream', | ||
'Cache-Control': 'no-cache', | ||
'Connection': 'keep-alive', | ||
'X-Accel-Buffering': 'no', | ||
} | ||
}, | ||
|
||
// 통신 로그 | ||
debug: (log) => console.log('STOMP : ', log), | ||
|
||
// 연결 성공 시 실행될 콜백 함수 | ||
onConnect: (frame) => { | ||
// 구독 설정 | ||
Client.subscribe('/queue/chat', (message) => { | ||
const payload = JSON.parse(message.body); | ||
console.log('message : ', payload); | ||
}, | ||
// { | ||
// Authorization: `Bearer ${jwtToken}`, // JWT를 헤더에 추가 | ||
// 'content-type': 'text/event-stream' | ||
// } | ||
); | ||
}, | ||
|
||
// 연결 실패 시 실행될 콜백 함수 | ||
onStompError: (frame) => { | ||
console.error('STOMP : ', frame); | ||
}, | ||
}); | ||
const onClick = () => { | ||
console.log('success'); | ||
Client.publish({ | ||
destination: '/pub/chat', | ||
body: JSON.stringify('First Message'), // 임시로 first message 보내서 테스트 | ||
}); | ||
} | ||
const active = () => { | ||
Client.activate(); | ||
console.log("client :",Client); | ||
} | ||
return ( | ||
<div> | ||
<div className={styles.container}>채팅 내용이 보이는 곳</div> | ||
<button onClick={onClick}>전송</button> | ||
<button onClick={active}>연결</button> | ||
</div> | ||
) | ||
} | ||
export default ChatRoom; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* 채팅창 크기,스타일링은 나중에 변경 예정 */ | ||
.container { | ||
background-color: gray; | ||
height: 80%; | ||
margin-bottom: 30px; | ||
} | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,4 +78,4 @@ export const IdeBottomBar = ({ sender, setSender, isDarkMode }) => { | |
</div> | ||
</> | ||
); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters