Ejemplo n.º 1
0
        public void CreateOrJoin(string key, string name)
        {
            var group = _groups.FirstOrDefault(g => g.Key == key);

            if (group == null)
            {
                group = new DrinkingGroup {
                    Key = key, Owner = Context.ConnectionId
                };
                _groups.Add(group);
            }

            if (group.HasFinished || group.HasStarted)
            {
                throw new Exception("You cannot join a group which has started or finished");
            }

            group.Glasses.Add(new Glass {
                ConnectionId = Context.ConnectionId, Name = name
            });

            BroadcastGroup(group);
            GetConnectionId();
        }
Ejemplo n.º 2
0
        private void BroadcastGroup(DrinkingGroup group, bool removing = false)
        {
            var clients = group.Glasses.Select(g => g.ConnectionId).ToList();

            Clients.Clients(clients).SendAsync("Group", removing ? null : group);
        }