From 4d56e6a0994802653b3acff7ec25672f74bf5c6c Mon Sep 17 00:00:00 2001 From: qiang Date: Sat, 18 Jul 2020 18:19:25 +0800 Subject: [PATCH] build v3 --- packages/uni-app-plus/dist/index.v3.js | 28 ++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/uni-app-plus/dist/index.v3.js b/packages/uni-app-plus/dist/index.v3.js index 388bbc9e86..f2338cf7b7 100644 --- a/packages/uni-app-plus/dist/index.v3.js +++ b/packages/uni-app-plus/dist/index.v3.js @@ -605,7 +605,7 @@ var serviceContext = (function () { for (let i = 0; i < hooks.length; i++) { const hook = hooks[i]; if (promise) { - promise = Promise.then(wrapperHook(hook)); + promise = Promise.resolve(wrapperHook(hook)); } else { const res = hook(data); if (isPromise(res)) { @@ -3375,7 +3375,7 @@ var serviceContext = (function () { state }, res)); - const events = ['play', 'pause', 'ended', 'stop']; + const events = ['play', 'pause', 'ended', 'stop', 'canplay']; function initMusic () { if (audio) { @@ -9791,6 +9791,9 @@ var serviceContext = (function () { ]; 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 = {}) { @@ -9807,10 +9810,14 @@ var serviceContext = (function () { 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; @@ -9827,7 +9834,11 @@ var serviceContext = (function () { 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; @@ -9836,6 +9847,10 @@ var serviceContext = (function () { this._loadAd(); } + get isExpired () { + return (Math.abs(Date.now() - this._lastLoadTime) > EXPIRED_TIME) + } + load () { return new Promise((resolve, reject) => { if (this._isLoad) { @@ -9850,6 +9865,15 @@ var serviceContext = (function () { 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