jitsi-roomsv2/frontend/src/hooks/useBackendData.ts
open-schnick 34cdf4aea1
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is failing
small changes
2023-04-10 23:45:43 +02:00

29 lines
928 B
TypeScript

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