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:
- 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.
- 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 ...