From bf5fce76d95c61a2578786f28d2288baadd115b7 Mon Sep 17 00:00:00 2001 From: Balte de Wit Date: Thu, 12 Nov 2020 14:06:13 +0100 Subject: [PATCH] fix: subscribe to VU meters upon connection --- client/index.tsx | 3 --- client/utils/SocketClientHandlers.ts | 7 +++++++ server/utils/vuServer.ts | 5 ++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/client/index.tsx b/client/index.tsx index 58e26240..f0d1b777 100644 --- a/client/index.tsx +++ b/client/index.tsx @@ -57,9 +57,6 @@ socketClientHandlers() window.socketIoClient.emit('get-store', 'update local store') window.socketIoClient.emit('get-settings', 'update local settings') window.socketIoClient.emit('get-mixerprotocol', 'get selected mixerprotocol') -if (!window.location.search.includes('vu=0')) { - window.socketIoClient.emit('subscribe-vu-meter', 'subscribe to vu meters') -} ReactDom.render( diff --git a/client/utils/SocketClientHandlers.ts b/client/utils/SocketClientHandlers.ts index 4302f455..98d2cd04 100644 --- a/client/utils/SocketClientHandlers.ts +++ b/client/utils/SocketClientHandlers.ts @@ -36,6 +36,13 @@ export const socketClientHandlers = () => { .on('connect', () => { window.storeRedux.dispatch(storeSetServerOnline(true)) console.log('CONNECTED TO SISYFOS SERVER') + if (!window.location.search.includes('vu=0')) { + // subscribe to VU' + window.socketIoClient.emit( + 'subscribe-vu-meter', + 'subscribe to vu meters' + ) + } }) .on('disconnect', () => { window.storeRedux.dispatch(storeSetServerOnline(false)) diff --git a/server/utils/vuServer.ts b/server/utils/vuServer.ts index 278e09d5..5d2b7054 100644 --- a/server/utils/vuServer.ts +++ b/server/utils/vuServer.ts @@ -6,7 +6,10 @@ export enum VuType { const sockets: Array = [] export function socketSubscribeVu(socket: any) { - sockets.push(socket) + const i = sockets.indexOf(socket) + if (i === -1) { + sockets.push(socket) + } } export function socketUnsubscribeVu(socket: any) {