提交 2e52784c 编写于 作者: d-u-a's avatar d-u-a

fix: 激励视频gdt超时调用显示透传原生错误;csj加载数据超过30分钟后调用显示时回调错误:提示重新加载

上级 040b93e5
const eventNames = [ const eventNames = [
'load', 'load',
'close', 'close',
...@@ -7,6 +6,9 @@ const eventNames = [ ...@@ -7,6 +6,9 @@ const eventNames = [
] ]
const ERROR_CODE_LIST = [-5001, -5002, -5003, -5004, -5005, -5006] 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 { class RewardedVideoAd {
constructor (options = {}) { constructor (options = {}) {
...@@ -23,10 +25,14 @@ class RewardedVideoAd { ...@@ -23,10 +25,14 @@ class RewardedVideoAd {
this._adError = '' this._adError = ''
this._loadPromiseResolve = null this._loadPromiseResolve = null
this._loadPromiseReject = null this._loadPromiseReject = null
this._lastLoadTime = 0
const rewardAd = this._rewardAd = plus.ad.createRewardedVideoAd(options) const rewardAd = this._rewardAd = plus.ad.createRewardedVideoAd(options)
rewardAd.onLoad((e) => { rewardAd.onLoad((e) => {
this._isLoad = true this._isLoad = true
this._dispatchEvent('load', {}) this._dispatchEvent('load', {})
this._lastLoadTime = Date.now()
if (this._loadPromiseResolve != null) { if (this._loadPromiseResolve != null) {
this._loadPromiseResolve() this._loadPromiseResolve()
this._loadPromiseResolve = null this._loadPromiseResolve = null
...@@ -43,7 +49,11 @@ class RewardedVideoAd { ...@@ -43,7 +49,11 @@ class RewardedVideoAd {
const { code, message } = e const { code, message } = e
const data = { code: code, errMsg: message } const data = { code: code, errMsg: message }
this._adError = message this._adError = message
if (code === -5008) {
this._isLoad = false
}
this._dispatchEvent('error', data) this._dispatchEvent('error', data)
// TODO
if ((code === -5005 || ERROR_CODE_LIST.index(code) === -1) && this._loadPromiseReject != null) { if ((code === -5005 || ERROR_CODE_LIST.index(code) === -1) && this._loadPromiseReject != null) {
this._loadPromiseReject(data) this._loadPromiseReject(data)
this._loadPromiseReject = null this._loadPromiseReject = null
...@@ -52,6 +62,10 @@ class RewardedVideoAd { ...@@ -52,6 +62,10 @@ class RewardedVideoAd {
this._loadAd() this._loadAd()
} }
get isExpired () {
return (Math.abs(Date.now() - this._lastLoadTime) > EXPIRED_TIME)
}
load () { load () {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (this._isLoad) { if (this._isLoad) {
...@@ -66,6 +80,15 @@ class RewardedVideoAd { ...@@ -66,6 +80,15 @@ class RewardedVideoAd {
show () { show () {
return new Promise((resolve, reject) => { 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) { if (this._isLoad) {
this._rewardAd.show() this._rewardAd.show()
resolve() resolve()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册