Add additional actions and a short timer

Modify to fit the needs of Openfest:
- lecture time of 45 min
- lightning talks time of 5 min
- multiple halls
- more control actions
This commit is contained in:
Tocho Tochev 2022-10-12 22:53:16 +03:00
parent dac0ea9241
commit 98c7db08b0
8 changed files with 88 additions and 13 deletions

47
app.js
View File

@ -35,10 +35,14 @@ io.configure(function () {
// Use the port that Heroku provides or default to 5000 // Use the port that Heroku provides or default to 5000
var port = process.env.PORT || 5000; var port = process.env.PORT || 5000;
app.listen(port, function() { var host = process.env.HOST || '0.0.0.0';
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env); app.listen(port, host, function() {
console.log("Express server listening on %j in %s mode", app.address(), app.settings.env);
}); });
// configure title
app.title = process.env.TITLE || 'Timer'
app.get('/', routes.index); app.get('/', routes.index);
var stopwatch = new Stopwatch(); var stopwatch = new Stopwatch();
@ -63,7 +67,46 @@ io.sockets.on('connection', function (socket) {
stopwatch.stop(); stopwatch.stop();
}); });
socket.on('click:zero', function () {
stopwatch.zero();
});
socket.on('click:reset', function () { socket.on('click:reset', function () {
stopwatch.reset(); stopwatch.reset();
}); });
socket.on('click:resetShort', function () {
stopwatch.resetShort();
});
});
app.post('/reset/', function (req, res) {
stopwatch.reset();
res.send("OK");
});
app.post('/reset-short/', function (req, res) {
stopwatch.resetShort();
res.send("OK");
});
app.post('/start-from-reset/', function (req, res) {
stopwatch.reset();
stopwatch.start();
res.send("OK");
});
app.post('/start-from-reset-short/', function (req, res) {
stopwatch.resetShort();
stopwatch.start();
res.send("OK");
});
app.post('/start/', function (req, res) {
stopwatch.start();
res.send("OK");
});
app.post('/stop/', function (req, res) {
stopwatch.stop();
res.send("OK");
});
app.post('/zero/', function (req, res) {
stopwatch.zero();
res.send("OK");
}); });

View File

@ -2,6 +2,9 @@ var util = require('util'),
events = require('events') events = require('events')
_ = require('underscore'); _ = require('underscore');
var DEFAULT_TIME = 45* 60 * 1000;
var DEFAULT_SHORT_TIME = 5 * 60 * 1000;
// --------------------------------------------- // ---------------------------------------------
// Constructor // Constructor
// --------------------------------------------- // ---------------------------------------------
@ -13,7 +16,9 @@ function Stopwatch() {
this.hour = 3600000; this.hour = 3600000;
this.minute = 60000; this.minute = 60000;
this.second = 1000; this.second = 1000;
this.time = this.hour; this.defaultTime = DEFAULT_TIME;
this.defaultShortTime = DEFAULT_SHORT_TIME;
this.time = this.defaultTime;
this.interval = undefined; this.interval = undefined;
events.EventEmitter.call(this); events.EventEmitter.call(this);
@ -55,7 +60,19 @@ Stopwatch.prototype.stop = function() {
Stopwatch.prototype.reset = function() { Stopwatch.prototype.reset = function() {
console.log('Resetting Stopwatch!'); console.log('Resetting Stopwatch!');
this.time = this.hour; this.time = this.defaultTime;
this.emit('reset:stopwatch', this.formatTime(this.time));
};
Stopwatch.prototype.zero = function() {
console.log('Zeroing Stopwatch!');
this.time = 1000;
this.emit('reset:stopwatch', this.formatTime(this.time));
};
Stopwatch.prototype.resetShort = function() {
console.log('Resetting Stopwatch to Short!');
this.time = this.defaultShortTime;
this.emit('reset:stopwatch', this.formatTime(this.time)); this.emit('reset:stopwatch', this.formatTime(this.time));
}; };

View File

@ -15,3 +15,7 @@ $('#stop').click(function() {
$('#reset').click(function() { $('#reset').click(function() {
socket.emit('click:reset'); socket.emit('click:reset');
}); });
$('#resetShort').click(function() {
socket.emit('click:resetShort');
});

View File

@ -5,5 +5,5 @@ var app = require('../app');
*/ */
exports.index = function(req, res) { exports.index = function(req, res) {
res.render('index') res.render('index', {"title": app.title})
}; };

8
start.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/bash
# Usage:
# HOST=127.0.0.1 PORT=5051 TITLE=HALL-B ./start.sh
cd "$(dirname "$0")"
NODE_ENV=production node app.js

View File

@ -3,4 +3,7 @@
<button id="start" class="thoughtbot">Start</button> <button id="start" class="thoughtbot">Start</button>
<button id="stop" class="thoughtbot">Stop</button> <button id="stop" class="thoughtbot">Stop</button>
<button id="reset" class="thoughtbot">Reset</button> <button id="reset" class="thoughtbot">Reset</button>
<button id="unused2" class="thoughtbot">&nbsp;</button>
<button id="zero" class="thoughtbot">&nbsp;</button>
<button id="resetShort" class="thoughtbot">Reset Short</button>
</div> </div>

View File

@ -2,7 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>DEFCON</title> <title><%= title =></title>
<meta name="description" content=""> <meta name="description" content="">
<meta name="author" content=""> <meta name="author" content="">