Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR - How to call server function with parameter from client using hubproxy

Tags:

signalr

I have my signalr running on a separate domain. We will have multiple applications using it to send and receive messages. I created the connection and hub proxy using the following code

connection = $.hubConnection("https://someurl.com", { useDefaultPath: false });
            chatHub = connection.createHubProxy('chatHub');

I can get messages from the server sent to the client using the following code which works fine

chatHub.on('receiveEntityMessage', function (chatMessage) {
                if (chatMessage) {
                    console.log(chatMessage.Message);
                }
            });

Now I dont know how to call server functions with parameters from the client. Can anybody please help me with this?

like image 549
Amitesh Avatar asked Nov 24 '25 23:11

Amitesh


1 Answers

chatHub.invoke("MethodName", param1, param2, param3).done(function(result) {
   console.log(result);
});
like image 117
Nimesco Avatar answered Nov 27 '25 22:11

Nimesco