I have an Angular app that connects to the Feathers API with socket.io
and feathers-reactive
using @feathersjs/authentication-client
. This works great!
This is my client code:
import * as feathersRx from 'feathers-reactive';
import * as io from 'socket.io-client';
import feathers from '@feathersjs/feathers';
import feathersSocketIOClient from '@feathersjs/socketio-client';
export function fInit(options: FeathersOptions): void {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const _feathersAuthClient = require('@feathersjs/authentication-client').default;
const _feathersApp = feathers();
const _socket: SocketIOClient.Socket = io(options.feathersIP, {
transports: ['websocket'],
forceNew: true
});
_feathersApp.configure(feathersSocketIOClient(_socket))
.configure(_feathersAuthClient({
storage: options.storage
}))
.configure(feathersRx({
idField: '_id'
}));
}
In this scenario I just started the app but not the API. Feathers gets initialized and looks for the server not finding it.
What I would like to know in the Angular app is when is the server down?
Is there any type of event, subscription, callback or anything else that I can get from the above code whenever an error like this occurs?
Any help/tip/pointer with this matter is greatly appreciated!
Thanks in advance
*Given the nature of the config with all the socketio
, authentication-client
, and feathers-reactive
, I don't even know where the error is coming from.
So the message/error is from socket.io and socket.io has the following events that you can listen to like:
_socket.on("disconnect", () => changeServerState('disconnected'));
_socket.on("connect", () => changeServerState('connected'));
_socket.on("connect_error", () => changeServerState('error'));
_socket.on("connect_timeout", () => changeServerState('connect_timeout'));