Exemple #1
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>());
        }