Skip to content

Commit d713aad

Browse files
lizh-lixiangvicancy
authored andcommitted
Set up the base frame of ReliableChatRoom sample (#108)
* Add ChatRoomWithAck sample. Add ChatRoomWithAck sample. Sending a message to a specified user will log the status (Sent, Arrived, Acknowledged) on the chat screen. The user who received the message can ack each message by clicking it. The server now stores the message for offline users. They will receive these messages the next time they login into this page with the same userName.
1 parent ab4ffe7 commit d713aad

File tree

10 files changed

+489
-0
lines changed

10 files changed

+489
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
bin/
2+
obj/
3+
.vs/
4+
**.csproj.user
5+
*.sln
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using Microsoft.AspNetCore.SignalR;
5+
using System.Security.Claims;
6+
7+
namespace Microsoft.Azure.SignalR.Samples.ReliableChatRoom
8+
{
9+
public class ReliableChatRoom : Hub
10+
{
11+
public void BroadcastMessage(string name, string message)
12+
{
13+
Clients.All.SendAsync("broadcastMessage", name, message);
14+
}
15+
16+
public string SendUserMessage(string messageId, string receiver, string messageContent)
17+
{
18+
var sender = Context.User.FindFirstValue(ClaimTypes.NameIdentifier);
19+
Clients.User(receiver).SendAsync("displayUserMessage", messageId, sender, messageContent);
20+
21+
// TODO: Create and add the new message to the storage
22+
23+
return "Sent";
24+
}
25+
26+
public string SendUserAck(string messageId, string sender, string messageStatus)
27+
{
28+
// TODO: Update the messageStatus in the storage
29+
30+
Clients.User(sender).SendAsync("displayAckMessage", messageId, messageStatus);
31+
32+
return "Sent";
33+
}
34+
}
35+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using Microsoft.AspNetCore;
5+
using Microsoft.AspNetCore.Hosting;
6+
7+
namespace Microsoft.Azure.SignalR.Samples.ReliableChatRoom
8+
{
9+
public class Program
10+
{
11+
public static void Main(string[] args)
12+
{
13+
CreateWebHostBuilder(args).Build().Run();
14+
}
15+
16+
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
17+
WebHost.CreateDefaultBuilder(args)
18+
.UseStartup<Startup>();
19+
}
20+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:5000/",
7+
"sslPort": 0
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"environmentVariables": {
15+
"ASPNETCORE_ENVIRONMENT": "Development"
16+
}
17+
},
18+
"ChatRoom": {
19+
"commandName": "Project",
20+
"launchBrowser": true,
21+
"environmentVariables": {
22+
"ASPNETCORE_ENVIRONMENT": "Development"
23+
},
24+
"applicationUrl": "http://localhost:5000/"
25+
}
26+
}
27+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
<PropertyGroup>
3+
<TargetFramework>netcoreapp2.2</TargetFramework>
4+
<UserSecretsId>reliablechatroom</UserSecretsId>
5+
<RootNamespace>Microsoft.Azure.SignalR.Samples.ReliableChatRoom</RootNamespace>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<Folder Include="wwwroot\" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.*" />
14+
<PackageReference Include="Microsoft.Azure.SignalR" Version="1.0.*" />
15+
</ItemGroup>
16+
</Project>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using Microsoft.AspNetCore.Builder;
5+
using Microsoft.Extensions.Configuration;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using System.Security.Claims;
8+
9+
namespace Microsoft.Azure.SignalR.Samples.ReliableChatRoom
10+
{
11+
public class Startup
12+
{
13+
public Startup(IConfiguration configuration)
14+
{
15+
Configuration = configuration;
16+
}
17+
18+
public IConfiguration Configuration { get; }
19+
20+
public void ConfigureServices(IServiceCollection services)
21+
{
22+
services.AddMvc();
23+
services.AddSignalR()
24+
.AddAzureSignalR(options =>
25+
{
26+
options.ClaimsProvider = context => new[]
27+
{
28+
new Claim(ClaimTypes.NameIdentifier, context.Request.Query["username"])
29+
};
30+
});
31+
}
32+
33+
public void Configure(IApplicationBuilder app)
34+
{
35+
app.UseMvc();
36+
app.UseFileServer();
37+
app.UseAzureSignalR(routes =>
38+
{
39+
routes.MapHub<ReliableChatRoom>("/chat");
40+
}
41+
);
42+
}
43+
}
44+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"Logging": {
3+
"IncludeScopes": false,
4+
"Debug": {
5+
"LogLevel": {
6+
"Default": "Debug"
7+
}
8+
},
9+
"Console": {
10+
"LogLevel": {
11+
"Default": "Debug"
12+
}
13+
}
14+
}
15+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*html, body {
2+
font-size: 16px;
3+
}
4+
5+
@media all and (max-device-width: 720px) {
6+
html, body {
7+
font-size: 20px;
8+
}
9+
}*/
10+
11+
html, body {
12+
padding: 0;
13+
height: 100%;
14+
}
15+
16+
#messages {
17+
width: 100%;
18+
border: 1px solid #ccc;
19+
height: calc(100% - 120px);
20+
float: none;
21+
margin: 0px auto;
22+
padding-left: 0px;
23+
overflow-y: auto;
24+
}
25+
26+
textarea:focus {
27+
outline: none !important;
28+
}
29+
30+
.system-message {
31+
background: #87CEFA;
32+
}
33+
34+
.broadcast-message {
35+
display: inline-block;
36+
background: yellow;
37+
margin: auto;
38+
padding: 5px 10px;
39+
}
40+
41+
.message-entry {
42+
overflow: auto;
43+
margin: 8px 0;
44+
}
45+
46+
.message-avatar {
47+
display: inline-block;
48+
padding: 10px;
49+
max-width: 8em;
50+
word-wrap: break-word;
51+
}
52+
53+
.message-content {
54+
display: inline-block;
55+
background-color: #b2e281;
56+
padding: 10px;
57+
margin: 0 0.5em;
58+
max-width: calc(60%);
59+
word-wrap: break-word;
60+
}
61+
62+
.message-content.pull-left:before {
63+
width: 0;
64+
height: 0;
65+
display: inline-block;
66+
float: left;
67+
border-top: 10px solid transparent;
68+
border-bottom: 10px solid transparent;
69+
border-right: 10px solid #b2e281;
70+
margin: 15px 0;
71+
}
72+
73+
.message-content.pull-right:after {
74+
width: 0;
75+
height: 0;
76+
display: inline-block;
77+
float: right;
78+
border-top: 10px solid transparent;
79+
border-bottom: 10px solid transparent;
80+
border-left: 10px solid #b2e281;
81+
margin: 15px 0;
82+
}
31.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)