Generateurv2/frontend/hooks/useReconnecting.jsx

22 lines
567 B
React
Raw Normal View History

2022-05-18 10:15:54 +02:00
import { useEffect, useState } from "react";
import { isBrowser } from "../utils/utils.js";
export default function useReconnecting(ws, url, connect, id_code) {
const [tried, setTried] = useState(false)
useEffect(() => {
if (ws == null) {
connect(url);
setTried(true);
//router.push({ pathname: "/room/join" });
} else if (ws != null && tried && isBrowser) {
ws.send(
JSON.stringify({
data: {
type: "reconnect",
clientId: clientId,
},
})
);
}
}, [tried]);
}