15d6090e-c229-4bb6-a44c-5b0cc5d80d62.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. "use strict";
  2. cc._RF.push(module, '15d60kOwilLtqRMWwzF2A1i', 'VivoAd');
  3. // Script/sdk/vivo/VivoAd.ts
  4. "use strict";
  5. var __extends = (this && this.__extends) || (function () {
  6. var extendStatics = function (d, b) {
  7. extendStatics = Object.setPrototypeOf ||
  8. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  10. return extendStatics(d, b);
  11. };
  12. return function (d, b) {
  13. extendStatics(d, b);
  14. function __() { this.constructor = d; }
  15. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16. };
  17. })();
  18. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  19. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  20. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  21. 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;
  22. return c > 3 && r && Object.defineProperty(target, key, r), r;
  23. };
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. var NavtiveData_1 = require("./NavtiveData");
  26. var Utils_1 = require("../tools/Utils");
  27. var Banner_1 = require("./Banner");
  28. var Interstitial_1 = require("./Interstitial");
  29. var Video_1 = require("./Video");
  30. var Icon_1 = require("./Icon");
  31. // Learn TypeScript:
  32. // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
  33. // Learn Attribute:
  34. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  35. // Learn life-cycle callbacks:
  36. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  37. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  38. // {"id" : 1, "open" : true,"info" : "主界面插屏" },
  39. // {"id" : 2, "open" : true, "info" : "关卡插屏" },
  40. // {"id" : 3, "open" : true, "info" : "皮肤插屏" },
  41. // {"id" : 4, "open" : true, "info" : "设置插屏" },
  42. // {"id" : 5, "open" : true, "info" : "暂停插屏" },
  43. // {"id" : 6, "open" : true, "info" : "游戏插屏" },
  44. // {"id" : 7, "open" : true, "info" : "胜利插屏" },
  45. // {"id" : 8, "open" : true, "info" : "失败插屏" },
  46. // {"id" : 9, "open" : true, "info" : "复活插屏" }
  47. var VivoAd = /** @class */ (function (_super) {
  48. __extends(VivoAd, _super);
  49. function VivoAd() {
  50. var _this = _super.call(this) || this;
  51. _this._config = null;
  52. _this._vivoNativeDateList = [];
  53. _this._hideCallback = null;
  54. _this._showCallback = null;
  55. _this._nativeAdInitTime = 0;
  56. _this._adCreating = false;
  57. var self = _this;
  58. _this._utils = Utils_1.default.instance;
  59. _this._banner = new Banner_1.default();
  60. _this._interstitial = new Interstitial_1.default();
  61. _this._video = new Video_1.default();
  62. _this._icon = new Icon_1.default();
  63. return _this;
  64. }
  65. VivoAd_1 = VivoAd;
  66. Object.defineProperty(VivoAd, "Instance", {
  67. get: function () {
  68. if (VivoAd_1._instance == null) {
  69. VivoAd_1._instance = new VivoAd_1();
  70. }
  71. return VivoAd_1._instance;
  72. },
  73. enumerable: false,
  74. configurable: true
  75. });
  76. VivoAd.prototype.getBanner = function () {
  77. return this._banner;
  78. };
  79. VivoAd.prototype.getConfig = function () {
  80. return this._config;
  81. };
  82. VivoAd.prototype.onListenHome = function () {
  83. var self = this;
  84. var isBG = false;
  85. cc.game.on(cc.game.EVENT_SHOW, function (event) {
  86. if (isBG) {
  87. self._utils.log("切换前台");
  88. isBG = false;
  89. if (self._showCallback) {
  90. self._showCallback();
  91. }
  92. }
  93. });
  94. cc.game.on(cc.game.EVENT_HIDE, function (event) {
  95. if (!isBG) {
  96. self._utils.log("切换后台");
  97. isBG = true;
  98. if (self._hideCallback) {
  99. self._hideCallback();
  100. }
  101. }
  102. });
  103. };
  104. VivoAd.prototype.initConfig = function (config, callBack) {
  105. var _this = this;
  106. this._config = config;
  107. this._utils.log("config:------- " + JSON.stringify(config));
  108. if (config) {
  109. this._banner.init(config);
  110. this._interstitial.init(config);
  111. this._video.init(config);
  112. this._icon.init(config);
  113. this.creatorNativeData(callBack);
  114. this.schedule(function () {
  115. _this.creatorNativeData(null);
  116. }, 15); //开启定时器,定时请求广告
  117. }
  118. };
  119. VivoAd.prototype.onHide = function (callbacks) {
  120. this._hideCallback = callbacks;
  121. };
  122. VivoAd.prototype.onShow = function (callback) {
  123. this._showCallback = callback;
  124. };
  125. VivoAd.prototype.getNetType = function (cb) {
  126. qg.getNetworkType({
  127. success: function (data) {
  128. console.log("handling success: " + data.type);
  129. if (cb) {
  130. cb(data.type);
  131. }
  132. // VivoAd._instance ._netType = data.type;
  133. }
  134. });
  135. };
  136. //广告初始化
  137. VivoAd.prototype.init = function () {
  138. };
  139. //创建广告
  140. VivoAd.prototype.creatorNativeData = function (callBack) {
  141. var _this = this;
  142. var self = this;
  143. if (self._adCreating) {
  144. this._utils.log("----有广告未完成创建 ");
  145. return;
  146. }
  147. this._utils.log("--------load ad----------");
  148. if (this._vivoNativeDateList.length >= 2) {
  149. this._utils.log("----广告未消耗,广告列表: " + this._vivoNativeDateList.length);
  150. return;
  151. }
  152. var curTime = new Date().getTime();
  153. var bigTime = (curTime - this._nativeAdInitTime) / 1000;
  154. this._utils.log("--------load ad time : " + bigTime);
  155. var initADgo = function () {
  156. self._adCreating = true;
  157. var navtiveData = new NavtiveData_1.default();
  158. var go = function (success) {
  159. self._adCreating = false;
  160. if (success) {
  161. self._nativeAdInitTime = new Date().getTime();
  162. self._vivoNativeDateList.push(navtiveData);
  163. _this._utils.log("--------广告缓存成功,列表: " + _this._vivoNativeDateList.length);
  164. }
  165. if (callBack) {
  166. callBack(success);
  167. }
  168. };
  169. navtiveData.initAd(self._config, go);
  170. };
  171. if (bigTime < 3.1) { //广告加载时间,离上次未到3秒,等待剩余时间
  172. var time = 3.1 - bigTime;
  173. this._utils.log("--------离上次未到3秒,等待剩余时间 : " + bigTime);
  174. this.scheduleOnce(initADgo, time);
  175. return;
  176. }
  177. initADgo();
  178. };
  179. VivoAd.prototype.hasNativeData = function () {
  180. if (this._vivoNativeDateList.length > 0) {
  181. this._utils.log("----列表已存在广告: " + this._vivoNativeDateList.length);
  182. return true;
  183. }
  184. return false;
  185. };
  186. //获取广告数据
  187. VivoAd.prototype.getVivoNativeData = function () {
  188. this._utils.log("----广告列表: " + this._vivoNativeDateList.length);
  189. var date = null;
  190. if (this._vivoNativeDateList.length > 0) {
  191. date = this._vivoNativeDateList.shift();
  192. }
  193. if (date && date.isReady()) {
  194. this._utils.log("-----存在新广告,用新的--------");
  195. return date;
  196. }
  197. else {
  198. this._utils.log("-----不存在广告或只存在旧广告--------");
  199. }
  200. this._utils.log("-----广告列表还有: " + this._vivoNativeDateList.length);
  201. return null;
  202. };
  203. /**
  204. * 展示原生banner
  205. * @param top 是否顶部显示
  206. */
  207. VivoAd.prototype.showBanner = function (type, top, y, x) {
  208. if (type === void 0) { type = null; }
  209. if (top === void 0) { top = false; }
  210. if (y === void 0) { y = 0; }
  211. if (x === void 0) { x = 0; }
  212. if (this._banner) {
  213. this._banner.showBanner(type, top, x, y);
  214. }
  215. };
  216. VivoAd.prototype.hideBanner = function () {
  217. if (this._banner) {
  218. this._banner.hideBanner();
  219. }
  220. };
  221. /**
  222. * 隐藏原生icon
  223. */
  224. VivoAd.prototype.hideIcon = function () {
  225. if (this._icon) {
  226. this._icon.hideIcon();
  227. }
  228. };
  229. /**
  230. * 展示原生插屏
  231. * 默认id节点为第一个0,有多个时,按服务端配置为准,进行传参
  232. * @param id 默认0
  233. * @param isforever true时,每次调用都会展示,false时,受服务器调用次数控制,默认false
  234. */
  235. VivoAd.prototype.showInterstitial = function (type) {
  236. if (type === void 0) { type = Interstitial_1.InterstitialType.INTERSTITIAL_GAME_OVER; }
  237. if (this._interstitial) {
  238. this._interstitial.showInterstitial(type);
  239. }
  240. };
  241. /**
  242. * 展示原生icon广告
  243. * 默认id节点为第一个0,有多个时,按服务端配置为准,进行传参
  244. * @param id
  245. */
  246. VivoAd.prototype.showIconAd = function (id, x, y) {
  247. if (id === void 0) { id = 0; }
  248. if (this._icon) {
  249. this._icon.showIconAd(id, x, y);
  250. }
  251. };
  252. /*显示视频*/
  253. VivoAd.prototype.showRewardVideo = function (callBacks, fail, noAd) {
  254. this._utils.log("---------showRewardVideo-----");
  255. var self = this;
  256. var sucCall = function () {
  257. if (callBacks) {
  258. callBacks();
  259. }
  260. };
  261. var failCall = function () {
  262. if (fail) {
  263. fail();
  264. }
  265. };
  266. var noAdCall = function () {
  267. if (noAd) {
  268. noAd();
  269. }
  270. else {
  271. self.showToast("暂无广告!");
  272. }
  273. };
  274. if (this._video)
  275. this._video.showRewardVideo(sucCall, failCall, noAdCall);
  276. };
  277. /**获取剪切板 */
  278. VivoAd.prototype.getClipboardData = function (callbacks) {
  279. var self = this;
  280. qg.getClipboardData({
  281. success: function (data) {
  282. if (callbacks) {
  283. callbacks(data.text);
  284. }
  285. self._utils.log("Clipboar handling success: " + data.text);
  286. },
  287. fail: function (data, code) {
  288. self._utils.log("handling fail, code = " + code);
  289. }
  290. });
  291. };
  292. VivoAd.prototype.getSystemInfoSync = function () {
  293. return qg.getSystemInfoSync();
  294. };
  295. VivoAd.prototype.getUserId = function () {
  296. var user = qg.getUserIdSync();
  297. ;
  298. if (user && user.userId) {
  299. return user.userId;
  300. }
  301. return "vivo not user id";
  302. };
  303. /**
  304. * 用户来源
  305. */
  306. VivoAd.prototype.getSource = function () {
  307. return qg.getLaunchOptionsSync();
  308. };
  309. VivoAd.prototype.showToast = function (message) {
  310. qg.showToast({
  311. message: message
  312. });
  313. };
  314. var VivoAd_1;
  315. VivoAd._instance = null;
  316. VivoAd = VivoAd_1 = __decorate([
  317. ccclass
  318. ], VivoAd);
  319. return VivoAd;
  320. }(cc.Component));
  321. exports.default = VivoAd;
  322. cc._RF.pop();