简体   繁体   English

如何在SignalR中关闭客户端JavaScript“Hub”连接?

[英]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:

signalrR原型

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将数据输入Javascript以进行客户端处理? - How can I input data to Javascript for client-side processing? 如何强制用户至少选中一个复选框,然后从客户端JavaScript回发? - How can I force the user to have at least one selected checkbox, and postback from client-side javascript? 客户端javascript:不允许使用CORS时,如何获取HTTP请求的响应标头? - Client-side javascript: how can I get the response header of a HTTP request when CORS is not allowed? 如何从客户端JavaScript代码访问Java列表元素? - How can I access Java list elements from my client-side JavaScript code? 如何在客户端 javascript 中将 .wav 文件从 url 转换为 base64? - how can i convert .wav file from url to base64 in client-side javascript? 如何使用ASP.NET添加客户端(JavaScript)确认消息框? - How can I add a client-side (JavaScript) confirmation message box using ASP.NET? 如何在客户端的 javascript 中访问 Django 返回的 json object? - How can I access a Django returned json object in javascript / on the client-side? 如何从客户端 Javascript 文件中访问 Express app.locals 变量? - How can I access an Express app.locals variable from within a client-side Javascript file? 如何通过全客户端实现来保护 Firebase? - How can I secure Firebase with an all client-side implementation? 如何在客户端访问GridView的DataKey单元? - How can I reach DataKey cells of GridView on the client-side?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM