2016-03-03 63 views
0

我想爲SignalR在客戶端做一個簡單的封裝。它基本上應該有方法send(hubName, methodName, args)並觸發某種callback(hubName, methodName, args)沒有明確訂閱特定的集線器。SignalR一次訂閱所有集線器/方法

有沒有一種簡單的方法來做到這一點,或者我應該挖掘到jquery.signalR?提前致謝。

回答

0

所以它似乎是類似的東西:

function send(hub, method, args) { 
    $.signalR.hub.send({ 
     H: method, 
     M: method, 
     A: args, 
     I: requestId++ // some global var which increments with every request 
    }); 
} 

$.signalR.hub.received(function(resp) { 
    if (resp.I) { 
     const requestId = resp.I; 
     const response = resp.R; 
     console.log('Response received', requestId, response); 
    } else { 
     const hub = resp.H; 
     const method = resp.M; 
     const args = resp.A; 
     console.log('Server sent event received', hub, method, args); 
    } 
}); 

I是一種請求計數器的。它包含在對相應請求的響應中。