jitsi-roomsv2/frontend/src/hooks/useBackendData.ts

27 lines
766 B
TypeScript
Raw Normal View History

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