private PlayerRequest GetActiveRequest()
        {
            if (_activeRequest == null)
            {
                _activeRequest = PlayerRequest.Create();
            }

            return(_activeRequest);
        }
Ejemplo n.º 2
0
        private void Send()
        {
#if NETFX_CORE
            try
            {
                if (!_websocketConnected)
                {
                    return;
                }

                var req = GetActiveRequest();

                var jsonStr = req.ToJsonObject().Stringify();
                LogReceived?.Invoke("Send() " + jsonStr);
                messageWriter.WriteString(jsonStr);
                messageWriter.StoreAsync();
                _activeRequest = null;
            }
            catch (Exception e)
            {
                LogReceived?.Invoke("Send() " + e.Message);
            }
#else
            try
            {
                if (!_websocketConnected)
                {
                    Console.Write("not connected.\n");
                    return;
                }

                var msg = JSON.ToJSON(GetActiveRequest(), DEFAULT_PARAM);
                Debug.WriteLine("Send() String " + msg);
                _webSocket.SendAsync(msg, b =>
                {
                    _activeRequest = null;
                });
            }
            catch (Exception e)
            {
                Console.Write($"{e.Message} {e}\n");
            }
#endif
        }
        private void Send()
        {
            try
            {
                if (!_websocketConnected)
                {
                    Console.Write("not connected.\n");
                    return;
                }

                var msg = GetActiveRequest().ToJsonObject().ToString();
                Debug.WriteLine("Send() String " + msg);
                _webSocket.SendAsync(msg, b =>
                {
                    _activeRequest = null;
                });
            }
            catch (Exception e)
            {
                Console.Write($"{e.Message} {e}\n");
            }
        }