Commit 265725a04d238c83922ea8dc528a5b18603ef853
1 parent
b9032f41
Exists in
master
and in
6 other branches
Improves translator request
Showing
1 changed file
with
35 additions
and
33 deletions
Show diff stats
Assets/Scripts/PlayerManager.cs
@@ -22,9 +22,9 @@ public class PlayerManager : GenericPlayerManager { | @@ -22,9 +22,9 @@ public class PlayerManager : GenericPlayerManager { | ||
22 | private const string BASE_URL = "http://dicionario.vlibras.gov.br/ANDROID/"; | 22 | private const string BASE_URL = "http://dicionario.vlibras.gov.br/ANDROID/"; |
23 | #endif | 23 | #endif |
24 | 24 | ||
25 | - //private const string SERVER_URL = "http://vlibras.lavid.ufpb.br/glosa?texto=";//old | ||
26 | - private const string SERVER_URL = "http://traducao.vlibras.gov.br/translate?text="; | ||
27 | - private const int version = 1; | 25 | + //private const string SERVER_URL = "http://vlibras.lavid.ufpb.br/glosa?texto=";//old |
26 | + private const string SERVER_URL = "http://traducao.vlibras.gov.br/translate?text="; | ||
27 | + private const int version = 1; | ||
28 | 28 | ||
29 | public enum ERROR_STATUS_MESSAGE | 29 | public enum ERROR_STATUS_MESSAGE |
30 | { | 30 | { |
@@ -71,7 +71,7 @@ public class PlayerManager : GenericPlayerManager { | @@ -71,7 +71,7 @@ public class PlayerManager : GenericPlayerManager { | ||
71 | base.Start(); | 71 | base.Start(); |
72 | 72 | ||
73 | // DEBUG: var onLoadPlayer = function(){} | 73 | // DEBUG: var onLoadPlayer = function(){} |
74 | - Application.ExternalCall("onLoadPlayer"); | 74 | + // Application.ExternalCall("onLoadPlayer"); |
75 | voiceRecognizer = new VoiceRecognition(); | 75 | voiceRecognizer = new VoiceRecognition(); |
76 | 76 | ||
77 | Screen.fullScreen = false; | 77 | Screen.fullScreen = false; |
@@ -158,12 +158,10 @@ public class PlayerManager : GenericPlayerManager { | @@ -158,12 +158,10 @@ public class PlayerManager : GenericPlayerManager { | ||
158 | { | 158 | { |
159 | lock (this.LOCKER_TRANSLATE) | 159 | lock (this.LOCKER_TRANSLATE) |
160 | { | 160 | { |
161 | - | ||
162 | - bool return_status_success = true; | 161 | + bool returnSuccess = true; |
163 | bool timeout = false; | 162 | bool timeout = false; |
164 | - float timeout_limit = 10f; | ||
165 | 163 | ||
166 | - Debug.Log("Requesting tranlator: " + gloss); | 164 | + Debug.Log("Requesting translator: " + gloss); |
167 | 165 | ||
168 | base.randomAnimations.lockFor("translate"); | 166 | base.randomAnimations.lockFor("translate"); |
169 | this.screenManager.setLoadingSnippetState(true); | 167 | this.screenManager.setLoadingSnippetState(true); |
@@ -172,55 +170,61 @@ public class PlayerManager : GenericPlayerManager { | @@ -172,55 +170,61 @@ public class PlayerManager : GenericPlayerManager { | ||
172 | 170 | ||
173 | if (glossRequest != null) | 171 | if (glossRequest != null) |
174 | { | 172 | { |
175 | - yield return glossRequest.isDone; | ||
176 | - | 173 | + const float timeoutLimit = 10f; |
177 | float timer = 0; | 174 | float timer = 0; |
178 | 175 | ||
179 | while (!glossRequest.isDone) | 176 | while (!glossRequest.isDone) |
180 | { | 177 | { |
181 | - if (timer > timeout_limit) | 178 | + if (timer > timeoutLimit) |
182 | { | 179 | { |
183 | - Debug.Log("Timeout"); | ||
184 | timeout = true; | 180 | timeout = true; |
185 | break; | 181 | break; |
186 | } | 182 | } |
183 | + | ||
187 | timer += Time.deltaTime; | 184 | timer += Time.deltaTime; |
188 | yield return null; | 185 | yield return null; |
189 | } | 186 | } |
190 | 187 | ||
191 | - if (glossRequest.error == null || timeout) | ||
192 | - { | ||
193 | - yield return glossRequest; | ||
194 | - | ||
195 | - return_status_success = glossRequest.responseHeaders.Count > 0 && glossRequest.responseHeaders["STATUS"].Equals("HTTP/1.0 200 OK"); | ||
196 | - | ||
197 | - if (return_status_success && !String.IsNullOrEmpty(glossRequest.text)) | 188 | + if (!timeout) |
189 | + { | ||
190 | + if (glossRequest.error == null) | ||
198 | { | 191 | { |
199 | - Debug.Log("Translator answer: " + glossRequest.text); | ||
200 | - | ||
201 | - base.gloss = glossRequest.text; | ||
202 | - base.playNow(glossRequest.text); | ||
203 | - this.screenManager.setLoadingSnippetState(false); | ||
204 | - base.randomAnimations.unlockFor("translate"); | ||
205 | - | ||
206 | - yield break; | 192 | + returnSuccess = glossRequest.responseHeaders.Count > 0 && glossRequest.responseHeaders["STATUS"].EndsWith("200 OK"); |
193 | + | ||
194 | + if (returnSuccess) | ||
195 | + { | ||
196 | + if (!String.IsNullOrEmpty(glossRequest.text)) | ||
197 | + { | ||
198 | + Debug.Log("Translator answer: " + glossRequest.text); | ||
199 | + | ||
200 | + base.gloss = glossRequest.text; | ||
201 | + base.playNow(glossRequest.text); | ||
202 | + this.screenManager.setLoadingSnippetState(false); | ||
203 | + base.randomAnimations.unlockFor("translate"); | ||
204 | + | ||
205 | + yield break; | ||
206 | + } | ||
207 | + else Debug.Log("Error at PlayerManager.translate: empty answer."); | ||
208 | + } | ||
209 | + else Debug.Log("Error at PlayerManager.translate: unsuccessful answer."); | ||
207 | } | 210 | } |
208 | - else Debug.Log("Error at PlayerManager.translate: empty answer."); | 211 | + else Debug.Log("Error at PlayerManager.translate: (WWW) glosaRequest: " + glossRequest.error); |
209 | } | 212 | } |
210 | - else Debug.Log("Error at PlayerManager.translate: (WWW) glosaRequest: " + glossRequest.error); | 213 | + else Debug.Log("Error at PlayerManager.translate: timeout."); |
211 | } | 214 | } |
212 | else Debug.Log ("Error at PlayerManager.translate: (WWW) glosaRequest is NULL."); | 215 | else Debug.Log ("Error at PlayerManager.translate: (WWW) glosaRequest is NULL."); |
213 | 216 | ||
214 | base.gloss = gloss.ToUpper(); | 217 | base.gloss = gloss.ToUpper(); |
215 | 218 | ||
216 | this.screenManager.setLoadingSnippetState(false); | 219 | this.screenManager.setLoadingSnippetState(false); |
220 | + base.randomAnimations.unlockFor("translate"); | ||
217 | 221 | ||
218 | - if (return_status_success) | 222 | + if (returnSuccess) |
219 | { | 223 | { |
220 | this.screenManager.showConnectionErrorDialog( | 224 | this.screenManager.showConnectionErrorDialog( |
221 | PlayerManager.ERROR_STATUS_MESSAGE.TRANSLATOR_CONNECTION_FAILURE); | 225 | PlayerManager.ERROR_STATUS_MESSAGE.TRANSLATOR_CONNECTION_FAILURE); |
222 | } | 226 | } |
223 | - else if(timeout) | 227 | + else if (timeout) |
224 | { | 228 | { |
225 | this.screenManager.showConnectionErrorDialog( | 229 | this.screenManager.showConnectionErrorDialog( |
226 | PlayerManager.ERROR_STATUS_MESSAGE.CONNECTION_TIMEOUT_FAILURE); | 230 | PlayerManager.ERROR_STATUS_MESSAGE.CONNECTION_TIMEOUT_FAILURE); |
@@ -230,8 +234,6 @@ public class PlayerManager : GenericPlayerManager { | @@ -230,8 +234,6 @@ public class PlayerManager : GenericPlayerManager { | ||
230 | this.screenManager.showConnectionErrorDialog( | 234 | this.screenManager.showConnectionErrorDialog( |
231 | PlayerManager.ERROR_STATUS_MESSAGE.INTERNET_CONNECTION_FAILURE); | 235 | PlayerManager.ERROR_STATUS_MESSAGE.INTERNET_CONNECTION_FAILURE); |
232 | } | 236 | } |
233 | - | ||
234 | - //base.randomAnimations.unlockFor("translate"); | ||
235 | } | 237 | } |
236 | } | 238 | } |
237 | 239 |