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

            if (channelEvent.ChannelName != "TestChannel")
            {
                // Push this out on the test channel
                //
                Clients.Group("TestChannel").OnEvent("TestChannel", channelEvent);
            }

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

            Publish(ev);

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

            Publish(ev);

            return(base.OnConnected());
        }
Example #4
0
        public async Task Subscribe(string channel)
        {
            await Groups.Add(Context.ConnectionId, channel);

            var ev = new ChannelEvent
            {
                ChannelName = "TestChannel",
                Name        = "user.subscribed",
                Data        = new
                {
                    Context.ConnectionId,
                    ChannelName = channel
                }
            };

            await Publish(ev);
        }