示例#1
0
        public Task Publish(ChannelEvent channelEvent)
        {
            Clients.Group(channelEvent.ChannelName).OnEvent(channelEvent.ChannelName, channelEvent);

            if (channelEvent.ChannelName != Constants.AdminChannel)
            {
                // Push this out on the admin channel
                //
                Clients.Group(Constants.AdminChannel).OnEvent(Constants.AdminChannel, channelEvent);
            }

            return(Task.FromResult(0));
        }
示例#2
0
        public override Task OnDisconnected(bool stopCalled)
        {
            var ev = new ChannelEvent
            {
                ChannelName = Constants.AdminChannel,
                Name        = "user.disconnected",
                Data        = new
                {
                    Context.ConnectionId,
                }
            };

            Publish(ev);

            return(base.OnDisconnected(stopCalled));
        }
示例#3
0
        public override Task OnConnected()
        {
            var ev = new ChannelEvent
            {
                ChannelName = Constants.AdminChannel,
                Name        = "user.connected",
                Data        = new
                {
                    Context.ConnectionId,
                }
            };

            Publish(ev);

            return(base.OnConnected());
        }
示例#4
0
        public async Task Unsubscribe(string channel)
        {
            await Groups.Remove(Context.ConnectionId, channel);

            var ev = new ChannelEvent
            {
                ChannelName = Constants.AdminChannel,
                Name        = "user.unsubscribed",
                Data        = new
                {
                    Context.ConnectionId,
                    ChannelName = channel
                }
            };

            await Publish(ev);
        }