SignalR如何解除对方法监听器的绑定?

问题描述 投票:0回答:1
this.signalr = new signalR.HubConnectionBuilder()
                    .withUrl('/pipelinehub')
                    .build();
this.signalr.start();
this.signalr.on('somemethod', function () { ... });

那么如果我想停止监听这个方法,我应该怎么做呢?

asp.net signalr
1个回答
0
投票

根据 SignalR源码 你可以用 off:

从服务器中心删除给定事件名称的回调调用请求。

 off: function (eventName, callback, callbackIdentity) {
    /// <summary>Removes the callback invocation request from the server hub for the given event name.</summary>
    /// <param name="eventName" type="String">The name of the hub event to unregister the callback for.</param>
    /// <param name="callback" type="Function">The callback to be removed.</param>

不过你在使用 OnOff 一起来看一下。来看看。

jQuery SignalR客户端.off()函数只删除上次注册的回调。

© www.soinside.com 2019 - 2024. All rights reserved.