Open odesey opened 4 years ago
I am also in need of a way to detect if my server is down.
I have a list of servers and I would like to connect to one that is up and running.
I have taken a similar approach to @odesey.
Here is what I have done so far.
const getServer = () => {
const serverUrls = [
"wss://..../websocket",
"wss://...../websocket",
];
let Server: SimpleDDP | null = null;
let isServerHealthy = false;
serverUrls.map(async endpoint => {
try {
if (!Server?.connected) {
const opts = {
endpoint,
SocketConstructor: ws,
reconnectInterval: 500,
autoConnect: false,
autoReconnect: false
};
Server = new SimpleDDP(opts, [simpleDDPLogin]);
await Server.connect()
isServerHealthy = await Server?.call("healthcheck");
}
console.log("url", endpoint, isServerHealthy, Server?.connected); // never called
} catch (err) {
console.log("Error connect server", err); // never called
}
});
console.log("final status", Server?.connected); // called
return Server;
};
Also, none of the event callbacks are called.
if the last endpoint in my array is valid, then the connection is established and everything works.
Do you have any ideas on how I could accomplish this?
Thanks.
My issue is similar to #18 and #21
I have a
react-native
app and I connect to my development server like so:If the
Meteor server
is running, everything works. If I stop the server, and attempt to load the App, theconsole.log()
statements never get called.I also tied the following:
None of the
server.on('error', ...)
events are called as well.How can I check if the server is available and connected?
Thanks.