如何在SignalR中关闭客户端JavaScript"Hub"连接? [英] How can I close the client-side JavaScript 'Hub' connection in SignalR?
本文介绍了如何在SignalR中关闭客户端JavaScript"Hub"连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已遵循
解决方案
根据Microsoft,JavaScript客户端包含停止功能.
I have followed this tutorial.
But there is no hint how to close the Websocket connection via the HubConnection
class in signalr.js
-file. The file is V1.0.4.
This solution does not resolve my problem because I am using the 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:
解决方案
According to Microsoft the JavaScript client contains a stop function.
In addition, you can find the .stop()-Method in the prototype of the framework:
这篇关于如何在SignalR中关闭客户端JavaScript"Hub"连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文