@cardsjd/portal 0.1.8 → 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.
@@ -179,9 +179,7 @@ export class AdMobPortal extends BasePortal {
179
179
  }
180
180
 
181
181
  async showRewardedAd() {
182
- if (this.isSetup === false) {
183
- return;
184
- }
182
+ await this.setupAds();
185
183
 
186
184
  if (!this.isRewardedAdLoaded()) {
187
185
  await this.loadRewardedAd();
package/lib/BasePortal.js CHANGED
@@ -51,8 +51,7 @@ export class BasePortal {
51
51
  createShortCut() { }
52
52
 
53
53
  async tryShowInterstitialAd(options) {
54
- //only load/show if ads enabled
55
- if (this.isSetup === false) { return; }
54
+ await this.setupAds();
56
55
 
57
56
  const config = this.config || {};
58
57
  const offsetStartdelay = options?.offsetStartdelay || config.offsetStartdelay || 120; //start with 1 min passed to get the first ad to show faster
@@ -98,8 +97,7 @@ export class BasePortal {
98
97
  }
99
98
  }
100
99
  async showAppOpenAdWithMaxDelay(maxDelay) {
101
- if (this.isSetUp === false) { return; }
102
-
100
+ await this.setupAds();
103
101
 
104
102
  if (!maxDelay) {
105
103
  maxDelay = 4000;
@@ -317,9 +317,7 @@ export class CrazyGamesPortal extends BasePortal {
317
317
  return false;
318
318
  }
319
319
 
320
- if (!this.isSetup) {
321
- await this.setupAds();
322
- }
320
+ await this.setupAds();
323
321
 
324
322
  const adType = 'rewarded';
325
323
  const adProvider = this.adProviderName;
@@ -407,9 +407,11 @@ export class FacebookPortal extends BasePortal {
407
407
 
408
408
  }
409
409
 
410
- showRewardedAd() {
410
+ async showRewardedAd() {
411
411
  console.log('FB_Ads.ShowRewardedAd');
412
412
 
413
+ await this.setupAds();
414
+
413
415
  if (this.isErrorState()) {
414
416
  console.log('FBInstant.ShowRewardedAd() - isErrorState = true');
415
417
  return true;
@@ -97,11 +97,13 @@ export class GameDistribution extends BasePortal {
97
97
  })();
98
98
  }
99
99
 
100
- showRewardedAd() {
100
+ async showRewardedAd() {
101
101
  if (!this.isReady()) {
102
102
  return false;
103
103
  }
104
104
 
105
+ await this.setupAds();
106
+
105
107
  return globalThis.gdsdk.showAd(AdType.Rewarded);
106
108
  }
107
109
  }
package/lib/PokiPortal.js CHANGED
@@ -245,6 +245,8 @@ export class PokiPortal extends BasePortal {
245
245
  return false;
246
246
  }
247
247
 
248
+ await this.setupAds();
249
+
248
250
  const adType = 'rewarded';
249
251
  const adProvider = this.adProviderName;
250
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,28 +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('GoogleH5.isSetup is already done');
53
- return;
54
- }
55
- if (this.isSetupLoading) {
56
- throw Error('GoogleH5 setup is in progress already');
57
- }
58
-
59
- this.isSetupLoading = true; //prevent async loading
60
-
61
- try {
62
- await this.loadScript();
63
- console.log('adsbygoogle loaded');
64
- } catch (error) {
65
- console.log(error);
66
- return;
67
- }
68
-
69
- if (typeof adConfig === 'undefined') {
70
- console.log('GoogleH5 adBreak plugin not ready');
71
- throw Error('GoogleH5 adBreak plugin not ready');
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');
72
79
  }
73
80
 
74
81
  globalThis.adConfig({
@@ -77,10 +84,9 @@ export class WebPortal extends BasePortal {
77
84
  onReady: () => {
78
85
  console.log('GoogleH5.isSetup is ready');
79
86
  },
80
- });
81
- this.isSetup = true;
82
- this.isSetupLoading = false;
83
- }
87
+ });
88
+ this.isSetup = true;
89
+ }
84
90
 
85
91
  async loadScript() {
86
92
  return new Promise((resolve, reject) => {
@@ -114,10 +120,11 @@ export class WebPortal extends BasePortal {
114
120
  });
115
121
  }
116
122
 
117
- loadInterstitialAd() {
118
- console.log('GoogleH5.loadAd');
119
- }
120
- showInterstitialAd() {
123
+ loadInterstitialAd() {
124
+ console.log('GoogleH5.loadAd');
125
+ }
126
+
127
+ showInterstitialAd() {
121
128
  console.log('GoogleH5.showAd');
122
129
 
123
130
  if (typeof adBreak === 'undefined' || !globalThis.adBreak) {
@@ -162,9 +169,11 @@ export class WebPortal extends BasePortal {
162
169
  return true;
163
170
  }
164
171
 
165
- showRewardedAd() {
172
+ async showRewardedAd() {
166
173
  console.log('GoogleH5.ShowRewardedAd');
167
174
 
175
+ await this.setupAds();
176
+
168
177
  if (typeof globalThis.adBreak === 'undefined' || !globalThis.adBreak) {
169
178
  console.log('GoogleH5 adBreak plugin not ready'); return;
170
179
  }
@@ -253,4 +262,4 @@ export class WebPortal extends BasePortal {
253
262
  return adStatus;
254
263
  }
255
264
 
256
- }
265
+ }
package/package.json CHANGED
@@ -1,23 +1,24 @@
1
1
  {
2
2
  "name": "@cardsjd/portal",
3
- "private": false,
4
- "version": "0.1.8",
5
- "type": "module",
6
- "main": "lib/index.js",
7
- "publishConfig": {
8
- "access": "public"
9
- },
10
- "files": [
11
- "lib"
12
- ],
13
- "scripts": {
14
- "lint": "eslint lib --report-unused-disable-directives --max-warnings 0",
15
- "lint:fix": "npm run lint -- --fix"
16
- },
17
- "devDependencies": {},
18
- "dependencies": {
19
- "@capacitor-community/admob": "^7.0.3",
20
- "@discord/embedded-app-sdk": "^2.4.0"
21
- },
22
- "peerDependencies": {}
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
  }