Skip to content

SignalR Hub Example Update to 7 plus add Hub Client Results #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

wadepickett
Copy link
Contributor

@wadepickett wadepickett commented Mar 30, 2023

------ Collaborative Work In Progress while in draft ------

Contributes to

Changes from existing 6.x version:

  • Updated to .NET 7 from scratch so it has the latest js libraries, templates, etc.
  • Added ChatHubClientResults.cs to the hub snippet examples provided by serpent5 last 7/2022.

@wadepickett wadepickett self-assigned this Mar 30, 2023
@wadepickett wadepickett changed the title SignalR Hub Example Update to 7 plus add Hub Client Return SignalR Hub Example Update to 7 plus add Hub Client Results Mar 30, 2023
@wadepickett
Copy link
Contributor Author

wadepickett commented Mar 30, 2023

@BrennanConroy,

Could you help me with the 3 Client Results hub classes for our standard hubs SingalRChat sample?
This Client Results section of this doc: [Use hubs in SignalR for ASP.NET Core]{https://learn.microsoft.com/en-us/aspnet/core/signalr/hubs?view=aspnetcore-7.0#client-results} has 3 include code samples that are generalized, but I need to move them into compilable/usable snippets here. Then I can link the updated snippets back the doc.

The 3 Client Results hub samples are here in this PR:

  1. SignalRHubsSample\Snippets\Hubs\ChatHubClientResults.cs
  2. SignalRHubsSample\Snippets\Hubs\ChatHubClientResultsContext.cs
  3. SignalRHubsSample\Snippets\Hubs\ChatHubClientResultsStronglyTyped.cs

image

Sorry to ask, I have been trying to work out the intent of how client results work but I'm not up to speed enough on SignalR to pull it off.

// <snippet_HubClientResultsStronglyTyped>
public interface IClient
{
Task<string> GetMessage();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to take a CancellationToken parameter.

// <snippet_HubClientReturnContext>
public class ChatHubClientResultsContext : Hub
{
async Task SomeMethod(IHubContext<ChatHubClientResultsContext> context)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an odd way to use IHubContext. It's probably better from a controller or minimal api:
https://learn.microsoft.com/aspnet/core/signalr/hubcontext?view=aspnetcore-7.0#inject-an-instance-of-ihubcontext-in-a-controller

.withUrl("/chat")
.build();

connection.on("ReceiveMessage", (user, message) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the intent is to have a runnable app, we'll need to add javascript code for the client results
https://learn.microsoft.com/aspnet/core/signalr/hubs?view=aspnetcore-7.0#typescript-client

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BrennanConroy, sorry, I should have been more clear. I just took your code that was inline from the doc. I was hoping you could create runnable versions of them so we have one runnable sample somewhere. I do not have enough experience with SignalR to make your original samples work. Sorry for the confusion.

@wadepickett
Copy link
Contributor Author

closing and reopening to run checks again

@wadepickett wadepickett reopened this Dec 12, 2023
@Rick-Anderson
Copy link
Contributor

@wadepickett can you update this for .NET 9?

@Rick-Anderson
Copy link
Contributor

@wadepickett can you update this for .NET 9?

Make that .NET 10?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants