Ejemplo n.º 1
0
        private void OnRegisterError()
        {
            Log.Error("TopicClient", "Failed to register embodiment.");
            m_Login = null;

            DoConnect();
        }
Ejemplo n.º 2
0
        public bool Connect(string a_Host   = null,
                            string a_selfId = null,
                            string a_Token  = null)
        {
            if (m_eState != ClientState.Inactive &&
                m_eState != ClientState.Disconnected)
            {
                Log.Error("TopicClient", "Client is wrong state for Connect().");
                return(false);
            }

            if (string.IsNullOrEmpty(a_Host))
            {
                a_Host = Config.Instance.GetVariableValue("Host");
            }
            if (string.IsNullOrEmpty(a_Host))
            {
                a_Host = "ws://127.0.0.1:9443";
            }
            if (string.IsNullOrEmpty(a_Token))
            {
                a_Token = Config.Instance.GetVariableValue("BearerToken");
            }
            if (string.IsNullOrEmpty(a_selfId))
            {
                a_selfId = Config.Instance.GetVariableValue("SelfID");
            }

            if (!a_Host.StartsWith("ws://", StringComparison.CurrentCultureIgnoreCase) &&
                a_Host.StartsWith("wss://", StringComparison.CurrentCultureIgnoreCase))
            {
                Log.Error("TopicClient", "Host doesn't begin with ws:// or wss://");
                return(false);
            }

            State            = ClientState.Connecting;
            m_Host           = a_Host;
            m_SelfId         = a_selfId;
            m_Token          = a_Token;
            m_bAuthenticated = false;

            if (string.IsNullOrEmpty(m_SelfId))
            {
                m_Login = new SelfLogin();
                m_Login.OnRegisteredEvent += OnRegisteredEmbodiment;
                m_Login.OnErrorEvent      += OnRegisterError;

                Log.Status("TopicClient", "Registering embodiment.");
                if (!m_Login.RegisterEmbodiment())
                {
                    OnRegisterError();
                }

                return(true);
            }

            DoConnect();

            return(true);
        }
Ejemplo n.º 3
0
        private void OnRegisteredEmbodiment(string a_SelfId, string a_Token)
        {
            m_SelfId = a_SelfId;
            m_Token  = a_Token;
            m_Login  = null;

            DoConnect();
        }