【发布时间】:2018-09-12 20:35:43
【问题描述】:
我有一些关于 SignalR 的问题。
第一个问题:
我已经下载了这样的信号器:npm install @aspnet/signalr 根据Npmjs (v1.0.3)。
但是,经过进一步检查,我的信号器文件不包含重新连接功能,如在此处的github:343 上可以找到的。
事实上,这似乎是两个不同的回购。为什么不一样,好像都是微软开发的?
这是两个仓库:https://github.com/SignalR/SignalR 和https://github.com/aspnet/SignalR
第二个问题:
我尝试在我的应用程序中实现重新连接功能,但我可以使用的功能有限。这是我目前的方法(因为我在第一个 repo 中缺少重新连接功能)下面的代码会在断开连接时产生此输出:
signalr.min.js:1353 Error: Connection disconnected with error 'Error: Server timeout elapsed without receiving a message from the server.'.
Uncaught TypeError: this.connect is not a function
at HubConnection.eval
trying to connect...
Uncaught TypeError: this.connect is not a function
at HubConnection.eval
trying to connect...
etc... etc...
代码:
this.connection.onclose(function (error) {
if (!this.isConnected) {
this.isConnected = false;
appService.emit("disconnected", true);
var intervalFunc = setInterval(function () {
console.log("trying to connect...");
this.connect();
if (this.isConnected) {
this.appService.emit("connected", true);
this.isConnected = true;
clearInterval(intervalFunc);
console.log("connection established");
}
}.bind(this), 5000);
}
});
在尝试实现重新连接功能时,我也遵循了这些资源:
- https://stackoverflow.com/a/23407156/2902996
- https://docs.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/handling-connection-lifetime-events#how-to-continuously-reconnect
- https://github.com/davidfowl/UT3/blob/dac409886c1bb7aec7c150b74d4ce9a3e246f03c/UTT/wwwroot/js/utt.js#L141-L153
- https://github.com/aspnet/Docs/issues/6757
任何帮助将不胜感激。
【问题讨论】:
标签: asp.net angularjs typescript signalr