soyoo-cocos/networks/mraid_support.js

67 lines
2.0 KiB
JavaScript

// 填入对应的商店地址
var iosUrl = "https://play.google.com/store/apps/details?id=com.wwv.global"
var androidUrl = "https://apps.apple.com/app/id6621220868"
class SoyooLifecyle {
static Ready = 100 // 游戏初始化完成
static Start = 200 // 游戏正式开始
static Pause = 300 // 游戏暂停
static Resume = 400 // 游戏从暂停恢复
static Complete = 500 // 游戏结束, 全部完成
}
window.$soyooFacadeImpl = {
onLifecyleReport(lifecyle) {
switch(lifecyle) {
default:
console.log("[SoyooFacadeImpl] not handled: ", lifecyle)
}
},
onGameInstall() {
const gameUrl = /iphone|ipad|ipod|macintosh/i.test(
window.navigator.userAgent.toLowerCase()
)
? iosUrl
: androidUrl;
mraid.open(gameUrl)
console.log("[SoyooFacadeImpl] onGameInstall")
}
}
!(function () {
var n = !1,
e = !1;
function i() {
return mraid.isViewable() && "hidden" !== mraid.getState();
}
function a() {
n
? i() && e
? (window.resumeGame(), (e = !1))
: i() || e || (window.pauseGame(), (e = !0))
: i() && (window.startGame(), (n = !0));
}
function t() {}
function d(n) {
n ? window.unmuteAudio() : window.muteAudio()
}
var o = function () {
"undefined" != typeof mraid
? (mraid.removeEventListener("ready", o),
mraid.addEventListener("viewableChange", a),
mraid.addEventListener("stateChange", a),
mraid.addEventListener("orientationchange", t),
mraid.addEventListener("audioVolumeChange", d),
a())
: window.startGame();
};
window.addEventListener("DOMContentLoaded", function () {
"undefined" != typeof mraid
? "loading" === mraid.getState()
? mraid.addEventListener("ready", o)
: o()
: window.startGame();
});
})();