jitsi-roomsv2/frontend/src/hooks/useBackendData.ts
2023-02-07 20:31:07 +01:00

27 lines
766 B
TypeScript

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