24 lines
665 B
C#
24 lines
665 B
C#
using IM_API.Application.Interfaces;
|
|
using IM_API.Domain.Events;
|
|
using IM_API.Hubs;
|
|
using IM_API.Tools;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
|
|
namespace IM_API.Application.EventHandlers
|
|
{
|
|
public class SignalREventHandler : IEventHandler<MessageCreatedEvent>
|
|
{
|
|
private readonly IHubContext<ChatHub> _hub;
|
|
public SignalREventHandler(IHubContext<ChatHub> hub)
|
|
{
|
|
_hub = hub;
|
|
}
|
|
|
|
public async Task Handle(MessageCreatedEvent @event)
|
|
{
|
|
var streamKey = @event.StreamKey;
|
|
await _hub.Clients.Group(streamKey).SendAsync(SignalRMethodDefine.ReceiveMessage, @event);
|
|
}
|
|
}
|
|
}
|