cleanup + small refract

- websockets
- event api
This commit is contained in:
cv
2021-04-11 19:17:54 +02:00
parent dee0ff1a5c
commit 964bdf0d2a
12 changed files with 145 additions and 149 deletions
@@ -23,19 +23,16 @@ export default function MessageControl() {
visible: false,
});
// Torbjorn: why is this not updating?
useEffect(() => {
if (socket == null) return;
// Handle presenter messages
socket.on('messages-presenter', (data) => {
console.log('websocket: got data', data);
setPres({ ...data });
});
// Handle public messages
socket.on('messages-public', (data) => {
console.log('websocket: got data', data);
setPubl({ ...data });
});
@@ -43,8 +40,11 @@ export default function MessageControl() {
socket.emit('get-presenter');
socket.emit('get-public');
// Clear listener
return () => socket.off('messages-presenter', 'messages-public');
// Clear listeners
return () => {
socket.off('messages-public');
socket.off('messages-presenter');
};
}, [socket]);
const messageControl = async (action, payload) => {