Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add resume content callback #1662

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/xgplayer-ads/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -15,7 +15,7 @@
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"access": "public",
"tag": "rc"
"tag": "alpha"
},
"license": "MIT",
"unpkgFiles": [
Expand Down
13 changes: 12 additions & 1 deletion packages/xgplayer-ads/src/imaAdManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class ImaAdManager extends BaseAdManager {
this.displayContainer = null
this.adsLoader = null
this.adsManager = null
this._resumeCallback = null
}

async init () {
Expand All @@ -70,12 +71,16 @@ export class ImaAdManager extends BaseAdManager {

destroy () {
super.destroy()

this.reset()
this.displayContainer.destroy()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.displayContainer 需要加一下防御,防止为空

this._removeMediaEvents()
this._destroyLoader()
}

set resumeCallback (resumeCallbackFunc) {
this._resumeCallback = resumeCallbackFunc
}

/**
* @private
*/
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions packages/xgplayer-ads/src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class AdsPlugin extends Plugin {
/**
* @private
*/
_initImaAd () {
async _initImaAd () {
this.csManager = new ImaAdManager({
plugin: this,
config: this.config.ima,
Expand Down Expand Up @@ -121,7 +121,8 @@ export class AdsPlugin extends Plugin {
this.uiManager.hideAdUI()
})

this.csManager.init()
await this.csManager.init()
return this.csManager
}

requestAds () {
Expand Down