a74c2bb4-c3dc-41b8-b2ae-5dc84afc0b2c.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. "use strict";
  2. cc._RF.push(module, 'a74c2u0w9xBuLKuXchK/Ass', 'AdAgentWiFi');
  3. // common-plugin/Scripts/AdAgentWiFi.ts
  4. "use strict";
  5. var __extends = (this && this.__extends) || (function () {
  6. var extendStatics = function (d, b) {
  7. extendStatics = Object.setPrototypeOf ||
  8. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10. return extendStatics(d, b);
  11. };
  12. return function (d, b) {
  13. extendStatics(d, b);
  14. function __() { this.constructor = d; }
  15. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16. };
  17. })();
  18. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  19. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  20. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  21. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  22. return c > 3 && r && Object.defineProperty(target, key, r), r;
  23. };
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. var AdAgent_1 = require("./AdAgent");
  26. var YZ_Constant_1 = require("./YZ_Constant");
  27. var PlatUtils_1 = require("./PlatUtils");
  28. var Utils_1 = require("./Utils");
  29. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  30. var AdAgentWiFi = /** @class */ (function (_super) {
  31. __extends(AdAgentWiFi, _super);
  32. function AdAgentWiFi() {
  33. var _this = _super !== null && _super.apply(this, arguments) || this;
  34. _this._sysData = null;
  35. _this._curBannerAd = null;
  36. _this._videoAd = null;
  37. _this._insertAd = null;
  38. _this._oldAd = null;
  39. _this._appBox = null; //游戏盒子广告
  40. _this._videoCallback = null;
  41. _this._isVideoLoaded = false;
  42. _this._isVideoShow = false;
  43. //@ts-ignore
  44. _this.wuji = window.wuji;
  45. _this._bannerShow = true;
  46. _this._showBannerTimerId = 0;
  47. return _this;
  48. }
  49. AdAgentWiFi.prototype.Init = function () {
  50. var _this = this;
  51. if (PlatUtils_1.default.IsWiFi) {
  52. Utils_1.utils.registerServerInitEvent(function () {
  53. _this._sysData = Utils_1.utils.wifiTool.getSystemInfo();
  54. }, this);
  55. }
  56. };
  57. Object.defineProperty(AdAgentWiFi.prototype, "ServerConfig", {
  58. get: function () {
  59. return Utils_1.utils.wifiTool.ServerConfig;
  60. },
  61. enumerable: false,
  62. configurable: true
  63. });
  64. AdAgentWiFi.prototype._initVideoAd = function () {
  65. var _this = this;
  66. if (!this._videoAd) {
  67. Utils_1.utils.showLog("初始化视频!");
  68. var example = {
  69. adUnitId: '',
  70. };
  71. this._videoAd = this.wuji.createRewardedVideoAd(example);
  72. this._videoAd.onLoad(function () {
  73. Utils_1.utils.showLog('激励视频加载完成');
  74. _this._videoAd
  75. .show()
  76. .then(function () { return Utils_1.utils.showLog('激励视频展示成功'); })
  77. .catch(function (err) {
  78. Utils_1.utils.showLog('激励视频展示失败', err);
  79. // 可以手动加载一次
  80. _this._videoAd
  81. .load()
  82. .then(function () {
  83. Utils_1.utils.showLog("手动加载成功");
  84. // 加载成功后需要再显示广告
  85. return _this._videoAd.show();
  86. });
  87. });
  88. });
  89. this._videoAd.onError(function (err) {
  90. Utils_1.utils.showLog('激励视频错误', err);
  91. if (_this._videoCallback) {
  92. _this._videoCallback(false, "暂无视频广告!");
  93. _this._videoCallback = null;
  94. }
  95. });
  96. this._videoAd.onClose(function (res) {
  97. _this._isVideoShow = false;
  98. if (res.isEnded) {
  99. // 正常播放结束,可以下发游戏奖励
  100. Utils_1.utils.showLog('激励视频广告完成,发放奖励');
  101. if (_this._videoCallback) {
  102. _this._videoCallback(true, "");
  103. _this._videoCallback = null;
  104. }
  105. }
  106. else {
  107. // 播放中途退出,不下发游戏奖励
  108. Utils_1.utils.showLog('激励视频广告取消关闭,不发放奖励');
  109. if (_this._videoCallback) {
  110. _this._videoCallback(false, "观看完视频才能获得奖励!");
  111. _this._videoCallback = null;
  112. }
  113. }
  114. });
  115. }
  116. };
  117. AdAgentWiFi.prototype._createBanner = function (location, args) {
  118. var _this = this;
  119. if (args === void 0) { args = null; }
  120. if (PlatUtils_1.default.IsWiFi) {
  121. var _a = this._sysData, windowWidth = _a.windowWidth, windowHeight = _a.windowHeight;
  122. var targetBannerAdWidth = windowWidth - 20;
  123. var example = {
  124. adUnitId: '',
  125. style: {
  126. top: windowHeight,
  127. left: (windowWidth - targetBannerAdWidth) / 2,
  128. width: targetBannerAdWidth,
  129. }
  130. };
  131. this._curBannerAd = this.wuji.createBannerAd(example);
  132. this._curBannerAd.onLoad(function () {
  133. _this._curBannerAd.show()
  134. .then(function () { return Utils_1.utils.showLog('banner ad 展示成功'); })
  135. .catch(function (err) { return Utils_1.utils.showLog(err); });
  136. });
  137. }
  138. };
  139. AdAgentWiFi.prototype._showBannerTimer = function (location, args) {
  140. var locationTmp = location;
  141. var argsTmp = args;
  142. this._createBanner(locationTmp, argsTmp);
  143. };
  144. AdAgentWiFi.prototype.ShowInterstitial = function () {
  145. Utils_1.utils.showLog("连尚小游戏没有插屏广告!");
  146. };
  147. AdAgentWiFi.prototype.ShowBanner = function (location, args) {
  148. var _this = this;
  149. if (location === void 0) { location = YZ_Constant_1.BannerLocation.Home; }
  150. if (args === void 0) { args = null; }
  151. if (PlatUtils_1.default.IsWiFi) {
  152. if (this.ServerConfig) {
  153. var locationTmp = location;
  154. var argsTmp = args;
  155. var interval = 30;
  156. if (this.ServerConfig.refresh_ad_time) {
  157. interval = this.ServerConfig.refresh_ad_time;
  158. }
  159. Utils_1.utils.showLog("\u663E\u793ABanner\u5E7F\u544A\uFF01location:" + locationTmp + "; args:" + JSON.stringify(argsTmp) + "; \u95F4\u9694\u65F6\u95F4:" + this.ServerConfig.refresh_ad_time);
  160. var _a = this._sysData, windowWidth = _a.windowWidth, windowHeight = _a.windowHeight;
  161. var targetBannerAdWidth = windowWidth - 20;
  162. var example = {
  163. adUnitId: '',
  164. adIntervals: interval,
  165. style: {
  166. top: windowHeight,
  167. left: (windowWidth - targetBannerAdWidth) / 2,
  168. width: targetBannerAdWidth,
  169. }
  170. };
  171. if (this._curBannerAd) {
  172. this._curBannerAd.offLoad();
  173. this._curBannerAd.destroy();
  174. }
  175. this._curBannerAd = this.wuji.createBannerAd(example);
  176. this._curBannerAd.onLoad(function () {
  177. _this._curBannerAd.show()
  178. .then(function () { return Utils_1.utils.showLog('banner ad 展示成功'); })
  179. .catch(function (err) { return Utils_1.utils.showLog(err); });
  180. });
  181. }
  182. else {
  183. Utils_1.utils.showLog("服务器配置数据未初始化!");
  184. }
  185. }
  186. };
  187. AdAgentWiFi.prototype.HideBanner = function (location) {
  188. if (location === void 0) { location = YZ_Constant_1.BannerLocation.Home; }
  189. if (PlatUtils_1.default.IsWiFi) {
  190. Utils_1.utils.showLog("隐藏广告条");
  191. this._bannerShow = false;
  192. clearInterval(this._showBannerTimerId);
  193. if (this._curBannerAd) {
  194. this._curBannerAd.hide();
  195. }
  196. }
  197. };
  198. AdAgentWiFi.prototype.ShowVideo = function (callback) {
  199. if (PlatUtils_1.default.IsWiFi) {
  200. this._videoCallback = callback;
  201. this._isVideoShow = true;
  202. if (!this._videoAd) {
  203. this._initVideoAd();
  204. }
  205. else {
  206. this._videoAd.load();
  207. }
  208. }
  209. };
  210. AdAgentWiFi = __decorate([
  211. ccclass
  212. ], AdAgentWiFi);
  213. return AdAgentWiFi;
  214. }(AdAgent_1.default));
  215. exports.default = AdAgentWiFi;
  216. cc._RF.pop();