JavaScript functions

Our client will need some code to send and consume messages to and from the server. I've tried to keep the JavaScript as simple as possible, opting for jQuery code for readability:

  1. Create a variable (I've named mine connection) for our SignalR Hub Server and call its start function:
let connection = new signalR.HubConnection('/chat');connection.start();

The '/chat' parameter for signalR.HubConnection refers to our Chat.cs class, which inherits the Hub interface from SignalR.

  1. Add the UpdateChat and Archived methods, which will be invoked by the server:
connection.on('UpdateChat', (user, message) => {updateChat(user, message);});connection.on('Archived', (message) => {updateChat('system', message);});

We simply pass ...

Get C# 7 and .NET Core 2.0 Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.