Created
September 5, 2019 08:07
-
-
Save tocalai/6d772508bfbc3212e135d716a1fd7c11 to your computer and use it in GitHub Desktop.
Demonstrate bi-direction communication between server and client.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.SignalR; | |
using Microsoft.AspNetCore.SignalR; | |
namespace SignalR.Lab.Web.Hubs | |
{ | |
public interface IEventHub | |
{ | |
// here place some method(s) for message from server to client(s) (broadcast) | |
Task SendNoticeEventToClient(string message); | |
send message from server to specific group if client registered | |
//Task SendMessageToGroup(string group, string message); | |
} | |
public class EventHub : Hub<IEventHub> | |
{ | |
// here place some method(s) for message from client to server | |
// subscription or un-subscription for client(s) | |
public Task JoinOrLeaveGroup(string group, bool check) | |
{ | |
if (check) | |
{ | |
return Groups.AddToGroupAsync(Context.ConnectionId, group); | |
} | |
else | |
{ | |
return Groups.RemoveFromGroupAsync(Context.ConnectionId, group); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment