@smoud/playable-sdk 1.0.14 → 1.0.16
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 +14 -14
- package/dist/esm/index.js +128 -129
- package/dist/iife/index.js +128 -129
- package/dist/index.js +128 -129
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -330,20 +330,20 @@ sdk.off('eventName', [callback], [context]);
|
|
|
330
330
|
|
|
331
331
|
#### Available Events
|
|
332
332
|
|
|
333
|
-
| Event | Parameters | Description
|
|
334
|
-
| ------------- | --------------- |
|
|
335
|
-
| `init` | - | SDK initialization started
|
|
336
|
-
| `boot` | - | Ad container is ready `pre` init callback
|
|
337
|
-
| `ready` | - | Ad container is ready `post` init callback
|
|
338
|
-
| `start` | - | Playable experience started
|
|
339
|
-
| `interaction` | `count` | User interaction occurred
|
|
340
|
-
| `resize` | `width, height` | Container size changed
|
|
341
|
-
| `pause` | - | Playable entered pause state
|
|
342
|
-
| `resume` | - | Playable resumed from pause
|
|
343
|
-
| `volume` | `level` | Volume level changed (0-1)
|
|
344
|
-
| `retry` | - | Retry/restart triggered
|
|
345
|
-
| `finish` | - | Playable marked as complete
|
|
346
|
-
| `install` | - | Install action triggered
|
|
333
|
+
| Event | Parameters | Description | Typical Usage |
|
|
334
|
+
| ------------- | --------------- | ------------------------------------------------- | ------------------------ |
|
|
335
|
+
| `init` | - | DOM Content loaded and SDK initialization started | Setup loading screen |
|
|
336
|
+
| `boot` | - | Ad container is ready `pre` init callback | Initialize core systems |
|
|
337
|
+
| `ready` | - | Ad container is ready `post` init callback | Start resource loading |
|
|
338
|
+
| `start` | - | Playable experience started | Begin gameplay/animation |
|
|
339
|
+
| `interaction` | `count` | User interaction occurred | Track engagement |
|
|
340
|
+
| `resize` | `width, height` | Container size changed | Update layout |
|
|
341
|
+
| `pause` | - | Playable entered pause state | Pause gameplay |
|
|
342
|
+
| `resume` | - | Playable resumed from pause | Resume gameplay |
|
|
343
|
+
| `volume` | `level` | Volume level changed (0-1) | Adjust audio |
|
|
344
|
+
| `retry` | - | Retry/restart triggered | Reset game state |
|
|
345
|
+
| `finish` | - | Playable marked as complete | Show end screen |
|
|
346
|
+
| `install` | - | Install action triggered | Track conversion |
|
|
347
347
|
|
|
348
348
|
### Properties
|
|
349
349
|
|
package/dist/esm/index.js
CHANGED
|
@@ -160,150 +160,152 @@ function handleResume() {
|
|
|
160
160
|
sdk.isPaused = false;
|
|
161
161
|
emitEvent("resume");
|
|
162
162
|
}
|
|
163
|
-
function
|
|
163
|
+
function fireResizeEvent(width, height) {
|
|
164
|
+
handleResize(width, height);
|
|
165
|
+
}
|
|
166
|
+
function startMraidProtocol() {
|
|
164
167
|
if ("mraid" !== AD_PROTOCOL) return;
|
|
165
|
-
if (
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
if (
|
|
168
|
+
if (isProtocolInitialized) return;
|
|
169
|
+
mraid.removeEventListener("ready", startMraidProtocol);
|
|
170
|
+
function mraidStateChanged(viewable) {
|
|
171
|
+
if (viewable) {
|
|
172
|
+
if (sdk.isReady) {
|
|
173
|
+
handleResume();
|
|
174
|
+
} else {
|
|
170
175
|
const maxSize = mraid.getMaxSize();
|
|
171
176
|
sdk.maxWidth = Math.floor(maxSize.width);
|
|
172
177
|
sdk.maxHeight = Math.floor(maxSize.height);
|
|
178
|
+
bootAd();
|
|
173
179
|
}
|
|
174
|
-
|
|
180
|
+
} else {
|
|
181
|
+
handlePause();
|
|
175
182
|
}
|
|
176
|
-
} else {
|
|
177
|
-
handlePause();
|
|
178
183
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
184
|
+
function isViewable() {
|
|
185
|
+
return mraid.isViewable() && "hidden" !== mraid.getState();
|
|
186
|
+
}
|
|
187
|
+
function stateChanged() {
|
|
188
|
+
mraidStateChanged(isViewable());
|
|
189
|
+
}
|
|
190
|
+
mraid.addEventListener("viewableChange", stateChanged);
|
|
191
|
+
mraid.addEventListener("stateChange", stateChanged);
|
|
192
|
+
if (isViewable()) {
|
|
193
|
+
mraidStateChanged(true);
|
|
194
|
+
}
|
|
195
|
+
if (mraid.getAudioVolume) {
|
|
196
|
+
const isAudioEnabled = mraid.getAudioVolume();
|
|
197
|
+
if (isAudioEnabled) {
|
|
198
|
+
handleVolumeChange(1);
|
|
185
199
|
} else {
|
|
186
|
-
|
|
187
|
-
screenSize.width = Math.floor(screenSize.width);
|
|
188
|
-
screenSize.height = Math.floor(screenSize.height);
|
|
189
|
-
bootAd();
|
|
200
|
+
handleVolumeChange(0);
|
|
190
201
|
}
|
|
191
|
-
} else {
|
|
192
|
-
handlePause();
|
|
193
202
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
function startMraidProtocol() {
|
|
199
|
-
if ("mraid" !== AD_PROTOCOL) return;
|
|
200
|
-
if (!isProtocolInitialized) {
|
|
201
|
-
mraid.removeEventListener("ready", startMraidProtocol);
|
|
202
|
-
mraid.addEventListener("viewableChange", function() {
|
|
203
|
-
const isViewable = mraid.isViewable();
|
|
204
|
-
mraidIsViewable(isViewable);
|
|
205
|
-
});
|
|
206
|
-
if (mraid.isViewable() || AD_NETWORK == "adcolony") {
|
|
207
|
-
mraidIsViewable(true);
|
|
208
|
-
}
|
|
209
|
-
if (mraid.getAudioVolume) {
|
|
210
|
-
const isAudioEnabled = mraid.getAudioVolume();
|
|
211
|
-
if (isAudioEnabled) {
|
|
203
|
+
mraid.addEventListener("audioVolumeChange", function(newVolume) {
|
|
204
|
+
if (newVolume !== null) {
|
|
205
|
+
if (newVolume > 0) {
|
|
212
206
|
handleVolumeChange(1);
|
|
213
207
|
} else {
|
|
214
208
|
handleVolumeChange(0);
|
|
215
209
|
}
|
|
216
210
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
mraid.addEventListener("error", function(t, e) {
|
|
227
|
-
console.log("mraid error: " + t + " action: " + e);
|
|
228
|
-
});
|
|
229
|
-
mraid.addEventListener("sizeChange", function() {
|
|
230
|
-
const maxSize = mraid.getMaxSize();
|
|
231
|
-
fireResizeEvent(maxSize.width, maxSize.height);
|
|
232
|
-
});
|
|
233
|
-
isProtocolInitialized = true;
|
|
234
|
-
}
|
|
211
|
+
});
|
|
212
|
+
mraid.addEventListener("error", function(t, e) {
|
|
213
|
+
console.log("mraid error: " + t + " action: " + e);
|
|
214
|
+
});
|
|
215
|
+
mraid.addEventListener("sizeChange", function() {
|
|
216
|
+
const maxSize = mraid.getMaxSize();
|
|
217
|
+
fireResizeEvent(maxSize.width, maxSize.height);
|
|
218
|
+
});
|
|
219
|
+
isProtocolInitialized = true;
|
|
235
220
|
}
|
|
236
221
|
function startDapiProtocol() {
|
|
237
222
|
if ("dapi" !== AD_PROTOCOL) return;
|
|
238
|
-
if (
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
223
|
+
if (isProtocolInitialized) return;
|
|
224
|
+
function dapiIsViewable(event) {
|
|
225
|
+
if (event.isViewable) {
|
|
226
|
+
if (sdk.isReady) {
|
|
227
|
+
handleResume();
|
|
228
|
+
} else {
|
|
229
|
+
const screenSize = dapi.getScreenSize();
|
|
230
|
+
screenSize.width = Math.floor(screenSize.width);
|
|
231
|
+
screenSize.height = Math.floor(screenSize.height);
|
|
232
|
+
bootAd();
|
|
233
|
+
}
|
|
234
|
+
} else {
|
|
235
|
+
handlePause();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
dapi.removeEventListener("ready", startDapiProtocol);
|
|
239
|
+
const isAudioEnabled = dapi.getAudioVolume();
|
|
240
|
+
if (isAudioEnabled) {
|
|
241
|
+
handleVolumeChange(1);
|
|
242
|
+
} else {
|
|
243
|
+
handleVolumeChange(0);
|
|
244
|
+
}
|
|
245
|
+
dapi.addEventListener("audioVolumeChange", function(volume) {
|
|
246
|
+
const isAudioEnabled2 = !!volume;
|
|
247
|
+
if (isAudioEnabled2) {
|
|
242
248
|
handleVolumeChange(1);
|
|
243
249
|
} else {
|
|
244
250
|
handleVolumeChange(0);
|
|
245
251
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
});
|
|
254
|
-
dapi.addEventListener("adResized", function(event) {
|
|
255
|
-
const maxSize = dapi.getScreenSize();
|
|
256
|
-
fireResizeEvent(event.width || maxSize.width, event.height || maxSize.height);
|
|
257
|
-
});
|
|
258
|
-
if (dapi.isViewable()) {
|
|
259
|
-
dapiIsViewable({ isViewable: true });
|
|
260
|
-
}
|
|
261
|
-
dapi.addEventListener("viewableChange", dapiIsViewable);
|
|
262
|
-
isProtocolInitialized = true;
|
|
252
|
+
});
|
|
253
|
+
dapi.addEventListener("adResized", function(event) {
|
|
254
|
+
const maxSize = dapi.getScreenSize();
|
|
255
|
+
fireResizeEvent(event.width || maxSize.width, event.height || maxSize.height);
|
|
256
|
+
});
|
|
257
|
+
if (dapi.isViewable()) {
|
|
258
|
+
dapiIsViewable({ isViewable: true });
|
|
263
259
|
}
|
|
260
|
+
dapi.addEventListener("viewableChange", dapiIsViewable);
|
|
261
|
+
isProtocolInitialized = true;
|
|
264
262
|
}
|
|
265
263
|
function startDefaultProtocol() {
|
|
266
|
-
if (
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
264
|
+
if (isProtocolInitialized) return;
|
|
265
|
+
if ("mintegral" === AD_NETWORK) {
|
|
266
|
+
window.mintGameStart = function() {
|
|
267
|
+
handleResume();
|
|
268
|
+
handleResize(sdk.maxWidth, sdk.maxHeight);
|
|
269
|
+
};
|
|
270
|
+
window.mintGameClose = function() {
|
|
271
|
+
handlePause();
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
document.addEventListener("visibilitychange", () => {
|
|
275
|
+
if (document.visibilityState === "visible") {
|
|
276
|
+
if (sdk.isReady) {
|
|
278
277
|
handleResume();
|
|
279
278
|
} else {
|
|
280
|
-
|
|
279
|
+
bootAd();
|
|
281
280
|
}
|
|
282
|
-
});
|
|
283
|
-
if (document.readyState === "complete") {
|
|
284
|
-
bootAd();
|
|
285
281
|
} else {
|
|
286
|
-
|
|
287
|
-
bootAd();
|
|
288
|
-
});
|
|
282
|
+
handlePause();
|
|
289
283
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
284
|
+
});
|
|
285
|
+
function documentIsReady() {
|
|
286
|
+
if (document.visibilityState === "visible") bootAd();
|
|
287
|
+
}
|
|
288
|
+
if (document.readyState === "complete") {
|
|
289
|
+
documentIsReady();
|
|
290
|
+
} else {
|
|
291
|
+
window.addEventListener("load", documentIsReady);
|
|
292
|
+
}
|
|
293
|
+
window.addEventListener("resize", function() {
|
|
294
|
+
handleResize();
|
|
295
|
+
});
|
|
296
|
+
if ("tapjoy" === AD_NETWORK && isTapjoy()) {
|
|
297
|
+
const tapjoyApi = {
|
|
298
|
+
skipAd: function() {
|
|
299
|
+
try {
|
|
300
|
+
sdk.finish();
|
|
301
|
+
} catch (e) {
|
|
302
|
+
console.warn("Could not skip ad! | " + e);
|
|
301
303
|
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
isProtocolInitialized = true;
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
window.TJ_API.setPlayableAPI && window.TJ_API.setPlayableAPI(tapjoyApi);
|
|
306
307
|
}
|
|
308
|
+
isProtocolInitialized = true;
|
|
307
309
|
}
|
|
308
310
|
function finishTapjoy() {
|
|
309
311
|
window.TJ_API.objectiveComplete && window.TJ_API.objectiveComplete();
|
|
@@ -333,6 +335,18 @@ function registerTouchHandlers() {
|
|
|
333
335
|
isTouchEventRegistered = true;
|
|
334
336
|
}
|
|
335
337
|
}
|
|
338
|
+
function initSDK() {
|
|
339
|
+
destinationUrl = /android/i.test(navigator.userAgent) ? GOOGLE_PLAY_URL : APP_STORE_URL;
|
|
340
|
+
ensureProtocol();
|
|
341
|
+
if ("mraid" === AD_PROTOCOL && isMraid()) {
|
|
342
|
+
mraid.getState() === "loading" ? mraid.addEventListener("ready", startMraidProtocol) : startMraidProtocol();
|
|
343
|
+
} else if ("dapi" === AD_PROTOCOL && isDapi()) {
|
|
344
|
+
dapi.isReady() ? startDapiProtocol() : dapi.addEventListener("ready", startDapiProtocol);
|
|
345
|
+
} else {
|
|
346
|
+
startDefaultProtocol();
|
|
347
|
+
}
|
|
348
|
+
emitEvent("init");
|
|
349
|
+
}
|
|
336
350
|
var _sdk = class _sdk {
|
|
337
351
|
/**
|
|
338
352
|
* Initializes the SDK and sets up protocol-specific handlers.
|
|
@@ -354,23 +368,8 @@ var _sdk = class _sdk {
|
|
|
354
368
|
*/
|
|
355
369
|
static init(callback) {
|
|
356
370
|
if (isSDKInitialized) return;
|
|
357
|
-
destinationUrl = /android/i.test(navigator.userAgent) ? GOOGLE_PLAY_URL : APP_STORE_URL;
|
|
358
|
-
ensureProtocol();
|
|
359
371
|
if (callback) initCallback = callback;
|
|
360
|
-
|
|
361
|
-
if (mraid.getState() !== "ready") {
|
|
362
|
-
mraid.addEventListener("ready", startMraidProtocol);
|
|
363
|
-
} else {
|
|
364
|
-
startMraidProtocol();
|
|
365
|
-
}
|
|
366
|
-
} else if ("dapi" === AD_PROTOCOL && isDapi()) {
|
|
367
|
-
window.addEventListener("load", function() {
|
|
368
|
-
dapi.isReady() ? startDapiProtocol() : dapi.addEventListener("ready", startDapiProtocol);
|
|
369
|
-
});
|
|
370
|
-
} else {
|
|
371
|
-
startDefaultProtocol();
|
|
372
|
-
}
|
|
373
|
-
emitEvent("init");
|
|
372
|
+
document.readyState === "loading" ? window.addEventListener("DOMContentLoaded", initSDK) : initSDK();
|
|
374
373
|
isSDKInitialized = true;
|
|
375
374
|
}
|
|
376
375
|
/**
|
|
@@ -595,7 +594,7 @@ var _sdk = class _sdk {
|
|
|
595
594
|
}
|
|
596
595
|
};
|
|
597
596
|
/** Current version of the SDK */
|
|
598
|
-
_sdk.version = "1.0.
|
|
597
|
+
_sdk.version = "1.0.16";
|
|
599
598
|
/** Current maximum width of the playable ad container in pixels */
|
|
600
599
|
_sdk.maxWidth = Math.floor(window.innerWidth);
|
|
601
600
|
/** Current maximum height of the playable ad container in pixels */
|
package/dist/iife/index.js
CHANGED
|
@@ -162,150 +162,152 @@
|
|
|
162
162
|
sdk.isPaused = false;
|
|
163
163
|
emitEvent("resume");
|
|
164
164
|
}
|
|
165
|
-
function
|
|
165
|
+
function fireResizeEvent(width, height) {
|
|
166
|
+
handleResize(width, height);
|
|
167
|
+
}
|
|
168
|
+
function startMraidProtocol() {
|
|
166
169
|
if ("mraid" !== AD_PROTOCOL) return;
|
|
167
|
-
if (
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if (
|
|
170
|
+
if (isProtocolInitialized) return;
|
|
171
|
+
mraid.removeEventListener("ready", startMraidProtocol);
|
|
172
|
+
function mraidStateChanged(viewable) {
|
|
173
|
+
if (viewable) {
|
|
174
|
+
if (sdk.isReady) {
|
|
175
|
+
handleResume();
|
|
176
|
+
} else {
|
|
172
177
|
const maxSize = mraid.getMaxSize();
|
|
173
178
|
sdk.maxWidth = Math.floor(maxSize.width);
|
|
174
179
|
sdk.maxHeight = Math.floor(maxSize.height);
|
|
180
|
+
bootAd();
|
|
175
181
|
}
|
|
176
|
-
|
|
182
|
+
} else {
|
|
183
|
+
handlePause();
|
|
177
184
|
}
|
|
178
|
-
} else {
|
|
179
|
-
handlePause();
|
|
180
185
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
186
|
+
function isViewable() {
|
|
187
|
+
return mraid.isViewable() && "hidden" !== mraid.getState();
|
|
188
|
+
}
|
|
189
|
+
function stateChanged() {
|
|
190
|
+
mraidStateChanged(isViewable());
|
|
191
|
+
}
|
|
192
|
+
mraid.addEventListener("viewableChange", stateChanged);
|
|
193
|
+
mraid.addEventListener("stateChange", stateChanged);
|
|
194
|
+
if (isViewable()) {
|
|
195
|
+
mraidStateChanged(true);
|
|
196
|
+
}
|
|
197
|
+
if (mraid.getAudioVolume) {
|
|
198
|
+
const isAudioEnabled = mraid.getAudioVolume();
|
|
199
|
+
if (isAudioEnabled) {
|
|
200
|
+
handleVolumeChange(1);
|
|
187
201
|
} else {
|
|
188
|
-
|
|
189
|
-
screenSize.width = Math.floor(screenSize.width);
|
|
190
|
-
screenSize.height = Math.floor(screenSize.height);
|
|
191
|
-
bootAd();
|
|
202
|
+
handleVolumeChange(0);
|
|
192
203
|
}
|
|
193
|
-
} else {
|
|
194
|
-
handlePause();
|
|
195
204
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
function startMraidProtocol() {
|
|
201
|
-
if ("mraid" !== AD_PROTOCOL) return;
|
|
202
|
-
if (!isProtocolInitialized) {
|
|
203
|
-
mraid.removeEventListener("ready", startMraidProtocol);
|
|
204
|
-
mraid.addEventListener("viewableChange", function() {
|
|
205
|
-
const isViewable = mraid.isViewable();
|
|
206
|
-
mraidIsViewable(isViewable);
|
|
207
|
-
});
|
|
208
|
-
if (mraid.isViewable() || AD_NETWORK == "adcolony") {
|
|
209
|
-
mraidIsViewable(true);
|
|
210
|
-
}
|
|
211
|
-
if (mraid.getAudioVolume) {
|
|
212
|
-
const isAudioEnabled = mraid.getAudioVolume();
|
|
213
|
-
if (isAudioEnabled) {
|
|
205
|
+
mraid.addEventListener("audioVolumeChange", function(newVolume) {
|
|
206
|
+
if (newVolume !== null) {
|
|
207
|
+
if (newVolume > 0) {
|
|
214
208
|
handleVolumeChange(1);
|
|
215
209
|
} else {
|
|
216
210
|
handleVolumeChange(0);
|
|
217
211
|
}
|
|
218
212
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
mraid.addEventListener("error", function(t, e) {
|
|
229
|
-
console.log("mraid error: " + t + " action: " + e);
|
|
230
|
-
});
|
|
231
|
-
mraid.addEventListener("sizeChange", function() {
|
|
232
|
-
const maxSize = mraid.getMaxSize();
|
|
233
|
-
fireResizeEvent(maxSize.width, maxSize.height);
|
|
234
|
-
});
|
|
235
|
-
isProtocolInitialized = true;
|
|
236
|
-
}
|
|
213
|
+
});
|
|
214
|
+
mraid.addEventListener("error", function(t, e) {
|
|
215
|
+
console.log("mraid error: " + t + " action: " + e);
|
|
216
|
+
});
|
|
217
|
+
mraid.addEventListener("sizeChange", function() {
|
|
218
|
+
const maxSize = mraid.getMaxSize();
|
|
219
|
+
fireResizeEvent(maxSize.width, maxSize.height);
|
|
220
|
+
});
|
|
221
|
+
isProtocolInitialized = true;
|
|
237
222
|
}
|
|
238
223
|
function startDapiProtocol() {
|
|
239
224
|
if ("dapi" !== AD_PROTOCOL) return;
|
|
240
|
-
if (
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
225
|
+
if (isProtocolInitialized) return;
|
|
226
|
+
function dapiIsViewable(event) {
|
|
227
|
+
if (event.isViewable) {
|
|
228
|
+
if (sdk.isReady) {
|
|
229
|
+
handleResume();
|
|
230
|
+
} else {
|
|
231
|
+
const screenSize = dapi.getScreenSize();
|
|
232
|
+
screenSize.width = Math.floor(screenSize.width);
|
|
233
|
+
screenSize.height = Math.floor(screenSize.height);
|
|
234
|
+
bootAd();
|
|
235
|
+
}
|
|
236
|
+
} else {
|
|
237
|
+
handlePause();
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
dapi.removeEventListener("ready", startDapiProtocol);
|
|
241
|
+
const isAudioEnabled = dapi.getAudioVolume();
|
|
242
|
+
if (isAudioEnabled) {
|
|
243
|
+
handleVolumeChange(1);
|
|
244
|
+
} else {
|
|
245
|
+
handleVolumeChange(0);
|
|
246
|
+
}
|
|
247
|
+
dapi.addEventListener("audioVolumeChange", function(volume) {
|
|
248
|
+
const isAudioEnabled2 = !!volume;
|
|
249
|
+
if (isAudioEnabled2) {
|
|
244
250
|
handleVolumeChange(1);
|
|
245
251
|
} else {
|
|
246
252
|
handleVolumeChange(0);
|
|
247
253
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
});
|
|
256
|
-
dapi.addEventListener("adResized", function(event) {
|
|
257
|
-
const maxSize = dapi.getScreenSize();
|
|
258
|
-
fireResizeEvent(event.width || maxSize.width, event.height || maxSize.height);
|
|
259
|
-
});
|
|
260
|
-
if (dapi.isViewable()) {
|
|
261
|
-
dapiIsViewable({ isViewable: true });
|
|
262
|
-
}
|
|
263
|
-
dapi.addEventListener("viewableChange", dapiIsViewable);
|
|
264
|
-
isProtocolInitialized = true;
|
|
254
|
+
});
|
|
255
|
+
dapi.addEventListener("adResized", function(event) {
|
|
256
|
+
const maxSize = dapi.getScreenSize();
|
|
257
|
+
fireResizeEvent(event.width || maxSize.width, event.height || maxSize.height);
|
|
258
|
+
});
|
|
259
|
+
if (dapi.isViewable()) {
|
|
260
|
+
dapiIsViewable({ isViewable: true });
|
|
265
261
|
}
|
|
262
|
+
dapi.addEventListener("viewableChange", dapiIsViewable);
|
|
263
|
+
isProtocolInitialized = true;
|
|
266
264
|
}
|
|
267
265
|
function startDefaultProtocol() {
|
|
268
|
-
if (
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
266
|
+
if (isProtocolInitialized) return;
|
|
267
|
+
if ("mintegral" === AD_NETWORK) {
|
|
268
|
+
window.mintGameStart = function() {
|
|
269
|
+
handleResume();
|
|
270
|
+
handleResize(sdk.maxWidth, sdk.maxHeight);
|
|
271
|
+
};
|
|
272
|
+
window.mintGameClose = function() {
|
|
273
|
+
handlePause();
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
document.addEventListener("visibilitychange", () => {
|
|
277
|
+
if (document.visibilityState === "visible") {
|
|
278
|
+
if (sdk.isReady) {
|
|
280
279
|
handleResume();
|
|
281
280
|
} else {
|
|
282
|
-
|
|
281
|
+
bootAd();
|
|
283
282
|
}
|
|
284
|
-
});
|
|
285
|
-
if (document.readyState === "complete") {
|
|
286
|
-
bootAd();
|
|
287
283
|
} else {
|
|
288
|
-
|
|
289
|
-
bootAd();
|
|
290
|
-
});
|
|
284
|
+
handlePause();
|
|
291
285
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
286
|
+
});
|
|
287
|
+
function documentIsReady() {
|
|
288
|
+
if (document.visibilityState === "visible") bootAd();
|
|
289
|
+
}
|
|
290
|
+
if (document.readyState === "complete") {
|
|
291
|
+
documentIsReady();
|
|
292
|
+
} else {
|
|
293
|
+
window.addEventListener("load", documentIsReady);
|
|
294
|
+
}
|
|
295
|
+
window.addEventListener("resize", function() {
|
|
296
|
+
handleResize();
|
|
297
|
+
});
|
|
298
|
+
if ("tapjoy" === AD_NETWORK && isTapjoy()) {
|
|
299
|
+
const tapjoyApi = {
|
|
300
|
+
skipAd: function() {
|
|
301
|
+
try {
|
|
302
|
+
sdk.finish();
|
|
303
|
+
} catch (e) {
|
|
304
|
+
console.warn("Could not skip ad! | " + e);
|
|
303
305
|
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
isProtocolInitialized = true;
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
window.TJ_API.setPlayableAPI && window.TJ_API.setPlayableAPI(tapjoyApi);
|
|
308
309
|
}
|
|
310
|
+
isProtocolInitialized = true;
|
|
309
311
|
}
|
|
310
312
|
function finishTapjoy() {
|
|
311
313
|
window.TJ_API.objectiveComplete && window.TJ_API.objectiveComplete();
|
|
@@ -335,6 +337,18 @@
|
|
|
335
337
|
isTouchEventRegistered = true;
|
|
336
338
|
}
|
|
337
339
|
}
|
|
340
|
+
function initSDK() {
|
|
341
|
+
destinationUrl = /android/i.test(navigator.userAgent) ? GOOGLE_PLAY_URL : APP_STORE_URL;
|
|
342
|
+
ensureProtocol();
|
|
343
|
+
if ("mraid" === AD_PROTOCOL && isMraid()) {
|
|
344
|
+
mraid.getState() === "loading" ? mraid.addEventListener("ready", startMraidProtocol) : startMraidProtocol();
|
|
345
|
+
} else if ("dapi" === AD_PROTOCOL && isDapi()) {
|
|
346
|
+
dapi.isReady() ? startDapiProtocol() : dapi.addEventListener("ready", startDapiProtocol);
|
|
347
|
+
} else {
|
|
348
|
+
startDefaultProtocol();
|
|
349
|
+
}
|
|
350
|
+
emitEvent("init");
|
|
351
|
+
}
|
|
338
352
|
var _sdk = class _sdk {
|
|
339
353
|
/**
|
|
340
354
|
* Initializes the SDK and sets up protocol-specific handlers.
|
|
@@ -356,23 +370,8 @@
|
|
|
356
370
|
*/
|
|
357
371
|
static init(callback) {
|
|
358
372
|
if (isSDKInitialized) return;
|
|
359
|
-
destinationUrl = /android/i.test(navigator.userAgent) ? GOOGLE_PLAY_URL : APP_STORE_URL;
|
|
360
|
-
ensureProtocol();
|
|
361
373
|
if (callback) initCallback = callback;
|
|
362
|
-
|
|
363
|
-
if (mraid.getState() !== "ready") {
|
|
364
|
-
mraid.addEventListener("ready", startMraidProtocol);
|
|
365
|
-
} else {
|
|
366
|
-
startMraidProtocol();
|
|
367
|
-
}
|
|
368
|
-
} else if ("dapi" === AD_PROTOCOL && isDapi()) {
|
|
369
|
-
window.addEventListener("load", function() {
|
|
370
|
-
dapi.isReady() ? startDapiProtocol() : dapi.addEventListener("ready", startDapiProtocol);
|
|
371
|
-
});
|
|
372
|
-
} else {
|
|
373
|
-
startDefaultProtocol();
|
|
374
|
-
}
|
|
375
|
-
emitEvent("init");
|
|
374
|
+
document.readyState === "loading" ? window.addEventListener("DOMContentLoaded", initSDK) : initSDK();
|
|
376
375
|
isSDKInitialized = true;
|
|
377
376
|
}
|
|
378
377
|
/**
|
|
@@ -597,7 +596,7 @@
|
|
|
597
596
|
}
|
|
598
597
|
};
|
|
599
598
|
/** Current version of the SDK */
|
|
600
|
-
_sdk.version = "1.0.
|
|
599
|
+
_sdk.version = "1.0.16";
|
|
601
600
|
/** Current maximum width of the playable ad container in pixels */
|
|
602
601
|
_sdk.maxWidth = Math.floor(window.innerWidth);
|
|
603
602
|
/** Current maximum height of the playable ad container in pixels */
|
package/dist/index.js
CHANGED
|
@@ -187,150 +187,152 @@ function handleResume() {
|
|
|
187
187
|
sdk.isPaused = false;
|
|
188
188
|
emitEvent("resume");
|
|
189
189
|
}
|
|
190
|
-
function
|
|
190
|
+
function fireResizeEvent(width, height) {
|
|
191
|
+
handleResize(width, height);
|
|
192
|
+
}
|
|
193
|
+
function startMraidProtocol() {
|
|
191
194
|
if ("mraid" !== AD_PROTOCOL) return;
|
|
192
|
-
if (
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
if (
|
|
195
|
+
if (isProtocolInitialized) return;
|
|
196
|
+
mraid.removeEventListener("ready", startMraidProtocol);
|
|
197
|
+
function mraidStateChanged(viewable) {
|
|
198
|
+
if (viewable) {
|
|
199
|
+
if (sdk.isReady) {
|
|
200
|
+
handleResume();
|
|
201
|
+
} else {
|
|
197
202
|
const maxSize = mraid.getMaxSize();
|
|
198
203
|
sdk.maxWidth = Math.floor(maxSize.width);
|
|
199
204
|
sdk.maxHeight = Math.floor(maxSize.height);
|
|
205
|
+
bootAd();
|
|
200
206
|
}
|
|
201
|
-
|
|
207
|
+
} else {
|
|
208
|
+
handlePause();
|
|
202
209
|
}
|
|
203
|
-
} else {
|
|
204
|
-
handlePause();
|
|
205
210
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
211
|
+
function isViewable() {
|
|
212
|
+
return mraid.isViewable() && "hidden" !== mraid.getState();
|
|
213
|
+
}
|
|
214
|
+
function stateChanged() {
|
|
215
|
+
mraidStateChanged(isViewable());
|
|
216
|
+
}
|
|
217
|
+
mraid.addEventListener("viewableChange", stateChanged);
|
|
218
|
+
mraid.addEventListener("stateChange", stateChanged);
|
|
219
|
+
if (isViewable()) {
|
|
220
|
+
mraidStateChanged(true);
|
|
221
|
+
}
|
|
222
|
+
if (mraid.getAudioVolume) {
|
|
223
|
+
const isAudioEnabled = mraid.getAudioVolume();
|
|
224
|
+
if (isAudioEnabled) {
|
|
225
|
+
handleVolumeChange(1);
|
|
212
226
|
} else {
|
|
213
|
-
|
|
214
|
-
screenSize.width = Math.floor(screenSize.width);
|
|
215
|
-
screenSize.height = Math.floor(screenSize.height);
|
|
216
|
-
bootAd();
|
|
227
|
+
handleVolumeChange(0);
|
|
217
228
|
}
|
|
218
|
-
} else {
|
|
219
|
-
handlePause();
|
|
220
229
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
function startMraidProtocol() {
|
|
226
|
-
if ("mraid" !== AD_PROTOCOL) return;
|
|
227
|
-
if (!isProtocolInitialized) {
|
|
228
|
-
mraid.removeEventListener("ready", startMraidProtocol);
|
|
229
|
-
mraid.addEventListener("viewableChange", function() {
|
|
230
|
-
const isViewable = mraid.isViewable();
|
|
231
|
-
mraidIsViewable(isViewable);
|
|
232
|
-
});
|
|
233
|
-
if (mraid.isViewable() || AD_NETWORK == "adcolony") {
|
|
234
|
-
mraidIsViewable(true);
|
|
235
|
-
}
|
|
236
|
-
if (mraid.getAudioVolume) {
|
|
237
|
-
const isAudioEnabled = mraid.getAudioVolume();
|
|
238
|
-
if (isAudioEnabled) {
|
|
230
|
+
mraid.addEventListener("audioVolumeChange", function(newVolume) {
|
|
231
|
+
if (newVolume !== null) {
|
|
232
|
+
if (newVolume > 0) {
|
|
239
233
|
handleVolumeChange(1);
|
|
240
234
|
} else {
|
|
241
235
|
handleVolumeChange(0);
|
|
242
236
|
}
|
|
243
237
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
mraid.addEventListener("error", function(t, e) {
|
|
254
|
-
console.log("mraid error: " + t + " action: " + e);
|
|
255
|
-
});
|
|
256
|
-
mraid.addEventListener("sizeChange", function() {
|
|
257
|
-
const maxSize = mraid.getMaxSize();
|
|
258
|
-
fireResizeEvent(maxSize.width, maxSize.height);
|
|
259
|
-
});
|
|
260
|
-
isProtocolInitialized = true;
|
|
261
|
-
}
|
|
238
|
+
});
|
|
239
|
+
mraid.addEventListener("error", function(t, e) {
|
|
240
|
+
console.log("mraid error: " + t + " action: " + e);
|
|
241
|
+
});
|
|
242
|
+
mraid.addEventListener("sizeChange", function() {
|
|
243
|
+
const maxSize = mraid.getMaxSize();
|
|
244
|
+
fireResizeEvent(maxSize.width, maxSize.height);
|
|
245
|
+
});
|
|
246
|
+
isProtocolInitialized = true;
|
|
262
247
|
}
|
|
263
248
|
function startDapiProtocol() {
|
|
264
249
|
if ("dapi" !== AD_PROTOCOL) return;
|
|
265
|
-
if (
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
250
|
+
if (isProtocolInitialized) return;
|
|
251
|
+
function dapiIsViewable(event) {
|
|
252
|
+
if (event.isViewable) {
|
|
253
|
+
if (sdk.isReady) {
|
|
254
|
+
handleResume();
|
|
255
|
+
} else {
|
|
256
|
+
const screenSize = dapi.getScreenSize();
|
|
257
|
+
screenSize.width = Math.floor(screenSize.width);
|
|
258
|
+
screenSize.height = Math.floor(screenSize.height);
|
|
259
|
+
bootAd();
|
|
260
|
+
}
|
|
261
|
+
} else {
|
|
262
|
+
handlePause();
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
dapi.removeEventListener("ready", startDapiProtocol);
|
|
266
|
+
const isAudioEnabled = dapi.getAudioVolume();
|
|
267
|
+
if (isAudioEnabled) {
|
|
268
|
+
handleVolumeChange(1);
|
|
269
|
+
} else {
|
|
270
|
+
handleVolumeChange(0);
|
|
271
|
+
}
|
|
272
|
+
dapi.addEventListener("audioVolumeChange", function(volume) {
|
|
273
|
+
const isAudioEnabled2 = !!volume;
|
|
274
|
+
if (isAudioEnabled2) {
|
|
269
275
|
handleVolumeChange(1);
|
|
270
276
|
} else {
|
|
271
277
|
handleVolumeChange(0);
|
|
272
278
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
});
|
|
281
|
-
dapi.addEventListener("adResized", function(event) {
|
|
282
|
-
const maxSize = dapi.getScreenSize();
|
|
283
|
-
fireResizeEvent(event.width || maxSize.width, event.height || maxSize.height);
|
|
284
|
-
});
|
|
285
|
-
if (dapi.isViewable()) {
|
|
286
|
-
dapiIsViewable({ isViewable: true });
|
|
287
|
-
}
|
|
288
|
-
dapi.addEventListener("viewableChange", dapiIsViewable);
|
|
289
|
-
isProtocolInitialized = true;
|
|
279
|
+
});
|
|
280
|
+
dapi.addEventListener("adResized", function(event) {
|
|
281
|
+
const maxSize = dapi.getScreenSize();
|
|
282
|
+
fireResizeEvent(event.width || maxSize.width, event.height || maxSize.height);
|
|
283
|
+
});
|
|
284
|
+
if (dapi.isViewable()) {
|
|
285
|
+
dapiIsViewable({ isViewable: true });
|
|
290
286
|
}
|
|
287
|
+
dapi.addEventListener("viewableChange", dapiIsViewable);
|
|
288
|
+
isProtocolInitialized = true;
|
|
291
289
|
}
|
|
292
290
|
function startDefaultProtocol() {
|
|
293
|
-
if (
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
291
|
+
if (isProtocolInitialized) return;
|
|
292
|
+
if ("mintegral" === AD_NETWORK) {
|
|
293
|
+
window.mintGameStart = function() {
|
|
294
|
+
handleResume();
|
|
295
|
+
handleResize(sdk.maxWidth, sdk.maxHeight);
|
|
296
|
+
};
|
|
297
|
+
window.mintGameClose = function() {
|
|
298
|
+
handlePause();
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
document.addEventListener("visibilitychange", () => {
|
|
302
|
+
if (document.visibilityState === "visible") {
|
|
303
|
+
if (sdk.isReady) {
|
|
305
304
|
handleResume();
|
|
306
305
|
} else {
|
|
307
|
-
|
|
306
|
+
bootAd();
|
|
308
307
|
}
|
|
309
|
-
});
|
|
310
|
-
if (document.readyState === "complete") {
|
|
311
|
-
bootAd();
|
|
312
308
|
} else {
|
|
313
|
-
|
|
314
|
-
bootAd();
|
|
315
|
-
});
|
|
309
|
+
handlePause();
|
|
316
310
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
311
|
+
});
|
|
312
|
+
function documentIsReady() {
|
|
313
|
+
if (document.visibilityState === "visible") bootAd();
|
|
314
|
+
}
|
|
315
|
+
if (document.readyState === "complete") {
|
|
316
|
+
documentIsReady();
|
|
317
|
+
} else {
|
|
318
|
+
window.addEventListener("load", documentIsReady);
|
|
319
|
+
}
|
|
320
|
+
window.addEventListener("resize", function() {
|
|
321
|
+
handleResize();
|
|
322
|
+
});
|
|
323
|
+
if ("tapjoy" === AD_NETWORK && isTapjoy()) {
|
|
324
|
+
const tapjoyApi = {
|
|
325
|
+
skipAd: function() {
|
|
326
|
+
try {
|
|
327
|
+
sdk.finish();
|
|
328
|
+
} catch (e) {
|
|
329
|
+
console.warn("Could not skip ad! | " + e);
|
|
328
330
|
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
isProtocolInitialized = true;
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
window.TJ_API.setPlayableAPI && window.TJ_API.setPlayableAPI(tapjoyApi);
|
|
333
334
|
}
|
|
335
|
+
isProtocolInitialized = true;
|
|
334
336
|
}
|
|
335
337
|
function finishTapjoy() {
|
|
336
338
|
window.TJ_API.objectiveComplete && window.TJ_API.objectiveComplete();
|
|
@@ -360,6 +362,18 @@ function registerTouchHandlers() {
|
|
|
360
362
|
isTouchEventRegistered = true;
|
|
361
363
|
}
|
|
362
364
|
}
|
|
365
|
+
function initSDK() {
|
|
366
|
+
destinationUrl = /android/i.test(navigator.userAgent) ? GOOGLE_PLAY_URL : APP_STORE_URL;
|
|
367
|
+
ensureProtocol();
|
|
368
|
+
if ("mraid" === AD_PROTOCOL && isMraid()) {
|
|
369
|
+
mraid.getState() === "loading" ? mraid.addEventListener("ready", startMraidProtocol) : startMraidProtocol();
|
|
370
|
+
} else if ("dapi" === AD_PROTOCOL && isDapi()) {
|
|
371
|
+
dapi.isReady() ? startDapiProtocol() : dapi.addEventListener("ready", startDapiProtocol);
|
|
372
|
+
} else {
|
|
373
|
+
startDefaultProtocol();
|
|
374
|
+
}
|
|
375
|
+
emitEvent("init");
|
|
376
|
+
}
|
|
363
377
|
var _sdk = class _sdk {
|
|
364
378
|
/**
|
|
365
379
|
* Initializes the SDK and sets up protocol-specific handlers.
|
|
@@ -381,23 +395,8 @@ var _sdk = class _sdk {
|
|
|
381
395
|
*/
|
|
382
396
|
static init(callback) {
|
|
383
397
|
if (isSDKInitialized) return;
|
|
384
|
-
destinationUrl = /android/i.test(navigator.userAgent) ? GOOGLE_PLAY_URL : APP_STORE_URL;
|
|
385
|
-
ensureProtocol();
|
|
386
398
|
if (callback) initCallback = callback;
|
|
387
|
-
|
|
388
|
-
if (mraid.getState() !== "ready") {
|
|
389
|
-
mraid.addEventListener("ready", startMraidProtocol);
|
|
390
|
-
} else {
|
|
391
|
-
startMraidProtocol();
|
|
392
|
-
}
|
|
393
|
-
} else if ("dapi" === AD_PROTOCOL && isDapi()) {
|
|
394
|
-
window.addEventListener("load", function() {
|
|
395
|
-
dapi.isReady() ? startDapiProtocol() : dapi.addEventListener("ready", startDapiProtocol);
|
|
396
|
-
});
|
|
397
|
-
} else {
|
|
398
|
-
startDefaultProtocol();
|
|
399
|
-
}
|
|
400
|
-
emitEvent("init");
|
|
399
|
+
document.readyState === "loading" ? window.addEventListener("DOMContentLoaded", initSDK) : initSDK();
|
|
401
400
|
isSDKInitialized = true;
|
|
402
401
|
}
|
|
403
402
|
/**
|
|
@@ -622,7 +621,7 @@ var _sdk = class _sdk {
|
|
|
622
621
|
}
|
|
623
622
|
};
|
|
624
623
|
/** Current version of the SDK */
|
|
625
|
-
_sdk.version = "1.0.
|
|
624
|
+
_sdk.version = "1.0.16";
|
|
626
625
|
/** Current maximum width of the playable ad container in pixels */
|
|
627
626
|
_sdk.maxWidth = Math.floor(window.innerWidth);
|
|
628
627
|
/** Current maximum height of the playable ad container in pixels */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smoud/playable-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
4
4
|
"description": "It's unified Playable SDK that supports MRAID, Google, Facebook, Vungle, and many more Ad Networks, simplifying playable ad development with a standardized interface for seamless cross-network compatibility.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|