fix: harden frontend reconnect callbacks
This commit is contained in:
parent
85858d8fd8
commit
464496222f
2 changed files with 33 additions and 3 deletions
|
|
@ -280,7 +280,7 @@ if (topbar) {
|
||||||
|
|
||||||
// Handle connection draining reconnect events
|
// Handle connection draining reconnect events
|
||||||
window.addEventListener("phx:reconnect", ((e: CustomEvent<{ delay?: number }>) => {
|
window.addEventListener("phx:reconnect", ((e: CustomEvent<{ delay?: number }>) => {
|
||||||
const delay = e.detail.delay || 1000;
|
const delay = e.detail?.delay || 1000;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
liveSocket.disconnect();
|
liveSocket.disconnect();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
@ -297,7 +297,11 @@ liveSocket.connect();
|
||||||
document.addEventListener("visibilitychange", () => {
|
document.addEventListener("visibilitychange", () => {
|
||||||
if (document.visibilityState === "visible") {
|
if (document.visibilityState === "visible") {
|
||||||
const socket = (liveSocket as any).socket;
|
const socket = (liveSocket as any).socket;
|
||||||
if (socket && socket.connectionState() !== "open") {
|
if (
|
||||||
|
socket &&
|
||||||
|
typeof socket.connectionState === "function" &&
|
||||||
|
socket.connectionState() !== "open"
|
||||||
|
) {
|
||||||
socket.disconnect(() => socket.connect());
|
socket.disconnect(() => socket.connect());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -316,7 +320,12 @@ window.addEventListener("phx:live_socket:connect", (_info) => {
|
||||||
// Also check periodically in case the event doesn't fire
|
// Also check periodically in case the event doesn't fire
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const socket = (liveSocket as any).socket;
|
const socket = (liveSocket as any).socket;
|
||||||
if (socket && socket.isConnected() && socket.fallbackTimer) {
|
if (
|
||||||
|
socket &&
|
||||||
|
typeof socket.isConnected === "function" &&
|
||||||
|
socket.isConnected() &&
|
||||||
|
socket.fallbackTimer
|
||||||
|
) {
|
||||||
clearTimeout(socket.fallbackTimer);
|
clearTimeout(socket.fallbackTimer);
|
||||||
socket.fallbackTimer = null;
|
socket.fallbackTimer = null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1018,15 +1018,36 @@ let MapAPRSMap = {
|
||||||
if ("geolocation" in navigator) {
|
if ("geolocation" in navigator) {
|
||||||
navigator.geolocation.getCurrentPosition(
|
navigator.geolocation.getCurrentPosition(
|
||||||
(position) => {
|
(position) => {
|
||||||
|
if (
|
||||||
|
!self.pushEvent ||
|
||||||
|
typeof self.pushEvent !== "function" ||
|
||||||
|
self.isDestroyed
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const { latitude, longitude } = position.coords;
|
const { latitude, longitude } = position.coords;
|
||||||
self.pushEvent("set_location", { lat: latitude, lng: longitude });
|
self.pushEvent("set_location", { lat: latitude, lng: longitude });
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
|
if (
|
||||||
|
!self.pushEvent ||
|
||||||
|
typeof self.pushEvent !== "function" ||
|
||||||
|
self.isDestroyed
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
console.warn("Geolocation error:", error.message);
|
console.warn("Geolocation error:", error.message);
|
||||||
self.pushEvent("geolocation_error", { error: error.message });
|
self.pushEvent("geolocation_error", { error: error.message });
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
if (
|
||||||
|
!self.pushEvent ||
|
||||||
|
typeof self.pushEvent !== "function" ||
|
||||||
|
self.isDestroyed
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
console.warn("Geolocation not available");
|
console.warn("Geolocation not available");
|
||||||
self.pushEvent("geolocation_error", {
|
self.pushEvent("geolocation_error", {
|
||||||
error: "Geolocation not supported",
|
error: "Geolocation not supported",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue