Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This hub created to let you get general ideas working with SignalR. There are nothing special. It does not even require you to be even authenticated.

To get fully working code navigate to https://mywebapiMyWebAPI.com/TestSignalRDemoSignalR/PingTest and get page source code.

To access hub you can get a link to it:

Code Block
languagejs
varconst hubconnection = $.connection.testnew signalR.HubConnectionBuilder()
    .withUrl('https://MyWebAPI.com/hubs/test/v1')
    .configureLogging(signalR.LogLevel.Debug)
    .build();

Method 'ping(string)'

You can pass any string to this method:

Code Block
languagejs
hub.server.ping("anything you want, current date and time, for example")connection
    .invoke("Ping", "test message")
    .then(() => console.log("Ping request sent"))
    .catch(err => console.error(err));

Server will be returned back through client side callback 'pong' exactly the same you have sent there:

Code Block
languagejs
// declare client-side callback
hub.client.pong = connection.on("pong",
    function(msg) {
        console.log("pong: " + msg);
    });

Get server time

Each second server will send its time through client side callback as of:

Code Block
languagejs
// declare client-side callback
hub.client.onClock = connection.on("onClock",
    function(clock) {
        console.log(clock);
    });