improve iOS Safari LiveView reliability
increase longPollFallbackMs from 2500 to 5000 to prevent premature fallback on mobile networks, and add visibilitychange handler to reconnect WebSocket when returning from a backgrounded tab
This commit is contained in:
parent
61368e5c5e
commit
7a83b13faa
1 changed files with 10 additions and 1 deletions
|
|
@ -1205,7 +1205,7 @@ const StatusTitle = {
|
|||
}
|
||||
|
||||
const liveSocket = new LiveSocket("/live", Socket, {
|
||||
longPollFallbackMs: 2500,
|
||||
longPollFallbackMs: 5000,
|
||||
params: { _csrf_token: csrfToken, timezone: userTimezone },
|
||||
hooks: { ...colocatedHooks, SensorChart, CopyToClipboard, ScrollToTop, AutoDismissFlash, BetaBannerDismiss, NetworkMap, SitesMap, LeafletMap, DeviceListReorder, MikrotikPortSync, GlobalSearch, GlobalSearchTrigger, DynamicFavicon, StatusTitle },
|
||||
})
|
||||
|
|
@ -1266,6 +1266,15 @@ window.addEventListener("phx:download", (event: any) => {
|
|||
window.URL.revokeObjectURL(url)
|
||||
})
|
||||
|
||||
// Reconnect WebSocket when returning from background (iOS Safari optimization)
|
||||
document.addEventListener("visibilitychange", () => {
|
||||
if (document.visibilityState === "visible") {
|
||||
if (liveSocket.socket.connectionState() !== "open") {
|
||||
liveSocket.socket.disconnect(() => liveSocket.socket.connect())
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// connect if there are any LiveViews on the page
|
||||
liveSocket.connect()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue