web-sdk-wrapper 2.0.0 → 2.0.1
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 +212 -0
- package/dist/web-sdk-wrapper.js +136 -106
- package/dist/web-sdk-wrapper.umd.cjs +2 -2
- package/package.json +1 -1
- package/src/index.js +30 -20
- package/src/networks/base.js +18 -1
- package/src/networks/cool-math-games.js +4 -0
- package/src/networks/crazy-games.js +4 -0
- package/src/networks/freeze-nova.js +2 -0
- package/src/networks/poki.js +10 -2
- package/src/networks/xiaomi.js +9 -3
package/README.md
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# web-sdk-wrapper
|
|
2
|
+
|
|
3
|
+
Unified wrapper for web game distribution platform SDKs. Write your game once, publish to multiple portals.
|
|
4
|
+
|
|
5
|
+
## Supported Networks
|
|
6
|
+
|
|
7
|
+
| Network | Ads | Interstitial | Rewarded | Banner | Accounts | Tokens |
|
|
8
|
+
|---|---|---|---|---|---|---|
|
|
9
|
+
| Poki | Yes | Yes | Yes | No | Yes | Yes |
|
|
10
|
+
| CrazyGames | Yes | Yes | Yes | Yes | No | No |
|
|
11
|
+
| CoolMathGames | Yes | Yes | No | No | No | No |
|
|
12
|
+
| HoodaMath | No | No | No | No | No | No |
|
|
13
|
+
| FreezeNova | Yes | Yes | Yes | No | No | No |
|
|
14
|
+
| Xiaomi | Yes | Yes | Yes | No | No | No |
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install web-sdk-wrapper
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Or include via script tag (UMD):
|
|
23
|
+
|
|
24
|
+
```html
|
|
25
|
+
<script src="dist/web-sdk-wrapper.umd.cjs"></script>
|
|
26
|
+
<script>
|
|
27
|
+
const Wrapper = WebSdkWrapper.default;
|
|
28
|
+
</script>
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Quick Start
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
import Wrapper from "web-sdk-wrapper";
|
|
35
|
+
|
|
36
|
+
// Initialize with a network
|
|
37
|
+
await Wrapper.init("Poki", false, { poki_gameId: "abc123" });
|
|
38
|
+
|
|
39
|
+
// Signal loading complete
|
|
40
|
+
Wrapper.loadingEnd();
|
|
41
|
+
|
|
42
|
+
// Start gameplay
|
|
43
|
+
Wrapper.gameplayStart();
|
|
44
|
+
|
|
45
|
+
// Show an interstitial ad (auto-pauses/resumes gameplay)
|
|
46
|
+
const shown = await Wrapper.interstitial();
|
|
47
|
+
|
|
48
|
+
// Show a rewarded ad
|
|
49
|
+
const rewarded = await Wrapper.rewarded();
|
|
50
|
+
if (rewarded) {
|
|
51
|
+
// Grant the reward
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Stop gameplay
|
|
55
|
+
Wrapper.gameplayStop();
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## API
|
|
59
|
+
|
|
60
|
+
### `Wrapper.init(name, debug?, data?)`
|
|
61
|
+
|
|
62
|
+
Initialize the wrapper with a specific network.
|
|
63
|
+
|
|
64
|
+
- `name` — Network name (case-insensitive): `"Poki"`, `"CrazyGames"`, `"CoolMathGames"`, `"HoodaMath"`, `"FreezeNova"`, `"Xiaomi"`
|
|
65
|
+
- `debug` — Enable debug mode (default: `false`). Networks with `requiresProduction` are disabled in debug mode.
|
|
66
|
+
- `data` — Network-specific configuration object. See [Network Configuration](#network-configuration).
|
|
67
|
+
|
|
68
|
+
Returns a `Promise<void>` that resolves when the SDK is loaded and initialized.
|
|
69
|
+
|
|
70
|
+
### Lifecycle
|
|
71
|
+
|
|
72
|
+
| Method | Description |
|
|
73
|
+
|---|---|
|
|
74
|
+
| `Wrapper.loadingStart()` | Signal that the game started loading |
|
|
75
|
+
| `Wrapper.loadingEnd()` | Signal that the game finished loading |
|
|
76
|
+
| `Wrapper.gameplayStart()` | Signal that a gameplay session started (duplicate calls are ignored) |
|
|
77
|
+
| `Wrapper.gameplayStop()` | Signal that a gameplay session stopped (duplicate calls are ignored) |
|
|
78
|
+
| `Wrapper.levelStart(level)` | Signal that a level started |
|
|
79
|
+
| `Wrapper.replayLevel(level)` | Signal that a level is being replayed |
|
|
80
|
+
|
|
81
|
+
### Ads
|
|
82
|
+
|
|
83
|
+
| Method | Returns | Description |
|
|
84
|
+
|---|---|---|
|
|
85
|
+
| `Wrapper.interstitial()` | `Promise<boolean>` | Show an interstitial ad. Automatically pauses/resumes gameplay. Returns whether the ad was shown. |
|
|
86
|
+
| `Wrapper.rewarded(size?)` | `Promise<boolean>` | Show a rewarded ad. Automatically pauses/resumes gameplay. Returns whether the reward was earned. |
|
|
87
|
+
| `Wrapper.onAdStarted(fn)` | `void` | Register a callback for when any ad starts. |
|
|
88
|
+
| `Wrapper.hasAds()` | `boolean` | Check if the current network supports ads. |
|
|
89
|
+
| `Wrapper.hasInterstitialAds()` | `boolean` | Check if the current network supports interstitial ads. |
|
|
90
|
+
| `Wrapper.hasRewardedAds()` | `boolean` | Check if the current network supports rewarded ads. |
|
|
91
|
+
|
|
92
|
+
### Accounts
|
|
93
|
+
|
|
94
|
+
| Method | Returns | Description |
|
|
95
|
+
|---|---|---|
|
|
96
|
+
| `Wrapper.login()` | `Promise<any>` | Log in via the platform. Rejects if not supported. |
|
|
97
|
+
| `Wrapper.getUser()` | `Promise<any>` | Get the current user. Returns `null` if not supported. |
|
|
98
|
+
| `Wrapper.getToken()` | `Promise<string\|null>` | Get an auth token. Returns `null` if not supported. |
|
|
99
|
+
| `Wrapper.hasAccounts()` | `boolean` | Check if the current network supports accounts. |
|
|
100
|
+
| `Wrapper.hasToken()` | `boolean` | Check if the current network supports tokens. |
|
|
101
|
+
|
|
102
|
+
### Misc
|
|
103
|
+
|
|
104
|
+
| Method | Description |
|
|
105
|
+
|---|---|
|
|
106
|
+
| `Wrapper.analyticsEvent({ category, action, label? })` | Track an analytics event. |
|
|
107
|
+
| `Wrapper.openExternalLink(url)` | Open an external URL through the platform's handler. |
|
|
108
|
+
| `Wrapper.onUnlockAllLevels(fn)` | Register a callback for unlocking all levels. |
|
|
109
|
+
| `Wrapper.enabled` | `boolean` getter — whether the wrapper is active. |
|
|
110
|
+
| `Wrapper.currentSdk` | Getter — the current network adapter instance. |
|
|
111
|
+
|
|
112
|
+
## Network Configuration
|
|
113
|
+
|
|
114
|
+
Pass network-specific options via the `data` parameter in `init()`.
|
|
115
|
+
|
|
116
|
+
### Poki
|
|
117
|
+
|
|
118
|
+
```javascript
|
|
119
|
+
await Wrapper.init("Poki", false, {
|
|
120
|
+
poki_gameId: "your-game-id",
|
|
121
|
+
poki_doBeacon: true, // Enable beacon tracking (optional)
|
|
122
|
+
poki_maxBeacons: 6, // Max beacons to send (default: 6)
|
|
123
|
+
poki_beaconInterval: 60, // Seconds between beacons (default: 60)
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Xiaomi
|
|
128
|
+
|
|
129
|
+
```javascript
|
|
130
|
+
await Wrapper.init("Xiaomi", false, {
|
|
131
|
+
xiaomi_publisherId: "pub-xxxxx",
|
|
132
|
+
xiaomi_bannerEnabled: true, // Enable banner ads (optional)
|
|
133
|
+
xiaomi_dataAdSlot: "xxxxx", // Ad slot ID (required if banner enabled)
|
|
134
|
+
xiaomi_bannerConainerId: "adSpace", // Banner container element ID (default: "adSpace")
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### FreezeNova
|
|
139
|
+
|
|
140
|
+
```javascript
|
|
141
|
+
await Wrapper.init("FreezeNova", false, {
|
|
142
|
+
freezeNova_id: 12345,
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### CrazyGames, CoolMathGames, HoodaMath
|
|
147
|
+
|
|
148
|
+
No additional configuration needed.
|
|
149
|
+
|
|
150
|
+
```javascript
|
|
151
|
+
await Wrapper.init("CrazyGames");
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Named Exports
|
|
155
|
+
|
|
156
|
+
```javascript
|
|
157
|
+
import Wrapper, { networks, NetworkAdapter, preventWeirdInputs } from "web-sdk-wrapper";
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
| Export | Description |
|
|
161
|
+
|---|---|
|
|
162
|
+
| `default` (Wrapper) | The singleton wrapper instance. |
|
|
163
|
+
| `networks` | `string[]` — List of supported network names. |
|
|
164
|
+
| `NetworkAdapter` | Base class for creating custom network adapters. |
|
|
165
|
+
| `preventWeirdInputs()` | Opt-in utility that prevents arrow key scrolling, mouse wheel scrolling, and text selection on canvas. Call explicitly if your game needs it. |
|
|
166
|
+
|
|
167
|
+
## Adding a Custom Network
|
|
168
|
+
|
|
169
|
+
Create a class extending `NetworkAdapter` and override only what you need:
|
|
170
|
+
|
|
171
|
+
```javascript
|
|
172
|
+
import { NetworkAdapter } from "web-sdk-wrapper";
|
|
173
|
+
|
|
174
|
+
export class MyPortalAdapter extends NetworkAdapter {
|
|
175
|
+
name = "MyPortal";
|
|
176
|
+
|
|
177
|
+
capabilities = {
|
|
178
|
+
ads: true,
|
|
179
|
+
interstitialAds: true,
|
|
180
|
+
rewardedAds: false,
|
|
181
|
+
bannerAds: false,
|
|
182
|
+
accounts: false,
|
|
183
|
+
tokens: false,
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
scriptSources = ["https://sdk.myportal.com/sdk.js"];
|
|
187
|
+
|
|
188
|
+
async init(options) {
|
|
189
|
+
this._sdk = globalThis.MyPortalSDK;
|
|
190
|
+
await this._sdk.initialize();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async showInterstitial() {
|
|
194
|
+
await this._sdk.showAd("interstitial");
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
onGameplayStart() {
|
|
199
|
+
this._sdk.gameplayStart();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
onGameplayStop() {
|
|
203
|
+
this._sdk.gameplayStop();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Then add it to the registry in `src/networks/index.js`.
|
|
209
|
+
|
|
210
|
+
## License
|
|
211
|
+
|
|
212
|
+
MIT
|
package/dist/web-sdk-wrapper.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
var m = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var t = (
|
|
2
|
+
var _ = (i, e, a) => e in i ? m(i, e, { enumerable: !0, configurable: !0, writable: !0, value: a }) : i[e] = a;
|
|
3
|
+
var t = (i, e, a) => _(i, typeof e != "symbol" ? e + "" : e, a);
|
|
4
|
+
const l = {};
|
|
5
|
+
function f(i, e, { once: a = !1 } = {}) {
|
|
6
|
+
l[i] = l[i] || [], l[i].push({ fn: e, once: a });
|
|
7
|
+
}
|
|
8
|
+
function p(i, ...e) {
|
|
9
|
+
(l[i] || []).forEach((a) => {
|
|
10
|
+
a.fn(...e);
|
|
11
|
+
}), l[i] = (l[i] || []).filter((a) => !a.once);
|
|
12
|
+
}
|
|
4
13
|
class c {
|
|
5
14
|
constructor() {
|
|
6
15
|
/** @type {string} */
|
|
@@ -23,7 +32,7 @@ class c {
|
|
|
23
32
|
accounts: !1,
|
|
24
33
|
tokens: !1
|
|
25
34
|
});
|
|
26
|
-
/** @type {string[]} SDK script URLs to load before init */
|
|
35
|
+
/** @type {string[]|null} SDK script URLs to load before init. Set to null to handle script loading in preInit. */
|
|
27
36
|
t(this, "scriptSources", []);
|
|
28
37
|
/** @type {boolean} If true, adapter is disabled when debug=true */
|
|
29
38
|
t(this, "requiresProduction", !1);
|
|
@@ -55,6 +64,12 @@ class c {
|
|
|
55
64
|
/** Called when the game finishes loading. */
|
|
56
65
|
onLoadingEnd() {
|
|
57
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Called with loading progress updates.
|
|
69
|
+
* @param {number} progress - 0 to 100
|
|
70
|
+
*/
|
|
71
|
+
onLoadingProgress(e) {
|
|
72
|
+
}
|
|
58
73
|
/**
|
|
59
74
|
* Handles duplicate-call gating for gameplay start.
|
|
60
75
|
* Do NOT override this — override onGameplayStart() instead.
|
|
@@ -98,6 +113,14 @@ class c {
|
|
|
98
113
|
// ========================
|
|
99
114
|
// Ads
|
|
100
115
|
// ========================
|
|
116
|
+
/**
|
|
117
|
+
* Dispatch the "adStarted" event. Call this from your ad methods
|
|
118
|
+
* at the moment the ad actually starts (e.g. inside an SDK callback).
|
|
119
|
+
* @param {"interstitial"|"rewarded"} type
|
|
120
|
+
*/
|
|
121
|
+
_dispatchAdStarted(e) {
|
|
122
|
+
p("adStarted", e);
|
|
123
|
+
}
|
|
101
124
|
/**
|
|
102
125
|
* Show an interstitial ad.
|
|
103
126
|
* @returns {Promise<boolean>} Whether the ad was shown successfully
|
|
@@ -146,7 +169,7 @@ class c {
|
|
|
146
169
|
* @param {string} action
|
|
147
170
|
* @param {string} [label]
|
|
148
171
|
*/
|
|
149
|
-
trackEvent(e, a,
|
|
172
|
+
trackEvent(e, a, s) {
|
|
150
173
|
}
|
|
151
174
|
/**
|
|
152
175
|
* Open an external link. Default: window.open.
|
|
@@ -156,7 +179,7 @@ class c {
|
|
|
156
179
|
window.open(e, "_blank");
|
|
157
180
|
}
|
|
158
181
|
}
|
|
159
|
-
class
|
|
182
|
+
class g extends c {
|
|
160
183
|
constructor() {
|
|
161
184
|
super(...arguments);
|
|
162
185
|
t(this, "name", "Poki");
|
|
@@ -182,12 +205,14 @@ class _ extends c {
|
|
|
182
205
|
*/
|
|
183
206
|
_beacon(a) {
|
|
184
207
|
if (!this._gameId || !this._doBeacon) return;
|
|
185
|
-
const
|
|
186
|
-
|
|
208
|
+
const s = Date.now();
|
|
209
|
+
s - this._lastBeaconTime < this._beaconInterval * 1e3 || this._maxBeacons <= 0 || (this._lastBeaconTime = s, this._maxBeacons--, navigator.sendBeacon(`https://leveldata.poki.io/${a}`, this._gameId));
|
|
187
210
|
}
|
|
188
211
|
async init(a) {
|
|
189
|
-
this._sdk = globalThis.PokiSDK
|
|
212
|
+
this._sdk = globalThis.PokiSDK;
|
|
213
|
+
const s = this._sdk.init().catch(() => {
|
|
190
214
|
});
|
|
215
|
+
this._sdk.setDebug(a.debug), await s;
|
|
191
216
|
const n = a.data || {};
|
|
192
217
|
this._gameId = n.poki_gameId, this._doBeacon = n.poki_doBeacon, this._maxBeacons = n.poki_maxBeacons || 6, this._beaconInterval = n.poki_beaconInterval || 60;
|
|
193
218
|
}
|
|
@@ -204,10 +229,15 @@ class _ extends c {
|
|
|
204
229
|
this._beacon("gameplayStop"), this._sdk.gameplayStop();
|
|
205
230
|
}
|
|
206
231
|
async showInterstitial() {
|
|
207
|
-
return this._beacon("interstitial"), await this._sdk.commercialBreak(), !0;
|
|
232
|
+
return this._beacon("interstitial"), this._dispatchAdStarted("interstitial"), await this._sdk.commercialBreak(), !0;
|
|
208
233
|
}
|
|
209
234
|
async showRewarded(a = "small") {
|
|
210
|
-
return this._beacon("rewarded"), await this._sdk.rewardedBreak({
|
|
235
|
+
return this._beacon("rewarded"), await this._sdk.rewardedBreak({
|
|
236
|
+
size: a,
|
|
237
|
+
onStart: () => {
|
|
238
|
+
this._dispatchAdStarted("rewarded");
|
|
239
|
+
}
|
|
240
|
+
});
|
|
211
241
|
}
|
|
212
242
|
login() {
|
|
213
243
|
return this._sdk.login();
|
|
@@ -218,14 +248,14 @@ class _ extends c {
|
|
|
218
248
|
getToken() {
|
|
219
249
|
return this._sdk.getToken();
|
|
220
250
|
}
|
|
221
|
-
trackEvent(a,
|
|
222
|
-
this._beacon(`${a}_${
|
|
251
|
+
trackEvent(a, s, n) {
|
|
252
|
+
this._beacon(`${a}_${s}`), this._sdk.measure(a, s, n);
|
|
223
253
|
}
|
|
224
254
|
openExternalLink(a) {
|
|
225
255
|
this._sdk && this._sdk.openExternalLink ? this._sdk.openExternalLink(a) : super.openExternalLink(a);
|
|
226
256
|
}
|
|
227
257
|
}
|
|
228
|
-
class
|
|
258
|
+
class y extends c {
|
|
229
259
|
constructor() {
|
|
230
260
|
super(...arguments);
|
|
231
261
|
t(this, "name", "CrazyGames");
|
|
@@ -245,11 +275,13 @@ class g extends c {
|
|
|
245
275
|
t(this, "_adResolve", null);
|
|
246
276
|
}
|
|
247
277
|
async init(a) {
|
|
248
|
-
var
|
|
249
|
-
this._sdk = (
|
|
278
|
+
var s, n;
|
|
279
|
+
this._sdk = (n = (s = globalThis == null ? void 0 : globalThis.CrazyGames) == null ? void 0 : s.CrazySDK) == null ? void 0 : n.getInstance(), await new Promise((r) => {
|
|
250
280
|
this._sdk.addEventListener("adblockDetectionExecuted", () => {
|
|
251
281
|
r();
|
|
252
282
|
}), this._sdk.init();
|
|
283
|
+
}), this._sdk.addEventListener("adStarted", () => {
|
|
284
|
+
this._dispatchAdStarted(this._lastRequestedAd);
|
|
253
285
|
}), this._sdk.addEventListener("adFinished", () => {
|
|
254
286
|
this._adResolve && (this._adResolve(!0), this._adResolve = null);
|
|
255
287
|
}), this._sdk.addEventListener("adError", () => {
|
|
@@ -273,7 +305,7 @@ class g extends c {
|
|
|
273
305
|
});
|
|
274
306
|
}
|
|
275
307
|
}
|
|
276
|
-
class
|
|
308
|
+
class k extends c {
|
|
277
309
|
constructor() {
|
|
278
310
|
super(...arguments);
|
|
279
311
|
t(this, "name", "CoolMathGames");
|
|
@@ -293,7 +325,9 @@ class y extends c {
|
|
|
293
325
|
t(this, "_adResolve", null);
|
|
294
326
|
}
|
|
295
327
|
async init(a) {
|
|
296
|
-
document.addEventListener("
|
|
328
|
+
document.addEventListener("adBreakStart", () => {
|
|
329
|
+
this._dispatchAdStarted("interstitial");
|
|
330
|
+
}), document.addEventListener("adBreakComplete", () => {
|
|
297
331
|
this._adResolve && (this._adResolve(!0), this._adResolve = null);
|
|
298
332
|
});
|
|
299
333
|
}
|
|
@@ -312,7 +346,7 @@ class y extends c {
|
|
|
312
346
|
});
|
|
313
347
|
}
|
|
314
348
|
}
|
|
315
|
-
class
|
|
349
|
+
class S extends c {
|
|
316
350
|
constructor() {
|
|
317
351
|
super(...arguments);
|
|
318
352
|
t(this, "name", "HoodaMath");
|
|
@@ -339,7 +373,7 @@ class b extends c {
|
|
|
339
373
|
t(this, "_adResolve", null);
|
|
340
374
|
}
|
|
341
375
|
async init(a) {
|
|
342
|
-
const
|
|
376
|
+
const s = a.data || {};
|
|
343
377
|
window.SubmitLeaderboardScore = function(r) {
|
|
344
378
|
}, window.InitExternEval = function() {
|
|
345
379
|
window.firstInit == null ? window.firstInit = 1 : window.ExternEval();
|
|
@@ -391,26 +425,26 @@ class b extends c {
|
|
|
391
425
|
window.canReward = 1;
|
|
392
426
|
}, 3e4));
|
|
393
427
|
};
|
|
394
|
-
const
|
|
428
|
+
const n = this;
|
|
395
429
|
window.RewardedSuccess = function() {
|
|
396
|
-
window.adRunning = 0, window.adReward = 1,
|
|
430
|
+
window.adRunning = 0, window.adReward = 1, n._adResolve && (n._adResolve(!0), n._adResolve = null);
|
|
397
431
|
}, window.RewardedFail = function() {
|
|
398
|
-
window.adRunning = 0,
|
|
432
|
+
window.adRunning = 0, n._adResolve && (n._adResolve(!1), n._adResolve = null);
|
|
399
433
|
}, window.OpenLink = function() {
|
|
400
|
-
}, window.adRunning = 0, window.adRunningRewarded = 0, window.adReward = 0, window.rewardError = 0, window.canReward = 0, window.callTime = 0, window.adPlatform = 4, window.myLeaderboardScore = 0, window.gameLang = "en", window.InitApi(
|
|
434
|
+
}, window.adRunning = 0, window.adRunningRewarded = 0, window.adReward = 0, window.rewardError = 0, window.canReward = 0, window.callTime = 0, window.adPlatform = 4, window.myLeaderboardScore = 0, window.gameLang = "en", window.InitApi(s.freezeNova_id || 0);
|
|
401
435
|
}
|
|
402
436
|
async showInterstitial() {
|
|
403
437
|
return new Promise((a) => {
|
|
404
|
-
this._adResolve = a, window.PreloadRewarded(), window.ShowRewarded();
|
|
438
|
+
this._adResolve = a, this._dispatchAdStarted("interstitial"), window.PreloadRewarded(), window.ShowRewarded();
|
|
405
439
|
});
|
|
406
440
|
}
|
|
407
441
|
async showRewarded() {
|
|
408
442
|
return new Promise((a) => {
|
|
409
|
-
this._adResolve = a, window.PreloadRewarded(), window.ShowRewarded();
|
|
443
|
+
this._adResolve = a, this._dispatchAdStarted("rewarded"), window.PreloadRewarded(), window.ShowRewarded();
|
|
410
444
|
});
|
|
411
445
|
}
|
|
412
446
|
}
|
|
413
|
-
class
|
|
447
|
+
class R extends c {
|
|
414
448
|
constructor() {
|
|
415
449
|
super(...arguments);
|
|
416
450
|
t(this, "name", "Xiaomi");
|
|
@@ -423,24 +457,24 @@ class S extends c {
|
|
|
423
457
|
tokens: !1
|
|
424
458
|
});
|
|
425
459
|
// Scripts are loaded manually in preInit, not via the standard loader
|
|
426
|
-
t(this, "scriptSources",
|
|
460
|
+
t(this, "scriptSources", null);
|
|
427
461
|
t(this, "requiresProduction", !0);
|
|
428
462
|
/** @type {function|null} */
|
|
429
463
|
t(this, "_adBreak", null);
|
|
430
464
|
}
|
|
431
465
|
async preInit(a) {
|
|
432
|
-
const
|
|
433
|
-
|
|
466
|
+
const s = a.data || {}, n = document.createElement("script");
|
|
467
|
+
n.async = !0, n.setAttribute("data-ad-frequency-hint", "30s"), n.src = `https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-${s.xiaomi_publisherId}`, n.setAttribute("crossorigin", "anonymous"), a.debug && n.setAttribute("data-adbreak-test", "on"), window.adsbygoogle = window.adsbygoogle || [], window.adConfig = function(r) {
|
|
434
468
|
adsbygoogle.push(r);
|
|
435
|
-
}, window.adBreak = window.adConfig, this._adBreak = window.adBreak, document.body.appendChild(
|
|
436
|
-
|
|
437
|
-
if (
|
|
469
|
+
}, window.adBreak = window.adConfig, this._adBreak = window.adBreak, document.body.appendChild(n), await new Promise((r) => {
|
|
470
|
+
n.onload = () => {
|
|
471
|
+
if (s.xiaomi_bannerEnabled) {
|
|
438
472
|
const d = document.createElement("ins");
|
|
439
473
|
d.className = "adsbygoogle", d.style.display = "block", d.setAttribute(
|
|
440
474
|
"data-ad-client",
|
|
441
|
-
`ca-${
|
|
442
|
-
), d.setAttribute("data-ad-slot",
|
|
443
|
-
const o =
|
|
475
|
+
`ca-${s.xiaomi_publisherId}`
|
|
476
|
+
), d.setAttribute("data-ad-slot", s.xiaomi_dataAdSlot), d.setAttribute("data-ad-format", "auto"), d.setAttribute("data-full-width-responsive", "true");
|
|
477
|
+
const o = s.xiaomi_bannerConainerId || "adSpace";
|
|
444
478
|
let w = document.getElementById(o);
|
|
445
479
|
w || (w = document.createElement("div"), w.id = o, document.body.appendChild(w)), w.appendChild(d), (adsbygoogle = window.adsbygoogle || []).push({});
|
|
446
480
|
}
|
|
@@ -450,14 +484,14 @@ class S extends c {
|
|
|
450
484
|
}
|
|
451
485
|
onLoadingStart() {
|
|
452
486
|
try {
|
|
453
|
-
funmax
|
|
487
|
+
funmax ? funmax.loadStart() : console.error("funmax not found");
|
|
454
488
|
} catch {
|
|
455
489
|
console.error("funmax not found");
|
|
456
490
|
}
|
|
457
491
|
}
|
|
458
492
|
onLoadingEnd() {
|
|
459
493
|
try {
|
|
460
|
-
funmax
|
|
494
|
+
funmax ? funmax.loadReady() : console.error("funmax not found");
|
|
461
495
|
} catch {
|
|
462
496
|
console.error("funmax not found");
|
|
463
497
|
}
|
|
@@ -468,6 +502,7 @@ class S extends c {
|
|
|
468
502
|
type: "next",
|
|
469
503
|
name: "interstitial",
|
|
470
504
|
beforeAd: () => {
|
|
505
|
+
this._dispatchAdStarted("interstitial");
|
|
471
506
|
},
|
|
472
507
|
adBreakDone: () => {
|
|
473
508
|
a(!0);
|
|
@@ -477,62 +512,54 @@ class S extends c {
|
|
|
477
512
|
}
|
|
478
513
|
async showRewarded() {
|
|
479
514
|
return new Promise((a) => {
|
|
480
|
-
let
|
|
515
|
+
let s = !1;
|
|
481
516
|
this._adBreak({
|
|
482
517
|
type: "reward",
|
|
483
518
|
name: "rewarded",
|
|
484
519
|
beforeAd: () => {
|
|
520
|
+
this._dispatchAdStarted("rewarded");
|
|
485
521
|
},
|
|
486
522
|
adBreakDone: () => {
|
|
487
|
-
a(
|
|
523
|
+
a(s);
|
|
488
524
|
},
|
|
489
|
-
beforeReward: (
|
|
490
|
-
|
|
525
|
+
beforeReward: (n) => {
|
|
526
|
+
n();
|
|
491
527
|
},
|
|
492
528
|
adDismissed: () => {
|
|
493
|
-
|
|
529
|
+
s = !1;
|
|
494
530
|
},
|
|
495
531
|
adViewed: () => {
|
|
496
|
-
|
|
532
|
+
s = !0;
|
|
497
533
|
}
|
|
498
534
|
});
|
|
499
535
|
});
|
|
500
536
|
}
|
|
501
537
|
}
|
|
502
538
|
const h = {
|
|
503
|
-
Poki:
|
|
504
|
-
CrazyGames:
|
|
505
|
-
CoolMathGames:
|
|
506
|
-
HoodaMath:
|
|
539
|
+
Poki: g,
|
|
540
|
+
CrazyGames: y,
|
|
541
|
+
CoolMathGames: k,
|
|
542
|
+
HoodaMath: S,
|
|
507
543
|
FreezeNova: b,
|
|
508
|
-
Xiaomi:
|
|
509
|
-
},
|
|
510
|
-
function
|
|
511
|
-
if (
|
|
512
|
-
const e = new Promise((a,
|
|
513
|
-
const
|
|
514
|
-
|
|
544
|
+
Xiaomi: R
|
|
545
|
+
}, L = Object.keys(h), u = /* @__PURE__ */ new Map();
|
|
546
|
+
function v(i) {
|
|
547
|
+
if (u.has(i)) return u.get(i);
|
|
548
|
+
const e = new Promise((a, s) => {
|
|
549
|
+
const n = document.createElement("script");
|
|
550
|
+
n.src = i, n.onload = () => a(), n.onerror = () => s(new Error(`Failed to load script: ${i}`)), document.head.appendChild(n);
|
|
515
551
|
});
|
|
516
|
-
return
|
|
552
|
+
return u.set(i, e), e;
|
|
517
553
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
}
|
|
522
|
-
function u(s, ...e) {
|
|
523
|
-
(l[s] || []).forEach((a) => {
|
|
524
|
-
a.fn(...e);
|
|
525
|
-
}), l[s] = (l[s] || []).filter((a) => !a.once);
|
|
526
|
-
}
|
|
527
|
-
function L() {
|
|
528
|
-
const s = document.createElement("style");
|
|
529
|
-
s.innerHTML = `
|
|
554
|
+
function x() {
|
|
555
|
+
const i = document.createElement("style");
|
|
556
|
+
i.innerHTML = `
|
|
530
557
|
canvas {
|
|
531
558
|
user-select: none !important;
|
|
532
559
|
-webkit-user-select: none !important;
|
|
533
560
|
-moz-user-select: none !important;
|
|
534
561
|
-ms-user-select: none !important;
|
|
535
|
-
}`, document.head.appendChild(
|
|
562
|
+
}`, document.head.appendChild(i), window.addEventListener("keydown", (e) => {
|
|
536
563
|
["ArrowDown", "ArrowUp", " "].includes(e.key) && e.preventDefault();
|
|
537
564
|
}), window.addEventListener("wheel", (e) => e.preventDefault(), {
|
|
538
565
|
passive: !1
|
|
@@ -558,24 +585,27 @@ class A {
|
|
|
558
585
|
* @param {Object} [data={}] - Network-specific configuration
|
|
559
586
|
* @returns {Promise<void>}
|
|
560
587
|
*/
|
|
561
|
-
async init(e, a = !1,
|
|
562
|
-
const
|
|
588
|
+
async init(e, a = !1, s = {}) {
|
|
589
|
+
const n = Object.keys(h).find(
|
|
563
590
|
(o) => o.toLowerCase() === e.toLowerCase()
|
|
564
|
-
), r =
|
|
565
|
-
if (!r
|
|
591
|
+
), r = n ? h[n] : null;
|
|
592
|
+
if (!r) return;
|
|
593
|
+
if (this._adapter = new r(), this._adapter.requiresProduction && a) {
|
|
594
|
+
this._adapter = null;
|
|
566
595
|
return;
|
|
596
|
+
}
|
|
567
597
|
this._enabled = !0;
|
|
568
|
-
const d = { debug: a, data:
|
|
569
|
-
await this._adapter.preInit(d)
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
await this._adapter.init(d), this.loadingStart();
|
|
598
|
+
const d = { debug: a, data: s };
|
|
599
|
+
if (await this._adapter.preInit(d), this._adapter.scriptSources !== null)
|
|
600
|
+
for (const o of this._adapter.scriptSources)
|
|
601
|
+
await v(o);
|
|
602
|
+
await this._adapter.init(d), this._adapter.scriptSources !== null && this.loadingStart();
|
|
573
603
|
}
|
|
574
604
|
loadingStart() {
|
|
575
|
-
this._adapter && this._adapter.onLoadingStart();
|
|
605
|
+
this._adapter && (this._adapter.onLoadingStart(), this._adapter.onLoadingProgress(0));
|
|
576
606
|
}
|
|
577
607
|
loadingEnd() {
|
|
578
|
-
this._adapter && this._adapter.onLoadingEnd();
|
|
608
|
+
this._adapter && (this._adapter.onLoadingProgress(100), this._adapter.onLoadingEnd());
|
|
579
609
|
}
|
|
580
610
|
gameplayStart() {
|
|
581
611
|
this._adapter && this._adapter.maybeGameplayStart();
|
|
@@ -597,11 +627,11 @@ class A {
|
|
|
597
627
|
* @returns {Promise<boolean>}
|
|
598
628
|
*/
|
|
599
629
|
async interstitial() {
|
|
600
|
-
var
|
|
601
|
-
if (!((
|
|
602
|
-
return
|
|
630
|
+
var s;
|
|
631
|
+
if (!((s = this._adapter) != null && s.capabilities.interstitialAds))
|
|
632
|
+
return p("adStarted", "interstitial"), !1;
|
|
603
633
|
const e = this._adapter._gameplayStarted;
|
|
604
|
-
e && this.gameplayStop()
|
|
634
|
+
e && this.gameplayStop();
|
|
605
635
|
const a = await this._adapter.showInterstitial();
|
|
606
636
|
return e && this.gameplayStart(), a;
|
|
607
637
|
}
|
|
@@ -611,42 +641,42 @@ class A {
|
|
|
611
641
|
* @returns {Promise<boolean>}
|
|
612
642
|
*/
|
|
613
643
|
async rewarded(e) {
|
|
614
|
-
var
|
|
615
|
-
if (!((
|
|
616
|
-
return
|
|
644
|
+
var n;
|
|
645
|
+
if (!((n = this._adapter) != null && n.capabilities.rewardedAds))
|
|
646
|
+
return p("adStarted", "rewarded"), !0;
|
|
617
647
|
const a = this._adapter._gameplayStarted;
|
|
618
|
-
a && this.gameplayStop()
|
|
619
|
-
const
|
|
620
|
-
return a && this.gameplayStart(),
|
|
648
|
+
a && this.gameplayStop();
|
|
649
|
+
const s = await this._adapter.showRewarded(e);
|
|
650
|
+
return a && this.gameplayStart(), s;
|
|
621
651
|
}
|
|
622
652
|
/**
|
|
623
653
|
* Register a callback for when an ad starts.
|
|
624
654
|
* @param {function} fn
|
|
625
655
|
*/
|
|
626
656
|
onAdStarted(e) {
|
|
627
|
-
|
|
657
|
+
f("adStarted", e);
|
|
628
658
|
}
|
|
629
|
-
/** @returns {
|
|
659
|
+
/** @returns {boolean} */
|
|
630
660
|
hasAds() {
|
|
631
661
|
var e;
|
|
632
|
-
return (e = this._adapter) != null && e.capabilities.ads
|
|
662
|
+
return !!((e = this._adapter) != null && e.capabilities.ads);
|
|
633
663
|
}
|
|
634
|
-
/** @returns {
|
|
664
|
+
/** @returns {boolean} */
|
|
635
665
|
hasInterstitialAds() {
|
|
636
666
|
var e;
|
|
637
|
-
return (e = this._adapter) != null && e.capabilities.interstitialAds
|
|
667
|
+
return !!((e = this._adapter) != null && e.capabilities.interstitialAds);
|
|
638
668
|
}
|
|
639
|
-
/** @returns {
|
|
669
|
+
/** @returns {boolean} */
|
|
640
670
|
hasRewardedAds() {
|
|
641
671
|
var e;
|
|
642
|
-
return (e = this._adapter) != null && e.capabilities.rewardedAds
|
|
672
|
+
return !!((e = this._adapter) != null && e.capabilities.rewardedAds);
|
|
643
673
|
}
|
|
644
674
|
/**
|
|
645
675
|
* Track an analytics event.
|
|
646
676
|
* @param {{ category: string, action: string, label?: string }} event
|
|
647
677
|
*/
|
|
648
|
-
analyticsEvent({ category: e, action: a, label:
|
|
649
|
-
this._adapter && this._adapter.trackEvent(e, a,
|
|
678
|
+
analyticsEvent({ category: e, action: a, label: s }) {
|
|
679
|
+
this._adapter && this._adapter.trackEvent(e, a, s);
|
|
650
680
|
}
|
|
651
681
|
login() {
|
|
652
682
|
var e;
|
|
@@ -660,15 +690,15 @@ class A {
|
|
|
660
690
|
var e;
|
|
661
691
|
return (e = this._adapter) != null && e.capabilities.tokens ? this._adapter.getToken() : Promise.resolve(null);
|
|
662
692
|
}
|
|
663
|
-
/** @returns {
|
|
693
|
+
/** @returns {boolean} */
|
|
664
694
|
hasAccounts() {
|
|
665
695
|
var e;
|
|
666
|
-
return (e = this._adapter) != null && e.capabilities.accounts
|
|
696
|
+
return !!((e = this._adapter) != null && e.capabilities.accounts);
|
|
667
697
|
}
|
|
668
|
-
/** @returns {
|
|
698
|
+
/** @returns {boolean} */
|
|
669
699
|
hasToken() {
|
|
670
700
|
var e;
|
|
671
|
-
return (e = this._adapter) != null && e.capabilities.tokens
|
|
701
|
+
return !!((e = this._adapter) != null && e.capabilities.tokens);
|
|
672
702
|
}
|
|
673
703
|
openExternalLink(e) {
|
|
674
704
|
if (!this._adapter || !this._enabled) {
|
|
@@ -678,10 +708,10 @@ class A {
|
|
|
678
708
|
this._adapter.openExternalLink(e);
|
|
679
709
|
}
|
|
680
710
|
}
|
|
681
|
-
const
|
|
711
|
+
const P = new A();
|
|
682
712
|
export {
|
|
683
713
|
c as NetworkAdapter,
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
714
|
+
P as default,
|
|
715
|
+
L as networks,
|
|
716
|
+
x as preventWeirdInputs
|
|
687
717
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
(function(o,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(o=typeof globalThis<"u"?globalThis:o||self,r(o.WebSdkWrapper={}))})(this,(function(o){"use strict";var x=Object.defineProperty;var I=(o,r,c)=>r in o?x(o,r,{enumerable:!0,configurable:!0,writable:!0,value:c}):o[r]=c;var t=(o,r,c)=>I(o,typeof r!="symbol"?r+"":r,c);class r{constructor(){t(this,"name","Unknown");t(this,"capabilities",{ads:!1,interstitialAds:!1,rewardedAds:!1,bannerAds:!1,accounts:!1,tokens:!1});t(this,"scriptSources",[]);t(this,"requiresProduction",!1);t(this,"_sdk",null);t(this,"_gameplayStarted",!1)}async preInit(e){}async init(e){}onLoadingStart(){}onLoadingEnd(){}maybeGameplayStart(){this._gameplayStarted||(this._gameplayStarted=!0,this.onGameplayStart())}maybeGameplayStop(){this._gameplayStarted&&(this._gameplayStarted=!1,this.onGameplayStop())}onGameplayStart(){}onGameplayStop(){}onLevelStart(e){}onReplayLevel(e){}async showInterstitial(){return!1}async showRewarded(e){return!0}login(){return Promise.reject(new Error("Accounts not supported"))}getUser(){return Promise.resolve(null)}getToken(){return Promise.resolve(null)}trackEvent(e,a,n){}openExternalLink(e){window.open(e,"_blank")}}class c extends r{constructor(){super(...arguments);t(this,"name","Poki");t(this,"capabilities",{ads:!0,interstitialAds:!0,rewardedAds:!0,bannerAds:!1,accounts:!0,tokens:!0});t(this,"scriptSources",["https://game-cdn.poki.com/scripts/v2/poki-sdk.js"]);t(this,"requiresProduction",!1);t(this,"_lastBeaconTime",0);t(this,"_maxBeacons",6);t(this,"_beaconInterval",60);t(this,"_gameId",null);t(this,"_doBeacon",!1)}_beacon(a){if(!this._gameId||!this._doBeacon)return;const n=Date.now();n-this._lastBeaconTime<this._beaconInterval*1e3||this._maxBeacons<=0||(this._lastBeaconTime=n,this._maxBeacons--,navigator.sendBeacon(`https://leveldata.poki.io/${a}`,this._gameId))}async init(a){this._sdk=globalThis.PokiSDK,this._sdk.setDebug(a.debug),await this._sdk.init().catch(()=>{});const n=a.data||{};this._gameId=n.poki_gameId,this._doBeacon=n.poki_doBeacon,this._maxBeacons=n.poki_maxBeacons||6,this._beaconInterval=n.poki_beaconInterval||60}onLoadingStart(){this._sdk.gameLoadingStart()}onLoadingEnd(){this._sdk.gameLoadingFinished(),this._beacon("loadingEnd")}onGameplayStart(){this._beacon("gameplayStart"),this._sdk.gameplayStart()}onGameplayStop(){this._beacon("gameplayStop"),this._sdk.gameplayStop()}async showInterstitial(){return this._beacon("interstitial"),await this._sdk.commercialBreak(),!0}async showRewarded(a="small"){return this._beacon("rewarded"),await this._sdk.rewardedBreak({size:a})}login(){return this._sdk.login()}getUser(){return this._sdk.getUser()}getToken(){return this._sdk.getToken()}trackEvent(a,n,i){this._beacon(`${a}_${n}`),this._sdk.measure(a,n,i)}openExternalLink(a){this._sdk&&this._sdk.openExternalLink?this._sdk.openExternalLink(a):super.openExternalLink(a)}}class _ extends r{constructor(){super(...arguments);t(this,"name","CrazyGames");t(this,"capabilities",{ads:!0,interstitialAds:!0,rewardedAds:!0,bannerAds:!0,accounts:!1,tokens:!1});t(this,"scriptSources",["https://sdk.crazygames.com/crazygames-sdk-v1.js"]);t(this,"requiresProduction",!1);t(this,"_lastRequestedAd",null);t(this,"_adResolve",null)}async init(a){var n,i;this._sdk=(i=(n=globalThis==null?void 0:globalThis.CrazyGames)==null?void 0:n.CrazySDK)==null?void 0:i.getInstance(),await new Promise(d=>{this._sdk.addEventListener("adblockDetectionExecuted",()=>{d()}),this._sdk.init()}),this._sdk.addEventListener("adFinished",()=>{this._adResolve&&(this._adResolve(!0),this._adResolve=null)}),this._sdk.addEventListener("adError",()=>{this._adResolve&&(this._adResolve(!1),this._adResolve=null)})}onGameplayStart(){this._sdk.gameplayStart()}onGameplayStop(){this._sdk.gameplayStop()}async showInterstitial(){return new Promise(a=>{this._adResolve=a,this._lastRequestedAd="interstitial",this._sdk.requestAd("midgame")})}async showRewarded(){return new Promise(a=>{this._adResolve=a,this._lastRequestedAd="rewarded",this._sdk.requestAd("rewarded")})}}class g extends r{constructor(){super(...arguments);t(this,"name","CoolMathGames");t(this,"capabilities",{ads:!0,interstitialAds:!0,rewardedAds:!1,bannerAds:!1,accounts:!1,tokens:!1});t(this,"scriptSources",["https://www.coolmathgames.com/sites/default/files/cmg-ads.js"]);t(this,"requiresProduction",!0);t(this,"_adResolve",null)}async init(a){document.addEventListener("adBreakComplete",()=>{this._adResolve&&(this._adResolve(!0),this._adResolve=null)})}onGameplayStart(){parent.cmgGameEvent("start")}onLevelStart(a){parent.cmgGameEvent("start",a.toString())}onReplayLevel(a){parent.cmgGameEvent("replay",a.toString())}async showInterstitial(){return new Promise(a=>{this._adResolve=a,window.cmgAdBreak()})}}class y extends r{constructor(){super(...arguments);t(this,"name","HoodaMath")}}class k extends r{constructor(){super(...arguments);t(this,"name","FreezeNova");t(this,"capabilities",{ads:!0,interstitialAds:!0,rewardedAds:!0,bannerAds:!1,accounts:!1,tokens:!1});t(this,"scriptSources",['https://universal.wgplayer.com/tag/?lh="+window.location.hostname+"&wp="+window.location.pathname+"&ws="+window.location.search']);t(this,"requiresProduction",!0);t(this,"_adResolve",null)}async init(a){const n=a.data||{};window.SubmitLeaderboardScore=function(d){},window.InitExternEval=function(){window.firstInit==null?window.firstInit=1:window.ExternEval()},window.TakeReward=function(){window.adReward=0},window.RewardErrorHandled=function(){window.rewardError=0},window.InitApi=function(d){const l=Math.round(Date.now()/1e3);window.callTime=l-181},window.ExternEval=function(){const d=Math.round(Date.now()/1e3);if(window.callTime!=null&&d-window.callTime>180&&(window.callTime=d,typeof preroll<"u"&&window[preroll.config.loaderObjectName]!=null)){window.adRunning=1;try{window[preroll.config.loaderObjectName].refetchAd(window.ExternEvalResumeGame)}catch(l){console.log(l.message),window.ExternEvalResumeGame()}}},window.ExternEvalResumeGame=function(){window.adRunning=0},window.PreloadRewarded=function(){if(window.rewardedCallbacks==null){window.rewardedCallbacks=!0;try{window[window.preroll.config.loaderObjectName].registerRewardCallbacks({onReady:window.RewardedReady,onSuccess:window.RewardedSuccess,onFail:window.RewardedFail})}catch(d){console.log(d.message)}}},window.ShowRewarded=function(){if(typeof preroll<"u"&&window[preroll.config.loaderObjectName]!=null){window.canReward=0,window.adRunning=1;try{window[preroll.config.loaderObjectName].showRewardAd()}catch(d){console.log(d.message),window.adRunning=0}}},window.RewardedReady=function(){window.rewardedCount==null?(window.rewardedCount=1,window.canReward=1):(window.rewardedCount=window.rewardedCount+1,setTimeout(function(){window.canReward=1},3e4))};const i=this;window.RewardedSuccess=function(){window.adRunning=0,window.adReward=1,i._adResolve&&(i._adResolve(!0),i._adResolve=null)},window.RewardedFail=function(){window.adRunning=0,i._adResolve&&(i._adResolve(!1),i._adResolve=null)},window.OpenLink=function(){},window.adRunning=0,window.adRunningRewarded=0,window.adReward=0,window.rewardError=0,window.canReward=0,window.callTime=0,window.adPlatform=4,window.myLeaderboardScore=0,window.gameLang="en",window.InitApi(n.freezeNova_id||0)}async showInterstitial(){return new Promise(a=>{this._adResolve=a,window.PreloadRewarded(),window.ShowRewarded()})}async showRewarded(){return new Promise(a=>{this._adResolve=a,window.PreloadRewarded(),window.ShowRewarded()})}}class b extends r{constructor(){super(...arguments);t(this,"name","Xiaomi");t(this,"capabilities",{ads:!0,interstitialAds:!0,rewardedAds:!0,bannerAds:!1,accounts:!1,tokens:!1});t(this,"scriptSources",[]);t(this,"requiresProduction",!0);t(this,"_adBreak",null)}async preInit(a){const n=a.data||{},i=document.createElement("script");i.async=!0,i.setAttribute("data-ad-frequency-hint","30s"),i.src=`https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-${n.xiaomi_publisherId}`,i.setAttribute("crossorigin","anonymous"),a.debug&&i.setAttribute("data-adbreak-test","on"),window.adsbygoogle=window.adsbygoogle||[],window.adConfig=function(d){adsbygoogle.push(d)},window.adBreak=window.adConfig,this._adBreak=window.adBreak,document.body.appendChild(i),await new Promise(d=>{i.onload=()=>{if(n.xiaomi_bannerEnabled){const l=document.createElement("ins");l.className="adsbygoogle",l.style.display="block",l.setAttribute("data-ad-client",`ca-${n.xiaomi_publisherId}`),l.setAttribute("data-ad-slot",n.xiaomi_dataAdSlot),l.setAttribute("data-ad-format","auto"),l.setAttribute("data-full-width-responsive","true");const u=n.xiaomi_bannerConainerId||"adSpace";let p=document.getElementById(u);p||(p=document.createElement("div"),p.id=u,document.body.appendChild(p)),p.appendChild(l),(adsbygoogle=window.adsbygoogle||[]).push({})}d()}})}onLoadingStart(){try{funmax&&funmax.loadStart()}catch{console.error("funmax not found")}}onLoadingEnd(){try{funmax&&funmax.loadReady()}catch{console.error("funmax not found")}}async showInterstitial(){return new Promise(a=>{this._adBreak({type:"next",name:"interstitial",beforeAd:()=>{},adBreakDone:()=>{a(!0)}})})}async showRewarded(){return new Promise(a=>{let n=!1;this._adBreak({type:"reward",name:"rewarded",beforeAd:()=>{},adBreakDone:()=>{a(n)},beforeReward:i=>{i()},adDismissed:()=>{n=!1},adViewed:()=>{n=!0}})})}}const m={Poki:c,CrazyGames:_,CoolMathGames:g,HoodaMath:y,FreezeNova:k,Xiaomi:b},S=Object.keys(m),f=new Map;function v(s){if(f.has(s))return f.get(s);const e=new Promise((a,n)=>{const i=document.createElement("script");i.src=s,i.onload=()=>a(),i.onerror=()=>n(new Error(`Failed to load script: ${s}`)),document.head.appendChild(i)});return f.set(s,e),e}const w={};function R(s,e,{once:a=!1}={}){w[s]=w[s]||[],w[s].push({fn:e,once:a})}function h(s,...e){(w[s]||[]).forEach(a=>{a.fn(...e)}),w[s]=(w[s]||[]).filter(a=>!a.once)}function A(){const s=document.createElement("style");s.innerHTML=`
|
|
1
|
+
(function(o,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(o=typeof globalThis<"u"?globalThis:o||self,r(o.WebSdkWrapper={}))})(this,(function(o){"use strict";var x=Object.defineProperty;var P=(o,r,w)=>r in o?x(o,r,{enumerable:!0,configurable:!0,writable:!0,value:w}):o[r]=w;var a=(o,r,w)=>P(o,typeof r!="symbol"?r+"":r,w);const r={};function w(s,e,{once:t=!1}={}){r[s]=r[s]||[],r[s].push({fn:e,once:t})}function h(s,...e){(r[s]||[]).forEach(t=>{t.fn(...e)}),r[s]=(r[s]||[]).filter(t=>!t.once)}class c{constructor(){a(this,"name","Unknown");a(this,"capabilities",{ads:!1,interstitialAds:!1,rewardedAds:!1,bannerAds:!1,accounts:!1,tokens:!1});a(this,"scriptSources",[]);a(this,"requiresProduction",!1);a(this,"_sdk",null);a(this,"_gameplayStarted",!1)}async preInit(e){}async init(e){}onLoadingStart(){}onLoadingEnd(){}onLoadingProgress(e){}maybeGameplayStart(){this._gameplayStarted||(this._gameplayStarted=!0,this.onGameplayStart())}maybeGameplayStop(){this._gameplayStarted&&(this._gameplayStarted=!1,this.onGameplayStop())}onGameplayStart(){}onGameplayStop(){}onLevelStart(e){}onReplayLevel(e){}_dispatchAdStarted(e){h("adStarted",e)}async showInterstitial(){return!1}async showRewarded(e){return!0}login(){return Promise.reject(new Error("Accounts not supported"))}getUser(){return Promise.resolve(null)}getToken(){return Promise.resolve(null)}trackEvent(e,t,i){}openExternalLink(e){window.open(e,"_blank")}}class _ extends c{constructor(){super(...arguments);a(this,"name","Poki");a(this,"capabilities",{ads:!0,interstitialAds:!0,rewardedAds:!0,bannerAds:!1,accounts:!0,tokens:!0});a(this,"scriptSources",["https://game-cdn.poki.com/scripts/v2/poki-sdk.js"]);a(this,"requiresProduction",!1);a(this,"_lastBeaconTime",0);a(this,"_maxBeacons",6);a(this,"_beaconInterval",60);a(this,"_gameId",null);a(this,"_doBeacon",!1)}_beacon(t){if(!this._gameId||!this._doBeacon)return;const i=Date.now();i-this._lastBeaconTime<this._beaconInterval*1e3||this._maxBeacons<=0||(this._lastBeaconTime=i,this._maxBeacons--,navigator.sendBeacon(`https://leveldata.poki.io/${t}`,this._gameId))}async init(t){this._sdk=globalThis.PokiSDK;const i=this._sdk.init().catch(()=>{});this._sdk.setDebug(t.debug),await i;const n=t.data||{};this._gameId=n.poki_gameId,this._doBeacon=n.poki_doBeacon,this._maxBeacons=n.poki_maxBeacons||6,this._beaconInterval=n.poki_beaconInterval||60}onLoadingStart(){this._sdk.gameLoadingStart()}onLoadingEnd(){this._sdk.gameLoadingFinished(),this._beacon("loadingEnd")}onGameplayStart(){this._beacon("gameplayStart"),this._sdk.gameplayStart()}onGameplayStop(){this._beacon("gameplayStop"),this._sdk.gameplayStop()}async showInterstitial(){return this._beacon("interstitial"),this._dispatchAdStarted("interstitial"),await this._sdk.commercialBreak(),!0}async showRewarded(t="small"){return this._beacon("rewarded"),await this._sdk.rewardedBreak({size:t,onStart:()=>{this._dispatchAdStarted("rewarded")}})}login(){return this._sdk.login()}getUser(){return this._sdk.getUser()}getToken(){return this._sdk.getToken()}trackEvent(t,i,n){this._beacon(`${t}_${i}`),this._sdk.measure(t,i,n)}openExternalLink(t){this._sdk&&this._sdk.openExternalLink?this._sdk.openExternalLink(t):super.openExternalLink(t)}}class g extends c{constructor(){super(...arguments);a(this,"name","CrazyGames");a(this,"capabilities",{ads:!0,interstitialAds:!0,rewardedAds:!0,bannerAds:!0,accounts:!1,tokens:!1});a(this,"scriptSources",["https://sdk.crazygames.com/crazygames-sdk-v1.js"]);a(this,"requiresProduction",!1);a(this,"_lastRequestedAd",null);a(this,"_adResolve",null)}async init(t){var i,n;this._sdk=(n=(i=globalThis==null?void 0:globalThis.CrazyGames)==null?void 0:i.CrazySDK)==null?void 0:n.getInstance(),await new Promise(d=>{this._sdk.addEventListener("adblockDetectionExecuted",()=>{d()}),this._sdk.init()}),this._sdk.addEventListener("adStarted",()=>{this._dispatchAdStarted(this._lastRequestedAd)}),this._sdk.addEventListener("adFinished",()=>{this._adResolve&&(this._adResolve(!0),this._adResolve=null)}),this._sdk.addEventListener("adError",()=>{this._adResolve&&(this._adResolve(!1),this._adResolve=null)})}onGameplayStart(){this._sdk.gameplayStart()}onGameplayStop(){this._sdk.gameplayStop()}async showInterstitial(){return new Promise(t=>{this._adResolve=t,this._lastRequestedAd="interstitial",this._sdk.requestAd("midgame")})}async showRewarded(){return new Promise(t=>{this._adResolve=t,this._lastRequestedAd="rewarded",this._sdk.requestAd("rewarded")})}}class y extends c{constructor(){super(...arguments);a(this,"name","CoolMathGames");a(this,"capabilities",{ads:!0,interstitialAds:!0,rewardedAds:!1,bannerAds:!1,accounts:!1,tokens:!1});a(this,"scriptSources",["https://www.coolmathgames.com/sites/default/files/cmg-ads.js"]);a(this,"requiresProduction",!0);a(this,"_adResolve",null)}async init(t){document.addEventListener("adBreakStart",()=>{this._dispatchAdStarted("interstitial")}),document.addEventListener("adBreakComplete",()=>{this._adResolve&&(this._adResolve(!0),this._adResolve=null)})}onGameplayStart(){parent.cmgGameEvent("start")}onLevelStart(t){parent.cmgGameEvent("start",t.toString())}onReplayLevel(t){parent.cmgGameEvent("replay",t.toString())}async showInterstitial(){return new Promise(t=>{this._adResolve=t,window.cmgAdBreak()})}}class k extends c{constructor(){super(...arguments);a(this,"name","HoodaMath")}}class b extends c{constructor(){super(...arguments);a(this,"name","FreezeNova");a(this,"capabilities",{ads:!0,interstitialAds:!0,rewardedAds:!0,bannerAds:!1,accounts:!1,tokens:!1});a(this,"scriptSources",['https://universal.wgplayer.com/tag/?lh="+window.location.hostname+"&wp="+window.location.pathname+"&ws="+window.location.search']);a(this,"requiresProduction",!0);a(this,"_adResolve",null)}async init(t){const i=t.data||{};window.SubmitLeaderboardScore=function(d){},window.InitExternEval=function(){window.firstInit==null?window.firstInit=1:window.ExternEval()},window.TakeReward=function(){window.adReward=0},window.RewardErrorHandled=function(){window.rewardError=0},window.InitApi=function(d){const l=Math.round(Date.now()/1e3);window.callTime=l-181},window.ExternEval=function(){const d=Math.round(Date.now()/1e3);if(window.callTime!=null&&d-window.callTime>180&&(window.callTime=d,typeof preroll<"u"&&window[preroll.config.loaderObjectName]!=null)){window.adRunning=1;try{window[preroll.config.loaderObjectName].refetchAd(window.ExternEvalResumeGame)}catch(l){console.log(l.message),window.ExternEvalResumeGame()}}},window.ExternEvalResumeGame=function(){window.adRunning=0},window.PreloadRewarded=function(){if(window.rewardedCallbacks==null){window.rewardedCallbacks=!0;try{window[window.preroll.config.loaderObjectName].registerRewardCallbacks({onReady:window.RewardedReady,onSuccess:window.RewardedSuccess,onFail:window.RewardedFail})}catch(d){console.log(d.message)}}},window.ShowRewarded=function(){if(typeof preroll<"u"&&window[preroll.config.loaderObjectName]!=null){window.canReward=0,window.adRunning=1;try{window[preroll.config.loaderObjectName].showRewardAd()}catch(d){console.log(d.message),window.adRunning=0}}},window.RewardedReady=function(){window.rewardedCount==null?(window.rewardedCount=1,window.canReward=1):(window.rewardedCount=window.rewardedCount+1,setTimeout(function(){window.canReward=1},3e4))};const n=this;window.RewardedSuccess=function(){window.adRunning=0,window.adReward=1,n._adResolve&&(n._adResolve(!0),n._adResolve=null)},window.RewardedFail=function(){window.adRunning=0,n._adResolve&&(n._adResolve(!1),n._adResolve=null)},window.OpenLink=function(){},window.adRunning=0,window.adRunningRewarded=0,window.adReward=0,window.rewardError=0,window.canReward=0,window.callTime=0,window.adPlatform=4,window.myLeaderboardScore=0,window.gameLang="en",window.InitApi(i.freezeNova_id||0)}async showInterstitial(){return new Promise(t=>{this._adResolve=t,this._dispatchAdStarted("interstitial"),window.PreloadRewarded(),window.ShowRewarded()})}async showRewarded(){return new Promise(t=>{this._adResolve=t,this._dispatchAdStarted("rewarded"),window.PreloadRewarded(),window.ShowRewarded()})}}class S extends c{constructor(){super(...arguments);a(this,"name","Xiaomi");a(this,"capabilities",{ads:!0,interstitialAds:!0,rewardedAds:!0,bannerAds:!1,accounts:!1,tokens:!1});a(this,"scriptSources",null);a(this,"requiresProduction",!0);a(this,"_adBreak",null)}async preInit(t){const i=t.data||{},n=document.createElement("script");n.async=!0,n.setAttribute("data-ad-frequency-hint","30s"),n.src=`https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-${i.xiaomi_publisherId}`,n.setAttribute("crossorigin","anonymous"),t.debug&&n.setAttribute("data-adbreak-test","on"),window.adsbygoogle=window.adsbygoogle||[],window.adConfig=function(d){adsbygoogle.push(d)},window.adBreak=window.adConfig,this._adBreak=window.adBreak,document.body.appendChild(n),await new Promise(d=>{n.onload=()=>{if(i.xiaomi_bannerEnabled){const l=document.createElement("ins");l.className="adsbygoogle",l.style.display="block",l.setAttribute("data-ad-client",`ca-${i.xiaomi_publisherId}`),l.setAttribute("data-ad-slot",i.xiaomi_dataAdSlot),l.setAttribute("data-ad-format","auto"),l.setAttribute("data-full-width-responsive","true");const u=i.xiaomi_bannerConainerId||"adSpace";let p=document.getElementById(u);p||(p=document.createElement("div"),p.id=u,document.body.appendChild(p)),p.appendChild(l),(adsbygoogle=window.adsbygoogle||[]).push({})}d()}})}onLoadingStart(){try{funmax?funmax.loadStart():console.error("funmax not found")}catch{console.error("funmax not found")}}onLoadingEnd(){try{funmax?funmax.loadReady():console.error("funmax not found")}catch{console.error("funmax not found")}}async showInterstitial(){return new Promise(t=>{this._adBreak({type:"next",name:"interstitial",beforeAd:()=>{this._dispatchAdStarted("interstitial")},adBreakDone:()=>{t(!0)}})})}async showRewarded(){return new Promise(t=>{let i=!1;this._adBreak({type:"reward",name:"rewarded",beforeAd:()=>{this._dispatchAdStarted("rewarded")},adBreakDone:()=>{t(i)},beforeReward:n=>{n()},adDismissed:()=>{i=!1},adViewed:()=>{i=!0}})})}}const m={Poki:_,CrazyGames:g,CoolMathGames:y,HoodaMath:k,FreezeNova:b,Xiaomi:S},v=Object.keys(m),f=new Map;function R(s){if(f.has(s))return f.get(s);const e=new Promise((t,i)=>{const n=document.createElement("script");n.src=s,n.onload=()=>t(),n.onerror=()=>i(new Error(`Failed to load script: ${s}`)),document.head.appendChild(n)});return f.set(s,e),e}function A(){const s=document.createElement("style");s.innerHTML=`
|
|
2
2
|
canvas {
|
|
3
3
|
user-select: none !important;
|
|
4
4
|
-webkit-user-select: none !important;
|
|
5
5
|
-moz-user-select: none !important;
|
|
6
6
|
-ms-user-select: none !important;
|
|
7
|
-
}`,document.head.appendChild(s),window.addEventListener("keydown",e=>{["ArrowDown","ArrowUp"," "].includes(e.key)&&e.preventDefault()}),window.addEventListener("wheel",e=>e.preventDefault(),{passive:!1})}class E{constructor(){
|
|
7
|
+
}`,document.head.appendChild(s),window.addEventListener("keydown",e=>{["ArrowDown","ArrowUp"," "].includes(e.key)&&e.preventDefault()}),window.addEventListener("wheel",e=>e.preventDefault(),{passive:!1})}class E{constructor(){a(this,"_adapter",null);a(this,"_enabled",!1)}get enabled(){return this._enabled}get currentSdk(){return this._adapter}async init(e,t=!1,i={}){const n=Object.keys(m).find(u=>u.toLowerCase()===e.toLowerCase()),d=n?m[n]:null;if(!d)return;if(this._adapter=new d,this._adapter.requiresProduction&&t){this._adapter=null;return}this._enabled=!0;const l={debug:t,data:i};if(await this._adapter.preInit(l),this._adapter.scriptSources!==null)for(const u of this._adapter.scriptSources)await R(u);await this._adapter.init(l),this._adapter.scriptSources!==null&&this.loadingStart()}loadingStart(){this._adapter&&(this._adapter.onLoadingStart(),this._adapter.onLoadingProgress(0))}loadingEnd(){this._adapter&&(this._adapter.onLoadingProgress(100),this._adapter.onLoadingEnd())}gameplayStart(){this._adapter&&this._adapter.maybeGameplayStart()}gameplayStop(){this._adapter&&this._adapter.maybeGameplayStop()}levelStart(e){this._adapter&&this._adapter.onLevelStart(e)}replayLevel(e){this._adapter&&this._adapter.onReplayLevel(e)}onUnlockAllLevels(e){window.unlockAllLevels=e}async interstitial(){var i;if(!((i=this._adapter)!=null&&i.capabilities.interstitialAds))return h("adStarted","interstitial"),!1;const e=this._adapter._gameplayStarted;e&&this.gameplayStop();const t=await this._adapter.showInterstitial();return e&&this.gameplayStart(),t}async rewarded(e){var n;if(!((n=this._adapter)!=null&&n.capabilities.rewardedAds))return h("adStarted","rewarded"),!0;const t=this._adapter._gameplayStarted;t&&this.gameplayStop();const i=await this._adapter.showRewarded(e);return t&&this.gameplayStart(),i}onAdStarted(e){w("adStarted",e)}hasAds(){var e;return!!((e=this._adapter)!=null&&e.capabilities.ads)}hasInterstitialAds(){var e;return!!((e=this._adapter)!=null&&e.capabilities.interstitialAds)}hasRewardedAds(){var e;return!!((e=this._adapter)!=null&&e.capabilities.rewardedAds)}analyticsEvent({category:e,action:t,label:i}){this._adapter&&this._adapter.trackEvent(e,t,i)}login(){var e;return(e=this._adapter)!=null&&e.capabilities.accounts?this._adapter.login():Promise.reject(new Error("Accounts not supported"))}getUser(){var e;return(e=this._adapter)!=null&&e.capabilities.accounts?this._adapter.getUser():Promise.resolve(null)}getToken(){var e;return(e=this._adapter)!=null&&e.capabilities.tokens?this._adapter.getToken():Promise.resolve(null)}hasAccounts(){var e;return!!((e=this._adapter)!=null&&e.capabilities.accounts)}hasToken(){var e;return!!((e=this._adapter)!=null&&e.capabilities.tokens)}openExternalLink(e){if(!this._adapter||!this._enabled){window.open(e,"_blank");return}this._adapter.openExternalLink(e)}}const L=new E;o.NetworkAdapter=c,o.default=L,o.networks=v,o.preventWeirdInputs=A,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import registry from "./networks/index.js";
|
|
2
2
|
import { loadScript } from "./script-loader.js";
|
|
3
|
-
import { listen,
|
|
3
|
+
import { listen, dispatch } from "./event-emitter.js";
|
|
4
4
|
|
|
5
5
|
export { preventWeirdInputs } from "./utils.js";
|
|
6
6
|
export { NetworkAdapter } from "./networks/base.js";
|
|
@@ -50,33 +50,45 @@ class Wrapper {
|
|
|
50
50
|
this._adapter = new AdapterClass();
|
|
51
51
|
|
|
52
52
|
if (this._adapter.requiresProduction && debug) {
|
|
53
|
+
this._adapter = null;
|
|
53
54
|
return;
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
this._enabled = true;
|
|
58
|
+
|
|
57
59
|
const options = { debug, data };
|
|
58
60
|
|
|
59
61
|
// preInit (before scripts load)
|
|
60
62
|
await this._adapter.preInit(options);
|
|
61
63
|
|
|
62
|
-
// Load SDK scripts
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
// Load SDK scripts (skipped when scriptSources is null — adapter handles its own loading in preInit)
|
|
65
|
+
if (this._adapter.scriptSources !== null) {
|
|
66
|
+
for (const src of this._adapter.scriptSources) {
|
|
67
|
+
await loadScript(src);
|
|
68
|
+
}
|
|
65
69
|
}
|
|
66
70
|
|
|
67
71
|
// Init adapter (after scripts are loaded)
|
|
68
72
|
await this._adapter.init(options);
|
|
69
73
|
|
|
70
|
-
// Signal loading started
|
|
71
|
-
this.
|
|
74
|
+
// Signal loading started (only when scripts were loaded by the Wrapper)
|
|
75
|
+
if (this._adapter.scriptSources !== null) {
|
|
76
|
+
this.loadingStart();
|
|
77
|
+
}
|
|
72
78
|
}
|
|
73
79
|
|
|
74
80
|
loadingStart() {
|
|
75
|
-
if (this._adapter)
|
|
81
|
+
if (this._adapter) {
|
|
82
|
+
this._adapter.onLoadingStart();
|
|
83
|
+
this._adapter.onLoadingProgress(0);
|
|
84
|
+
}
|
|
76
85
|
}
|
|
77
86
|
|
|
78
87
|
loadingEnd() {
|
|
79
|
-
if (this._adapter)
|
|
88
|
+
if (this._adapter) {
|
|
89
|
+
this._adapter.onLoadingProgress(100);
|
|
90
|
+
this._adapter.onLoadingEnd();
|
|
91
|
+
}
|
|
80
92
|
}
|
|
81
93
|
|
|
82
94
|
gameplayStart() {
|
|
@@ -112,7 +124,6 @@ class Wrapper {
|
|
|
112
124
|
const wasPlaying = this._adapter._gameplayStarted;
|
|
113
125
|
if (wasPlaying) this.gameplayStop();
|
|
114
126
|
|
|
115
|
-
dispatch("adStarted", "interstitial");
|
|
116
127
|
const success = await this._adapter.showInterstitial();
|
|
117
128
|
|
|
118
129
|
if (wasPlaying) this.gameplayStart();
|
|
@@ -133,7 +144,6 @@ class Wrapper {
|
|
|
133
144
|
const wasPlaying = this._adapter._gameplayStarted;
|
|
134
145
|
if (wasPlaying) this.gameplayStop();
|
|
135
146
|
|
|
136
|
-
dispatch("adStarted", "rewarded");
|
|
137
147
|
const success = await this._adapter.showRewarded(size);
|
|
138
148
|
|
|
139
149
|
if (wasPlaying) this.gameplayStart();
|
|
@@ -148,19 +158,19 @@ class Wrapper {
|
|
|
148
158
|
listen("adStarted", fn);
|
|
149
159
|
}
|
|
150
160
|
|
|
151
|
-
/** @returns {
|
|
161
|
+
/** @returns {boolean} */
|
|
152
162
|
hasAds() {
|
|
153
|
-
return this._adapter?.capabilities.ads
|
|
163
|
+
return !!this._adapter?.capabilities.ads;
|
|
154
164
|
}
|
|
155
165
|
|
|
156
|
-
/** @returns {
|
|
166
|
+
/** @returns {boolean} */
|
|
157
167
|
hasInterstitialAds() {
|
|
158
|
-
return this._adapter?.capabilities.interstitialAds
|
|
168
|
+
return !!this._adapter?.capabilities.interstitialAds;
|
|
159
169
|
}
|
|
160
170
|
|
|
161
|
-
/** @returns {
|
|
171
|
+
/** @returns {boolean} */
|
|
162
172
|
hasRewardedAds() {
|
|
163
|
-
return this._adapter?.capabilities.rewardedAds
|
|
173
|
+
return !!this._adapter?.capabilities.rewardedAds;
|
|
164
174
|
}
|
|
165
175
|
|
|
166
176
|
/**
|
|
@@ -192,14 +202,14 @@ class Wrapper {
|
|
|
192
202
|
return this._adapter.getToken();
|
|
193
203
|
}
|
|
194
204
|
|
|
195
|
-
/** @returns {
|
|
205
|
+
/** @returns {boolean} */
|
|
196
206
|
hasAccounts() {
|
|
197
|
-
return this._adapter?.capabilities.accounts
|
|
207
|
+
return !!this._adapter?.capabilities.accounts;
|
|
198
208
|
}
|
|
199
209
|
|
|
200
|
-
/** @returns {
|
|
210
|
+
/** @returns {boolean} */
|
|
201
211
|
hasToken() {
|
|
202
|
-
return this._adapter?.capabilities.tokens
|
|
212
|
+
return !!this._adapter?.capabilities.tokens;
|
|
203
213
|
}
|
|
204
214
|
|
|
205
215
|
openExternalLink(url) {
|
package/src/networks/base.js
CHANGED
|
@@ -48,6 +48,8 @@
|
|
|
48
48
|
* @method trackEvent - Track an analytics event
|
|
49
49
|
* @method openExternalLink - Open a URL (default: window.open)
|
|
50
50
|
*/
|
|
51
|
+
import { dispatch } from "../event-emitter.js";
|
|
52
|
+
|
|
51
53
|
export class NetworkAdapter {
|
|
52
54
|
/** @type {string} */
|
|
53
55
|
name = "Unknown";
|
|
@@ -71,7 +73,7 @@ export class NetworkAdapter {
|
|
|
71
73
|
tokens: false,
|
|
72
74
|
};
|
|
73
75
|
|
|
74
|
-
/** @type {string[]} SDK script URLs to load before init */
|
|
76
|
+
/** @type {string[]|null} SDK script URLs to load before init. Set to null to handle script loading in preInit. */
|
|
75
77
|
scriptSources = [];
|
|
76
78
|
|
|
77
79
|
/** @type {boolean} If true, adapter is disabled when debug=true */
|
|
@@ -107,6 +109,12 @@ export class NetworkAdapter {
|
|
|
107
109
|
/** Called when the game finishes loading. */
|
|
108
110
|
onLoadingEnd() {}
|
|
109
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Called with loading progress updates.
|
|
114
|
+
* @param {number} progress - 0 to 100
|
|
115
|
+
*/
|
|
116
|
+
onLoadingProgress(progress) {}
|
|
117
|
+
|
|
110
118
|
/**
|
|
111
119
|
* Handles duplicate-call gating for gameplay start.
|
|
112
120
|
* Do NOT override this — override onGameplayStart() instead.
|
|
@@ -157,6 +165,15 @@ export class NetworkAdapter {
|
|
|
157
165
|
// Ads
|
|
158
166
|
// ========================
|
|
159
167
|
|
|
168
|
+
/**
|
|
169
|
+
* Dispatch the "adStarted" event. Call this from your ad methods
|
|
170
|
+
* at the moment the ad actually starts (e.g. inside an SDK callback).
|
|
171
|
+
* @param {"interstitial"|"rewarded"} type
|
|
172
|
+
*/
|
|
173
|
+
_dispatchAdStarted(type) {
|
|
174
|
+
dispatch("adStarted", type);
|
|
175
|
+
}
|
|
176
|
+
|
|
160
177
|
/**
|
|
161
178
|
* Show an interstitial ad.
|
|
162
179
|
* @returns {Promise<boolean>} Whether the ad was shown successfully
|
|
@@ -23,6 +23,10 @@ export class CoolMathGamesAdapter extends NetworkAdapter {
|
|
|
23
23
|
|
|
24
24
|
async init(options) {
|
|
25
25
|
// CMG SDK is loaded via script tag and uses document events + parent.cmgGameEvent
|
|
26
|
+
document.addEventListener("adBreakStart", () => {
|
|
27
|
+
this._dispatchAdStarted("interstitial");
|
|
28
|
+
});
|
|
29
|
+
|
|
26
30
|
document.addEventListener("adBreakComplete", () => {
|
|
27
31
|
if (this._adResolve) {
|
|
28
32
|
this._adResolve(true);
|
|
@@ -33,6 +33,10 @@ export class CrazyGamesAdapter extends NetworkAdapter {
|
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
// Set up SDK event listeners once
|
|
36
|
+
this._sdk.addEventListener("adStarted", () => {
|
|
37
|
+
this._dispatchAdStarted(this._lastRequestedAd);
|
|
38
|
+
});
|
|
39
|
+
|
|
36
40
|
this._sdk.addEventListener("adFinished", () => {
|
|
37
41
|
if (this._adResolve) {
|
|
38
42
|
this._adResolve(true);
|
|
@@ -160,6 +160,7 @@ export class FreezeNovaAdapter extends NetworkAdapter {
|
|
|
160
160
|
async showInterstitial() {
|
|
161
161
|
return new Promise((resolve) => {
|
|
162
162
|
this._adResolve = resolve;
|
|
163
|
+
this._dispatchAdStarted("interstitial");
|
|
163
164
|
window.PreloadRewarded();
|
|
164
165
|
window.ShowRewarded();
|
|
165
166
|
});
|
|
@@ -168,6 +169,7 @@ export class FreezeNovaAdapter extends NetworkAdapter {
|
|
|
168
169
|
async showRewarded() {
|
|
169
170
|
return new Promise((resolve) => {
|
|
170
171
|
this._adResolve = resolve;
|
|
172
|
+
this._dispatchAdStarted("rewarded");
|
|
171
173
|
window.PreloadRewarded();
|
|
172
174
|
window.ShowRewarded();
|
|
173
175
|
});
|
package/src/networks/poki.js
CHANGED
|
@@ -40,8 +40,10 @@ export class PokiAdapter extends NetworkAdapter {
|
|
|
40
40
|
|
|
41
41
|
async init(options) {
|
|
42
42
|
this._sdk = globalThis.PokiSDK;
|
|
43
|
+
// V1 order: start init() first, then call setDebug while init is in-flight
|
|
44
|
+
const initPromise = this._sdk.init().catch(() => {});
|
|
43
45
|
this._sdk.setDebug(options.debug);
|
|
44
|
-
await
|
|
46
|
+
await initPromise;
|
|
45
47
|
|
|
46
48
|
// Beacon config from data
|
|
47
49
|
const data = options.data || {};
|
|
@@ -72,13 +74,19 @@ export class PokiAdapter extends NetworkAdapter {
|
|
|
72
74
|
|
|
73
75
|
async showInterstitial() {
|
|
74
76
|
this._beacon("interstitial");
|
|
77
|
+
this._dispatchAdStarted("interstitial");
|
|
75
78
|
await this._sdk.commercialBreak();
|
|
76
79
|
return true;
|
|
77
80
|
}
|
|
78
81
|
|
|
79
82
|
async showRewarded(size = "small") {
|
|
80
83
|
this._beacon("rewarded");
|
|
81
|
-
const success = await this._sdk.rewardedBreak({
|
|
84
|
+
const success = await this._sdk.rewardedBreak({
|
|
85
|
+
size,
|
|
86
|
+
onStart: () => {
|
|
87
|
+
this._dispatchAdStarted("rewarded");
|
|
88
|
+
},
|
|
89
|
+
});
|
|
82
90
|
return success;
|
|
83
91
|
}
|
|
84
92
|
|
package/src/networks/xiaomi.js
CHANGED
|
@@ -13,7 +13,7 @@ export class XiaomiAdapter extends NetworkAdapter {
|
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
// Scripts are loaded manually in preInit, not via the standard loader
|
|
16
|
-
scriptSources =
|
|
16
|
+
scriptSources = null;
|
|
17
17
|
|
|
18
18
|
requiresProduction = true;
|
|
19
19
|
|
|
@@ -75,6 +75,7 @@ export class XiaomiAdapter extends NetworkAdapter {
|
|
|
75
75
|
onLoadingStart() {
|
|
76
76
|
try {
|
|
77
77
|
if (funmax) funmax.loadStart();
|
|
78
|
+
else console.error("funmax not found");
|
|
78
79
|
} catch (e) {
|
|
79
80
|
console.error("funmax not found");
|
|
80
81
|
}
|
|
@@ -83,6 +84,7 @@ export class XiaomiAdapter extends NetworkAdapter {
|
|
|
83
84
|
onLoadingEnd() {
|
|
84
85
|
try {
|
|
85
86
|
if (funmax) funmax.loadReady();
|
|
87
|
+
else console.error("funmax not found");
|
|
86
88
|
} catch (e) {
|
|
87
89
|
console.error("funmax not found");
|
|
88
90
|
}
|
|
@@ -93,7 +95,9 @@ export class XiaomiAdapter extends NetworkAdapter {
|
|
|
93
95
|
this._adBreak({
|
|
94
96
|
type: "next",
|
|
95
97
|
name: "interstitial",
|
|
96
|
-
beforeAd: () => {
|
|
98
|
+
beforeAd: () => {
|
|
99
|
+
this._dispatchAdStarted("interstitial");
|
|
100
|
+
},
|
|
97
101
|
adBreakDone: () => {
|
|
98
102
|
resolve(true);
|
|
99
103
|
},
|
|
@@ -107,7 +111,9 @@ export class XiaomiAdapter extends NetworkAdapter {
|
|
|
107
111
|
this._adBreak({
|
|
108
112
|
type: "reward",
|
|
109
113
|
name: "rewarded",
|
|
110
|
-
beforeAd: () => {
|
|
114
|
+
beforeAd: () => {
|
|
115
|
+
this._dispatchAdStarted("rewarded");
|
|
116
|
+
},
|
|
111
117
|
adBreakDone: () => {
|
|
112
118
|
resolve(rewardEarned);
|
|
113
119
|
},
|