Multiple SignalR JS proxy instances, multiple callbacks

Is it possible to create multiple instances of the SignalR proxy server or implement a function callback once?

If I write something like:

var obj1 = function() 
{
    var someHub = $.connection.someHub;
    var self = this;

    someHub.client.someFunction = function(item){

        //do something
    };
}

var obj2 = function() 
{
    var someHub = $.connection.someHub;
    var self = this;

    someHub.client.someFunction = function(item){

        //do something else
    };
}

Which incarnation someFunctionwould be triggered? Is it possible to implement the same function twice and execute both implementations?

+4
source share
1 answer
var someHub = $.connection.someHub;

someHub.on('someFunction', function (item) { /* ... */ });
someHub.on('someFunction', function (item) { /* ... */ });

In the above code, both callbacks will be called in the order in which they were attached for each call Clients.*.someFunctionon the server.

http://www.asp.net/signalr/overview/signalr-20/hubs-api/hubs-api-guide-javascript-client#genproxy

+5
source

Source: https://habr.com/ru/post/1535807/


All Articles