bugfix with socket client
- client now subscribes to events
- client gets playstate on start
This commit is contained in:
cv
2021-04-11 13:10:57 +02:00
parent 4ce9a40e64
commit dee0ff1a5c
3 changed files with 47 additions and 16 deletions
@@ -39,23 +39,32 @@ export default function PlaybackControl() {
expectedFinish: null,
});
// Torbjorn: why is this not updating?
// handle incoming messages
useEffect(() => {
if (socket == null) return;
// Subscribe to timer event
socket.emit('subscribe-to-timer');
// ask for playstate
socket.emit('get-playstate');
socket.on('playstate', (data) => {
setPlayback(data);
});
// Handle timer
socket.on('timer', (data) => {
console.log('websocket: got data', data);
setTimer({ ...data });
});
// Clear listener
return () => socket.off('timer');
return () => {
socket.emit('release-timer');
socket.off('timer');
};
}, [socket]);
// TO SEND TO SOCKET HERE WE CAN USE
// socket.emit('test')
// TODO: Move to playback API
// Soould this go through sockets?
const playbackControl = async (action, payload) => {