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
var port = process.env.PORT || 5000;
app.listen(port, function() {
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
var host = process.env.HOST || '0.0.0.0';
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);
var stopwatch = new Stopwatch();
@ -63,7 +67,46 @@ io.sockets.on('connection', function (socket) {
stopwatch.stop();
});
socket.on('click:zero', function () {
stopwatch.zero();
});
socket.on('click:reset', function () {
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')
_ = require('underscore');
var DEFAULT_TIME = 45* 60 * 1000;
var DEFAULT_SHORT_TIME = 5 * 60 * 1000;
// ---------------------------------------------
// Constructor
// ---------------------------------------------
@ -13,7 +16,9 @@ function Stopwatch() {
this.hour = 3600000;
this.minute = 60000;
this.second = 1000;
this.time = this.hour;
this.defaultTime = DEFAULT_TIME;
this.defaultShortTime = DEFAULT_SHORT_TIME;
this.time = this.defaultTime;
this.interval = undefined;
events.EventEmitter.call(this);
@ -55,7 +60,19 @@ Stopwatch.prototype.stop = function() {
Stopwatch.prototype.reset = function() {
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));
};

View File

@ -15,3 +15,7 @@ $('#stop').click(function() {
$('#reset').click(function() {
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) {
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="stop" class="thoughtbot">Stop</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>

View File

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