telefonicaid/tdigital-hybridge — pull request #22 by jmendiara (2014-10-02 13:59:56+00:00)
Title: Race condition in Native initialization handshake

Native part set in their injected javascript the `switch` class to `#hybridgeTrigger` as part as its handshake mechanism. But this last was set dynamically in the DOM by the javascript part.
Therefore, if the #hybridgeTrigger did not exist when the native javascript was executed, the initialization failed silently cause the `|| {}` in
```js
(window.document.getElementById('hybridgeTrigger') || {}).className = 'switch';
```
adding the property `className` to an empty object, and therefore the javascript part never get informed of the classname change.

This was partially hacked by the iOS native javascript, which set a Timeout of 500ms before setting the class. But this didn't solve the problem at all, it only made difficult to happen. Furthermore, the inducted delay lead the iOS platform to be (seen experimentally in my app) delayed in startup for 380ms.

The implemented polling for the `window.HybridgeGlobal` existence solves the problem, not very nicely, but effectively. iOS/Android platform has now an experimentally seen delay of 20/30 ms until HybridgeGlobal is added, which is significantly better than the 380ms for iOS and the very common miss in Android

Other solutions must be investigated, such:
* Force the HTML to include a minimum javascript before DOMReady event is raised. Then native handshake must wait to a DOMReady on the webview for triggering the event.

@dcantelar please, add the .jar for the compiled java