4db215b4-356f-402d-a40b-e848cecb06b0.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. "use strict";
  2. cc._RF.push(module, '4db21W0NW9ALaQL6EjOywaw', 'AdAgentBaidu');
  3. // common-plugin/Scripts/AdAgentBaidu.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 AdAgentBaidu = /** @class */ (function (_super) {
  31. __extends(AdAgentBaidu, _super);
  32. function AdAgentBaidu() {
  33. var _this = _super !== null && _super.apply(this, arguments) || this;
  34. _this._sysData = null;
  35. _this._baiduVersion = "";
  36. _this._recorder = null;
  37. _this._bannerAd = null;
  38. _this._videoAd = null;
  39. _this._videoCallback = null;
  40. _this._isVideoShow = false;
  41. _this._isVideoLoaded = false;
  42. //@ts-ignore
  43. _this.swan = window.swan;
  44. _this._bannerSizePercent = 0.1;
  45. _this._bannerBottom = 0;
  46. return _this;
  47. }
  48. AdAgentBaidu.prototype.Init = function () {
  49. var _this = this;
  50. if (PlatUtils_1.default.IsBaidu) {
  51. this._sysData = this.swan.getSystemInfoSync();
  52. Utils_1.utils.registerServerInitEvent(function () {
  53. _this._initVideoAd();
  54. }, this);
  55. }
  56. };
  57. AdAgentBaidu.prototype.ShowBanner = function (location, args) {
  58. var _this = this;
  59. if (location === void 0) { location = YZ_Constant_1.BannerLocation.Home; }
  60. if (args === void 0) { args = null; }
  61. if (PlatUtils_1.default.IsBaidu) {
  62. if (Utils_1.utils.isShowRecommondGamesBanner() && Utils_1.utils.isSupportnavigateToMiniGame()) {
  63. Utils_1.utils.showRecommendGamesBanner();
  64. Utils_1.utils.showLog("\u670D\u52A1\u5668\u914D\u7F6E\u5C55\u793A\u81EA\u5B9A\u4E49banner");
  65. return;
  66. }
  67. Utils_1.utils.showLog("显示banner广告...");
  68. var argsTmp = args;
  69. if (argsTmp && argsTmp.width) {
  70. if (cc.winSize.height / cc.winSize.width < 1) {
  71. this._bannerSizePercent = argsTmp.width;
  72. }
  73. else {
  74. this._bannerSizePercent = ((argsTmp.width <= 0.8) ? 0.8 : argsTmp.width);
  75. }
  76. this._bannerSizePercent = ((argsTmp.width > 1) ? 1 : this._bannerSizePercent);
  77. }
  78. if (argsTmp && argsTmp.bottom) {
  79. this._bannerBottom = argsTmp.bottom / this._sysData.pixelRatio;
  80. this._bannerBottom = ((this._bannerBottom < 0) ? 0 : this._bannerBottom);
  81. this._bannerBottom = ((this._bannerBottom > this._sysData.screenHeight) ? this._sysData.screenHeight : this._bannerBottom);
  82. }
  83. // banner 广告
  84. if (Utils_1.utils.config.baiduconfig
  85. && Utils_1.utils.config.baiduconfig.bannerId
  86. && Utils_1.utils.config.baiduconfig.appSID) {
  87. var left = (this._sysData.screenWidth - this._sysData.screenWidth * this._bannerSizePercent) / 2;
  88. var width_1 = this._sysData.screenWidth * this._bannerSizePercent;
  89. var bannerOpts = {
  90. adUnitId: Utils_1.utils.config.baiduconfig.bannerId,
  91. appSid: Utils_1.utils.config.baiduconfig.appSID,
  92. style: {
  93. top: 0,
  94. left: left,
  95. width: width_1
  96. }
  97. };
  98. var bannerAd_1 = null;
  99. var oldBannerAd_1 = this._bannerAd;
  100. var onLoadFunc_1 = function () {
  101. if (bannerAd_1) {
  102. bannerAd_1.show().then(function () {
  103. _this._bannerAd = bannerAd_1;
  104. if (oldBannerAd_1) {
  105. oldBannerAd_1.destroy();
  106. oldBannerAd_1.offLoad(onLoadFunc_1);
  107. oldBannerAd_1.offError(onErrorFunc_1);
  108. }
  109. Utils_1.utils.showLog("Banner显示成功!");
  110. }).catch(function () {
  111. Utils_1.utils.showLog("Banner显示出错!");
  112. });
  113. }
  114. };
  115. var onErrorFunc_1 = function (err) {
  116. if (err) {
  117. Utils_1.utils.showLog("Banner 广告出错 : ", err.errCode, err.errMsg);
  118. }
  119. };
  120. var onResizeFunc = function (res) {
  121. bannerAd_1.style.width = width_1;
  122. bannerAd_1.style.top = _this._sysData.screenHeight - res.height - _this._bannerBottom;
  123. };
  124. bannerAd_1 = this.swan.createBannerAd(bannerOpts);
  125. if (bannerAd_1) {
  126. bannerAd_1.onLoad(onLoadFunc_1);
  127. bannerAd_1.onError(onErrorFunc_1);
  128. bannerAd_1.onResize(onResizeFunc);
  129. bannerAd_1.style.width = width_1 + 1;
  130. if (PlatUtils_1.default.IsIOS) {
  131. bannerAd_1.style.top = this._sysData.screenHeight;
  132. }
  133. }
  134. }
  135. else {
  136. cc.warn("百度广告配置文件出错!");
  137. }
  138. }
  139. };
  140. /**
  141. * 显示结算广告
  142. * @param data 参数: closeBtn:
  143. * statement_type
  144. * 1:只显示小游戏插屏广告
  145. * 2:只显示6个互推广告
  146. * 3:显示插屏广告+6个互推
  147. */
  148. AdAgentBaidu.prototype.showStatementAds = function () {
  149. var result = { "type": 0, "node": null };
  150. var node = null;
  151. var resType = 0;
  152. Utils_1.utils.showLog("结算广告 >> 显示插屏广告+6个互推");
  153. this.ShowInterstitial();
  154. node = Utils_1.utils.showCrossWidget6();
  155. resType = 1;
  156. result.type = resType;
  157. result.node = node;
  158. return result;
  159. };
  160. AdAgentBaidu.prototype.HideBanner = function (location) {
  161. if (location === void 0) { location = YZ_Constant_1.BannerLocation.Home; }
  162. if (PlatUtils_1.default.IsBaidu) {
  163. if (this._bannerAd) {
  164. this._bannerAd.hide();
  165. }
  166. }
  167. };
  168. AdAgentBaidu.prototype.ShowInterstitial = function (location) {
  169. if (location === void 0) { location = YZ_Constant_1.BannerLocation.Home; }
  170. console.warn("百度没有插屏");
  171. };
  172. AdAgentBaidu.prototype.ShowVideo = function (callback) {
  173. var _this = this;
  174. if (PlatUtils_1.default.IsBaidu) {
  175. // 视频广告
  176. if (this._videoCallback) {
  177. return;
  178. }
  179. else {
  180. this._videoCallback = callback;
  181. }
  182. this._isVideoShow = true;
  183. if (!this._videoAd) {
  184. this._initVideoAd();
  185. }
  186. else {
  187. if (this._isVideoLoaded) {
  188. this._videoAd.show().then(function () {
  189. Utils_1.utils.showLog("视频显示成功!");
  190. _this._isVideoLoaded = false;
  191. }).catch(function (err) {
  192. });
  193. }
  194. else {
  195. this._videoAd.load().catch(function (err) {
  196. });
  197. }
  198. }
  199. }
  200. };
  201. AdAgentBaidu.prototype._initVideoAd = function () {
  202. var _this = this;
  203. if (!this._videoAd) {
  204. if (!(Utils_1.utils.config.baiduconfig
  205. && Utils_1.utils.config.baiduconfig.appSID
  206. && Utils_1.utils.config.baiduconfig.videoId)) {
  207. Utils_1.utils.showLog("视频ID配置不正确!");
  208. if (this._videoCallback) {
  209. this._videoCallback(false, "暂无视频广告!");
  210. this._videoCallback = null;
  211. }
  212. return;
  213. }
  214. var videoOpts = {
  215. adUnitId: Utils_1.utils.config.baiduconfig.videoId,
  216. appSid: Utils_1.utils.config.baiduconfig.appSID
  217. };
  218. Utils_1.utils.showLog("视频广告参数:", JSON.stringify(videoOpts));
  219. this._videoAd = this.swan.createRewardedVideoAd(videoOpts);
  220. if (this._videoAd) {
  221. this._videoAd.onLoad(function () {
  222. Utils_1.utils.showLog("视频加载成功");
  223. _this._isVideoLoaded = true;
  224. if (_this._isVideoShow) {
  225. _this._videoAd.show().then(function () {
  226. _this._isVideoLoaded = false;
  227. }).catch(function () {
  228. Utils_1.utils.showLog("视频播放失败!");
  229. });
  230. }
  231. });
  232. this._videoAd.onClose(function (res) {
  233. _this._isVideoShow = false;
  234. if (res && res.isEnded) {
  235. Utils_1.utils.showLog("正常播放结束,可以下发游戏奖励");
  236. if (_this._videoCallback) {
  237. _this._videoCallback(true, "");
  238. _this._videoCallback = null;
  239. }
  240. }
  241. else {
  242. Utils_1.utils.showLog("播放中途退出,不下发游戏奖励");
  243. if (_this._videoCallback) {
  244. _this._videoCallback(false, "观看完视频才能获得奖励!");
  245. _this._videoCallback = null;
  246. }
  247. }
  248. });
  249. this._videoAd.onError(function (err) {
  250. Utils_1.utils.showLog("激励视频异常!", err.errCode);
  251. _this._isVideoLoaded = false;
  252. if (_this._videoCallback) {
  253. _this._videoCallback(false, "暂无视频广告!");
  254. _this._videoCallback = null;
  255. }
  256. });
  257. }
  258. }
  259. };
  260. AdAgentBaidu = __decorate([
  261. ccclass
  262. ], AdAgentBaidu);
  263. return AdAgentBaidu;
  264. }(AdAgent_1.default));
  265. exports.default = AdAgentBaidu;
  266. cc._RF.pop();