To register a callback for a specific method in SignalR (JavaScript), you can do the following:
hubConnection.on("MyMethod", (...) => { ... });
However, is it possible to be able to listen to all methods and to get all arguments?
To register a callback for a specific method in SignalR (JavaScript), you can do the following:
hubConnection.on("MyMethod", (...) => { ... });
However, is it possible to be able to listen to all methods and to get all arguments?
I don't believe so because you have to register all of your callbacks before starting the connection. This example from the docs shows this.
"use strict";
var connection = new signalR.HubConnectionBuilder().withUrl("/chatHub").build();
//Disable send button until connection is established
document.getElementById("sendButton").disabled = true;
connection.on("ReceiveMessage", function (user, message) {
var msg = message.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
var encodedMsg = user + " says " + msg;
var li = document.createElement("li");
li.textContent = encodedMsg;
document.getElementById("messagesList").appendChild(li);
});
connection.start().then(function () {
document.getElementById("sendButton").disabled = false;
}).catch(function (err) {
return console.error(err.toString());
});
document.getElementById("sendButton").addEventListener("click", function (event) {
var user = document.getElementById("userInput").value;
var message = document.getElementById("messageInput").value;
connection.invoke("SendMessage", user, message).catch(function (err) {
return console.error(err.toString());
});
event.preventDefault();
});