Skip to content

Commit

Permalink
Add socket.io server code
Browse files Browse the repository at this point in the history
  • Loading branch information
devjin0617 committed Jan 10, 2017
1 parent 695d59d commit 213160b
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use strict';
const io = require('socket.io').listen(50000);

io.sockets.on('connection', socket => {

socket.emit('connection', {
type : 'connected'
});

socket.on('connection', data => {

if(data.type === 'join') {

socket.join(data.room);

// depracated
// socket.set('room', data.room);
socket.room = data.room;

socket.emit('system', {
message : 'welcome to chat room'
});

socket.broadcast.to(data.room).emit('system', {
message : `${data.name} is connected`
});
}

});

socket.on('user', data => {

// depracated
// socket.get('room', (error, room) => {
// });

var room = socket.room;

if(room) {
socket.broadcast.to(room).emit('message', data);
}
});

});

0 comments on commit 213160b

Please sign in to comment.