【问题标题】:Feathersjs know when server is offline(from the client)Feathersjs 知道服务器何时离线(来自客户端)
【发布时间】:2021-07-05 17:50:34
【问题描述】:

我有一个 Angular 应用程序,它使用 @feathersjs/authentication-client 使用 socket.iofeathers-reactive 连接到 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 被初始化并寻找没有找到它的服务器。

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

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

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

提前致谢

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

【问题讨论】:

    标签: feathersjs


    【解决方案1】:

    所以消息/错误来自 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'));
    

    【讨论】:

      猜你喜欢
      • 2016-10-12
      • 1970-01-01
      • 2015-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多