-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
58 lines (41 loc) · 1.4 KB
/
app.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// This is the server-side file of our mobile remote controller app.
// It initializes socket.io and a new express instance.
// Start it by running 'node app.js' from your terminal.
// Creating an express server
var express = require('express'),
app = express();
// This is needed if the app is run on heroku and other cloud providers:
var port = process.env.PORT || 8080;
// Initialize a new socket.io object. It is bound to
// the express app, which allows them to coexist.
var io = require('socket.io').listen(app.listen(port));
// App Configuration
// Make the files in the public folder available to the world
app.use(express.static(__dirname + '/public'));
// This is a secret key that prevents others from opening your presentation
// and controlling it. Change it to something that only you know.
var secret = 'kittens';
var presentation = io.on('connection', function (socket) {
socket.on('load', function(data){
socket.emit('access', {
access: (data.key === secret ? "granted" : "denied")
});
});
socket.on('navigate-change', function(data) {
if (data.key === secret) {
presentation.emit('navigate', {
next: data.next,
click: true
});
}
})
socket.on('hash-change', function(data){
if (data.key === secret) {
presentation.emit('navigate', {
hash: data.hash,
click: false
});
}
});
});
console.log('Your presentation is running on http://localhost:' + port);