mirror of
https://github.com/sr229/kuru-kuru.git
synced 2024-09-20 04:10:33 +00:00
re-set connection handlers on reconnection
This commit is contained in:
parent
2ab8369d4e
commit
d46adc06c5
1 changed files with 7 additions and 3 deletions
|
@ -98,9 +98,7 @@ export default function Counter(props: SharedProps) {
|
||||||
}, 5000));
|
}, 5000));
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
const handleWSEvents = (ws: WebSocket) => {
|
||||||
let ws = new WebSocket(window.location.href.replace("http", "ws"));
|
|
||||||
|
|
||||||
ws.onopen = () => {
|
ws.onopen = () => {
|
||||||
console.log(
|
console.log(
|
||||||
`[${new Date().toISOString()}] Connected to statistics socket`,
|
`[${new Date().toISOString()}] Connected to statistics socket`,
|
||||||
|
@ -123,10 +121,16 @@ export default function Counter(props: SharedProps) {
|
||||||
console.error(`[${new Date().toISOString()}] Socket Errored. Aggressively reconnecting...`,);
|
console.error(`[${new Date().toISOString()}] Socket Errored. Aggressively reconnecting...`,);
|
||||||
ws = new WebSocket(window.location.href.replace("http", "ws"));
|
ws = new WebSocket(window.location.href.replace("http", "ws"));
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let ws = new WebSocket(window.location.href.replace("http", "ws"));
|
||||||
|
handleWSEvents(ws);
|
||||||
|
|
||||||
const onlineHandler = () => {
|
const onlineHandler = () => {
|
||||||
console.log("Client detected online, resuming connection.");
|
console.log("Client detected online, resuming connection.");
|
||||||
ws = new WebSocket(window.location.href.replace("http", "ws"));
|
ws = new WebSocket(window.location.href.replace("http", "ws"));
|
||||||
|
handleWSEvents(ws);
|
||||||
};
|
};
|
||||||
|
|
||||||
const offlineHandler = () => {
|
const offlineHandler = () => {
|
||||||
|
|
Loading…
Reference in a new issue