Skip to content

Commit 11e0225

Browse files
author
Dave 'Gizmo' Gymer
committed
Simple SignalR implementation.
1 parent 7a884a6 commit 11e0225

File tree

7 files changed

+5357
-1
lines changed

7 files changed

+5357
-1
lines changed

Controlzmo/Hub.cs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Microsoft.AspNetCore.SignalR;
2+
using System.Threading.Tasks;
3+
4+
namespace Controlzmo
5+
{
6+
public class TestHub : Hub
7+
{
8+
// Nothing magic about user, it and message are just arguments
9+
public async Task TestMessage(string message)
10+
{
11+
await Clients.All.SendAsync("TestMessage", message);
12+
}
13+
}
14+
}

Controlzmo/Pages/Index.cshtml

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
</tr>
1313
<tr>
1414
<th>@Html.DisplayNameFor(model => model.Field2)</th>
15-
<td>@Model.Field2</td>
15+
<td id="clickyClicky">@Model.Field2</td>
1616
</tr>
1717
</table>
18+
<ul id="messagesList"></ul>
1819
</div>
20+
21+
<script src="~/js/signalr/dist/browser/signalr.js"></script>
22+
<script src="~/js/test.js"></script>

Controlzmo/Startup.cs

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public Startup(IConfiguration configuration)
2323
public void ConfigureServices(IServiceCollection services)
2424
{
2525
services.AddRazorPages();
26+
services.AddSignalR();
2627
}
2728

2829
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -46,6 +47,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
4647
app.UseEndpoints(endpoints =>
4748
{
4849
endpoints.MapRazorPages();
50+
endpoints.MapHub<TestHub>("/hub/test");
4951
});
5052
}
5153
}

Controlzmo/libman.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"version": "1.0",
3+
"defaultProvider": "cdnjs",
4+
"libraries": [
5+
{
6+
"provider": "unpkg",
7+
"library": "@microsoft/signalr@latest",
8+
"destination": "wwwroot/js/signalr/",
9+
"files": [
10+
"dist/browser/signalr.js",
11+
"dist/browser/signalr.min.js"
12+
]
13+
}
14+
]
15+
}

0 commit comments

Comments
 (0)