/// <summary> /// Receives UTC seconds from url. Runs asynchronously in coroutine. /// </summary> /// Automatically switches to the current domain when running in WebGL to avoid CORS limitation. /// <param name="uri">Absolute url to receive time from. /// Make sure this server has proper Date values in the response headers /// (almost all popular web sites are suitable).</param> /// <param name="callback">Delegate to call and pass OnlineTimeResult to.</param> /// <param name="method">Method to use for url request. Use Head method if possible and fall back to get if server does not reply or block head requests.</param> public static IEnumerator GetOnlineTimeCoroutine(Uri uri, OnlineTimeCallback callback, RequestMethod method = RequestMethod.Head) { #if ACTK_WEBGL_BUILD EnsureCurrentDomainUsed(ref uri); #endif if (gettingOnlineTime) { yield return(CachedEndOfFrame); } gettingOnlineTime = true; var result = new OnlineTimeResult(); using (var wr = GetWebRequest(uri, method)) { yield return(wr.SendWebRequest()); FillRequestResult(wr, ref result); } if (callback != null) { callback.Invoke(result); } gettingOnlineTime = false; }
/// <summary> /// Receives UTC seconds from url. Runs asynchronously in coroutine. /// </summary> /// Automatically switches to the current domain when running in WebGL to avoid CORS limitation. /// <param name="url">Absolute url to receive time from. /// Make sure this server has proper Date values in the response headers /// (almost all popular web sites are suitable).</param> /// <param name="callback">Delegate to call and pass OnlineTimeResult to.</param> /// <param name="method">Method to use for url request. Use Head method if possible and fall back to get if server does not reply or block head requests.</param> public static IEnumerator GetOnlineTimeCoroutine(string url, OnlineTimeCallback callback, RequestMethod method = RequestMethod.Head) { var uri = UrlToUri(url); yield return(GetOnlineTimeCoroutine(uri, callback, method)); }