Example #1
0
        public void Authenticate()
        {
            if (!AuthSettings)
            {
                Debug.LogError("Vivox Auth Settings is null, set the property before authenticate.");
                return;
            }

            string uniqueId    = string.IsNullOrEmpty(Id) ? Guid.NewGuid().ToString() : Id;
            string displayName = string.IsNullOrEmpty(DisplayName) ? "Bot 2031" : DisplayName;

            //for proto purposes only, need to get a real token from server eventually
            _accountId   = new AccountId(AuthSettings.TokenIssuer, uniqueId, AuthSettings.Domain, displayName);
            LoginSession = Client.GetLoginSession(_accountId);
            LoginSession.PropertyChanged += OnLoginSessionPropertyChanged;
            LoginSession.BeginLogin(AuthSettings.ServerUri, LoginSession.GetLoginToken(AuthSettings.TokenKey, AuthSettings.TokenExpiration),
                                    SubscriptionMode.Accept, null, null, null, ar =>
            {
                try
                {
                    LoginSession.EndLogin(ar);
                }
                catch (Exception e)
                {
                    // Handle error
                    VivoxLogError(nameof(e));
                    // Unbind if we failed to login.
                    LoginSession.PropertyChanged -= OnLoginSessionPropertyChanged;
                    return;
                }
            });
        }
    public void Login(string userName)
    {
        AccountId accountId = new AccountId(issuer, userName, domain);

        loginSession = client.GetLoginSession(accountId);

        Bind_Login_Callback_Listeners(true, loginSession);
        loginSession.BeginLogin(server, loginSession.GetLoginToken(tokenKey, timeSpan), ar =>
        {
            try
            {
                loginSession.EndLogin(ar);
            }
            catch (Exception e)
            {
                Bind_Login_Callback_Listeners(false, loginSession);
                Debug.Log(e.Message);
            }
            // run more code here
        });
    }
Example #3
0
        public IEnumerator SentReceivedMessageComparison()
        {
            CheckCredentials();

            // Initialize the client.
            Client _client = new Client();

            _client.Initialize();

            float        timeout;
            IAsyncResult waitHandle;

            // Login.
            bool          isLoggedIn   = false;
            string        uniqueId     = Guid.NewGuid().ToString();
            AccountId     _accountId   = new AccountId(_tokenIssuer, uniqueId, _domain, TEST_ACCOUNT_NAME);
            ILoginSession LoginSession = _client.GetLoginSession(_accountId);

            waitHandle = LoginSession.BeginLogin(_server, LoginSession.GetLoginToken(_tokenKey, _tokenExpiration), SubscriptionMode.Accept, null, null, null, ar =>
            {
                try
                {
                    isLoggedIn = true;
                    LoginSession.EndLogin(ar);
                }
                catch (Exception e)
                {
                    Assert.Fail($"BeginLogin failed: {e}");
                    return;
                }
            });
            timeout = Time.time + TIMEOUT_INTERVAL;
            yield return(new WaitUntil(() => waitHandle.IsCompleted && LoginSession.State == LoginState.LoggedIn || Time.time > timeout));

            Assert.IsTrue(isLoggedIn, "Failed to login.");

            // Join a channel with audio and text enabled.
            ChannelId       channelId      = new ChannelId(_tokenIssuer, TEST_CHANNEL_NAME, _domain);
            IChannelSession channelSession = LoginSession.GetChannelSession(channelId);

            channelSession.MessageLog.AfterItemAdded += OnMessageLogRecieved;
            bool isInChannel = false;

            waitHandle = channelSession.BeginConnect(true, true, true, channelSession.GetConnectToken(_tokenKey, _tokenExpiration), ar =>
            {
                try
                {
                    isInChannel = true;
                    channelSession.EndConnect(ar);
                }
                catch (Exception e)
                {
                    Assert.Fail($"BeginConnect failed: {e}");
                    return;
                }
            });
            timeout = Time.time + TIMEOUT_INTERVAL;
            yield return(new WaitUntil(() => waitHandle.IsCompleted && channelSession.TextState == ConnectionState.Connected && channelSession.AudioState == ConnectionState.Connected || Time.time > timeout));

            Assert.IsTrue(isInChannel, "Failed to join the specified channel.");

            // Send a message to the channel.
            string textMessage = "hello 😉";

            waitHandle = channelSession.BeginSendText(textMessage, ar =>
            {
                try
                {
                    channelSession.EndSendText(ar);
                }
                catch (Exception e)
                {
                    Assert.Fail($"BeginSendText failed: {e}");
                }
            });
            timeout = Time.time + TIMEOUT_INTERVAL;
            yield return(new WaitUntil(() => waitHandle.IsCompleted || Time.time > timeout));

            // Make sure the sent and received messages are the same.
            var originalMsg = Encoding.UTF8.GetBytes(textMessage);
            var receivedMsg = Encoding.UTF8.GetBytes(testMessage);

            // Ensure that the same amount of bytes exist for the sent and received messages.
            Assert.IsTrue(originalMsg.Length == receivedMsg.Length, "Sent and received messages should have the same length but they do not.");
            // Make sure each byte matches between the sent and received messages.
            for (int i = 0; i < originalMsg.Length; i++)
            {
                Assert.IsTrue(originalMsg[i] == receivedMsg[i], "Comparison of sent and received message failed. They should be the same but are not.");
            }

            _client.Uninitialize();

            GameObject.Destroy(GameObject.FindObjectOfType <VxUnityInterop>());
        }