-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
37 lines (30 loc) · 1.02 KB
/
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
var express = require('express');
var http = require('http');
var sio = require('socket.io');
var app = express();
var server = http.createServer(app);
var io = sio.listen(server);
var port = process.env.PORT || 8080;
app
.use('/js', express.static(__dirname + '/public/js'))
.use('/css', express.static(__dirname + '/public/css'))
.use('/assets', express.static(__dirname + '/public/assets'))
.use('/templates', express.static(__dirname + '/public/templates'))
.get('/', function(req, res) {
res.sendfile(__dirname + '/public/index.html');
});
io.sockets.on('connection', function(socket) {
socket.on('I\'m ready to be a socket!', function() {
socket.emit('New socket', socket.id);
})
socket.on('Hi, I\'m new :)', function() {
socket.broadcast.emit('Welcome new socket');
});
socket.on('disconnect', function() {
socket.broadcast.emit('Bye bye sockets :(', socket.id);
});
socket.on('Here I am', function(hereHeIs) {
socket.broadcast.emit('Here he is', hereHeIs);
});
});
server.listen(port);