internal static void SendHeartBeatRequest() { var payload = _jsonWrapper.SerializeObject(CurrentState); if (string.IsNullOrEmpty(payload)) { return; } var payloadBytes = Encoding.ASCII.GetBytes(payload); PlayFabHttp.SimplePostCall(baseURL, payloadBytes, (success) => { var json = System.Text.Encoding.UTF8.GetString(success); Debug.Log(json); if (string.IsNullOrEmpty(json)) { return; } var hb = _jsonWrapper.DeserializeObject <SessionHostHeartbeatInfo>(json); if (hb != null) { ProcessAgentResponse(hb); } CurrentErrorState = ErrorStates.Ok; IsProcessing = false; }, (error) => { var guid = Guid.NewGuid(); Debug.LogFormat("CurrentError: {0} - {1}", error, guid.ToString()); //Exponential backoff for 30 minutes for retries. switch (CurrentErrorState) { case ErrorStates.Ok: CurrentErrorState = ErrorStates.Retry30s; if (IsDebugging) { Debug.Log("Retrying heartbeat in 30s"); } break; case ErrorStates.Retry30s: CurrentErrorState = ErrorStates.Retry5m; if (IsDebugging) { Debug.Log("Retrying heartbeat in 5m"); } break; case ErrorStates.Retry5m: CurrentErrorState = ErrorStates.Retry10m; if (IsDebugging) { Debug.Log("Retrying heartbeat in 10m"); } break; case ErrorStates.Retry10m: CurrentErrorState = ErrorStates.Retry15m; if (IsDebugging) { Debug.Log("Retrying heartbeat in 15m"); } break; case ErrorStates.Retry15m: CurrentErrorState = ErrorStates.Cancelled; if (IsDebugging) { Debug.Log("Agent reconnection cannot be established - cancelling"); } break; } if (OnAgentError != null) { OnAgentError.Invoke(error); } IsProcessing = false; }); }
internal static void SendHeartBeatRequest() { string payload = _jsonWrapper.SerializeObject(CurrentState); if (string.IsNullOrEmpty(payload)) { return; } byte[] payloadBytes = Encoding.ASCII.GetBytes(payload); if (IsDebugging) { Debug.Log(payload); } PlayFabHttp.SimplePostCall(_baseUrl, payloadBytes, success => { string json = Encoding.UTF8.GetString(success); Debug.Log(json); if (string.IsNullOrEmpty(json)) { return; } HeartbeatResponse hb = _jsonWrapper.DeserializeObject <HeartbeatResponse>(json); if (hb != null) { ProcessAgentResponse(hb); } CurrentErrorState = ErrorStates.Ok; IsProcessing = false; }, error => { Guid guid = Guid.NewGuid(); Debug.LogFormat("CurrentError: {0} - {1}", error, guid.ToString()); //Exponential backoff for 30 minutes for retries. switch (CurrentErrorState) { case ErrorStates.Ok: CurrentErrorState = ErrorStates.Retry30S; if (IsDebugging) { Debug.Log("Retrying heartbeat in 30s"); } break; case ErrorStates.Retry30S: CurrentErrorState = ErrorStates.Retry5M; if (IsDebugging) { Debug.Log("Retrying heartbeat in 5m"); } break; case ErrorStates.Retry5M: CurrentErrorState = ErrorStates.Retry10M; if (IsDebugging) { Debug.Log("Retrying heartbeat in 10m"); } break; case ErrorStates.Retry10M: CurrentErrorState = ErrorStates.Retry15M; if (IsDebugging) { Debug.Log("Retrying heartbeat in 15m"); } break; case ErrorStates.Retry15M: CurrentErrorState = ErrorStates.Cancelled; if (IsDebugging) { Debug.Log("Agent reconnection cannot be established - cancelling"); } break; } if (OnAgentErrorCallback != null) { OnAgentErrorCallback.Invoke(error); } IsProcessing = false; }); }