TTAdSdk.ts 2.81 KB
import { AppSdk } from "./AppSdk";
import ObjectInstance from "../uitl/ObjectInstance";

export default class TTAdSdk {
    async showRewardVideoAd( preload: number = 0) {
        let data = {
            w: AppSdk.I.width,
            h: AppSdk.I.height,
            preloading: preload,
        }
        return new Promise((resolve, reject) => {
            let isComplete = false;
            AppSdk.I.callAppWithBack(ret => {
                let { code, message } = JSON.parse(ret);
                switch (code) {
                    case -1:
                        reject('error');
                       /**'暂无视频广告!每日0点重置'*/;
                        break;
                    case 200:
                        isComplete = true;
                        break;
                    case 100:
                        break;
                    case 0:
                        if (isComplete) {
                            resolve();
                        } else {
                            reject('unComplete');
                        }
                        break;
                }
            }, 'showRewardVideoAd', 1, JSON.stringify(data))
        })
    }

    async loadFullScreenVideoAd( preload: number = 0) {
        let data = {
            preloading: preload,
        }
        return new Promise((resolve, reject) => {
            let isComplete = false;
            AppSdk.I.callAppWithBack(ret => {
            }, 'loadFullScreenVideoAd', 1, JSON.stringify(data))
        })
    }

    async loadNativeExpressAd( x, y, width, height) {
        let scaleX = AppSdk.I.width / Laya.stage.width;
        let scaleY = AppSdk.I.height / Laya.stage.height;
        let data = {
            w: width * scaleX,
            h: height * scaleY,
            left: x * scaleX,
            top: y * scaleY
        }
        AppSdk.I.callAppWithBack(ret => {
        }, 'loadNativeExpressAd', JSON.stringify(data))
    }

    async loadBannerExpressAd() {
        let data = {
            w: AppSdk.I.width,
            h: AppSdk.I.width * 90 / 600,  
        }
        AppSdk.I.callAppWithBack(ret => {
        }, 'loadBannerExpressAd', 2, JSON.stringify(data))
    }

    hideAd() {
        AppSdk.I.callApp('close_adver_dialog');
    }

    async showInteractionExpressAd( preload: number = 0) {
        let data = {
            w: AppSdk.I.width * 0.8,
            h: AppSdk.I.height,
            preloading: preload,
        }
        return new Promise((resolve, reject) => {
            let isComplete = false;
            AppSdk.I.callAppWithBack(ret => {
            }, 'showInteractionExpressAd', JSON.stringify(data))
        })
    }


    

    static get I(): TTAdSdk {
        return ObjectInstance.get(TTAdSdk) as TTAdSdk;
    }
}