this.signalr = new signalR.HubConnectionBuilder()
.withUrl('/pipelinehub')
.build();
this.signalr.start();
this.signalr.on('somemethod', function () { ... });
那么如果我想停止监听这个方法,我应该怎么做呢?
根据 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>
不过你在使用 On
和 Off
一起来看一下。来看看。