public IAsyncResult BeginConnect(bool connectAudio, bool connectText, bool switchTransmission, string accessToken, AsyncCallback callback) { AssertSessionNotDeleted(); if (string.IsNullOrEmpty(accessToken)) { throw new ArgumentNullException(nameof(accessToken)); } if (!connectAudio && !connectText) { throw new ArgumentException($"{GetType().Name}: connectAudio and connectText cannot both be false", nameof(connectAudio)); } if (AudioState != ConnectionState.Disconnected || TextState != ConnectionState.Disconnected) { throw new InvalidOperationException($"{GetType().Name}: Both AudioState and Text State must be disconnected"); } AsyncNoResult ar = new AsyncNoResult(callback); var request = new vx_req_sessiongroup_add_session_t { account_handle = _loginSession.AccountHandle, uri = Key.ToString(), session_handle = _sessionHandle, sessiongroup_handle = GroupId, connect_audio = connectAudio ? 1 : 0, connect_text = connectText ? 1 : 0, access_token = accessToken }; VxClient.Instance.BeginIssueRequest(request, result => { try { VxClient.Instance.EndIssueRequest(result); ar.SetComplete(); } catch (Exception e) { VivoxDebug.Instance.VxExceptionMessage($"{request.GetType().Name} failed: {e}"); AudioState = ConnectionState.Disconnected; TextState = ConnectionState.Disconnected; ar.SetComplete(e); if (VivoxDebug.Instance.throwInternalExcepetions) { throw; } return; } }); if (connectAudio) { AudioState = ConnectionState.Connecting; } if (connectText) { TextState = ConnectionState.Connecting; } ChannelState = ConnectionState.Connecting; if (switchTransmission) { if (!connectAudio) { VivoxDebug.Instance.DebugMessage("Switching audio transmission exclusively to text-only channel -- this is allowed but unusual."); } _loginSession.SetTransmissionMode(TransmissionMode.Single, Key); } else { _loginSession.SetTransmission(); } return(ar); }
public IAsyncResult BeginConnect(bool connectAudio, bool connectText, TransmitPolicy transmit, string accessToken, AsyncCallback callback) { AssertSessionNotDeleted(); if (string.IsNullOrEmpty(accessToken)) { throw new ArgumentNullException(nameof(accessToken)); } if (!connectAudio && !connectText) { throw new ArgumentException($"{GetType().Name}: connectAudio and connectText cannot both be false", nameof(connectAudio)); } if (AudioState != ConnectionState.Disconnected || TextState != ConnectionState.Disconnected) { throw new InvalidOperationException($"{GetType().Name}: Both AudioState and Text State must be disconnected"); } AsyncNoResult ar = new AsyncNoResult(callback); var request = new vx_req_sessiongroup_add_session_t { account_handle = _loginSession.AccountHandle, uri = Key.ToString(), session_handle = _sessionHandle, sessiongroup_handle = GroupId, connect_audio = connectAudio ? 1 : 0, connect_text = connectText ? 1 : 0, access_token = accessToken }; VxClient.Instance.BeginIssueRequest(request, result => { try { VxClient.Instance.EndIssueRequest(result); ar.SetComplete(); } catch (Exception e) { VivoxDebug.Instance.VxExceptionMessage($"{request.GetType().Name} failed: {e}"); AudioState = ConnectionState.Disconnected; TextState = ConnectionState.Disconnected; ar.SetComplete(e); if (VivoxDebug.Instance.throwInternalExcepetions) { throw; } return; } }); Debug.WriteLine(transmit); if (connectAudio) { switch (transmit) { case TransmitPolicy.No: { if (_loginSession.TransmittingSession == null) { SetNoSessionTransmitting(); } } break; case TransmitPolicy.Yes: { SetTransmitting(); } break; default: break; } AudioState = ConnectionState.Connecting; } if (connectText) { TextState = ConnectionState.Connecting; } return(ar); }