Reputation: 2495
I have a WebView running a page containing a socket.io client that connects to a remote node.js server. The problem is that because websockets are not supported in the Android webview (they are in the Android Chrome browser), it falls back to xhr-polling.
I have an onProgressChanged
listener for the WebChromeClient
, but the xhr-polling keeps the page continuously loading. When I log the progress, it reaches ~90-95% and gets no further. This means that I cannot dismiss any loading indicators or perform any other actions that require the page to be fully loaded.
Is there anyway I can make Android think that the xhr-polling
is not part of the page loading? Or is there a workaround? I haven't tested it with jsonp-polling
yet. I would prefer a solution to this issue, rather than a hack/workaround, but ultimately I just want my app to work.
P.S, I am aware of native libraries for socket.io and WebSockets on android. However, this all needs to be done in a WebView.
Thanks
Upvotes: 1
Views: 1422
Reputation: 206
I found the problem!
On the socket.io-client apparently there's a special defer if it's XHR + webkit browser in here:
https://github.com/LearnBoost/socket.io-client/blob/0.9/lib/util.js#L203
As you can see, 100ms it's not enough for a mobile phone, I had to change it for at least 500ms! I think the authors didn't remember this use case! Patch the socket.io-client with this and profit :)
Upvotes: 1
Reputation: 2495
Until I can discover a better solution, I am using a workaround. I noticed that every time, the progress will reach at least 90%. So, instead of waiting for 100%, I wait for 90%. Even at 90%, I can see that pretty much all of my page has loaded, there are no visual changes made to the page after 90%.
Upvotes: 0