Ejemplo n.º 1
0
        public async Task Publish(ChannelEvent channelEvent)
        {
            await Clients.Group(channelEvent.ChannelName).SendAsync(channelEvent.ChannelName, channelEvent);

            if (channelEvent.ChannelName != Constants.AdminChannel)
            {
                await Clients.Group(Constants.AdminChannel).SendAsync(Constants.AdminChannel, channelEvent);
            }
            await Task.FromResult(0);
        }
Ejemplo n.º 2
0
        public async override Task OnDisconnectedAsync(Exception exception)
        {
            var ev = new ChannelEvent
            {
                ChannelName = Constants.AdminChannel,
                Name        = "user.disconnected",
                Data        = new
                {
                    Context.ConnectionId,
                }
            };

            await Publish(ev);

            await Groups.RemoveFromGroupAsync(Context.ConnectionId, "SignalR Users");

            await base.OnDisconnectedAsync(exception);
        }
Ejemplo n.º 3
0
        public override async Task OnConnectedAsync()
        {
            var ev = new ChannelEvent
            {
                ChannelName = Constants.AdminChannel,
                Name        = "user.connected",
                Data        = new
                {
                    Context.ConnectionId,
                }
            };

            await Publish(ev);

            await Groups.AddToGroupAsync(Context.ConnectionId, Constants.AdminChannel);

            await base.OnConnectedAsync();
        }
Ejemplo n.º 4
0
        public async Task <ChannelEvent> Subscribe(string channel)
        {
            Trace.WriteLine(channel);
            await Groups.AddToGroupAsync(Context.ConnectionId, channel);

            var ev = new ChannelEvent
            {
                ChannelName = channel,
                Name        = "user.subscribed",
                Data        = new
                {
                    Context.ConnectionId,
                    ChannelName = channel
                }
            };
            await Clients.Caller.SendAsync("Subscribed", ev);

            return(ev);
        }
Ejemplo n.º 5
0
 public async Task PublishToSingleClient(ChannelEvent channelEvent)
 {
     await Clients.Client(Context.ConnectionId).SendAsync(channelEvent.ChannelName, channelEvent);
 }