@cardsjd/portal 0.1.3 → 0.1.5

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
@@ -1,11 +1,10 @@
1
- import { Advertisement } from './Advertisement.js';
2
1
  export class BasePortal {
3
2
 
4
3
  async init() { }
5
4
 
6
5
  async load() { }
7
6
 
8
- async save(data, forceSave) { }
7
+ async save(_data, _forceSave) { }
9
8
 
10
9
  async delete() { }
11
10
 
@@ -21,26 +20,17 @@ export class BasePortal {
21
20
 
22
21
  async getInvite() { }
23
22
 
24
- async inviteSend(user, room) { }
23
+ async inviteSend(_user, _room) { }
25
24
 
26
- async findAndInvite(userFrom, room) { }
25
+ async findAndInvite(_userFrom, _room) { }
27
26
 
28
27
  async getFriends() { }
29
28
 
30
- tryShowInterstitialAd(options) {
31
- const readyToShowAd = Advertisement.isInterstitialAdReady(options);
32
- if (readyToShowAd) {
33
- this.showInterstitialAd();
34
- } else {
35
- this.loadInterstitialAd();
36
- }
37
- }
38
-
39
29
  setupAds() { }
40
30
 
41
- loadInterstitialAd(_force) { }
31
+ async loadInterstitialAd(_force) { }
42
32
 
43
- showInterstitialAd() { }
33
+ async showInterstitialAd() { }
44
34
 
45
35
  loadRewardedAd(_onLoaded) { }
46
36
 
@@ -48,7 +38,7 @@ export class BasePortal {
48
38
 
49
39
  loadAppOpenAd() { }
50
40
 
51
- showAppOpenAd(maxDelay) { }
41
+ async showAppOpenAd(_maxDelay) { }
52
42
 
53
43
  isAdLoaded() { }
54
44
 
@@ -59,4 +49,8 @@ export class BasePortal {
59
49
  isErrorState() { }
60
50
 
61
51
  createShortCut() { }
52
+
53
+ async tryShowInterstitialAd(options) {
54
+
55
+ }
62
56
  }
@@ -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.3",
4
+ "version": "0.1.5",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "publishConfig": {
@@ -1,99 +0,0 @@
1
- export class Advertisement {
2
- isInterstitialAdReady(options) {
3
- //only load/show if ads enabled
4
- if (this.isSetup === false) { return; }
5
-
6
- const config = this.config;
7
- const offsetStartdelay = options?.offsetStartdelay || config.offsetStartdelay || 120; //start with 1 min passed to get the first ad to show faster
8
- const delayBetweenAds = options?.delayBetweenAds || config.delayBetweenAds || 240; //check for 240 (4 min) seconds passed was 180
9
- 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
10
- const delayBetweenRewardedAds = options?.delayBetweenRewardedAds || config.delayBetweenRewardedAds || 300; //check for 600 seconds passed
11
-
12
-
13
- //0. if ads removed, dont even load the ad
14
- //1. only allow ad to be shown/loaded once every 150 second (Advertisement.delayBetweenAds)
15
- //2. check if over 20 min, may have not been in the app and reopened it with out restarting
16
- //3. load ad ether way
17
- //4. show ad if conditions met
18
- if (this.removeAds) { return false; }
19
-
20
- let readyToShowAd = false;
21
-
22
- //reset timer
23
- if (this.lastShownInterstitial === null) {
24
- this.lastShownInterstitial = Date.now();//now
25
- //add start offset delay
26
- const newDate = new Date();
27
- newDate.setSeconds(newDate.getSeconds() - offsetStartdelay);
28
- this.lastShownInterstitial = newDate;
29
- }
30
-
31
- const secondsSinceLastAd = (Date.now() - this.lastShownInterstitial) / 1000;
32
-
33
- //check for delayBetweenAds seconds passed
34
- if (secondsSinceLastAd > delayBetweenAds) {
35
- readyToShowAd = true;
36
- }
37
-
38
- //check if over 20 min, may have not been in the app and reopened it with out restarting
39
- if (secondsSinceLastAd > awayResetTime) {
40
- readyToShowAd = false;
41
- this.lastShownInterstitial = Date.now();//now, reset
42
- }
43
-
44
- console.log('readyToShowInterstitialAd: ' + readyToShowAd + ' : ' + secondsSinceLastAd + ' of ' + delayBetweenAds);
45
-
46
- // show ad or just load ad
47
- if (readyToShowAd) {
48
- true;
49
- } else {
50
- false;
51
- }
52
- }
53
- async showAppOpenAdWithMaxDelay(maxDelay) {
54
- if (this.isSetUp === false) { return; }
55
- if (this.adProvider == null) { return; }
56
-
57
-
58
-
59
- if (!maxDelay) {
60
- maxDelay = 4000;
61
- }
62
-
63
- //todo: fix if long loader time than maxDelay, then skip ad
64
- //something like this:
65
- //return new Promise(async (resolve, reject) => {
66
- // if (this.adProvider && this.adProvider.showAppOpenAd) {
67
- // timeoutPromise = setTimeout(() => {
68
- // //stop ad from showing
69
- // if (this.adProvider) this.adProvider.appOpenAdAutoShow = false;
70
- // reject(new Error('showAppOpenAd has not fired after 4 seconds. Skipping ad'));
71
- // }, maxDelay);
72
- // await this.adProvider.showAppOpenAd();
73
- // clearTimeout(timeoutPromise);
74
- // resolve();
75
- // }
76
- // else {
77
- // reject();
78
- // }
79
-
80
-
81
- //get start time
82
- const startTime = Date.now();
83
- if (this.adProvider.loadAppOpenAd) {
84
- await this.adProvider.loadAppOpenAd();
85
- }
86
-
87
- //this wont work...
88
- //is timer over maxDelay
89
- const timePassed = Date.now() - startTime;
90
- if (timePassed > maxDelay) {
91
- console.log(`showAppOpenAdWithMaxDelay took too long to load [${timePassed}ms/${maxDelay}ms], skipping ad`);
92
- return;
93
- }
94
-
95
- if (this.adProvider.showAppOpenAd) {
96
- await this.adProvider.showAppOpenAd();
97
- }
98
- }
99
- }