Skip to content

Commit

Permalink
feat: client side 예시 작성 #175
Browse files Browse the repository at this point in the history
(cherry picked from commit bf7ac4e)
  • Loading branch information
NaayoungKwon committed Dec 2, 2022
1 parent 9a2743c commit 22bbfa1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions server/apps/socket/src/mock_client/client.js
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~' });

0 comments on commit 22bbfa1

Please sign in to comment.