简体   繁体   中英

SignalR subscribe all hubs/methods at once

I'd like to make a simple wrapper for SignalR on clientside. It basically should have method send(hubName, methodName, args) and trigger some kind of callback(hubName, methodName, args) without explicit subscription to specific hubs.

Is there an easy way to do it or i should dig into jquery.signalR ? Thanks in advance.

So it seems to be something like that:

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 is kind of request counter. It's included in responses for corresponding requests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM