Created
December 23, 2021 05:58
-
-
Save MahdiKarimipour/1a5e1cd0786e841002a0a941fd6c5448 to your computer and use it in GitHub Desktop.
Pellerex Realtime Messaging with SignalR Hubs
This file contains hidden or 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
| [Authorize] | |
| public class ChatHub : Hub | |
| { | |
| private readonly IChatService chatService; | |
| public ChatHub(IChatService chatService) | |
| { | |
| this.chatService = chatService; | |
| } | |
| public async Task JoinRoom(UserConnection userConnection) | |
| { | |
| await Groups.AddToGroupAsync(Context.ConnectionId, userConnection.ChatGroupId); | |
| } | |
| public async Task SendMessageToGroup(ChatMessageViewModel message) | |
| { | |
| var result = await chatService.ProcessMessage(message, Context.User.GetUserId()); | |
| if (result == MessagingConstants.ErrorCodes.GroupNotFound) | |
| { | |
| return; | |
| } | |
| await Clients.Group(message.ChatGroupId.ToString()).SendAsync("ReceiveMessage", message); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment