import ObjectInstance from "../uitl/ObjectInstance"; import AdManager from "./AdManager"; import RedpacketModel from "./model/RedpacketModel"; import LuckDrawModel from "./LuckDrawModel"; import { AppSdkData } from "./sdkData/AppSdkData"; import { LuckDrawData } from "./sdkData/LuckDrawData"; export default class AppSdk { private _width: number; private _height: number; private _channel: string; private _version: string; private _level: number; private _gameConfig: number; public pangolinId: string; public adnetId: string; public uid: number public isMyBridge: boolean public isHide: boolean static async init() { AppSdk.I.getSystemInfo() AppSdk.I.initGameConfig(); AdManager.I.init();//预加载广告 await ObjectInstance.get(RedpacketModel).init(); LuckDrawModel.I.init(); } initSdk() { return new Promise(async (resolve, reject) => { await this.getUserInfo(); resolve(1) }) } private get myBridge() { if (typeof MyBridge !== 'undefined') { return MyBridge; } else { console.error(' no register myBridge!!!') } } /**获取基本版本信息以及手机的配置 */ getSystemInfo(key: number = 0) { let ret = this.myBridge.getSystemInfo(key); let { w, h, versionName, channel, pangolin, adnet, level } = JSON.parse(ret); [this._width, this._height, this._version, this._channel, this.pangolinId, this.adnetId, this._level] = [w, h, versionName, channel, pangolin, adnet, level]; } private getUserInfo() { return new Promise(async (resolve, reject) => { console.log("-------------getUserInfo回调 前---------------") this.myBridge.getGameUserInfo((ret) => { console.log("-------------getUserInfo回调---------------", ret) let res = JSON.parse(ret); AppSdkData.I.initData(res); resolve(1) }); }) } initGameConfig() { this._gameConfig = this.getGameConfig(); } /** * 震动 * @param key 0 短震动 1 长震动 */ vibrate(key: number = 0) { this.myBridge.openSystemFun(key); } /**隐藏启动屏 */ hideSplash() { this.myBridge.hideSplash(); } /**弹出提现 */ withDrawal() { this.myBridge.withDrawal(); } /**意见反馈 */ feedback() { this.myBridge.feedback(); } /** * key 默认0 ,签到 1 */ personal() { this.myBridge.personal(); } /**邀请好友*/ invitation() { this.myBridge.invitation(); } /**邀请好友*/ openReward() { this.myBridge.openReward(); } /**签到*/ openSignin() { this.myBridge.openSingin(); } putData(key: String, value: String) { this.myBridge.putData(key, value); } /** * @param key 存数据的时候的唯一key * @return 存储的数据 * */ getData(key: String) { let ret = this.myBridge.getData(key); return JSON.parse(ret); } /** * 获取游戏配置 */ public getGameConfig() { let result = this.myBridge.getGameConfig(); console.log("获取游戏配置",JSON.stringify(result)) LuckDrawData.I.initData(JSON.parse(result)['draw']);//转盘数据配置 return JSON.parse(result); } /** * 要求发放金币 * @param key 1红包 */ async addGold(key = 1) { return new Promise(async (resolve, reject) => { await this.myBridge.addGold(key, res => { console.log("要求发放金币",JSON.stringify(res)) res = JSON.parse(res) const { code, data, msg } = res; if ('0' === code || !code) { resolve(data) } else { reject(msg); } }); }) } /** * 要求发放金币 可翻倍类型 */ async rewardInfo() { return new Promise(async (resolve, reject) => { this.myBridge.rewardInfo(res => { res = JSON.parse(res) const { code, data, msg } = res; if ('0' === code || !code) { resolve(data.coin); } else { reject(msg); } }); }) } /** * 获取双倍金币 * @param type 1原金币 2双倍金币 */ async twofoldReward(type: number = 1) { return new Promise(async (resolve, reject) => { this.myBridge.twofoldReward(type, res => { res = JSON.parse(res) const { code, data, msg } = res; if ('0' === code || !code) { resolve(data.coin); } else { reject(msg); } }); }) } /**获取总金币 */ async myCoin() { return new Promise(async (resolve, reject) => { await this.myBridge.myCoin(res => { res = JSON.parse(res) const { code, data, msg } = res; if ('0' === code || !code) { resolve(data['coin']) } else { reject(msg); } }); }) } /**获取当前提现的档位 */ async minWithDrawal() { return new Promise(async (resolve, reject) => { await this.myBridge.minWithDrawal(res => { res = JSON.parse(res) const { code, data, msg } = res; if ('0' === code || !code) { resolve(data['money']) } else { reject(msg); } }); }) } /**上报埋点 */ appDotLog(key: string, value?) { this.myBridge.appDotLog(key, value); } /**热云打点 */ appDotTracKing(key: string) { this.myBridge.appDotTracKing(key); } setCallback(funName: string, pramas?: any) { console.log('---------------setCallback---- this.myBridge---' + JSON.stringify(this.myBridge)) return new Promise((resolve, reject) => { this.myBridge[funName](pramas, res => { let { code, data } = JSON.parse(res); if ('0' === code) { resolve(data); } else { reject(0); } }) }) } closeAdverDialog() { this.myBridge.closeAdverDialog(); } closeAdBanner() { this.myBridge.closeAdBanner(); } /**激励视频 */ showRewardVideoAd(value: IVideo, JBCallback: Function) { this.myBridge.showRewardVideoAd(value, JBCallback) } /** 全屏广告*/ loadFullScreenVideoAd(data: any, JBCallback: Function) { this.myBridge.loadFullScreenVideoAd(data, JBCallback) } /**信息流广告 */ loadNativeExpressAd(data: any, JBCallback: Function) { this.myBridge.loadNativeExpressAd(data, JBCallback) } /**信息流广告- 优量汇 */ loadNativeAdYLH(data: any, JBCallback: Function) { this.myBridge.loadNativeAd(data, JBCallback) } // 打开信息流-优量汇 openLoadNativeAdEvent(){ this.myBridge.openLoadNativeAdEvent() } /**banner */ loadBannerExpressAd(data: any, JBCallback: Function) { this.myBridge.loadBannerExpressAd(data, JBCallback) } /**插屏广告 */ showInteractionExpressAd(data: any, JBCallback: Function) { this.myBridge.showInteractionExpressAd(data, JBCallback) } get level() { return this._level; } get width() { return this._width; } get height() { return this._height; } get version() { return this._version; } get channel() { return this._channel; } protected get bridge() { return null; } get gameConfig() { return this._gameConfig; } static get I(): AppSdk { return ObjectInstance.get(AppSdk); } } // //这里是浏览器环境下, 接收web传过来的消息 window.onMyBridgeReady = () => { AppSdk.I.isMyBridge = true; console.log("onMyBridgeReady load finish, cost:" + (new Date().getTime()) + "ms"); MyBridge.App.onResume = (...ret) => { console.log(' laya onResume', ret) } MyBridge.App.onPause = (...ret) => { console.log(' laya onPause', ret) } } interface IVideo { preloading: number, type: number, }