"use strict"; cc._RF.push(module, 'b5e23r+ncZBY6EnSw61Qf+n', 'Video'); // Script/sdk/vivo/Video.ts "use strict"; // Learn TypeScript: // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); var SDK_1 = require("../SDK"); var Utils_1 = require("../tools/Utils"); var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property; var Video = /** @class */ (function (_super) { __extends(Video, _super); function Video() { var _this = _super !== null && _super.apply(this, arguments) || this; _this._videoAd = null; return _this; } Video.prototype.init = function (config) { this._config = config; this._isVideo = config.videoAdEnable > 0; Utils_1.default.instance.log('创建Video广告'); this.initRewardVideo(); }; Video.prototype.initRewardVideo = function () { var self = this; var rewardvideoCode = this._config.videoAdCode; Utils_1.default.instance.log("-------激励视频创建----- " + rewardvideoCode); this._videoAd = qg.createRewardedVideoAd({ posId: rewardvideoCode }); this._videoAd.load(); this._videoAd.onError(function (err) { Utils_1.default.instance.log("激励视频广告加载失败" + JSON.stringify(err)); self.scheduleOnce(function () { self.initRewardVideo(); }, 4); self._loadVideo = false; }); this._videoAd.onLoad(function () { Utils_1.default.instance.log('激励视频加载成功'); self._loadVideo = true; }); this._videoAd.onClose(function (res) { self._loadVideo = false; if (res && res.isEnded) { Utils_1.default.instance.log('激励视频广告完成,发放奖励'); SDK_1.default.Instance.reportLog(SDK_1.NodeAction.VIDEO_CLOSE, "激励视频广告完成,发放奖励"); if (self._callBacks) { self._callBacks(); } } else { Utils_1.default.instance.log('激励视频广告取消关闭,不发放奖励'); SDK_1.default.Instance.reportLog(SDK_1.NodeAction.VIDEO_CLOSE, "激励视频广告取消关闭,不发放奖励"); if (self._fail) { self._fail(); } } self._callBacks = null; self._fail = null; self.loadRewardVideo(); }); }; Video.prototype.loadRewardVideo = function () { if (this._videoAd) { this._videoAd.load(); } else { this.initRewardVideo(); } }; Video.prototype.showRewardVideo = function (callBacks, fail, noAd) { this._callBacks = callBacks; this._fail = fail; if (this._isVideo) { if (this._videoAd) { if (this._loadVideo) { this._videoAd.show(); SDK_1.default.Instance.reportLog(SDK_1.NodeAction.VIDEO_SHOW, "激励视频广告展示"); } else { if (noAd) { noAd(); noAd = null; } this.loadRewardVideo(); } } else { if (noAd) { noAd(); noAd = null; } this.initRewardVideo(); } } }; Video = __decorate([ ccclass ], Video); return Video; }(cc.Component)); exports.default = Video; cc._RF.pop();