-
Notifications
You must be signed in to change notification settings - Fork 9
/
server.js
40 lines (31 loc) · 829 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
39
40
var express = require('express');
var app = express();
var port = 5030;
var ioport = 5040;
var io = require('socket.io').listen(ioport);
/*
* express server setup
*/
app.set('view engine', 'html');
app.engine('html', require('hbs').__express);
app.get('/', function (req, res) {
res.render('controller', {port:ioport});
});
app.use(express.static(__dirname + '/public'));
app.listen(port);
/*
* socket.io setup
*/
io.on('connection', function (socket) {
// Define socket messages used in your application
socket.on('led', function(data) {
socket.broadcast.emit('led', data);
});
socket.on('press', function(data) {
socket.broadcast.emit('press', data);
});
// broadcast message when socket is disconnected
socket.on('disconnect', function() {
socket.broadcast.emit('disconnected');
});
});