123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490 |
- import { sys } from 'cc';
- // import { Alert } from '../game/gameUi/Alert';
- import { KS } from './Platform/kuaishouSDK/kuaishou';
- import { Meizu } from './Platform/meizuSDK/meizu';
- import { OPPO } from './Platform/oppoSDK/oppoAdMange';
- import { Toutiao } from './Platform/toutiao/toutiao';
- import { Vivo } from './Platform/vivoSDK/Vivo';
- import { Wechat } from './Platform/wechat/wechat';
- import { EType, IPos, WXCustomAd } from './Platform/wechat/WXCustomAd';
- import { XM } from './Platform/xiaomiSDK/xiaomi';
- import { tyqSDK } from './tyq-sdk';
- // import { JXDef } from '../conventions/JXCommon';
- let adStr = "广告";
- /**渠道 */
- export enum Channel {
- /**默认 浏览器*/
- DEFAULT = 0,
- /**微信 */
- WECHAT = 1,
- /**头条 抖音 */
- TT = 2,
- /**快手 */
- KS = 3,
- /**oppo渠道 */
- OPPO = 4,
- /**vivo渠道 */
- VIVO = 5,
- /**魅族渠道 */
- MEIZU = 6,
- /**小米渠道 */
- XIAOMI = 7,
- ANDROID,
- IOS,
- }
- export interface IUserInfo {
- nickName: string;
- avatar: string;
- sex?: number,
- uid?: string,
- }
- export default class SdkMgr {
- protected static _ins: SdkMgr;
- /**录屏对象 */
- private _mediaRecorder: any = null;
- public static get ins(): SdkMgr {
- if (!this._ins) {
- this._ins = new SdkMgr;
- }
- return this._ins;
- }
- constructor() {
- // if (sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
- // this.channel = Channel.TT;
- // } else if (window.kwaigame) {
- // this.channel = Channel.KS;
- // } else if (sys.platform == sys.Platform.WECHAT_GAME && window.wx) {
- // this.channel = Channel.WECHAT;
- // } else if (sys.isMobile && sys.isBrowser) {
- // this.channel = Channel.DEFAULT;
- // } else if (false) {
- // this.channel = Channel.DEFAULT;
- // }
- if (sys.platform == sys.WECHAT_GAME) {
- this.channel = Channel.WECHAT;
- }
- }
- private channel: Channel = Channel.DEFAULT;
- private _videoRes: string = "";
- public getChannel() {
- return this.channel;
- }
- /**观看广告 */
- public showRewardAd(des: any, callback: Function, cancel?: Function, fail?: Function) {
- let cb = () => {
- // GameMgr.lUserData.doneTask(ETaskType.watchAd);
- // loader.loadRes('Alert', Prefab, (err, prefab: Prefab) => {
- // // if (err) {
- // // console.error(err);
- // // return;
- // // }
- // // let node = instantiate(prefab);
- // // find('Canvas').addChild(node);
- // // node.getComponent(Alert).init("广告观看成功");
- // })
- callback();
- }
- console.log("观看广告", des);
- switch (this.channel) {
- case Channel.DEFAULT: {
- cb();
- break;
- }
- case Channel.TT: {
- Toutiao.showRewardVideoAd("guanggao").then((is) => {
- if (is) {
- console.log("success")
- this.umaSetPoint(adStr, { way: des });
- cb();
- } else if (cancel) {
- cancel();
- }
- }, (res) => {
- // GameMgr.uiMgr.showToast("广告加载失败");
- if (fail) {
- fail();
- }
- })
- break;
- }
- case Channel.WECHAT: {
- Wechat.showRewardVideoAd().then((isSuc) => {
- if (isSuc) {
- console.log("success")
- this.umaSetPoint(adStr, { way: des });
- cb();
- } else if (cancel) {
- cancel();
- // loader.loadRes('Alert', Prefab, (err, prefab: Prefab) => {
- // if (err) {
- // console.error(err);
- // return;
- // }
- // let node = instantiate(prefab);
- // find('Canvas').addChild(node);
- // node.getComponent(Alert).init("取消观看广告");
- // })
- }
- }, (res?) => {
- if (fail) {
- fail();
- }
- // loader.loadRes('Alert', Prefab, (err, prefab: Prefab) => {
- // // if (err) {
- // // console.error(err);
- // // return;
- // // }
- // // let node = instantiate(prefab);
- // // find('Canvas').addChild(node);
- // // node.getComponent(Alert).init("广告加载失败");
- // })
- })
- break;
- }
- case Channel.MEIZU: {
- Meizu.showRewardedVideoAd().then(() => {
- console.log("success")
- this.umaSetPoint(adStr, { way: des });
- cb();
- }, () => {
- console.log("fail")
- })
- break;
- }
- case Channel.OPPO: {
- OPPO.showRewardVideoAd(() => {
- console.log("success")
- this.umaSetPoint(adStr, { way: des });
- cb();
- }, () => {
- console.log("fail")
- })
- break;
- }
- case Channel.VIVO: {
- Vivo.showRewardVideoAd((isSuc) => {
- if (isSuc) {
- this.umaSetPoint(adStr, { way: des });
- console.log("success")
- cb();
- } else {
- console.log("fail")
- }
- })
- break;
- }
- case Channel.XIAOMI: {
- XM.showRewardedVideoAd(() => {
- this.umaSetPoint(adStr, { way: des });
- console.log("success");
- cb();
- }, () => {
- console.log("fail")
- })
- break;
- }
- case Channel.KS: {
- KS.showRewardedVideoAd(() => {
- this.umaSetPoint(adStr, { way: des });
- cb();
- })
- break;
- }
- }
- }
- public umaSetPoint(event: string, obj?: object) {
- return;
- switch (this.channel) {
- case Channel.DEFAULT: {
- break;
- }
- case Channel.TT: {
- tt.uma && tt.uma.trackEvent(event, obj ? obj : null);
- break;
- }
- case Channel.KS: {
- break;
- }
- case Channel.WECHAT: {
- wx.uma && wx.uma.trackEvent(event, obj ? obj : null);
- break;
- }
- }
- }
- public showMoreGamesModal() {
- switch (this.channel) {
- case Channel.TT: {
- Toutiao.showMoreGamesModal();
- break;
- }
- }
- }
- public ttFocusOn() {
- Toutiao.openAwemeUserProfile();
- }
- /**录屏开始 */
- protected startRecoding() {
- }
- /**事件添加开始录屏 */
- public recordStart() {
- console.log("录屏开始*--*");
- if (this.channel == Channel.TT) {
- Toutiao.startRecordScreen(300, this.startRecoding);
- console.log("录屏开始11111", 11111);
- } else if (this.channel == Channel.KS) {
- this._mediaRecorder = kwaigame.createMediaRecorder();
- this._mediaRecorder.start();
- } else if (this.channel == Channel.WECHAT) {
- }
- }
- public puaseRecord() {
- console.log("暂停录屏");
- if (this.channel == Channel.TT) {
- Toutiao.pauseRecordScreen();
- } else if (this.channel == Channel.KS) {
- this._mediaRecorder.pause();
- }
- }
- public resumeRecord() {
- console.log("继续录屏")
- if (this.channel === Channel.TT) {
- Toutiao.resumeRecordScreen()
- } else if (this.channel == Channel.KS) {
- this._mediaRecorder.resume();
- }
- }
- /**事件添加结束录屏 */
- public recordEnd() {
- console.log("录屏结束*--*");
- if (this.channel == Channel.TT) {
- Toutiao.stopRecordScreen((path) => {
- Toutiao.clipVideo(60, path, (res) => {
- this._videoRes = res.videoPath;
- console.log("录屏结束*--*", 11111);
- })
- });
- } else if (this.channel == Channel.KS) {
- this._mediaRecorder.stop();
- }
- }
- /**事件转发 */
- public recordCut(cb: Function) {
- if (this.channel == Channel.TT) {
- console.log("录屏" + this._videoRes);
- Toutiao.shareAppMessage("最强小英雄", this._videoRes, ["最强小英雄", "抖音小游戏", "卡牌回合", "卡牌格斗"]).then(() => {
- console.log('分享视频成功');
- cb();
- this.umaSetPoint("分享视频")
- })
- } else if (this.channel == Channel.KS) {
- this._mediaRecorder.publishVideo({
- });
- } else {
- console.log("假装分享视频成功")
- cb();
- }
- }
- //授权
- public authorize(cb: (userInfo: IUserInfo | null) => void) {
- if (this.channel == Channel.TT) {
- Toutiao.TTLogin(() => {
- Toutiao.toutiaoLogin().then((res: any) => {
- if (res) {
- let userInfo: IUserInfo = {
- nickName: res.name,
- avatar: res.photo,
- }
- cb(userInfo);
- //获取抖音的oppenid
- } else {
- cb(null);
- }
- }).catch((res) => {
- console.log(`toutiaoLogin 调用失败`);
- console.log(res);
- cb(null);
- })
- }, (res) => {
- console.log(res);
- cb(null);
- }, false)
- } else if (this.channel == Channel.KS) {
- KS.KSlogin(() => {
- KS.KSgetUserInfo((res: any) => {
- let userInfo: IUserInfo = {
- nickName: res.userName,
- avatar: res.userHead,
- }
- cb(userInfo);
- })
- })
- } else if (this.channel == Channel.DEFAULT) {
- cb(null);
- } else if (this.channel == Channel.WECHAT) {
- // Wechat.login(() => {
- // Wechat.getUserInfo((res: any) => {
- // let userInfo: IUserInfo = {
- // nickName: res.userInfo.nickName,
- // avatar: res.userInfo.avatarUrl,
- // }
- // cb(userInfo);
- // }, (res) => {
- // console.log(`getUserInfo 调用失败`);
- // console.log(res);
- // cb(null);
- // })
- // }, (res) => {
- // log(res);
- // cb(null);
- // });
- let button = wx.createUserInfoButton({
- type: 'text',
- text: '获取用户信息',
- style: {
- left: 10,
- top: 76,
- width: 200,
- height: 40,
- lineHeight: 40,
- backgroundColor: '#ff0000',
- color: '#ffffff',
- textAlign: 'center',
- fontSize: 16,
- borderRadius: 4
- }
- })
- button.onTap((res) => {
- console.log(res.userInfo.avatarUrl);
- console.log(res.userInfo.nickName);
- })
- } else {
- cb(null);
- }
- }
- public initGame() {
- }
- public loginOut() {
- }
- /**是否显示分享录屏按钮 */
- public isShowRecordBtn() {
- if (this.channel == Channel.TT || this.channel == Channel.KS) {
- return true;
- }
- return false;
- }
- public isWechat() {
- return this.channel == Channel.WECHAT;
- }
- public preLoadAd() {
- if (this.channel == Channel.WECHAT) {
- Wechat.preLoadAd();
- }
- }
- //显示插屏广告
- public showIntersAd(closeCb?: Function) {
- if (this.channel == Channel.VIVO) {
- Vivo.showInterstitialAd();
- } else if (this.channel == Channel.TT) {
- Toutiao.showInterstitialAd();
- } else if (this.channel == Channel.WECHAT) {
- Wechat.showInterstitialAd(closeCb);
- } else if (this.channel == Channel.OPPO) {
- OPPO.showInterstitialAd();
- }
- }
- public showBanner(node) {
- if (this.channel == Channel.TT) {
- Toutiao.showBannerAd();
- } else if (this.channel == Channel.WECHAT) {
- Wechat.showBannerAd(4000);
- } else if (this.channel == Channel.VIVO) {
- Vivo.showBannerAd();
- } else if (this.channel == Channel.OPPO) {
- OPPO.showBannerAd();
- }
- }
- public showBannerTurns(time) {
- if (this.channel == Channel.WECHAT) {
- Wechat.showBannerTurns(time);
- }
- }
- public hideBanner() {
- if (this.channel == Channel.TT) {
- Toutiao.hideBannerAd();
- } else if (this.channel == Channel.VIVO) {
- Vivo.hideBannerAd();
- } else if (this.channel == Channel.OPPO) {
- OPPO.hideBannerAd();
- } else if (this.channel == Channel.WECHAT) {
- Wechat.hideBannerAd();
- }
- }
- public showWxCustomAd(flag, type: EType, pos: IPos, extraId?, cb?: Function) {
- if (this.channel == Channel.WECHAT) {
- WXCustomAd.createCustomAd(flag, type, pos, extraId, cb);
- }
- }
- public hideWxCustomAd(flag) {
- if (this.channel == Channel.WECHAT) {
- WXCustomAd.hideCustomAd(flag);
- }
- }
- public hideAllWxCustom() {
- if (this.channel == Channel.WECHAT) {
- WXCustomAd.hideAllAd();
- }
- }
- /**跳转小游戏 */
- jumpGame(appid: string, event, id) {
- // if (cc.sys.platform != cc.sys.WECHAT_GAME) return
- Wechat.navigateToMiniProgram(appid, "", () => {
- console.log("成功跳转");
- tyqSDK.collectClickEventGame(event, id);
- }, () => {
- console.log("跳转失败");
- //好友在玩界面
- })
- }
- }
|