private IEnumerator MaintainAccessToken() { TimeSpan refreshBackoff = TimeSpan.FromSeconds(10); var rand = new Random(); while (true) { if (refreshBackoff >= OauthLoginSession.MaxBackoffInterval) { yield break; } if (this.tokenData == null || DateTime.UtcNow < this.nextRefreshTime) { yield return(new WaitForSeconds(OauthLoginSession.WaitExpiryDelay / 1000f)); continue; } Result <TokenData> refreshResult = null; yield return(RefreshToken(result => refreshResult = result)); if (!refreshResult.IsError) { this.nextRefreshTime = OauthLoginSession.ScheduleNormalRefresh(this.tokenData.expires_in); } else { refreshBackoff = OauthLoginSession.CalculateBackoffInterval(refreshBackoff, rand.Next(1, 60)); this.nextRefreshTime = DateTime.UtcNow + refreshBackoff; } } }
static AccelBytePlugin() { #if UNITY_WEBGL && !UNITY_EDITOR Utf8Json.Resolvers.CompositeResolver.RegisterAndSetAsDefault( new [] { Utf8Json.Formatters.PrimitiveObjectFormatter.Default }, new[] { Utf8Json.Resolvers.GeneratedResolver.Instance, Utf8Json.Resolvers.BuiltinResolver.Instance, Utf8Json.Resolvers.EnumResolver.Default, // for unity Utf8Json.Unity.UnityResolver.Instance } ); #endif var configFile = Resources.Load("AccelByteSDKConfig"); if (configFile == null) { throw new Exception("'AccelByteSDKConfig.json' isn't found in the Project/Assets/Resources directory"); } string wholeJsonText = ((TextAsset)configFile).text; AccelBytePlugin.config = wholeJsonText.ToObject <Config>(); AccelBytePlugin.config.Expand(); AccelBytePlugin.coroutineRunner = new CoroutineRunner(); AccelBytePlugin.httpWorker = new UnityHttpWorker(); ILoginSession loginSession; if (AccelBytePlugin.config.UseSessionManagement) { loginSession = new ManagedLoginSession( AccelBytePlugin.config.LoginServerUrl, AccelBytePlugin.config.Namespace, AccelBytePlugin.config.ClientId, AccelBytePlugin.config.ClientSecret, AccelBytePlugin.config.RedirectUri, AccelBytePlugin.httpWorker); } else { loginSession = new OauthLoginSession( AccelBytePlugin.config.LoginServerUrl, AccelBytePlugin.config.Namespace, AccelBytePlugin.config.ClientId, AccelBytePlugin.config.ClientSecret, AccelBytePlugin.config.RedirectUri, AccelBytePlugin.httpWorker, AccelBytePlugin.coroutineRunner); } AccelBytePlugin.user = new User( loginSession, new UserAccount( AccelBytePlugin.config.IamServerUrl, AccelBytePlugin.config.Namespace, loginSession, AccelBytePlugin.httpWorker), AccelBytePlugin.coroutineRunner, AccelBytePlugin.config.UseSessionManagement); ServicePointManager.ServerCertificateValidationCallback = AccelBytePlugin.OnCertificateValidated; }