예제 #1
0
        /// <summary>
        /// Login to SkyResponse API
        /// </summary>
        /// <returns></returns>
        public async Task Login()
        {
            _accesstoken = await _userService.GetAccessToken();

            if (!string.IsNullOrEmpty(_accesstoken))
            {
                _userService.SaveUserInfo();

                try
                {
                    await _httpRequest.RegisterForPush(_accesstoken);
                }
                catch (HttpRequestException)
                {
                    ReConnect();
                    return;
                }

                try
                {
                    var webSocketUrl = string.Concat(WebSocketUrl, _accesstoken);
                    _webSocket.Connect(webSocketUrl);
                }
                catch (WebSocketException)
                {
                    ReConnect();
                    return;
                }

                _webSocket.OnMessage(OnMessageAsync);
                _webSocket.OnDisconnect(OnDisconnect);
            }
        }