Added websockts for admin interface
This commit is contained in:
parent
536c1272d8
commit
b7cf1e4d9a
@ -13,7 +13,7 @@ function pause() {};
|
|||||||
function reset() {};
|
function reset() {};
|
||||||
function end() {};
|
function end() {};
|
||||||
function print() {};
|
function print() {};
|
||||||
|
function getValues() {};
|
||||||
|
|
||||||
function start() {
|
function start() {
|
||||||
if(isPaused == true && durationLeft.asSeconds() != 0) { // Only allow start if timer ist currently paused and durationLeft is not 0 seconds
|
if(isPaused == true && durationLeft.asSeconds() != 0) { // Only allow start if timer ist currently paused and durationLeft is not 0 seconds
|
||||||
@ -61,6 +61,15 @@ function print() {
|
|||||||
return minutes + ":" + seconds
|
return minutes + ":" + seconds
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getValues() {
|
||||||
|
return {
|
||||||
|
isPaused: isPaused,
|
||||||
|
duration: duration,
|
||||||
|
durationLeft: durationLeft,
|
||||||
|
print: print()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
duration, durationLeft, isPaused, start, pause, reset, end, print
|
duration, durationLeft, isPaused, start, pause, reset, end, print, getValues
|
||||||
};
|
}
|
||||||
@ -1,3 +1,20 @@
|
|||||||
|
let wss = "ws://" + window.location.hostname + ":3001" // Build socketio endpoint from window.location
|
||||||
|
const socket = io(wss); // Connect to socketio server
|
||||||
|
|
||||||
|
socket.on('connected', (message) => { // Once client is connected to websocket
|
||||||
|
console.log("Connected");
|
||||||
|
initialUpdate() // Request important values to update admin frontend
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('timerDurationLeft', (message) => {
|
||||||
|
console.log(message) // Log durationLeft in client console
|
||||||
|
document.getElementById("durationLeft").innerHTML = message; // Display durationLeft in corresponding html Element
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('timerEnded', (message) => {
|
||||||
|
initialUpdate(); // Update admin frontend to set correct buttonstatus
|
||||||
|
});
|
||||||
|
|
||||||
function updateFrontend(values) {
|
function updateFrontend(values) {
|
||||||
values.duration = moment.duration(values.duration) // Create moment object from ISO 8601 string
|
values.duration = moment.duration(values.duration) // Create moment object from ISO 8601 string
|
||||||
values.durationLeft = moment.duration(values.durationLeft) // Create moment object from ISO 8601 string
|
values.durationLeft = moment.duration(values.durationLeft) // Create moment object from ISO 8601 string
|
||||||
|
|||||||
@ -11,5 +11,5 @@ socket.on('timerDurationLeft', (message) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on('timerEnded', (message) => {
|
socket.on('timerEnded', (message) => {
|
||||||
document.getElementById("durationLeft").innerHTML = "STOP"; // Display "STOP" in same html element as the duration
|
document.getElementById("durationLeft").innerHTML = "ENDE"; // Display "STOP" in same html element as the duration
|
||||||
});
|
});
|
||||||
@ -1,7 +1,7 @@
|
|||||||
var express = require('express');
|
var express = require('express');
|
||||||
var router = express.Router();
|
var router = express.Router();
|
||||||
|
|
||||||
let timer = require('../controllers/timer');
|
var timer = require('../controllers/timer');
|
||||||
|
|
||||||
// Express router entpoint to start the timer
|
// Express router entpoint to start the timer
|
||||||
router.get('/timerStart', function(req, res, next) {
|
router.get('/timerStart', function(req, res, next) {
|
||||||
@ -36,6 +36,8 @@ router.get('/timerGetValues', function(req, res, next) {
|
|||||||
res.json(timer.getValues()); // Respond with important values for frontend
|
res.json(timer.getValues()); // Respond with important values for frontend
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Express router endpoint to switch the score after halftime
|
||||||
|
router.get('/scoreSwitch', function(req, res, next) {
|
||||||
res.render('admin');
|
res.render('admin');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user