Пример #1
0
        public async Task <List <string> > Join(long ticket)
        {
            ChatUserInfo info;

            if (!_awaitingUsers.TryGetValue(ticket, out info))
            {
                throw new InvalidInput(JoinRoomInvalidRetCode.ClientNotAwaited);
            }

            _awaitingUsers.Remove(ticket);
            ChatRoomClient client;

            if (!_usersById.TryGetValue(info.Id, out client))
            {
                client = new ChatRoomClient(Context.Source, info);
                _usersById.Add(info.Id, client);
                _usersByChannelId.Add(client.Peer.Channel.Id, client);

                client.DisconnectionSubscription = Context.Source.DisconnectedEvent.Subscribe(OnUserDisconnected);
            }
            string connectMsg = client.Info.Name + " has connected";

            _messages.Add(connectMsg);

            SendToAll(connectMsg);

            Log.Info("User<Name:{0}> has joined", client.Info.Name);
            return(_messages);
        }
        public async Task<List<string>> Join(long ticket)
        {
            ChatUserInfo info;
            if(!_awaitingUsers.TryGetValue(ticket, out info))
                throw new InvalidInput(JoinRoomInvalidRetCode.ClientNotAwaited);

            _awaitingUsers.Remove(ticket);
            ChatRoomClient client;
            if (!_usersById.TryGetValue(info.Id, out client))
            {
                client = new ChatRoomClient(Context.Source, info);
                _usersById.Add(info.Id, client);
                _usersByChannelId.Add(client.Peer.Channel.Id, client);

                client.DisconnectionSubscription = Context.Source.DisconnectedEvent.Subscribe(OnUserDisconnected);
            }
            string connectMsg = client.Info.Name + " has connected";
            _messages.Add(connectMsg);

            SendToAll(connectMsg);

            Log.Info("User<Name:{0}> has joined", client.Info.Name);
            return _messages;
            
        }