@cardsjd/portal 0.1.2 → 0.1.4
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 +3 -3
- package/lib/BasePortal.js +85 -10
- package/lib/CrazyGamesPortal.js +2 -2
- package/lib/FacebookPortal.js +12 -12
- package/lib/GameDistributionPortal.js +3 -3
- package/lib/PokiPortal.js +2 -2
- package/lib/WebPortal.js +2 -2
- package/package.json +1 -1
package/lib/AdMobPortal.js
CHANGED
|
@@ -140,7 +140,7 @@ export class AdMobPortal extends BasePortal {
|
|
|
140
140
|
return this._isRewardedAdLoaded;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
async
|
|
143
|
+
async loadInterstitialAd() {
|
|
144
144
|
if (this.isSetup === false) {
|
|
145
145
|
return;
|
|
146
146
|
}
|
|
@@ -154,9 +154,9 @@ export class AdMobPortal extends BasePortal {
|
|
|
154
154
|
});
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
-
async
|
|
157
|
+
async showInterstitialAd() {
|
|
158
158
|
if (!this.isAdLoaded()) {
|
|
159
|
-
await this.
|
|
159
|
+
await this.loadInterstitialAd();
|
|
160
160
|
return; // no auto show
|
|
161
161
|
}
|
|
162
162
|
|
package/lib/BasePortal.js
CHANGED
|
@@ -4,8 +4,8 @@ export class BasePortal {
|
|
|
4
4
|
|
|
5
5
|
async load() { }
|
|
6
6
|
|
|
7
|
-
async save(
|
|
8
|
-
|
|
7
|
+
async save(_data, _forceSave) { }
|
|
8
|
+
|
|
9
9
|
async delete() { }
|
|
10
10
|
|
|
11
11
|
gameStart() { }
|
|
@@ -20,26 +20,26 @@ export class BasePortal {
|
|
|
20
20
|
|
|
21
21
|
async getInvite() { }
|
|
22
22
|
|
|
23
|
-
async inviteSend(
|
|
23
|
+
async inviteSend(_user, _room) { }
|
|
24
24
|
|
|
25
|
-
async findAndInvite(
|
|
25
|
+
async findAndInvite(_userFrom, _room) { }
|
|
26
26
|
|
|
27
27
|
async getFriends() { }
|
|
28
28
|
|
|
29
|
-
tryShowInterstitialAd() { }
|
|
30
|
-
|
|
31
29
|
setupAds() { }
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
showAd() { }
|
|
31
|
+
async loadInterstitialAd(_force) { }
|
|
36
32
|
|
|
37
|
-
|
|
33
|
+
async showInterstitialAd() { }
|
|
38
34
|
|
|
39
35
|
loadRewardedAd(_onLoaded) { }
|
|
40
36
|
|
|
41
37
|
showRewardedAd() { }
|
|
42
38
|
|
|
39
|
+
loadAppOpenAd() { }
|
|
40
|
+
|
|
41
|
+
async showAppOpenAd(_maxDelay) { }
|
|
42
|
+
|
|
43
43
|
isAdLoaded() { }
|
|
44
44
|
|
|
45
45
|
isRewardedAdLoaded() { }
|
|
@@ -49,4 +49,79 @@ export class BasePortal {
|
|
|
49
49
|
isErrorState() { }
|
|
50
50
|
|
|
51
51
|
createShortCut() { }
|
|
52
|
+
|
|
53
|
+
async tryShowInterstitialAd(options) {
|
|
54
|
+
//only load/show if ads enabled
|
|
55
|
+
if (this.isSetup === false) { return; }
|
|
56
|
+
|
|
57
|
+
const config = this.config;
|
|
58
|
+
const offsetStartdelay = options?.offsetStartdelay || config.offsetStartdelay || 120; //start with 1 min passed to get the first ad to show faster
|
|
59
|
+
const delayBetweenAds = options?.delayBetweenAds || config.delayBetweenAds || 240; //check for 240 (4 min) seconds passed was 180
|
|
60
|
+
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
|
|
61
|
+
|
|
62
|
+
//1. only allow ad to be shown/loaded once every 150 second (Advertisement.delayBetweenAds)
|
|
63
|
+
//2. check if over 20 min, may have not been in the app and reopened it with out restarting
|
|
64
|
+
//3. load ad ether way
|
|
65
|
+
//4. show ad if conditions met
|
|
66
|
+
|
|
67
|
+
let readyToShowAd = false;
|
|
68
|
+
|
|
69
|
+
//reset timer
|
|
70
|
+
if (this.lastShownInterstitial === null) {
|
|
71
|
+
this.lastShownInterstitial = Date.now();//now
|
|
72
|
+
//add start offset delay
|
|
73
|
+
const newDate = new Date();
|
|
74
|
+
newDate.setSeconds(newDate.getSeconds() - offsetStartdelay);
|
|
75
|
+
this.lastShownInterstitial = newDate;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const secondsSinceLastAd = (Date.now() - this.lastShownInterstitial) / 1000;
|
|
79
|
+
|
|
80
|
+
//check for delayBetweenAds seconds passed
|
|
81
|
+
if (secondsSinceLastAd > delayBetweenAds) {
|
|
82
|
+
readyToShowAd = true;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
//check if over 20 min, may have not been in the app and reopened it with out restarting
|
|
86
|
+
if (secondsSinceLastAd > awayResetTime) {
|
|
87
|
+
readyToShowAd = false;
|
|
88
|
+
this.lastShownInterstitial = Date.now();//now, reset
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
console.log('readyToShowInterstitialAd: ' + readyToShowAd + ' : ' + secondsSinceLastAd + ' of ' + delayBetweenAds);
|
|
92
|
+
|
|
93
|
+
// show ad or just load ad (not load and show)
|
|
94
|
+
if (readyToShowAd) {
|
|
95
|
+
await this.showInterstitialAd();
|
|
96
|
+
} else {
|
|
97
|
+
await this.loadInterstitialAd();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async showAppOpenAdWithMaxDelay(maxDelay) {
|
|
102
|
+
if (this.isSetUp === false) { return; }
|
|
103
|
+
if (this.adProvider == null) { return; }
|
|
104
|
+
|
|
105
|
+
if (!maxDelay) {
|
|
106
|
+
maxDelay = 4000;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
//get start time
|
|
110
|
+
const startTime = Date.now();
|
|
111
|
+
if (this.loadAppOpenAd) {
|
|
112
|
+
await this.loadAppOpenAd();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
//this wont work...
|
|
116
|
+
//is timer over maxDelay
|
|
117
|
+
const timePassed = Date.now() - startTime;
|
|
118
|
+
if (timePassed > maxDelay) {
|
|
119
|
+
console.log(`showAppOpenAdWithMaxDelay took too long to load [${timePassed}ms/${maxDelay}ms], skipping ad`);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (this.showAppOpenAd) {
|
|
124
|
+
await this.showAppOpenAd();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
52
127
|
}
|
package/lib/CrazyGamesPortal.js
CHANGED
|
@@ -245,7 +245,7 @@ export class CrazyGamesPortal extends BasePortal {
|
|
|
245
245
|
return this.isCrazyGames();
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
-
async
|
|
248
|
+
async loadInterstitialAd() {
|
|
249
249
|
console.log('CrazyGames.loadAd');
|
|
250
250
|
|
|
251
251
|
if (!this.isCrazyGames()) {
|
|
@@ -257,7 +257,7 @@ export class CrazyGamesPortal extends BasePortal {
|
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
259
|
|
|
260
|
-
async
|
|
260
|
+
async showInterstitialAd() {
|
|
261
261
|
console.log('CrazyGames.showAd');
|
|
262
262
|
|
|
263
263
|
if (!this.isCrazyGames()) {
|
package/lib/FacebookPortal.js
CHANGED
|
@@ -159,25 +159,25 @@ export class FacebookPortal extends BasePortal {
|
|
|
159
159
|
this._errorCount = (this._errorCount || 0) + 1;
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
|
|
163
|
-
console.log('FB_Ads.
|
|
162
|
+
loadInterstitialAd(force) {
|
|
163
|
+
console.log('FB_Ads.loadInterstitialAd');
|
|
164
164
|
|
|
165
165
|
if (typeof FBInstant === 'undefined' || !globalThis.FBInstant) {
|
|
166
166
|
console.log('FBInstant plugin not ready'); return false;
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
if (!force && this._isAdLoading) {
|
|
170
|
-
console.log('FBInstant.
|
|
170
|
+
console.log('FBInstant.loadInterstitialAd() - _isAdLoading = true');
|
|
171
171
|
return true;
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
if (!force && this._isAdLoaded) {
|
|
175
|
-
console.log('FBInstant.
|
|
175
|
+
console.log('FBInstant.loadInterstitialAd() - _isAdLoaded = true');
|
|
176
176
|
return true;
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
if (!force && this.isErrorState()) {
|
|
180
|
-
console.log('FBInstant.
|
|
180
|
+
console.log('FBInstant.loadInterstitialAd() - ErrorState = true');
|
|
181
181
|
return true;
|
|
182
182
|
}
|
|
183
183
|
|
|
@@ -228,27 +228,27 @@ export class FacebookPortal extends BasePortal {
|
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
-
|
|
232
|
-
console.log('FB_Ads.
|
|
231
|
+
showInterstitialAd() {
|
|
232
|
+
console.log('FB_Ads.showInterstitialAd');
|
|
233
233
|
|
|
234
234
|
if (typeof FBInstant === 'undefined' || !globalThis.FBInstant) {
|
|
235
235
|
console.log('FBInstant plugin not ready'); return false;
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
if (this.isErrorState()) {
|
|
239
|
-
console.log('FBInstant.
|
|
239
|
+
console.log('FBInstant.showInterstitialAd() - ErrorState = true');
|
|
240
240
|
return true;
|
|
241
241
|
}
|
|
242
242
|
|
|
243
243
|
const isAdLoaded = this._isAdLoaded;
|
|
244
244
|
|
|
245
245
|
if (!isAdLoaded) {
|
|
246
|
-
this.
|
|
246
|
+
this.loadInterstitialAd();
|
|
247
247
|
}
|
|
248
248
|
|
|
249
249
|
if (isAdLoaded) {
|
|
250
250
|
if (!this.preloadedInterstitial) {
|
|
251
|
-
console.log('FBInstant.
|
|
251
|
+
console.log('FBInstant.showInterstitialAd() - error: preloadedInterstitial = null');
|
|
252
252
|
return false;
|
|
253
253
|
}
|
|
254
254
|
|
|
@@ -273,11 +273,11 @@ export class FacebookPortal extends BasePortal {
|
|
|
273
273
|
|
|
274
274
|
}
|
|
275
275
|
|
|
276
|
-
|
|
276
|
+
loadAndShowInterstitialAd() {
|
|
277
277
|
console.log('FB_Ads.showAd');
|
|
278
278
|
|
|
279
279
|
if (this.isErrorState()) {
|
|
280
|
-
console.log('FBInstant.
|
|
280
|
+
console.log('FBInstant.loadAndShowInterstitialAd() - isErrorState = true');
|
|
281
281
|
return true;
|
|
282
282
|
}
|
|
283
283
|
|
|
@@ -51,7 +51,7 @@ export class GameDistribution extends BasePortal {
|
|
|
51
51
|
return true;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
async
|
|
54
|
+
async loadInterstitialAd() {
|
|
55
55
|
if (!this.isReady()) {
|
|
56
56
|
return false;
|
|
57
57
|
}
|
|
@@ -64,7 +64,7 @@ export class GameDistribution extends BasePortal {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
async
|
|
67
|
+
async showInterstitialAd() {
|
|
68
68
|
if (!this.isReady()) {
|
|
69
69
|
return false;
|
|
70
70
|
}
|
|
@@ -80,7 +80,7 @@ export class GameDistribution extends BasePortal {
|
|
|
80
80
|
return this.isRewardedAdReady;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
loadRewardedAd() {
|
|
83
|
+
async loadRewardedAd() {
|
|
84
84
|
if (!this.isReady()) {
|
|
85
85
|
return false;
|
|
86
86
|
}
|
package/lib/PokiPortal.js
CHANGED
|
@@ -182,11 +182,11 @@ export class PokiPortal extends BasePortal {
|
|
|
182
182
|
return true;
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
async
|
|
185
|
+
async loadInterstitialAd() {
|
|
186
186
|
// Poki commercial breaks do not require manual preloading
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
-
async
|
|
189
|
+
async showInterstitialAd() {
|
|
190
190
|
if (!this.isReady()) {
|
|
191
191
|
return false;
|
|
192
192
|
}
|
package/lib/WebPortal.js
CHANGED
|
@@ -115,11 +115,11 @@ export class WebPortal extends BasePortal {
|
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
|
|
118
|
+
loadInterstitialAd() {
|
|
119
119
|
console.log('GoogleH5.loadAd');
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
showInterstitialAd() {
|
|
123
123
|
console.log('GoogleH5.showAd');
|
|
124
124
|
|
|
125
125
|
if (typeof adBreak === 'undefined' || !globalThis.adBreak) {
|