-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
38 lines (32 loc) · 851 Bytes
/
server.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
33
34
35
36
37
38
// Setup web server
var express = require('express');
var app = express();
var server = require('http').createServer(app);
// Serve static files
app.use(express.static('public'));
// socket.io
var io = require('socket.io')(server);
// run
var port = process.env.PORT || 3000;
server.listen(port, function () {
console.log('Server listening at port %d...', port);
});
var Connection = {
init: function(socket, Rooms, Events) {
for( var i in Rooms )
socket.join(Rooms[i]);
for( var e in Events )
socket.on(e, Events[e]);
},
deinit: function(socket, Rooms, Events) {
for( var i in Rooms )
socket.leave(Rooms[i]);
for( var e in Events )
socket.removeListener(e, Events[e]);
}
};
module.exports = {
io: io,
app: app,
Connection: Connection
};