Note: This is tested only on ASP.NET Core 3.1 and may/may not work on older versions.
You can pass multiple objects from C# and then receive them all in a Typescript function with a similar signature. For brevity, i am including only the relevant parts.
On server side (I used C#), you can use something like this to send a message (with multiple object parameters) to the client.
IHubContext<MessageHub> _hubContext;
_hubContext.Clients.All.SendCoreAsync(
"MethodName",
new object[] {someObject, someNumber, someString });
On client side (in Typescript), you would have something like this to receive all parameters.
// Configure the hub connection.
this.hubConnection = new HubConnectionBuilder()
.withUrl(hubUrl, { accessTokenFactory: () => myToken })
.withAutomaticReconnect()
.configureLogging(LogLevel.Error)
.build();
// Wire up an event handler to receive messages.
private registerEvent = (eventName: string, index: number) => {
this.hubConnection.on(eventName, this.alertHandler);
};
private alertHandler = (someObject: any, someNumber: number, someString: string) => {
console.log(someObject, someNumber, someString);
};
Hope this helps.