joe*_*oey 7 javascript c# signalr typescript angular
我正在使用
"@aspnet/signalr": "^1.1.4",
Run Code Online (Sandbox Code Playgroud)
在 Angular 8 项目中。
不幸的是,文档似乎已过时?
https://docs.microsoft.com/en-us/aspnet/core/signalr/javascript-client?view=aspnetcore-3.1
文档声称有一种方法
withAutomaticReconnect()
Run Code Online (Sandbox Code Playgroud)
用作
const connection = new signalR.HubConnectionBuilder()
.withUrl("/chatHub")
.withAutomaticReconnect()
.build();
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试输入它时,我得到
“HubConnectionBuilder”类型上不存在属性“WithAutomaticReconnect”
这是文档过时的问题吗?还是我误解了配置?
这是我尝试添加此方法之前的确切代码
private _hubConnection: HubConnection;
Run Code Online (Sandbox Code Playgroud)
...
this._hubConnection = new HubConnectionBuilder()
.withUrl(this.myAPIUrl + '/myHub', { accessTokenFactory: () => tokenFromCache })
.configureLogging(signalR.LogLevel.Error)
.build();
Run Code Online (Sandbox Code Playgroud)
小智 8
您参考的文档使用 npm 包“@microsoft/signalr”,而您的使用“@aspnet/signalr”
小智 5
你需要一个更新的版本,我相信它是版本 3,只需在你的终端运行以下命令,我正在将它与反应前端一起使用。
npm install @microsoft/signalr
Run Code Online (Sandbox Code Playgroud)
也许你可以这样做
this._hubConnection.start().catch(_ => setTimeout(() => {
this._hubConnection.start();
}, 1000));
Run Code Online (Sandbox Code Playgroud)
因此,如果出现任何异常,它会将您的客户端重新连接到集线器
| 归档时间: |
|
| 查看次数: |
1898 次 |
| 最近记录: |