a545e96c-bb9e-4ca6-b121-e19383d7dfda.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. "use strict";
  2. cc._RF.push(module, 'a545elsu55MprEh4ZOD19/a', 'AdAgentFaceBook');
  3. // common-plugin/Scripts/AdAgentFaceBook.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 FBAdManager_1 = require("./FaceBookSdk/FBAdManager");
  30. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  31. var AdAgentFaceBook = /** @class */ (function (_super) {
  32. __extends(AdAgentFaceBook, _super);
  33. function AdAgentFaceBook() {
  34. var _this = _super !== null && _super.apply(this, arguments) || this;
  35. _this._sysData = null;
  36. _this._curBannerAd = null;
  37. _this._videoAd = null;
  38. _this._insertAd = null;
  39. _this._oldAd = null;
  40. _this._appBox = null; //游戏盒子广告
  41. _this._videoCallback = null;
  42. _this._isVideoLoaded = false;
  43. _this._isVideoShow = false;
  44. //@ts-ignore
  45. _this.qq = window.qq;
  46. _this._bannerShow = false;
  47. _this._bannerSizePercent = 0.5;
  48. _this._bannerBottom = 0;
  49. _this._oldBannerLocation = YZ_Constant_1.BannerLocation.None;
  50. _this._curBannerHeight = 240;
  51. _this._moveBtn = null;
  52. _this._cur_level = null;
  53. _this._showBannerTimerId = 0;
  54. _this._isShow = false;
  55. return _this;
  56. }
  57. AdAgentFaceBook.prototype.Init = function () {
  58. var _this = this;
  59. if (PlatUtils_1.default.IsFaceBook) {
  60. Utils_1.utils.registerServerInitEvent(function () {
  61. _this._initAd();
  62. }, this);
  63. }
  64. };
  65. Object.defineProperty(AdAgentFaceBook.prototype, "ServerConfig", {
  66. get: function () {
  67. return Utils_1.utils.Tool_Facebook.ServerConfig;
  68. },
  69. enumerable: false,
  70. configurable: true
  71. });
  72. AdAgentFaceBook.prototype._initAd = function () {
  73. Utils_1.utils.showLog("facebook init ad>>>>>>>>");
  74. FBAdManager_1.default.addInterstitial(Utils_1.utils.config.faceBookConfig.insertId, 3);
  75. FBAdManager_1.default.addRewardedVideo(Utils_1.utils.config.faceBookConfig.videoId, 3);
  76. FBAdManager_1.default.addBanner(Utils_1.utils.config.faceBookConfig.bannerId);
  77. setTimeout(function () {
  78. FBAdManager_1.default.loadAll();
  79. }, 3000);
  80. };
  81. AdAgentFaceBook.prototype._createBanner = function (location, args) {
  82. if (args === void 0) { args = null; }
  83. if (PlatUtils_1.default.IsFaceBook) {
  84. FBAdManager_1.default.showBannerAsync().then(function () {
  85. Utils_1.utils.showLog("显示Banner广告: 成功");
  86. }).catch(function (e) {
  87. Utils_1.utils.showLog("显示Banner广告: 失败,原因: " + e.message);
  88. });
  89. }
  90. };
  91. AdAgentFaceBook.prototype._showBannerTimer = function (location, args) {
  92. var locationTmp = location;
  93. var argsTmp = args;
  94. Utils_1.utils.showLog("\u663E\u793ABanner\u5E7F\u544Axxx\uFF01location:" + locationTmp + "; \u95F4\u9694\u65F6\u95F4:" + Utils_1.utils.Tool_Facebook.ServerConfig.refresh_ad_time + ":\u4F18\u5148\u7EA7\uFF1A" + this.ServerConfig.banner_first_ad);
  95. this._createBanner(locationTmp, argsTmp);
  96. };
  97. AdAgentFaceBook.prototype.ShowBanner = function (location, args) {
  98. if (location === void 0) { location = YZ_Constant_1.BannerLocation.Home; }
  99. if (args === void 0) { args = null; }
  100. if (PlatUtils_1.default.IsFaceBook) {
  101. if (Utils_1.utils.ServerConfig) {
  102. var locationTmp = location;
  103. var argsTmp = args;
  104. this._moveBtn = args ? args.moveBtn : null;
  105. this._cur_level = args ? args.cur_level : null;
  106. this._showBannerTimer(locationTmp, argsTmp);
  107. }
  108. else {
  109. Utils_1.utils.showLog("服务器配置数据未初始化!");
  110. }
  111. }
  112. };
  113. AdAgentFaceBook.prototype.HideBanner = function (location) {
  114. if (location === void 0) { location = YZ_Constant_1.BannerLocation.Home; }
  115. if (PlatUtils_1.default.IsFaceBook) {
  116. Utils_1.utils.showLog("隐藏广告条");
  117. this._bannerShow = false;
  118. clearInterval(this._showBannerTimerId);
  119. FBAdManager_1.default.hideBannerAsync().then(function () {
  120. Utils_1.utils.showLog("隐藏Banner广告: 成功");
  121. }).catch(function (e) {
  122. Utils_1.utils.showLog("隐藏Banner广告: 失败,原因: " + e.message);
  123. });
  124. }
  125. };
  126. AdAgentFaceBook.prototype.ShowVideo = function (callback) {
  127. var _this = this;
  128. if (PlatUtils_1.default.IsFaceBook) {
  129. this._videoCallback = callback;
  130. if (FBAdManager_1.default.isRewardedVideoReady()) {
  131. FBAdManager_1.default.showRewardedVideo().then(function () {
  132. Utils_1.utils.showLog("播放激励视频广告: 成功");
  133. if (_this._videoCallback) {
  134. _this._videoCallback(true, "");
  135. _this._videoCallback = null;
  136. }
  137. }).catch(function (e) {
  138. Utils_1.utils.showLog("视频播放失败:" + e.message);
  139. if (_this._videoCallback) {
  140. _this._videoCallback(false, "Ad playback failed!");
  141. _this._videoCallback = null;
  142. }
  143. });
  144. }
  145. else {
  146. Utils_1.utils.showLog("激励视频广告未加载!");
  147. if (this._videoCallback) {
  148. this._videoCallback(false, "Video ad not loaded successfully!");
  149. this._videoCallback = null;
  150. }
  151. }
  152. }
  153. };
  154. /**
  155. * 显示插屏
  156. * 2001 触发频率限制 小程序启动一定时间内不允许展示插屏广告
  157. * 2002 触发频率限制 距离小程序插屏广告或者激励视频广告上次播放时间间隔不足,不允许展示插屏广告
  158. * 2003 触发频率限制 当前正在播放激励视频广告或者插屏广告,不允许再次展示插屏广告
  159. * 2004 广告渲染失败 该项错误不是开发者的异常情况,或因小程序页面切换导致广告渲染失败
  160. * 2005 广告调用异常 插屏广告实例不允许跨页面调用
  161. * 销毁插屏广告后才能重新创建
  162. * @param location
  163. */
  164. AdAgentFaceBook.prototype.ShowInterstitial = function (location) {
  165. if (location === void 0) { location = null; }
  166. if (PlatUtils_1.default.IsFaceBook) {
  167. if (this.ServerConfig) {
  168. Utils_1.utils.delayCall(this._createInsterstitial.bind(this), this.ServerConfig.intersititia_delay_show_time || 0);
  169. }
  170. else {
  171. this._createInsterstitial.bind(this);
  172. }
  173. }
  174. };
  175. AdAgentFaceBook.prototype._createInsterstitial = function () {
  176. if (FBAdManager_1.default.isInterstitialAdReady()) {
  177. FBAdManager_1.default.showInterstitialAd().then(function () {
  178. Utils_1.utils.showLog("播放插屏广告: 成功");
  179. }).catch(function (e) {
  180. Utils_1.utils.showLog("播放插屏广告: 失败,原因: " + e.message);
  181. });
  182. }
  183. else {
  184. Utils_1.utils.showLog("插屏广告没有加载成功!");
  185. }
  186. };
  187. AdAgentFaceBook = __decorate([
  188. ccclass
  189. ], AdAgentFaceBook);
  190. return AdAgentFaceBook;
  191. }(AdAgent_1.default));
  192. exports.default = AdAgentFaceBook;
  193. cc._RF.pop();