-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
10 additions
and
2 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,12 +1,20 @@ | ||
import { io } from 'socket.io-client'; | ||
|
||
const port = 8081; | ||
// 형식은 'commu-{community id}' | ||
const helloSocket = io(`http://localhost:${port}/socket/commu-hello`); | ||
// const worldSocket = io(`http://localhost:${port}/socket/commu-world`); | ||
console.log(helloSocket.connected); | ||
// const worldSocket = io(`http://localhost:${port}/socket/commu-world`); // 다른 namesapce | ||
|
||
// console.log(helloSocket.connected); // 연결되었는지 true, false로 나옴 | ||
|
||
// 처음 연결 후 channel 배열을 전달해야함 | ||
helloSocket.emit('join', { channels: ['a', 'b', 'c'] }); | ||
// worldSocket.emit('join', { channels: ['x', 'y', 'z'] }); | ||
|
||
// message listen | ||
helloSocket.on('new-message', ({ channelId, message }) => { | ||
console.log(`new message from server : ${channelId} ${message}`); | ||
}); | ||
|
||
// message 전송 | ||
helloSocket.emit('new-message', { channelId: 'a', message: 'hi i am the first client~' }); |