Skip to content

Commit 716888f

Browse files
authored
Merge pull request #137 from JialinXin/blazor-chat
Add a tutorial to build a simple chat Blazor Server app.
2 parents d489f4e + e82a01e commit 716888f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2071
-0
lines changed

docs/images/blazorchat-azure.png

73.2 KB
Loading

docs/images/blazorchat-profile.gif

90.5 KB
Loading

docs/images/blazorchat.gif

436 KB
Loading
4 KB
Loading
34.9 KB
Loading
8.9 KB
Loading

samples/BlazorChat/App.razor

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
<Router AppAssembly="@typeof(Program).Assembly">
3+
<Found Context="routeData">
4+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
5+
</Found>
6+
<NotFound>
7+
<LayoutView Layout="@typeof(MainLayout)">
8+
<p>Sorry, there's nothing at this address.</p>
9+
</LayoutView>
10+
</NotFound>
11+
</Router>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.7" />
9+
<PackageReference Include="Microsoft.Azure.SignalR" Version="1.4.0" />
10+
</ItemGroup>
11+
12+
</Project>

samples/BlazorChat/BlazorChat.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30404.54
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorChat", "BlazorChat.csproj", "{CB98C96E-8B22-41E2-84C7-89FE3507CAA5}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{CB98C96E-8B22-41E2-84C7-89FE3507CAA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{CB98C96E-8B22-41E2-84C7-89FE3507CAA5}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{CB98C96E-8B22-41E2-84C7-89FE3507CAA5}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{CB98C96E-8B22-41E2-84C7-89FE3507CAA5}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {20B707F6-886D-4DC7-8D78-0F691346FA8E}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
4+
using Microsoft.AspNetCore.SignalR;
5+
6+
namespace BlazorChat
7+
{
8+
public class BlazorChatSampleHub : Hub
9+
{
10+
public const string HubUrl = "/chat";
11+
12+
public async Task Broadcast(string username, string message)
13+
{
14+
await Clients.All.SendAsync("Broadcast", username, message);
15+
}
16+
17+
public override Task OnConnectedAsync()
18+
{
19+
Console.WriteLine($"{Context.ConnectionId} connected");
20+
return base.OnConnectedAsync();
21+
}
22+
23+
public override async Task OnDisconnectedAsync(Exception e)
24+
{
25+
Console.WriteLine($"Disconnected {e?.Message} {Context.ConnectionId}");
26+
await base.OnDisconnectedAsync(e);
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)