85bc0b95-17a6-46da-b9d6-5c856f416c19.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. "use strict";
  2. cc._RF.push(module, '85bc0uVF6ZG2rnWXIVvQWwZ', 'AdAgentNative');
  3. // common-plugin/Scripts/AdAgentNative.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. exports.NativeCallBack = void 0;
  26. var AdAgent_1 = require("./AdAgent");
  27. var YZ_Constant_1 = require("./YZ_Constant");
  28. var PlatUtils_1 = require("./PlatUtils");
  29. var Utils_1 = require("./Utils");
  30. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  31. var ST_JNIMessage = "JNIMessage";
  32. var ST_VideoCallback = "VideoCallback";
  33. var AdAgentNative = /** @class */ (function (_super) {
  34. __extends(AdAgentNative, _super);
  35. function AdAgentNative() {
  36. var _this = _super !== null && _super.apply(this, arguments) || this;
  37. _this._videoCallback = null;
  38. _this._showBannerTimerId = 0;
  39. _this._showNativeIconTimerId = 0;
  40. return _this;
  41. }
  42. Object.defineProperty(AdAgentNative.prototype, "_className", {
  43. get: function () {
  44. return Utils_1.utils.Tool_Native.jniClassName;
  45. },
  46. enumerable: false,
  47. configurable: true
  48. });
  49. Object.defineProperty(AdAgentNative.prototype, "ServerConfig", {
  50. get: function () {
  51. return Utils_1.utils.Tool_Native.ServerConfig;
  52. },
  53. enumerable: false,
  54. configurable: true
  55. });
  56. AdAgentNative.prototype.Init = function () {
  57. var _this = this;
  58. if (PlatUtils_1.default.IsNativeAndroid) {
  59. cc.game.on(ST_JNIMessage, function (event) {
  60. if (event.type == ST_VideoCallback) {
  61. if (_this._videoCallback) {
  62. if (event.ret == true) {
  63. _this._videoCallback && _this._videoCallback(true);
  64. }
  65. else {
  66. _this._videoCallback && _this._videoCallback(false, event.msg);
  67. }
  68. _this._videoCallback = null;
  69. }
  70. }
  71. });
  72. }
  73. };
  74. AdAgentNative.prototype.ShowBanner = function (location, args, isTimeRefresh) {
  75. if (location === void 0) { location = YZ_Constant_1.BannerLocation.Home; }
  76. if (args === void 0) { args = null; }
  77. if (isTimeRefresh === void 0) { isTimeRefresh = false; }
  78. if (PlatUtils_1.default.IsNativeAndroid) {
  79. Utils_1.utils.showLog("AdAgentNative ShowBanner");
  80. var interval_1 = 60;
  81. if (this.ServerConfig && this.ServerConfig.refresh_ad_time) {
  82. interval_1 = this.ServerConfig.refresh_ad_time;
  83. }
  84. var jsonObj = {};
  85. jsonObj.location = location;
  86. jsonObj.isTimeRefresh = isTimeRefresh ? "true" : "false";
  87. try {
  88. Utils_1.utils.showLog("调用banner Json >>>" + JSON.stringify(jsonObj));
  89. jsb.reflection.callStaticMethod(this._className, "showBanner", "(Ljava/lang/String;)V", JSON.stringify(jsonObj));
  90. }
  91. catch (error) {
  92. Utils_1.utils.showLog(error);
  93. }
  94. clearInterval(this._showBannerTimerId);
  95. this._showBannerTimerId = setInterval(function () {
  96. Utils_1.utils.showLog("\u5B9A\u65F6\u5237\u65B0\u663E\u793ABanner\u5E7F\u544A\uFF01location:" + location + "; args:" + JSON.stringify(args) + "; \u95F4\u9694\u65F6\u95F4:" + interval_1);
  97. this.ShowBanner(location, args, true);
  98. }.bind(this), interval_1 * 1000);
  99. }
  100. };
  101. AdAgentNative.prototype.HideBanner = function (location) {
  102. if (location === void 0) { location = YZ_Constant_1.BannerLocation.Home; }
  103. Utils_1.utils.showLog("AdAgentNative HideBanner");
  104. clearInterval(this._showBannerTimerId);
  105. jsb.reflection.callStaticMethod(this._className, "hideBanner", "(Ljava/lang/String;)V", location);
  106. };
  107. AdAgentNative.prototype.ShowInterstitial = function () {
  108. var _this = this;
  109. if (PlatUtils_1.default.IsNativeAndroid) {
  110. try {
  111. var delayShowTime = 0.5;
  112. if (this.ServerConfig && this.ServerConfig.intersititia_delay_show_time) {
  113. delayShowTime = this.ServerConfig.intersititia_delay_show_time;
  114. }
  115. Utils_1.utils.showLog("AdAgentNative ShowInterstitial 延迟", delayShowTime, "秒调用!");
  116. Utils_1.utils.delayCall(function () {
  117. jsb.reflection.callStaticMethod(_this._className, "showInterstitial", "()V");
  118. }, delayShowTime);
  119. }
  120. catch (error) {
  121. Utils_1.utils.showLog(error);
  122. }
  123. }
  124. };
  125. /**
  126. * 显示浮窗广告挂件
  127. * @param params
  128. * ```
  129. * {
  130. * group:string
  131. * left:number
  132. * bottom:number
  133. * scale:number
  134. * parent:cc.Node
  135. * }
  136. * ```
  137. * @returns 生成的组件
  138. */
  139. AdAgentNative.prototype.showNativeTryGameWidget = function (params) {
  140. if (params === void 0) { params = null; }
  141. if (PlatUtils_1.default.IsNativeAndroid) {
  142. Utils_1.utils.showLog("AdAgentNative showNativeTryGameWidget=" + this.ServerConfig.show_native_icon_method);
  143. try {
  144. var interval_2 = 15;
  145. if (this.ServerConfig && this.ServerConfig.icon_jump_native) {
  146. var iv = parseInt(this.ServerConfig.icon_jump_native);
  147. if (iv > 3) {
  148. interval_2 = iv;
  149. }
  150. else {
  151. Utils_1.utils.showLog("悬浮ICON必须大于3秒,当前默认为15秒刷新");
  152. }
  153. }
  154. if (this.ServerConfig.show_native_icon_method) {
  155. var style = {};
  156. "left" in params && (style.left = params.left);
  157. "right" in params && (style.right = params.right);
  158. "top" in params && (style.top = params.top);
  159. "bottom" in params && (style.bottom = params.bottom);
  160. "location" in params && (style.location = params.location);
  161. style.winSizeWidth = cc.winSize.width;
  162. style.winSizeHeight = cc.winSize.height;
  163. // style.left = params.left != undefined ? params.left : -1;
  164. // style.right = params.right != undefined ? params.right : -1;
  165. // style.top = params.top != undefined ? params.top : -1;
  166. // style.bottom = params.bottom != undefined ? params.bottom : -1;
  167. // style.location = params.location != undefined ? params.location : -1;
  168. jsb.reflection.callStaticMethod(Utils_1.utils.Tool_Native.jniClassName, this.ServerConfig.show_native_icon_method, "(Ljava/lang/String;)V", JSON.stringify(style));
  169. }
  170. else {
  171. var x = 10;
  172. var y = 250;
  173. if (params) {
  174. if (params.top != null) {
  175. y = params.top;
  176. }
  177. else if (params.bottom != null) {
  178. y = cc.winSize.height - params.bottom;
  179. }
  180. if (params.left != null) {
  181. x = params.left;
  182. }
  183. else if (params.right != null) {
  184. x = cc.winSize.width - params.right;
  185. }
  186. }
  187. jsb.reflection.callStaticMethod(Utils_1.utils.Tool_Native.jniClassName, "showFloatIcon", "(II)V", x, y);
  188. }
  189. clearInterval(this._showNativeIconTimerId);
  190. this._showNativeIconTimerId = setInterval(function () {
  191. Utils_1.utils.showLog("\u5B9A\u65F6\u5237\u65B0\u663E\u793A\u539F\u751F\u60AC\u6D6EICON\u5E7F\u544A\uFF01 args:" + params + "; \u95F4\u9694\u65F6\u95F4:" + interval_2);
  192. this.showNativeTryGameWidget(params);
  193. }.bind(this), interval_2 * 1000);
  194. }
  195. catch (error) {
  196. Utils_1.utils.showLog(error);
  197. }
  198. }
  199. };
  200. AdAgentNative.prototype.ShowVideo = function (callback) {
  201. if (PlatUtils_1.default.IsNativeAndroid) {
  202. Utils_1.utils.showLog("AdAgentNative ShowVideo");
  203. this._videoCallback = callback;
  204. try {
  205. jsb.reflection.callStaticMethod(this._className, "showVideo", "()V");
  206. }
  207. catch (error) {
  208. Utils_1.utils.showLog(error);
  209. if (callback) {
  210. callback(false);
  211. }
  212. }
  213. }
  214. };
  215. AdAgentNative.prototype.showFullScreenVideo = function (callback) {
  216. if (PlatUtils_1.default.IsNativeAndroid) {
  217. Utils_1.utils.showLog("AdAgentNative showFullScreenVideo");
  218. this._videoCallback = callback;
  219. try {
  220. jsb.reflection.callStaticMethod(this._className, "showFullScreenVideo", "()V");
  221. }
  222. catch (error) {
  223. Utils_1.utils.showLog(error);
  224. if (callback) {
  225. callback(false);
  226. }
  227. }
  228. }
  229. };
  230. /**
  231. * 隐藏浮动试玩挂件
  232. */
  233. AdAgentNative.prototype.hideNativeTryGameWidget = function () {
  234. if (PlatUtils_1.default.IsNativeAndroid) {
  235. clearInterval(this._showNativeIconTimerId);
  236. jsb.reflection.callStaticMethod(this._className, "hideFloatIcon", "()V");
  237. return;
  238. }
  239. };
  240. AdAgentNative = __decorate([
  241. ccclass
  242. ], AdAgentNative);
  243. return AdAgentNative;
  244. }(AdAgent_1.default));
  245. exports.default = AdAgentNative;
  246. var NativeCallBack = /** @class */ (function () {
  247. function NativeCallBack() {
  248. }
  249. /**
  250. * 1:播放完成
  251. * 2:播放失败
  252. * 3:无广告
  253. *
  254. */
  255. NativeCallBack.videoCallBack = function (result, msg) {
  256. console.log("视频广告回调函数 ------>result=", result, " msg=", msg);
  257. if (result == 1) {
  258. //播放成功
  259. cc.game.emit(ST_JNIMessage, { type: ST_VideoCallback, ret: true });
  260. }
  261. else {
  262. //播放失败
  263. cc.game.emit(ST_JNIMessage, { type: ST_VideoCallback, ret: false, msg: msg ? msg : "暂无视频!" });
  264. }
  265. };
  266. NativeCallBack.sendEvent = function (eventMsg) {
  267. Utils_1.utils.showLog("事件上报:" + eventMsg);
  268. Utils_1.utils.SendEvent(eventMsg);
  269. };
  270. NativeCallBack.sendEventNew = function (eventName, eventId, eventData) {
  271. Utils_1.utils.showLog("事件上报:" + eventName);
  272. if (Utils_1.utils.Tool_Native) {
  273. Utils_1.utils.Tool_Native.sendEventNew(eventName, eventId, eventData);
  274. }
  275. };
  276. /**
  277. * 上报插屏点击时间
  278. */
  279. NativeCallBack.reportInsertClick = function () {
  280. Utils_1.utils.showLog("上报插屏点击时间:" + Utils_1.utils.overPageInsertAdIsTouch);
  281. if (Utils_1.utils.overPageInsertAdIsTouch)
  282. return;
  283. Utils_1.utils.overPageInsertAdIsTouch = true;
  284. var time = (new Date().getTime() - Utils_1.utils.overPageShowTime) / 1000;
  285. var json = {};
  286. json.data = time;
  287. Utils_1.utils.SendEventNew("\u7ED3\u7B97\u9875\u9762-\u63D2\u5C4F\u70B9\u51FB\u65F6\u95F4", "overPageInsertAdTouch", JSON.stringify(json));
  288. };
  289. /**
  290. *
  291. * @param idCard
  292. * @param realName
  293. */
  294. NativeCallBack.realNameAuth = function (idCard, realName) {
  295. Utils_1.utils.showLog("realNameAuth>>>> #idCard=" + idCard + " #realName=" + realName);
  296. Utils_1.utils.Tool_Native.realNameAuth(idCard, realName, function (res, result) {
  297. Utils_1.utils.showLog("realNameAuth>>>> #res=" + res + " #result=" + result);
  298. if (res) {
  299. if (result) {
  300. var res_1 = JSON.parse(result);
  301. switch (res_1.code) {
  302. case 1:
  303. Utils_1.utils.showMsg(res_1.msg);
  304. Utils_1.utils.Tool_Native.realNameAuthResult(result);
  305. break;
  306. case 0:
  307. if (res_1.nonage == "0") {
  308. Utils_1.utils.setRealNameAuthLocalData("2");
  309. }
  310. else {
  311. Utils_1.utils.setRealNameAuthLocalData("1");
  312. }
  313. Utils_1.utils._isRealNameAuth = true;
  314. if (res_1.msg) {
  315. Utils_1.utils.showMsg(res_1.msg);
  316. }
  317. Utils_1.utils.Tool_Native.realNameAuthResult(result);
  318. Utils_1.utils.scheduleOnce(function () {
  319. Utils_1.utils.emitRealNameAuthCloseEvent();
  320. }, 0.5);
  321. break;
  322. case 2:
  323. //未成年限制内,显示下线
  324. Utils_1.utils.setRealNameAuthLocalData("2");
  325. Utils_1.utils.Tool_Native.realNameAuthResult(result);
  326. break;
  327. }
  328. }
  329. else {
  330. var result_1 = {};
  331. result_1.code = "-1";
  332. result_1.msg = "请求失败,请重新提交验证!";
  333. Utils_1.utils.Tool_Native.realNameAuthResult(JSON.stringify(result_1));
  334. Utils_1.utils.showMsg("请求失败,请重新提交验证!");
  335. }
  336. }
  337. else {
  338. Utils_1.utils.showMsg("请求失败,请重新提交验证!");
  339. var result_2 = {};
  340. result_2.code = "-1";
  341. result_2.msg = "请求失败,请重新提交验证!";
  342. Utils_1.utils.Tool_Native.realNameAuthResult(JSON.stringify(result_2));
  343. }
  344. });
  345. };
  346. return NativeCallBack;
  347. }());
  348. exports.NativeCallBack = NativeCallBack;
  349. cc["NativeCallBack"] = NativeCallBack;
  350. cc._RF.pop();