-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
45 lines (38 loc) · 1012 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
33
34
35
36
37
38
39
40
41
42
43
44
45
'use strict';
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var j5 = require("./app/j5");
var io = require('socket.io');
var socket = io.listen(server);
var port = 3000;
app.use('/', express.static(__dirname + '/public'));
app.get('/', function(req, res){
res.sendFile('index.html');
});
socket.on('connection', function(client) {
j5.init();
client.on('message', function(action) {
console.log('Message recievde from client with action "' + action.type + '"');
var functionToExecute = getFunctionFromAction(action);
functionToExecute();
});
});
console.log('Listening on port http://localhost:' + port);
server.listen(port);
function getFunctionFromAction(action) {
switch(action.type) {
case 'TASK_COMPLETED':
return rewardUser;
default:
return action;
}
}
function rewardUser() {
j5.openDispenser();
var timeoutID = null;
timeoutID = setTimeout(function() {
j5.closeDispenser();
clearTimeout(timeoutID);
}, 2000);
}