403ecb43-a0e7-41d3-9f19-fbfefd1ec2ba.js 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547
  1. "use strict";
  2. cc._RF.push(module, '403ectDoOdB058Z+/79HsK6', 'AdAgentVIVO');
  3. // common-plugin/Scripts/AdAgentVIVO.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 NativeTryGamesWidget_1 = require("./NativeTryGamesWidget");
  30. var CompatibleTool_1 = require("./CompatibleTool");
  31. var YZ_NativeAdObject_1 = require("./YZ_NativeAdObject");
  32. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  33. var AdAgentVIVO = /** @class */ (function (_super) {
  34. __extends(AdAgentVIVO, _super);
  35. function AdAgentVIVO() {
  36. var _this = _super !== null && _super.apply(this, arguments) || this;
  37. _this._bannerAd = null;
  38. _this._insertAd = null;
  39. _this._videoAd = null;
  40. _this._nativeBannerAd = [];
  41. _this._nativeInsertAd = [];
  42. _this._nativeSingleAd = [];
  43. _this._isBannerShow = false;
  44. _this._isInsertShow = false;
  45. // 当前位置id的索引
  46. _this._curPosIdIndexNativeBanner = 0;
  47. _this._curPosIdIndexNativeInser = 0;
  48. _this._curPosIdIndexSingleNative = 0;
  49. _this._nativeData = null;
  50. _this._nativeInsertData = null;
  51. _this._nativeBannerNode = null;
  52. _this._nativeInsertNode = null;
  53. _this._videoCallback = null;
  54. _this._videoLoaded = null;
  55. _this._isInsertAdShow = false;
  56. _this._isInsertAdLoaded = false;
  57. _this._isVideoLoaded = false;
  58. _this._isVideoShow = false;
  59. _this.lastLastShowVideoTime = 0; //最后一次显示视频时间
  60. _this.showNum = 0; // Banner广告展示次数
  61. _this.showInsertNum = 0; // 插屏广告展示次数
  62. _this._curNativeItem = null;
  63. _this._nativeAdObject = null;
  64. _this._nativeAd = null;
  65. _this._nativeBannerInfo = null;
  66. //当前显示Banner的位置
  67. _this._curLocation = YZ_Constant_1.BannerLocation.None;
  68. _this._lastShowTime = 0; //上一次调用showBanner的时间
  69. _this._bannerTimeoutShow = 0;
  70. _this._nativeIsClose = false; //原生banner是否已经被关闭
  71. _this._showBannerTimerId = 0;
  72. _this._delayShowBannerId = 0;
  73. _this._startBannerTimerTask = 0;
  74. _this._tryIndex = 0;
  75. _this._nativeInsertAdShowCount = 0;
  76. _this._curNativeBannerInfo = {};
  77. _this._nativeTryGameNode = null;
  78. _this.signleNativeAd = null;
  79. _this._singleAdCreateTime = 0;
  80. _this._customAd = null;
  81. _this._refreshCustomAdTimerTask = null;
  82. _this._isHide = false;
  83. _this._lastLocation = "";
  84. return _this;
  85. }
  86. Object.defineProperty(AdAgentVIVO.prototype, "SysInfo", {
  87. get: function () {
  88. return Utils_1.utils.Tool_Vivo.SysInfo;
  89. },
  90. enumerable: false,
  91. configurable: true
  92. });
  93. Object.defineProperty(AdAgentVIVO.prototype, "ServerConfig", {
  94. get: function () {
  95. if (PlatUtils_1.default.IsVIVO) {
  96. return Utils_1.utils.Tool_Vivo.ServerConfig;
  97. }
  98. return null;
  99. },
  100. enumerable: false,
  101. configurable: true
  102. });
  103. /**
  104. * 获取当前banner配置
  105. */
  106. AdAgentVIVO.prototype.getNativeBannerInfo = function () {
  107. if (this._nativeBannerInfo && this._nativeBannerInfo.location == this._curLocation) {
  108. return this._nativeBannerInfo;
  109. }
  110. return Utils_1.utils.config.vivoconfig.getNativeBannerInfo(this._curLocation);
  111. };
  112. AdAgentVIVO.prototype.Init = function () {
  113. var _this = this;
  114. if (PlatUtils_1.default.IsVIVO) {
  115. if (Utils_1.utils.Tool_Vivo.isOverMiniVersion("1084")) {
  116. //@ts-ignore
  117. qg.isSupportNativeAd = true;
  118. }
  119. Utils_1.utils.registerServerInitEvent(function () {
  120. if (Utils_1.utils.config.vivoconfig.showAd) {
  121. _this._initVideoAd();
  122. }
  123. else {
  124. Utils_1.utils.showLog("广告开关关闭状态,所有广告不显示!要显示广告,请打开 CommonUtils 组件上VIVIO 配置下的广告开关!");
  125. }
  126. }, this);
  127. }
  128. };
  129. AdAgentVIVO.prototype._initVideoAd = function () {
  130. var _this = this;
  131. if (!this._videoAd) {
  132. if (!Utils_1.utils.Tool_Vivo.isOverMiniVersion("1041")) {
  133. Utils_1.utils.showLog("当前版本不支持视频广告!");
  134. if (this._videoCallback) {
  135. this._videoCallback(false, "暂无视频广告!");
  136. this._videoCallback = null;
  137. }
  138. return;
  139. }
  140. if (!Utils_1.utils.config.vivoconfig.videoId) {
  141. Utils_1.utils.showLog("视频ID配置不正确!");
  142. if (this._videoCallback) {
  143. this._videoCallback(false, "暂无视频广告!");
  144. this._videoCallback = null;
  145. }
  146. return;
  147. }
  148. var posId = Utils_1.utils.config.vivoconfig.videoId.trim();
  149. Utils_1.utils.showLog("video广告ID:" + posId);
  150. //@ts-ignore
  151. this._videoAd = qg.createRewardedVideoAd({
  152. posId: posId
  153. });
  154. if (this._videoAd) {
  155. this._videoAd.onLoad((function () {
  156. Utils_1.utils.showLog("激励视频加载成功!");
  157. _this._isVideoLoaded = true;
  158. if (_this._isVideoShow) {
  159. var adshow = _this._videoAd.show();
  160. // 调用then和catch之前需要对show的结果做下判空处理,防止出错(如果没有判空,在平台版本为1052以及以下的手机上将会出现错误)
  161. adshow && adshow.then(function () {
  162. _this._isVideoLoaded = false;
  163. }).catch(function (err) {
  164. if (_this._videoCallback) {
  165. _this._videoCallback(false, "暂无视频广告!");
  166. _this._videoCallback = null;
  167. }
  168. Utils_1.utils.showLog("视频播放失败!");
  169. });
  170. }
  171. }));
  172. this._videoAd.onError((function (err) {
  173. Utils_1.utils.showLog("激励视频异常!" + err.errCode);
  174. _this._isVideoLoaded = false;
  175. if (_this._videoCallback) {
  176. _this._videoCallback(false, "暂无视频广告!");
  177. _this._videoCallback = null;
  178. }
  179. }));
  180. this._videoAd.onClose(function (res) {
  181. // setTimeout(() => {
  182. // utils.showLog(`延时调用加载视频!`);
  183. _this._videoAd.load();
  184. // }, 500);
  185. _this._isVideoShow = false;
  186. if (res && res.isEnded) {
  187. Utils_1.utils.showLog("正常播放结束,可以下发游戏奖励");
  188. if (_this._videoCallback) {
  189. _this._videoCallback(true, "");
  190. _this._videoCallback = null;
  191. }
  192. }
  193. else {
  194. Utils_1.utils.showLog("播放中途退出,不下发游戏奖励");
  195. if (_this._videoCallback) {
  196. _this._videoCallback(false, "观看完视频才能获得奖励!");
  197. _this._videoCallback = null;
  198. }
  199. }
  200. });
  201. }
  202. }
  203. };
  204. AdAgentVIVO.prototype.ShowBanner = function (location, args, isTimeRefresh) {
  205. var _this = this;
  206. if (location === void 0) { location = YZ_Constant_1.BannerLocation.Home; }
  207. if (args === void 0) { args = null; }
  208. if (isTimeRefresh === void 0) { isTimeRefresh = false; }
  209. if (!this.ServerConfig) {
  210. Utils_1.utils.showLog("未请求到配置文件!");
  211. return;
  212. }
  213. var oldLocation = this._curLocation;
  214. this._curLocation = location;
  215. //如果跳用位置切换之后,验证是不是通过定时器强制刷新数据,不是则先隐藏banner
  216. if (oldLocation != location) {
  217. this.HideBanner(location);
  218. }
  219. var curTime = new Date().getTime();
  220. var refresh_ad_time = (curTime - this._startBannerTimerTask) / 1000;
  221. var interval = this.ServerConfig.refresh_ad_time;
  222. if (args && args.isRefresh) {
  223. isTimeRefresh = true;
  224. }
  225. else if (interval && interval > 0) {
  226. if (refresh_ad_time > interval) {
  227. isTimeRefresh = true;
  228. }
  229. }
  230. // 判断当前位置是不是显示banner
  231. if (this.getNativeBannerInfo().is_show_banner == -1) {
  232. Utils_1.utils.showLog("当前位置配置为不展示banner!");
  233. this.HideBanner(location);
  234. return;
  235. }
  236. else if (this.getNativeBannerInfo().is_show_rec > -1) {
  237. Utils_1.utils.showLog("当前位置显示互推banner");
  238. if (Utils_1.utils.Tool_Vivo.canShowRecommend()) {
  239. this.HideBanner(location);
  240. Utils_1.utils.Tool_Vivo.showRecBanner();
  241. return;
  242. }
  243. Utils_1.utils.showLog("当前平台不支持互推banner");
  244. }
  245. else {
  246. if (!isTimeRefresh) {
  247. if (this.ServerConfig.nbclr && this.ServerConfig.nbclr == "true" && this._curNativeBannerInfo.nativeBannerAd) {
  248. Utils_1.utils.showLog("服务器配置定时器刷新数据 ");
  249. this._showNativeBanner(this._curNativeBannerInfo.nativeBannerAd, this._curNativeBannerInfo.data);
  250. Utils_1.utils.showLog("开启定时刷新 >>>>>>>>>" + (interval - refresh_ad_time));
  251. clearTimeout(this._showBannerTimerId);
  252. clearTimeout(this._delayShowBannerId);
  253. //@ts-ignore
  254. this._showBannerTimerId = setTimeout(function () {
  255. Utils_1.utils.showLog("\u5B9A\u65F6" + interval + "\u79D2\u8C03\u7528showbanner");
  256. _this.ShowOldBanner(_this._curLocation, {});
  257. }, (interval - refresh_ad_time) * 1000);
  258. return;
  259. }
  260. }
  261. }
  262. if (Utils_1.utils._tool_Vivo.isOverMiniVersion("1059")) {
  263. this.showNewBanner(location, args);
  264. }
  265. else {
  266. this.ShowOldBanner(location, args);
  267. }
  268. };
  269. AdAgentVIVO.prototype.showNewBanner = function (location, args) {
  270. var _this = this;
  271. if (location === void 0) { location = YZ_Constant_1.BannerLocation.Home; }
  272. if (args === void 0) { args = null; }
  273. var curTime = new Date().getTime();
  274. var cap = this.ServerConfig ? this.ServerConfig.cap_show_banner_time : undefined;
  275. cap = cap ? cap : 15;
  276. if (((curTime - this._lastShowTime) / 1000) > cap) {
  277. this._lastShowTime = curTime;
  278. this.ShowOldBanner(location, args);
  279. }
  280. else {
  281. this._lastShowTime = curTime;
  282. clearTimeout(this._bannerTimeoutShow);
  283. this._bannerTimeoutShow = setTimeout(function () {
  284. Utils_1.utils.showLog("达到" + cap + "间隔,显示banner");
  285. _this.ShowOldBanner(_this._curLocation, args);
  286. }, cap * 1000);
  287. Utils_1.utils.showLog("1059以上展示banner必须间隔" + cap + "秒");
  288. }
  289. };
  290. AdAgentVIVO.prototype.ShowOldBanner = function (location, args) {
  291. var _this = this;
  292. if (location === void 0) { location = YZ_Constant_1.BannerLocation.Home; }
  293. if (args === void 0) { args = null; }
  294. if (PlatUtils_1.default.IsVIVO) {
  295. if (!Utils_1.utils.config.vivoconfig.showAd) {
  296. return;
  297. }
  298. clearTimeout(this._showBannerTimerId);
  299. clearTimeout(this._delayShowBannerId);
  300. this._nativeIsClose = false;
  301. if (this.ServerConfig) {
  302. var interval_1 = this.ServerConfig.refresh_ad_time;
  303. var bannerInfo = this.getNativeBannerInfo();
  304. if (interval_1 && interval_1 > 0) {
  305. //@ts-ignore
  306. this._showBannerTimerId = setTimeout(function () {
  307. Utils_1.utils.showLog("\u5B9A\u65F6" + interval_1 + "\u79D2\u8C03\u7528showbanner");
  308. _this.ShowBanner(location, {}, true);
  309. }, interval_1 * 1000);
  310. }
  311. if (this.ServerConfig && this.ServerConfig.isTest && this.ServerConfig.isTest == "true") {
  312. this.showNum++;
  313. //@ts-ignore
  314. if (this.showNum % 2 != 0 && qg.isSupportNativeAd) {
  315. Utils_1.utils.showLog("测试模式>> 顺序展示原生Banner广告!");
  316. this._createNativeBannerAd(this._showNativeBanner);
  317. }
  318. else {
  319. //@ts-ignore
  320. Utils_1.utils.showLog("测试模式>>" + (qg.isSupportNativeAd ? "" : "平台不支持原生广告>>" + "顺序展示小游戏Banner广告!"));
  321. this._createMiniGameBannerAd(location);
  322. }
  323. return;
  324. }
  325. if (this.ServerConfig.banner_first_ad) {
  326. //@ts-ignore
  327. if (this.ServerConfig.banner_first_ad == "native" && qg.isSupportNativeAd) {
  328. Utils_1.utils.showLog("优先展示原生Banner广告!");
  329. if (this.ServerConfig.intersititial_first_ad == "native") {
  330. var timeOut = 1;
  331. if (this.ServerConfig.native_banner_delay_time) {
  332. timeOut = this.ServerConfig.native_banner_delay_time;
  333. }
  334. Utils_1.utils.showLog("\u56E0\u4E3A\u63D2\u5C4F\u4E5F\u662F\u4F18\u5148\u5C55\u793A\u539F\u751F\uFF0C\u6240\u4EE5banner\u5EF6\u8FDF\u663E\u793A" + timeOut + "\u79D2");
  335. //@ts-ignore
  336. this._delayShowBannerId = setTimeout(function () {
  337. _this._createNativeBannerAd(_this._showNativeBanner);
  338. }, timeOut * 1000);
  339. }
  340. else {
  341. this._createNativeBannerAd(this._showNativeBanner);
  342. }
  343. }
  344. else {
  345. //@ts-ignore
  346. Utils_1.utils.showLog("优先展示小游戏Banner广告,引擎" + (qg.isSupportNativeAd ? "支持" : "不支持") + "原生广告");
  347. this._createMiniGameBannerAd(location);
  348. }
  349. }
  350. else {
  351. Utils_1.utils.showLog("配置数据中没有 banner_first_ad 字段, banner广告不显示!");
  352. }
  353. }
  354. else {
  355. Utils_1.utils.showLog("服务器配置数据未初始化!");
  356. }
  357. }
  358. };
  359. AdAgentVIVO.prototype.HideBanner = function (location) {
  360. var _this = this;
  361. if (location === void 0) { location = YZ_Constant_1.BannerLocation.Home; }
  362. if (PlatUtils_1.default.IsVIVO) {
  363. clearTimeout(this._showBannerTimerId);
  364. clearTimeout(this._delayShowBannerId);
  365. clearTimeout(this._bannerTimeoutShow);
  366. this._nativeIsClose = true;
  367. if (this._bannerAd) {
  368. var adhide = this._bannerAd.hide();
  369. adhide && adhide.then(function () {
  370. console.log("banner广告隐藏成功");
  371. }).catch(function (err) {
  372. console.log("banner广告隐藏失败", JSON.stringify(err));
  373. var addestroy = _this._bannerAd.destroy();
  374. addestroy && addestroy.then(function () {
  375. console.log("banner广告销毁成功");
  376. }).catch(function (err) {
  377. console.log("banner广告销毁失败", JSON.stringify(err));
  378. });
  379. });
  380. }
  381. if (this._nativeBannerNode) {
  382. Utils_1.utils.showLog("隐藏原生Banner");
  383. this._nativeBannerNode.active = false;
  384. }
  385. //隐藏互推banner
  386. Utils_1.utils.Tool_Vivo && Utils_1.utils.Tool_Vivo.hideRecBanner();
  387. }
  388. };
  389. AdAgentVIVO.prototype.showNativeTryGameWidget = function (params) {
  390. var _this = this;
  391. if (params === void 0) { params = null; }
  392. if (PlatUtils_1.default.IsVIVO) {
  393. Utils_1.utils.showLog("创建原生抖动广告。 posId:" + Utils_1.utils.config.vivoconfig.nativeTryGameIds[0], " utils.tryGameDate", Utils_1.utils.tryGameDate, "needchange", Utils_1.utils.nativeNeedChange);
  394. if (Utils_1.utils.nativeNeedChange || !Utils_1.utils.tryGameDate) {
  395. if (Utils_1.utils.config.vivoconfig.nativeTryGameIds) {
  396. //@ts-ignore
  397. var tryGameAd_1 = qg.createNativeAd({
  398. posId: Utils_1.utils.config.vivoconfig.nativeTryGameIds[0]
  399. });
  400. Utils_1.utils.showLog("tryGameAd:" + tryGameAd_1);
  401. if (tryGameAd_1) {
  402. tryGameAd_1.onLoad(function (res) {
  403. Utils_1.utils.showLog("res", res);
  404. Utils_1.utils.nativeNeedChange = false;
  405. _this.tryGameInfo = res.adList;
  406. if (res && res.adList && res.adList.length > 0) {
  407. Utils_1.utils.showLog("原生抖动试完广告资源拉取成功!");
  408. Utils_1.utils.showLog(JSON.stringify(res));
  409. res = JSON.parse(JSON.stringify(res));
  410. var adId_1 = res.adList[0].adId;
  411. Utils_1.utils.showLog("adId:" + adId_1);
  412. var canAdd_1 = true;
  413. Utils_1.utils.tryGameDate.forEach(function (element) {
  414. if (adId_1 == element.date[0].adId) {
  415. canAdd_1 = false;
  416. }
  417. });
  418. if (canAdd_1) {
  419. Utils_1.utils.tryGameDate.push({ "tryGameAd": tryGameAd_1, "date": _this.tryGameInfo });
  420. if (Utils_1.utils._nativeTryGameNode) {
  421. Utils_1.utils._nativeTryGameNode.getComponent(NativeTryGamesWidget_1.default).init();
  422. }
  423. }
  424. }
  425. });
  426. tryGameAd_1.onError(function (err) {
  427. console.log("原生广告加载异常", JSON.stringify(err));
  428. });
  429. tryGameAd_1.load();
  430. }
  431. }
  432. else {
  433. Utils_1.utils.showLog("原生抖动id不存在");
  434. }
  435. }
  436. this.createNativeTryGameWidget(params);
  437. }
  438. };
  439. AdAgentVIVO.prototype.ShowInterstitial = function (location) {
  440. if (location === void 0) { location = null; }
  441. if (PlatUtils_1.default.IsVIVO) {
  442. if (!Utils_1.utils.config.vivoconfig.showAd) {
  443. return;
  444. }
  445. if (this.ServerConfig && this.ServerConfig.isTest && this.ServerConfig.isTest == "true") {
  446. this.showInsertNum++;
  447. // utils.showLog(this.showInsertNum % 2 == 0, "<<this.showInsertNum % 2 == 0");
  448. //@ts-ignore
  449. if (this.showInsertNum % 2 == 0 && qg.isSupportNativeAd) {
  450. Utils_1.utils.showLog("测试模式>> 顺序展示原生插屏广告!");
  451. this.nativeInserAdDelayCall();
  452. }
  453. else {
  454. //@ts-ignore
  455. Utils_1.utils.showLog("测试模式>>" + (qg.isSupportNativeAd ? "" : "平台不支持原生广告>>") + "顺序展示小游戏插屏广告!");
  456. this._createMiniGameInsertAd();
  457. }
  458. return;
  459. }
  460. if (this.ServerConfig) {
  461. if (location && location == YZ_Constant_1.BannerLocation.Pause) {
  462. //@ts-ignore
  463. if (this.ServerConfig.intersititial_first_ad == "native" && qg.isSupportNativeAd) {
  464. Utils_1.utils.showLog("暂停界面不延时展示!");
  465. Utils_1.utils.showLog("优先展示原生插屏广告!");
  466. this.nativeInserAdDelayCall();
  467. }
  468. else {
  469. Utils_1.utils.showLog("优先展示小游戏插屏广告!");
  470. this._createMiniGameInsertAd();
  471. }
  472. }
  473. else {
  474. //@ts-ignore
  475. if (this.ServerConfig.intersititial_first_ad == "native" && qg.isSupportNativeAd) {
  476. Utils_1.utils.showLog("优先展示原生插屏广告!");
  477. Utils_1.utils.delayCall(this.nativeInserAdDelayCall.bind(this), this.ServerConfig.intersititia_delay_show_time || 0);
  478. }
  479. else {
  480. Utils_1.utils.showLog("优先展示小游戏插屏广告!");
  481. this._createMiniGameInsertAd();
  482. }
  483. }
  484. }
  485. else {
  486. Utils_1.utils.showLog("服务器配置数据未初始化!");
  487. }
  488. }
  489. };
  490. AdAgentVIVO.prototype.nativeInserAdDelayCall = function () {
  491. Utils_1.utils.showLog("原生插屏广告: 当前点击次数=" + Utils_1.utils.Tool_Vivo.NativeInsertAdClickTimes + "; 点击次数限制=" + this.ServerConfig.intersititia_click_count + "; 展示次数间隔=" + this.ServerConfig.intersititial_interval_time + "; 展示累计=" + this._nativeInsertAdShowCount);
  492. if (Utils_1.utils.Tool_Vivo.NativeInsertAdClickTimes >= (this.ServerConfig.intersititia_click_count || 0)) {
  493. // 每日点击次数到达上限,限制展示次数
  494. if (this._nativeInsertAdShowCount >= (this.ServerConfig.intersititia_show_interval || 0)) {
  495. // 可以展示
  496. this._createNativeInsertAd(this._showNativeInsert);
  497. }
  498. else {
  499. // 不能展示
  500. this._nativeInsertAdShowCount++;
  501. }
  502. }
  503. else {
  504. this._createNativeInsertAd(this._showNativeInsert);
  505. }
  506. };
  507. AdAgentVIVO.prototype.ShowVideo = function (callback) {
  508. var _this = this;
  509. if (PlatUtils_1.default.IsVIVO) {
  510. this._videoCallback = callback;
  511. if (!Utils_1.utils.config.vivoconfig.showAd) {
  512. if (this._videoCallback) {
  513. this._videoCallback(false, "暂无视频广告!");
  514. this._videoCallback = null;
  515. }
  516. return;
  517. }
  518. this._isVideoShow = true;
  519. var curTime = new Date().getTime();
  520. var interval = (curTime - this.lastLastShowVideoTime) / 1000;
  521. var interval_time = 0;
  522. if (Utils_1.utils.ServerConfig && Utils_1.utils.ServerConfig.video_interval_time) {
  523. interval_time = Utils_1.utils.ServerConfig.video_interval_time;
  524. }
  525. if (interval > interval_time) {
  526. this.lastLastShowVideoTime = new Date().getTime();
  527. if (!this._videoAd) {
  528. this._initVideoAd();
  529. }
  530. else {
  531. if (this._isVideoLoaded) {
  532. var adshow = this._videoAd.show();
  533. // 调用then和catch之前需要对show的结果做下判空处理,防止出错(如果没有判空,在平台版本为1052以及以下的手机上将会出现错误)
  534. adshow && adshow.then(function () {
  535. Utils_1.utils.showLog("视频显示成功!");
  536. _this._isVideoLoaded = false;
  537. }).catch(function (err) {
  538. Utils_1.utils.showLog("激励视频广告显示失败" + JSON.stringify(err));
  539. if (_this._videoCallback) {
  540. _this._videoCallback(false, "暂无视频广告!");
  541. _this._videoCallback = null;
  542. }
  543. });
  544. }
  545. else {
  546. this._isVideoShow = false;
  547. if (this._videoCallback) {
  548. this._videoCallback(false, "暂无视频广告!");
  549. this._videoCallback = null;
  550. }
  551. this._videoAd.load();
  552. return;
  553. }
  554. }
  555. }
  556. else {
  557. Utils_1.utils.showLog("视频广告请求间隔小于60秒,直接返回false");
  558. if (this._videoCallback) {
  559. this._videoCallback(false, "暂无视频广告!");
  560. this._videoCallback = null;
  561. }
  562. }
  563. }
  564. };
  565. AdAgentVIVO.prototype._createMiniGameInsertAd = function () {
  566. var _this = this;
  567. if (PlatUtils_1.default.IsVIVO) {
  568. this._isInsertShow = true;
  569. if (Utils_1.utils.config.vivoconfig
  570. && Utils_1.utils.config.vivoconfig.insertId) {
  571. // if (!this._insertAd) {
  572. //@ts-ignore
  573. this._insertAd = qg.createInterstitialAd({
  574. posId: Utils_1.utils.config.vivoconfig.insertId
  575. });
  576. if (this._insertAd) {
  577. Utils_1.utils.showLog("注册小游戏插屏广告回调!");
  578. this._insertAd.onError((function (err) {
  579. Utils_1.utils.showLog("vivo 小游戏插屏广告出错:" + err.errCode + err.errMsg);
  580. if (_this._isInsertShow) {
  581. if (_this.ServerConfig.intersititial_first_ad == "default") {
  582. _this._isInsertShow = false;
  583. Utils_1.utils.showLog("开始显示原生插屏广告!");
  584. _this._curPosIdIndexNativeInser = 0;
  585. Utils_1.utils.delayCall(_this.nativeInserAdDelayCall.bind(_this), _this.ServerConfig.intersititia_delay_show_time || 0);
  586. }
  587. }
  588. }).bind(this));
  589. // this._insertAd.onLoad((() => {
  590. if (this._isInsertShow) {
  591. // this._isInsertShow = false;
  592. var adshow = this._insertAd.show();
  593. // 调用then和catch之前需要对show的结果做下判空处理,防止出错(如果没有判空,在平台版本为1052以及以下的手机上将会出现错误)
  594. adshow && adshow.then(function () {
  595. Utils_1.utils.showLog("vivo 小游戏插屏广告显示成功!");
  596. _this._isInsertShow = false;
  597. }).catch(function (err) {
  598. switch (err.code) {
  599. case 30003:
  600. Utils_1.utils.showLog("新用户7天内不能曝光插屏,请将手机时间调整为7天后,退出游戏重新进入");
  601. break;
  602. case 30009:
  603. Utils_1.utils.showLog("10秒内调用广告次数超过1次,10秒后再调用");
  604. // setTimeout(() => {
  605. // show()
  606. // }, 10000);
  607. break;
  608. case 30002:
  609. Utils_1.utils.showLog("加载广告失败,重新加载广告");
  610. break;
  611. default:
  612. // 参考 https://minigame.vivo.com.cn/documents/#/lesson/open-ability/ad?id=广告错误码信息 对错误码做分类处理
  613. Utils_1.utils.showLog("插屏广告展示失败");
  614. break;
  615. }
  616. });
  617. }
  618. // }).bind(this));
  619. }
  620. // } else {
  621. // this._insertAd.load();
  622. // }
  623. if (!this._insertAd) {
  624. Utils_1.utils.showLog("vivo 小游戏插屏广告创建失败!");
  625. if (this.ServerConfig.intersititial_first_ad == "default") {
  626. Utils_1.utils.showLog("开始显示原生插屏广告!");
  627. this._curPosIdIndexNativeInser = 0;
  628. Utils_1.utils.delayCall(this.nativeInserAdDelayCall.bind(this), this.ServerConfig.intersititia_delay_show_time || 0);
  629. }
  630. }
  631. }
  632. else {
  633. Utils_1.utils.showLog("vivo 小游戏插屏广告配置信息错误!");
  634. if (this.ServerConfig.intersititial_first_ad == "default") {
  635. Utils_1.utils.showLog("开始显示原生插屏广告!");
  636. this._curPosIdIndexNativeInser = 0;
  637. Utils_1.utils.delayCall(this.nativeInserAdDelayCall.bind(this), this.ServerConfig.intersititia_delay_show_time || 0);
  638. }
  639. }
  640. }
  641. };
  642. AdAgentVIVO.prototype._createMiniGameBannerAd = function (location) {
  643. var _this = this;
  644. if (location === void 0) { location = null; }
  645. if (PlatUtils_1.default.IsVIVO) {
  646. this._isBannerShow = true;
  647. if (Utils_1.utils.config.vivoconfig
  648. && Utils_1.utils.config.vivoconfig.bannerId) {
  649. var oldBannerAd = this._bannerAd;
  650. if (oldBannerAd) {
  651. var addestroy = oldBannerAd.destroy();
  652. addestroy && addestroy.then(function () {
  653. console.log("banner广告销毁成功");
  654. }).catch(function (err) {
  655. console.log("banner广告销毁失败", JSON.stringify(err));
  656. });
  657. }
  658. // if (!this._bannerAd) {
  659. //@ts-ignore
  660. this._bannerAd = qg.createBannerAd({
  661. posId: Utils_1.utils.config.vivoconfig.bannerId,
  662. style: {}
  663. });
  664. if (this._bannerAd) {
  665. Utils_1.utils.showLog("注册小游戏banner回调!");
  666. this._bannerAd.onError((function (err) {
  667. Utils_1.utils.showLog("VIVO 广告条加载失败! code : " + err.errCode + "; msg : " + err.errMsg);
  668. var bannerInfo = _this.getNativeBannerInfo();
  669. if (bannerInfo.st_banner_show_back_up == -1) {
  670. Utils_1.utils.showLog("服务器配置不显示备用广告");
  671. return;
  672. }
  673. if (_this._isBannerShow) {
  674. _this._isBannerShow = false;
  675. if (_this.ServerConfig.banner_first_ad == "default") {
  676. _this._curPosIdIndexNativeBanner = 0;
  677. _this._createNativeBannerAd(_this._showNativeBanner.bind(_this));
  678. }
  679. }
  680. }).bind(this));
  681. }
  682. else {
  683. if (this.ServerConfig.banner_first_ad == "default") {
  684. this._curPosIdIndexNativeBanner = 0;
  685. this._createNativeBannerAd(this._showNativeBanner.bind(this));
  686. }
  687. }
  688. // }
  689. if (this._bannerAd) {
  690. var adshow = this._bannerAd.show();
  691. adshow && adshow.then(function () {
  692. Utils_1.utils.showLog("vivo小游戏banner广告展示成功");
  693. if (_this._nativeBannerNode) {
  694. _this._nativeBannerNode.active = false;
  695. }
  696. }).catch(function (err) {
  697. switch (err.code) {
  698. case 30003:
  699. Utils_1.utils.showLog("新用户7天内不能曝光Banner,请将手机时间调整为7天后,退出游戏重新进入");
  700. break;
  701. case 30009:
  702. Utils_1.utils.showLog("10秒内调用广告次数超过1次,10秒后再调用");
  703. // setTimeout(() => {
  704. // show()
  705. // }, 10000);
  706. break;
  707. case 30002:
  708. Utils_1.utils.showLog("加载广告失败,重新加载广告");
  709. break;
  710. default:
  711. // 参考 https://minigame.vivo.com.cn/documents/#/lesson/open-ability/ad?id=广告错误码信息 对错误码做分类处理
  712. Utils_1.utils.showLog("banner广告展示失败");
  713. break;
  714. }
  715. });
  716. }
  717. else {
  718. Utils_1.utils.showLog("vivo 小游戏Banner广告创建失败!");
  719. if (this.ServerConfig.banner_first_ad == "default") {
  720. this._curPosIdIndexNativeBanner = 0;
  721. this._createNativeBannerAd(this._showNativeBanner.bind(this));
  722. }
  723. }
  724. }
  725. else {
  726. Utils_1.utils.showLog("vivo 小游戏Banner广告配置信息错误!");
  727. var bannerInfo = this.getNativeBannerInfo();
  728. if (bannerInfo.st_banner_show_back_up == -1) {
  729. Utils_1.utils.showLog("服务器配置不显示备用广告");
  730. return;
  731. }
  732. if (this.ServerConfig.banner_first_ad == "default") {
  733. this._curPosIdIndexNativeBanner = 0;
  734. this._createNativeBannerAd(this._showNativeBanner.bind(this));
  735. }
  736. }
  737. }
  738. };
  739. AdAgentVIVO.prototype._createNativeBannerAd = function (completeCallback) {
  740. var _this = this;
  741. if (PlatUtils_1.default.IsVIVO) {
  742. //@ts-ignore
  743. if (!qg.isSupportNativeAd) {
  744. Utils_1.utils.showLog("当前引擎不支持原生Banner广告!");
  745. return;
  746. }
  747. var callback_1 = completeCallback;
  748. Utils_1.utils.showLog("curPosIdIndexNativeBanner:" + this._curPosIdIndexNativeBanner);
  749. if (Utils_1.utils.config.vivoconfig.nativeBannerIds
  750. && Utils_1.utils.config.vivoconfig.nativeBannerIds[this._curPosIdIndexNativeBanner]) {
  751. Utils_1.utils.showLog("创建原生广告Banner。 posId:" + Utils_1.utils.config.vivoconfig.nativeBannerIds[this._curPosIdIndexNativeBanner]);
  752. //@ts-ignore
  753. var nativeBannerAd_1 = qg.createNativeAd({
  754. posId: Utils_1.utils.config.vivoconfig.nativeBannerIds[this._curPosIdIndexNativeBanner]
  755. });
  756. if (nativeBannerAd_1) {
  757. nativeBannerAd_1.onLoad(function (res) {
  758. if (_this._nativeIsClose) {
  759. Utils_1.utils.showLog("隐藏了BANNER,不做任何处理!");
  760. return;
  761. }
  762. if (res && res.adList && res.adList.length > 0) {
  763. _this._startBannerTimerTask = new Date().getTime();
  764. Utils_1.utils.showLog("原生Banner广告资源拉取成功!");
  765. Utils_1.utils.showLog(JSON.stringify(res));
  766. res = JSON.parse(JSON.stringify(res));
  767. var data = res.adList[0];
  768. if (_this._checkNativeDataValid(data) || _this.getNativeBannerInfo().show_st_banner == "true") {
  769. _this._curPosIdIndexNativeBanner = 0;
  770. _this._showNativeBanner(nativeBannerAd_1, data);
  771. _this._curNativeBannerInfo.nativeBannerAd = nativeBannerAd_1;
  772. _this._curNativeBannerInfo.data = data;
  773. // 删除当前广告
  774. if (_this._bannerAd) {
  775. var adhide = _this._bannerAd.hide();
  776. adhide && adhide.then(function () {
  777. console.log("banner广告隐藏成功");
  778. }).catch(function (err) {
  779. console.log("banner广告隐藏失败", JSON.stringify(err));
  780. var addestroy = _this._bannerAd.destroy();
  781. addestroy && addestroy.then(function () {
  782. console.log("banner广告销毁成功");
  783. }).catch(function (err) {
  784. console.log("banner广告销毁失败", JSON.stringify(err));
  785. });
  786. });
  787. }
  788. return;
  789. }
  790. }
  791. Utils_1.utils.showLog("原生Banner广告资源出错!");
  792. _this._curPosIdIndexNativeBanner++;
  793. if (_this._curPosIdIndexNativeBanner < Utils_1.utils.config.vivoconfig.nativeBannerIds.length) {
  794. _this._createNativeBannerAd(callback_1);
  795. }
  796. else {
  797. _this._curPosIdIndexNativeBanner = 0;
  798. // 原生广告遍历完毕
  799. Utils_1.utils.showLog("原生广告条遍历完毕,无法展示!");
  800. var bannerInfo = _this.getNativeBannerInfo();
  801. if (bannerInfo.st_banner_show_back_up == -1) {
  802. Utils_1.utils.showLog(">>>>>服务器配置不显示备用广告!");
  803. return;
  804. }
  805. if (_this.ServerConfig.banner_first_ad == "native") {
  806. Utils_1.utils.showLog("开始展示小游戏广告条!");
  807. _this._createMiniGameBannerAd();
  808. }
  809. }
  810. });
  811. var adLoad = nativeBannerAd_1.load();
  812. adLoad && adLoad.then(function (res) {
  813. console.log("res", JSON.stringify(res));
  814. }).catch(function (err) {
  815. Utils_1.utils.showLog("原生Banner广告资源拉取失败!" + JSON.stringify(err));
  816. if (_this._nativeIsClose) {
  817. Utils_1.utils.showLog("隐藏了BANNER,不做任何处理!");
  818. return;
  819. }
  820. _this._curPosIdIndexNativeBanner++;
  821. if (_this._curPosIdIndexNativeBanner < Utils_1.utils.config.vivoconfig.nativeBannerIds.length) {
  822. _this._createNativeBannerAd(callback_1);
  823. }
  824. else {
  825. _this._curPosIdIndexNativeBanner = 0;
  826. // 原生广告遍历完毕
  827. Utils_1.utils.showLog("原生广告条遍历完毕,无法展示!");
  828. var bannerInfo = _this.getNativeBannerInfo();
  829. if (bannerInfo.st_banner_show_back_up == -1) {
  830. Utils_1.utils.showLog(">>>>>服务器配置不显示备用广告!");
  831. return;
  832. }
  833. if (_this.ServerConfig.banner_first_ad == "native") {
  834. Utils_1.utils.showLog("开始展示小游戏广告条!");
  835. _this._createMiniGameBannerAd();
  836. }
  837. }
  838. });
  839. }
  840. else {
  841. this._curPosIdIndexNativeBanner++;
  842. if (Utils_1.utils.config.vivoconfig.nativeBannerIds && this._curPosIdIndexNativeBanner < Utils_1.utils.config.vivoconfig.nativeBannerIds.length) {
  843. this._createNativeBannerAd(callback_1);
  844. }
  845. else {
  846. this._curPosIdIndexNativeBanner = 0;
  847. // 原生广告遍历完毕
  848. Utils_1.utils.showLog("原生广告条遍历完毕,无法展示!");
  849. var bannerInfo = this.getNativeBannerInfo();
  850. if (bannerInfo.st_banner_show_back_up == -1) {
  851. Utils_1.utils.showLog(">>>>>服务器配置不显示备用广告!");
  852. return;
  853. }
  854. if (this.ServerConfig.banner_first_ad == "native") {
  855. Utils_1.utils.showLog("开始展示小游戏广告条!");
  856. this._createMiniGameBannerAd();
  857. }
  858. }
  859. }
  860. }
  861. }
  862. };
  863. AdAgentVIVO.prototype._createNativeInsertAd = function (completeCallback) {
  864. var _this = this;
  865. if (PlatUtils_1.default.IsVIVO) {
  866. //@ts-ignore
  867. if (!qg.isSupportNativeAd) {
  868. Utils_1.utils.showLog("当前引擎不支持原生插屏广告!");
  869. return;
  870. }
  871. var callback_2 = completeCallback;
  872. Utils_1.utils.showLog("curPosIdIndexNativeInsert:" + this._curPosIdIndexNativeInser);
  873. if (Utils_1.utils.config.vivoconfig.nativeInsertIds
  874. && Utils_1.utils.config.vivoconfig.nativeInsertIds[this._curPosIdIndexNativeInser]) {
  875. Utils_1.utils.showLog("创建原生插屏广告。 posId:" + Utils_1.utils.config.vivoconfig.nativeInsertIds[this._curPosIdIndexNativeInser]);
  876. //@ts-ignore
  877. var nativeInsertAd_1 = qg.createNativeAd({
  878. posId: Utils_1.utils.config.vivoconfig.nativeInsertIds[this._curPosIdIndexNativeInser]
  879. });
  880. if (nativeInsertAd_1) {
  881. // this._nativeInsertAd.push(nativeInsertAd);
  882. nativeInsertAd_1.onLoad(function (res) {
  883. if (res && res.adList && res.adList.length > 0) {
  884. Utils_1.utils.showLog("原生插屏广告资源拉取成功!");
  885. Utils_1.utils.showLog(JSON.stringify(res));
  886. res = JSON.parse(JSON.stringify(res));
  887. var data = res.adList[0];
  888. if (_this._checkNativeInsertDataValid(data)) {
  889. _this._curPosIdIndexNativeInser = 0;
  890. _this._showNativeInsert(nativeInsertAd_1, data);
  891. return;
  892. }
  893. else {
  894. Utils_1.utils.showLog("原生插屏广告资源不合法!");
  895. }
  896. }
  897. Utils_1.utils.showLog("原生插屏广告资源出错!");
  898. _this._curPosIdIndexNativeInser++;
  899. if (_this._curPosIdIndexNativeInser < Utils_1.utils.config.vivoconfig.nativeInsertIds.length) {
  900. _this._createNativeInsertAd(callback_2);
  901. }
  902. else {
  903. _this._curPosIdIndexNativeInser = 0;
  904. // 原生广告遍历完毕
  905. Utils_1.utils.showLog("原生插屏广告遍历完毕,无法展示!");
  906. if (_this.ServerConfig.intersititial_first_ad == "native") {
  907. Utils_1.utils.showLog("开始展示小游戏插屏广告!");
  908. _this._createMiniGameInsertAd();
  909. }
  910. }
  911. });
  912. nativeInsertAd_1.onError(function (err) {
  913. Utils_1.utils.showLog("原生插屏广告创建失败!" + JSON.stringify(err));
  914. });
  915. var adLoad = nativeInsertAd_1.load();
  916. adLoad && adLoad.then(function (res) {
  917. console.log("res", JSON.stringify(res));
  918. }).catch(function (err) {
  919. Utils_1.utils.showLog("原生插屏广告资源拉取失败!" + JSON.stringify(err));
  920. _this._curPosIdIndexNativeInser++;
  921. if (_this._curPosIdIndexNativeInser < Utils_1.utils.config.vivoconfig.nativeInsertIds.length) {
  922. _this._createNativeInsertAd(callback_2);
  923. }
  924. else {
  925. _this._curPosIdIndexNativeInser = 0;
  926. // 原生广告遍历完毕
  927. Utils_1.utils.showLog("原生插屏广告遍历完毕,无法展示!");
  928. if (_this.ServerConfig.intersititial_first_ad == "native") {
  929. Utils_1.utils.showLog("开始展示小游戏插屏广告!");
  930. _this._createMiniGameInsertAd();
  931. }
  932. }
  933. });
  934. }
  935. else {
  936. this._curPosIdIndexNativeInser++;
  937. if (Utils_1.utils.config.vivoconfig.nativeInsertIds && this._curPosIdIndexNativeInser < Utils_1.utils.config.vivoconfig.nativeInsertIds.length) {
  938. this._createNativeInsertAd(callback_2);
  939. }
  940. else {
  941. this._curPosIdIndexNativeInser = 0;
  942. // 原生广告遍历完毕
  943. Utils_1.utils.showLog("原生插屏广告遍历完毕,无法展示!");
  944. if (this.ServerConfig.intersititial_first_ad == "native") {
  945. Utils_1.utils.showLog("开始展示小游戏插屏广告!");
  946. this._createMiniGameInsertAd();
  947. }
  948. }
  949. }
  950. }
  951. }
  952. };
  953. /**
  954. * 显示原生banner组件
  955. */
  956. AdAgentVIVO.prototype._showNativeBanner = function (nativeBannerAd, data) {
  957. if (PlatUtils_1.default.IsVIVO) {
  958. if (data) {
  959. Utils_1.utils.showLog("显示原生banner");
  960. if (cc.isValid(this._nativeBannerNode) && this._nativeBannerNode) {
  961. this._nativeBannerNode.destroy();
  962. }
  963. // if (!cc.isValid(this._nativeBannerNode) || (!this._nativeBannerNode && utils.config.otherconfig.nativeBanner)) {
  964. Utils_1.utils.showLog("创建原生广告banner位");
  965. this._nativeBannerNode = cc.instantiate(Utils_1.utils.config.otherconfig.nativeBanner);
  966. this._nativeBannerNode.position = CompatibleTool_1.default.position(cc.winSize.width / 2, this._nativeBannerNode.height * this._nativeBannerNode.scaleY / 2);
  967. cc.director.getScene().addChild(this._nativeBannerNode, 1000);
  968. // }
  969. if (this._nativeBannerNode) {
  970. this._nativeBannerNode.active = true;
  971. var nativeBanner = this._nativeBannerNode.getComponent("YZ_NativeBanner");
  972. if (nativeBanner) {
  973. nativeBanner.init(nativeBannerAd, data, this.getNativeBannerInfo());
  974. }
  975. else {
  976. Utils_1.utils.showLog("NativeBanner组件不存在!");
  977. }
  978. }
  979. else {
  980. Utils_1.utils.showLog("原生广告banner位没有创建!");
  981. }
  982. }
  983. }
  984. };
  985. /**
  986. * 显示原生插屏组件
  987. */
  988. AdAgentVIVO.prototype._showNativeInsert = function (nativeInsertAd, data) {
  989. if (PlatUtils_1.default.IsVIVO) {
  990. if (data) {
  991. Utils_1.utils.showLog("显示原生插屏");
  992. if ((!cc.isValid(this._nativeInsertNode)) || !this._nativeInsertNode && Utils_1.utils.config.otherconfig.nativeInsert) {
  993. Utils_1.utils.showLog("创建原生插屏广告位");
  994. this._nativeInsertNode = cc.instantiate(Utils_1.utils.config.otherconfig.nativeInsert);
  995. this._nativeInsertNode.position = CompatibleTool_1.default.position(cc.winSize.width / 2, cc.winSize.height / 2);
  996. cc.director.getScene().addChild(this._nativeInsertNode, 9999);
  997. }
  998. if (this._nativeInsertNode) {
  999. var nativeInsert = this._nativeInsertNode.getComponent("YZ_NativeInsert");
  1000. if (nativeInsert) {
  1001. this._nativeInsertAdShowCount = 0;
  1002. nativeInsert.init(nativeInsertAd, data);
  1003. }
  1004. else {
  1005. Utils_1.utils.showLog("NativeInsert组件不存在!");
  1006. }
  1007. }
  1008. else {
  1009. Utils_1.utils.showLog("原生广告插屏位没有创建!");
  1010. }
  1011. if (!this.ServerConfig.show_insert_hide_banner || this.ServerConfig.show_insert_hide_banner != "false") {
  1012. Utils_1.utils.showLog("原生广告插屏展示后隐藏Banner!");
  1013. this.HideBanner();
  1014. }
  1015. }
  1016. }
  1017. };
  1018. AdAgentVIVO.prototype.ShowCloseBtnBanner = function (location, args) {
  1019. var _this = this;
  1020. if (location === void 0) { location = YZ_Constant_1.BannerLocation.Home; }
  1021. Utils_1.utils.showLog("ShowCloseBtnBanner >>>>>>>>>.");
  1022. var isMoveBtn = 0;
  1023. var btn = args.closeBtn;
  1024. var winHeight = cc.winSize.height;
  1025. if (this.ServerConfig) {
  1026. if (this.ServerConfig.is_move_btn) {
  1027. isMoveBtn = this.ServerConfig.is_move_btn;
  1028. }
  1029. Utils_1.utils.showLog(isMoveBtn == 0 ? "显示banner,且按钮在上面" : "\u663E\u793ABanner,\u6309\u94AE\u5C45\u5E95\u90E8\u4E14" + isMoveBtn + "\u6BEB\u79D2\u540E\u79FB\u52A8");
  1030. // if (!isMoveBtn || isMoveBtn == 0) {
  1031. // btn.y = -(winHeight / 2) + btn.height;
  1032. // this.ShowBanner(location, args);
  1033. // } else {
  1034. setTimeout(function () {
  1035. // if (!this._bannerIsHide) {
  1036. Utils_1.utils.showLog("延迟调用关闭按钮的Banner >>>>");
  1037. _this.ShowBanner(location, args);
  1038. // } else {
  1039. // utils.showLog("当前Banner为隐藏状态,关闭按钮的Banner不显示 >>>>");
  1040. // }
  1041. var adY = 240;
  1042. Utils_1.utils.showLog('utils - adY:' + adY);
  1043. if (adY > 0 && btn) {
  1044. btn.y = -(winHeight / 2 - adY) + btn.height;
  1045. Utils_1.utils.showLog("btnClose.y" + btn.y);
  1046. }
  1047. }, isMoveBtn);
  1048. // }
  1049. }
  1050. };
  1051. // {"adList":[{"adId":0,"title":"快手","desc":"手机总是这么卡,如何解决","icon":"http://imgwsdl.vivo.com.cn/appstore/developer/icon/20190918/201909181113001599041.png",
  1052. // "imgUrlList":["http://ads-marketing-vivofs.vivo.com.cn/NtBrJ9dueygDLoz8/material/201908/78707646401346ca9fc8398ff79850d220190809.jpg"],
  1053. // "logoUrl":"","creativeType":0,"interactionType":2},
  1054. // {"adId":1,"title":"快手","desc":"手机总是这么卡,如何解决","icon":"http://imgwsdl.vivo.com.cn/appstore/developer/icon/20190918/201909181113001599041.png",
  1055. // "imgUrlList":["http://ads-marketing-vivofs.vivo.com.cn/NtBrJ9dueygDLoz8/material/201908/78707646401346ca9fc8398ff79850d220190809.jpg"],"logoUrl":"","creativeType":0,"interactionType":2},
  1056. // {"adId":2,"title":"快手","desc":"手机总是这么卡,如何解决","icon":"http://imgwsdl.vivo.com.cn/appstore/developer/icon/20190918/201909181113001599041.png","imgUrlList":["http://ads-marketing-vivofs.vivo.com.cn/NtBrJ9dueygDLoz8/material/201908/78707646401346ca9fc8398ff79850d220190809.jpg
  1057. AdAgentVIVO.prototype._checkNativeDataValid = function (data) {
  1058. if (!data) {
  1059. return false;
  1060. }
  1061. return (data.icon || (data.imgUrlList && data.imgUrlList.length > 0));
  1062. };
  1063. AdAgentVIVO.prototype._checkNativeInsertDataValid = function (data) {
  1064. if (!data) {
  1065. return false;
  1066. }
  1067. return (data.icon || (data.imgUrlList && data.imgUrlList.length > 0));
  1068. };
  1069. AdAgentVIVO.prototype._checkNativeSignDataValid = function (data) {
  1070. if (!data) {
  1071. return false;
  1072. }
  1073. return (data.imgUrlList && data.imgUrlList.length > 0);
  1074. };
  1075. /**
  1076. * 显示浮窗广告挂件
  1077. * @param params
  1078. * ```
  1079. * {
  1080. * group:string
  1081. * left:number
  1082. * bottom:number
  1083. * scale:number
  1084. * parent:cc.Node
  1085. * }
  1086. * ```
  1087. * @returns 生成的组件
  1088. */
  1089. AdAgentVIVO.prototype.createNativeTryGameWidget = function (params) {
  1090. if (params === void 0) { params = null; }
  1091. if (this._nativeTryGameNode && cc.isValid(this._nativeTryGameNode)) {
  1092. this._nativeTryGameNode.destroy();
  1093. }
  1094. var node = cc.instantiate(Utils_1.utils.config.otherconfig.nativeTryGameWidget);
  1095. if (node) {
  1096. this._nativeTryGameNode = node;
  1097. this._nativeTryGameNode.zIndex = 9999;
  1098. }
  1099. node = this._nativeTryGameNode;
  1100. var widget = node.getComponent(cc.Widget);
  1101. if (params) {
  1102. if (params.group) {
  1103. node.group = params.group;
  1104. }
  1105. if (params.scale != null) {
  1106. node.scale = params.scale;
  1107. }
  1108. if (params.top != null) {
  1109. widget.isAlignTop = true;
  1110. widget.isAlignBottom = false;
  1111. widget.top = params.top;
  1112. }
  1113. else if (params.bottom != null) {
  1114. widget.isAlignTop = false;
  1115. widget.isAlignBottom = true;
  1116. widget.bottom = params.bottom;
  1117. }
  1118. if (params.left != null) {
  1119. widget.isAlignLeft = true;
  1120. widget.isAlignRight = false;
  1121. widget.left = params.left;
  1122. }
  1123. else if (params.right != null) {
  1124. widget.isAlignLeft = false;
  1125. widget.isAlignRight = true;
  1126. widget.right = params.right;
  1127. }
  1128. if (params.parent != null) {
  1129. node.parent = params.parent;
  1130. }
  1131. }
  1132. widget.updateAlignment();
  1133. node.active = true;
  1134. if (this._nativeTryGameNode) {
  1135. this._nativeTryGameNode.getComponent(NativeTryGamesWidget_1.default).init();
  1136. }
  1137. };
  1138. /**
  1139. * 隐藏浮动试玩挂件
  1140. */
  1141. AdAgentVIVO.prototype.hideNativeTryGameWidget = function () {
  1142. if (this._nativeTryGameNode && cc.isValid(this._nativeTryGameNode)) {
  1143. this._nativeTryGameNode.destroy();
  1144. }
  1145. };
  1146. /**
  1147. * 创建结算页面推广组件
  1148. */
  1149. AdAgentVIVO.prototype.ShowSingleNativeAd = function (params) {
  1150. if (Utils_1.utils.config.otherconfig.singleNativeAd) {
  1151. if (this.signleNativeAd && cc.isValid(this.signleNativeAd)) {
  1152. this.signleNativeAd.destroy();
  1153. }
  1154. this.signleNativeAd = cc.instantiate(Utils_1.utils.config.otherconfig.singleNativeAd);
  1155. var nativeItem = this.signleNativeAd.getComponent("YZ_NativeItem");
  1156. nativeItem.showType = 2;
  1157. nativeItem.params = params;
  1158. this._curNativeItem = nativeItem;
  1159. if (params && params.parent) {
  1160. params.parent.addChild(this.signleNativeAd, cc.macro.MAX_ZINDEX);
  1161. }
  1162. this.createNativeAd();
  1163. Utils_1.utils.showLog("单个原生广告创建成功!");
  1164. return this.signleNativeAd;
  1165. }
  1166. else {
  1167. Utils_1.utils.showLog("未找到预制体 singleNativeAd, 请查看CommonUtils组件上是否赋值!");
  1168. return null;
  1169. }
  1170. };
  1171. /**
  1172. * 创建单个原生广告
  1173. * @param completeCallback
  1174. */
  1175. AdAgentVIVO.prototype.createNativeAd = function (params, nativeItem) {
  1176. var _this = this;
  1177. if (params === void 0) { params = null; }
  1178. Utils_1.utils.showLog("_createNativeAd >>>>>");
  1179. if (PlatUtils_1.default.IsVIVO) {
  1180. if (nativeItem) {
  1181. this._curNativeItem = nativeItem;
  1182. }
  1183. var refreshTime = this.ServerConfig.st_native_ad_refresh_time ? this.ServerConfig.st_native_ad_refresh_time : 0;
  1184. if (this._nativeAdObject && this._nativeAdObject.data && !this._nativeAdObject.is_reportClick && (new Date().getTime() - this._singleAdCreateTime) / 1000 < refreshTime) {
  1185. Utils_1.utils.showLog("\u5F53\u524D\u539F\u751F\u5E7F\u544A\u7684\u5C55\u793A\u65F6\u95F4" + (new Date().getTime() - this._singleAdCreateTime) / 1000 + "\u79D2\uFF0C\u672A\u8FBE\u5237\u65B0\u65F6\u95F4" + refreshTime + "\u79D2\u9650\u5236\uFF0C\u76F4\u63A5\u4F7F\u7528\u4E0A\u4E00\u6B21\u6570\u636E\uFF01");
  1186. this._showNativeAd();
  1187. return;
  1188. }
  1189. Utils_1.utils.showLog("_curPosIdIndexSingleNative:" + this._curPosIdIndexSingleNative + " #this._nativeSingleAd.length" + this._nativeSingleAd.length);
  1190. var nativeSingleAd_1 = this._nativeSingleAd[this._curPosIdIndexSingleNative];
  1191. if (!nativeSingleAd_1) {
  1192. if (Utils_1.utils.config.vivoconfig.nativeSingleAdIds
  1193. && Utils_1.utils.config.vivoconfig.nativeSingleAdIds[this._curPosIdIndexSingleNative]) {
  1194. Utils_1.utils.showLog("创建原生广告。 posId:" + Utils_1.utils.config.vivoconfig.nativeSingleAdIds[this._curPosIdIndexSingleNative]);
  1195. //@ts-ignore
  1196. nativeSingleAd_1 = qg.createNativeAd({
  1197. posId: Utils_1.utils.config.vivoconfig.nativeSingleAdIds[this._curPosIdIndexSingleNative]
  1198. });
  1199. if (nativeSingleAd_1) {
  1200. this._nativeSingleAd.push(nativeSingleAd_1);
  1201. nativeSingleAd_1.onLoad(function (res) {
  1202. if (res && res.adList && res.adList.length > 0) {
  1203. Utils_1.utils.showLog("原生广告资源拉取成功!");
  1204. Utils_1.utils.showLog(JSON.stringify(res));
  1205. res = JSON.parse(JSON.stringify(res));
  1206. var data = res.adList[0];
  1207. if (_this._checkNativeSignDataValid(data)) {
  1208. _this._singleAdCreateTime = new Date().getTime();
  1209. _this._curPosIdIndexSingleNative = 0;
  1210. _this._nativeData = data;
  1211. _this._nativeAd = nativeSingleAd_1;
  1212. // utils.showLog("callback >>>", callback);
  1213. // callback(this.getNativeAdData());
  1214. _this._showNativeAd();
  1215. return;
  1216. }
  1217. else {
  1218. Utils_1.utils.showLog("原生广告资源不合法!");
  1219. }
  1220. }
  1221. Utils_1.utils.showLog("原生广告资源出错!");
  1222. _this._curPosIdIndexSingleNative++;
  1223. if (_this._curPosIdIndexSingleNative < Utils_1.utils.config.vivoconfig.nativeSingleAdIds.length) {
  1224. _this.createNativeAd();
  1225. }
  1226. else {
  1227. _this._curPosIdIndexSingleNative = 0;
  1228. // 原生广告遍历完毕
  1229. Utils_1.utils.showLog("单个原生广告ID遍历完毕,无法展示!");
  1230. }
  1231. });
  1232. nativeSingleAd_1.onError(function (err) {
  1233. Utils_1.utils.showLog("原生单个广告资源拉取失败!" + err.code + err.msg);
  1234. _this._curPosIdIndexSingleNative++;
  1235. if (_this._curPosIdIndexSingleNative < Utils_1.utils.config.vivoconfig.nativeSingleAdIds.length) {
  1236. _this.createNativeAd();
  1237. }
  1238. else {
  1239. _this._curPosIdIndexSingleNative = 0;
  1240. // 原生广告遍历完毕
  1241. Utils_1.utils.showLog("单个原生广告ID遍历完毕,无法展示!");
  1242. }
  1243. });
  1244. }
  1245. }
  1246. }
  1247. if (nativeSingleAd_1) {
  1248. Utils_1.utils.showLog("nativeSingleAd reload");
  1249. nativeSingleAd_1.load();
  1250. }
  1251. else {
  1252. this._curPosIdIndexSingleNative++;
  1253. if (Utils_1.utils.config.vivoconfig.nativeSingleAdIds && this._curPosIdIndexSingleNative < Utils_1.utils.config.vivoconfig.nativeSingleAdIds.length) {
  1254. this.createNativeAd();
  1255. }
  1256. else {
  1257. this._curPosIdIndexSingleNative = 0;
  1258. // 原生广告遍历完毕
  1259. Utils_1.utils.showLog("单个原生广告ID 遍历完毕,无法展示!");
  1260. }
  1261. }
  1262. }
  1263. };
  1264. AdAgentVIVO.prototype._showNativeAd = function () {
  1265. if (this._curNativeItem && cc.isValid(this._curNativeItem.node)) {
  1266. this._curNativeItem.init(this.getNativeAdData());
  1267. }
  1268. };
  1269. /**
  1270. * 获取原生广告数据
  1271. * @param args
  1272. */
  1273. AdAgentVIVO.prototype.getNativeAdData = function () {
  1274. if (!this._nativeAdObject) {
  1275. this._nativeAdObject = new YZ_NativeAdObject_1.default();
  1276. }
  1277. this._nativeAdObject._nativeObj = this._nativeAd;
  1278. if (this._nativeAdObject.data) {
  1279. if (this._nativeAdObject.data.adId != this._nativeData.adId) {
  1280. this._nativeAdObject.is_reportClick = false;
  1281. this._nativeAdObject.is_reportShow = false;
  1282. }
  1283. }
  1284. this._nativeAdObject.data = this._nativeData;
  1285. // setTimeout(() => {
  1286. // utils.showLog("延迟两秒重新请求原生广告数据");
  1287. // this._createNativeAd(args);
  1288. // }, 2000);
  1289. if (this._nativeData && this._nativeAd) {
  1290. // this._nativeData = null;
  1291. Utils_1.utils.showLog("获取原生数据 >>>", this._nativeData, "...", this._nativeAdObject);
  1292. return this._nativeAdObject;
  1293. }
  1294. return null;
  1295. };
  1296. /**
  1297. * 显示模版广告
  1298. * @param parmas
  1299. */
  1300. AdAgentVIVO.prototype.showCustomAd = function (parme) {
  1301. var _this = this;
  1302. if (Utils_1.utils.config.vivoconfig.customAdInfos.length <= 0) {
  1303. Utils_1.utils.showLog("服务器配置未配置模版广告!");
  1304. return;
  1305. }
  1306. //@ts-ignore
  1307. if (qg.createCustomAd) {
  1308. clearTimeout(this._refreshCustomAdTimerTask);
  1309. var customAdInfo_1 = Utils_1.utils.config.vivoconfig.getCustomAdInfoInfo(parme.location);
  1310. Utils_1.utils.showLog("当前位置 obj >>>", customAdInfo_1.customAdObj);
  1311. if (customAdInfo_1.is_show_ad != "true") {
  1312. Utils_1.utils.showLog("当前位置服务器配置为不显示模版广告!");
  1313. return;
  1314. }
  1315. if (this._lastLocation != parme.location) {
  1316. this.hideCustomAd();
  1317. }
  1318. if (customAdInfo_1.customAdObj != null) {
  1319. this._customAd = customAdInfo_1.customAdObj;
  1320. if (!customAdInfo_1.customAdObj.isShow()) {
  1321. Utils_1.utils.showLog("当前位置上次展示过原生模版,当前重新显示出来!");
  1322. customAdInfo_1.customAdObj.show().then(function () {
  1323. if (customAdInfo_1.hide_banner == "true") {
  1324. _this.HideBanner();
  1325. }
  1326. Utils_1.utils.showLog("重新展示成功!");
  1327. }).catch(function (err) {
  1328. customAdInfo_1.customAdObj.destroy();
  1329. customAdInfo_1.customAdObj = null;
  1330. Utils_1.utils.showLog('重新展示原生模板广告失败', JSON.stringify(err));
  1331. _this.showCustomAd(parme);
  1332. });
  1333. }
  1334. else {
  1335. Utils_1.utils.showLog("当前位置的模版正在显示中,不执行加载!");
  1336. }
  1337. if (customAdInfo_1.refresh_time > 0) {
  1338. this._refreshCustomAdTimerTask = setTimeout(function () {
  1339. Utils_1.utils.showLog("\u5B9A\u65F6" + customAdInfo_1.refresh_time + "\u79D2\u5237\u65B0\u539F\u751F\u6A21\u7248");
  1340. _this.showCustomAd(parme);
  1341. }, customAdInfo_1.refresh_time * 1000);
  1342. }
  1343. return;
  1344. }
  1345. this._lastLocation = parme.location;
  1346. this._isHide = false;
  1347. var style = {};
  1348. if (customAdInfo_1.top > 0) {
  1349. style.top = customAdInfo_1.top / cc.winSize.height * this.SysInfo.screenHeight;
  1350. }
  1351. else if (customAdInfo_1.bottom > 0) {
  1352. style.top = this.SysInfo.screenHeight - customAdInfo_1.height - customAdInfo_1.bottom / cc.winSize.height * this.SysInfo.screenHeight;
  1353. }
  1354. if (customAdInfo_1.left > 0) {
  1355. style.left = customAdInfo_1.left / cc.winSize.width * this.SysInfo.screenWidth;
  1356. }
  1357. else if (customAdInfo_1.right > 0) {
  1358. style.left = this.SysInfo.screenWidth - customAdInfo_1.width - customAdInfo_1.right / cc.winSize.width * this.SysInfo.screenWidth;
  1359. }
  1360. Utils_1.utils.showLog("custom ad style>>" + JSON.stringify(style));
  1361. //@ts-ignore
  1362. var _customAd = qg.createCustomAd({
  1363. posId: customAdInfo_1.id,
  1364. style: style
  1365. });
  1366. _customAd.onError(function (err) {
  1367. try {
  1368. Utils_1.utils.showLog("原生模板广告加载失败", JSON.stringify(err));
  1369. }
  1370. catch (erro) {
  1371. console.log("模版异常:#errMsg=" + erro);
  1372. }
  1373. });
  1374. _customAd.onClose(function () {
  1375. Utils_1.utils.showLog("原生模板广告 onClose");
  1376. _customAd.destroy();
  1377. _customAd = null;
  1378. customAdInfo_1.customAdObj = null;
  1379. });
  1380. _customAd.onLoad(function () {
  1381. _customAd.offLoad();
  1382. Utils_1.utils.showLog("原生模板广告加载成功!");
  1383. _this._customAd = _customAd;
  1384. customAdInfo_1.customAdObj && customAdInfo_1.customAdObj.destroy();
  1385. customAdInfo_1.customAdObj = _customAd;
  1386. if (!_this._isHide) {
  1387. _customAd.show().then(function () {
  1388. if (customAdInfo_1.hide_banner == "true") {
  1389. _this.HideBanner();
  1390. }
  1391. Utils_1.utils.showLog('原生模板广告展示完成!');
  1392. }).catch(function (err) {
  1393. Utils_1.utils.showLog('原生模板广告展示失败', JSON.stringify(err));
  1394. });
  1395. }
  1396. else {
  1397. Utils_1.utils.showLog('原生模板广告调用了隐藏,当前广告不显示!');
  1398. }
  1399. });
  1400. if (customAdInfo_1.refresh_time > 0) {
  1401. this._refreshCustomAdTimerTask = setTimeout(function () {
  1402. Utils_1.utils.showLog("\u5B9A\u65F6" + customAdInfo_1.refresh_time + "\u79D2\u5237\u65B0\u539F\u751F\u6A21\u7248");
  1403. _this.showCustomAd(parme);
  1404. }, customAdInfo_1.refresh_time * 1000);
  1405. }
  1406. }
  1407. else {
  1408. Utils_1.utils.showLog("当前平台不支持原生模版广告!");
  1409. }
  1410. };
  1411. /**
  1412. * 显示模版广告
  1413. * @param parmas
  1414. */
  1415. AdAgentVIVO.prototype.showCustomAdV2 = function (parme) {
  1416. var _this = this;
  1417. if (Utils_1.utils.config.vivoconfig.customAdInfos.length <= 0) {
  1418. Utils_1.utils.showLog("服务器配置未配置模版广告!");
  1419. return;
  1420. }
  1421. //@ts-ignore
  1422. if (qg.createCustomAd) {
  1423. clearTimeout(this._refreshCustomAdTimerTask);
  1424. var customAdInfo_2 = Utils_1.utils.config.vivoconfig.getCustomAdInfoInfo(parme.location);
  1425. Utils_1.utils.showLog("当前位置的广告对象 >>>", customAdInfo_2.customAdObj);
  1426. if (customAdInfo_2.is_show_ad != "true") {
  1427. Utils_1.utils.showLog("当前位置服务器配置为不显示模版广告!");
  1428. return;
  1429. }
  1430. var isRefresh = true;
  1431. if (this._lastLocation != parme.location) {
  1432. this.hideCustomAd();
  1433. }
  1434. else {
  1435. if (customAdInfo_2.customAdObj != null) {
  1436. if (!customAdInfo_2.customAdObj.isShow()) {
  1437. Utils_1.utils.showLog("当前位置上次展示过原生模版,当前重新显示出来!");
  1438. isRefresh = false;
  1439. customAdInfo_2.customAdObj.show().then(function () {
  1440. if (customAdInfo_2.hide_banner == "true") {
  1441. _this.HideBanner();
  1442. }
  1443. Utils_1.utils.showLog("重新展示成功!");
  1444. }).catch(function (err) {
  1445. isRefresh = true;
  1446. customAdInfo_2.customAdObj.destroy();
  1447. customAdInfo_2.customAdObj = null;
  1448. Utils_1.utils.showLog('重新展示原生模板广告失败', JSON.stringify(err));
  1449. // this.showCustomAd(parme);
  1450. });
  1451. }
  1452. else {
  1453. Utils_1.utils.showLog("当前位置的模版正在显示中,不执行加载!");
  1454. }
  1455. // if (customAdInfo.refresh_time > 0) {
  1456. // this._refreshCustomAdTimerTask = setTimeout(() => {
  1457. // utils.showLog(`定时${customAdInfo.refresh_time}秒刷新原生模版`);
  1458. // this.showCustomAd(parme)
  1459. // }, customAdInfo.refresh_time * 1000);
  1460. // }
  1461. // return;
  1462. }
  1463. }
  1464. this._lastLocation = parme.location;
  1465. this._isHide = false;
  1466. var style = {};
  1467. if (customAdInfo_2.top > 0) {
  1468. style.top = customAdInfo_2.top / cc.winSize.height * this.SysInfo.screenHeight;
  1469. }
  1470. else if (customAdInfo_2.bottom > 0) {
  1471. style.top = this.SysInfo.screenHeight - customAdInfo_2.height - customAdInfo_2.bottom / cc.winSize.height * this.SysInfo.screenHeight;
  1472. }
  1473. if (customAdInfo_2.left > 0) {
  1474. style.left = customAdInfo_2.left / cc.winSize.width * this.SysInfo.screenWidth;
  1475. }
  1476. else if (customAdInfo_2.right > 0) {
  1477. style.left = this.SysInfo.screenWidth - customAdInfo_2.width - customAdInfo_2.right / cc.winSize.width * this.SysInfo.screenWidth;
  1478. }
  1479. Utils_1.utils.showLog("custom ad style>>" + JSON.stringify(style));
  1480. //@ts-ignore
  1481. var _customAd = qg.createCustomAd({
  1482. posId: customAdInfo_2.id,
  1483. style: style
  1484. });
  1485. _customAd.onError(function (err) {
  1486. try {
  1487. Utils_1.utils.showLog("原生模板广告加载失败", JSON.stringify(err));
  1488. }
  1489. catch (erro) {
  1490. console.log("模版异常:#errMsg=" + erro);
  1491. }
  1492. });
  1493. _customAd.onClose(function () {
  1494. Utils_1.utils.showLog("原生模板广告 onClose");
  1495. _customAd.destroy();
  1496. _customAd = null;
  1497. customAdInfo_2.customAdObj = null;
  1498. });
  1499. _customAd.onLoad(function () {
  1500. Utils_1.utils.showLog("原生模板广告加载成功!");
  1501. _this._customAd = _customAd;
  1502. customAdInfo_2.customAdObj && customAdInfo_2.customAdObj.destroy();
  1503. customAdInfo_2.customAdObj = _customAd;
  1504. if (!_this._isHide && isRefresh) {
  1505. _customAd.show().then(function () {
  1506. if (customAdInfo_2.hide_banner == "true") {
  1507. _this.HideBanner();
  1508. }
  1509. Utils_1.utils.showLog('原生模板广告展示完成!');
  1510. }).catch(function (err) {
  1511. Utils_1.utils.showLog('原生模板广告展示失败', JSON.stringify(err));
  1512. });
  1513. }
  1514. else {
  1515. Utils_1.utils.showLog('原生模板广告调用了隐藏或者当前不刷新广告,当前广告不显示!');
  1516. }
  1517. });
  1518. if (customAdInfo_2.refresh_time > 0) {
  1519. this._refreshCustomAdTimerTask = setTimeout(function () {
  1520. Utils_1.utils.showLog("\u5B9A\u65F6" + customAdInfo_2.refresh_time + "\u79D2\u5237\u65B0\u539F\u751F\u6A21\u7248");
  1521. _this.showCustomAd(parme);
  1522. }, customAdInfo_2.refresh_time * 1000);
  1523. }
  1524. }
  1525. else {
  1526. Utils_1.utils.showLog("当前平台不支持原生模版广告!");
  1527. }
  1528. };
  1529. /**
  1530. * 隐藏模版广告
  1531. */
  1532. AdAgentVIVO.prototype.hideCustomAd = function () {
  1533. this._isHide = true;
  1534. clearTimeout(this._refreshCustomAdTimerTask);
  1535. if (this._customAd) {
  1536. this._customAd.hide();
  1537. }
  1538. };
  1539. AdAgentVIVO = __decorate([
  1540. ccclass
  1541. ], AdAgentVIVO);
  1542. return AdAgentVIVO;
  1543. }(AdAgent_1.default));
  1544. exports.default = AdAgentVIVO;
  1545. cc._RF.pop();