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