22 lines
567 B
React
22 lines
567 B
React
|
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]);
|
||
|
}
|