Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions UI/ChatSignalR/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
# Chat SignalR App

Implements [SignalR library](https://learn.microsoft.com/en-us/aspnet/core/signalr/introduction?view=aspnetcore-3.1) for asynchronous notifications in an Uno Platform application.
Implements [ASP.NET Core SignalR](https://learn.microsoft.com/en-us/aspnet/core/signalr/introduction) for real-time notifications in an Uno Platform application.

To try out the sample, first launch an instance of the UnoChat.Service project which hosts the server that the chat clients will connect to. Next, simply launch any number of UnoChat projects which will serve as the chat clients. If you want to add chat clients that are hosted by system consoles, you can launch any number of them as well using the UnoChat.Client.Console project.
To try out the sample:

1. Launch `UnoChat.Service` first (the SignalR server).
2. Launch one or more `UnoChat` clients (Uno Platform app).
3. Optionally launch one or more `UnoChat.Client.Console` clients.

All clients connect to `https://localhost:7167/chatHub` by default.

> [!NOTE]
> An Azure account is not required for this sample. It runs locally.

## Quick start

From `src/`:

```bash
# Run the SignalR server
dotnet run --project UnoChat.Service

# Run the console client (optional)
dotnet run --project UnoChat.Client.Console
```

Run the Uno app from your IDE using one of the platform launch profiles in `UnoChat`.

![ChatSignalR Image](doc/assets/chatSignalR.png)

Expand Down
2 changes: 1 addition & 1 deletion UI/ChatSignalR/src/UnoChat.Client.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static async Task Main(string[] args)
Console.WriteLine($"Ok {name} one second, we're going to connect to the SignalR server...");

var connection = new HubConnectionBuilder()
.WithUrl("https://localhost:7167/ChatHub")
.WithUrl("https://localhost:7167/chatHub")
.WithAutomaticReconnect()
.Build();

Expand Down
41 changes: 26 additions & 15 deletions UI/ChatSignalR/src/UnoChat.Service/Program.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
namespace UnoChat.Service
using UnoChat.Service.Hubs;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddSignalR();

builder.Services.AddCors(options =>
{
public class Program
options.AddPolicy("CorsPolicy", policy =>
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
policy
.AllowAnyHeader()
.AllowAnyMethod()
.SetIsOriginAllowed(_ => true)
.AllowCredentials();
});
});

var app = builder.Build();

app.UseCors("CorsPolicy");

app.MapGet("/", () => "UnoChat SignalR Service is running.");
app.MapHub<ChatHub>("/chatHub");

app.Run();

public partial class Program { }
64 changes: 0 additions & 64 deletions UI/ChatSignalR/src/UnoChat.Service/Startup.cs

This file was deleted.

2 changes: 1 addition & 1 deletion UI/ChatSignalR/src/UnoChat/Presentation/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public ViewModel()
_allMessages = new ObservableCollection<Model>();

_connection = new HubConnectionBuilder()
.WithUrl("https://localhost:7167/ChatHub")
.WithUrl("https://localhost:7167/chatHub")
//.WithUrl("http://localhost:61877")
.WithAutomaticReconnect()
.Build();
Expand Down
4 changes: 3 additions & 1 deletion UI/ChatSignalR/src/global.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"Uno.Sdk": "5.3.96"
},
"sdk":{
"allowPrerelease": false
"version": "8.0.100",
"allowPrerelease": false,
"rollForward": "latestFeature"
}
}
Loading