@cardsjd/portal 0.1.8 → 0.1.10
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/README.md +0 -0
- package/lib/AdMobPortal.js +1 -3
- package/lib/AndroidPortal.js +3 -14
- package/lib/BasePortal.js +11 -7
- package/lib/CrazyGamesPortal.js +1 -3
- package/lib/FacebookPortal.js +21 -14
- package/lib/GameDistributionPortal.js +3 -1
- package/lib/NextGenAdMobPortal.js +402 -0
- package/lib/PokiPortal.js +2 -0
- package/lib/WebPortal.js +45 -36
- package/lib/iOSPortal.js +31 -7
- package/package.json +38 -21
package/README.md
CHANGED
|
Binary file
|
package/lib/AdMobPortal.js
CHANGED
package/lib/AndroidPortal.js
CHANGED
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NextGenAdMobPortal } from './NextGenAdMobPortal.js';
|
|
2
2
|
|
|
3
|
-
export class AndroidPortal extends
|
|
3
|
+
export class AndroidPortal extends NextGenAdMobPortal {
|
|
4
4
|
name = 'AndroidPortal';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
const configToUpdate = structuredClone(config);
|
|
8
|
-
|
|
9
|
-
// Map android-specific ad config items to generic "ad" config items
|
|
10
|
-
configToUpdate.interstitialAdId = adConfig.admobInterstitialAdId_Android;
|
|
11
|
-
configToUpdate.rewardedAdId = adConfig.admobRewardedAdId_Android;
|
|
12
|
-
configToUpdate.appOpenAdId = adConfig.admobAppOpenAdId_Android;
|
|
13
|
-
configToUpdate.appId = adConfig.admobAppId_Android;
|
|
14
|
-
|
|
15
|
-
return configToUpdate;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
6
|
+
}
|
package/lib/BasePortal.js
CHANGED
|
@@ -42,17 +42,22 @@ export class BasePortal {
|
|
|
42
42
|
|
|
43
43
|
isAdLoaded() { }
|
|
44
44
|
|
|
45
|
-
isRewardedAdLoaded() { }
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
isRewardedAdLoaded() { }
|
|
46
|
+
|
|
47
|
+
isPrivacyOptionsRequired() {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async showPrivacyOptions() { }
|
|
52
|
+
|
|
53
|
+
logError(_errorCode) { }
|
|
48
54
|
|
|
49
55
|
isErrorState() { }
|
|
50
56
|
|
|
51
57
|
createShortCut() { }
|
|
52
58
|
|
|
53
59
|
async tryShowInterstitialAd(options) {
|
|
54
|
-
|
|
55
|
-
if (this.isSetup === false) { return; }
|
|
60
|
+
await this.setupAds();
|
|
56
61
|
|
|
57
62
|
const config = this.config || {};
|
|
58
63
|
const offsetStartdelay = options?.offsetStartdelay || config.offsetStartdelay || 120; //start with 1 min passed to get the first ad to show faster
|
|
@@ -98,8 +103,7 @@ export class BasePortal {
|
|
|
98
103
|
}
|
|
99
104
|
}
|
|
100
105
|
async showAppOpenAdWithMaxDelay(maxDelay) {
|
|
101
|
-
|
|
102
|
-
|
|
106
|
+
await this.setupAds();
|
|
103
107
|
|
|
104
108
|
if (!maxDelay) {
|
|
105
109
|
maxDelay = 4000;
|
package/lib/CrazyGamesPortal.js
CHANGED
package/lib/FacebookPortal.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BasePortal } from './BasePortal';
|
|
1
|
+
import { BasePortal } from './BasePortal';
|
|
2
2
|
import { FBInstantGame } from '@cardsjd/fbinstantgame';
|
|
3
3
|
|
|
4
4
|
export class FacebookPortal extends BasePortal {
|
|
@@ -32,15 +32,20 @@ export class FacebookPortal extends BasePortal {
|
|
|
32
32
|
|
|
33
33
|
async load() {
|
|
34
34
|
const fbUserdata = await this.fBInstantGame.loadData();
|
|
35
|
-
const fbProfile = await this.fBInstantGame.getProfile();
|
|
36
|
-
const data = {};
|
|
37
|
-
data.userdata = fbUserdata;
|
|
38
|
-
data.user = fbProfile
|
|
35
|
+
const fbProfile = await this.fBInstantGame.getProfile();
|
|
36
|
+
const data = {};
|
|
37
|
+
data.userdata = fbUserdata;
|
|
38
|
+
data.user = fbProfile ? {
|
|
39
|
+
facebookId: fbProfile.facebookId ?? fbProfile.id,
|
|
40
|
+
name: fbProfile.name,
|
|
41
|
+
avatar: fbProfile.avatar ?? fbProfile.pic,
|
|
42
|
+
locale: fbProfile.locale,
|
|
43
|
+
} : null;
|
|
39
44
|
return data;
|
|
40
45
|
}
|
|
41
46
|
|
|
42
|
-
async save(data, forceSave) {
|
|
43
|
-
this.fBInstantGame.saveData(data, forceSave).catch(function () { });
|
|
47
|
+
async save(data, forceSave) {
|
|
48
|
+
this.fBInstantGame.saveData(data, forceSave).catch(function () { });
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
gameStart() {
|
|
@@ -60,10 +65,10 @@ export class FacebookPortal extends BasePortal {
|
|
|
60
65
|
|
|
61
66
|
this.subscribeBot();
|
|
62
67
|
}
|
|
63
|
-
createShortCut() {
|
|
64
|
-
this.portal?.createShortCut?.();
|
|
65
|
-
}
|
|
66
|
-
async subscribeBot() {
|
|
68
|
+
createShortCut() {
|
|
69
|
+
this.portal?.createShortCut?.();
|
|
70
|
+
}
|
|
71
|
+
async subscribeBot() {
|
|
67
72
|
await this.fBInstantGame.subscribeBot();
|
|
68
73
|
}
|
|
69
74
|
|
|
@@ -183,7 +188,7 @@ export class FacebookPortal extends BasePortal {
|
|
|
183
188
|
|
|
184
189
|
this._isAdLoading = true;
|
|
185
190
|
|
|
186
|
-
const interstitialAdId = this.appConfig?.
|
|
191
|
+
const interstitialAdId = this.appConfig?.interstitialAdId;
|
|
187
192
|
|
|
188
193
|
console.log('FB_Ads.getInterstitialAdAsync start: ' + interstitialAdId);
|
|
189
194
|
if (!this.isApiSupported('getInterstitialAdAsync')) {
|
|
@@ -285,7 +290,7 @@ export class FacebookPortal extends BasePortal {
|
|
|
285
290
|
console.log('FBInstant plugin not ready'); return false;
|
|
286
291
|
}
|
|
287
292
|
|
|
288
|
-
const interstitialAdId = this.appConfig?.
|
|
293
|
+
const interstitialAdId = this.appConfig?.interstitialAdId;
|
|
289
294
|
if (!this.isApiSupported('getInterstitialAdAsync')) {
|
|
290
295
|
this.logError('CLIENT_UNSUPPORTED_OPERATION');
|
|
291
296
|
console.warn('FBInstant.getInterstitialAdAsync is not supported on this client');
|
|
@@ -407,9 +412,11 @@ export class FacebookPortal extends BasePortal {
|
|
|
407
412
|
|
|
408
413
|
}
|
|
409
414
|
|
|
410
|
-
showRewardedAd() {
|
|
415
|
+
async showRewardedAd() {
|
|
411
416
|
console.log('FB_Ads.ShowRewardedAd');
|
|
412
417
|
|
|
418
|
+
await this.setupAds();
|
|
419
|
+
|
|
413
420
|
if (this.isErrorState()) {
|
|
414
421
|
console.log('FBInstant.ShowRewardedAd() - isErrorState = true');
|
|
415
422
|
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
|
}
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import { BasePortal } from './BasePortal.js';
|
|
2
|
+
|
|
3
|
+
export class NextGenAdMobPortal extends BasePortal {
|
|
4
|
+
name = 'NextGenAdMobPortal';
|
|
5
|
+
autoLogin = false;
|
|
6
|
+
|
|
7
|
+
constructor(appConfig) {
|
|
8
|
+
super();
|
|
9
|
+
this.appConfig = appConfig;
|
|
10
|
+
|
|
11
|
+
// Ad callback properties
|
|
12
|
+
this.onAdLoaded = null;
|
|
13
|
+
this.onAdOpened = null;
|
|
14
|
+
this.onAdClosed = null;
|
|
15
|
+
this.onAdError = null;
|
|
16
|
+
this.onAdRewarded = null;
|
|
17
|
+
this.onBeforeTrackingAuthorization = null;
|
|
18
|
+
this.onPrivacyOptionsRequirementChanged = null;
|
|
19
|
+
|
|
20
|
+
this.adProviderName = 'CapgoAdmob';
|
|
21
|
+
this.isSetup = false;
|
|
22
|
+
this.isSetupLoading = false;
|
|
23
|
+
this.isInterstitialAdReady = false;
|
|
24
|
+
this._isRewardedAdLoaded = false;
|
|
25
|
+
this._receivedReward = false;
|
|
26
|
+
this._rewardInfo = null;
|
|
27
|
+
this._interstitialAd = null;
|
|
28
|
+
this._interstitialLoadPromise = null;
|
|
29
|
+
this._rewardedAd = null;
|
|
30
|
+
this._adMobModule = null;
|
|
31
|
+
this._umpModule = null;
|
|
32
|
+
this._consentInfoUpdated = false;
|
|
33
|
+
this._consentGathered = false;
|
|
34
|
+
this._canRequestAds = false;
|
|
35
|
+
this._privacyOptionsRequired = false;
|
|
36
|
+
this.isTesting = false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async getAdMob() {
|
|
40
|
+
if (!this._adMobModule) {
|
|
41
|
+
// eslint-disable-next-line import/no-unresolved
|
|
42
|
+
this._adMobModule = await import('@capgo/capacitor-admob');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return this._adMobModule;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async getUmp() {
|
|
49
|
+
if (!this._umpModule) {
|
|
50
|
+
// eslint-disable-next-line import/no-unresolved
|
|
51
|
+
const { GoogleUmpConsent } = await import('@cardsjd/google-ump');
|
|
52
|
+
this._umpModule = GoogleUmpConsent;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return this._umpModule;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async requestTrackingAuthorization(_consentInfo) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async canStartAdsWithoutPrompt() {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
setConsentInfo(consentInfo) {
|
|
67
|
+
const wasRequired = this._privacyOptionsRequired;
|
|
68
|
+
if (typeof consentInfo?.canRequestAds === 'boolean') {
|
|
69
|
+
this._canRequestAds = consentInfo.canRequestAds;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
this._privacyOptionsRequired = consentInfo?.privacyOptionsRequired === true;
|
|
73
|
+
|
|
74
|
+
if (
|
|
75
|
+
wasRequired !== this._privacyOptionsRequired &&
|
|
76
|
+
this.onPrivacyOptionsRequirementChanged
|
|
77
|
+
) {
|
|
78
|
+
this.onPrivacyOptionsRequirementChanged(this._privacyOptionsRequired);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
isPrivacyOptionsRequired() {
|
|
83
|
+
return this._privacyOptionsRequired;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async showPrivacyOptions() {
|
|
87
|
+
const ump = await this.getUmp();
|
|
88
|
+
const consentInfo = await ump.showPrivacyOptions();
|
|
89
|
+
this.setConsentInfo(consentInfo);
|
|
90
|
+
return consentInfo;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async updateConsentInfo() {
|
|
94
|
+
const ump = await this.getUmp();
|
|
95
|
+
const consentInfo = await ump.updateConsentInfo();
|
|
96
|
+
this._consentInfoUpdated = true;
|
|
97
|
+
this.setConsentInfo(consentInfo);
|
|
98
|
+
return consentInfo;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async gatherConsent() {
|
|
102
|
+
const ump = await this.getUmp();
|
|
103
|
+
const consentInfo = await ump.gatherConsent();
|
|
104
|
+
this._consentInfoUpdated = true;
|
|
105
|
+
this._consentGathered = true;
|
|
106
|
+
this.setConsentInfo(consentInfo);
|
|
107
|
+
return consentInfo;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
getAdError(info, fallbackMessage) {
|
|
111
|
+
return new Error(info?.error?.message || info?.message || fallbackMessage);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// ----- Ad methods -----
|
|
115
|
+
|
|
116
|
+
async setupAds() {
|
|
117
|
+
if (this.isSetup || this._consentInfoUpdated) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (this.isSetupLoading) {
|
|
122
|
+
throw Error('Capgo AdMob setup is in progress already');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
this.isSetupLoading = true;
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
await this.updateConsentInfo();
|
|
129
|
+
} catch (error) {
|
|
130
|
+
console.error('Failed to update UMP consent info:', error);
|
|
131
|
+
} finally {
|
|
132
|
+
this.isSetupLoading = false;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async ensureAdsReady() {
|
|
137
|
+
if (this.isSetup) {
|
|
138
|
+
return {
|
|
139
|
+
canRequestAds: true,
|
|
140
|
+
promptShown: false,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
let consentInfo;
|
|
145
|
+
try {
|
|
146
|
+
if (!this._consentInfoUpdated) {
|
|
147
|
+
await this.updateConsentInfo();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
consentInfo = this._consentGathered ? {
|
|
151
|
+
canRequestAds: this._canRequestAds,
|
|
152
|
+
} : await this.gatherConsent();
|
|
153
|
+
} catch (error) {
|
|
154
|
+
if (this.onAdError) {
|
|
155
|
+
this.onAdError(error);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
canRequestAds: false,
|
|
160
|
+
promptShown: false,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const trackingPromptShown = await this.requestTrackingAuthorization(consentInfo);
|
|
165
|
+
const promptShown = consentInfo?.formShown === true || trackingPromptShown;
|
|
166
|
+
|
|
167
|
+
if (consentInfo.canRequestAds !== true) {
|
|
168
|
+
return {
|
|
169
|
+
canRequestAds: false,
|
|
170
|
+
promptShown,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
await this.startAds();
|
|
175
|
+
return {
|
|
176
|
+
canRequestAds: true,
|
|
177
|
+
promptShown,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
async prepareAdsWithoutPrompt() {
|
|
182
|
+
if (this.isSetup) {
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (!this._consentInfoUpdated) {
|
|
187
|
+
await this.setupAds();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (!this._canRequestAds || !await this.canStartAdsWithoutPrompt()) {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
await this.startAds();
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async startAds() {
|
|
199
|
+
if (this.isSetup) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (this.isSetupLoading) {
|
|
204
|
+
throw Error('Capgo AdMob setup is in progress already');
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
this.isSetupLoading = true;
|
|
208
|
+
|
|
209
|
+
try {
|
|
210
|
+
const { AdMob } = await this.getAdMob();
|
|
211
|
+
await AdMob.start();
|
|
212
|
+
|
|
213
|
+
await AdMob.addListener('interstitial.show', (info) => {
|
|
214
|
+
if (info.id === this._interstitialAd?.id) {
|
|
215
|
+
this.isInterstitialAdReady = false;
|
|
216
|
+
if (this.onAdOpened) {
|
|
217
|
+
this.onAdOpened({
|
|
218
|
+
adType: 'interstitial',
|
|
219
|
+
adProvider: this.adProviderName,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
await AdMob.addListener('interstitial.dismiss', (info) => {
|
|
225
|
+
if (info.id === this._interstitialAd?.id) {
|
|
226
|
+
this.isInterstitialAdReady = false;
|
|
227
|
+
this._interstitialAd = null;
|
|
228
|
+
if (this.onAdClosed) {
|
|
229
|
+
this.onAdClosed({
|
|
230
|
+
adType: 'interstitial',
|
|
231
|
+
adProvider: this.adProviderName,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
await AdMob.addListener('interstitial.loadfail', (info) => {
|
|
237
|
+
if (info.id === this._interstitialAd?.id) {
|
|
238
|
+
this.isInterstitialAdReady = false;
|
|
239
|
+
this._interstitialAd = null;
|
|
240
|
+
if (this.onAdError) {
|
|
241
|
+
this.onAdError(this.getAdError(info, 'InterstitialAd failed to load'));
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
await AdMob.addListener('interstitial.showfail', (info) => {
|
|
246
|
+
if (info.id === this._interstitialAd?.id) {
|
|
247
|
+
this.isInterstitialAdReady = false;
|
|
248
|
+
this._interstitialAd = null;
|
|
249
|
+
if (this.onAdError) {
|
|
250
|
+
this.onAdError(this.getAdError(info, 'InterstitialAd failed to show'));
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
await AdMob.addListener('rewarded.dismiss', (info) => {
|
|
255
|
+
if (info.id === this._rewardedAd?.id) {
|
|
256
|
+
this._isRewardedAdLoaded = false;
|
|
257
|
+
this._rewardedAd = null;
|
|
258
|
+
if (this.onAdClosed) {
|
|
259
|
+
this.onAdClosed({
|
|
260
|
+
adType: 'rewarded',
|
|
261
|
+
adProvider: this.adProviderName,
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (this._receivedReward && this.onAdRewarded) {
|
|
266
|
+
this.onAdRewarded(this._rewardInfo);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
await AdMob.addListener('rewarded.loadfail', (info) => {
|
|
271
|
+
if (info.id === this._rewardedAd?.id) {
|
|
272
|
+
this._isRewardedAdLoaded = false;
|
|
273
|
+
this._rewardedAd = null;
|
|
274
|
+
if (this.onAdError) {
|
|
275
|
+
this.onAdError(this.getAdError(info, 'RewardAd failed to load'));
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
await AdMob.addListener('rewarded.showfail', (info) => {
|
|
280
|
+
if (info.id === this._rewardedAd?.id) {
|
|
281
|
+
this._isRewardedAdLoaded = false;
|
|
282
|
+
this._rewardedAd = null;
|
|
283
|
+
if (this.onAdError) {
|
|
284
|
+
this.onAdError(this.getAdError(info, 'RewardAd failed to show'));
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
await AdMob.addListener('rewarded.reward', (info) => {
|
|
289
|
+
if (info.id === this._rewardedAd?.id) {
|
|
290
|
+
this._receivedReward = true;
|
|
291
|
+
this._rewardInfo = info.reward;
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
this.isSetup = true;
|
|
296
|
+
} finally {
|
|
297
|
+
this.isSetupLoading = false;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
isAdLoaded() {
|
|
302
|
+
return this.isInterstitialAdReady;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
isRewardedAdLoaded() {
|
|
306
|
+
return this._isRewardedAdLoaded;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
async loadInterstitialAd() {
|
|
310
|
+
if (this.isAdLoaded()) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (!this._interstitialLoadPromise) {
|
|
315
|
+
this._interstitialLoadPromise = (async () => {
|
|
316
|
+
if (!await this.prepareAdsWithoutPrompt()) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const { InterstitialAd } = await this.getAdMob();
|
|
321
|
+
this._interstitialAd = new InterstitialAd({
|
|
322
|
+
adUnitId: this.appConfig?.interstitialAdId,
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
await this._interstitialAd.load();
|
|
326
|
+
this.isInterstitialAdReady = true;
|
|
327
|
+
})();
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const loadPromise = this._interstitialLoadPromise;
|
|
331
|
+
try {
|
|
332
|
+
await loadPromise;
|
|
333
|
+
} catch (error) {
|
|
334
|
+
this._interstitialAd = null;
|
|
335
|
+
throw error;
|
|
336
|
+
} finally {
|
|
337
|
+
if (this._interstitialLoadPromise === loadPromise) {
|
|
338
|
+
this._interstitialLoadPromise = null;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
async showInterstitialAd() {
|
|
344
|
+
const setup = await this.ensureAdsReady();
|
|
345
|
+
if (!setup.canRequestAds || setup.promptShown) {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (!this.isAdLoaded()) {
|
|
350
|
+
let timeoutId;
|
|
351
|
+
await Promise.race([this.loadInterstitialAd(), new Promise(resolve => {
|
|
352
|
+
timeoutId = setTimeout(resolve, 2000);
|
|
353
|
+
})]);
|
|
354
|
+
clearTimeout(timeoutId);
|
|
355
|
+
if (!this.isAdLoaded()) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
this.isInterstitialAdReady = false;
|
|
361
|
+
return this._interstitialAd.show();
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
async loadRewardedAd() {
|
|
365
|
+
if (!await this.prepareAdsWithoutPrompt()) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (this.isRewardedAdLoaded()) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const { RewardedAd } = await this.getAdMob();
|
|
374
|
+
this._rewardedAd = new RewardedAd({
|
|
375
|
+
adUnitId: this.appConfig?.rewardedAdId,
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
try {
|
|
379
|
+
await this._rewardedAd.load();
|
|
380
|
+
this._isRewardedAdLoaded = true;
|
|
381
|
+
this._receivedReward = false;
|
|
382
|
+
this._rewardInfo = null;
|
|
383
|
+
} catch (error) {
|
|
384
|
+
this._rewardedAd = null;
|
|
385
|
+
throw error;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
async showRewardedAd() {
|
|
390
|
+
const setup = await this.ensureAdsReady();
|
|
391
|
+
if (!setup.canRequestAds || setup.promptShown) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if (!this.isRewardedAdLoaded()) {
|
|
396
|
+
await this.loadRewardedAd();
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
this._isRewardedAdLoaded = false;
|
|
400
|
+
return this._rewardedAd.show();
|
|
401
|
+
}
|
|
402
|
+
}
|
package/lib/PokiPortal.js
CHANGED
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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/lib/iOSPortal.js
CHANGED
|
@@ -1,7 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export class iOSPortal extends
|
|
4
|
-
name = 'iOSPortal';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
1
|
+
import { NextGenAdMobPortal } from './NextGenAdMobPortal.js';
|
|
2
|
+
|
|
3
|
+
export class iOSPortal extends NextGenAdMobPortal {
|
|
4
|
+
name = 'iOSPortal';
|
|
5
|
+
|
|
6
|
+
async canStartAdsWithoutPrompt() {
|
|
7
|
+
const { AdMob, TrackingAuthorizationStatus } = await this.getAdMob();
|
|
8
|
+
const trackingInfo = await AdMob.trackingAuthorizationStatus();
|
|
9
|
+
return trackingInfo.status !== TrackingAuthorizationStatus.notDetermined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async requestTrackingAuthorization(consentInfo) {
|
|
13
|
+
const { AdMob, TrackingAuthorizationStatus } = await this.getAdMob();
|
|
14
|
+
const trackingInfo = await AdMob.trackingAuthorizationStatus();
|
|
15
|
+
|
|
16
|
+
if (trackingInfo.status === TrackingAuthorizationStatus.notDetermined) {
|
|
17
|
+
// UMP reaches this fallback only when no IDFA explainer handled ATT.
|
|
18
|
+
if (this.onBeforeTrackingAuthorization) {
|
|
19
|
+
const shouldContinue = await this.onBeforeTrackingAuthorization();
|
|
20
|
+
if (shouldContinue === false) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
await AdMob.requestTrackingAuthorization();
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return consentInfo?.trackingAuthorizationChanged === true;
|
|
30
|
+
}
|
|
31
|
+
}
|
package/package.json
CHANGED
|
@@ -1,23 +1,40 @@
|
|
|
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
|
-
|
|
23
|
-
}
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "0.1.10",
|
|
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
|
+
"@cardsjd/device": "^0.1.15",
|
|
21
|
+
"@cardsjd/fbinstantgame": "^0.1.12",
|
|
22
|
+
"@discord/embedded-app-sdk": "^2.4.0"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@capacitor-community/admob": ">=7 <9",
|
|
26
|
+
"@capgo/capacitor-admob": ">=8 <9",
|
|
27
|
+
"@cardsjd/google-ump": ">=0.0.1 <1"
|
|
28
|
+
},
|
|
29
|
+
"peerDependenciesMeta": {
|
|
30
|
+
"@capacitor-community/admob": {
|
|
31
|
+
"optional": true
|
|
32
|
+
},
|
|
33
|
+
"@capgo/capacitor-admob": {
|
|
34
|
+
"optional": true
|
|
35
|
+
},
|
|
36
|
+
"@cardsjd/google-ump": {
|
|
37
|
+
"optional": true
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|