我如何在Angle 8项目中为SignalR配置重新连接逻辑?

问题描述 投票:-1回答:1

我正在使用

    "@aspnet/signalr": "^1.1.4",

在Angular 8项目中。

很遗憾,文档似乎已过时?

https://docs.microsoft.com/en-us/aspnet/core/signalr/javascript-client?view=aspnetcore-3.1

文档声称有一种方法

withAutomaticReconnect()

用作

const connection = new signalR.HubConnectionBuilder()
    .withUrl("/chatHub")
    .withAutomaticReconnect()
    .build();

但是,当我尝试输入时,我得到

类型'HubConnectionBuilder'不存在属性'WithAutomaticReconnect'

这是文档过期问题吗?还是我误解了配置?

这是我尝试添加此方法之前的确切代码

    private _hubConnection: HubConnection;

...

        this._hubConnection = new HubConnectionBuilder()
        .withUrl(this.myAPIUrl + '/myHub', { accessTokenFactory: () => tokenFromCache })
        .configureLogging(signalR.LogLevel.Error)
        .build();
signalr signalr-hub
1个回答
0
投票

也许您可以这样做

this._hubConnection.start().catch(_ => setTimeout(() => {
            this._hubConnection.start();
        }, 1000));

因此,如果有任何异常,它将重新将您的客户端连接到集线器

© www.soinside.com 2019 - 2024. All rights reserved.