"use strict"; cc._RF.push(module, '15d60kOwilLtqRMWwzF2A1i', 'VivoAd'); // Script/sdk/vivo/VivoAd.ts "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); var NavtiveData_1 = require("./NavtiveData"); var Utils_1 = require("../tools/Utils"); var Banner_1 = require("./Banner"); var Interstitial_1 = require("./Interstitial"); var Video_1 = require("./Video"); var Icon_1 = require("./Icon"); // Learn TypeScript: // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property; // {"id" : 1, "open" : true,"info" : "主界面插屏" }, // {"id" : 2, "open" : true, "info" : "关卡插屏" }, // {"id" : 3, "open" : true, "info" : "皮肤插屏" }, // {"id" : 4, "open" : true, "info" : "设置插屏" }, // {"id" : 5, "open" : true, "info" : "暂停插屏" }, // {"id" : 6, "open" : true, "info" : "游戏插屏" }, // {"id" : 7, "open" : true, "info" : "胜利插屏" }, // {"id" : 8, "open" : true, "info" : "失败插屏" }, // {"id" : 9, "open" : true, "info" : "复活插屏" } var VivoAd = /** @class */ (function (_super) { __extends(VivoAd, _super); function VivoAd() { var _this = _super.call(this) || this; _this._config = null; _this._vivoNativeDateList = []; _this._hideCallback = null; _this._showCallback = null; _this._nativeAdInitTime = 0; _this._adCreating = false; var self = _this; _this._utils = Utils_1.default.instance; _this._banner = new Banner_1.default(); _this._interstitial = new Interstitial_1.default(); _this._video = new Video_1.default(); _this._icon = new Icon_1.default(); return _this; } VivoAd_1 = VivoAd; Object.defineProperty(VivoAd, "Instance", { get: function () { if (VivoAd_1._instance == null) { VivoAd_1._instance = new VivoAd_1(); } return VivoAd_1._instance; }, enumerable: false, configurable: true }); VivoAd.prototype.getBanner = function () { return this._banner; }; VivoAd.prototype.getConfig = function () { return this._config; }; VivoAd.prototype.onListenHome = function () { var self = this; var isBG = false; cc.game.on(cc.game.EVENT_SHOW, function (event) { if (isBG) { self._utils.log("切换前台"); isBG = false; if (self._showCallback) { self._showCallback(); } } }); cc.game.on(cc.game.EVENT_HIDE, function (event) { if (!isBG) { self._utils.log("切换后台"); isBG = true; if (self._hideCallback) { self._hideCallback(); } } }); }; VivoAd.prototype.initConfig = function (config, callBack) { var _this = this; this._config = config; this._utils.log("config:------- " + JSON.stringify(config)); if (config) { this._banner.init(config); this._interstitial.init(config); this._video.init(config); this._icon.init(config); this.creatorNativeData(callBack); this.schedule(function () { _this.creatorNativeData(null); }, 15); //开启定时器,定时请求广告 } }; VivoAd.prototype.onHide = function (callbacks) { this._hideCallback = callbacks; }; VivoAd.prototype.onShow = function (callback) { this._showCallback = callback; }; VivoAd.prototype.getNetType = function (cb) { qg.getNetworkType({ success: function (data) { console.log("handling success: " + data.type); if (cb) { cb(data.type); } // VivoAd._instance ._netType = data.type; } }); }; //广告初始化 VivoAd.prototype.init = function () { }; //创建广告 VivoAd.prototype.creatorNativeData = function (callBack) { var _this = this; var self = this; if (self._adCreating) { this._utils.log("----有广告未完成创建 "); return; } this._utils.log("--------load ad----------"); if (this._vivoNativeDateList.length >= 2) { this._utils.log("----广告未消耗,广告列表: " + this._vivoNativeDateList.length); return; } var curTime = new Date().getTime(); var bigTime = (curTime - this._nativeAdInitTime) / 1000; this._utils.log("--------load ad time : " + bigTime); var initADgo = function () { self._adCreating = true; var navtiveData = new NavtiveData_1.default(); var go = function (success) { self._adCreating = false; if (success) { self._nativeAdInitTime = new Date().getTime(); self._vivoNativeDateList.push(navtiveData); _this._utils.log("--------广告缓存成功,列表: " + _this._vivoNativeDateList.length); } if (callBack) { callBack(success); } }; navtiveData.initAd(self._config, go); }; if (bigTime < 3.1) { //广告加载时间,离上次未到3秒,等待剩余时间 var time = 3.1 - bigTime; this._utils.log("--------离上次未到3秒,等待剩余时间 : " + bigTime); this.scheduleOnce(initADgo, time); return; } initADgo(); }; VivoAd.prototype.hasNativeData = function () { if (this._vivoNativeDateList.length > 0) { this._utils.log("----列表已存在广告: " + this._vivoNativeDateList.length); return true; } return false; }; //获取广告数据 VivoAd.prototype.getVivoNativeData = function () { this._utils.log("----广告列表: " + this._vivoNativeDateList.length); var date = null; if (this._vivoNativeDateList.length > 0) { date = this._vivoNativeDateList.shift(); } if (date && date.isReady()) { this._utils.log("-----存在新广告,用新的--------"); return date; } else { this._utils.log("-----不存在广告或只存在旧广告--------"); } this._utils.log("-----广告列表还有: " + this._vivoNativeDateList.length); return null; }; /** * 展示原生banner * @param top 是否顶部显示 */ VivoAd.prototype.showBanner = function (type, top, y, x) { if (type === void 0) { type = null; } if (top === void 0) { top = false; } if (y === void 0) { y = 0; } if (x === void 0) { x = 0; } if (this._banner) { this._banner.showBanner(type, top, x, y); } }; VivoAd.prototype.hideBanner = function () { if (this._banner) { this._banner.hideBanner(); } }; /** * 隐藏原生icon */ VivoAd.prototype.hideIcon = function () { if (this._icon) { this._icon.hideIcon(); } }; /** * 展示原生插屏 * 默认id节点为第一个0,有多个时,按服务端配置为准,进行传参 * @param id 默认0 * @param isforever true时,每次调用都会展示,false时,受服务器调用次数控制,默认false */ VivoAd.prototype.showInterstitial = function (type) { if (type === void 0) { type = Interstitial_1.InterstitialType.INTERSTITIAL_GAME_OVER; } if (this._interstitial) { this._interstitial.showInterstitial(type); } }; /** * 展示原生icon广告 * 默认id节点为第一个0,有多个时,按服务端配置为准,进行传参 * @param id */ VivoAd.prototype.showIconAd = function (id, x, y) { if (id === void 0) { id = 0; } if (this._icon) { this._icon.showIconAd(id, x, y); } }; /*显示视频*/ VivoAd.prototype.showRewardVideo = function (callBacks, fail, noAd) { this._utils.log("---------showRewardVideo-----"); var self = this; var sucCall = function () { if (callBacks) { callBacks(); } }; var failCall = function () { if (fail) { fail(); } }; var noAdCall = function () { if (noAd) { noAd(); } else { self.showToast("暂无广告!"); } }; if (this._video) this._video.showRewardVideo(sucCall, failCall, noAdCall); }; /**获取剪切板 */ VivoAd.prototype.getClipboardData = function (callbacks) { var self = this; qg.getClipboardData({ success: function (data) { if (callbacks) { callbacks(data.text); } self._utils.log("Clipboar handling success: " + data.text); }, fail: function (data, code) { self._utils.log("handling fail, code = " + code); } }); }; VivoAd.prototype.getSystemInfoSync = function () { return qg.getSystemInfoSync(); }; VivoAd.prototype.getUserId = function () { var user = qg.getUserIdSync(); ; if (user && user.userId) { return user.userId; } return "vivo not user id"; }; /** * 用户来源 */ VivoAd.prototype.getSource = function () { return qg.getLaunchOptionsSync(); }; VivoAd.prototype.showToast = function (message) { qg.showToast({ message: message }); }; var VivoAd_1; VivoAd._instance = null; VivoAd = VivoAd_1 = __decorate([ ccclass ], VivoAd); return VivoAd; }(cc.Component)); exports.default = VivoAd; cc._RF.pop();