diff --git a/Assets/Scripts/PlayerManager.cs b/Assets/Scripts/PlayerManager.cs index f680d82..6f71773 100644 --- a/Assets/Scripts/PlayerManager.cs +++ b/Assets/Scripts/PlayerManager.cs @@ -22,9 +22,9 @@ public class PlayerManager : GenericPlayerManager { private const string BASE_URL = "http://dicionario.vlibras.gov.br/ANDROID/"; #endif - //private const string SERVER_URL = "http://vlibras.lavid.ufpb.br/glosa?texto=";//old - private const string SERVER_URL = "http://traducao.vlibras.gov.br/translate?text="; - private const int version = 1; + //private const string SERVER_URL = "http://vlibras.lavid.ufpb.br/glosa?texto=";//old + private const string SERVER_URL = "http://traducao.vlibras.gov.br/translate?text="; + private const int version = 1; public enum ERROR_STATUS_MESSAGE { @@ -71,7 +71,7 @@ public class PlayerManager : GenericPlayerManager { base.Start(); // DEBUG: var onLoadPlayer = function(){} - Application.ExternalCall("onLoadPlayer"); + // Application.ExternalCall("onLoadPlayer"); voiceRecognizer = new VoiceRecognition(); Screen.fullScreen = false; @@ -158,12 +158,10 @@ public class PlayerManager : GenericPlayerManager { { lock (this.LOCKER_TRANSLATE) { - - bool return_status_success = true; + bool returnSuccess = true; bool timeout = false; - float timeout_limit = 10f; - Debug.Log("Requesting tranlator: " + gloss); + Debug.Log("Requesting translator: " + gloss); base.randomAnimations.lockFor("translate"); this.screenManager.setLoadingSnippetState(true); @@ -172,55 +170,61 @@ public class PlayerManager : GenericPlayerManager { if (glossRequest != null) { - yield return glossRequest.isDone; - + const float timeoutLimit = 10f; float timer = 0; while (!glossRequest.isDone) { - if (timer > timeout_limit) + if (timer > timeoutLimit) { - Debug.Log("Timeout"); timeout = true; break; } + timer += Time.deltaTime; yield return null; } - if (glossRequest.error == null || timeout) - { - yield return glossRequest; - - return_status_success = glossRequest.responseHeaders.Count > 0 && glossRequest.responseHeaders["STATUS"].Equals("HTTP/1.0 200 OK"); - - if (return_status_success && !String.IsNullOrEmpty(glossRequest.text)) + if (!timeout) + { + if (glossRequest.error == null) { - Debug.Log("Translator answer: " + glossRequest.text); - - base.gloss = glossRequest.text; - base.playNow(glossRequest.text); - this.screenManager.setLoadingSnippetState(false); - base.randomAnimations.unlockFor("translate"); - - yield break; + returnSuccess = glossRequest.responseHeaders.Count > 0 && glossRequest.responseHeaders["STATUS"].EndsWith("200 OK"); + + if (returnSuccess) + { + if (!String.IsNullOrEmpty(glossRequest.text)) + { + Debug.Log("Translator answer: " + glossRequest.text); + + base.gloss = glossRequest.text; + base.playNow(glossRequest.text); + this.screenManager.setLoadingSnippetState(false); + base.randomAnimations.unlockFor("translate"); + + yield break; + } + else Debug.Log("Error at PlayerManager.translate: empty answer."); + } + else Debug.Log("Error at PlayerManager.translate: unsuccessful answer."); } - else Debug.Log("Error at PlayerManager.translate: empty answer."); + else Debug.Log("Error at PlayerManager.translate: (WWW) glosaRequest: " + glossRequest.error); } - else Debug.Log("Error at PlayerManager.translate: (WWW) glosaRequest: " + glossRequest.error); + else Debug.Log("Error at PlayerManager.translate: timeout."); } else Debug.Log ("Error at PlayerManager.translate: (WWW) glosaRequest is NULL."); base.gloss = gloss.ToUpper(); this.screenManager.setLoadingSnippetState(false); + base.randomAnimations.unlockFor("translate"); - if (return_status_success) + if (returnSuccess) { this.screenManager.showConnectionErrorDialog( PlayerManager.ERROR_STATUS_MESSAGE.TRANSLATOR_CONNECTION_FAILURE); } - else if(timeout) + else if (timeout) { this.screenManager.showConnectionErrorDialog( PlayerManager.ERROR_STATUS_MESSAGE.CONNECTION_TIMEOUT_FAILURE); @@ -230,8 +234,6 @@ public class PlayerManager : GenericPlayerManager { this.screenManager.showConnectionErrorDialog( PlayerManager.ERROR_STATUS_MESSAGE.INTERNET_CONNECTION_FAILURE); } - - //base.randomAnimations.unlockFor("translate"); } } -- libgit2 0.21.2