| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420 |
- import { STORAGE_KEY } from "../../../datas/GlobalStorage";
- import EffectNode from "../../../ui/EffectNode";
- import NativeADAwardNode from "../../../ui/NativeAdAwardNode";
- import LogUtil from "../../../utils/LogUtil";
- import { Utils } from "../../../utils/Utils";
- import AdM from "../../AdM";
- import GameM from "../../GameM";
- import NativeAdAwardData from "../../NativeAdAwardData";
- import SwitchM from "../../SwitchM";
- import UiM from "../../UiM";
- import { zgSingleton } from "./zgSingleton";
- export class thirdVideoTS extends zgSingleton {
- private canGet = false
- private interType = 0
- private onloadInter = false
- private onLoadReward = false
- init() {
- cc["thirdVideo"].proxy = this;
- cc["thirdVideo"].init(GameM.commonData.toponId, GameM.commonData.toponKey, GameM.commonData.rewardPlaceId, GameM.commonData.interPlaceId, GameM.commonData.nativePlaceId,
- GameM.commonData.fullInterPlaceId, GameM.commonData.bannerPlaceId, GameM.commonData.umengChannel);
- this.loadAd()
- this.loadNative()
- if (SwitchM.forceMakeMoney) {
- this.loadBanner()
- }
- // this.loadInter(1)
- //5秒后加载普通插屏
- let id = setTimeout(() => {
- this.loadInter(0)
- clearTimeout(id)
- }, 5000);
- GameM.commonData.toponLoaded = true
- }
- /** 加载广告 激励视频
- */
- loadAd() {
- if (this.onLoadReward) {
- return
- }
- LogUtil.logV('showAd ', 'loadAd end')
- setTimeout(() => {
- this.onLoadReward = false
- }, 3000);
- this.onLoadReward = true
- this.canGet = false
- cc["thirdVideo"].loadAd("userIdKey", "userDataKey", GameM.commonData.rewardPlaceId);
- let eventID = Utils.randomString(32);
- AdM.sendUROIEvent(eventID, '', GameM.commonData.rewardPlaceId, "ad_request", "rewarded", 'other', '')
- }
- showAd() {
- LogUtil.logV('showAd ', 'before')
- if (!GameM.commonData.toponLoaded) {
- return
- }
- LogUtil.logV('showAd ', 'end')
- if (this.checkReady()) {
- LogUtil.logV('showAd ', 'showAd')
- cc["thirdVideo"].showAd();
- }
- else {
- this.loadAd()
- AdM.onWatchFailEnd()
- }
- //ATRewardedVideoJSSDK.showAdInScenario(this.placementID(), "f5e54970dc84e6");
- }
- checkReady() {
- //ATJSSDK.printLog("AnyThinkRewardedVideoDemo::checkReady() " + (ATRewardedVideoJSSDK.hasAdReady(this.placementID()) ? "Ready" : "No"));
- return cc["thirdVideo"].checkReady()
- }
- //Callbacks
- onRewardedVideoAdLoaded(placementId: string) {
- // cc["thirdVideo"].onRewardedVideoAdLoaded(placementId);
- // ATJSSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdLoaded(" + placementId + ")");
- console.log('AnyThinkRewardedVideoDemo loadAd完毕,准备显示Ad')
- this.onLoadReward = false
- let eventID = Utils.randomString(32);
- AdM.sendUROIEvent(eventID, '', placementId, "ad_fill", "rewarded", 'other', '')
- }
- onRewardedVideoAdFailed(placementId, errorInfo) {
- // cc["thirdVideo"].onRewardedVideoAdFailed(placementId,errorInfo);
- //ATJSSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdFailed(" + placementId + ", " + errorInfo + ")");
- console.log('AnyThinkRewardedVideoDemo onRewardedVideoAdFailed')
- console.log('placementId ', placementId, ' onRewardedVideoAdFailed ', errorInfo)
- this.onLoadReward = false
- GameM.commonData.updateADLog(5, placementId)
- }
- onRewardedVideoAdPlayStart(placementId, callbackInfo) {
- console.log('AnyThinkRewardedVideoDemo onRewardedVideoAdPlayStart')
- //ATJSSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayStart(" + placementId + ", " + callbackInfo + ")");
- let data = JSON.parse(callbackInfo)
- GameM.commonData.updateADLog(4, placementId, data.adunit_format, data.network_type, data.network_placement_id,
- data.network_firm_id, data.adsource_id, data.adsource_index, data.adsource_price,
- data.adsource_isheaderbidding, data.publisher_revenue, data.precision, data.ecpm_level)
- let eventID = Utils.randomString(32);
- let adAdn = this.getAdAdn(data.network_firm_id)
- let price = GameM.commonData.getAdPrice(data.adsource_id, data.adsource_price)
- AdM.sendUROIEvent(eventID, data.id, placementId, "ad_show", "rewarded", adAdn, price)
- }
- onRewardedVideoAdPlayEnd(placementId, callbackInfo) {
- console.log('AnyThinkRewardedVideoDemo onRewardedVideoAdPlayEnd')
- //ATJSSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayEnd(" + placementId + ", " + callbackInfo + ")");
- }
- onRewardedVideoAdPlayFailed(placementId, errorInfo, callbackInfo) {
- console.log('AnyThinkRewardedVideoDemo onRewardedVideoAdPlayFailed')
- //ATJSSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayFailed(" + placementId + ", " + errorInfo + ", " + callbackInfo + ")");
- // console.log('play placementId ', placementId, ' errorInfo ', errorInfo)
- AdM.onWatchFailEnd()
- }
- onRewardedVideoAdClosed(placementId, callbackInfo) {
- // ATJSSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdClosed(" + placementId + ", " + callbackInfo + ")");
- console.log('AnyThinkRewardedVideoDemo onRewardedVideoAdClosed, canGet ', this.canGet)
- if (this.canGet) {
- let data = JSON.parse(callbackInfo)
- AdM.onWatchEnd(placementId, data.adunit_format, data.network_type, data.network_placement_id,
- data.network_firm_id, data.adsource_id, data.adsource_index, data.adsource_price,
- data.adsource_isheaderbidding, data.publisher_revenue, data.precision, data.ecpm_level)
- AdM.onKSEvent(3)
- }
- else {
- AdM.onWatchCancleEnd()
- }
- this.canGet = false
- this.loadAd()
- }
- onRewardedVideoAdPlayClicked(placementId, callbackInfo) {
- // ATJSSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayClicked(" + placementId + ", " + callbackInfo + ")");
- let data = JSON.parse(callbackInfo)
- let eventID = Utils.randomString(32);
- console.log('AnyThinkRewardedVideoDemo onRewardedVideoAdPlayClicked')
- let adAdn = this.getAdAdn(data.network_firm_id)
- let price = GameM.commonData.getAdPrice(data.adsource_id, data.adsource_price)
- AdM.sendUROIEvent(eventID, data.id, placementId, "ad_click", "rewarded", adAdn, price)
- }
- onReward(placementId, callbackInfo) {
- // ATJSSDK.printLog("AnyThinkRewardedVideoDemo::onReward(" + placementId + ", " + callbackInfo + ")");
- console.log('AnyThinkRewardedVideoDemo onReward')
- this.canGet = true
- }
- /** 插屏广告
- * @param type 0 普通插屏 1 全屏视频插屏
- */
- loadInter(type) {
- // console.log('99999999 loadInterPre ', type)
- if (!this.onloadInter) {
- this.onloadInter = true
- // console.log('99999999 loadInter ', type)
- cc["thirdVideo"].loadInter(type);
- let eventID = Utils.randomString(32);
- AdM.sendUROIEvent(eventID, '', GameM.commonData.interPlaceId, "ad_request", "interstitial", 'other', '')
- }
- }
- showInter(type) {
- if (!GameM.commonData.toponLoaded) {
- return
- }
- this.interType = type
- if (cc["thirdVideo"].checkInterReady(type)) {
- // console.log('99999999 showInter success')
- cc["thirdVideo"].showInter(type);
- }
- else {
- // console.log('99999999 showInter fail')
- this.loadInter(type)
- }
- }
- onInterstitialAdLoaded(placementId) {
- this.onloadInter = false
- // console.log('99999999 onInterstitialAdLoaded ')
- let eventID = Utils.randomString(32);
- AdM.sendUROIEvent(eventID, '', placementId, "ad_fill", "interstitial", 'other', '')
- }
- onInterstitialAdLoadFail(placementId, errorInfo) {
- this.onloadInter = false
- // console.log('99999999 onInterstitialAdLoadFail')
- if (placementId == GameM.commonData.fullInterPlaceId) {
- EffectNode.instance.PlayTip('拉取全屏视频失败,请稍后再试')
- GameM.commonData.updateADLog(10, placementId)
- }
- else if (placementId == GameM.commonData.interPlaceId) {
- GameM.commonData.updateADLog(11, placementId)
- }
- }
- //广告展示成功
- onInterstitialAdShow(placementId, callbackInfo) {
- // console.log('99999999 onInterstitialAdShow')
- let data = JSON.parse(callbackInfo)
- let id = 2
- if (placementId == GameM.commonData.interPlaceId) {
- id = 2
- }
- else if (placementId == GameM.commonData.fullInterPlaceId) {
- id = 9
- }
- GameM.commonData.updateADLog(id, placementId, data.adunit_format, data.network_type, data.network_placement_id,
- data.network_firm_id, data.adsource_id, data.adsource_index, data.adsource_price,
- data.adsource_isheaderbidding, data.publisher_revenue, data.precision, data.ecpm_level)
- let eventID = Utils.randomString(32);
- let adAdn = this.getAdAdn(data.network_firm_id)
- let price = GameM.commonData.getAdPrice(data.adsource_id, data.adsource_price)
- AdM.sendUROIEvent(eventID, data.id, placementId, "ad_show", "interstitial", adAdn, price)
- }
- onInterstitialAdClick(placementId, callbackInfo) {
- let data = JSON.parse(callbackInfo)
- let eventID = Utils.randomString(32);
- let adAdn = this.getAdAdn(data.network_firm_id)
- let price = GameM.commonData.getAdPrice(data.adsource_id, data.adsource_price)
- AdM.sendUROIEvent(eventID, data.id, placementId, "ad_click", "interstitial", adAdn, price)
- }
- //插屏广告关闭
- onInterstitialAdClose(placementId, callbackInfo) {
- //给奖励
- // console.log('AnyThinkInterstitialDemo ', this.interType)
- if (placementId == GameM.commonData.fullInterPlaceId) {
- GameM.commonData.showFull = false
- GameM.commonData.todayFullInterTimes++
- GameM.globalStorage.setStorage(STORAGE_KEY.todayFullInterTimes, GameM.commonData.todayFullInterTimes)
- AdM.videoReward()
- let data = JSON.parse(callbackInfo)
- GameM.commonData.updateADLog(8, placementId, data.adunit_format, data.network_type, data.network_placement_id,
- data.network_firm_id, data.adsource_id, data.adsource_index, data.adsource_price,
- data.adsource_isheaderbidding, data.publisher_revenue, data.precision, data.ecpm_level)
- }
- this.loadInter(this.interType)
- }
- loadNative(type = 0, show = false) {
- // console.log('AnyThinkNativeDemo loadNative ')
- cc["thirdVideo"].loadNative(type, show);
- let eventID = Utils.randomString(32);
- AdM.sendUROIEvent(eventID, '', GameM.commonData.nativePlaceId, "ad_request", "flow", 'other', '')
- }
- /** 信息流位置
- * @param type 0 弹窗里 1 最底部 2 弹窗顶部 3 底部小窗口
- */
- showNative(type) {
- if (!GameM.commonData.toponLoaded) {
- return
- }
- // console.log('AnyThinkNativeDemo showNative ')
- cc["thirdVideo"].showNative(type);
- }
- onNativeAdLoaded(placementId) {
- let eventID = Utils.randomString(32);
- AdM.sendUROIEvent(eventID, '', placementId, "ad_fill", "flow", 'other', '')
- }
- //广告展示成功
- onNativeAdShow(placementId, callbackInfo) {
- let data = JSON.parse(callbackInfo)
- GameM.commonData.updateADLog(3, placementId, data.adunit_format, data.network_type, data.network_placement_id,
- data.network_firm_id, data.adsource_id, data.adsource_index, data.adsource_price,
- data.adsource_isheaderbidding, data.publisher_revenue, data.precision, data.ecpm_level)
- let eventID = Utils.randomString(32);
- let adAdn = this.getAdAdn(data.network_firm_id)
- let price = GameM.commonData.getAdPrice(data.adsource_id, data.adsource_price)
- AdM.sendUROIEvent(eventID, data.id, placementId, "ad_show", "flow", adAdn, price)
- this.loadNative()
- }
- onNativeAdClick(placementId, callbackInfo) {
- let data = JSON.parse(callbackInfo)
- let eventID = Utils.randomString(32);
- let adAdn = this.getAdAdn(data.network_firm_id)
- let price = GameM.commonData.getAdPrice(data.adsource_id, data.adsource_price)
- AdM.sendUROIEvent(eventID, data.id, placementId, "ad_click", "flow", adAdn, price)
- if (NativeAdAwardData.Instance.openNativeState) {
- NativeAdAwardData.Instance.setHasClickNative()
- if (UiM.Instance.nativeAdAwardNode) {
- // let type = UiM.Instance.nativeAdAwardNode.getComponent(NativeADAwardNode).type
- // AdM.onSendEvent('NativeAdAwardClick' + type, `信息流变现点击${type}`, 'NativeAdAwardClick')
- }
- }
- }
- onNativeAdLoadFail(placementId, errorInfo) {
- GameM.commonData.updateADLog(12, placementId)
- }
- destroyNative() {
- if (!GameM.commonData.toponLoaded) {
- return
- }
- cc["thirdVideo"].destroyNative();
- }
- getIsNativeShow() {
- return cc["thirdVideo"].nativeIsShow || cc["thirdVideo"].nativeShow
- }
- /** banner相关------------- */
- loadBanner() {
- cc["thirdVideo"].loadBanner();
- }
- checkBannerReady() {
- return cc["thirdVideo"].checkBannerReady()
- }
- /** banner是否显示 */
- getIsBannerShow() {
- return cc["thirdVideo"].bannerIsShow
- }
- /** 显示banner
- */
- showBanner() {
- if (!GameM.commonData.toponLoaded) {
- return
- }
- if (this.checkBannerReady()) {
- cc["thirdVideo"].showBanner();
- }
- else {
- this.loadBanner()
- }
- }
- destroyBanner() {
- if (!GameM.commonData.toponLoaded) {
- return
- }
- cc["thirdVideo"].destroyBanner();
- }
- onBannerAdLoaded(placementId) {
- let eventID = Utils.randomString(32);
- AdM.sendUROIEvent(eventID, '', placementId, "ad_fill", "flow", 'other', '')
- }
- //广告展示成功
- onBannerAdShow(placementId, callbackInfo) {
- let data = JSON.parse(callbackInfo)
- GameM.commonData.updateADLog(7, placementId, data.adunit_format, data.network_type, data.network_placement_id,
- data.network_firm_id, data.adsource_id, data.adsource_index, data.adsource_price,
- data.adsource_isheaderbidding, data.publisher_revenue, data.precision, data.ecpm_level)
- let eventID = Utils.randomString(32);
- let adAdn = this.getAdAdn(data.network_firm_id)
- let price = GameM.commonData.getAdPrice(data.adsource_id, data.adsource_price)
- AdM.sendUROIEvent(eventID, data.id, placementId, "ad_show", "flow", adAdn, price)
- }
- onBannerAdClick(placementId, callbackInfo) {
- let data = JSON.parse(callbackInfo)
- let eventID = Utils.randomString(32);
- let adAdn = this.getAdAdn(data.network_firm_id)
- let price = GameM.commonData.getAdPrice(data.adsource_id, data.adsource_price)
- AdM.sendUROIEvent(eventID, data.id, placementId, "ad_click", "flow", adAdn, price)
- }
- onBannerAdLoadFail(placementId, errorInfo) {
- GameM.commonData.updateADLog(14, placementId)
- }
- /** 获取 广告平台来源
- * @param network_firm_id topon平台ID
- */
- getAdAdn(network_firm_id) {
- let adAdn = ''
- if (network_firm_id == 8) {
- adAdn = "gdt"
- }
- else if (network_firm_id == 15) {
- adAdn = "bytedance_pangle"
- }
- else if (network_firm_id == 28) {
- adAdn = "other"
- }
- return adAdn;
- }
- }
|