@cardsjd/portal 0.1.4 → 0.1.6

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.
@@ -153,7 +153,53 @@ 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 === null) {
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);
156
195
 
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
+ }
157
203
  async showInterstitialAd() {
158
204
  if (!this.isAdLoaded()) {
159
205
  await this.loadInterstitialAd();
package/lib/BasePortal.js CHANGED
@@ -50,78 +50,10 @@ export class BasePortal {
50
50
 
51
51
  createShortCut() { }
52
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
- }
53
+ async tryShowInterstitialAd(_options) {
54
+
99
55
  }
56
+ async showAppOpenAdWithMaxDelay(_maxDelay) {
100
57
 
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
58
  }
127
59
  }
@@ -256,7 +256,53 @@ 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; }
259
262
 
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 === null) {
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
+ }
260
306
  async showInterstitialAd() {
261
307
  console.log('CrazyGames.showAd');
262
308
 
@@ -227,7 +227,53 @@ export class FacebookPortal extends BasePortal {
227
227
  console.error('FB_Ads.getInterstitialAdAsync error: ' + ex);
228
228
  }
229
229
  }
230
+ async tryShowInterstitialAd(options) {
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 === null) {
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;
230
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
+ }
231
277
  showInterstitialAd() {
232
278
  console.log('FB_Ads.showInterstitialAd');
233
279
 
@@ -63,7 +63,53 @@ 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 === null) {
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;
66
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
+
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
+ }
67
113
  async showInterstitialAd() {
68
114
  if (!this.isReady()) {
69
115
  return false;
package/lib/PokiPortal.js CHANGED
@@ -185,7 +185,53 @@ 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 === null) {
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;
188
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
+
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
+ }
189
235
  async showInterstitialAd() {
190
236
  if (!this.isReady()) {
191
237
  return false;
package/lib/WebPortal.js CHANGED
@@ -118,7 +118,53 @@ export class WebPortal extends BasePortal {
118
118
  loadInterstitialAd() {
119
119
  console.log('GoogleH5.loadAd');
120
120
  }
121
+ async tryShowInterstitialAd(options) {
122
+ //only load/show if ads enabled
123
+ if (this.isSetup === false) { return; }
124
+
125
+ const config = this.config;
126
+ const offsetStartdelay = options?.offsetStartdelay || config.offsetStartdelay || 120; //start with 1 min passed to get the first ad to show faster
127
+ const delayBetweenAds = options?.delayBetweenAds || config.delayBetweenAds || 240; //check for 240 (4 min) seconds passed was 180
128
+ 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
129
+
130
+ //1. only allow ad to be shown/loaded once every 150 second (Advertisement.delayBetweenAds)
131
+ //2. check if over 20 min, may have not been in the app and reopened it with out restarting
132
+ //3. load ad ether way
133
+ //4. show ad if conditions met
134
+
135
+ let readyToShowAd = false;
136
+
137
+ //reset timer
138
+ if (this.lastShownInterstitial === null) {
139
+ this.lastShownInterstitial = Date.now();//now
140
+ //add start offset delay
141
+ const newDate = new Date();
142
+ newDate.setSeconds(newDate.getSeconds() - offsetStartdelay);
143
+ this.lastShownInterstitial = newDate;
144
+ }
145
+
146
+ const secondsSinceLastAd = (Date.now() - this.lastShownInterstitial) / 1000;
121
147
 
148
+ //check for delayBetweenAds seconds passed
149
+ if (secondsSinceLastAd > delayBetweenAds) {
150
+ readyToShowAd = true;
151
+ }
152
+
153
+ //check if over 20 min, may have not been in the app and reopened it with out restarting
154
+ if (secondsSinceLastAd > awayResetTime) {
155
+ readyToShowAd = false;
156
+ this.lastShownInterstitial = Date.now();//now, reset
157
+ }
158
+
159
+ console.log('readyToShowInterstitialAd: ' + readyToShowAd + ' : ' + secondsSinceLastAd + ' of ' + delayBetweenAds);
160
+
161
+ // show ad or just load ad (not load and show)
162
+ if (readyToShowAd) {
163
+ await this.showInterstitialAd();
164
+ } else {
165
+ await this.loadInterstitialAd();
166
+ }
167
+ }
122
168
  showInterstitialAd() {
123
169
  console.log('GoogleH5.showAd');
124
170
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cardsjd/portal",
3
3
  "private": false,
4
- "version": "0.1.4",
4
+ "version": "0.1.6",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "publishConfig": {