private ILoginSession ConvertTo(ILoginSession loginSession) { var result = new Transfer.Persistence.Account.LoginSession(); result.CopyProperties(loginSession); return(result); }
public Task LoginAsync(VoiceLoginCredentials credentials) { if (client == null) { client = new Client(); var config = new VivoxConfig { InitialLogLevel = vx_log_level.log_error }; client.Initialize(config); } var tcs = new TaskCompletionSource <byte>(); var accountId = new AccountId(credentials.AccountId); loginSession = client.GetLoginSession(accountId); loginSession.BeginLogin(credentials.ServerAddress, credentials.AccessToken, ar => { try { loginSession.EndLogin(ar); tcs.SetResult(0); //Debug.Log("[Vivox] Login sucessful"); } catch (Exception e) { tcs.SetException(e); Debug.LogError("[Vivox] Login error " + e.Message); } }); return(tcs.Task); }
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 string RetrieveToken(string userID) { Ensure.StringArgumentNotNullAndNotEmpty(userID, nameof(userID)); ILoginSession loginSession = cache.GetAndRefreshTimeout(userID) as ILoginSession; return(loginSession?.AuthenticationIdentifier); }
internal User(ILoginSession loginSession, IUserAccount userAccount, CoroutineRunner coroutineRunner, bool needsUserId) { this.loginSession = loginSession; this.userAccount = userAccount; this.coroutineRunner = coroutineRunner; this.needsUserId = needsUserId; }
public void Bind_Login_Callback_Listeners(bool bind, ILoginSession loginSesh) { if (bind) { loginSesh.PropertyChanged += Login_Status; } else { loginSesh.PropertyChanged -= Login_Status; } }
partial void AfterCopyProperties(ILoginSession other) { if (other is LoginSession loginSession) { PasswordHash = loginSession.PasswordHash; PasswordSalt = loginSession.PasswordSalt; Roles.Clear(); Roles.AddRange(loginSession.Roles); } }
private void BindLoginCallbackListeners(bool bind, ILoginSession loginSess) { if (bind) { loginSess.PropertyChanged += LoginStatus; } else { loginSess.PropertyChanged -= LoginStatus; } }
public static Task LogoutAsync(ILoginSession login) { login.CheckArgument(nameof(login)); var trAccMngr = new AccountManger { BaseUri = BaseUri, Adapter = Adapters.AdapterType.Service, }; return(trAccMngr.LogoutAsync(login.SessionToken)); }
public static void Logout(ILoginSession login) { login.CheckArgument(nameof(login)); var trAccMngr = new AccountManger { BaseUri = BaseUri, Adapter = Adapters.AdapterType.Service, }; AsyncHelper.RunSync(() => trAccMngr.LogoutAsync(login.SessionToken)); }
public NewGame(ISettingsLoader sl, IPlayersLoader players, IProvincesLoader provinces, IActionLoader actions, IActivePlayer active, IPowersLoader powers, ILoginSession login, IGameLoader game, IFormerPlayersLoader former) { this.sl = sl; this.players = players; this.provinces = provinces; this.actions = actions; this.active = active; this.powers = powers; this.login = login; this.game = game; this.former = former; }
protected override void OnEventFired(object source, EventArgs args) { UnityAsyncHelper.UnityMainThreadContext.PostAsync(async() => { try { //TODO: Expose these vivox stuff as shared constants between client and server. ILoginSession session = VoiceClient.GetLoginSession(new AccountId("vrguardian-vrg-dev", PlayerDetails.LocalPlayerGuid.EntityId.ToString(), "vdx5.vivox.com")); ResponseModel <string, VivoxLoginResponseCode> loginResult = await VivoxAutheAuthorizationService.LoginAsync(); //TODO: Better error and retry handling. if (!loginResult.isSuccessful) { if (Logger.IsErrorEnabled) { Logger.Error($"Failed to authenticate Vivox. Reason: {loginResult.ResultCode}"); return; } } await session.LoginAsync(new Uri("https://vdx5.www.vivox.com/api2"), loginResult.Result) .ConfigureAwait(true); //TODO: Does this above task complete immediately or does it wait until the state is known?? if (session.State == LoginState.LoggedIn) { OnVoiceSessionAuthenticated?.Invoke(this, new VoiceSessionAuthenticatedEventArgs(session)); } else { throw new InvalidOperationException($"Failed to authentication with Vivox."); } } catch (Exception e) { if (Logger.IsErrorEnabled) { Logger.Error($"Failed to Initialize Vivox Voice. Reason: {e.Message}\n\nStack: {e.StackTrace}"); } throw; } }); }
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 }); }
/// <summary> /// Injects a new Text-To-Speech message as the supplied user. /// </summary> /// <param name="userSpeaking">The local user which will speak the message.</param> /// <remarks>This method is a shortcut for `userSpeaking.TTS.Speak(this)`.</remarks> public void Speak(ILoginSession userSpeaking) { userSpeaking.TTS.Speak(this); }
public Menu(IUIWriter writer, ILoginSession session) { this.writer = writer; this.session = session; }
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>()); }