520fe7f5-bb4c-4265-b398-5fc5c1d98962.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. "use strict";
  2. cc._RF.push(module, '520fef1u0xCZbOYX8XB2Yli', 'AdAgentQTT');
  3. // common-plugin/Scripts/AdAgentQTT.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 (b.hasOwnProperty(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 AdAgent_1 = require("./AdAgent");
  26. var YZ_Constant_1 = require("./YZ_Constant");
  27. var PlatUtils_1 = require("./PlatUtils");
  28. var Utils_1 = require("./Utils");
  29. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  30. /**
  31. * 趣头条广告组件
  32. */
  33. var AdAgentQTT = /** @class */ (function (_super) {
  34. __extends(AdAgentQTT, _super);
  35. function AdAgentQTT() {
  36. var _this = _super !== null && _super.apply(this, arguments) || this;
  37. _this._bannerAd = null;
  38. _this._videoAd = null;
  39. _this._isInsertAdShow = false;
  40. _this._isInsertAdLoaded = false;
  41. _this._videoCallback = null;
  42. _this._isVideoLoaded = false;
  43. _this._isVideoShow = false;
  44. //@ts-ignore
  45. _this.qttGame = window.qttGame;
  46. /**
  47. * 当视频广告资源不足
  48. * 备选互动广告
  49. * -- 平台强制添加 ---
  50. */
  51. _this.options = null;
  52. _this._insertLastShowTime = 0;
  53. return _this;
  54. }
  55. Object.defineProperty(AdAgentQTT.prototype, "ServerConfig", {
  56. get: function () {
  57. if (Utils_1.utils._tool_QTT && Utils_1.utils._tool_QTT.ServerConfig) {
  58. return Utils_1.utils._tool_QTT.ServerConfig;
  59. }
  60. return {};
  61. },
  62. enumerable: false,
  63. configurable: true
  64. });
  65. AdAgentQTT.prototype.Init = function () {
  66. if (PlatUtils_1.default.IsQTT) {
  67. if (!Utils_1.utils.config.qttconfig.showAd) {
  68. cc.warn("广告开关关闭状态,所有广告不显示!要显示广告,请打开 CommonUtils 组件上VIVIO 配置下的广告开关!");
  69. }
  70. // this.options = {};
  71. // this.options.gametype = 1;//互动游戏类型,1(砸金蛋) 2(laba) 3(大转盘)
  72. // this.options.rewardtype = 1;//互动广告框,只有 1
  73. // this.options.data = {};
  74. // this.options.data.title = "获得奖励";//互动抽中奖后的道具提示文字
  75. // this.options.data.url = "//newidea4-gamecenter-frontend.1sapp.com/game/prod/fkxxl_img/1.png";//互动抽中奖后的道具图标(可选)
  76. // this.options.callback = (res) => {
  77. // //回调函数
  78. // utils.showLog("播放互动广告>> #res=", res)
  79. // if (res == 1) {
  80. // //播放完成,发放奖励
  81. // if (this._videoCallback) {
  82. // this._videoCallback(true, "");
  83. // this._videoCallback = null;
  84. // }
  85. // } else {
  86. // //res = 0 填充不足
  87. // if (this._videoCallback) {
  88. // this._videoCallback(false, "广告加载失败,请稍后再试!");
  89. // this._videoCallback = null;
  90. // }
  91. // }
  92. // };
  93. }
  94. };
  95. /**
  96. * 创建互动广告
  97. */
  98. AdAgentQTT.prototype.createOption = function () {
  99. var _this = this;
  100. var options = {};
  101. options.gametype = (Math.floor(Math.random() * 3 + 1)); //互动游戏类型,1(砸金蛋) 2(laba) 3(大转盘)
  102. options.rewardtype = 1; //互动广告框,只有 1
  103. options.data = {};
  104. options.data.title = "获得奖励"; //互动抽中奖后的道具提示文字
  105. options.data.url = "//newidea4-gamecenter-frontend.1sapp.com/game/prod/fkxxl_img/1.png"; //互动抽中奖后的道具图标(可选)
  106. options.callback = function (res) {
  107. //回调函数
  108. Utils_1.utils.showLog("播放互动广告>> #res=", res);
  109. if (res == 1) {
  110. //播放完成,发放奖励
  111. if (_this._videoCallback) {
  112. _this._videoCallback(true, "");
  113. _this._videoCallback = null;
  114. }
  115. }
  116. else {
  117. //res = 0 填充不足
  118. if (_this._videoCallback) {
  119. _this._videoCallback(false, "广告加载失败,请稍后再试!");
  120. _this._videoCallback = null;
  121. }
  122. }
  123. };
  124. return options;
  125. };
  126. /**
  127. * 显示banner
  128. */
  129. AdAgentQTT.prototype.ShowBanner = function () {
  130. if (PlatUtils_1.default.IsQTT) {
  131. if (!Utils_1.utils.config.qttconfig.showAd) {
  132. return;
  133. }
  134. var options = {};
  135. options.index = location; //
  136. if (cc.winSize.height < cc.winSize.width) {
  137. //横屏游戏
  138. options.x = 1;
  139. options.y = 1;
  140. options.w = cc.winSize.width;
  141. options.stage_width = cc.winSize.width;
  142. options.stage_height = cc.winSize.height;
  143. }
  144. this.qttGame.showBanner(options);
  145. }
  146. };
  147. /**
  148. * 隐藏banner
  149. */
  150. AdAgentQTT.prototype.HideBanner = function () {
  151. if (PlatUtils_1.default.IsQTT) {
  152. if (!Utils_1.utils.config.qttconfig.showAd) {
  153. return;
  154. }
  155. this.qttGame.hideBanner();
  156. }
  157. };
  158. /**
  159. * 暂时没有插屏广告
  160. * @param location
  161. */
  162. AdAgentQTT.prototype.ShowInterstitial = function (location) {
  163. if (location === void 0) { location = YZ_Constant_1.BannerLocation.Home; }
  164. // if (PlatUtils.IsQTT) {
  165. // if (!utils.config.qttconfig.showAd) {
  166. // return;
  167. // }
  168. // }
  169. return;
  170. };
  171. /**
  172. * 显示互动直弹广告
  173. */
  174. AdAgentQTT.prototype.showInteractiveAd = function () {
  175. if (PlatUtils_1.default.IsQTT) {
  176. if (!this.checkInsertAdShow()) {
  177. return;
  178. }
  179. var options = {};
  180. options.rewardtype = 1; //互动广告框,只有 1
  181. Utils_1.utils.showLog("互动直弹时间间隔开始");
  182. this._insertLastShowTime = new Date().getTime();
  183. this.qttGame.showHDReward(options);
  184. }
  185. };
  186. /**
  187. * 验证插屏是否能展示
  188. * 2、时间限制 默认30秒
  189. */
  190. AdAgentQTT.prototype.checkInsertAdShow = function () {
  191. var intervalTime = this.ServerConfig.intersititial_interval_time ? this.ServerConfig.intersititial_interval_time : 30;
  192. var curTime = new Date().getTime();
  193. var interval = (curTime - this._insertLastShowTime) / 1000;
  194. Utils_1.utils.showLog("qtt服务器插屏间隔显示时间为:" + intervalTime + "秒!");
  195. Utils_1.utils.showLog("qtt插屏当前广告间隔时间:" + interval + "秒!");
  196. if (intervalTime > 0 && interval < intervalTime) {
  197. Utils_1.utils.showLog("qtt插屏广告显示的间隔少于" + intervalTime + "秒。插屏不显示");
  198. return false;
  199. }
  200. return true;
  201. };
  202. /**
  203. * 显示视频广告
  204. * @param callback 回调函数
  205. */
  206. AdAgentQTT.prototype.ShowVideo = function (callback) {
  207. var _this = this;
  208. if (PlatUtils_1.default.IsQTT) {
  209. this._videoCallback = callback;
  210. if (!Utils_1.utils.config.qttconfig.showAd) {
  211. if (this._videoCallback) {
  212. this._videoCallback(false, "暂无视频广告!");
  213. this._videoCallback = null;
  214. }
  215. return;
  216. }
  217. this._isVideoShow = true;
  218. var opt = this.createOption();
  219. this.qttGame.showVideo(function (res) {
  220. Utils_1.utils.showLog("播放视频广告>> #res=", res);
  221. if (res == 1) {
  222. if (_this._videoCallback) {
  223. _this._videoCallback(true, "");
  224. _this._videoCallback = null;
  225. }
  226. }
  227. else {
  228. if (_this._videoCallback) {
  229. if (res == 0) {
  230. _this._videoCallback(false, "广告加载失败,请稍后再试!");
  231. }
  232. else if (res == 2) {
  233. _this._videoCallback(false, "视频播放完毕才能够获取奖励!");
  234. }
  235. _this._videoCallback = null;
  236. }
  237. }
  238. }, opt);
  239. }
  240. };
  241. AdAgentQTT = __decorate([
  242. ccclass
  243. ], AdAgentQTT);
  244. return AdAgentQTT;
  245. }(AdAgent_1.default));
  246. exports.default = AdAgentQTT;
  247. cc._RF.pop();