From fd409d62165b733758e96b146d918bcc54f98c63 Mon Sep 17 00:00:00 2001 From: gawhyte Date: Wed, 6 Jun 2018 11:12:44 -0400 Subject: [PATCH] fix: Wait until PlayerWrapper ready before invoking SdkImpl.initAdObjects (#638) --- src/controller.js | 8 ++++++++ src/player-wrapper.js | 2 ++ src/sdk-impl.js | 16 +++++++++------- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/controller.js b/src/controller.js index b200608c..383ac347 100644 --- a/src/controller.js +++ b/src/controller.js @@ -482,6 +482,14 @@ Controller.prototype.onPlayerReadyForPreroll = function() { }; +/** + * Called when the player is ready. + */ +Controller.prototype.onPlayerReady = function() { + this.sdkImpl.onPlayerReady(); +}; + + /** * Called when the player enters fullscreen. */ diff --git a/src/player-wrapper.js b/src/player-wrapper.js index e4d0e7a7..1bb73ff9 100644 --- a/src/player-wrapper.js +++ b/src/player-wrapper.js @@ -278,6 +278,8 @@ PlayerWrapper.prototype.onPlayerReady = function() { this.onVolumeChange(); this.vjsPlayer.on('fullscreenchange', this.onFullscreenChange.bind(this)); this.vjsPlayer.on('volumechange', this.onVolumeChange.bind(this)); + + this.controller.onPlayerReady(); }; diff --git a/src/sdk-impl.js b/src/sdk-impl.js index 933c6293..42687aaf 100644 --- a/src/sdk-impl.js +++ b/src/sdk-impl.js @@ -142,13 +142,6 @@ const SdkImpl = function(controller) { google.ima.settings.setDisableCustomPlaybackForIOS10Plus( this.controller.getSettings().disableCustomPlaybackForIOS10Plus); } - - this.initAdObjects(); - - if (this.controller.getSettings().adTagUrl || - this.controller.getSettings().adsResponse) { - this.requestAds(); - } }; @@ -533,6 +526,15 @@ SdkImpl.prototype.onPlayerReadyForPreroll = function() { } }; +SdkImpl.prototype.onPlayerReady = function() { + this.initAdObjects(); + + if (this.controller.getSettings().adTagUrl || + this.controller.getSettings().adsResponse) { + this.requestAds(); + } +}; + SdkImpl.prototype.onPlayerEnterFullscreen = function() { if (this.adsManager) {