Skip to content

Instantly share code, notes, and snippets.

@MahdiKarimipour
Created December 23, 2021 05:58
Show Gist options
  • Select an option

  • Save MahdiKarimipour/1a5e1cd0786e841002a0a941fd6c5448 to your computer and use it in GitHub Desktop.

Select an option

Save MahdiKarimipour/1a5e1cd0786e841002a0a941fd6c5448 to your computer and use it in GitHub Desktop.
Pellerex Realtime Messaging with SignalR Hubs
[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