[英]How can I close the client-side JavaScript 'Hub' connection in SignalR?
I have followed this tutorial . 我已经按照本教程 。
But there is no hint how to close the Websocket connection via the HubConnection
class in signalr.js
-file. 但是没有提示如何通过
signalr.js
-file中的HubConnection
类关闭Websocket连接。 The file is V1.0.4. 该文件是V1.0.4。
This solution does not resolve my problem because I am using the microsofts javascript-library. 此解决方案无法解决我的问题,因为我正在使用microsofts javascript-library。
Here ist the code: 这是代码:
var lHubConnection = null;
var Init = function () {
// create instance
lHubConnection = new signalR.lHubConnectionBuilder().withUrl("/chatHub").build();
// receive message
lHubConnection.on("ReceiveMessage", function (pMessage) {
// show message
console.log(JSON.parse(pMessage));
});
// [...]
};
// close websocket connection
var CloseConnection = function(){
if (lHubConnection !== null && lHubConnection.connection.connectionState === 1) {
// lHubConnection.invoke("?"); ???
}
};
Here is an console output of the lHubConnection instance: 这是lHubConnection实例的控制台输出:
According to Microsoft the JavaScript client contains a stop function. 据微软称,JavaScript客户端包含一个停止功能。
https://docs.microsoft.com/en-us/javascript/api/%40aspnet/signalr/hubconnection?view=signalr-js-latest#stop https://docs.microsoft.com/en-us/javascript/api/%40aspnet/signalr/hubconnection?view=signalr-js-latest#stop
In addition, you can find the .stop()-Method in the prototype of the framework: 另外,你可以在框架的原型中找到.stop() - Method:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.