@cardsjd/portal 0.1.13 → 0.1.14
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 +12 -6
- package/lib/BasePortal.js +15 -12
- package/lib/CrazyGamesPortal.js +7 -1
- package/lib/FacebookPortal.js +22 -21
- package/lib/GameDistributionPortal.js +7 -1
- package/lib/NextGenAdMobPortal.js +9 -3
- package/lib/PokiPortal.js +12 -12
- package/lib/WebPortal.js +19 -17
- package/package.json +1 -1
package/lib/AdMobPortal.js
CHANGED
|
@@ -77,8 +77,8 @@ export class AdMobPortal extends BasePortal {
|
|
|
77
77
|
AdMob.addListener(InterstitialAdPluginEvents.Loaded, () => {
|
|
78
78
|
this.isInterstitialAdReady = true;
|
|
79
79
|
});
|
|
80
|
-
AdMob.addListener(InterstitialAdPluginEvents.Showed, () => {
|
|
81
|
-
this.isInterstitialAdReady = false;
|
|
80
|
+
AdMob.addListener(InterstitialAdPluginEvents.Showed, () => {
|
|
81
|
+
this.isInterstitialAdReady = false;
|
|
82
82
|
if (this.onAdOpened) {
|
|
83
83
|
this.onAdOpened({
|
|
84
84
|
adType: 'interstitial',
|
|
@@ -155,13 +155,19 @@ export class AdMobPortal extends BasePortal {
|
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
async showInterstitialAd() {
|
|
158
|
-
if (!this.isAdLoaded()) {
|
|
159
|
-
await this.loadInterstitialAd();
|
|
160
|
-
return; // no auto show
|
|
158
|
+
if (!this.isAdLoaded()) {
|
|
159
|
+
await this.loadInterstitialAd();
|
|
160
|
+
return false; // no auto show
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
this.isInterstitialAdReady = false;
|
|
164
|
-
|
|
164
|
+
try {
|
|
165
|
+
await AdMob.showInterstitial();
|
|
166
|
+
} catch (error) {
|
|
167
|
+
console.error('Interstitial ad failed to show', error);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return true;
|
|
165
171
|
}
|
|
166
172
|
|
|
167
173
|
async loadRewardedAd() {
|
package/lib/BasePortal.js
CHANGED
|
@@ -26,11 +26,12 @@ export class BasePortal {
|
|
|
26
26
|
|
|
27
27
|
async getFriends() { }
|
|
28
28
|
|
|
29
|
-
async setupAds() { }
|
|
29
|
+
async setupAds() { }
|
|
30
30
|
|
|
31
31
|
async loadInterstitialAd(_force) { }
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
// Returns true if a display was attempted, false if only loading or unavailable.
|
|
34
|
+
async showInterstitialAd() { return true; }
|
|
34
35
|
|
|
35
36
|
loadRewardedAd(_onLoaded) { }
|
|
36
37
|
|
|
@@ -42,15 +43,15 @@ export class BasePortal {
|
|
|
42
43
|
|
|
43
44
|
isAdLoaded() { }
|
|
44
45
|
|
|
45
|
-
isRewardedAdLoaded() { }
|
|
46
|
-
|
|
47
|
-
isPrivacyOptionsRequired() {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async showPrivacyOptions() { }
|
|
52
|
-
|
|
53
|
-
logError(_errorCode) { }
|
|
46
|
+
isRewardedAdLoaded() { }
|
|
47
|
+
|
|
48
|
+
isPrivacyOptionsRequired() {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async showPrivacyOptions() { }
|
|
53
|
+
|
|
54
|
+
logError(_errorCode) { }
|
|
54
55
|
|
|
55
56
|
isErrorState() { }
|
|
56
57
|
|
|
@@ -97,7 +98,9 @@ export class BasePortal {
|
|
|
97
98
|
|
|
98
99
|
// show ad or just load ad (not load and show)
|
|
99
100
|
if (readyToShowAd) {
|
|
100
|
-
await this.showInterstitialAd()
|
|
101
|
+
if (await this.showInterstitialAd()) {
|
|
102
|
+
this.lastShownInterstitial = Date.now();
|
|
103
|
+
}
|
|
101
104
|
} else {
|
|
102
105
|
await this.loadInterstitialAd();
|
|
103
106
|
}
|
package/lib/CrazyGamesPortal.js
CHANGED
|
@@ -299,7 +299,13 @@ export class CrazyGamesPortal extends BasePortal {
|
|
|
299
299
|
},
|
|
300
300
|
};
|
|
301
301
|
|
|
302
|
-
|
|
302
|
+
try {
|
|
303
|
+
await globalThis.CrazyGames.SDK.ad.requestAd('midgame', callbacks);
|
|
304
|
+
} catch (error) {
|
|
305
|
+
console.error('Interstitial ad failed to show', error);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return true;
|
|
303
309
|
}
|
|
304
310
|
|
|
305
311
|
isAdLoaded() {
|
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,20 +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 ? {
|
|
39
|
-
facebookId: fbProfile.facebookId ?? fbProfile.id,
|
|
40
|
-
name: fbProfile.name,
|
|
41
|
-
avatar: fbProfile.avatar ?? fbProfile.pic,
|
|
42
|
-
locale: fbProfile.locale,
|
|
43
|
-
} : null;
|
|
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;
|
|
44
44
|
return data;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
async save(data, forceSave) {
|
|
48
|
-
this.fBInstantGame.saveData(data, forceSave).catch(function () { });
|
|
47
|
+
async save(data, forceSave) {
|
|
48
|
+
this.fBInstantGame.saveData(data, forceSave).catch(function () { });
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
gameStart() {
|
|
@@ -65,10 +65,10 @@ export class FacebookPortal extends BasePortal {
|
|
|
65
65
|
|
|
66
66
|
this.subscribeBot();
|
|
67
67
|
}
|
|
68
|
-
createShortCut() {
|
|
69
|
-
this.portal?.createShortCut?.();
|
|
70
|
-
}
|
|
71
|
-
async subscribeBot() {
|
|
68
|
+
createShortCut() {
|
|
69
|
+
this.portal?.createShortCut?.();
|
|
70
|
+
}
|
|
71
|
+
async subscribeBot() {
|
|
72
72
|
await this.fBInstantGame.subscribeBot();
|
|
73
73
|
}
|
|
74
74
|
|
|
@@ -111,7 +111,7 @@ export class FacebookPortal extends BasePortal {
|
|
|
111
111
|
|
|
112
112
|
// ----- Ad methods -----
|
|
113
113
|
|
|
114
|
-
async setupAds() {
|
|
114
|
+
async setupAds() {
|
|
115
115
|
console.log('FB_Ads.setup');
|
|
116
116
|
|
|
117
117
|
if (typeof FBInstant === 'undefined' || !globalThis.FBInstant) {
|
|
@@ -188,7 +188,7 @@ export class FacebookPortal extends BasePortal {
|
|
|
188
188
|
|
|
189
189
|
this._isAdLoading = true;
|
|
190
190
|
|
|
191
|
-
const interstitialAdId = this.appConfig?.interstitialAdId;
|
|
191
|
+
const interstitialAdId = this.appConfig?.interstitialAdId;
|
|
192
192
|
|
|
193
193
|
console.log('FB_Ads.getInterstitialAdAsync start: ' + interstitialAdId);
|
|
194
194
|
if (!this.isApiSupported('getInterstitialAdAsync')) {
|
|
@@ -249,6 +249,7 @@ export class FacebookPortal extends BasePortal {
|
|
|
249
249
|
|
|
250
250
|
if (!isAdLoaded) {
|
|
251
251
|
this.loadInterstitialAd();
|
|
252
|
+
return false;
|
|
252
253
|
}
|
|
253
254
|
|
|
254
255
|
if (isAdLoaded) {
|
|
@@ -257,7 +258,7 @@ export class FacebookPortal extends BasePortal {
|
|
|
257
258
|
return false;
|
|
258
259
|
}
|
|
259
260
|
|
|
260
|
-
this.preloadedInterstitial.showAsync()
|
|
261
|
+
return Promise.resolve().then(() => this.preloadedInterstitial.showAsync())
|
|
261
262
|
.then(() => {
|
|
262
263
|
// Perform post-ad success operation
|
|
263
264
|
console.log('Interstitial ad finished successfully');
|
|
@@ -273,7 +274,7 @@ export class FacebookPortal extends BasePortal {
|
|
|
273
274
|
this.logError(err.code);
|
|
274
275
|
console.error('interstitialAd Error: ' + err.message + ' ' + err.code);
|
|
275
276
|
|
|
276
|
-
});
|
|
277
|
+
}).then(() => true);
|
|
277
278
|
}
|
|
278
279
|
|
|
279
280
|
}
|
|
@@ -290,7 +291,7 @@ export class FacebookPortal extends BasePortal {
|
|
|
290
291
|
console.log('FBInstant plugin not ready'); return false;
|
|
291
292
|
}
|
|
292
293
|
|
|
293
|
-
const interstitialAdId = this.appConfig?.interstitialAdId;
|
|
294
|
+
const interstitialAdId = this.appConfig?.interstitialAdId;
|
|
294
295
|
if (!this.isApiSupported('getInterstitialAdAsync')) {
|
|
295
296
|
this.logError('CLIENT_UNSUPPORTED_OPERATION');
|
|
296
297
|
console.warn('FBInstant.getInterstitialAdAsync is not supported on this client');
|
|
@@ -69,7 +69,13 @@ export class GameDistribution extends BasePortal {
|
|
|
69
69
|
return false;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
try {
|
|
73
|
+
await globalThis.gdsdk.showAd(AdType.Interstitial);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.error('Interstitial ad failed to show', error);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return true;
|
|
73
79
|
}
|
|
74
80
|
|
|
75
81
|
isAdLoaded() {
|
|
@@ -351,7 +351,7 @@ export class NextGenAdMobPortal extends BasePortal {
|
|
|
351
351
|
async showInterstitialAd() {
|
|
352
352
|
const setup = await this.ensureAdsReady();
|
|
353
353
|
if (!setup.canRequestAds || setup.promptShown) {
|
|
354
|
-
return;
|
|
354
|
+
return false;
|
|
355
355
|
}
|
|
356
356
|
|
|
357
357
|
if (!this.isAdLoaded()) {
|
|
@@ -361,12 +361,18 @@ export class NextGenAdMobPortal extends BasePortal {
|
|
|
361
361
|
})]);
|
|
362
362
|
clearTimeout(timeoutId);
|
|
363
363
|
if (!this.isAdLoaded()) {
|
|
364
|
-
return;
|
|
364
|
+
return false;
|
|
365
365
|
}
|
|
366
366
|
}
|
|
367
367
|
|
|
368
368
|
this.isInterstitialAdReady = false;
|
|
369
|
-
|
|
369
|
+
try {
|
|
370
|
+
await this._interstitialAd.show();
|
|
371
|
+
} catch (error) {
|
|
372
|
+
console.error('Interstitial ad failed to show', error);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
return true;
|
|
370
376
|
}
|
|
371
377
|
|
|
372
378
|
async loadRewardedAd() {
|
package/lib/PokiPortal.js
CHANGED
|
@@ -221,18 +221,18 @@ export class PokiPortal extends BasePortal {
|
|
|
221
221
|
});
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
-
if (typeof this.onAdClosed === 'function') {
|
|
225
|
-
this.onAdClosed({
|
|
226
|
-
adType,
|
|
227
|
-
adProvider,
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
return
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
isAdLoaded() {
|
|
224
|
+
if (typeof this.onAdClosed === 'function') {
|
|
225
|
+
this.onAdClosed({
|
|
226
|
+
adType,
|
|
227
|
+
adProvider,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
isAdLoaded() {
|
|
236
236
|
return this.isReady();
|
|
237
237
|
}
|
|
238
238
|
|
package/lib/WebPortal.js
CHANGED
|
@@ -125,22 +125,22 @@ export class WebPortal extends BasePortal {
|
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
showInterstitialAd() {
|
|
128
|
-
console.log('GoogleH5.showAd');
|
|
129
|
-
|
|
130
|
-
if (typeof adBreak === 'undefined' || !globalThis.adBreak) {
|
|
131
|
-
console.log('GoogleH5 adBreak plugin not ready'); return;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (!this.isSetup) {
|
|
135
|
-
console.log('GoogleH5.showAd - isSetup is false');
|
|
136
|
-
return;
|
|
128
|
+
console.log('GoogleH5.showAd');
|
|
129
|
+
|
|
130
|
+
if (typeof adBreak === 'undefined' || !globalThis.adBreak) {
|
|
131
|
+
console.log('GoogleH5 adBreak plugin not ready'); return false;
|
|
137
132
|
}
|
|
138
133
|
|
|
139
|
-
|
|
134
|
+
if (!this.isSetup) {
|
|
135
|
+
console.log('GoogleH5.showAd - isSetup is false');
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return Promise.resolve().then(() => globalThis.adBreak({
|
|
140
140
|
type: 'next', // The type of this placement (required)
|
|
141
|
-
name: 'post_game', // A descriptive name for this placement
|
|
142
|
-
beforeAd: () => {
|
|
143
|
-
if (this.onAdOpened) {
|
|
141
|
+
name: 'post_game', // A descriptive name for this placement
|
|
142
|
+
beforeAd: () => {
|
|
143
|
+
if (this.onAdOpened) {
|
|
144
144
|
this.onAdOpened({
|
|
145
145
|
adType: 'interstitial',
|
|
146
146
|
adProvider: this.adProviderName,
|
|
@@ -155,10 +155,12 @@ export class WebPortal extends BasePortal {
|
|
|
155
155
|
});
|
|
156
156
|
}
|
|
157
157
|
},
|
|
158
|
-
adBreakDone: (placementInfo) => {
|
|
159
|
-
console.log('placementInfo', placementInfo);
|
|
160
|
-
},
|
|
161
|
-
})
|
|
158
|
+
adBreakDone: (placementInfo) => {
|
|
159
|
+
console.log('placementInfo', placementInfo);
|
|
160
|
+
},
|
|
161
|
+
})).catch(error => {
|
|
162
|
+
console.error('Interstitial ad failed to show', error);
|
|
163
|
+
}).then(() => true);
|
|
162
164
|
}
|
|
163
165
|
|
|
164
166
|
isAdLoaded() {
|