290c4b09-fb81-4556-a6dd-568910f7cf83.js 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857
  1. "use strict";
  2. cc._RF.push(module, '290c4sJ+4FFVqbdVokQ98+D', 'AdAgentHuaWei');
  3. // common-plugin/Scripts/AdAgentHuaWei.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 YZ_NativeAdObject_1 = require("./YZ_NativeAdObject");
  30. var NativeTryGamesWidget_1 = require("./NativeTryGamesWidget");
  31. var CompatibleTool_1 = require("./CompatibleTool");
  32. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  33. var AdAgentHuaWei = /** @class */ (function (_super) {
  34. __extends(AdAgentHuaWei, _super);
  35. function AdAgentHuaWei() {
  36. var _this = _super !== null && _super.apply(this, arguments) || this;
  37. //@ts-ignore
  38. _this.huawei = window.qg;
  39. _this._bannerAd = null;
  40. _this._insertAd = null;
  41. _this._videoAd = null;
  42. _this._nativeBannerAd = [];
  43. _this._nativeInsertAd = [];
  44. _this._nativeSingleAd = [];
  45. _this._nativeAd = null;
  46. // 广告组件是否初始化成功
  47. _this._isAdInit = false;
  48. _this._isBannerShow = false;
  49. _this._isInsertShow = false;
  50. // 当前位置id的索引
  51. _this._curPosIdIndexNativeBanner = 0;
  52. _this._curPosIdIndexNativeInser = 0;
  53. _this._curPosIdIndexSingleNative = 0;
  54. _this._nativeData = null;
  55. _this._nativeInsertData = null;
  56. _this._nativeBannerNode = null;
  57. _this._nativeInsertNode = null;
  58. _this._videoCallback = null;
  59. _this._videoLoaded = null;
  60. _this._miniBannerHeight = 0;
  61. _this._showBannerCallBack = null;
  62. _this._nativeAdObject = null;
  63. //插屏显示次数
  64. _this._insertShowCount = 0;
  65. _this._insertLastShowTime = 0;
  66. _this._curNativeItem = null;
  67. _this._isNativeBannerShow = false; //原生广告展示,调用的隐藏
  68. _this.lastLastShowVideoTime = 0; //最后一次显示视频时间
  69. _this._bannerHideCount = 0;
  70. _this.canShowNativeBanner = true; //原生banner是否展示
  71. _this._nativeBannerInfo = null;
  72. _this.bannerType = 1;
  73. /**
  74. * banner样式:1代表原生banner,2代表默认banner
  75. */
  76. _this.banner_style_mod = [1, 2];
  77. _this.intersititialType = 1;
  78. /**
  79. * 插屏样式:1代表原生插屏,2代表默认插屏,3代表原生icon
  80. */
  81. _this.intersititial_style_mod = [1, 2, 3];
  82. /**
  83. * banner展示次数
  84. */
  85. _this.bannerTimes = 0;
  86. /**
  87. * 插屏展示次数
  88. */
  89. _this.intersititialTimes = 0;
  90. _this._nativeIsClose = false;
  91. _this._showBannerTimerId = 0;
  92. _this._delayShowBannerId = 0;
  93. // nbclr:是否开启强制刷新
  94. //当前显示Banner的位置
  95. _this._curLocation = YZ_Constant_1.BannerLocation.None;
  96. //启动定时器的时间
  97. _this._startBannerTimerTask = 0;
  98. _this.tryGameAdArr = [];
  99. _this._nativeTryGameNode = null;
  100. _this._isDataInit = false;
  101. _this._nativeSplashNode = null;
  102. _this.insertTimeID = 0;
  103. _this._nativeInsertAdShowCount = 0;
  104. /**
  105. * 验证是否第一次创建插屏
  106. */
  107. _this.miniInserAdIsCreate = false;
  108. /**
  109. * 创建小程序插屏广告
  110. * @param isUnique 是否唯一展示 不轮询显示原生
  111. */
  112. // _createMiniGameInsertAd(isUnique: boolean = false) {
  113. // if (PlatUtils.IsHuaWei) {
  114. // if (isUnique) {
  115. // if (!this.checkInsertAdShow()) return;
  116. // }
  117. // this._isInsertShow = true;
  118. // if (utils.config.huaweiConfig
  119. // && utils.config.huaweiConfig.insertId) {
  120. // //@ts-ignore
  121. // let _insertAd = qg.createInterstitialAd({
  122. // adUnitId: utils.config.huaweiConfig.insertId
  123. // });
  124. // utils.showLog("小游戏插屏ID:", utils.config.huaweiConfig.insertId);
  125. // if (_insertAd) {
  126. // utils.showLog("注册小游戏插屏广告回调!");
  127. // _insertAd.onError(((err) => {
  128. // utils.showLog("华为 小游戏插屏广告出错:" + JSON.stringify(err));
  129. // if (this._isInsertShow && !isUnique) {
  130. // if (this.ServerConfig.intersititial_style_level) {
  131. // if (this.ServerConfig.intersititial_style_mod[this.intersititialType - 1] == 2) {
  132. // utils.showLog("开始展示原生插屏!");
  133. // utils.delayCall(this.nativeInserAdDelayCall.bind(this), this.ServerConfig.intersititia_delay_show_time || 0);
  134. // }
  135. // else if (this.ServerConfig.intersititial_style_mod[this.intersititialType - 1] == 1) {
  136. // utils.showLog("开始展示原生icon!");
  137. // this.showNativeTryGameWidget();
  138. // }
  139. // }
  140. // else if (this.ServerConfig.intersititial_first_ad == "default") {
  141. // this._isInsertShow = false;
  142. // utils.showLog("开始显示原生插屏广告!");
  143. // this._curPosIdIndexNativeInser = 0;
  144. // utils.delayCall(this.nativeInserAdDelayCall.bind(this), this.ServerConfig.intersititia_delay_show_time || 0);
  145. // }
  146. // else {
  147. // utils.showLog("开始展示原生icon!");
  148. // this.showNativeTryGameWidget();
  149. // }
  150. // }
  151. // _insertAd.offError();
  152. // }).bind(this));
  153. // _insertAd.onLoad((() => {
  154. // utils.showLog("Huawei 小程序插屏广告加载成功!");
  155. // if (this._isInsertShow) {
  156. // this._isInsertShow = false;
  157. // _insertAd.show();
  158. // //onShow
  159. // this._isInsertShow = false;
  160. // // utils.Tool_Huawei.countInserShowCount();
  161. // this._insertLastShowTime = new Date().getTime();
  162. // let closeType = this.ServerConfig.intersititial_open_close_banner;
  163. // if (closeType && closeType > 0) {
  164. // utils.showLog("Huawei 配置当前插屏显示成功后" + (closeType == 1 ? "销毁" : "隐藏") + "banner!");
  165. // this.HideBanner();
  166. // }
  167. // }
  168. // _insertAd.offLoad();
  169. // }).bind(this));
  170. // // _insertAd.onClose((() => {
  171. // // utils.showLog("关闭插屏广告,展示banner")
  172. // // this.ShowBanner();
  173. // // }).bind(this));
  174. // _insertAd.load();
  175. // }
  176. // if (!_insertAd) {
  177. // utils.showLog("Huawei小游戏插屏广告创建失败!");
  178. // if (this.ServerConfig.intersititial_first_ad == "default" && !isUnique) {
  179. // utils.showLog("开始显示原生插屏广告!");
  180. // this._curPosIdIndexNativeInser = 0;
  181. // utils.delayCall(this.nativeInserAdDelayCall.bind(this), this.ServerConfig.intersititia_delay_show_time || 0);
  182. // }
  183. // }
  184. // } else {
  185. // utils.showLog("Huawei 小游戏插屏广告配置信息错误!");
  186. // if (this.ServerConfig.intersititial_first_ad == "default" && !isUnique) {
  187. // utils.showLog("开始显示原生插屏广告!");
  188. // this._curPosIdIndexNativeInser = 0;
  189. // utils.delayCall(this.nativeInserAdDelayCall.bind(this), this.ServerConfig.intersititia_delay_show_time || 0);
  190. // }
  191. // }
  192. // }
  193. // }
  194. _this._isInsertLoad = false;
  195. _this._canInsertShow = false;
  196. _this._curNativeBannerInfo = {};
  197. _this._rewardInsertNode = null;
  198. return _this;
  199. }
  200. Object.defineProperty(AdAgentHuaWei.prototype, "ServerConfig", {
  201. get: function () {
  202. if (Utils_1.utils.Tool_Huawei && Utils_1.utils.Tool_Huawei.ServerConfig)
  203. return Utils_1.utils.Tool_Huawei.ServerConfig;
  204. return {};
  205. },
  206. enumerable: false,
  207. configurable: true
  208. });
  209. /**
  210. * 获取当前banner配置
  211. */
  212. AdAgentHuaWei.prototype.getNativeBannerInfo = function () {
  213. if (this._nativeBannerInfo && this._nativeBannerInfo.location == this._curLocation) {
  214. return this._nativeBannerInfo;
  215. }
  216. return Utils_1.utils.config.huaweiConfig.getNativeBannerInfo(this._curLocation);
  217. };
  218. AdAgentHuaWei.prototype.Init = function () {
  219. var _this = this;
  220. if (PlatUtils_1.default.IsHuaWei) {
  221. cc.director.on("IsDataInit", (function () {
  222. _this._isDataInit = true;
  223. cc.director.off("IsDataInit");
  224. }), this);
  225. Utils_1.utils.registerServerInitEvent(function () {
  226. Utils_1.utils.showLog("HuaWei 广告代理组件初始化!");
  227. _this._initVideoAd();
  228. // this._initInsertAd();
  229. // this._initLocalDate();
  230. }, this);
  231. }
  232. };
  233. AdAgentHuaWei.prototype._initLocalDate = function () {
  234. if (!this.ServerConfig.banner_style_mod) {
  235. this.ServerConfig.banner_style_mod = [1, 2];
  236. }
  237. if (!this.ServerConfig.intersititial_style_mod) {
  238. this.ServerConfig.intersititial_style_mod = [1, 2, 3];
  239. }
  240. if (!this.ServerConfig.icon_jump_native) {
  241. this.ServerConfig.icon_jump_native = 1;
  242. }
  243. if (!this.ServerConfig.banner_style_level) {
  244. this.ServerConfig.banner_style_level = 2;
  245. }
  246. if (!this.ServerConfig.intersititial_style_level) {
  247. this.ServerConfig.intersititial_style_level = 2;
  248. }
  249. this.ServerConfig.intersititia_delay_show_time = 0;
  250. console.log("插屏延时展示,延时时间:" + this.ServerConfig.intersititia_delay_show_time);
  251. console.log("banner && inter", this.ServerConfig.banner_style_mod, this.ServerConfig.intersititial_style_mod);
  252. };
  253. ;
  254. AdAgentHuaWei.prototype.ShowBanner = function (location, args, isTimeRefresh) {
  255. var _this = this;
  256. if (location === void 0) { location = null; }
  257. if (args === void 0) { args = null; }
  258. if (isTimeRefresh === void 0) { isTimeRefresh = false; }
  259. // return
  260. if (PlatUtils_1.default.IsHuaWei) {
  261. if (!this.ServerConfig) {
  262. Utils_1.utils.showLog("未请求到配置文件!");
  263. return;
  264. }
  265. var oldLocation = this._curLocation;
  266. this._curLocation = location;
  267. //如果跳用位置切换之后,验证是不是通过定时器强制刷新数据,不是则先隐藏banner
  268. if (oldLocation != location) {
  269. this.HideBanner(location);
  270. }
  271. var curTime = new Date().getTime();
  272. var refresh_ad_time = (curTime - this._startBannerTimerTask) / 1000;
  273. var interval_1 = this.ServerConfig.refresh_ad_time;
  274. if (args && args.isRefresh) {
  275. isTimeRefresh = true;
  276. }
  277. else if (interval_1 && interval_1 > 0) {
  278. if (refresh_ad_time > interval_1) {
  279. isTimeRefresh = true;
  280. }
  281. }
  282. // 判断当前位置是不是显示banner
  283. if (this.getNativeBannerInfo().is_show_banner == -1) {
  284. Utils_1.utils.showLog("当前位置配置为不展示banner!");
  285. this.HideBanner(location);
  286. return;
  287. }
  288. else {
  289. if (!isTimeRefresh) {
  290. if (this.ServerConfig.nbclr && this.ServerConfig.nbclr == "true" && this._curNativeBannerInfo.nativeBannerAd) {
  291. Utils_1.utils.showLog("服务器配置定时器刷新数据 ");
  292. this._showNativeBanner(this._curNativeBannerInfo.nativeBannerAd, this._curNativeBannerInfo.data);
  293. Utils_1.utils.showLog("开启定时刷新 >>>>>>>>>" + (interval_1 - refresh_ad_time));
  294. clearTimeout(this._showBannerTimerId);
  295. clearTimeout(this._delayShowBannerId);
  296. //@ts-ignore
  297. this._showBannerTimerId = setTimeout(function () {
  298. Utils_1.utils.showLog("\u5B9A\u65F6" + interval_1 + "\u79D2\u8C03\u7528showbanner");
  299. _this.ShowBanner(_this._curLocation, {}, true);
  300. }, (interval_1 - refresh_ad_time) * 1000);
  301. return;
  302. }
  303. }
  304. }
  305. this.canShowNativeBanner = true;
  306. this._nativeIsClose = false;
  307. clearTimeout(this._showBannerTimerId);
  308. clearTimeout(this._delayShowBannerId);
  309. Utils_1.utils.showLog("清理定时器");
  310. if (this.ServerConfig) {
  311. Utils_1.utils.showLog("banner 优先展示 >>>>" + this.ServerConfig.banner_first_ad);
  312. if (interval_1 && interval_1 > 0) {
  313. Utils_1.utils.showLog("开启定时刷新 >>>>>>>>>" + interval_1);
  314. //@ts-ignore
  315. this._showBannerTimerId = setTimeout(function () {
  316. Utils_1.utils.showLog("\u5B9A\u65F6" + interval_1 + "\u79D2\u8C03\u7528showbanner");
  317. _this.ShowBanner(_this._curLocation, {}, true);
  318. }, interval_1 * 1000);
  319. }
  320. if (this.ServerConfig.banner_style_level) {
  321. if (this.ServerConfig.banner_style_mod) {
  322. if (this.ServerConfig.banner_style_mod[this.bannerType - 1] == 1) {
  323. Utils_1.utils.showLog("banner_style_mod 为 1,展示原生banner");
  324. this._createNativeBannerAd(this._showNativeBanner);
  325. }
  326. else if (this.ServerConfig.banner_style_mod[this.bannerType - 1] == 2) {
  327. Utils_1.utils.showLog("banner_style_mod 为 2,展示默认banner");
  328. this._createMiniGameBannerAd(location);
  329. }
  330. else {
  331. Utils_1.utils.showLog("banner_style_mod 配置出错!");
  332. }
  333. }
  334. else {
  335. Utils_1.utils.showLog("服务器没有配置 banner_style_mod 字段!!");
  336. this.ServerConfig.banner_style_level = 0;
  337. this.ShowBanner(location);
  338. }
  339. this.bannerTimes++;
  340. if (this.bannerTimes % this.ServerConfig.banner_style_level == 0) {
  341. this.bannerType++;
  342. this.bannerType = this.bannerType > 2 ? 1 : this.bannerType;
  343. }
  344. }
  345. else if (this.ServerConfig.banner_first_ad) {
  346. if (this.ServerConfig.banner_first_ad.indexOf("native") > -1) {
  347. Utils_1.utils.showLog("优先展示原生Banner广告!");
  348. if (this.ServerConfig.intersititial_first_ad == "native") {
  349. var timeOut = 0;
  350. if (this.ServerConfig.native_banner_delay_time) {
  351. timeOut = this.ServerConfig.native_banner_delay_time;
  352. }
  353. 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");
  354. //@ts-ignore
  355. this._delayShowBannerId = setTimeout(function () {
  356. _this._createNativeBannerAd(_this._showNativeBanner);
  357. }, timeOut * 1000);
  358. }
  359. else {
  360. this._createNativeBannerAd(this._showNativeBanner);
  361. }
  362. }
  363. else {
  364. Utils_1.utils.showLog("优先展示小游戏Banner广告!");
  365. this._createMiniGameBannerAd(location);
  366. }
  367. }
  368. else {
  369. this._createNativeBannerAd(this._showNativeBanner);
  370. }
  371. }
  372. else {
  373. Utils_1.utils.showLog("服务器配置数据未初始化!");
  374. }
  375. }
  376. };
  377. AdAgentHuaWei.prototype.HideBanner = function (location) {
  378. if (location === void 0) { location = null; }
  379. if (PlatUtils_1.default.IsHuaWei) {
  380. clearTimeout(this._showBannerTimerId);
  381. clearTimeout(this._delayShowBannerId);
  382. if (this._bannerAd) {
  383. Utils_1.utils.showLog("隐藏小游戏Banner");
  384. this._bannerAd.hide();
  385. }
  386. if (this._nativeBannerNode) {
  387. Utils_1.utils.showLog("隐藏原生Banner");
  388. this._nativeBannerNode.active = false;
  389. }
  390. }
  391. };
  392. AdAgentHuaWei.prototype.showNativeTryGameWidget = function () {
  393. var _this = this;
  394. if (PlatUtils_1.default.IsHuaWei) {
  395. Utils_1.utils.showLog("显示原生icon nativeNeedChange=", Utils_1.utils.nativeNeedChange, " utils.tryGameDate", Utils_1.utils.tryGameDate, "utils.config.huaweiConfig.nativeTryGameIds", Utils_1.utils.config.huaweiConfig.nativeTryGameIds);
  396. if (Utils_1.utils.nativeNeedChange || !Utils_1.utils.tryGameDate) {
  397. if (Utils_1.utils.config.huaweiConfig.nativeTryGameIds) {
  398. var len = Utils_1.utils.config.huaweiConfig.nativeTryGameIds.length;
  399. Utils_1.utils.showLog("len:" + len);
  400. var _loop_1 = function (i) {
  401. if (!this_1.tryGameAdArr[i]) {
  402. var posId = Utils_1.utils.config.huaweiConfig.nativeTryGameIds[i];
  403. Utils_1.utils.showLog("创建原生icon。 posId:" + posId);
  404. //@ts-ignore
  405. var tryGameAd_1 = qg.createNativeAd({
  406. adUnitId: posId,
  407. success: function (code) {
  408. console.log("loadNativeAd loadNativeAd : success");
  409. },
  410. fail: function (data, code) {
  411. console.log("loadNativeAd loadNativeAd fail: " + data + "," + code);
  412. },
  413. complete: function () {
  414. console.log("loadNativeAd loadNativeAd : complete");
  415. }
  416. });
  417. if (tryGameAd_1) {
  418. tryGameAd_1.onLoad(function (res) {
  419. Utils_1.utils.nativeNeedChange = false;
  420. console.log("原生icon加载成功");
  421. if (res && res.adList && res.adList.length > 0) {
  422. res = JSON.parse(JSON.stringify(res));
  423. var adId_1 = res.adList[0].adId;
  424. Utils_1.utils.showLog("adId:" + adId_1);
  425. var canAdd_1 = true;
  426. Utils_1.utils.tryGameDate.forEach(function (element) {
  427. if (adId_1 == element.date[0].adId) {
  428. canAdd_1 = false;
  429. }
  430. });
  431. if (canAdd_1) {
  432. Utils_1.utils.tryGameDate.push({ "tryGameAd": tryGameAd_1, "date": res.adList });
  433. if (Utils_1.utils._nativeTryGameNode) {
  434. Utils_1.utils._nativeTryGameNode.getComponent(NativeTryGamesWidget_1.default).init();
  435. }
  436. else {
  437. _this.createNativeTryGameWidget();
  438. }
  439. }
  440. Utils_1.utils.showLog("原生icon广告资源拉取成功,是否可以添加广告" + canAdd_1);
  441. Utils_1.utils.showLog(JSON.stringify(res));
  442. }
  443. });
  444. tryGameAd_1.onError(function (err) {
  445. Utils_1.utils.showLog("原生icon广告资源拉取失败!" + JSON.stringify(err));
  446. Utils_1.utils.nativeNeedChange = true;
  447. if (_this.ServerConfig.intersititial_style_level) {
  448. if (_this.ServerConfig.intersititial_style_mod[_this.intersititialType - 1] == 3) {
  449. Utils_1.utils.showLog("开始展示原生插屏!");
  450. Utils_1.utils.delayCall(_this.nativeInserAdDelayCall.bind(_this), _this.ServerConfig.intersititia_delay_show_time || 0);
  451. }
  452. }
  453. tryGameAd_1.destroy();
  454. });
  455. tryGameAd_1.load();
  456. this_1.tryGameAdArr[i] = tryGameAd_1;
  457. }
  458. }
  459. else {
  460. this_1.tryGameAdArr[i].load();
  461. }
  462. };
  463. var this_1 = this;
  464. for (var i = 0; i < len; i++) {
  465. _loop_1(i);
  466. }
  467. }
  468. }
  469. this.createNativeTryGameWidget();
  470. }
  471. };
  472. /**
  473. * 显示浮窗广告挂件
  474. * @param params
  475. * ```
  476. * {
  477. * group:string
  478. * left:number
  479. * bottom:number
  480. * scale:number
  481. * parent:cc.Node
  482. * }
  483. * ```
  484. * @returns 生成的组件
  485. */
  486. AdAgentHuaWei.prototype.createNativeTryGameWidget = function (params) {
  487. if (params === void 0) { params = null; }
  488. if (this._nativeTryGameNode && cc.isValid(this._nativeTryGameNode)) {
  489. this._nativeTryGameNode.destroy();
  490. }
  491. var node = cc.instantiate(Utils_1.utils.config.otherconfig.nativeTryGameWidget);
  492. if (node) {
  493. this._nativeTryGameNode = node;
  494. this._nativeTryGameNode.zIndex = 9999;
  495. }
  496. node = this._nativeTryGameNode;
  497. var widget = node.getComponent(cc.Widget);
  498. if (params) {
  499. if (params.group) {
  500. node.group = params.group;
  501. }
  502. if (params.scale != null) {
  503. node.scale = params.scale;
  504. }
  505. if (params.top != null) {
  506. widget.isAlignTop = true;
  507. widget.isAlignBottom = false;
  508. widget.top = params.top;
  509. }
  510. else if (params.bottom != null) {
  511. widget.isAlignTop = false;
  512. widget.isAlignBottom = true;
  513. widget.bottom = params.bottom;
  514. }
  515. if (params.left != null) {
  516. widget.isAlignLeft = true;
  517. widget.isAlignRight = false;
  518. widget.left = params.left;
  519. }
  520. else if (params.right != null) {
  521. widget.isAlignLeft = false;
  522. widget.isAlignRight = true;
  523. widget.right = params.right;
  524. }
  525. if (params.parent != null) {
  526. node.parent = params.parent;
  527. }
  528. widget.updateAlignment();
  529. }
  530. else {
  531. node.parent = cc.director.getScene();
  532. if (Utils_1.utils.otherConfig && Utils_1.utils.otherConfig.group) {
  533. node.group = Utils_1.utils.otherConfig.group;
  534. }
  535. widget.enabled = false;
  536. node.setPosition(cc.v2(cc.winSize.width / 2, cc.winSize.height / 2));
  537. }
  538. node.active = true;
  539. if (this._nativeTryGameNode) {
  540. this._nativeTryGameNode.getComponent(NativeTryGamesWidget_1.default).init();
  541. }
  542. };
  543. /**
  544. * 隐藏浮动试玩挂件
  545. */
  546. AdAgentHuaWei.prototype.hideNativeTryGameWidget = function () {
  547. if (this._nativeTryGameNode && cc.isValid(this._nativeTryGameNode)) {
  548. this._nativeTryGameNode.destroy();
  549. }
  550. };
  551. AdAgentHuaWei.prototype._canShowNativeSplashView = function (callBack) {
  552. var _this = this;
  553. if (!this._isDataInit) {
  554. Utils_1.utils.showLog("广告数据未初始化完成,设置回调>>>>>");
  555. cc.director.off("IsDataInit");
  556. var call_1 = callBack;
  557. cc.director.on("IsDataInit", (function () {
  558. Utils_1.utils.showLog("回调成功,展示开屏广告>>>>>");
  559. _this._isDataInit = true;
  560. _this.showNativeSplashView(call_1);
  561. cc.director.off("IsDataInit");
  562. }), this);
  563. return false;
  564. }
  565. return true;
  566. };
  567. AdAgentHuaWei.prototype.showNativeSplashView = function (callBack) {
  568. var _this = this;
  569. if (callBack === void 0) { callBack = null; }
  570. if (!this._canShowNativeSplashView(callBack))
  571. return;
  572. if (PlatUtils_1.default.IsHuaWei) {
  573. // utils.config.huaweiConfig.nativeSplashId = "testu7m3hc4gvm";
  574. Utils_1.utils.showLog("显示开屏广告,广告ID ", Utils_1.utils.config.huaweiConfig.nativeSplashId);
  575. if (Utils_1.utils.config.huaweiConfig.nativeSplashId) {
  576. var posId = Utils_1.utils.config.huaweiConfig.nativeSplashId;
  577. Utils_1.utils.showLog("创建原生开屏广告。 posId:" + posId);
  578. //@ts-ignore
  579. var splashView_1 = qg.createNativeAd({
  580. adUnitId: posId,
  581. success: function (code) {
  582. console.log("loadNativeAd loadNativeAd : success");
  583. },
  584. fail: function (data, code) {
  585. console.log("loadNativeAd loadNativeAd fail: " + data + "," + code);
  586. },
  587. complete: function () {
  588. console.log("loadNativeAd loadNativeAd : complete");
  589. }
  590. });
  591. if (splashView_1) {
  592. splashView_1.onLoad(function (res) {
  593. if (res && res.adList && res.adList.length > 0) {
  594. res = JSON.parse(JSON.stringify(res));
  595. var adId = res.adList[0].adId;
  596. Utils_1.utils.showLog("adId:" + adId);
  597. Utils_1.utils.showLog("原生开屏广告资源拉取成功:" + JSON.stringify(res));
  598. var data = res.adList[0];
  599. _this._creatNativeSplashView(splashView_1, data);
  600. if (callBack) {
  601. cc.director.on("SplashViewOff", (function () {
  602. callBack();
  603. cc.director.off("SplashViewOff");
  604. }), _this);
  605. }
  606. }
  607. });
  608. splashView_1.onError(function (err) {
  609. if (callBack) {
  610. callBack();
  611. }
  612. Utils_1.utils.showLog("原生开屏广告资源拉取失败!" + JSON.stringify(err));
  613. splashView_1.destroy();
  614. });
  615. splashView_1.load();
  616. }
  617. else {
  618. if (callBack) {
  619. callBack();
  620. }
  621. Utils_1.utils.showLog("原生开屏广告创建失败!");
  622. }
  623. }
  624. else {
  625. if (callBack) {
  626. callBack();
  627. }
  628. Utils_1.utils.showLog("原生开屏广告ID配置有误!!");
  629. }
  630. }
  631. };
  632. /**
  633. * 显示原生开屏组件
  634. */
  635. AdAgentHuaWei.prototype._creatNativeSplashView = function (splashView, data) {
  636. if (PlatUtils_1.default.IsHuaWei) {
  637. if (data) {
  638. if (!cc.isValid(this._nativeSplashNode) && Utils_1.utils.config.otherconfig.nativeSplashView) {
  639. Utils_1.utils.showLog("创建原生插屏广告位");
  640. this._nativeSplashNode = cc.instantiate(Utils_1.utils.config.otherconfig.nativeSplashView);
  641. this._nativeSplashNode.position = CompatibleTool_1.default.position(cc.winSize.width / 2, cc.winSize.height / 2);
  642. cc.director.getScene().addChild(this._nativeSplashNode, 999999);
  643. }
  644. if (this._nativeSplashNode) {
  645. var nativeSplash = this._nativeSplashNode.getComponent("YZ_NativeSplashView");
  646. if (nativeSplash) {
  647. nativeSplash.init(splashView, data);
  648. // utils.HuaweiTool.countInserShowCount();
  649. // utils.showLog("原生插屏显示成功,当前显示次数=" + utils.HuaweiTool.insertAdShowCounts);
  650. }
  651. else {
  652. cc.director.emit("SplashViewOff");
  653. Utils_1.utils.showLog("NativeSplashView组件不存在!");
  654. }
  655. }
  656. else {
  657. cc.director.emit("SplashViewOff");
  658. Utils_1.utils.showLog("原生开屏广告没有创建成功!");
  659. }
  660. }
  661. }
  662. };
  663. AdAgentHuaWei.prototype.ShowInterstitial = function (location) {
  664. var _this = this;
  665. if (location === void 0) { location = null; }
  666. // utils.delayCall(this.nativeInserAdDelayCall.bind(this), this.ServerConfig.intersititia_delay_show_time || 0);
  667. if (PlatUtils_1.default.IsHuaWei) {
  668. if (this.ServerConfig) {
  669. if (!this.checkInsertAdShow())
  670. return;
  671. if (location && location == YZ_Constant_1.BannerLocation.Pause) {
  672. if (this.ServerConfig.intersititial_first_ad == "native") {
  673. Utils_1.utils.showLog("暂停界面不延时展示!");
  674. Utils_1.utils.showLog("优先展示原生插屏广告!");
  675. this.nativeInserAdDelayCall();
  676. }
  677. else {
  678. Utils_1.utils.showLog("优先展示小游戏插屏广告!");
  679. this._createMiniGameInsertAd();
  680. }
  681. }
  682. else {
  683. if (this.ServerConfig.intersititial_style_level) {
  684. if (this.ServerConfig.intersititial_style_mod) {
  685. if (this.ServerConfig.intersititial_style_mod[this.intersititialType - 1] == 1) {
  686. Utils_1.utils.showLog("intersititial_style_mod 为 1,展示原生插屏");
  687. Utils_1.utils.delayCall(this.nativeInserAdDelayCall.bind(this), this.ServerConfig.intersititia_delay_show_time || 0);
  688. }
  689. else if (this.ServerConfig.intersititial_style_mod[this.intersititialType - 1] == 2) {
  690. Utils_1.utils.showLog("intersititial_style_mod 为 2,展示默认插屏");
  691. this._createMiniGameInsertAd();
  692. }
  693. else if (this.ServerConfig.intersititial_style_mod[this.intersititialType - 1] == 3) {
  694. Utils_1.utils.showLog("intersititial_style_mod 为 2,展示原生icon");
  695. this.showNativeTryGameWidget();
  696. }
  697. else {
  698. Utils_1.utils.showLog("banner_style_mod 配置出错!");
  699. }
  700. }
  701. else {
  702. Utils_1.utils.showLog("服务器没有配置 banner_style_mod 字段!!");
  703. this.ServerConfig.intersititial_style_level = 0;
  704. this.ShowInterstitial(location);
  705. }
  706. setTimeout(function () {
  707. _this.intersititialTimes++;
  708. if (_this.intersititialTimes % _this.ServerConfig.intersititial_style_level == 0) {
  709. _this.intersititialType++;
  710. _this.intersititialType = _this.intersititialType > 3 ? 1 : _this.intersititialType;
  711. }
  712. }, 3000);
  713. }
  714. else if (this.ServerConfig.intersititial_first_ad == "native") {
  715. Utils_1.utils.showLog("优先展示原生插屏广告!");
  716. Utils_1.utils.delayCall(this.nativeInserAdDelayCall.bind(this), this.ServerConfig.intersititia_delay_show_time || 0);
  717. }
  718. else {
  719. Utils_1.utils.showLog("优先展示小游戏插屏广告!");
  720. this._createMiniGameInsertAd();
  721. }
  722. }
  723. }
  724. else {
  725. Utils_1.utils.showLog("服务器配置数据未初始化!");
  726. }
  727. }
  728. };
  729. AdAgentHuaWei.prototype.nativeInserAdDelayCall = function () {
  730. // utils.showLog("原生插屏广告: 当前点击次数=" + utils.HuaweiTool.NativeInsertAdClickTimes + "; 点击次数限制=" + this.ServerConfig.intersititia_click_count + "; 展示次数间隔=" + this.ServerConfig.intersititia_show_interval + "; 展示累计=" + this._nativeInsertAdShowCount);
  731. // if (utils.HuaweiTool.NativeInsertAdClickTimes >= (this.ServerConfig.intersititia_click_count || 0)) {
  732. // // 每日点击次数到达上限,限制展示次数
  733. // if (this._nativeInsertAdShowCount >= (this.ServerConfig.intersititia_show_interval || 0)) {
  734. // 可以展示
  735. this._createNativeInsertAd(this._showNativeInsert);
  736. // } else {
  737. // // 不能展示
  738. // this._nativeInsertAdShowCount++;
  739. // }
  740. // } else {
  741. // this._createNativeInsertAd(this._showNativeInsert);
  742. // }
  743. };
  744. AdAgentHuaWei.prototype.ShowVideo = function (callback) {
  745. if (PlatUtils_1.default.IsHuaWei) {
  746. this._videoCallback = callback;
  747. var curTime = new Date().getTime();
  748. var interval = (curTime - this.lastLastShowVideoTime) / 1000;
  749. if (interval < 4) {
  750. Utils_1.utils.showLog("视频广告请求间隔小于4秒,直接返回false");
  751. if (this._videoCallback) {
  752. this._videoCallback(false, "暂无视频广告!");
  753. this._videoCallback = null;
  754. }
  755. return;
  756. }
  757. if (this.ServerConfig) {
  758. if (!this._videoAd) {
  759. this._initVideoAd();
  760. }
  761. if (this._videoAd && this._videoLoaded) {
  762. this._videoAd.show();
  763. return;
  764. }
  765. }
  766. Utils_1.utils.showLog("暂无视频广告!");
  767. this._videoAd.load();
  768. if (this._videoCallback) {
  769. this._videoCallback(false, "暂无视频广告!");
  770. this._videoCallback = null;
  771. }
  772. }
  773. };
  774. AdAgentHuaWei.prototype._initVideoAd = function () {
  775. var _this = this;
  776. if (!this._videoAd) {
  777. if (Utils_1.utils.config.huaweiConfig.videoId) {
  778. Utils_1.utils.showLog("视频广告初始化:ID=" + Utils_1.utils.config.huaweiConfig.videoId);
  779. this._videoAd = this.huawei.createRewardedVideoAd({
  780. adUnitId: Utils_1.utils.config.huaweiConfig.videoId,
  781. success: function (code) {
  782. console.log("ad demo : loadAndShowVideoAd createRewardedVideoAd: success");
  783. },
  784. fail: function (data, code) {
  785. console.log("ad demo : loadAndShowVideoAd createRewardedVideoAd fail: " + data + "," + code);
  786. },
  787. complete: function () {
  788. console.log("ad demo : loadAndShowVideoAd createRewardedVideoAd complete");
  789. }
  790. });
  791. var self_1 = this;
  792. if (this._videoAd) {
  793. Utils_1.utils.showLog("初始化注册视频回调!");
  794. this._videoAd.onLoad(function () {
  795. Utils_1.utils.showLog("激励视频加载成功");
  796. self_1._videoLoaded = true;
  797. });
  798. this._videoAd.onError(function (err) {
  799. Utils_1.utils.showLog("激励视频出错: " + err.code + err.msg);
  800. self_1._videoLoaded = false;
  801. if (self_1._videoCallback) {
  802. self_1._videoCallback(false, "暂无视频广告!");
  803. self_1._videoCallback = null;
  804. }
  805. });
  806. this._videoAd.onClose(function (res) {
  807. setTimeout(function () {
  808. self_1._videoAd.load();
  809. Utils_1.utils.showLog("延迟3秒重新加载视频广告");
  810. }, 3000);
  811. if (res.isEnded) {
  812. _this.lastLastShowVideoTime = new Date().getTime();
  813. Utils_1.utils.showLog('激励视频广告完成,发放奖励');
  814. if (self_1._videoCallback) {
  815. self_1._videoCallback(true, "");
  816. self_1._videoCallback = null;
  817. }
  818. }
  819. else {
  820. Utils_1.utils.showLog('激励视频广告取消关闭,不发放奖励');
  821. if (self_1._videoCallback) {
  822. self_1._videoCallback(false, "观看完视频才能获得奖励!");
  823. self_1._videoCallback = null;
  824. }
  825. }
  826. });
  827. this._videoAd.load();
  828. }
  829. }
  830. else {
  831. Utils_1.utils.showLog("视频广告Id配置错误!");
  832. }
  833. }
  834. };
  835. /**
  836. * 验证插屏是否能展示
  837. * 1、次数限制 默认每日8次
  838. * 2、时间限制 默认60秒
  839. */
  840. AdAgentHuaWei.prototype.checkInsertAdShow = function () {
  841. var maxShowCount = this.ServerConfig.intersititial_max_show_count;
  842. var intervalTime = this.ServerConfig.intersititial_interval_time;
  843. var curTime = new Date().getTime();
  844. var interval = (curTime - this._insertLastShowTime) / 1000;
  845. Utils_1.utils.showLog("Huawei服务器插屏最大显示次数为:" + maxShowCount + ",间隔显示时间为:" + intervalTime + "秒!");
  846. // utils.showLog("Huawei插屏当前广告显示次数:" + utils.Tool_Huawei.insertAdShowCounts + "次,间隔时间:" + interval + "秒!");
  847. // if (maxShowCount > 0 && utils.HuaweiTool.insertAdShowCounts >= maxShowCount) {
  848. // utils.showLog("Huawei插屏广告显示的次数达到" + maxShowCount + "次。插屏不显示");
  849. // return false;
  850. // }
  851. if (intervalTime > 0 && interval < intervalTime) {
  852. Utils_1.utils.showLog("Huawei插屏广告显示的间隔少于" + intervalTime + "秒。插屏不显示");
  853. return false;
  854. }
  855. return true;
  856. };
  857. AdAgentHuaWei.prototype._initInsertAd = function () {
  858. var _this = this;
  859. if (!this._insertAd) {
  860. if (Utils_1.utils.config.huaweiConfig
  861. && Utils_1.utils.config.huaweiConfig.insertId) {
  862. //@ts-ignore
  863. this._insertAd = qg.createInterstitialAd({
  864. adUnitId: Utils_1.utils.config.huaweiConfig.insertId
  865. });
  866. Utils_1.utils.showLog("小游戏插屏ID:", Utils_1.utils.config.huaweiConfig.insertId);
  867. if (this._insertAd) {
  868. Utils_1.utils.showLog("注册小游戏插屏广告回调!");
  869. this._insertAd.onError((function (err) {
  870. Utils_1.utils.showLog("华为 小游戏插屏广告出错:" + JSON.stringify(err));
  871. if (_this._canInsertShow) {
  872. if (_this.ServerConfig.intersititial_style_level) {
  873. if (_this.ServerConfig.intersititial_style_mod[_this.intersititialType - 1] == 2) {
  874. Utils_1.utils.showLog("开始展示原生插屏!");
  875. Utils_1.utils.delayCall(_this.nativeInserAdDelayCall.bind(_this), _this.ServerConfig.intersititia_delay_show_time || 0);
  876. }
  877. else if (_this.ServerConfig.intersititial_style_mod[_this.intersititialType - 1] == 1) {
  878. Utils_1.utils.showLog("开始展示原生icon!");
  879. _this.showNativeTryGameWidget();
  880. }
  881. }
  882. else if (_this.ServerConfig.intersititial_first_ad == "default") {
  883. _this._isInsertShow = false;
  884. Utils_1.utils.showLog("开始显示原生插屏广告!");
  885. _this._curPosIdIndexNativeInser = 0;
  886. Utils_1.utils.delayCall(_this.nativeInserAdDelayCall.bind(_this), _this.ServerConfig.intersititia_delay_show_time || 0);
  887. }
  888. else {
  889. Utils_1.utils.showLog("开始展示原生icon!");
  890. _this.showNativeTryGameWidget();
  891. }
  892. _this._canInsertShow = false;
  893. }
  894. _this._insertAd.destroy();
  895. _this._insertAd = null;
  896. }).bind(this));
  897. this._insertAd.onLoad((function () {
  898. Utils_1.utils.showLog("Huawei 小程序插屏广告加载成功! #_canInsertShow=" + _this._canInsertShow);
  899. _this._isInsertLoad = true;
  900. // utils.Tool_Huawei.countInserShowCount();
  901. if (_this._canInsertShow) {
  902. _this._insertLastShowTime = new Date().getTime();
  903. var closeType = _this.ServerConfig.intersititial_open_close_banner;
  904. if (closeType && closeType > 0) {
  905. Utils_1.utils.showLog("Huawei 配置当前插屏显示成功后" + (closeType == 1 ? "销毁" : "隐藏") + "banner!");
  906. _this.HideBanner();
  907. }
  908. _this._insertAd.show();
  909. }
  910. }).bind(this));
  911. this._insertAd.onClose((function () {
  912. Utils_1.utils.showLog("huawei 小程序插屏广告关闭");
  913. _this._isInsertLoad = false;
  914. _this._canInsertShow = false;
  915. _this.ShowBanner();
  916. // setTimeout(() => {
  917. // this._insertAd.load();
  918. // }, 3000);
  919. }).bind(this));
  920. }
  921. if (!this._insertAd) {
  922. Utils_1.utils.showLog("Huawei小游戏插屏广告创建失败!");
  923. if (this._canInsertShow) {
  924. if (this.ServerConfig.intersititial_style_level) {
  925. if (this.ServerConfig.intersititial_style_mod[this.intersititialType - 1] == 2) {
  926. Utils_1.utils.showLog("开始展示原生插屏!");
  927. Utils_1.utils.delayCall(this.nativeInserAdDelayCall.bind(this), this.ServerConfig.intersititia_delay_show_time || 0);
  928. }
  929. else if (this.ServerConfig.intersititial_style_mod[this.intersititialType - 1] == 1) {
  930. Utils_1.utils.showLog("开始展示原生icon!");
  931. this.showNativeTryGameWidget();
  932. }
  933. }
  934. else if (this.ServerConfig.intersititial_first_ad == "default") {
  935. this._isInsertShow = false;
  936. Utils_1.utils.showLog("开始显示原生插屏广告!");
  937. this._curPosIdIndexNativeInser = 0;
  938. Utils_1.utils.delayCall(this.nativeInserAdDelayCall.bind(this), this.ServerConfig.intersititia_delay_show_time || 0);
  939. }
  940. else {
  941. Utils_1.utils.showLog("开始展示原生icon!");
  942. this.showNativeTryGameWidget();
  943. }
  944. this._canInsertShow = false;
  945. }
  946. }
  947. }
  948. else {
  949. Utils_1.utils.showLog("Huawei 小游戏插屏广告配置信息错误!");
  950. }
  951. }
  952. };
  953. AdAgentHuaWei.prototype._createMiniGameInsertAd = function () {
  954. if (PlatUtils_1.default.IsHuaWei) {
  955. Utils_1.utils.showLog("[展示小游戏插屏广告]");
  956. if (this.ServerConfig) {
  957. this._canInsertShow = true;
  958. if (!this._insertAd) {
  959. this._initInsertAd();
  960. }
  961. if (this._insertAd) {
  962. this._insertAd.load();
  963. return;
  964. }
  965. }
  966. }
  967. };
  968. AdAgentHuaWei.prototype._createMiniGameBannerAd = function (location) {
  969. var _this = this;
  970. if (location === void 0) { location = null; }
  971. this._isBannerShow = true;
  972. if (!Utils_1.utils.config.huaweiConfig.bannerId) {
  973. Utils_1.utils.showLog("BannerID 未正确配置!");
  974. return;
  975. }
  976. if (!this._bannerAd) {
  977. //@ts-ignore
  978. var top = Utils_1.utils.Tool_Huawei.SysInfo.safeArea.height - 57;
  979. Utils_1.utils.showLog("banner =====#top=" + Utils_1.utils.Tool_Huawei.SysInfo.safeArea.height + " #top=" + top);
  980. this._bannerAd = this.huawei.createBannerAd({
  981. adUnitId: Utils_1.utils.config.huaweiConfig.bannerId,
  982. style: {
  983. top: top,
  984. left: 0,
  985. height: 57,
  986. width: 360
  987. }
  988. });
  989. Utils_1.utils.showLog("注册小游戏banner回调!" + this._bannerAd + " id=" + Utils_1.utils.config.huaweiConfig.bannerId);
  990. if (this._bannerAd) {
  991. this._bannerAd.onError(function (err) {
  992. Utils_1.utils.showLog("huawei小游戏Banner,显示异常:" + JSON.stringify(err));
  993. if (_this.ServerConfig.banner_style_level) {
  994. if (_this.ServerConfig.banner_style_mod[_this.bannerType - 1] == 2) {
  995. Utils_1.utils.showLog("开始展示默认banner");
  996. _this._createNativeBannerAd(_this._showNativeBanner);
  997. }
  998. }
  999. });
  1000. this._bannerAd.onLoad(function () {
  1001. Utils_1.utils.showLog("huawei小游戏Banner,加载成功");
  1002. if (_this._nativeBannerNode) {
  1003. _this._nativeBannerNode.active = false;
  1004. }
  1005. });
  1006. // this._bannerAd.onShow((() => {
  1007. // utils.showLog("huawei 小游戏Banner显示成功!");
  1008. // }).bind(this));
  1009. // this._bannerAd.onHide(function () {
  1010. // utils.showLog("huawei 小游戏Banner 广告隐藏");
  1011. // })
  1012. }
  1013. }
  1014. if (this._bannerAd) {
  1015. this._bannerAd.show();
  1016. }
  1017. else {
  1018. Utils_1.utils.showLog("huawei 小游戏Banner广告创建失败!");
  1019. if (this.ServerConfig.banner_style_level) {
  1020. if (this.ServerConfig.banner_style_mod[this.bannerType - 1] == 2) {
  1021. Utils_1.utils.showLog("开始展示默认banner");
  1022. this._createNativeBannerAd(this._showNativeBanner);
  1023. }
  1024. }
  1025. }
  1026. };
  1027. AdAgentHuaWei.prototype._createNativeBannerAd = function (completeCallback) {
  1028. var _this = this;
  1029. if (PlatUtils_1.default.IsHuaWei) {
  1030. var callback_1 = completeCallback;
  1031. Utils_1.utils.showLog("curPosIdIndexNativeBanner:" + this._curPosIdIndexNativeBanner + " #id=" + Utils_1.utils.config.huaweiConfig.nativeBannerIds[this._curPosIdIndexNativeBanner]);
  1032. var nativeBannerAd_1 = this._nativeBannerAd[this._curPosIdIndexNativeBanner];
  1033. if (!nativeBannerAd_1) {
  1034. if (Utils_1.utils.config.huaweiConfig.nativeBannerIds
  1035. && Utils_1.utils.config.huaweiConfig.nativeBannerIds[this._curPosIdIndexNativeBanner]) {
  1036. Utils_1.utils.showLog("创建原生广告Banner。 posId:" + Utils_1.utils.config.huaweiConfig.nativeBannerIds[this._curPosIdIndexNativeBanner]);
  1037. //@ts-ignore
  1038. // nativeBannerAd = qg.createNativeAd({
  1039. // posId: utils.config.huaweiConfig.nativeBannerIds[this._curPosIdIndexNativeBanner]
  1040. // });
  1041. nativeBannerAd_1 = this.huawei.createNativeAd({
  1042. adUnitId: Utils_1.utils.config.huaweiConfig.nativeBannerIds[this._curPosIdIndexNativeBanner],
  1043. success: function (code) {
  1044. console.log("loadNativeAd loadNativeAd : success");
  1045. },
  1046. fail: function (data, code) {
  1047. console.log("loadNativeAd loadNativeAd fail: " + data + "," + code);
  1048. },
  1049. complete: function () {
  1050. console.log("loadNativeAd loadNativeAd : complete");
  1051. }
  1052. });
  1053. if (nativeBannerAd_1) {
  1054. this._nativeBannerAd.push(nativeBannerAd_1);
  1055. nativeBannerAd_1.onLoad(function (res) {
  1056. if (_this._nativeIsClose) {
  1057. Utils_1.utils.showLog("隐藏了BANNER,不做任何处理!");
  1058. return;
  1059. }
  1060. if (res && res.adList && res.adList.length > 0) {
  1061. _this._startBannerTimerTask = new Date().getTime();
  1062. Utils_1.utils.showLog("原生Banner广告资源拉取成功!");
  1063. Utils_1.utils.showLog(JSON.stringify(res));
  1064. res = JSON.parse(JSON.stringify(res));
  1065. var data = res.adList[0];
  1066. //如果当前显示为结算banner,则不做数据验证
  1067. if (_this._checkNativeDataValid(data) || _this.getNativeBannerInfo().show_st_banner == "true") {
  1068. Utils_1.utils.showLog("当前原生Banner数据:" + data);
  1069. if (_this.canShowNativeBanner) {
  1070. _this._curPosIdIndexNativeBanner = 0;
  1071. _this._showNativeBanner(nativeBannerAd_1, data);
  1072. _this._curNativeBannerInfo.nativeBannerAd = nativeBannerAd_1;
  1073. _this._curNativeBannerInfo.data = data;
  1074. }
  1075. else {
  1076. cc.warn("已经隐藏banner不可重复展示");
  1077. }
  1078. return;
  1079. }
  1080. }
  1081. Utils_1.utils.showLog("原生Banner广告资源出错!");
  1082. _this._curPosIdIndexNativeBanner++;
  1083. if (_this._curPosIdIndexNativeBanner < Utils_1.utils.config.huaweiConfig.nativeBannerIds.length) {
  1084. _this._createNativeBannerAd(callback_1);
  1085. }
  1086. else {
  1087. _this._curPosIdIndexNativeBanner = 0;
  1088. // 原生广告遍历完毕
  1089. Utils_1.utils.showLog("原生广告条遍历完毕,无法展示!");
  1090. var bannerInfo = _this.getNativeBannerInfo();
  1091. if (bannerInfo.st_banner_show_back_up == -1) {
  1092. Utils_1.utils.showLog(">>>>>服务器配置不显示备用广告!");
  1093. return;
  1094. }
  1095. if (_this.ServerConfig.banner_first_ad.indexOf("native") > -1) {
  1096. Utils_1.utils.showLog("开始展示小游戏广告条!");
  1097. _this._createMiniGameBannerAd();
  1098. }
  1099. else {
  1100. //显示自定义banner
  1101. if (Utils_1.utils.isShowRecommondGamesBanner()) {
  1102. clearTimeout(_this._showBannerTimerId);
  1103. Utils_1.utils.showRecommendGamesBanner();
  1104. Utils_1.utils.showLog("\u5C0F\u6E38\u620F\u3001\u539F\u751F\u5E7F\u544A\u6761\u90FD\u65E0\u6CD5\u5C55\u793A\uFF0C\u5C55\u793A\u81EA\u5B9A\u4E49banner");
  1105. return;
  1106. }
  1107. }
  1108. }
  1109. });
  1110. nativeBannerAd_1.onError(function (err) {
  1111. if (_this._nativeIsClose) {
  1112. Utils_1.utils.showLog("隐藏了BANNER,不做任何处理!");
  1113. return;
  1114. }
  1115. Utils_1.utils.showLog("原生Banner广告资源拉取失败!" + JSON.stringify(err));
  1116. _this._curPosIdIndexNativeBanner++;
  1117. if (_this._curPosIdIndexNativeBanner < Utils_1.utils.config.huaweiConfig.nativeBannerIds.length) {
  1118. _this._createNativeBannerAd(callback_1);
  1119. }
  1120. else {
  1121. _this._curPosIdIndexNativeBanner = 0;
  1122. // 原生广告遍历完毕
  1123. Utils_1.utils.showLog("原生广告条遍历完毕,无法展示!");
  1124. var bannerInfo = _this.getNativeBannerInfo();
  1125. if (bannerInfo.st_banner_show_back_up == -1) {
  1126. Utils_1.utils.showLog(">>>>>服务器配置不显示备用广告!");
  1127. return;
  1128. }
  1129. if (_this.ServerConfig.banner_style_level) {
  1130. if (_this.ServerConfig.banner_style_mod[_this.bannerType - 1] == 1) {
  1131. Utils_1.utils.showLog("开始展示默认banner");
  1132. _this._createMiniGameBannerAd();
  1133. }
  1134. }
  1135. else if (_this.ServerConfig.banner_first_ad.indexOf("native") > -1) {
  1136. Utils_1.utils.showLog("开始展示小游戏广告条!");
  1137. _this._createMiniGameBannerAd();
  1138. }
  1139. else {
  1140. //显示自定义banner
  1141. if (Utils_1.utils.isShowRecommondGamesBanner()) {
  1142. clearTimeout(_this._showBannerTimerId);
  1143. Utils_1.utils.showRecommendGamesBanner();
  1144. Utils_1.utils.showLog("\u5C0F\u6E38\u620F\u3001\u539F\u751F\u5E7F\u544A\u6761\u90FD\u65E0\u6CD5\u5C55\u793A\uFF0C\u5C55\u793A\u81EA\u5B9A\u4E49banner");
  1145. return;
  1146. }
  1147. }
  1148. }
  1149. });
  1150. }
  1151. }
  1152. }
  1153. if (nativeBannerAd_1) {
  1154. Utils_1.utils.showLog("nativeBannerAd reLoad>>");
  1155. nativeBannerAd_1.load();
  1156. }
  1157. else {
  1158. this._curPosIdIndexNativeBanner++;
  1159. if (Utils_1.utils.config.huaweiConfig.nativeBannerIds && this._curPosIdIndexNativeBanner < Utils_1.utils.config.huaweiConfig.nativeBannerIds.length) {
  1160. this._createNativeBannerAd(callback_1);
  1161. }
  1162. else {
  1163. this._curPosIdIndexNativeBanner = 0;
  1164. // 原生广告遍历完毕
  1165. Utils_1.utils.showLog("原生广告条遍历完毕,无法展示!");
  1166. var bannerInfo = this.getNativeBannerInfo();
  1167. if (bannerInfo.st_banner_show_back_up == -1) {
  1168. Utils_1.utils.showLog(">>>>>服务器配置不显示备用广告!");
  1169. return;
  1170. }
  1171. if (this.ServerConfig.banner_style_level) {
  1172. if (this.ServerConfig.banner_style_mod[this.bannerType - 1] == 1) {
  1173. Utils_1.utils.showLog("开始展示默认banner");
  1174. this._createMiniGameBannerAd();
  1175. }
  1176. }
  1177. else if (this.ServerConfig.banner_first_ad.indexOf("native") > -1) {
  1178. Utils_1.utils.showLog("开始展示小游戏广告条!");
  1179. this._createMiniGameBannerAd();
  1180. }
  1181. else {
  1182. //显示自定义banner
  1183. if (Utils_1.utils.isShowRecommondGamesBanner()) {
  1184. clearTimeout(this._showBannerTimerId);
  1185. Utils_1.utils.showRecommendGamesBanner();
  1186. Utils_1.utils.showLog("\u5C0F\u6E38\u620F\u3001\u539F\u751F\u5E7F\u544A\u6761\u90FD\u65E0\u6CD5\u5C55\u793A\uFF0C\u5C55\u793A\u81EA\u5B9A\u4E49banner");
  1187. return;
  1188. }
  1189. }
  1190. }
  1191. }
  1192. }
  1193. };
  1194. AdAgentHuaWei.prototype._createNativeInsertAd = function (completeCallback) {
  1195. var _this = this;
  1196. if (PlatUtils_1.default.IsHuaWei) {
  1197. var callback_2 = completeCallback;
  1198. Utils_1.utils.showLog("curPosIdIndexNativeInsert:" + this._curPosIdIndexNativeInser);
  1199. var nativeInsertAd_1 = this._nativeInsertAd[this._curPosIdIndexNativeInser];
  1200. if (!nativeInsertAd_1) {
  1201. if (Utils_1.utils.config.huaweiConfig.nativeInsertIds
  1202. && Utils_1.utils.config.huaweiConfig.nativeInsertIds[this._curPosIdIndexNativeInser]) {
  1203. Utils_1.utils.showLog("创建原生插屏广告。 posId:" + Utils_1.utils.config.huaweiConfig.nativeInsertIds[this._curPosIdIndexNativeInser]);
  1204. //@ts-ignore
  1205. nativeInsertAd_1 = qg.createNativeAd({
  1206. adUnitId: Utils_1.utils.config.huaweiConfig.nativeInsertIds[this._curPosIdIndexNativeInser]
  1207. });
  1208. if (nativeInsertAd_1) {
  1209. this._nativeInsertAd.push(nativeInsertAd_1);
  1210. nativeInsertAd_1.onLoad(function (res) {
  1211. if (res && res.adList && res.adList.length > 0) {
  1212. Utils_1.utils.showLog("原生插屏广告资源拉取成功!");
  1213. Utils_1.utils.showLog(JSON.stringify(res));
  1214. res = JSON.parse(JSON.stringify(res));
  1215. var data = res.adList[0];
  1216. if (_this._checkNativeInsertDataValid(data)) {
  1217. _this._curPosIdIndexNativeInser = 0;
  1218. _this._showNativeInsert(nativeInsertAd_1, data);
  1219. return;
  1220. }
  1221. else {
  1222. Utils_1.utils.showLog("原生插屏广告资源不合法!");
  1223. }
  1224. }
  1225. Utils_1.utils.showLog("原生插屏广告资源出错!");
  1226. _this._curPosIdIndexNativeInser++;
  1227. if (_this._curPosIdIndexNativeInser < Utils_1.utils.config.huaweiConfig.nativeInsertIds.length) {
  1228. _this._createNativeInsertAd(callback_2);
  1229. }
  1230. else {
  1231. _this._curPosIdIndexNativeInser = 0;
  1232. // 原生广告遍历完毕
  1233. Utils_1.utils.showLog("原生插屏广告遍历完毕,无法展示!");
  1234. if (_this.ServerConfig.intersititial_first_ad == "native") {
  1235. Utils_1.utils.showLog("开始展示小游戏插屏广告!");
  1236. _this._createMiniGameInsertAd();
  1237. }
  1238. }
  1239. });
  1240. nativeInsertAd_1.onError(function (err) {
  1241. Utils_1.utils.showLog("原生插屏广告资源拉取失败!" + err.code + err.msg);
  1242. _this._curPosIdIndexNativeInser++;
  1243. if (_this._curPosIdIndexNativeInser < Utils_1.utils.config.huaweiConfig.nativeInsertIds.length) {
  1244. _this._createNativeInsertAd(callback_2);
  1245. }
  1246. else {
  1247. _this._curPosIdIndexNativeInser = 0;
  1248. // 原生广告遍历完毕
  1249. Utils_1.utils.showLog("原生插屏广告遍历完毕,无法展示!");
  1250. if (_this.ServerConfig.intersititial_style_level) {
  1251. if (_this.ServerConfig.intersititial_style_mod[_this.intersititialType - 1] != 2) {
  1252. Utils_1.utils.showLog("开始展示默认插屏!");
  1253. _this._createMiniGameInsertAd();
  1254. }
  1255. else {
  1256. _this.showNativeTryGameWidget();
  1257. }
  1258. }
  1259. else if (_this.ServerConfig.intersititial_first_ad == "native") {
  1260. Utils_1.utils.showLog("开始展示小游戏插屏广告!");
  1261. _this._createMiniGameInsertAd();
  1262. }
  1263. else {
  1264. _this.showNativeTryGameWidget();
  1265. }
  1266. }
  1267. });
  1268. }
  1269. }
  1270. }
  1271. if (nativeInsertAd_1) {
  1272. nativeInsertAd_1.load();
  1273. }
  1274. else {
  1275. this._curPosIdIndexNativeInser++;
  1276. if (Utils_1.utils.config.huaweiConfig.nativeInsertIds && this._curPosIdIndexNativeInser < Utils_1.utils.config.huaweiConfig.nativeInsertIds.length) {
  1277. this._createNativeInsertAd(callback_2);
  1278. }
  1279. else {
  1280. this._curPosIdIndexNativeInser = 0;
  1281. // 原生广告遍历完毕
  1282. Utils_1.utils.showLog("原生插屏广告遍历完毕,无法展示!");
  1283. if (this.ServerConfig.intersititial_first_ad == "native") {
  1284. Utils_1.utils.showLog("开始展示小游戏插屏广告!");
  1285. this._createMiniGameInsertAd();
  1286. }
  1287. }
  1288. }
  1289. }
  1290. };
  1291. /**
  1292. * 获取原生广告数据
  1293. * @param args
  1294. */
  1295. AdAgentHuaWei.prototype.getNativeAdData = function () {
  1296. if (!this._nativeAdObject) {
  1297. this._nativeAdObject = new YZ_NativeAdObject_1.default();
  1298. }
  1299. this._nativeAdObject._nativeObj = this._nativeAd;
  1300. this._nativeAdObject.data = this._nativeData;
  1301. // utils.showLog("获取原生数据 >>>", this._nativeData)
  1302. // setTimeout(() => {
  1303. // utils.showLog("延迟两秒重新请求原生广告数据");
  1304. // this._createNativeAd(args);
  1305. // }, 2000);
  1306. if (this._nativeData && this._nativeAd) {
  1307. this._nativeData = null;
  1308. return this._nativeAdObject;
  1309. }
  1310. return null;
  1311. };
  1312. // /**
  1313. // * 创建单个原生广告
  1314. // * @param completeCallback
  1315. // */
  1316. // createNativeAd(nativeItem?: YZ_NativeItem) {
  1317. // utils.showLog("_createNativeAd >>>>>");
  1318. // if (PlatUtils.IsHuaWei) {
  1319. // if (nativeItem) {
  1320. // this._curNativeItem = nativeItem;
  1321. // }
  1322. // utils.showLog("_curPosIdIndexSingleNative:" + this._curPosIdIndexSingleNative + " #this._nativeSingleAd.length" + this._nativeSingleAd.length);
  1323. // let nativeSingleAd = this._nativeSingleAd[this._curPosIdIndexSingleNative];
  1324. // if (!nativeSingleAd) {
  1325. // if (utils.config.huaweiConfig.nativeSingleAdIds
  1326. // && utils.config.huaweiConfig.nativeSingleAdIds[this._curPosIdIndexSingleNative]) {
  1327. // utils.showLog("创建原生广告。 posId:" + utils.config.huaweiConfig.nativeSingleAdIds[this._curPosIdIndexSingleNative]);
  1328. // //@ts-ignore
  1329. // nativeSingleAd = qg.createNativeAd({
  1330. // posId: utils.config.huaweiConfig.nativeSingleAdIds[this._curPosIdIndexSingleNative]
  1331. // });
  1332. // if (nativeSingleAd) {
  1333. // this._nativeSingleAd.push(nativeSingleAd);
  1334. // nativeSingleAd.onLoad((res) => {
  1335. // if (res && res.adList && res.adList.length > 0) {
  1336. // utils.showLog("原生广告资源拉取成功!");
  1337. // utils.showLog(JSON.stringify(res));
  1338. // res = JSON.parse(JSON.stringify(res));
  1339. // let data = res.adList[0];
  1340. // if (this._checkNativeDataValid(data)) {
  1341. // this._curPosIdIndexSingleNative = 0;
  1342. // this._nativeData = data;
  1343. // this._nativeAd = nativeSingleAd;
  1344. // // utils.showLog("callback >>>", callback);
  1345. // // callback(this.getNativeAdData());
  1346. // this._showNativeAd();
  1347. // return;
  1348. // } else {
  1349. // utils.showLog("原生广告资源不合法!");
  1350. // }
  1351. // }
  1352. // utils.showLog("原生广告资源出错!");
  1353. // this._curPosIdIndexSingleNative++;
  1354. // if (this._curPosIdIndexSingleNative < utils.config.huaweiConfig.nativeSingleAdIds.length) {
  1355. // this.createNativeAd();
  1356. // } else {
  1357. // this._curPosIdIndexSingleNative = 0;
  1358. // // 原生广告遍历完毕
  1359. // utils.showLog("单个原生广告ID遍历完毕,无法展示!");
  1360. // }
  1361. // });
  1362. // nativeSingleAd.onError((err) => {
  1363. // utils.showLog("原生单个广告资源拉取失败!" + err.code + err.msg);
  1364. // this._curPosIdIndexSingleNative++;
  1365. // if (this._curPosIdIndexSingleNative < utils.config.huaweiConfig.nativeSingleAdIds.length) {
  1366. // this.createNativeAd();
  1367. // } else {
  1368. // this._curPosIdIndexSingleNative = 0;
  1369. // // 原生广告遍历完毕
  1370. // utils.showLog("单个原生广告ID遍历完毕,无法展示!");
  1371. // }
  1372. // });
  1373. // }
  1374. // }
  1375. // }
  1376. // if (nativeSingleAd) {
  1377. // utils.showLog("nativeSingleAd reload");
  1378. // nativeSingleAd.load();
  1379. // } else {
  1380. // this._curPosIdIndexSingleNative++;
  1381. // if (utils.config.huaweiConfig.nativeSingleAdIds && this._curPosIdIndexSingleNative < utils.config.huaweiConfig.nativeSingleAdIds.length) {
  1382. // this.createNativeAd();
  1383. // } else {
  1384. // this._curPosIdIndexSingleNative = 0;
  1385. // // 原生广告遍历完毕
  1386. // utils.showLog("单个原生广告ID 遍历完毕,无法展示!");
  1387. // }
  1388. // }
  1389. // }
  1390. // }
  1391. /**
  1392. * 显示原生banner组件
  1393. */
  1394. AdAgentHuaWei.prototype._showNativeBanner = function (nativeBannerAd, data) {
  1395. if (PlatUtils_1.default.IsHuaWei) {
  1396. if (data) {
  1397. Utils_1.utils.showLog("显示原生banner");
  1398. if (this._bannerAd) {
  1399. this._bannerAd.hide();
  1400. }
  1401. if (!cc.isValid(this._nativeBannerNode) || (!this._nativeBannerNode && Utils_1.utils.config.otherconfig.nativeBanner)) {
  1402. this._nativeBannerNode = cc.instantiate(Utils_1.utils.config.otherconfig.nativeBanner);
  1403. this._nativeBannerNode.position = CompatibleTool_1.default.position(cc.winSize.width / 2, this._nativeBannerNode.height * this._nativeBannerNode.scaleY / 2);
  1404. cc.director.getScene().addChild(this._nativeBannerNode, 1000);
  1405. }
  1406. if (this._nativeBannerNode) {
  1407. this._nativeBannerNode.active = true;
  1408. var nativeBanner = this._nativeBannerNode.getComponent("YZ_NativeBanner");
  1409. if (nativeBanner) {
  1410. nativeBanner.init(nativeBannerAd, data, this.getNativeBannerInfo());
  1411. }
  1412. else {
  1413. Utils_1.utils.showLog("NativeBanner组件不存在!");
  1414. }
  1415. this._showBannerCallBack && this._showBannerCallBack();
  1416. this._showBannerCallBack = null;
  1417. }
  1418. else {
  1419. Utils_1.utils.showLog("原生广告banner位没有创建!");
  1420. }
  1421. }
  1422. }
  1423. };
  1424. /**
  1425. * 显示原生插屏组件
  1426. */
  1427. AdAgentHuaWei.prototype._showNativeInsert = function (nativeInsertAd, data) {
  1428. if (PlatUtils_1.default.IsHuaWei) {
  1429. if (data) {
  1430. if ((!cc.isValid(this._nativeInsertNode)) || !this._nativeInsertNode && Utils_1.utils.config.otherconfig.nativeInsert) {
  1431. Utils_1.utils.showLog("创建原生插屏广告位");
  1432. this._nativeInsertNode = cc.instantiate(Utils_1.utils.config.otherconfig.nativeInsert);
  1433. this._nativeInsertNode.position = CompatibleTool_1.default.position(cc.winSize.width / 2, cc.winSize.height / 2);
  1434. cc.director.getScene().addChild(this._nativeInsertNode, 999999);
  1435. }
  1436. if (this._nativeInsertNode) {
  1437. var nativeInsert = this._nativeInsertNode.getComponent("YZ_NativeInsert");
  1438. if (nativeInsert) {
  1439. this._nativeInsertAdShowCount = 0;
  1440. nativeInsert.init(nativeInsertAd, data);
  1441. this._insertLastShowTime = new Date().getTime();
  1442. // utils.HuaweiTool.countInserShowCount();
  1443. // utils.showLog("原生插屏显示成功,当前显示次数=" + utils.HuaweiTool.insertAdShowCounts);
  1444. var closeType = this.ServerConfig.intersititial_open_close_banner;
  1445. if (closeType && closeType > 0) {
  1446. Utils_1.utils.showLog("Huawei 配置当前插屏显示成功后" + (closeType == 1 ? "销毁" : "隐藏") + "banner!");
  1447. this.HideBanner();
  1448. }
  1449. }
  1450. else {
  1451. Utils_1.utils.showLog("NativeInsert组件不存在!");
  1452. }
  1453. }
  1454. else {
  1455. Utils_1.utils.showLog("原生广告插屏位没有创建!");
  1456. }
  1457. }
  1458. }
  1459. };
  1460. AdAgentHuaWei.prototype.ShowCloseBtnBanner = function (location, args) {
  1461. var _this = this;
  1462. if (location === void 0) { location = YZ_Constant_1.BannerLocation.Home; }
  1463. Utils_1.utils.showLog("ShowCloseBtnBanner >>>>>>>>>.");
  1464. var isMoveBtn = 0;
  1465. var fadeInTime = 0;
  1466. var btn = args.closeBtn;
  1467. var winHeight = cc.winSize.height;
  1468. btn.opacity = 0;
  1469. if (this.ServerConfig) {
  1470. if (this.ServerConfig.is_move_btn) {
  1471. isMoveBtn = this.ServerConfig.is_move_btn;
  1472. }
  1473. if (this.ServerConfig.close_btn_fade_in_time) {
  1474. fadeInTime = this.ServerConfig.close_btn_fade_in_time;
  1475. }
  1476. Utils_1.utils.showLog(isMoveBtn == 0 ? "显示banner,且按钮在上面" : "\u663E\u793ABanner,\u6309\u94AE\u5C45\u5E95\u90E8\u4E14" + isMoveBtn + "\u6BEB\u79D2\u540E\u79FB\u52A8");
  1477. setTimeout(function () {
  1478. Utils_1.utils.showLog("延迟调用关闭按钮的Banner >>>>");
  1479. _this.ShowBanner(location, args);
  1480. var adY = 240;
  1481. Utils_1.utils.showLog('utils - adY:' + adY);
  1482. if (adY > 0 && btn) {
  1483. btn.y = -(winHeight / 2 - adY) + btn.height;
  1484. Utils_1.utils.showLog("btnClose.y" + btn.y);
  1485. }
  1486. }, isMoveBtn);
  1487. setTimeout(function () {
  1488. btn.runAction(cc.fadeIn(0.3));
  1489. }, fadeInTime * 1000);
  1490. }
  1491. };
  1492. AdAgentHuaWei.prototype._checkNativeInsertDataValid = function (data) {
  1493. if (!data) {
  1494. return false;
  1495. }
  1496. return data.title && ((data.iconUrlList && data.iconUrlList.length > 0) || (data.imgUrlList && data.imgUrlList.length > 0));
  1497. };
  1498. AdAgentHuaWei.prototype._checkNativeDataValid = function (data) {
  1499. Utils_1.utils.showLog("checkNativeDataValid");
  1500. if (!data) {
  1501. return false;
  1502. }
  1503. if (data.imgUrlList && data.imgUrlList.length > 0) {
  1504. return true;
  1505. }
  1506. if (data.title && data.desc && data.clickBtnTxt && ((data.iconUrlList && data.iconUrlList.length > 0))) {
  1507. return true;
  1508. }
  1509. return false;
  1510. };
  1511. /**
  1512. * 验证是否显示激励插屏
  1513. */
  1514. AdAgentHuaWei.prototype.checkRewardInsertIsShow = function () {
  1515. // let jumpList = utils.getRecommondGameList();
  1516. // if (utils.isSupportnavigateToMiniGame()) {
  1517. // if (utils.HuaweiTool
  1518. // && utils.HuaweiTool.ServerConfig
  1519. // && utils.HuaweiTool.ServerConfig.is_reward_intersititia) {
  1520. // if (utils.HuaweiTool.ServerConfig.is_reward_intersititia == "true"
  1521. // && jumpList && jumpList.length > 0) {
  1522. // utils.showLog("激励插屏显示环境验证通过!");
  1523. // return true;
  1524. // } else {
  1525. // utils.showLog("is_reward_intersititia 参数为false,激励插屏组件不显示!");
  1526. // return false;
  1527. // }
  1528. // } else {
  1529. // utils.showLog("配置中没有is_reward_intersititia参数,激励插屏组件组件不显示!");
  1530. // return false;
  1531. // }
  1532. // }
  1533. // utils.showLog("当前平台不支持小程序跳转!");
  1534. // return false;
  1535. };
  1536. /**
  1537. * 显示激励插屏组件
  1538. */
  1539. AdAgentHuaWei.prototype.showRewardInsert = function () {
  1540. Utils_1.utils.showLog("show reward");
  1541. // let self = this;
  1542. // if (!this.checkRewardInsertIsShow()) {
  1543. // self._videoCallback && self._videoCallback(false, "暂无视频广告!");
  1544. // utils.adManager.videoCallBack = null;
  1545. // return;
  1546. // }
  1547. // if (((!cc.isValid(this._rewardInsertNode)) || !this._rewardInsertNode) && utils.config.otherconfig.rewardInsert) {
  1548. // utils.showLog("创建激励插屏广告");
  1549. // this._rewardInsertNode = cc.instantiate(utils.config.otherconfig.rewardInsert);
  1550. // this._rewardInsertNode.position = CompatibleTool.position(cc.winSize.width / 2, cc.winSize.height / 2);
  1551. // cc.director.getScene().addChild(this._rewardInsertNode, 9999);
  1552. // }
  1553. // if (this._rewardInsertNode) {
  1554. // let rewardInsert: RewardInsert = this._rewardInsertNode.getComponent("RewardInsert");
  1555. // if (rewardInsert) {
  1556. // rewardInsert.isShow = false;
  1557. // utils.showLog("显示激励插屏组件!");
  1558. // } else {
  1559. // utils.showLog("RewardInsert组件不存在!");
  1560. // }
  1561. // } else {
  1562. // utils.showLog("激励插屏没有创建!");
  1563. // }
  1564. };
  1565. AdAgentHuaWei.prototype.hideRewardInsert = function () {
  1566. if (this._rewardInsertNode) {
  1567. var rewardInsert = this._rewardInsertNode.getComponent("RewardInsert");
  1568. if (rewardInsert) {
  1569. rewardInsert.hide();
  1570. Utils_1.utils.showLog("隐藏激励插屏组件!");
  1571. }
  1572. else {
  1573. Utils_1.utils.showLog("RewardInsert组件不存在!");
  1574. }
  1575. }
  1576. else {
  1577. Utils_1.utils.showLog("激励插屏没有创建!");
  1578. }
  1579. };
  1580. // public ShowStatementRecomment(): cc.Node {
  1581. // if (PlatUtils.IsHuaWei) {
  1582. // utils.showLog("curPosIdIndexNativeInsert:", this._curPosIdIndexNativeInser);
  1583. // let nativeInsertAd = this._nativeInsertAd[this._curPosIdIndexNativeInser];
  1584. // if (!nativeInsertAd) {
  1585. // if (utils.config.huaweiConfig.nativeInsertIds
  1586. // && utils.config.huaweiConfig.nativeInsertIds[this._curPosIdIndexNativeInser]) {
  1587. // utils.showLog("创建原生结算页面广告。 posId:", utils.config.huaweiConfig.nativeInsertIds[this._curPosIdIndexNativeInser]);
  1588. // nativeInsertAd = qg.createNativeAd({
  1589. // posId: utils.config.huaweiConfig.nativeInsertIds[this._curPosIdIndexNativeInser]
  1590. // });
  1591. // if (nativeInsertAd) {
  1592. // this._nativeInsertAd.push(nativeInsertAd);
  1593. // nativeInsertAd.onLoad((res) => {
  1594. // if (res && res.adList && res.adList.length > 0) {
  1595. // utils.showLog("原生原生结算页面资源拉取成功!");
  1596. // utils.showLog(JSON.stringify(res));
  1597. // res = JSON.parse(JSON.stringify(res));
  1598. // let data = res.adList[0];
  1599. // if (this._checkNativeDataValid(data)) {
  1600. // this._curPosIdIndexNativeInser = 0;
  1601. // // this._showNativeInsert(nativeInsertAd, data);
  1602. // // return this.cre;
  1603. // } else {
  1604. // utils.showLog("原生结算页面资源不合法!");
  1605. // }
  1606. // }
  1607. // utils.showLog("原生结算页面资源出错!");
  1608. // this._curPosIdIndexNativeInser++;
  1609. // if (this._curPosIdIndexNativeInser < utils.config.huaweiConfig.nativeInsertIds.length) {
  1610. // this.ShowStatementRecomment();
  1611. // } else {
  1612. // this._curPosIdIndexNativeInser = 0;
  1613. // // 原生广告遍历完毕
  1614. // utils.showLog("原生结算页面遍历完毕,无法展示!");
  1615. // }
  1616. // });
  1617. // nativeInsertAd.onError((err) => {
  1618. // utils.showLog("原生结算页面资源拉取失败!", err.code, err.msg);
  1619. // this._curPosIdIndexNativeInser++;
  1620. // if (this._curPosIdIndexNativeInser < utils.config.huaweiConfig.nativeInsertIds.length) {
  1621. // this.ShowStatementRecomment();
  1622. // } else {
  1623. // this._curPosIdIndexNativeInser = 0;
  1624. // // 原生广告遍历完毕
  1625. // utils.showLog("原生结算页面遍历完毕,无法展示!");
  1626. // }
  1627. // });
  1628. // }
  1629. // }
  1630. // }
  1631. // if (nativeInsertAd) {
  1632. // nativeInsertAd.load();
  1633. // } else {
  1634. // this._curPosIdIndexNativeInser++;
  1635. // if (utils.config.huaweiConfig.nativeInsertIds && this._curPosIdIndexNativeInser < utils.config.huaweiConfig.nativeInsertIds.length) {
  1636. // this.ShowStatementRecomment();
  1637. // } else {
  1638. // this._curPosIdIndexNativeInser = 0;
  1639. // // 原生广告遍历完毕
  1640. // utils.showLog("原生插屏广告遍历完毕,无法展示!");
  1641. // }
  1642. // }
  1643. // }
  1644. // return null;
  1645. // }
  1646. AdAgentHuaWei.prototype.checkIsShowStatementAd = function () {
  1647. if (Utils_1.utils.isSupportnavigateToMiniGame() && this.ServerConfig) {
  1648. return true;
  1649. }
  1650. Utils_1.utils.showLog("当前平台不支持游戏内跳转,6元素交叉推广组件不显示!");
  1651. return false;
  1652. };
  1653. /**
  1654. * 创建结算页面推广组件
  1655. */
  1656. AdAgentHuaWei.prototype.ShowStatementRecomment = function (showNativeAd) {
  1657. if (showNativeAd === void 0) { showNativeAd = true; }
  1658. if (this.checkIsShowStatementAd()) {
  1659. if (!showNativeAd) {
  1660. if (Utils_1.utils.config.otherconfig.crossWidget6) {
  1661. var node = cc.instantiate(Utils_1.utils.config.otherconfig.crossWidget6);
  1662. Utils_1.utils.showLog("只显示结算互推广告");
  1663. return node;
  1664. }
  1665. else {
  1666. Utils_1.utils.showLog("未找到预制体 crossWidget6, 请查看CommonUtils组件上是否赋值!");
  1667. return null;
  1668. }
  1669. }
  1670. else {
  1671. if (Utils_1.utils.config.otherconfig.statementRecomment) {
  1672. var node = cc.instantiate(Utils_1.utils.config.otherconfig.statementRecomment);
  1673. var statementRecomment = node.getComponent("YZ_StatementRecommentAd");
  1674. statementRecomment.showNativeAd = showNativeAd;
  1675. Utils_1.utils.showLog("显示结算互推和原生广告");
  1676. return node;
  1677. }
  1678. else {
  1679. Utils_1.utils.showLog("未找到预制体 StatementRecomment, 请查看CommonUtils组件上是否赋值!");
  1680. return null;
  1681. }
  1682. }
  1683. }
  1684. else {
  1685. return null;
  1686. }
  1687. };
  1688. AdAgentHuaWei.prototype._showNativeAd = function () {
  1689. if (this._curNativeItem) {
  1690. this._curNativeItem.init(this.getNativeAdData());
  1691. }
  1692. // let nativeItem: YZ_NativeItem = node.getComponent("YZ_NativeItem");
  1693. // utils.showLog("ShowSingleNativeAd <<<<<<<<<", nativeItem, "===", res)
  1694. // if (nativeItem)
  1695. };
  1696. /**
  1697. * 创建结算页面推广组件
  1698. */
  1699. AdAgentHuaWei.prototype.ShowSingleNativeAd = function () {
  1700. if (Utils_1.utils.config.otherconfig.singleNativeAd) {
  1701. // if (this.getNativeAdData()) {
  1702. var node = cc.instantiate(Utils_1.utils.config.otherconfig.singleNativeAd);
  1703. var nativeItem = node.getComponent("YZ_NativeItem");
  1704. nativeItem.showType = 2;
  1705. this._curNativeItem = nativeItem;
  1706. this.createNativeAd();
  1707. // this.createNativeAd((res) => {
  1708. // utils.showLog("ShowSingleNativeAd <<<<<<<<<", nativeItem, "===", res)
  1709. // if (nativeItem) nativeItem.init(res, 2);
  1710. // })
  1711. // if (this._nativeAdObject._nativeAdData) {
  1712. // statementRecomment.nativeData = this._nativeAdObject._nativeAdData;
  1713. // } else {
  1714. // utils.showLog("结算推广组件 >> 原生广告数据不存在!");
  1715. // return null;
  1716. // }
  1717. Utils_1.utils.showLog("单个原生广告创建成功!");
  1718. // this._createNativeAd();
  1719. return node;
  1720. // } else {
  1721. // utils.showLog("单个原生广告创建失败,原生广告数据不存在");
  1722. // return null;
  1723. // }
  1724. }
  1725. else {
  1726. Utils_1.utils.showLog("未找到预制体 singleNativeAd, 请查看CommonUtils组件上是否赋值!");
  1727. return null;
  1728. }
  1729. };
  1730. /**
  1731. * 显示结算广告
  1732. * @param data 参数: closeBtn:
  1733. */
  1734. AdAgentHuaWei.prototype.showStatementAds = function (data) {
  1735. // let result: any = { "type": 0, "node": null };
  1736. // if (this.ServerConfig && this.ServerConfig.statement_type) {
  1737. // let type = this.ServerConfig.statement_type;
  1738. // let spareType = this.ServerConfig.st_spare_type;
  1739. // let isSycn = this.ServerConfig.st_sync;
  1740. // let node: cc.Node = null;
  1741. // let resType: number = 0;
  1742. // switch (type) {
  1743. // case 1:
  1744. // utils.showLog("结算广告 >> 只显示小游戏插屏广告");
  1745. // if (!this.checkInsertAdShow()) {
  1746. // if (spareType && spareType > 0) {
  1747. // switch (spareType) {
  1748. // case 3:
  1749. // utils.showLog("结算广告 >> 小游戏插屏达到限制的次数 >> 显示备用组件 6个互推");
  1750. // node = this.ShowStatementRecomment(false);
  1751. // resType = 1;
  1752. // break;
  1753. // case 4:
  1754. // utils.showLog("结算广告 >> 小游戏插屏达到限制的次数 >> 显示备用组件 单个原生广告");
  1755. // node = this.ShowSingleNativeAd();
  1756. // resType = 2;
  1757. // break;
  1758. // case 5:
  1759. // utils.showLog("结算广告 >> 小游戏插屏达到限制的次数 >> 显示备用组件 3个互推+单个原生广告");
  1760. // node = this.ShowStatementRecomment();
  1761. // resType = 1;
  1762. // break;
  1763. // }
  1764. // }
  1765. // } else {
  1766. // this._createMiniGameInsertAd(true);
  1767. // }
  1768. // break;
  1769. // case 2:
  1770. // utils.showLog("结算广告 >> 显示插屏广告且判断优先级");
  1771. // if (!this.checkInsertAdShow()) {
  1772. // if (spareType) {
  1773. // switch (spareType) {
  1774. // case 3:
  1775. // utils.showLog("结算广告 >> 小游戏插屏达到限制的次数 >> 显示备用组件 6个互推");
  1776. // node = this.ShowStatementRecomment(false);
  1777. // resType = 1;
  1778. // break;
  1779. // case 4:
  1780. // utils.showLog("结算广告 >> 小游戏插屏达到限制的次数 >> 显示备用组件 单个原生广告");
  1781. // node = this.ShowSingleNativeAd();
  1782. // resType = 2;
  1783. // break;
  1784. // case 5:
  1785. // utils.showLog("结算广告 >> 小游戏插屏达到限制的次数 >> 显示备用组件 3个互推+单个原生广告");
  1786. // node = this.ShowStatementRecomment();
  1787. // resType = 1;
  1788. // break;
  1789. // }
  1790. // }
  1791. // } else {
  1792. // this.ShowInterstitial();
  1793. // }
  1794. // break;
  1795. // case 3:
  1796. // utils.showLog("结算广告 >> 显示插屏广告+6个互推");
  1797. // this.ShowInterstitial();
  1798. // node = this.ShowStatementRecomment(false);
  1799. // resType = 1;
  1800. // break;
  1801. // case 4:
  1802. // if (isSycn && isSycn == "true") {
  1803. // utils.showLog("结算广告 >> 显示插屏广告+单个原生广告");
  1804. // this.ShowInterstitial();
  1805. // node = this.ShowSingleNativeAd();
  1806. // } else {
  1807. // node = this.ShowSingleNativeAd();
  1808. // utils.showLog("结算广告 >> 只显示单个原生广告");
  1809. // }
  1810. // resType = 2;
  1811. // break;
  1812. // case 5:
  1813. // if (isSycn && isSycn == "true") {
  1814. // utils.showLog("结算广告 >> 显示插屏广告+ 3个互推+单个原生广告");
  1815. // this.ShowInterstitial();
  1816. // node = this.ShowStatementRecomment();
  1817. // } else {
  1818. // utils.showLog("结算广告 >> 只显示 3个互推+单个原生广告");
  1819. // node = this.ShowStatementRecomment();
  1820. // }
  1821. // resType = 1;
  1822. // break;
  1823. // case 6:
  1824. // if (isSycn && isSycn == "true") {
  1825. // utils.showLog("结算广告 >> 显示滚动互推+原生广告");
  1826. // node = this.ShowStatementRecomment(true);
  1827. // } else {
  1828. // utils.showLog("结算广告 >> 只显示滚动互推");
  1829. // node = this.ShowStatementRecomment();
  1830. // }
  1831. // resType = 1;
  1832. // break;
  1833. // default:
  1834. // utils.showLog("非法的结算广告类型,:" + type)
  1835. // break;
  1836. // }
  1837. // result.type = resType;
  1838. // result.node = node;
  1839. // return result;
  1840. // } else {
  1841. // utils.showLog("配置未初始化、或者没有配置结算广告!");
  1842. // return result;
  1843. // }
  1844. };
  1845. AdAgentHuaWei.prototype.showFullScreenVideo = function () {
  1846. };
  1847. AdAgentHuaWei.prototype.GameExit = function () { };
  1848. AdAgentHuaWei.prototype.Share = function () { };
  1849. AdAgentHuaWei = __decorate([
  1850. ccclass
  1851. ], AdAgentHuaWei);
  1852. return AdAgentHuaWei;
  1853. }(AdAgent_1.default));
  1854. exports.default = AdAgentHuaWei;
  1855. cc._RF.pop();