UniWebView message throttling / collision?

I have the following listener setup in my only scene:

ui.OnMessageReceived += (view, message) => { var path = message.Path; var action = message.Args ["action"]; if (path == "app") { if (action == "log") { Debug.Log ("[W] " + message.Args ["text"]); } } }; 

And in my web view, I have this log function:

 log: function(m) { window.location.href = 'uniwebview://app?action=log&text=' + m; } 

When I execute the following code, the only result that appears in logcat are tests 5 and E:

 app.log("Echo Test (1)"); app.log("Echo Test (2)"); app.log("Echo Test (3)"); app.log("Echo Test (4)"); app.log("Echo Test (5)"); setTimeout(function() { app.log("Echo Test (A)"); app.log("Echo Test (B)"); app.log("Echo Test (C)"); app.log("Echo Test (D)"); app.log("Echo Test (E)"); }, 500); 
 08-16 13:55:20.229 13860 13881 I Unity : [W] Echo Test (5) 08-16 13:55:20.693 13860 13881 I Unity : [W] Echo Test (E) 

What causes this and how can it be fixed?

+5
source share
1 answer

It looks like the url is not getting time to send a message to the listener. You instantly change the address so that it does not execute. You have added a timeout, which is a reasonable task, I suggest you create a function that waits after each log.

Here is another message that has a similar problem requiring a timeout.

 log: function(m) { setTimeout(function(){ window.location.href = 'uniwebview://app?action=log&text=' + m; },500 } 

I did not test this, but if you did not want to use a timer with 500 milliseconds, you could probably check if the download has finished loading before executing the next request.

 var readyStateCheckInterval = setInterval(function() { if (document.readyState === "complete") { clearInterval(readyStateCheckInterval); init(); } }, 10); 
0
source

Source: https://habr.com/ru/post/1270937/


All Articles