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