-
Notifications
You must be signed in to change notification settings - Fork 1
/
ChatHub.cs
38 lines (33 loc) · 1.16 KB
/
ChatHub.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR;
namespace ChatHub.IntegrationTests
{
public class ChatHub : Hub
{
public async Task SendMessage(string user, string message)
{
await Clients.All.SendAsync("OnReceiveMessage", user, message);
}
public Task SendMessageToCaller(string message)
{
return Clients.Caller.SendAsync("OnReceiveMessage", message);
}
public Task SendMessageToGroups(string message)
{
List<string> groups = new List<string>() { "SignalR Users" };
return Clients.Groups(groups).SendAsync("OnReceiveMessage", message);
}
public override async Task OnConnectedAsync()
{
await Groups.AddToGroupAsync(Context.ConnectionId, "SignalR Users");
await base.OnConnectedAsync();
}
public override async Task OnDisconnectedAsync(Exception exception)
{
await Groups.RemoveFromGroupAsync(Context.ConnectionId, "SignalR Users");
await base.OnDisconnectedAsync(exception);
}
}
}