@smoud/playable-sdk 1.0.5 → 1.0.7
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 +1 -1
- package/defines.d.ts +4 -8
- package/dist/esm/index.js +599 -2
- package/dist/iife/index.js +1 -2
- package/dist/{esm/core.d.ts → index.d.mts} +4 -2
- package/dist/index.d.ts +176 -0
- package/dist/index.js +1 -2
- package/package.json +3 -4
- package/dist/esm/core.js +0 -517
- package/dist/esm/events.d.ts +0 -4
- package/dist/esm/events.js +0 -58
- package/dist/esm/index.d.ts +0 -2
- package/dist/esm/protocols.d.ts +0 -9
- package/dist/esm/protocols.js +0 -77
package/README.md
CHANGED
|
@@ -400,7 +400,7 @@ sdk.off('eventName', [callback], [context]);
|
|
|
400
400
|
- [Facebook Playable Preview Tool](https://developers.facebook.com/tools/playable-preview/)
|
|
401
401
|
- [Google HTML5 Validator](https://h5validator.appspot.com/adwords/asset)
|
|
402
402
|
- [IronSource Integration Validation](https://developers.is.com/ironsource-mobile/general/test-suite/)
|
|
403
|
-
- [Mintegral Testing Tool](https://www.playturbo.com/review
|
|
403
|
+
- [Mintegral Testing Tool](https://www.playturbo.com/review)
|
|
404
404
|
|
|
405
405
|
## Issues
|
|
406
406
|
|
package/defines.d.ts
CHANGED
|
@@ -65,10 +65,6 @@ declare const GOOGLE_PLAY_URL: string;
|
|
|
65
65
|
declare const APP_STORE_URL: string;
|
|
66
66
|
declare const BUILD_HASH: string;
|
|
67
67
|
|
|
68
|
-
// Mintegral functions
|
|
69
|
-
declare const gameStart: Function;
|
|
70
|
-
declare const gameClose: Function;
|
|
71
|
-
|
|
72
68
|
interface Window {
|
|
73
69
|
PlayableSDK: any;
|
|
74
70
|
|
|
@@ -77,8 +73,8 @@ interface Window {
|
|
|
77
73
|
gameEnd: Function;
|
|
78
74
|
gameRetry: Function;
|
|
79
75
|
install: Function;
|
|
80
|
-
mintGameStart: Function
|
|
81
|
-
mintGameClose: Function
|
|
76
|
+
mintGameStart: Function;
|
|
77
|
+
mintGameClose: Function;
|
|
82
78
|
|
|
83
79
|
// Tapjoy functions
|
|
84
80
|
TJ_API: {
|
|
@@ -86,9 +82,9 @@ interface Window {
|
|
|
86
82
|
playableFinished: Function;
|
|
87
83
|
gameplayFinished: Function;
|
|
88
84
|
setPlayableBuild: Function;
|
|
89
|
-
setPlayableAPI: Function
|
|
85
|
+
setPlayableAPI: Function;
|
|
90
86
|
click: Function;
|
|
91
87
|
};
|
|
92
|
-
|
|
88
|
+
|
|
93
89
|
openAppStore: Function;
|
|
94
90
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1,599 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/events.ts
|
|
2
|
+
var registeredEvents = {};
|
|
3
|
+
function onEvent(event, fn, context, once) {
|
|
4
|
+
let listeners = registeredEvents[event];
|
|
5
|
+
if (!listeners) {
|
|
6
|
+
listeners = registeredEvents[event] = {
|
|
7
|
+
list: []
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
listeners.list.push(fn, context || null, once || false);
|
|
11
|
+
}
|
|
12
|
+
function offEvent(event, fn, context) {
|
|
13
|
+
const listeners = registeredEvents[event];
|
|
14
|
+
if (!listeners) return;
|
|
15
|
+
var fnArray = listeners.list;
|
|
16
|
+
if (!fn) {
|
|
17
|
+
fnArray.length = 0;
|
|
18
|
+
} else {
|
|
19
|
+
let i = fnArray.length;
|
|
20
|
+
while (i > 0) {
|
|
21
|
+
i -= 3;
|
|
22
|
+
if (fnArray[i] == fn && (context !== void 0 || fnArray[i + 1] == context)) {
|
|
23
|
+
fnArray.splice(i, 3);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (fnArray.length == 0) {
|
|
28
|
+
delete registeredEvents[event];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function emitEvent(event, a1, a2, a3) {
|
|
32
|
+
var listeners = registeredEvents[event];
|
|
33
|
+
if (!listeners) return;
|
|
34
|
+
const fnArray = listeners.list;
|
|
35
|
+
const len = arguments.length;
|
|
36
|
+
let fn, ctx;
|
|
37
|
+
for (var i = 0; i < fnArray.length; i += 3) {
|
|
38
|
+
fn = fnArray[i];
|
|
39
|
+
ctx = fnArray[i + 1];
|
|
40
|
+
if (fnArray[i + 2]) {
|
|
41
|
+
fnArray.splice(i, 3);
|
|
42
|
+
i -= 3;
|
|
43
|
+
}
|
|
44
|
+
if (len <= 1) fn.call(ctx);
|
|
45
|
+
else if (len == 2) fn.call(ctx, a1);
|
|
46
|
+
else if (len == 3) fn.call(ctx, a1, a2);
|
|
47
|
+
else fn.call(ctx, a1, a2, a3);
|
|
48
|
+
}
|
|
49
|
+
if (fnArray.length == 0) {
|
|
50
|
+
delete registeredEvents[event];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/protocols.ts
|
|
55
|
+
var uid = 0;
|
|
56
|
+
var NONE = uid++;
|
|
57
|
+
var MRAID = uid++;
|
|
58
|
+
var DAPI = uid++;
|
|
59
|
+
var NUCLEO = uid++;
|
|
60
|
+
var FACEBOOK = uid++;
|
|
61
|
+
var GOOGLE = uid++;
|
|
62
|
+
var MINTEGRAL = uid++;
|
|
63
|
+
var TAPJOY = uid++;
|
|
64
|
+
var TIKTOK = uid++;
|
|
65
|
+
var actualProtocol = NONE;
|
|
66
|
+
function isMraid() {
|
|
67
|
+
return actualProtocol === MRAID;
|
|
68
|
+
}
|
|
69
|
+
function isDapi() {
|
|
70
|
+
return actualProtocol === DAPI;
|
|
71
|
+
}
|
|
72
|
+
function isNucleo() {
|
|
73
|
+
return actualProtocol === NUCLEO;
|
|
74
|
+
}
|
|
75
|
+
function isFacebook() {
|
|
76
|
+
return actualProtocol === FACEBOOK;
|
|
77
|
+
}
|
|
78
|
+
function isGoogle() {
|
|
79
|
+
return actualProtocol === GOOGLE;
|
|
80
|
+
}
|
|
81
|
+
function isMintegral() {
|
|
82
|
+
return actualProtocol === MINTEGRAL;
|
|
83
|
+
}
|
|
84
|
+
function isTapjoy() {
|
|
85
|
+
return actualProtocol === TAPJOY;
|
|
86
|
+
}
|
|
87
|
+
function isTikTok() {
|
|
88
|
+
return actualProtocol === TIKTOK;
|
|
89
|
+
}
|
|
90
|
+
function ensureProtocol() {
|
|
91
|
+
if ("mraid" === AD_PROTOCOL) {
|
|
92
|
+
try {
|
|
93
|
+
mraid.getState();
|
|
94
|
+
actualProtocol = MRAID;
|
|
95
|
+
} catch (error) {
|
|
96
|
+
}
|
|
97
|
+
} else if ("dapi" === AD_PROTOCOL) {
|
|
98
|
+
try {
|
|
99
|
+
dapi.isReady();
|
|
100
|
+
actualProtocol = DAPI;
|
|
101
|
+
} catch (error) {
|
|
102
|
+
}
|
|
103
|
+
} else if ("facebook" === AD_NETWORK) {
|
|
104
|
+
try {
|
|
105
|
+
if (FbPlayableAd) actualProtocol = FACEBOOK;
|
|
106
|
+
} catch (error) {
|
|
107
|
+
}
|
|
108
|
+
} else if ("google" === AD_NETWORK) {
|
|
109
|
+
try {
|
|
110
|
+
if (ExitApi) actualProtocol = GOOGLE;
|
|
111
|
+
} catch (error) {
|
|
112
|
+
}
|
|
113
|
+
} else if ("mintegral" === AD_NETWORK) {
|
|
114
|
+
if (window.gameReady) actualProtocol = MINTEGRAL;
|
|
115
|
+
} else if ("tapjoy" === AD_NETWORK) {
|
|
116
|
+
if (window.TJ_API) actualProtocol = TAPJOY;
|
|
117
|
+
} else if ("tiktok" === AD_NETWORK) {
|
|
118
|
+
if (window.openAppStore) actualProtocol = TIKTOK;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// src/core.ts
|
|
123
|
+
var destinationUrl = /android/i.test(navigator.userAgent) ? GOOGLE_PLAY_URL : APP_STORE_URL;
|
|
124
|
+
var isSDKInitialized = false;
|
|
125
|
+
var isProtocolInitialized = false;
|
|
126
|
+
var isForcePaused = false;
|
|
127
|
+
var isInstallClicked = false;
|
|
128
|
+
var initCallback = () => {
|
|
129
|
+
};
|
|
130
|
+
function bootAd() {
|
|
131
|
+
if (sdk.isReady) return;
|
|
132
|
+
emitEvent("boot");
|
|
133
|
+
document.body.oncontextmenu = function() {
|
|
134
|
+
return false;
|
|
135
|
+
};
|
|
136
|
+
initCallback(sdk.maxWidth, sdk.maxHeight);
|
|
137
|
+
emitEvent("ready");
|
|
138
|
+
sdk.isReady = true;
|
|
139
|
+
}
|
|
140
|
+
function changeVolume(value) {
|
|
141
|
+
emitEvent("volume", value);
|
|
142
|
+
}
|
|
143
|
+
function handlePause() {
|
|
144
|
+
changeVolume(0);
|
|
145
|
+
sdk.isPaused = true;
|
|
146
|
+
emitEvent("pause");
|
|
147
|
+
}
|
|
148
|
+
function handleResume() {
|
|
149
|
+
if (isForcePaused) return;
|
|
150
|
+
changeVolume(sdk.volume);
|
|
151
|
+
sdk.isPaused = false;
|
|
152
|
+
emitEvent("resume");
|
|
153
|
+
}
|
|
154
|
+
function mraidIsViewable(viewable) {
|
|
155
|
+
if ("mraid" !== AD_PROTOCOL) return;
|
|
156
|
+
if (viewable) {
|
|
157
|
+
if (sdk.isReady) {
|
|
158
|
+
handleResume();
|
|
159
|
+
} else {
|
|
160
|
+
if (AD_NETWORK == "ironsource") {
|
|
161
|
+
const maxSize = mraid.getMaxSize();
|
|
162
|
+
sdk.maxWidth = Math.floor(maxSize.width);
|
|
163
|
+
sdk.maxHeight = Math.floor(maxSize.height);
|
|
164
|
+
}
|
|
165
|
+
bootAd();
|
|
166
|
+
}
|
|
167
|
+
} else {
|
|
168
|
+
handlePause();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function dapiIsViewable(event) {
|
|
172
|
+
if ("dapi" !== AD_PROTOCOL) return;
|
|
173
|
+
if (event.isViewable) {
|
|
174
|
+
if (sdk.isReady) {
|
|
175
|
+
handleResume();
|
|
176
|
+
} else {
|
|
177
|
+
var screenSize = dapi.getScreenSize();
|
|
178
|
+
screenSize.width = Math.floor(screenSize.width);
|
|
179
|
+
screenSize.height = Math.floor(screenSize.height);
|
|
180
|
+
bootAd();
|
|
181
|
+
}
|
|
182
|
+
} else {
|
|
183
|
+
handlePause();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function fireResizeEvent(width, height) {
|
|
187
|
+
handleResize(width, height);
|
|
188
|
+
}
|
|
189
|
+
function startMraidProtocol() {
|
|
190
|
+
if ("mraid" !== AD_PROTOCOL) return;
|
|
191
|
+
if (!isProtocolInitialized) {
|
|
192
|
+
mraid.removeEventListener("ready", startMraidProtocol);
|
|
193
|
+
mraid.addEventListener("viewableChange", function() {
|
|
194
|
+
var isViewable = mraid.isViewable();
|
|
195
|
+
mraidIsViewable(isViewable);
|
|
196
|
+
});
|
|
197
|
+
if (mraid.isViewable() || AD_NETWORK == "adcolony") {
|
|
198
|
+
mraidIsViewable(true);
|
|
199
|
+
}
|
|
200
|
+
mraid.addEventListener("audioVolumeChange", function(newVolume) {
|
|
201
|
+
if (newVolume !== null) {
|
|
202
|
+
if (newVolume > 0) {
|
|
203
|
+
changeVolume(sdk.volume);
|
|
204
|
+
} else {
|
|
205
|
+
changeVolume(0);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
mraid.addEventListener("error", function(t, e) {
|
|
210
|
+
console.log("mraid error: " + t + " action: " + e);
|
|
211
|
+
});
|
|
212
|
+
mraid.addEventListener("sizeChange", function() {
|
|
213
|
+
var maxSize = mraid.getMaxSize();
|
|
214
|
+
fireResizeEvent(maxSize.width, maxSize.height);
|
|
215
|
+
});
|
|
216
|
+
isProtocolInitialized = true;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function startDapiProtocol() {
|
|
220
|
+
if ("dapi" !== AD_PROTOCOL) return;
|
|
221
|
+
if (!isProtocolInitialized) {
|
|
222
|
+
dapi.removeEventListener("ready", startDapiProtocol);
|
|
223
|
+
dapi.getAudioVolume();
|
|
224
|
+
dapi.addEventListener("audioVolumeChange", function(volume) {
|
|
225
|
+
var isAudioEnabled = !!volume;
|
|
226
|
+
if (isAudioEnabled) {
|
|
227
|
+
changeVolume(sdk.volume);
|
|
228
|
+
} else {
|
|
229
|
+
changeVolume(0);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
dapi.addEventListener("adResized", function(event) {
|
|
233
|
+
var maxSize = dapi.getScreenSize();
|
|
234
|
+
fireResizeEvent(event.width || maxSize.width, event.height || maxSize.height);
|
|
235
|
+
});
|
|
236
|
+
if (dapi.isViewable()) {
|
|
237
|
+
dapiIsViewable({ isViewable: true });
|
|
238
|
+
}
|
|
239
|
+
dapi.addEventListener("viewableChange", dapiIsViewable);
|
|
240
|
+
isProtocolInitialized = true;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
function startDefaultProtocol() {
|
|
244
|
+
if ("none" !== AD_PROTOCOL) return;
|
|
245
|
+
if (!isProtocolInitialized) {
|
|
246
|
+
if ("mintegral" === AD_NETWORK) {
|
|
247
|
+
window.mintGameStart = function() {
|
|
248
|
+
handleResume();
|
|
249
|
+
handleResize(sdk.maxWidth, sdk.maxHeight);
|
|
250
|
+
};
|
|
251
|
+
window.mintGameClose = function() {
|
|
252
|
+
handlePause();
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
document.addEventListener("visibilitychange", () => {
|
|
256
|
+
if (document.visibilityState === "visible") {
|
|
257
|
+
handleResume();
|
|
258
|
+
} else {
|
|
259
|
+
handlePause();
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
if (document.readyState === "complete") {
|
|
263
|
+
bootAd();
|
|
264
|
+
} else {
|
|
265
|
+
window.addEventListener("load", () => {
|
|
266
|
+
bootAd();
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
window.addEventListener("resize", function() {
|
|
270
|
+
handleResize();
|
|
271
|
+
});
|
|
272
|
+
if ("tapjoy" === AD_NETWORK && isTapjoy()) {
|
|
273
|
+
var tapjoyApi = {
|
|
274
|
+
skipAd: function() {
|
|
275
|
+
try {
|
|
276
|
+
sdk.finish();
|
|
277
|
+
} catch (e) {
|
|
278
|
+
console.warn("Could not skip ad! | " + e);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
window.TJ_API.setPlayableAPI && window.TJ_API.setPlayableAPI(tapjoyApi);
|
|
283
|
+
}
|
|
284
|
+
isProtocolInitialized = true;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function finishTapjoy() {
|
|
288
|
+
window.TJ_API.objectiveComplete && window.TJ_API.objectiveComplete();
|
|
289
|
+
window.TJ_API.playableFinished && window.TJ_API.playableFinished();
|
|
290
|
+
window.TJ_API.gameplayFinished && window.TJ_API.gameplayFinished();
|
|
291
|
+
}
|
|
292
|
+
function handleResize(width, height) {
|
|
293
|
+
sdk.maxWidth = Math.floor(width || window.innerWidth);
|
|
294
|
+
sdk.maxHeight = Math.floor(height || window.innerHeight);
|
|
295
|
+
sdk.isLandscape = sdk.maxWidth > sdk.maxHeight;
|
|
296
|
+
emitEvent("resize", sdk.maxWidth, sdk.maxHeight);
|
|
297
|
+
}
|
|
298
|
+
var isListeningToTouchEvents = false;
|
|
299
|
+
var isTouchEventRegistered = false;
|
|
300
|
+
function onUserInteraction(event) {
|
|
301
|
+
if (typeof TouchEvent !== "undefined" && event instanceof TouchEvent) {
|
|
302
|
+
isListeningToTouchEvents = true;
|
|
303
|
+
}
|
|
304
|
+
if (isListeningToTouchEvents && event instanceof MouseEvent) return;
|
|
305
|
+
sdk.interactions += 1;
|
|
306
|
+
emitEvent("interaction", sdk.interactions);
|
|
307
|
+
}
|
|
308
|
+
function registerTouchHandlers() {
|
|
309
|
+
if (!isTouchEventRegistered) {
|
|
310
|
+
document.addEventListener("mousedown", onUserInteraction);
|
|
311
|
+
document.addEventListener("touchstart", onUserInteraction);
|
|
312
|
+
isTouchEventRegistered = true;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
var _sdk = class _sdk {
|
|
316
|
+
/**
|
|
317
|
+
* Initializes the SDK and sets up protocol-specific handlers.
|
|
318
|
+
* This must be called as earlier as possible.
|
|
319
|
+
*
|
|
320
|
+
* @param callback Optional function called when ad container is ready
|
|
321
|
+
* @example
|
|
322
|
+
* // Basic initialization
|
|
323
|
+
* sdk.init();
|
|
324
|
+
*
|
|
325
|
+
* // Initialization with callback
|
|
326
|
+
* sdk.init((width, height) => {
|
|
327
|
+
* new App(width, height)
|
|
328
|
+
* });
|
|
329
|
+
*
|
|
330
|
+
* @fires init When initialization starts
|
|
331
|
+
* @fires boot When the ad begins booting
|
|
332
|
+
* @fires ready When Ad Network is ready and playable ad can be initialized
|
|
333
|
+
*/
|
|
334
|
+
static init(callback) {
|
|
335
|
+
if (isSDKInitialized) return;
|
|
336
|
+
ensureProtocol();
|
|
337
|
+
if (callback) initCallback = callback;
|
|
338
|
+
if ("mraid" === AD_PROTOCOL && isMraid()) {
|
|
339
|
+
if (mraid.getState() !== "ready" && "adcolony" !== AD_NETWORK) {
|
|
340
|
+
mraid.addEventListener("ready", startMraidProtocol);
|
|
341
|
+
} else {
|
|
342
|
+
startMraidProtocol();
|
|
343
|
+
}
|
|
344
|
+
} else if ("dapi" === AD_PROTOCOL && isDapi()) {
|
|
345
|
+
window.addEventListener("load", function() {
|
|
346
|
+
dapi.isReady() ? startDapiProtocol() : dapi.addEventListener("ready", startDapiProtocol);
|
|
347
|
+
});
|
|
348
|
+
} else {
|
|
349
|
+
startDefaultProtocol();
|
|
350
|
+
}
|
|
351
|
+
emitEvent("init");
|
|
352
|
+
isSDKInitialized = true;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Starts the playable ad experience.
|
|
356
|
+
* Should be called after all resources are loaded and first frame is rendered.
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
* // Call just after all resources are preloaded and first frame is rendered
|
|
360
|
+
* sdk.start();
|
|
361
|
+
*
|
|
362
|
+
* @fires start When the playable ad starts
|
|
363
|
+
* @fires resize When the ad container is initially sized
|
|
364
|
+
*/
|
|
365
|
+
static start() {
|
|
366
|
+
if (_sdk.isStarted) return;
|
|
367
|
+
_sdk.isStarted = true;
|
|
368
|
+
emitEvent("start");
|
|
369
|
+
registerTouchHandlers();
|
|
370
|
+
if ("mintegral" === AD_NETWORK && isMintegral()) {
|
|
371
|
+
_sdk.resize();
|
|
372
|
+
handlePause();
|
|
373
|
+
window.gameReady && window.gameReady();
|
|
374
|
+
} else {
|
|
375
|
+
if ("tapjoy" === AD_NETWORK && isTapjoy()) {
|
|
376
|
+
window.TJ_API.setPlayableBuild({
|
|
377
|
+
orientation: this.isLandscape ? "landscape" : "portrait",
|
|
378
|
+
buildID: BUILD_HASH
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
_sdk.resize();
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Marks the playable ad as finished.
|
|
386
|
+
* This triggers network-specific completion handlers.
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* // Call when game/experience is complete
|
|
390
|
+
* sdk.finish();
|
|
391
|
+
*
|
|
392
|
+
* @fires finish When the playable ad is marked as finished
|
|
393
|
+
*/
|
|
394
|
+
static finish() {
|
|
395
|
+
_sdk.isFinished = true;
|
|
396
|
+
if ("tapjoy" === AD_NETWORK && isTapjoy()) {
|
|
397
|
+
finishTapjoy();
|
|
398
|
+
} else if ("mintegral" === AD_NETWORK && isMintegral()) {
|
|
399
|
+
window.gameEnd && window.gameEnd();
|
|
400
|
+
} else if ("vungle" === AD_NETWORK) {
|
|
401
|
+
parent.postMessage("complete", "*");
|
|
402
|
+
}
|
|
403
|
+
emitEvent("finish");
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Triggers a retry/restart of the playable ad.
|
|
407
|
+
* Behavior varies by ad network.
|
|
408
|
+
*
|
|
409
|
+
* @example
|
|
410
|
+
* // Allow user to try again
|
|
411
|
+
* retryButton.onclick = () => sdk.retry();
|
|
412
|
+
*
|
|
413
|
+
* @fires retry When a retry is triggered
|
|
414
|
+
*/
|
|
415
|
+
static retry() {
|
|
416
|
+
if ("mintegral" === AD_NETWORK && isMintegral()) {
|
|
417
|
+
} else if ("nucleo" === AD_PROTOCOL && isNucleo()) {
|
|
418
|
+
NUC.trigger.tryAgain();
|
|
419
|
+
}
|
|
420
|
+
emitEvent("retry");
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Triggers the install/download action for the advertised app.
|
|
424
|
+
* Handles different store opening methods across ad networks.
|
|
425
|
+
*
|
|
426
|
+
* @example
|
|
427
|
+
* // Call when user wants to install
|
|
428
|
+
* installButton.onclick = () => sdk.install();
|
|
429
|
+
*
|
|
430
|
+
* @fires finish If the ad hasn't been marked as finished
|
|
431
|
+
* @fires install When the install action is triggered
|
|
432
|
+
*/
|
|
433
|
+
static install() {
|
|
434
|
+
if (!_sdk.isFinished) {
|
|
435
|
+
_sdk.isFinished = true;
|
|
436
|
+
let timeout = 0;
|
|
437
|
+
if ("tapjoy" === AD_NETWORK && isTapjoy()) {
|
|
438
|
+
finishTapjoy();
|
|
439
|
+
timeout = 300;
|
|
440
|
+
}
|
|
441
|
+
emitEvent("finish");
|
|
442
|
+
setTimeout(function() {
|
|
443
|
+
_sdk.install();
|
|
444
|
+
}, timeout);
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
if (isInstallClicked) return;
|
|
448
|
+
isInstallClicked = true;
|
|
449
|
+
setTimeout(function() {
|
|
450
|
+
isInstallClicked = false;
|
|
451
|
+
}, 500);
|
|
452
|
+
emitEvent("install");
|
|
453
|
+
if ("mraid" === AD_PROTOCOL && isMraid()) {
|
|
454
|
+
mraid.open(destinationUrl);
|
|
455
|
+
} else if ("dapi" === AD_PROTOCOL && isDapi()) {
|
|
456
|
+
dapi.openStoreUrl();
|
|
457
|
+
} else if ("nucleo" === AD_PROTOCOL && isNucleo()) {
|
|
458
|
+
NUC.trigger.convert(destinationUrl);
|
|
459
|
+
} else if ("facebook" == AD_NETWORK && isFacebook()) {
|
|
460
|
+
FbPlayableAd.onCTAClick();
|
|
461
|
+
} else if ("vungle" == AD_NETWORK) {
|
|
462
|
+
parent.postMessage("download", "*");
|
|
463
|
+
} else if ("google" == AD_NETWORK && isGoogle()) {
|
|
464
|
+
ExitApi.exit();
|
|
465
|
+
} else if ("mintegral" === AD_NETWORK && isMintegral()) {
|
|
466
|
+
window.install && window.install();
|
|
467
|
+
} else if ("tapjoy" === AD_NETWORK && isTapjoy()) {
|
|
468
|
+
window.TJ_API.click();
|
|
469
|
+
} else if ("tiktok" === AD_NETWORK && isTikTok()) {
|
|
470
|
+
window.openAppStore();
|
|
471
|
+
} else {
|
|
472
|
+
window.open(destinationUrl);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Trigger force resize event
|
|
477
|
+
* Useful when container size changes need to be manually propagated.
|
|
478
|
+
*
|
|
479
|
+
* @example
|
|
480
|
+
* sdk.resize();
|
|
481
|
+
*
|
|
482
|
+
* @fires resize With current maxWidth and maxHeight
|
|
483
|
+
*/
|
|
484
|
+
static resize() {
|
|
485
|
+
handleResize(_sdk.maxWidth, _sdk.maxHeight);
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Forces the playable ad into a paused state.
|
|
489
|
+
*
|
|
490
|
+
* @example
|
|
491
|
+
* // Pause the experience
|
|
492
|
+
* pauseButton.onclick = () => sdk.pause();
|
|
493
|
+
*
|
|
494
|
+
* @fires pause When the ad enters paused state
|
|
495
|
+
*/
|
|
496
|
+
static pause() {
|
|
497
|
+
if (!isForcePaused) {
|
|
498
|
+
isForcePaused = true;
|
|
499
|
+
handlePause();
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Resumes the playable ad from a forced pause state.
|
|
504
|
+
* Only works if the ad was paused via sdk.pause().
|
|
505
|
+
*
|
|
506
|
+
* @example
|
|
507
|
+
* // Resume from pause
|
|
508
|
+
* resumeButton.onclick = () => sdk.resume();
|
|
509
|
+
*
|
|
510
|
+
* @fires resume When the ad resumes from pause
|
|
511
|
+
*/
|
|
512
|
+
static resume() {
|
|
513
|
+
if (isForcePaused) {
|
|
514
|
+
isForcePaused = false;
|
|
515
|
+
handleResume();
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Registers an event listener.
|
|
520
|
+
*
|
|
521
|
+
* @param event Name of the event to listen for
|
|
522
|
+
* @param fn Callback function to execute when event occurs
|
|
523
|
+
* @param context Optional 'this' context for the callback
|
|
524
|
+
*
|
|
525
|
+
* @example
|
|
526
|
+
* // Listen for user interactions
|
|
527
|
+
* sdk.on('interaction', (count) => {
|
|
528
|
+
* console.log(`User interaction #${count}`);
|
|
529
|
+
* });
|
|
530
|
+
*
|
|
531
|
+
* // Listen for resize with context
|
|
532
|
+
* sdk.on('resize', function(width, height) {
|
|
533
|
+
* this.updateLayout(width, height);
|
|
534
|
+
* }, gameInstance);
|
|
535
|
+
*/
|
|
536
|
+
static on(event, fn, context) {
|
|
537
|
+
onEvent(event, fn, context);
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Registers a one-time event listener that removes itself after execution.
|
|
541
|
+
*
|
|
542
|
+
* @param event Name of the event to listen for
|
|
543
|
+
* @param fn Callback function to execute when event occurs
|
|
544
|
+
* @param context Optional 'this' context for the callback
|
|
545
|
+
*
|
|
546
|
+
* @example
|
|
547
|
+
* // Listen for first interaction only
|
|
548
|
+
* sdk.once('interaction', () => {
|
|
549
|
+
* console.log('First user interaction occurred!');
|
|
550
|
+
* });
|
|
551
|
+
*/
|
|
552
|
+
static once(event, fn, context) {
|
|
553
|
+
onEvent(event, fn, context, true);
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Removes an event listener.
|
|
557
|
+
*
|
|
558
|
+
* @param event Name of the event to stop listening for
|
|
559
|
+
* @param fn Optional callback function to remove (if not provided, removes all listeners for the event)
|
|
560
|
+
* @param context Optional 'this' context to match when removing
|
|
561
|
+
*
|
|
562
|
+
* @example
|
|
563
|
+
* // Remove specific listener
|
|
564
|
+
* const handler = () => console.log('Interaction');
|
|
565
|
+
* sdk.off('interaction', handler);
|
|
566
|
+
*
|
|
567
|
+
* // Remove all listeners for an event
|
|
568
|
+
* sdk.off('interaction');
|
|
569
|
+
*/
|
|
570
|
+
static off(event, fn, context) {
|
|
571
|
+
offEvent(event, fn, context);
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
/** Current version of the SDK */
|
|
575
|
+
_sdk.version = "1.0.7";
|
|
576
|
+
/** Current maximum width of the playable ad container in pixels */
|
|
577
|
+
_sdk.maxWidth = Math.floor(window.innerWidth);
|
|
578
|
+
/** Current maximum height of the playable ad container in pixels */
|
|
579
|
+
_sdk.maxHeight = Math.floor(window.innerHeight);
|
|
580
|
+
/** Indicates if the current orientation is landscape (width > height) */
|
|
581
|
+
_sdk.isLandscape = window.innerWidth > window.innerHeight;
|
|
582
|
+
/** Indicates if the Ad Network is ready and playable ad can be initialized */
|
|
583
|
+
_sdk.isReady = false;
|
|
584
|
+
/** Indicates if all playable ad resources are loaded and gameplay has started */
|
|
585
|
+
_sdk.isStarted = false;
|
|
586
|
+
/** Indicates if the playable ad is currently paused */
|
|
587
|
+
_sdk.isPaused = false;
|
|
588
|
+
/** Indicates if the playable ad has finished */
|
|
589
|
+
_sdk.isFinished = false;
|
|
590
|
+
/** Current volume level (0-1) */
|
|
591
|
+
_sdk.volume = 1;
|
|
592
|
+
/** Number of user interactions with the playable ad */
|
|
593
|
+
_sdk.interactions = 0;
|
|
594
|
+
var sdk = _sdk;
|
|
595
|
+
window.PlayableSDK = sdk;
|
|
596
|
+
export {
|
|
597
|
+
sdk as default,
|
|
598
|
+
sdk
|
|
599
|
+
};
|
package/dist/iife/index.js
CHANGED
|
@@ -416,7 +416,6 @@
|
|
|
416
416
|
*/
|
|
417
417
|
static retry() {
|
|
418
418
|
if ("mintegral" === AD_NETWORK && isMintegral()) {
|
|
419
|
-
window.gameRetry && window.gameRetry();
|
|
420
419
|
} else if ("nucleo" === AD_PROTOCOL && isNucleo()) {
|
|
421
420
|
NUC.trigger.tryAgain();
|
|
422
421
|
}
|
|
@@ -575,7 +574,7 @@
|
|
|
575
574
|
}
|
|
576
575
|
};
|
|
577
576
|
/** Current version of the SDK */
|
|
578
|
-
_sdk.version = "1.0.
|
|
577
|
+
_sdk.version = "1.0.7";
|
|
579
578
|
/** Current maximum width of the playable ad container in pixels */
|
|
580
579
|
_sdk.maxWidth = Math.floor(window.innerWidth);
|
|
581
580
|
/** Current maximum height of the playable ad container in pixels */
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
type EventName = 'init' | 'boot' | 'ready' | 'start' | 'interaction' | 'resize' | 'pause' | 'resume' | 'volume' | 'retry' | 'finish' | 'install';
|
|
2
|
+
|
|
2
3
|
type InitCallbackType = (maxWidth: number, maxHeight: number) => void;
|
|
3
4
|
/**
|
|
4
5
|
* Main SDK class providing playable ad functionality and state management.
|
|
@@ -171,4 +172,5 @@ declare class sdk {
|
|
|
171
172
|
*/
|
|
172
173
|
static off(event: EventName, fn?: Function, context?: any): void;
|
|
173
174
|
}
|
|
174
|
-
|
|
175
|
+
|
|
176
|
+
export { sdk as default, sdk };
|