From 2e52784c491d1d74ed2dee605726780cd710a9e1 Mon Sep 17 00:00:00 2001 From: handongxun Date: Fri, 17 Jul 2020 11:19:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=BF=80=E5=8A=B1=E8=A7=86=E9=A2=91gdt?= =?UTF-8?q?=E8=B6=85=E6=97=B6=E8=B0=83=E7=94=A8=E6=98=BE=E7=A4=BA=E9=80=8F?= =?UTF-8?q?=E4=BC=A0=E5=8E=9F=E7=94=9F=E9=94=99=E8=AF=AF=EF=BC=9Bcsj?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E6=95=B0=E6=8D=AE=E8=B6=85=E8=BF=8730?= =?UTF-8?q?=E5=88=86=E9=92=9F=E5=90=8E=E8=B0=83=E7=94=A8=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E6=97=B6=E5=9B=9E=E8=B0=83=E9=94=99=E8=AF=AF=EF=BC=9A=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E9=87=8D=E6=96=B0=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/api/ad/rewarded-video-ad.js | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/platforms/app-plus/service/api/ad/rewarded-video-ad.js b/src/platforms/app-plus/service/api/ad/rewarded-video-ad.js index 5d44ee5d..acf41922 100644 --- a/src/platforms/app-plus/service/api/ad/rewarded-video-ad.js +++ b/src/platforms/app-plus/service/api/ad/rewarded-video-ad.js @@ -1,4 +1,3 @@ - const eventNames = [ 'load', 'close', @@ -7,6 +6,9 @@ const eventNames = [ ] const ERROR_CODE_LIST = [-5001, -5002, -5003, -5004, -5005, -5006] +const EXPIRED_TIME = 1000 * 60 * 30 +const EXPIRED_TEXT = { code: -5008, errMsg: '广告数据已过期,请重新加载' } +const ProviderType = { CSJ: 'csj', GDT: 'gdt' } class RewardedVideoAd { constructor (options = {}) { @@ -23,10 +25,14 @@ class RewardedVideoAd { this._adError = '' this._loadPromiseResolve = null this._loadPromiseReject = null + this._lastLoadTime = 0 + const rewardAd = this._rewardAd = plus.ad.createRewardedVideoAd(options) rewardAd.onLoad((e) => { this._isLoad = true this._dispatchEvent('load', {}) + this._lastLoadTime = Date.now() + if (this._loadPromiseResolve != null) { this._loadPromiseResolve() this._loadPromiseResolve = null @@ -43,7 +49,11 @@ class RewardedVideoAd { const { code, message } = e const data = { code: code, errMsg: message } this._adError = message + if (code === -5008) { + this._isLoad = false + } this._dispatchEvent('error', data) + // TODO if ((code === -5005 || ERROR_CODE_LIST.index(code) === -1) && this._loadPromiseReject != null) { this._loadPromiseReject(data) this._loadPromiseReject = null @@ -52,6 +62,10 @@ class RewardedVideoAd { this._loadAd() } + get isExpired () { + return (Math.abs(Date.now() - this._lastLoadTime) > EXPIRED_TIME) + } + load () { return new Promise((resolve, reject) => { if (this._isLoad) { @@ -66,6 +80,15 @@ class RewardedVideoAd { show () { return new Promise((resolve, reject) => { + const provider = this.getProvider() + if (provider === ProviderType.CSJ && this.isExpired) { + this._isLoad = false + // TODO + this._dispatchEvent('error', EXPIRED_TEXT) + reject(new Error(EXPIRED_TEXT.errMsg)) + return + } + if (this._isLoad) { this._rewardAd.show() resolve() -- GitLab