feat(ws): add a warning toast if websocket gets disconnected

This commit is contained in:
Elian Doran 2025-09-24 21:50:07 +03:00
parent 619888847b
commit 59ce8b912d
No known key found for this signature in database
2 changed files with 12 additions and 5 deletions

View File

@ -7,6 +7,7 @@ import appContext from "../components/app_context.js";
import { t } from "./i18n.js";
import type { EntityChange } from "../server_types.js";
import { WebSocketMessage } from "@triliumnext/commons";
import toast from "./toast.js";
type MessageHandler = (message: WebSocketMessage) => void;
let messageHandlers: MessageHandler[] = [];
@ -278,13 +279,17 @@ function connectWebSocket() {
async function sendPing() {
if (Date.now() - lastPingTs > 30000) {
console.log(
utils.now(),
"Lost websocket connection to the backend. If you keep having this issue repeatedly, you might want to check your reverse proxy (nginx, apache) configuration and allow/unblock WebSocket."
);
console.warn(utils.now(), "Lost websocket connection to the backend");
toast.showPersistent({
id: "lost-websocket-connection",
title: t("ws.lost-websocket-connection-title"),
message: t("ws.lost-websocket-connection-message"),
icon: "no-signal"
});
}
if (ws.readyState === ws.OPEN) {
toast.closePersistent("lost-websocket-connection");
ws.send(
JSON.stringify({
type: "ping",

View File

@ -1787,7 +1787,9 @@
"ws": {
"sync-check-failed": "Sync check failed!",
"consistency-checks-failed": "Consistency checks failed! See logs for details.",
"encountered-error": "Encountered error \"{{message}}\", check out the console."
"encountered-error": "Encountered error \"{{message}}\", check out the console.",
"lost-websocket-connection-title": "Lost connection to the server",
"lost-websocket-connection-message": "Check your reverse proxy (e.g. nginx or Apache) configuration to ensure WebSocket connections are properly allowed and not being blocked."
},
"hoisted_note": {
"confirm_unhoisting": "Requested note '{{requestedNote}}' is outside of hoisted note '{{hoistedNote}}' subtree and you must unhoist to access the note. Do you want to proceed with unhoisting?"