mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-07 16:33:51 +00:00
bugfix
bugfix with socket client - client now subscribes to events - client gets playstate on start
This commit is contained in:
+28
-10
@@ -52,26 +52,44 @@ const io = socketIo(server, {
|
||||
},
|
||||
});
|
||||
|
||||
// Torbjorn: should the interval be here or inside the connection?
|
||||
// I am guessing one interval per timer
|
||||
// interval function
|
||||
let interval;
|
||||
|
||||
io.on('connection', (socket) => {
|
||||
console.log('New client connected');
|
||||
|
||||
// timer API
|
||||
socket.emit('timer', timer.getObject());
|
||||
// let interval = null;
|
||||
|
||||
// avoid multiple intervals
|
||||
if (interval) {
|
||||
clearInterval(interval);
|
||||
}
|
||||
// set callback for timer events
|
||||
interval = setInterval(() => getApiAndEmit(socket), config.timer.refresh);
|
||||
// subscribe to timer
|
||||
socket.on('subscribe-to-timer', () => {
|
||||
console.log('New subscription');
|
||||
// avoid multiple intervals
|
||||
if (interval) clearInterval(interval);
|
||||
|
||||
// send current data
|
||||
socket.emit('timer', timer.getObject());
|
||||
|
||||
// set callback for timer events
|
||||
interval = setInterval(() => emitTimer(socket), config.timer.refresh);
|
||||
});
|
||||
|
||||
// unsubscribe to timer
|
||||
socket.on('release-timer', () => {
|
||||
console.log('Releasing subscription');
|
||||
// avoid multiple intervals
|
||||
if (interval) clearInterval(interval);
|
||||
});
|
||||
|
||||
socket.on('get-timer', () => {
|
||||
socket.emit('timer', timer.getObject());
|
||||
});
|
||||
|
||||
socket.on('get-playstate', () => {
|
||||
socket.emit('playstate', timer.playState);
|
||||
});
|
||||
|
||||
// playback API
|
||||
socket.on('set-presenter-text', (data) => {
|
||||
timer.presenterText = data;
|
||||
@@ -104,12 +122,12 @@ io.on('connection', (socket) => {
|
||||
// handle client disconnect
|
||||
socket.on('disconnect', () => {
|
||||
console.log('Client disconnected');
|
||||
clearInterval(interval);
|
||||
if (interval) clearInterval(interval);
|
||||
});
|
||||
});
|
||||
|
||||
// send timer events
|
||||
const getApiAndEmit = (socket) => {
|
||||
const emitTimer = (socket) => {
|
||||
// send current timer
|
||||
socket.emit('timer', timer.getObject());
|
||||
};
|
||||
|
||||
@@ -88,6 +88,10 @@ class Timer {
|
||||
return Timer.toSeconds(this._current);
|
||||
}
|
||||
|
||||
get playState() {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
// playback
|
||||
start() {
|
||||
// do we need to change
|
||||
|
||||
Reference in New Issue
Block a user