Page 1 of 1

How to map parameters in TscHubConnection.Register method?

Posted: Wed 11 Mar 2020 12:23
by oscar
Hi All,

This snippet is how we setup our client in javascript:
...
this.connection = new signalR.HubConnectionBuilder()
.withUrl(URL_ENDPOINT, { accessTokenFactory: () => this.loginToken })
.build();
this.connection.on("ReceiveNotification", (info, kind) => this.receiveNotification(info, kind));
yield this.connection.start();
...

Where the info is an object (marshalled as json) & kind is an enum (int).

When setting up a TscHubConnection in Delphi,
how do i map these expected parameters to the TscHubConnection.Register method?

eg:
hubConnection.Register('ReceiveNotification', HandleReceiveNotification, [var??, var??] );

Tia, Rj

Re: How to map parameters in TscHubConnection.Register method?

Posted: Wed 11 Mar 2020 15:13
by ViktorV
The type of the parameter should match the type of the method declared on the server. For example, if the method is declared in the following way:

Code: Select all

public async Task ReceiveNotification(string info, int kind)
then the method should be registered as follows

Code: Select all

hubConnection.Register('ReceiveNotification', HandleReceiveNotification, [varString, varInteger]);

Re: How to map parameters in TscHubConnection.Register method?

Posted: Wed 11 Mar 2020 15:40
by oscar
Hi VictorV,

Our SignalR server has been implemented in asp.net core,
and the first parameter (info) I reffered to is a C# class, used as a POCO.
So the question still remains, what's the TVarType i have to use?

Thanks, Rj

Re: How to map parameters in TscHubConnection.Register method?

Posted: Thu 12 Mar 2020 13:33
by ViktorV
You can assign the type varString to the parameter info, in which case you'll be able to read the responce as a JSON string and use it at your discretion.

Re: How to map parameters in TscHubConnection.Register method?

Posted: Thu 12 Mar 2020 14:36
by oscar
Hi,

Thanks for your suggestion, i have tried it, and my callback function gets called, however Values array has zero elements!?
Any ideas?

Tia, Rj

Re: How to map parameters in TscHubConnection.Register method?

Posted: Thu 12 Mar 2020 14:56
by oscar
Hi,

Little update here...
After a restart of my session, i have a json-payload as parm in my callback!

Thanks, Rj

Re: How to map parameters in TscHubConnection.Register method?

Posted: Fri 13 Mar 2020 10:01
by ViktorV
Thank you for interest to our product.
Feel free to contact us if you have any further questions about our products.