public void LeaveChannel()
        {
            if (channelId == null)
            {
                return;
            }

            loginSession?.GetChannelSession(channelId).Disconnect();
            channelId = null;
        }
        public Task JoinChannelAsync(VoiceChannelCredentials credentials)
        {
            if (loginSession == null)
            {
                throw new InvalidOperationException("[Vivox] Trying to join a chnanel without being logged in");
            }

            var tcs = new TaskCompletionSource <byte>();

            var tmpChannelId = new ChannelId(credentials.ChannelId);

            var channelSession = loginSession.GetChannelSession(tmpChannelId);

            // Connect to channel
            channelSession.BeginConnect(allowAudio, allowText, switchTransmission, credentials.AccessToken, ar =>
            {
                try
                {
                    channelSession.EndConnect(ar);
                    channelId = tmpChannelId;
                    channelSession.Participants.AfterKeyAdded += OnParticipantJoined;
                    tcs.SetResult(0);

                    //Debug.Log($"[Vivox] Join channel [{channelId}] sucessful");
                    // Subscribe to property changes for all channels.
                    //channelSession.PropertyChanged += SourceOnChannelPropertyChanged;
                }
                catch (Exception e)
                {
                    tcs.SetException(e);
                    Debug.LogError($"[Vivox] Join Channel [{channelId}] error: {e}");
                }
                // Reaching this point indicates no error occurred, but the user is still not �in the channel� until the AudioState and/or TextState are in ConnectionState.Connected.
            });

            return(tcs.Task);
        }
Exemple #3
0
    public void JoinChannel(string channelName, bool IsAudio, bool IsText, bool switchTransmission, ChannelType channelType)
    {
        ChannelId channelId = new ChannelId(issuer, channelName, domain, channelType);

        channelSession = loginSession.GetChannelSession(channelId);
        Bind_Channel_Callback_Listeners(true, channelSession);

        channelSession.BeginConnect(IsAudio, IsText, switchTransmission, channelSession.GetConnectToken(tokenKey, timeSpan), ar =>
        {
            try
            {
                channelSession.EndConnect(ar);
            }
            catch (Exception e)
            {
                Bind_Channel_Callback_Listeners(false, channelSession);
                Debug.Log(e.Message);
            }
        });
    }
Exemple #4
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>());
        }