ludei / webview-plus

Uniform webview on any Android 4.x device.
103 stars 16 forks source link

Very strange (incorrect) sequence of events for full screen (interstitial)/AD event listeners. #16

Open agamemnus opened 9 years ago

agamemnus commented 9 years ago

So far only tested in Webview+.

window.addEventListener ("touchstart", function () {console.log ('show'); CocoonJS.Ad.showFullScreen()})
CocoonJS.Ad.onFullScreenShown.addEventListener (function() {console.log ("onFullScreenShown")})
CocoonJS.Ad.onFullScreenHidden.addEventListener (function() {console.log ("onFullScreenHidden")})
CocoonJS.Ad.onFullScreenReady.addEventListener (function() {console.log ("onFullScreenReady")})
CocoonJS.Ad.preloadFullScreen()

1) CocoonJS.Ad.preloadFullScreen() seems to do what you'd expect. onFullScreenReady is fired when the fullscreen ad is preloaded. That's fine.

2) CocoonJS.Ad.showFullScreen(): shows the full screen ad. OK.

3) onFullScreenShown fires when the ad is shown, and onFullScreenHidden fires when it's hidden (when the ad is closed).

Bug/feature: 4) showFullScreen() actually works as preloadFullScreen() if the screen isn't preloaded yet.

Definitely bugs: 5) Preloading sometimes stalls/times out and does not activate anything. The showFullScreen/preloadFullScreen function sometimes needs to be run multiple times. I understand sometimes nothing is available (potentially?), but we have seemingly no event to tell us this.

6) For video interstitials, the ad event sequence is totally wrong: onFullScreenShown fires, then onFullScreenHidden, and then onFullScreenShown again, and then the ad displays. No event fires when the ad is closed.

7) CocoonJS.Ad.preloadFullScreen() only runs once. Subsequent invocation does nothing.

agamemnus commented 9 years ago

Here is the code I am using. This is obviously not optimal.

var run_fullscreen_ad = function (init) {
 var gs = init.gs
 if (typeof gs.fullscreen_ad == "undefined") {
  CocoonJS.Ad.preloadFullScreen () // Only works once..??
  gs.fullscreen_ad = {}
  // Create a full-screen ad callbacks.
  CocoonJS.Ad.onFullScreenReady.addEventListener (function() {
   if (load_success == true) return
   load_success = true
   clearTimeout (try_load_timeout)
   CocoonJS.Ad.showFullScreen ()
  })
  CocoonJS.Ad.onFullScreenHidden.addEventListener (function() {
   CocoonJS.Ad.showFullScreen ()
   document.body.style.pointerEvents = ""
   gs.fullscreen_ad.callback ()
  })
 } else {
  CocoonJS.Ad.showFullScreen ()
 }
 var load_success = false
 gs.fullscreen_ad.callback = init.callback

 var try_load_timeout = setTimeout (function () {
  if (load_success == true) return
  load_success = true
  document.body.style.pointerEvents = ""
  gs.fullscreen_ad.callback ()
 }, 3000)
}