-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
29 lines (22 loc) · 835 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
server.listen('3000');
app.get('/' , function (request , response) {
response.sendFile(__dirname + '/index.html');
});
io.on('connection' , function (socket) {
console.log('New User Has connected');
socket.on('newMessage' , function (data , room , name) {
console.log('There are new message '+data+' on Room '+ room);
socket.to(room).emit('clientMessage' , {"name" : name , "message" : data , "type" : "message" });
});
socket.on('joinRoom' , function (data) {
console.log('User Join to room '+data);
socket.join(data);
});
socket.on('leaveRoom' , function (data) {
console.log('User Leave to room '+data);
socket.leave(data);
});
});