import { useEffect } from 'react' import { UserInfo } from '../components/jitsi/types' import useAllChat from './useAllChat' import useRoomData from './useRoomData' import useWebSocketConnection from './useWebSocketConnection' function useBackendData(userInfo: UserInfo) { console.log('[Rooms] useBackendData') const { onMessage, sendMessage, disconnect } = useWebSocketConnection(userInfo) const { roomData, setRoomData } = useRoomData() const { addChatMessage } = useAllChat() useEffect(() => { onMessage((messageString) => { console.log('[Rooms] message from ws', messageString) const messageObject = JSON.parse(messageString) !!messageObject.roomsData && setRoomData(messageObject) !!messageObject.content && addChatMessage(messageObject) return disconnect }) }, [onMessage, setRoomData, disconnect]) return { roomData, sendMessage } } export default useBackendData