reconnect without delay on first try

This commit is contained in:
Roland Osborne 2022-11-28 11:39:09 -08:00
parent af39243ed8
commit fc5415eb3f

View File

@ -28,6 +28,7 @@ export function useAppContext() {
const card = useContext(CardContext);
const channel = useContext(ChannelContext);
const count = useRef(0);
const delay = useRef(0);
const ws = useRef(null);
@ -134,6 +135,7 @@ export function useAppContext() {
clearWebsocket();
ws.current = new WebSocket(`wss://${server}/status`);
ws.current.onmessage = (ev) => {
delay.current = 0;
try {
const rev = JSON.parse(ev.data);
try {
@ -162,9 +164,10 @@ export function useAppContext() {
ws.current.onclose = () => {}
ws.current.onopen = () => {}
ws.current.onerror = () => {}
delay.current = 1;
setWebsocket(server, token);
}
}, 1000)
}, 1000 * delay.current)
}
ws.current.onopen = () => {
ws.current.send(JSON.stringify({ AppToken: token }))