Exemplo n.º 1
0
        public async Task <IActionResult> IdentifyAsync(string subscriberId, [FromBody] User user)
        {
            user.Guid = (await _connections.GetConnectionInfoAsync(subscriberId)).Guid;
            await _broadcastService.IdentifyAsync(subscriberId, user);

            return(Ok());
        }
Exemplo n.º 2
0
        public async Task SubscribeAsync(string subscriberId, string channel)
        {
            await _subscriptions.SubscribeAsync(subscriberId, channel);

            await _context.Groups.AddToGroupAsync(subscriberId, channel);

            var user = await _connections.GetConnectionInfoAsync(subscriberId);

            await PublishAsync(channel, new Subscribe { Channel = channel, User = user });

            await Task.WhenAll((await _subscriptions.GetSubscribersAsync(channel)).Select(async subscriber =>
            {
                if (subscriber != subscriberId)
                {
                    user = await _connections.GetConnectionInfoAsync(subscriber);
                    await WhisperAsync(subscriberId, new Subscribe {
                        Channel = channel, User = user
                    });
                }
            }));
        }