@cardsjd/portal 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/AdMobPortal.js +1 -49
- package/lib/BasePortal.js +69 -4
- package/lib/CrazyGamesPortal.js +1 -49
- package/lib/FacebookPortal.js +4 -48
- package/lib/GameDistributionPortal.js +3 -47
- package/lib/PokiPortal.js +2 -46
- package/lib/WebPortal.js +46 -88
- package/package.json +21 -20
package/lib/AdMobPortal.js
CHANGED
|
@@ -153,53 +153,7 @@ export class AdMobPortal extends BasePortal {
|
|
|
153
153
|
adId: this.appConfig?.interstitialAdId,
|
|
154
154
|
});
|
|
155
155
|
}
|
|
156
|
-
async tryShowInterstitialAd(options) {
|
|
157
|
-
//only load/show if ads enabled
|
|
158
|
-
if (this.isSetup === false) { return; }
|
|
159
|
-
|
|
160
|
-
const config = this.config;
|
|
161
|
-
const offsetStartdelay = options?.offsetStartdelay || config.offsetStartdelay || 120; //start with 1 min passed to get the first ad to show faster
|
|
162
|
-
const delayBetweenAds = options?.delayBetweenAds || config.delayBetweenAds || 240; //check for 240 (4 min) seconds passed was 180
|
|
163
|
-
const awayResetTime = options?.awayResetTime || config.awayResetTime || 1200; //check if over 20 min, may have not been in the app and reopened it with out restarting
|
|
164
|
-
|
|
165
|
-
//1. only allow ad to be shown/loaded once every 150 second (Advertisement.delayBetweenAds)
|
|
166
|
-
//2. check if over 20 min, may have not been in the app and reopened it with out restarting
|
|
167
|
-
//3. load ad ether way
|
|
168
|
-
//4. show ad if conditions met
|
|
169
|
-
|
|
170
|
-
let readyToShowAd = false;
|
|
171
|
-
|
|
172
|
-
//reset timer
|
|
173
|
-
if (!this.lastShownInterstitial) {
|
|
174
|
-
this.lastShownInterstitial = Date.now();//now
|
|
175
|
-
//add start offset delay
|
|
176
|
-
const newDate = new Date();
|
|
177
|
-
newDate.setSeconds(newDate.getSeconds() - offsetStartdelay);
|
|
178
|
-
this.lastShownInterstitial = newDate;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const secondsSinceLastAd = (Date.now() - this.lastShownInterstitial) / 1000;
|
|
182
|
-
|
|
183
|
-
//check for delayBetweenAds seconds passed
|
|
184
|
-
if (secondsSinceLastAd > delayBetweenAds) {
|
|
185
|
-
readyToShowAd = true;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
//check if over 20 min, may have not been in the app and reopened it with out restarting
|
|
189
|
-
if (secondsSinceLastAd > awayResetTime) {
|
|
190
|
-
readyToShowAd = false;
|
|
191
|
-
this.lastShownInterstitial = Date.now();//now, reset
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
console.log('readyToShowInterstitialAd: ' + readyToShowAd + ' : ' + secondsSinceLastAd + ' of ' + delayBetweenAds);
|
|
195
156
|
|
|
196
|
-
// show ad or just load ad (not load and show)
|
|
197
|
-
if (readyToShowAd) {
|
|
198
|
-
await this.showInterstitialAd();
|
|
199
|
-
} else {
|
|
200
|
-
await this.loadInterstitialAd();
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
157
|
async showInterstitialAd() {
|
|
204
158
|
if (!this.isAdLoaded()) {
|
|
205
159
|
await this.loadInterstitialAd();
|
|
@@ -225,9 +179,7 @@ export class AdMobPortal extends BasePortal {
|
|
|
225
179
|
}
|
|
226
180
|
|
|
227
181
|
async showRewardedAd() {
|
|
228
|
-
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
182
|
+
await this.setupAds();
|
|
231
183
|
|
|
232
184
|
if (!this.isRewardedAdLoaded()) {
|
|
233
185
|
await this.loadRewardedAd();
|
package/lib/BasePortal.js
CHANGED
|
@@ -50,10 +50,75 @@ export class BasePortal {
|
|
|
50
50
|
|
|
51
51
|
createShortCut() { }
|
|
52
52
|
|
|
53
|
-
async tryShowInterstitialAd(
|
|
54
|
-
|
|
53
|
+
async tryShowInterstitialAd(options) {
|
|
54
|
+
await this.setupAds();
|
|
55
|
+
|
|
56
|
+
const config = this.config || {};
|
|
57
|
+
const offsetStartdelay = options?.offsetStartdelay || config.offsetStartdelay || 120; //start with 1 min passed to get the first ad to show faster
|
|
58
|
+
const delayBetweenAds = options?.delayBetweenAds || config.delayBetweenAds || 240; //check for 240 (4 min) seconds passed was 180
|
|
59
|
+
const awayResetTime = options?.awayResetTime || config.awayResetTime || 1200; //check if over 20 min, may have not been in the app and reopened it with out restarting
|
|
60
|
+
|
|
61
|
+
//1. only allow ad to be shown/loaded once every 150 second (Advertisement.delayBetweenAds)
|
|
62
|
+
//2. check if over 20 min, may have not been in the app and reopened it with out restarting
|
|
63
|
+
//3. load ad ether way
|
|
64
|
+
//4. show ad if conditions met
|
|
65
|
+
|
|
66
|
+
let readyToShowAd = false;
|
|
67
|
+
|
|
68
|
+
//reset timer
|
|
69
|
+
if (!this.lastShownInterstitial) {
|
|
70
|
+
this.lastShownInterstitial = Date.now();//now
|
|
71
|
+
//add start offset delay
|
|
72
|
+
const newDate = new Date();
|
|
73
|
+
newDate.setSeconds(newDate.getSeconds() - offsetStartdelay);
|
|
74
|
+
this.lastShownInterstitial = newDate;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const secondsSinceLastAd = (Date.now() - this.lastShownInterstitial) / 1000;
|
|
78
|
+
|
|
79
|
+
//check for delayBetweenAds seconds passed
|
|
80
|
+
if (secondsSinceLastAd > delayBetweenAds) {
|
|
81
|
+
readyToShowAd = true;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
//check if over 20 min, may have not been in the app and reopened it with out restarting
|
|
85
|
+
if (secondsSinceLastAd > awayResetTime) {
|
|
86
|
+
readyToShowAd = false;
|
|
87
|
+
this.lastShownInterstitial = Date.now();//now, reset
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
console.log('readyToShowInterstitialAd: ' + readyToShowAd + ' : ' + secondsSinceLastAd + ' of ' + delayBetweenAds);
|
|
91
|
+
|
|
92
|
+
// show ad or just load ad (not load and show)
|
|
93
|
+
if (readyToShowAd) {
|
|
94
|
+
await this.showInterstitialAd();
|
|
95
|
+
} else {
|
|
96
|
+
await this.loadInterstitialAd();
|
|
97
|
+
}
|
|
55
98
|
}
|
|
56
|
-
async showAppOpenAdWithMaxDelay(
|
|
57
|
-
|
|
99
|
+
async showAppOpenAdWithMaxDelay(maxDelay) {
|
|
100
|
+
await this.setupAds();
|
|
101
|
+
|
|
102
|
+
if (!maxDelay) {
|
|
103
|
+
maxDelay = 4000;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
//get start time
|
|
107
|
+
const startTime = Date.now();
|
|
108
|
+
if (this.loadAppOpenAd) {
|
|
109
|
+
await this.loadAppOpenAd();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
//this wont work...
|
|
113
|
+
//is timer over maxDelay
|
|
114
|
+
const timePassed = Date.now() - startTime;
|
|
115
|
+
if (timePassed > maxDelay) {
|
|
116
|
+
console.log(`showAppOpenAdWithMaxDelay took too long to load [${timePassed}ms/${maxDelay}ms], skipping ad`);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (this.showAppOpenAd) {
|
|
121
|
+
await this.showAppOpenAd();
|
|
122
|
+
}
|
|
58
123
|
}
|
|
59
124
|
}
|
package/lib/CrazyGamesPortal.js
CHANGED
|
@@ -256,53 +256,7 @@ export class CrazyGamesPortal extends BasePortal {
|
|
|
256
256
|
await this.setupAds();
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
|
-
async tryShowInterstitialAd(options) {
|
|
260
|
-
//only load/show if ads enabled
|
|
261
|
-
if (this.isSetup === false) { return; }
|
|
262
259
|
|
|
263
|
-
const config = this.config;
|
|
264
|
-
const offsetStartdelay = options?.offsetStartdelay || config.offsetStartdelay || 120; //start with 1 min passed to get the first ad to show faster
|
|
265
|
-
const delayBetweenAds = options?.delayBetweenAds || config.delayBetweenAds || 240; //check for 240 (4 min) seconds passed was 180
|
|
266
|
-
const awayResetTime = options?.awayResetTime || config.awayResetTime || 1200; //check if over 20 min, may have not been in the app and reopened it with out restarting
|
|
267
|
-
|
|
268
|
-
//1. only allow ad to be shown/loaded once every 150 second (Advertisement.delayBetweenAds)
|
|
269
|
-
//2. check if over 20 min, may have not been in the app and reopened it with out restarting
|
|
270
|
-
//3. load ad ether way
|
|
271
|
-
//4. show ad if conditions met
|
|
272
|
-
|
|
273
|
-
let readyToShowAd = false;
|
|
274
|
-
|
|
275
|
-
//reset timer
|
|
276
|
-
if (!this.lastShownInterstitial) {
|
|
277
|
-
this.lastShownInterstitial = Date.now();//now
|
|
278
|
-
//add start offset delay
|
|
279
|
-
const newDate = new Date();
|
|
280
|
-
newDate.setSeconds(newDate.getSeconds() - offsetStartdelay);
|
|
281
|
-
this.lastShownInterstitial = newDate;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
const secondsSinceLastAd = (Date.now() - this.lastShownInterstitial) / 1000;
|
|
285
|
-
|
|
286
|
-
//check for delayBetweenAds seconds passed
|
|
287
|
-
if (secondsSinceLastAd > delayBetweenAds) {
|
|
288
|
-
readyToShowAd = true;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
//check if over 20 min, may have not been in the app and reopened it with out restarting
|
|
292
|
-
if (secondsSinceLastAd > awayResetTime) {
|
|
293
|
-
readyToShowAd = false;
|
|
294
|
-
this.lastShownInterstitial = Date.now();//now, reset
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
console.log('readyToShowInterstitialAd: ' + readyToShowAd + ' : ' + secondsSinceLastAd + ' of ' + delayBetweenAds);
|
|
298
|
-
|
|
299
|
-
// show ad or just load ad (not load and show)
|
|
300
|
-
if (readyToShowAd) {
|
|
301
|
-
await this.showInterstitialAd();
|
|
302
|
-
} else {
|
|
303
|
-
await this.loadInterstitialAd();
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
260
|
async showInterstitialAd() {
|
|
307
261
|
console.log('CrazyGames.showAd');
|
|
308
262
|
|
|
@@ -363,9 +317,7 @@ async tryShowInterstitialAd(options) {
|
|
|
363
317
|
return false;
|
|
364
318
|
}
|
|
365
319
|
|
|
366
|
-
|
|
367
|
-
await this.setupAds();
|
|
368
|
-
}
|
|
320
|
+
await this.setupAds();
|
|
369
321
|
|
|
370
322
|
const adType = 'rewarded';
|
|
371
323
|
const adProvider = this.adProviderName;
|
package/lib/FacebookPortal.js
CHANGED
|
@@ -227,53 +227,7 @@ export class FacebookPortal extends BasePortal {
|
|
|
227
227
|
console.error('FB_Ads.getInterstitialAdAsync error: ' + ex);
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
|
-
|
|
231
|
-
//only load/show if ads enabled
|
|
232
|
-
if (this.isSetup === false) { return; }
|
|
233
|
-
|
|
234
|
-
const config = this.config;
|
|
235
|
-
const offsetStartdelay = options?.offsetStartdelay || config.offsetStartdelay || 120; //start with 1 min passed to get the first ad to show faster
|
|
236
|
-
const delayBetweenAds = options?.delayBetweenAds || config.delayBetweenAds || 240; //check for 240 (4 min) seconds passed was 180
|
|
237
|
-
const awayResetTime = options?.awayResetTime || config.awayResetTime || 1200; //check if over 20 min, may have not been in the app and reopened it with out restarting
|
|
238
|
-
|
|
239
|
-
//1. only allow ad to be shown/loaded once every 150 second (Advertisement.delayBetweenAds)
|
|
240
|
-
//2. check if over 20 min, may have not been in the app and reopened it with out restarting
|
|
241
|
-
//3. load ad ether way
|
|
242
|
-
//4. show ad if conditions met
|
|
243
|
-
|
|
244
|
-
let readyToShowAd = false;
|
|
245
|
-
|
|
246
|
-
//reset timer
|
|
247
|
-
if (!this.lastShownInterstitial) {
|
|
248
|
-
this.lastShownInterstitial = Date.now();//now
|
|
249
|
-
//add start offset delay
|
|
250
|
-
const newDate = new Date();
|
|
251
|
-
newDate.setSeconds(newDate.getSeconds() - offsetStartdelay);
|
|
252
|
-
this.lastShownInterstitial = newDate;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
const secondsSinceLastAd = (Date.now() - this.lastShownInterstitial) / 1000;
|
|
256
|
-
|
|
257
|
-
//check for delayBetweenAds seconds passed
|
|
258
|
-
if (secondsSinceLastAd > delayBetweenAds) {
|
|
259
|
-
readyToShowAd = true;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
//check if over 20 min, may have not been in the app and reopened it with out restarting
|
|
263
|
-
if (secondsSinceLastAd > awayResetTime) {
|
|
264
|
-
readyToShowAd = false;
|
|
265
|
-
this.lastShownInterstitial = Date.now();//now, reset
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
console.log('readyToShowInterstitialAd: ' + readyToShowAd + ' : ' + secondsSinceLastAd + ' of ' + delayBetweenAds);
|
|
269
|
-
|
|
270
|
-
// show ad or just load ad (not load and show)
|
|
271
|
-
if (readyToShowAd) {
|
|
272
|
-
await this.showInterstitialAd();
|
|
273
|
-
} else {
|
|
274
|
-
await this.loadInterstitialAd();
|
|
275
|
-
}
|
|
276
|
-
}
|
|
230
|
+
|
|
277
231
|
showInterstitialAd() {
|
|
278
232
|
console.log('FB_Ads.showInterstitialAd');
|
|
279
233
|
|
|
@@ -453,9 +407,11 @@ async tryShowInterstitialAd(options) {
|
|
|
453
407
|
|
|
454
408
|
}
|
|
455
409
|
|
|
456
|
-
showRewardedAd() {
|
|
410
|
+
async showRewardedAd() {
|
|
457
411
|
console.log('FB_Ads.ShowRewardedAd');
|
|
458
412
|
|
|
413
|
+
await this.setupAds();
|
|
414
|
+
|
|
459
415
|
if (this.isErrorState()) {
|
|
460
416
|
console.log('FBInstant.ShowRewardedAd() - isErrorState = true');
|
|
461
417
|
return true;
|
|
@@ -63,53 +63,7 @@ export class GameDistribution extends BasePortal {
|
|
|
63
63
|
this.isInterstitialAdReady = false;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
async tryShowInterstitialAd(options) {
|
|
67
|
-
//only load/show if ads enabled
|
|
68
|
-
if (this.isSetup === false) { return; }
|
|
69
|
-
|
|
70
|
-
const config = this.config;
|
|
71
|
-
const offsetStartdelay = options?.offsetStartdelay || config.offsetStartdelay || 120; //start with 1 min passed to get the first ad to show faster
|
|
72
|
-
const delayBetweenAds = options?.delayBetweenAds || config.delayBetweenAds || 240; //check for 240 (4 min) seconds passed was 180
|
|
73
|
-
const awayResetTime = options?.awayResetTime || config.awayResetTime || 1200; //check if over 20 min, may have not been in the app and reopened it with out restarting
|
|
74
|
-
|
|
75
|
-
//1. only allow ad to be shown/loaded once every 150 second (Advertisement.delayBetweenAds)
|
|
76
|
-
//2. check if over 20 min, may have not been in the app and reopened it with out restarting
|
|
77
|
-
//3. load ad ether way
|
|
78
|
-
//4. show ad if conditions met
|
|
79
|
-
|
|
80
|
-
let readyToShowAd = false;
|
|
81
|
-
|
|
82
|
-
//reset timer
|
|
83
|
-
if (!this.lastShownInterstitial) {
|
|
84
|
-
this.lastShownInterstitial = Date.now();//now
|
|
85
|
-
//add start offset delay
|
|
86
|
-
const newDate = new Date();
|
|
87
|
-
newDate.setSeconds(newDate.getSeconds() - offsetStartdelay);
|
|
88
|
-
this.lastShownInterstitial = newDate;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const secondsSinceLastAd = (Date.now() - this.lastShownInterstitial) / 1000;
|
|
92
|
-
|
|
93
|
-
//check for delayBetweenAds seconds passed
|
|
94
|
-
if (secondsSinceLastAd > delayBetweenAds) {
|
|
95
|
-
readyToShowAd = true;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
//check if over 20 min, may have not been in the app and reopened it with out restarting
|
|
99
|
-
if (secondsSinceLastAd > awayResetTime) {
|
|
100
|
-
readyToShowAd = false;
|
|
101
|
-
this.lastShownInterstitial = Date.now();//now, reset
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
console.log('readyToShowInterstitialAd: ' + readyToShowAd + ' : ' + secondsSinceLastAd + ' of ' + delayBetweenAds);
|
|
105
66
|
|
|
106
|
-
// show ad or just load ad (not load and show)
|
|
107
|
-
if (readyToShowAd) {
|
|
108
|
-
await this.showInterstitialAd();
|
|
109
|
-
} else {
|
|
110
|
-
await this.loadInterstitialAd();
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
67
|
async showInterstitialAd() {
|
|
114
68
|
if (!this.isReady()) {
|
|
115
69
|
return false;
|
|
@@ -143,11 +97,13 @@ async tryShowInterstitialAd(options) {
|
|
|
143
97
|
})();
|
|
144
98
|
}
|
|
145
99
|
|
|
146
|
-
showRewardedAd() {
|
|
100
|
+
async showRewardedAd() {
|
|
147
101
|
if (!this.isReady()) {
|
|
148
102
|
return false;
|
|
149
103
|
}
|
|
150
104
|
|
|
105
|
+
await this.setupAds();
|
|
106
|
+
|
|
151
107
|
return globalThis.gdsdk.showAd(AdType.Rewarded);
|
|
152
108
|
}
|
|
153
109
|
}
|
package/lib/PokiPortal.js
CHANGED
|
@@ -185,53 +185,7 @@ export class PokiPortal extends BasePortal {
|
|
|
185
185
|
async loadInterstitialAd() {
|
|
186
186
|
// Poki commercial breaks do not require manual preloading
|
|
187
187
|
}
|
|
188
|
-
async tryShowInterstitialAd(options) {
|
|
189
|
-
//only load/show if ads enabled
|
|
190
|
-
if (this.isSetup === false) { return; }
|
|
191
|
-
|
|
192
|
-
const config = this.config;
|
|
193
|
-
const offsetStartdelay = options?.offsetStartdelay || config.offsetStartdelay || 120; //start with 1 min passed to get the first ad to show faster
|
|
194
|
-
const delayBetweenAds = options?.delayBetweenAds || config.delayBetweenAds || 240; //check for 240 (4 min) seconds passed was 180
|
|
195
|
-
const awayResetTime = options?.awayResetTime || config.awayResetTime || 1200; //check if over 20 min, may have not been in the app and reopened it with out restarting
|
|
196
|
-
|
|
197
|
-
//1. only allow ad to be shown/loaded once every 150 second (Advertisement.delayBetweenAds)
|
|
198
|
-
//2. check if over 20 min, may have not been in the app and reopened it with out restarting
|
|
199
|
-
//3. load ad ether way
|
|
200
|
-
//4. show ad if conditions met
|
|
201
|
-
|
|
202
|
-
let readyToShowAd = false;
|
|
203
|
-
|
|
204
|
-
//reset timer
|
|
205
|
-
if (!this.lastShownInterstitial) {
|
|
206
|
-
this.lastShownInterstitial = Date.now();//now
|
|
207
|
-
//add start offset delay
|
|
208
|
-
const newDate = new Date();
|
|
209
|
-
newDate.setSeconds(newDate.getSeconds() - offsetStartdelay);
|
|
210
|
-
this.lastShownInterstitial = newDate;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
const secondsSinceLastAd = (Date.now() - this.lastShownInterstitial) / 1000;
|
|
214
|
-
|
|
215
|
-
//check for delayBetweenAds seconds passed
|
|
216
|
-
if (secondsSinceLastAd > delayBetweenAds) {
|
|
217
|
-
readyToShowAd = true;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
//check if over 20 min, may have not been in the app and reopened it with out restarting
|
|
221
|
-
if (secondsSinceLastAd > awayResetTime) {
|
|
222
|
-
readyToShowAd = false;
|
|
223
|
-
this.lastShownInterstitial = Date.now();//now, reset
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
console.log('readyToShowInterstitialAd: ' + readyToShowAd + ' : ' + secondsSinceLastAd + ' of ' + delayBetweenAds);
|
|
227
188
|
|
|
228
|
-
// show ad or just load ad (not load and show)
|
|
229
|
-
if (readyToShowAd) {
|
|
230
|
-
await this.showInterstitialAd();
|
|
231
|
-
} else {
|
|
232
|
-
await this.loadInterstitialAd();
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
189
|
async showInterstitialAd() {
|
|
236
190
|
if (!this.isReady()) {
|
|
237
191
|
return false;
|
|
@@ -291,6 +245,8 @@ async tryShowInterstitialAd(options) {
|
|
|
291
245
|
return false;
|
|
292
246
|
}
|
|
293
247
|
|
|
248
|
+
await this.setupAds();
|
|
249
|
+
|
|
294
250
|
const adType = 'rewarded';
|
|
295
251
|
const adProvider = this.adProviderName;
|
|
296
252
|
|
package/lib/WebPortal.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BasePortal } from './BasePortal';
|
|
1
|
+
import { BasePortal } from './BasePortal.js';
|
|
2
2
|
|
|
3
3
|
export class WebPortal extends BasePortal {
|
|
4
4
|
name = 'WebPortal';
|
|
@@ -16,9 +16,10 @@ export class WebPortal extends BasePortal {
|
|
|
16
16
|
this.onAdRewarded = null;
|
|
17
17
|
|
|
18
18
|
this.page_url = 'cardsjd.com';
|
|
19
|
-
this.adProviderName = 'GoogleH5';
|
|
20
|
-
this.isSetup = false;
|
|
21
|
-
this.isSetupLoading = false;
|
|
19
|
+
this.adProviderName = 'GoogleH5';
|
|
20
|
+
this.isSetup = false;
|
|
21
|
+
this.isSetupLoading = false;
|
|
22
|
+
this.setupPromise = null;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
async init() {
|
|
@@ -47,33 +48,34 @@ export class WebPortal extends BasePortal {
|
|
|
47
48
|
|
|
48
49
|
// ----- Ad methods -----
|
|
49
50
|
|
|
50
|
-
async setupAds() {
|
|
51
|
-
if (this.isSetup) {
|
|
52
|
-
console.log('
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
51
|
+
async setupAds() {
|
|
52
|
+
if (this.isSetup) {
|
|
53
|
+
console.log('GoogleH5.isSetup is already done');
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (this.setupPromise) {
|
|
58
|
+
return this.setupPromise;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
this.isSetupLoading = true;
|
|
62
|
+
this.setupPromise = this.setupAdsOnce();
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
return await this.setupPromise;
|
|
66
|
+
} finally {
|
|
67
|
+
this.isSetupLoading = false;
|
|
68
|
+
this.setupPromise = null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async setupAdsOnce() {
|
|
73
|
+
await this.loadScript();
|
|
74
|
+
console.log('adsbygoogle loaded');
|
|
75
|
+
|
|
76
|
+
if (typeof globalThis.adConfig === 'undefined') {
|
|
77
|
+
console.log('GoogleH5 adBreak plugin not ready');
|
|
78
|
+
throw Error('GoogleH5 adBreak plugin not ready');
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
globalThis.adConfig({
|
|
@@ -82,10 +84,9 @@ export class WebPortal extends BasePortal {
|
|
|
82
84
|
onReady: () => {
|
|
83
85
|
console.log('GoogleH5.isSetup is ready');
|
|
84
86
|
},
|
|
85
|
-
});
|
|
86
|
-
this.isSetup = true;
|
|
87
|
-
|
|
88
|
-
}
|
|
87
|
+
});
|
|
88
|
+
this.isSetup = true;
|
|
89
|
+
}
|
|
89
90
|
|
|
90
91
|
async loadScript() {
|
|
91
92
|
return new Promise((resolve, reject) => {
|
|
@@ -119,57 +120,11 @@ export class WebPortal extends BasePortal {
|
|
|
119
120
|
});
|
|
120
121
|
}
|
|
121
122
|
|
|
122
|
-
loadInterstitialAd() {
|
|
123
|
-
console.log('GoogleH5.loadAd');
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (this.isSetup === false) { return; }
|
|
128
|
-
|
|
129
|
-
const config = this.config;
|
|
130
|
-
const offsetStartdelay = options?.offsetStartdelay || config.offsetStartdelay || 120; //start with 1 min passed to get the first ad to show faster
|
|
131
|
-
const delayBetweenAds = options?.delayBetweenAds || config.delayBetweenAds || 240; //check for 240 (4 min) seconds passed was 180
|
|
132
|
-
const awayResetTime = options?.awayResetTime || config.awayResetTime || 1200; //check if over 20 min, may have not been in the app and reopened it with out restarting
|
|
133
|
-
|
|
134
|
-
//1. only allow ad to be shown/loaded once every 150 second (Advertisement.delayBetweenAds)
|
|
135
|
-
//2. check if over 20 min, may have not been in the app and reopened it with out restarting
|
|
136
|
-
//3. load ad ether way
|
|
137
|
-
//4. show ad if conditions met
|
|
138
|
-
|
|
139
|
-
let readyToShowAd = false;
|
|
140
|
-
|
|
141
|
-
//reset timer
|
|
142
|
-
if (!this.lastShownInterstitial) {
|
|
143
|
-
this.lastShownInterstitial = Date.now();//now
|
|
144
|
-
//add start offset delay
|
|
145
|
-
const newDate = new Date();
|
|
146
|
-
newDate.setSeconds(newDate.getSeconds() - offsetStartdelay);
|
|
147
|
-
this.lastShownInterstitial = newDate;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const secondsSinceLastAd = (Date.now() - this.lastShownInterstitial) / 1000;
|
|
151
|
-
|
|
152
|
-
//check for delayBetweenAds seconds passed
|
|
153
|
-
if (secondsSinceLastAd > delayBetweenAds) {
|
|
154
|
-
readyToShowAd = true;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
//check if over 20 min, may have not been in the app and reopened it with out restarting
|
|
158
|
-
if (secondsSinceLastAd > awayResetTime) {
|
|
159
|
-
readyToShowAd = false;
|
|
160
|
-
this.lastShownInterstitial = Date.now();//now, reset
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
console.log('readyToShowInterstitialAd: ' + readyToShowAd + ' : ' + secondsSinceLastAd + ' of ' + delayBetweenAds);
|
|
164
|
-
|
|
165
|
-
// show ad or just load ad (not load and show)
|
|
166
|
-
if (readyToShowAd) {
|
|
167
|
-
await this.showInterstitialAd();
|
|
168
|
-
} else {
|
|
169
|
-
await this.loadInterstitialAd();
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
showInterstitialAd() {
|
|
123
|
+
loadInterstitialAd() {
|
|
124
|
+
console.log('GoogleH5.loadAd');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
showInterstitialAd() {
|
|
173
128
|
console.log('GoogleH5.showAd');
|
|
174
129
|
|
|
175
130
|
if (typeof adBreak === 'undefined' || !globalThis.adBreak) {
|
|
@@ -214,9 +169,11 @@ export class WebPortal extends BasePortal {
|
|
|
214
169
|
return true;
|
|
215
170
|
}
|
|
216
171
|
|
|
217
|
-
showRewardedAd() {
|
|
172
|
+
async showRewardedAd() {
|
|
218
173
|
console.log('GoogleH5.ShowRewardedAd');
|
|
219
174
|
|
|
175
|
+
await this.setupAds();
|
|
176
|
+
|
|
220
177
|
if (typeof globalThis.adBreak === 'undefined' || !globalThis.adBreak) {
|
|
221
178
|
console.log('GoogleH5 adBreak plugin not ready'); return;
|
|
222
179
|
}
|
|
@@ -304,4 +261,5 @@ export class WebPortal extends BasePortal {
|
|
|
304
261
|
|
|
305
262
|
return adStatus;
|
|
306
263
|
}
|
|
307
|
-
|
|
264
|
+
|
|
265
|
+
}
|
package/package.json
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cardsjd/portal",
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "0.1.9",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"lib"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"test": "node --test",
|
|
15
|
+
"lint": "eslint lib --report-unused-disable-directives --max-warnings 0",
|
|
16
|
+
"lint:fix": "npm run lint -- --fix"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@capacitor-community/admob": "^7.0.3",
|
|
21
|
+
"@discord/embedded-app-sdk": "^2.4.0"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {}
|
|
23
24
|
}
|