Feathersjs 知道服务器何时离线(来自客户端)

时间:2021-07-02 11:34:17

标签: feathersjs

我有一个 Angular 应用程序,它使用 socket.io 连接到带有 feathers-reactive@feathersjs/authentication-client 的 Feathers API。这很好用!

这是我的客户端代码:

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'
        }));
}

在这种情况下,我只是启动了应用程序而不是 API。 Feathers 被初始化并寻找没有找到它的服务器。

Connection keeps on trying...

And the error tells me it's CORS even though it's not

我想在 Angular 应用程序中了解服务器何时关闭?

每当发生此类错误时,是否有任何类型的事件、订阅、回调或其他任何类型可以从上述代码中获取?

非常感谢有关此事的任何帮助/提示/指示!

提前致谢

*考虑到包含所有 socketioauthentication-clientfeathers-reactive 的配置的性质,我什至不知道错误来自哪里。

1 个答案:

答案 0 :(得分:0)

所以消息/错误来自 socket.io 和 socket.io 有以下事件,你可以听:

_socket.on("disconnect", () => changeServerState('disconnected'));
_socket.on("connect", () => changeServerState('connected'));
_socket.on("connect_error", () => changeServerState('error'));
_socket.on("connect_timeout", () => changeServerState('connect_timeout'));