Reconnect websocket on window focus (#366)

This commit is contained in:
advo-kat 2023-01-29 04:24:16 +11:00 committed by GitHub
parent 5427dd0f5b
commit 0056d94d57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -164,8 +164,14 @@ USE_EFFECT = join(
" if(!isReady) {{",
" return;",
" }}",
f" if (!{SOCKET}.current) {{{{",
f" connect({SOCKET}, {{state}}, {{set_state}}, {RESULT}, {SET_RESULT}, {ROUTER}, {EVENT_ENDPOINT})",
" const reconnectSocket = () => {{",
f" {SOCKET}.current.reconnect()",
" }}",
f" if (typeof {SOCKET}.current !== 'undefined') {{{{",
f" if (!{SOCKET}.current) {{{{",
f" window.addEventListener('focus', reconnectSocket)",
f" connect({SOCKET}, {{state}}, {{set_state}}, {RESULT}, {SET_RESULT}, {ROUTER}, {EVENT_ENDPOINT})",
" }}",
" }}",
" const update = async () => {{",
f" if ({RESULT}.{STATE} != null) {{{{",