Make Websocket Client try to reconnect when connection is lost?
Closed this issue · 1 comments
OfficialCRUGG commented
Hey there. I have two NodeJS Processes. One is a Faye Server and the other uses the Faye Client.
A problem right now is, that if the Server crashes, gets restarted etc., the Client Process needs to be restarted as well. Is there any way to make it automatically try to reconnect after a specific interval?
My Code:
//// index.ts
import { ws } from "./faye";
// some other things here which calls other files which then access the ws Variable
export { ws };
//// faye.ts
import * as WebSocket from "faye-websocket";
const ws = new WebSocket.Client("ws://localhost:1234/");
ws.on("open", (event) => {
console.log("Connected to Server");
});
ws.on("error", (event) => {
console.log("Connection to Server failed");
// Somehow reconnect the Websocket here
});
export { ws };
I already tried overwriting ws
Variable to a new Client in the error event, but that doesn't work either...
OfficialCRUGG commented
GitHub frontend apparently messed something up. Sorry for the double-post.