AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

SignalR with TypeScript code examples do not match other articles

Open RyanTaite opened this issue 6 years ago • 0 comments

The method used in the TypeScript example for ChatHub.cs is:

public async Task NewMessage(long username, string message)
{
    await Clients.All.SendAsync("messageReceived", username, message);
}

Both the JavaScript and Blazor examples use:

public async Task SendMessage(string user, string message)
{
    await Clients.All.SendAsync("ReceiveMessage", user, message);
}

The differences being:

  • NewMessage -> SendMessage
  • long username -> string user
  • "messageReceived" -> "ReceiveMessage"

This is also present in the .ts/.js.|.razor examples where they call the methods, and anywhere in the article that references to it of course. Biggest difference (besides the name changes) is that the TypeScript example doesn't have a username input field, it just uses the Date().getTime() value

A smaller but similiar difference is the endpoint defined:

TypeScript example

endpoints.MapHub<ChatHub>("/hub");

versus the JavaScript and Blazor example:

endpoints.MapHub<ChatHub>("/chathub");

This tripped me up personally when I was reading the Strongly Typed Hubs article that uses the JavaScript and Blazor example syntax


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

RyanTaite avatar Nov 05 '20 18:11 RyanTaite