| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517 |
- require("./AnyThinkAds/ATRewardedVideoJSSDK");
- require("./AnyThinkAds/ATJSSDK");
- require("./AnyThinkAds/ATInterstitialJSSDK");
- require("./AnyThinkAds/ATNativeJSSDK");
- require("./AnyThinkAds/ATBannerJSSDK");
- var thirdVideo = cc.Class({
- name: "thirdVideo",
- proxy: null,
- toponId: '',
- toponKey: '',
- rewardPlaceId: '',
- interPlacementId: '',
- nativePlaceId: '',
- newCarNativePlaceId: '',
- fullInterPlacementId: '',
- bannerPlaceId: '',
- curPlacementId: '',
- curNativeId: '',
- frameWidth: 0,
- frameHeight: 0,
- nativeIsShow: false,
- nativeType: 0,
- nativeShow: false,
- nativeIsLoad: false,
- nativeIsLoading: false,
- interType: 0,
- // timeID: 0,
- bannerIsShow: false,
- // 启动
- ctor: function () {
- },
- initATJSSDK: function (channel) {
- console.log("Main Scene start.......")
- ATJSSDK.setLogDebug(false);
- var customMap = {
- "appCustomKey1": "appCustomValue1",
- "appCustomKey2": "appCustomValue2"
- };
- ATJSSDK.initCustomMap(customMap);
- // ATJSSDK.setChannel(channel);
- var placementCustomMap = {
- "placementCustomKey1": "placementCustomValue1",
- "placementCustomKey2": "placementCustomValue2"
- };
- ATJSSDK.setPlacementCustomMap(this.rewardPlaceId, placementCustomMap);
- if (cc.sys.os === cc.sys.OS_IOS) {
- ATJSSDK.initSDK("a5b0e8491845b3", "7eae0567827cfe2b22874061763f30c9");
- } else if (cc.sys.os === cc.sys.OS_ANDROID) {
- ATJSSDK.initSDK(this.toponId, this.toponKey);
- }
- ATJSSDK.getUserLocation(function (userLocation) {
- ATJSSDK.printLog("getUserLocation callback userLocation :" + userLocation);
- if (userLocation === ATJSSDK.kATUserLocationInEU) {
- if (ATJSSDK.getGDPRLevel() === ATJSSDK.UNKNOWN) {
- ATJSSDK.showGDPRAuth();
- }
- }
- });
- },
- init: function (toponId, toponKey, rewardPlaceId, interPlacementId, nativePlaceId, fullInterPlacementId, bannerPlaceId, channel) {
- this.toponId = toponId
- this.toponKey = toponKey
- this.rewardPlaceId = rewardPlaceId
- this.interPlacementId = interPlacementId
- this.nativePlaceId = nativePlaceId
- this.fullInterPlacementId = fullInterPlacementId
- this.bannerPlaceId = bannerPlaceId
- this.initATJSSDK(channel);
- cc["ATRewardedVideoJSSDK"] = ATRewardedVideoJSSDK;
- ATRewardedVideoJSSDK.setAdListener(this);
- },
- setAdListener(v) {
- ATRewardedVideoJSSDK.setAdListener(v);
- },
- back: function () {
- cc.director.loadScene("AnyThinkDemoScene");
- },
- loadAd: function (userIdKey, userDataKey, id) {
- console.log("loadAd ???????????????????????????? ")
- var setting = {};
- setting[ATRewardedVideoJSSDK.userIdKey] = userIdKey;
- setting[ATRewardedVideoJSSDK.userDataKey] = userDataKey;
- this.curPlacementId = id
- ATRewardedVideoJSSDK.loadRewardedVideo(this.curPlacementId, setting);
- },
- showAd: function () {
- console.log("showAd ???????????????????????????? ", this.curPlacementId)
- // ATRewardedVideoJSSDK.showAd(this.curPlacementId);
- ATRewardedVideoJSSDK.showAdInScenario(this.curPlacementId, "");
- },
- checkReady: function () {
- if (this.proxy == null) return;
- // this.proxy.checkReady();
- // ATJSSDK.printLog("AnyThinkRewardedVideo::checkReady() " + (ATRewardedVideoJSSDK.hasAdReady(this.curPlacementId) ? "Ready" : "No"));
- return ATRewardedVideoJSSDK.hasAdReady(this.curPlacementId) ? true : false;
- },
- //Callbacks
- onRewardedVideoAdLoaded: function (placementId) {
- //ATJSSDK.printLog("AnyThinkRewardedVideo::onRewardedVideoAdLoaded(" + placementId + ")");
- // console.log("AnyThinkRewardedVideo::onRewardedVideoAdLoaded(" + placementId + ")");
- if (this.proxy == null) return;
- this.proxy.onRewardedVideoAdLoaded(placementId);
- },
- onRewardedVideoAdFailed: function (placementId, errorInfo) {
- //ATJSSDK.printLog("AnyThinkRewardedVideo::onRewardedVideoAdFailed(" + placementId + ", " + errorInfo + ")");
- // console.log("AnyThinkRewardedVideo::onRewardedVideoAdFailed(" + placementId + ", " + errorInfo + ")");
- if (this.proxy == null) return;
- this.proxy.onRewardedVideoAdFailed(placementId, errorInfo);
- },
- onRewardedVideoAdPlayStart: function (placementId, callbackInfo) {
- //ATJSSDK.printLog("AnyThinkRewardedVideo::onRewardedVideoAdPlayStart(" + placementId + ", " + callbackInfo + ")");
- // console.log("AnyThinkRewardedVideo::onRewardedVideoAdPlayStart(" + placementId + ", " + callbackInfo + ")");
- if (this.proxy == null) return;
- this.proxy.onRewardedVideoAdPlayStart(placementId, callbackInfo);
- },
- onRewardedVideoAdPlayEnd: function (placementId, callbackInfo) {
- // ATJSSDK.printLog("AnyThinkRewardedVideo::onRewardedVideoAdPlayEnd(" + placementId + ", " + callbackInfo + ")");
- // console.log("AnyThinkRewardedVideo::onRewardedVideoAdPlayEnd(" + placementId + ", " + callbackInfo + ")");
- if (this.proxy == null) return;
- this.proxy.onRewardedVideoAdPlayEnd(placementId, callbackInfo);
- },
- onRewardedVideoAdPlayFailed: function (placementId, errorInfo, callbackInfo) {
- //ATJSSDK.printLog("AnyThinkRewardedVideo::onRewardedVideoAdPlayFailed(" + placementId + ", " + errorInfo + ", " + callbackInfo + ")");
- // console.log("AnyThinkRewardedVideo::onRewardedVideoAdPlayFailed(" + placementId + ", " + errorInfo + ", " + callbackInfo + ")");
- if (this.proxy == null) return;
- this.proxy.onRewardedVideoAdPlayFailed(placementId, errorInfo, callbackInfo);
- },
- onRewardedVideoAdClosed: function (placementId, callbackInfo) {
- //ATJSSDK.printLog("AnyThinkRewardedVideo::onRewardedVideoAdClosed(" + placementId + ", " + callbackInfo + ")");
- // console.log("AnyThinkRewardedVideo::onRewardedVideoAdClosed(" + placementId + ", " + callbackInfo + ")");
- if (this.proxy == null) return;
- this.proxy.onRewardedVideoAdClosed(placementId, callbackInfo);
- },
- onRewardedVideoAdPlayClicked: function (placementId, callbackInfo) {
- //ATJSSDK.printLog("AnyThinkRewardedVideo::onRewardedVideoAdPlayClicked(" + placementId + ", " + callbackInfo + ")");
- // console.log("AnyThinkRewardedVideo::onRewardedVideoAdPlayClicked(" + placementId + ", " + callbackInfo + ")");
- if (this.proxy == null) return;
- this.proxy.onRewardedVideoAdPlayClicked(placementId, callbackInfo);
- },
- onReward: function (placementId, callbackInfo) {
- //ATJSSDK.printLog("AnyThinkRewardedVideo::onReward(" + placementId + ", " + callbackInfo + ")");
- // console.log("AnyThinkRewardedVideo::onReward(" + placementId + ", " + callbackInfo + ")");
- if (this.proxy == null) return;
- this.proxy.onReward(placementId, callbackInfo);
- },
- //插屏广告
- loadInter: function (type) {
- //v5.6.8新增,只针对Sigmob平台,Sigmob的激励视频广告源当做插屏使用
- var setting = {};
- setting[ATInterstitialJSSDK.UseRewardedVideoAsInterstitial] = false;
- this.interType = type
- ATInterstitialJSSDK.setAdListener(this);
- //setting[ATInterstitialJSSDK.UseRewardedVideoAsInterstitial] = true;
- if (this.interType == 0) {
- ATInterstitialJSSDK.loadInterstitial(this.interPlacementId, setting);
- // ATInterstitialJSSDK.showAd(this.interPlacementId);
- }
- else if (this.interType == 1) {
- ATInterstitialJSSDK.loadInterstitial(this.fullInterPlacementId, setting);
- // ATInterstitialJSSDK.showAd(this.fullInterPlacementId);
- }
- },
- /** 检查插屏是否加载成功 */
- checkInterReady(type) {
- if (this.proxy == null) return;
- if (type == 0) {
- return ATInterstitialJSSDK.hasAdReady(this.interPlacementId) ? true : false;
- }
- else if (type == 1) {
- return ATInterstitialJSSDK.hasAdReady(this.fullInterPlacementId) ? true : false;
- }
- },
- showInter(type) {
- if (type == 0) {
- ATInterstitialJSSDK.showAd(this.interPlacementId);
- }
- else if (type == 1) {
- ATInterstitialJSSDK.showAd(this.fullInterPlacementId);
- }
- },
- //广告加载成功
- onInterstitialAdLoaded: function (placementId) {
- // console.log("AnyThinkInterstitialDemo::onInterstitialAdLoaded(" + placementId + ")");
- // if (this.interType == 0) {
- // ATInterstitialJSSDK.showAd(this.interPlacementId);
- // }
- // else if (this.interType == 1) {
- // ATInterstitialJSSDK.showAd(this.fullInterPlacementId);
- // }
- if (this.proxy == null) return;
- this.proxy.onInterstitialAdLoaded(placementId);
- },
- //广告加载失败
- onInterstitialAdLoadFail: function (placementId, errorInfo) {
- // console.log("AnyThinkInterstitialDemo::onInterstitialAdLoadFail(" + placementId + ", " + errorInfo + ")");
- if (this.proxy == null) return;
- this.proxy.onInterstitialAdLoadFail(placementId, errorInfo);
- },
- //广告展示成功
- onInterstitialAdShow: function (placementId, callbackInfo) {
- // console.log("AnyThinkInterstitialDemo::onInterstitialAdShow(" + placementId + ", " + callbackInfo + ")");
- if (this.proxy == null) return;
- this.proxy.onInterstitialAdShow(placementId, callbackInfo);
- },
- //广告视频开始播放,部分平台有此回调
- onInterstitialAdStartPlayingVideo: function (placementId, callbackInfo) {
- // console.log("AnyThinkInterstitialDemo::onInterstitialAdStartPlayingVideo(" + placementId + ", " + callbackInfo + ")");
- },
- //广告视频播放结束,部分广告平台有此回调
- onInterstitialAdEndPlayingVideo: function (placementId, callbackInfo) {
- // console.log("AnyThinkInterstitialDemo::onInterstitialAdEndPlayingVideo(" + placementId + ", " + callbackInfo + ")");
- },
- //广告视频播放失败,部分广告平台有此回调
- onInterstitialAdFailedToPlayVideo: function (placementId, errorInfo) {
- // console.log("AnyThinkInterstitialDemo::onInterstitialAdFailedToPlayVideo(" + placementId + ", " + errorInfo + ")");
- },
- //广告展示失败
- onInterstitialAdFailedToShow: function (placementId) {
- // console.log("AnyThinkInterstitialDemo::onInterstitialAdFailedToShow(" + placementId + ")");
- },
- //广告被关闭
- onInterstitialAdClose: function (placementId, callbackInfo) {
- // console.log("AnyThinkInterstitialDemo::onInterstitialAdClose(" + placementId + ", " + callbackInfo + ")");
- if (this.proxy == null) return;
- this.proxy.onInterstitialAdClose(placementId, callbackInfo);
- },
- //广告被点击
- onInterstitialAdClick: function (placementId, callbackInfo) {
- // console.log("AnyThinkInterstitialDemo::onInterstitialAdClick(" + placementId + ", " + callbackInfo + ")");
- if (this.proxy == null) return;
- this.proxy.onInterstitialAdClick(placementId, callbackInfo);
- },
- //原生广告
- loadNative: function (type = 0, show = false) {
- this.nativeType = type
- this.nativeShow = show
- this.nativeIsLoading = true
- //加载原生广告时需要传入广告展示的宽高
- var frameSize = cc.view.getFrameSize();
- this.frameWidth = frameSize.width;
- this.frameHeight = frameSize.height;
- var per = this.frameWidth / 750
- var sw = per * 656
- var sh = per * 440
- if (this.nativeType == 2) {
- this.destroyNative(false)
- sw *= 0.9
- sh *= 0.8
- this.curNativeId = this.nativePlaceId
- }
- else if (this.nativeType == 3) {
- this.destroyNative(false)
- sw *= 0.9
- sh *= 0.75
- this.curNativeId = this.nativePlaceId
- }
- else {
- this.curNativeId = this.nativePlaceId
- sw *= 0.95
- }
- ATNativeJSSDK.setAdListener(this)
- ATNativeJSSDK.loadNative(this.curNativeId, ATNativeJSSDK.createLoadAdSize(sw, sh));
- },
- destroyNative: function (load = true) {
- ATNativeJSSDK.removeAd(this.curNativeId);
- // this.nativeIsLoad = false
- this.nativeIsShow = false
- this.nativeShow = false
- if (load) {
- // this.loadNative()
- }
- },
- /** 信息流位置
- * @param type 0 弹窗里 1 最底部 2 弹窗顶部 3 底部小窗口
- */
- showNative(type) {
- // console.log('AnyThinkNativeDemo 111111111 ')
- if (this.nativeIsShow) {
- return
- }
- if (this.nativeIsLoading) {
- this.nativeType = type
- this.nativeShow = true
- return
- }
- if (!this.nativeIsLoad) {
- this.loadNative(type, true)
- return
- }
- // console.log('AnyThinkNativeDemo 2222222222 ')
- // console.log('AnyThinkNativeDemo 333333333333 ')
- this.nativeIsShow = true
- var per = this.frameWidth / 750
- var sw = per * 656
- var sh = per * 440
- var fontSize = 12
- var nativeAdViewProperty = new ATNativeJSSDK.AdViewProperty();
- var posy = 0
- if (type == 0) {
- // posy = this.frameHeight * 0.5 - 100
- posy = this.frameHeight * 0.605 - sh * 0.5
- sw *= 0.95
- var fontSize = 10
- }
- else if (type == 1) {
- // posy = this.frameHeight * 0.5 + 280
- posy = this.frameHeight * 0.625
- }
- else if (type == 2) {
- // posy = this.frameHeight * 0.5 + 210
- sw *= 0.95
- posy = this.frameHeight * 0.36 - sh * 0.5
- }
- else if (type == 3) {
- // posy = this.frameHeight * 0.5 + 420
- posy = this.frameHeight * 0.69
- sw *= 0.9
- sh *= 0.75
- fontSize = 8
- }
- var parx = (this.frameWidth - sw) * 0.5
- nativeAdViewProperty.parent = nativeAdViewProperty.createItemViewProperty(parx, posy, sw, sh, "#ffffff", "", 0);
- nativeAdViewProperty.mainImage = nativeAdViewProperty.createItemViewProperty(0, 0, sw, sh, "#ffffff", "#ffffff", fontSize);
- ATNativeJSSDK.showAd(this.curNativeId, nativeAdViewProperty);
- },
- //广告加载成功
- onNativeAdLoaded: function (placementId) {
- this.nativeIsLoad = true
- this.nativeIsLoading = false
- // console.log("AnyThinkNativeDemo::onNativeAdLoaded(" + placementId + ")");
- if (this.nativeShow) {
- // console.log('AnyThinkNativeDemo aaaaaaaaaa ')
- this.nativeIsShow = false
- this.showNative(this.nativeType)
- }
- if (this.proxy == null) return;
- this.proxy.onNativeAdLoaded(placementId);
- },
- //广告加载失败
- onNativeAdLoadFail: function (placementId, errorInfo) {
- // console.log("AnyThinkNativeDemo::onNativeAdLoadFail(" + placementId + ", " + errorInfo + ")");
- this.nativeIsLoading = false
- this.nativeIsLoad = false
- if (this.proxy == null) return;
- this.proxy.onNativeAdLoadFail(placementId, errorInfo);
- },
- //广告展示成功
- onNativeAdShow: function (placementId, callbackInfo) {
- // console.log("AnyThinkNativeDemo::onNativeAdShow(" + placementId + ", " + callbackInfo + ")");
- if (this.proxy == null) return;
- this.proxy.onNativeAdShow(placementId, callbackInfo);
- },
- //广告被点击
- onNativeAdClick: function (placementId, callbackInfo) {
- // console.log("AnyThinkNativeDemo::onNativeAdClick(" + placementId + ", " + callbackInfo + ")");
- if (this.proxy == null) return;
- this.proxy.onNativeAdClick(placementId, callbackInfo);
- },
- //广告视频开始播放,部分广告平台有此回调
- onNativeAdVideoStart: function (placementId) {
- // console.log("AnyThinkNativeDemo::onNativeAdVideoStart(" + placementId + ")");
- },
- //广告视频结束播放,部分广告平台有此回调
- onNativeAdVideoEnd: function (placementId) {
- // console.log("AnyThinkNativeDemo::onNativeAdVideoEnd(" + placementId + ")");
- },
- //广告关闭按钮被点击,部分广告平台有此回调
- onNativeAdCloseButtonTapped: function (placementId, callbackInfo) {
- // console.log("AnyThinkNativeDemo::onNativeAdCloseButtonTapped(" + placementId + ", " + callbackInfo + ")");
- },
- /** banner广告----------------- */
- //加载banner
- loadBanner: function () {
- let winHeight = cc.view.getFrameSize().height
- if (winHeight < 1400) {
- return
- }
- var setting = {}
- var bannerH = winHeight / 1334 * 120
- console.log('winHeight ', winHeight, ' winWidth ', cc.view.getFrameSize().width, ' bannerHeight ', bannerH)
- setting[ATBannerJSSDK.kATBannerAdLoadingExtraBannerAdSizeStruct] = ATBannerJSSDK.createLoadAdSize(cc.view.getFrameSize().width, bannerH);
- //只针对Admob的自适应banner
- setting[ATBannerJSSDK.kATBannerAdInlineAdaptiveWidth] = cc.view.getFrameSize().width;
- setting[ATBannerJSSDK.kATBannerAdInlineAdaptiveOrientation] = ATBannerJSSDK.kATBannerAdInlineAdaptiveOrientationCurrent;
- // setting[ATBannerJSSDK.kATBannerAdInlineAdaptiveOrientation] = ATBannerJSSDK.kATBannerAdInlineAdaptiveOrientationPortrait;
- // setting[ATBannerJSSDK.kATBannerAdInlineAdaptiveOrientation] = ATBannerJSSDK.kATBannerAdInlineAdaptiveOrientationLandscape;
- ATBannerJSSDK.setAdListener(this)
- ATBannerJSSDK.loadBanner(this.bannerPlaceId, setting);
- },
- //banner是否准备就绪
- checkBannerReady() {
- return ATBannerJSSDK.hasAdReady(this.bannerPlaceId) ? true : false
- },
- //显示banner
- showBanner() {
- if (this.bannerIsShow) {
- return
- }
- ATBannerJSSDK.showAdInPosition(this.bannerPlaceId, ATBannerJSSDK.kATBannerAdShowingPositionBottom);
- },
- destroyBanner() {
- if (this.bannerIsShow) {
- ATBannerJSSDK.removeAd(this.bannerPlaceId);
- this.bannerIsShow = false
- this.loadBanner()
- }
- },
- //广告加载成功
- onBannerAdLoaded: function (placementId) {
- ATJSSDK.printLog("AnyThinkBannerDemo::onBannerAdLoaded(" + placementId + ")");
- if (this.proxy == null) return;
- this.proxy.onBannerAdLoaded(placementId);
- },
- //广告加载失败
- onBannerAdLoadFail: function (placementId, errorInfo) {
- ATJSSDK.printLog("AnyThinkBannerDemo::onBannerAdLoadFail(" + placementId + ", " + errorInfo + ")");
- if (this.proxy == null) return;
- this.proxy.onBannerAdLoadFail(placementId, errorInfo);
- },
- //广告展示成功
- onBannerAdShow: function (placementId, callbackInfo) {
- ATJSSDK.printLog("AnyThinkBannerDemo::onBannerAdShow(" + placementId + ", " + callbackInfo + ")");
- this.bannerIsShow = true
- if (this.proxy == null) return;
- this.proxy.onBannerAdShow(placementId, callbackInfo);
- },
- //广告被点击
- onBannerAdClick: function (placementId, callbackInfo) {
- ATJSSDK.printLog("AnyThinkBannerDemo::onBannerAdClick(" + placementId + ", " + callbackInfo + ")");
- if (this.proxy == null) return;
- this.proxy.onBannerAdClick(placementId, callbackInfo);
- },
- //广告自动刷新成功
- onBannerAdAutoRefresh: function (placementId, callbackInfo) {
- ATJSSDK.printLog("AnyThinkBannerDemo::onBannerAdAutoRefresh(" + placementId + ", " + callbackInfo + ")");
- if (this.proxy == null) return;
- },
- //广告自动刷新失败
- onBannerAdAutoRefreshFail: function (placementId, errorInfo) {
- ATJSSDK.printLog("AnyThinkBannerDemo::onBannerAdAutoRefreshFail(" + placementId + ", " + errorInfo + ")");
- if (this.proxy == null) return;
- },
- //广告关闭按钮被点击
- onBannerAdCloseButtonTapped: function (placementId, callbackInfo) {
- ATJSSDK.printLog("AnyThinkBannerDemo::onBannerAdCloseButtonTapped(" + placementId + ", " + callbackInfo + ")");
- if (this.proxy == null) return;
- }
- });
- module.exports = thirdVideo;
- cc["thirdVideo"] = new thirdVideo();
|