Added websockts for admin interface
This commit is contained in:
@@ -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) {
|
||||
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
|
||||
|
||||
@@ -11,5 +11,5 @@ socket.on('timerDurationLeft', (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
|
||||
});
|
||||
Reference in New Issue
Block a user