Add retrying logic for ethical ads, add variable for the API url (#244)

This commit is contained in:
Redblueflame 2021-05-28 22:20:22 +02:00 committed by GitHub
parent cd8bc7a7a1
commit fd17e5a4c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 12 deletions

View File

@ -79,6 +79,7 @@ export default {
onSmallScreen: false, onSmallScreen: false,
windowResizeListenerDebounce: null, windowResizeListenerDebounce: null,
ethicalAdLoad: null, ethicalAdLoad: null,
tries: 0,
} }
}, },
computed: { computed: {
@ -119,7 +120,7 @@ export default {
this.displayed = true this.displayed = true
if (process.browser) { if (process.browser) {
this.handleWindowResize() this.handleWindowResize()
this.refresh_ad() this.refresh_ad(true)
} }
}, },
methods: { methods: {
@ -133,14 +134,14 @@ export default {
this.format = sizes[this.type] this.format = sizes[this.type]
this.displayed = true this.displayed = true
// Refresh ad // Refresh ad
this.refresh_ad() this.refresh_ad(true)
} }
return return
} }
if (this.onSmallScreen === false) { if (this.onSmallScreen === false) {
// Reload ad // Reload ad
this.onSmallScreen = true this.onSmallScreen = true
this.refresh_ad() this.refresh_ad(true)
} }
this.onSmallScreen = true this.onSmallScreen = true
if (this.smallScreen === 'destroy') { if (this.smallScreen === 'destroy') {
@ -151,15 +152,24 @@ export default {
} }
}, 300) }, 300)
}, },
refresh_ad() { refresh_ad(reset = false) {
if (reset) {
this.tries = 0
}
if (this.tries >= 3) {
// Too many tries, we stop
return
}
if (this.ethical_ads_on) { if (this.ethical_ads_on) {
clearTimeout(this.ethicalAdLoad) clearTimeout(this.ethicalAdLoad)
this.ethicalAdLoad = setTimeout(() => { this.ethicalAdLoad = setTimeout(() => {
if (typeof window.ethicalads === 'undefined') { try {
ethicalads.load()
} catch (e) {
console.log('EthicalAds are not loaded yet, retrying...') console.log('EthicalAds are not loaded yet, retrying...')
this.refresh_ad() this.refresh_ad()
this.tries++
} }
ethicalads.load()
}, 100) }, 100)
} }
}, },

View File

@ -175,7 +175,7 @@ export default {
}, },
publicRuntimeConfig: { publicRuntimeConfig: {
axios: { axios: {
browserBaseURL: process.env.BROWSER_BASE_URL, baseURL: process.env.API_URL,
}, },
ads: { ads: {
ghostMode: process.env.ENABLE_ADS == null, ghostMode: process.env.ENABLE_ADS == null,
@ -187,11 +187,6 @@ export default {
base_url: process.env.ARIADNE_URL, base_url: process.env.ARIADNE_URL,
}, },
}, },
privateRuntimeConfig: {
axios: {
baseURL: process.env.BASE_URL,
},
},
} }
function getDomain() { function getDomain() {