Exemplo n.º 1
0
        public void Login(string username)
        {
            var response = _client.Login(new UserInfo()
            {
                Username = username
            });

            if (response.ErrorCode != 0)
            {
                throw new Exception(response.ErrorMessage);
            }

            _username = username;
            var userInfo = new UserInfo()
            {
                Username = _username
            };

            Task.Run(async() =>
            {
                using (var call = _client.ListenForMessageUpdates(userInfo))
                {
                    var responseStream = call.ResponseStream;
                    while (await responseStream.MoveNext())
                    {
                        var message = responseStream.Current;
                        _subjectChatMessage.OnNext(message);
                    }
                }
            });

            Task.Run(async() =>
            {
                using (var call = _client.ListenForUserUpdates(userInfo))
                {
                    var responseStream = call.ResponseStream;
                    while (await responseStream.MoveNext())
                    {
                        var userUpdate = responseStream.Current;
                        _subjectUserUpdate.OnNext(userUpdate);
                    }
                }
            });
        }