diff --git a/packages/xgplayer-ads/package.json b/packages/xgplayer-ads/package.json index ce2b7d872..915cad805 100644 --- a/packages/xgplayer-ads/package.json +++ b/packages/xgplayer-ads/package.json @@ -1,6 +1,6 @@ { "name": "xgplayer-ads", - "version": "3.0.21-rc.7", + "version": "3.0.20-alpha.9", "main": "dist/index.min.js", "module": "es/index.js", "typings": "es/index.d.ts", @@ -15,7 +15,7 @@ "publishConfig": { "registry": "https://registry.npmjs.org/", "access": "public", - "tag": "rc" + "tag": "alpha" }, "license": "MIT", "unpkgFiles": [ diff --git a/packages/xgplayer-ads/src/imaAdManager.js b/packages/xgplayer-ads/src/imaAdManager.js index 28f2827a0..6ce93a744 100644 --- a/packages/xgplayer-ads/src/imaAdManager.js +++ b/packages/xgplayer-ads/src/imaAdManager.js @@ -45,6 +45,7 @@ export class ImaAdManager extends BaseAdManager { this.displayContainer = null this.adsLoader = null this.adsManager = null + this._resumeCallback = null } async init () { @@ -70,12 +71,16 @@ export class ImaAdManager extends BaseAdManager { destroy () { super.destroy() - this.reset() + this.displayContainer.destroy() this._removeMediaEvents() this._destroyLoader() } + set resumeCallback (resumeCallbackFunc) { + this._resumeCallback = resumeCallbackFunc + } + /** * @private */ @@ -468,6 +473,12 @@ export class ImaAdManager extends BaseAdManager { // Fires when media content should be resumed. // This usually happens when an ad finishes or collapses. case google.ima.AdEvent.Type.CONTENT_RESUME_REQUESTED: { + if (this._resumeCallback) { + const { canResume } = this._resumeCallback() + if (!canResume) { + break + } + } this._resumeContent() this.emit(ADEvents.IMA_CONTENT_RESUME_REQUESTED, { ad diff --git a/packages/xgplayer-ads/src/plugin.js b/packages/xgplayer-ads/src/plugin.js index 062a5a46c..c1e16af23 100644 --- a/packages/xgplayer-ads/src/plugin.js +++ b/packages/xgplayer-ads/src/plugin.js @@ -93,7 +93,7 @@ export class AdsPlugin extends Plugin { /** * @private */ - _initImaAd () { + async _initImaAd () { this.csManager = new ImaAdManager({ plugin: this, config: this.config.ima, @@ -121,7 +121,8 @@ export class AdsPlugin extends Plugin { this.uiManager.hideAdUI() }) - this.csManager.init() + await this.csManager.init() + return this.csManager } requestAds () {