Answer the question
In order to leave comments, you need to log in
How to add HubProxy dynamically in SignalR?
There are two hubs UserOrderHub and UserLocationHub.
UserOrderHub - should run when the user is logged in to the site.
UserLocationHub - should be launched when the user has entered the site.
If you run the following methods in this order, only the last UserOrderHub will work.
//Зашел на сайт
initUserLocationHub()
//Авторизовался через форму
initUserOrderHub()
var connection = $.hubConnection();
var initUserOrderHub = function() {
var UserOrderHub = connection.createHubProxy('UserOrderHub');
$.signalR.ajaxDefaults.headers = {
Authorization: 'Bearer {here token string}'
};
UserOrderHub.on('orderStatusChanged', function(data) {
console.log('orderStatusChanged', data);
});
connection.start();
};
var initUserLocationHub = function() {
var UserLocationHub = connection.createHubProxy('UserLocationHub');
UserLocationHub.on('courierLocationChanged', function(data) {
console.log('courierLocationChanged', data);
});
connection.start();
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question