-
Notifications
You must be signed in to change notification settings - Fork 0
/
SignalRBench.cs
69 lines (58 loc) · 2.06 KB
/
SignalRBench.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.AspNet.SignalR;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace ChatRoom
{
public class SignalRBench : Hub
{
public void Send(string name, string message)
{
// Call the broadcastMessage method to update clients.
Clients.All.broadcastMessage(name, message);
}
public Task TestEcho(string name, string message)
{
Clients.Client(Context.ConnectionId).testEchoBack(name, message);
return Task.CompletedTask;
}
public Task Echo(IDictionary<string, object> data)
{
Clients.Client(Context.ConnectionId).RecordLatency(data);
return Task.CompletedTask;
}
public void Broadcast(IDictionary<string, object> data)
{
Clients.All.RecordLatency(data);
}
public void SendToClient(IDictionary<string, object> data)
{
var targetId = (string)data["information.ConnectionId"];
Clients.Client(targetId).RecordLatency(data);
}
public string GetConnectionId()
{
return Context.ConnectionId;
}
public void ConnectionId()
{
Clients.Client(Context.ConnectionId).ConnectionId(Context.ConnectionId);
}
public async Task JoinGroup(string groupName)
{
await Groups.Add(Context.ConnectionId, groupName);
Clients.Client(Context.ConnectionId).JoinGroup();
}
public async Task LeaveGroup(string groupName)
{
await Groups.Remove(Context.ConnectionId, groupName);
Clients.Client(Context.ConnectionId).LeaveGroup();
}
public void SendToGroup(IDictionary<string, object> data)
{
var groupName = (string)data["information.GroupName"];
Clients.Group(groupName).RecordLatency(data);
}
}
}