b5e23afe-9dc6-4163-a127-4b0eb541ffa7.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. "use strict";
  2. cc._RF.push(module, 'b5e23r+ncZBY6EnSw61Qf+n', 'Video');
  3. // Script/sdk/vivo/Video.ts
  4. "use strict";
  5. // Learn TypeScript:
  6. // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
  7. // Learn Attribute:
  8. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  9. // Learn life-cycle callbacks:
  10. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  11. var __extends = (this && this.__extends) || (function () {
  12. var extendStatics = function (d, b) {
  13. extendStatics = Object.setPrototypeOf ||
  14. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  15. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  16. return extendStatics(d, b);
  17. };
  18. return function (d, b) {
  19. extendStatics(d, b);
  20. function __() { this.constructor = d; }
  21. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  22. };
  23. })();
  24. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  25. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  26. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  27. 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;
  28. return c > 3 && r && Object.defineProperty(target, key, r), r;
  29. };
  30. Object.defineProperty(exports, "__esModule", { value: true });
  31. var SDK_1 = require("../SDK");
  32. var Utils_1 = require("../tools/Utils");
  33. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  34. var Video = /** @class */ (function (_super) {
  35. __extends(Video, _super);
  36. function Video() {
  37. var _this = _super !== null && _super.apply(this, arguments) || this;
  38. _this._videoAd = null;
  39. return _this;
  40. }
  41. Video.prototype.init = function (config) {
  42. this._config = config;
  43. this._isVideo = config.videoAdEnable > 0;
  44. Utils_1.default.instance.log('创建Video广告');
  45. this.initRewardVideo();
  46. };
  47. Video.prototype.initRewardVideo = function () {
  48. var self = this;
  49. var rewardvideoCode = this._config.videoAdCode;
  50. Utils_1.default.instance.log("-------激励视频创建----- " + rewardvideoCode);
  51. this._videoAd = qg.createRewardedVideoAd({
  52. posId: rewardvideoCode
  53. });
  54. this._videoAd.load();
  55. this._videoAd.onError(function (err) {
  56. Utils_1.default.instance.log("激励视频广告加载失败" + JSON.stringify(err));
  57. self.scheduleOnce(function () {
  58. self.initRewardVideo();
  59. }, 4);
  60. self._loadVideo = false;
  61. });
  62. this._videoAd.onLoad(function () {
  63. Utils_1.default.instance.log('激励视频加载成功');
  64. self._loadVideo = true;
  65. });
  66. this._videoAd.onClose(function (res) {
  67. self._loadVideo = false;
  68. if (res && res.isEnded) {
  69. Utils_1.default.instance.log('激励视频广告完成,发放奖励');
  70. SDK_1.default.Instance.reportLog(SDK_1.NodeAction.VIDEO_CLOSE, "激励视频广告完成,发放奖励");
  71. if (self._callBacks) {
  72. self._callBacks();
  73. }
  74. }
  75. else {
  76. Utils_1.default.instance.log('激励视频广告取消关闭,不发放奖励');
  77. SDK_1.default.Instance.reportLog(SDK_1.NodeAction.VIDEO_CLOSE, "激励视频广告取消关闭,不发放奖励");
  78. if (self._fail) {
  79. self._fail();
  80. }
  81. }
  82. self._callBacks = null;
  83. self._fail = null;
  84. self.loadRewardVideo();
  85. });
  86. };
  87. Video.prototype.loadRewardVideo = function () {
  88. if (this._videoAd) {
  89. this._videoAd.load();
  90. }
  91. else {
  92. this.initRewardVideo();
  93. }
  94. };
  95. Video.prototype.showRewardVideo = function (callBacks, fail, noAd) {
  96. this._callBacks = callBacks;
  97. this._fail = fail;
  98. if (this._isVideo) {
  99. if (this._videoAd) {
  100. if (this._loadVideo) {
  101. this._videoAd.show();
  102. SDK_1.default.Instance.reportLog(SDK_1.NodeAction.VIDEO_SHOW, "激励视频广告展示");
  103. }
  104. else {
  105. if (noAd) {
  106. noAd();
  107. noAd = null;
  108. }
  109. this.loadRewardVideo();
  110. }
  111. }
  112. else {
  113. if (noAd) {
  114. noAd();
  115. noAd = null;
  116. }
  117. this.initRewardVideo();
  118. }
  119. }
  120. };
  121. Video = __decorate([
  122. ccclass
  123. ], Video);
  124. return Video;
  125. }(cc.Component));
  126. exports.default = Video;
  127. cc._RF.pop();