diff --git a/src/lib/store/runtimeConfig/runtimeConfig.slice.ts b/src/lib/store/runtimeConfig/runtimeConfig.slice.ts index 6ba404b..d940c3a 100644 --- a/src/lib/store/runtimeConfig/runtimeConfig.slice.ts +++ b/src/lib/store/runtimeConfig/runtimeConfig.slice.ts @@ -10,6 +10,7 @@ const initialState: RuntimeConfigState = { pluginVersion: '', disconnectionMessage: '', token: '', + roomKey: '', roomData: { clientId: '', roomKey: '', @@ -45,7 +46,7 @@ const runtimeConfigSlice = createSlice({ state.roomData = action.payload; }, setCurrentRoomKey(state, action: PayloadAction) { - state.roomData.roomKey = action.payload; + state.roomKey = action.payload; }, setUserCode(state, action: PayloadAction) { state.roomData.userCode = action.payload.userCode; @@ -63,6 +64,7 @@ export interface RuntimeConfigState { pluginVersion: string; disconnectionMessage: string; token: string; + roomKey: string; roomData: RoomData; } diff --git a/src/lib/store/runtimeConfig/runtimeSelectors.ts b/src/lib/store/runtimeConfig/runtimeSelectors.ts index b3f51b3..52b1421 100644 --- a/src/lib/store/runtimeConfig/runtimeSelectors.ts +++ b/src/lib/store/runtimeConfig/runtimeSelectors.ts @@ -2,7 +2,7 @@ import { useAppSelector } from '../hooks'; export const useWsIsConnected = () => useAppSelector((state) => state.runtimeConfig.websocket.isConnected); -export const useRoomKey = () => useAppSelector((state) => state.runtimeConfig.roomData.roomKey); +export const useRoomKey = () => useAppSelector((state) => state.runtimeConfig.roomKey); export const useClientId = () => useAppSelector((state) => state.runtimeConfig.roomData.clientId); diff --git a/src/lib/utils/WebsocketProvider.tsx b/src/lib/utils/WebsocketProvider.tsx index 122513f..cc8d20d 100644 --- a/src/lib/utils/WebsocketProvider.tsx +++ b/src/lib/utils/WebsocketProvider.tsx @@ -95,9 +95,10 @@ const WebsocketProvider = ({ children }: { children: ReactNode }) => { * @param value */ const sendSimpleMessage = + useCallback( (type: string, value: boolean | number | string ) => { sendMessage(type, { value }); - }; + },[sendMessage]) const addEventHandler = useCallback( (eventType: string, key: string, callback: (data: Message) => void) => { @@ -261,7 +262,7 @@ const WebsocketProvider = ({ children }: { children: ReactNode }) => { clientRef.current = null; }; - }, [appConfig.apiPath, appConfig.gatewayAppPath, getRoomData, roomKey, serverIsRunningOnProcessorHardware, systemUuid, token, userCode, waitingToReconnect]); + }, [appConfig.apiPath, appConfig.gatewayAppPath, getRoomData, serverIsRunningOnProcessorHardware, systemUuid, token, userCode, waitingToReconnect]); /** * Send a status message to the server to get the current state of the room when the roomKey changes @@ -270,7 +271,8 @@ const WebsocketProvider = ({ children }: { children: ReactNode }) => { if (roomKey) { sendMessage(`/room/${roomKey}/status`, null); } - }, [roomKey, sendMessage]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [roomKey]); //* RENDER **********************************************************/ return (