-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
33 lines (27 loc) · 828 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
30
31
32
const express = require('express');
const app = express();
const http = require('http');
app.use('/', express.static("wwwroot"));
const server = app.listen(process.env.PORT || 1337, function(){
console.log('server is running at %s', server.address().port);
});
var io = require('socket.io').listen(server);
io.on('connection', function(socket){
socket.on('poker message', function(msg){
try {
var data = JSON.parse(msg);
if(data && data.room) {
if(data.command === 'join'){
socket.join(msg.to);
}
io.to(msg.room).emit('poker message', msg);
return;
}
}
catch (ex) {
//empty
}
});
socket.on('disconnect', function(){
});
});