123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792 |
- import { _decorator, error, SpriteFrame, sys } from "cc";
- import { config } from "./config";
- import { uiManager } from "./manager/uiManager";
- import { userInfo } from "./data";
- //管理广告、分享、SDK相关内容的组件
- export class SdkUtil {
- public static platform: string = 'cocos'; //平台
- public static imgAd: SpriteFrame = null!;
- public static imgShare: SpriteFrame = null!;
- public static isDebugMode: boolean = false;
- public static onlineInterval: number = -1;
- public static isEnableVibrate: boolean = true;
- public static isCheckOffline: boolean = false; //登录后会检查是否展示登录界面,而且只检查一次
- public static isWatchVideoAd: boolean = false;//是否正在播放广告
- public static isEnableMoving: boolean = false;//是否允许屏幕上下移动
- public static isEnableZoom: boolean = false;//是否允许屏幕缩放
- public static arrLockDiary = [];//未解锁日记
- public static vibrateInterval: number = 100;//两次震动之间的间隔,AppActivity里面的震动间隔也是100
- public static vibratePreTime: number = 0;//上次震动时间
- public static KS_GAME:boolean = false; //是否ks游戏
- public static videoAd:any =null;
- public static isLookAd:boolean = false; //是否在看广告
- public static tt_systemInfo: any = null; //抖音_系统信息
- private static tt_isSupportSidebar:boolean = false; //抖音_是否支持侧边栏
- private static tt_isToEnterFromSidebar:boolean = false; //抖音_是否从侧边栏进入
- private static tt_gameRecorder:any = null; //抖音游戏录制
- private static tt_recordVideoPath:string = ''; //抖音录制视频路径
- private static tt_totalRecord:number = 4000; //抖音总录制时间
- private static tt_isRecording:boolean = false; //抖音是否录制中
- //------------------------------ 公共 ------------------------------//
- public static init() {
- if(sys.platform==sys.Platform.WECHAT_GAME) {
- let isKSGame = typeof KSGameGlobal != 'undefined'
- // console.log('isKSGame=',isKSGame)
- SdkUtil.KS_GAME = isKSGame
- }
- this.ttGetSystemInfo(()=> {
- this.ttRegisterInfo()
- })
- }
- // 自定义事件统计
- public static customEventStatistics(eventType: string, objParams?: any) {
- eventType = eventType.toString();
- if (!objParams) { objParams = {}; }
- // console.log({'eventType': eventType},{'objParams': objParams});
- if (this.platform === 'wx') {
- //@ts-ignore
- if (window['wx'] && window['wx']['aldSendEvent']) {
- //@ts-ignore
- window.wx['aldSendEvent'](eventType, objParams);
- }
- }
- //@ts-ignore
- if (this.platform === 'cocos' && window.cocosAnalytics && window.cocosAnalytics.isInited()) {
- console.log("###统计", eventType, objParams);
- //@ts-ignore
- window.cocosAnalytics.CACustomEvent.onStarted(eventType, objParams);
- }
- }
- // 检测授权用户信息
- public static checkAuthUserInfo(cb) {
- if(sys.platform == sys.Platform.WECHAT_GAME && !SdkUtil.KS_GAME) {
- SdkUtil.wxCheckAuthUserInfo(cb)
- } else {
- cb(true)
- }
- }
-
- // 登录
- public static login(call){
- if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
- tt.login({
- force: true,
- success(res) {
- console.log(`tt_login 调用成功:${res.code} ${res.anonymousCode}`);
- call({"code":res.code,"anonymousCode":res.anonymousCode})
- },
- fail(err) {
- console.log(`tt_login 调用失败:${err}`);
- // call(null)
- },
- });
- }
- else if(sys.platform == sys.Platform.WECHAT_GAME) {
- if(SdkUtil.KS_GAME) {
- ks.login({
- success(res) {
- console.log(`ks_login 调用成功:${res.code}`);
- call({"code":res.code})
- },
- fali(err) {
- console.log(`ks_login 调用失败:${err}`);
- // call(null)
- }
- })
- } else {
- wx.login({
- success(res) {
- console.log(`wx_login 调用成功:${res.code}`);
- call({"code":res.code})
- },
- fali(err) {
- console.log(`wx_login 调用失败:${err}`);
- // call(null)
- }
- })
- }
- }
- else{
- call(null)
- }
- }
- // 获取用户信息
- public static getUserInfo(call){
- if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
- tt.getUserInfo({
- // withCredentials: true,
- // withRealNameAuthenticationInfo: true,
- success(res) {
- console.log(`tt_getUserInfo 调用成功`, res);
- call(res.userInfo)
- },
- fail(err) {
- console.log(`tt_getUserInfo 调用失败`, err);
- call(new userInfo())
- },
- });
- }
- else if(sys.platform == sys.Platform.WECHAT_GAME) {
- if(SdkUtil.KS_GAME) {
- ks.getUserInfo({
- success(res) {
- console.log(`ks_getUserInfo 调用成功`, res);
- call(res.userInfo)
- },
- fail(err) {
- console.log(`ks_getUserInfo 调用失败`, err);
- },
- })
- } else {
- SdkUtil.wxCheckAuthUserInfo((is_true)=>{
- if(is_true) {
- wx.getUserInfo({
- success(res) {
- console.log(`wx_getUserInfo 调用成功`, res);
- call(res.userInfo)
- },
- fail(err) {
- console.log(`wx_getUserInfo 调用失败`, err);
- },
- })
- }
- })
- }
- }
- else{
- call(null)
- }
- }
- // 震动
- public static vibrateShort(){
- if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
- tt.vibrateShort({ success(res) {}, fail(err) {} });
- }
- else if(sys.platform == sys.Platform.WECHAT_GAME) {
- if(SdkUtil.KS_GAME) {
- ks.vibrateShort({ success(res) {}, fail(err) {} });
- } else {
- wx.vibrateShort({ success(res) {}, fail(err) {} });
- }
- }
-
- }
- // 关于loading
- public static showLoading(title:string) {
- if(title.length<=0) { return }
- if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
- tt.showLoading({ title: title, success(res) {},fail(err) {} })
- }
- else if(sys.platform == sys.Platform.WECHAT_GAME) {
- if(SdkUtil.KS_GAME) {
- ks.showLoading({ title: title, success(res) {},fail(err) {} })
- } else {
- wx.showLoading({ title: title, success(res) {},fail(err) {} })
- }
- }
- }
- public static hideLoading() {
- if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
- tt.hideLoading({ success(res) { }, fail(err) { } });
- }
- else if(sys.platform == sys.Platform.WECHAT_GAME) {
- if(SdkUtil.KS_GAME) {
- ks.hideLoading({ success(res) { }, fail(err) { } });
- } else {
- wx.hideLoading({ success(res) { }, fail(err) { } });
- }
- }
- }
- // 展示toast
- public static showToast(title:string,duration=2000,success_cb=null, fail_cb=null) {
- if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
- tt.showToast({
- title: title,
- duration: duration,
- success(res) { if(success_cb){ success_cb() } },
- fail(err) { if(fail_cb) { fail_cb() } },
- });
- }
- else if(sys.platform == sys.Platform.WECHAT_GAME) {
- if(SdkUtil.KS_GAME) {
- ks.showToast({
- title: title,
- duration: duration,
- success(res) { if(success_cb){ success_cb() } },
- fail(err) { if(fail_cb) { fail_cb() } },
- });
- } else {
- wx.showToast({
- title: title,
- duration: duration,
- success(res) { if(success_cb){ success_cb() } },
- fail(err) { if(fail_cb) { fail_cb() } },
- });
- }
- }
- }
- // 展示modal (确定:res.confirm 取消:res.cancel)
- public static showModal(title:string, content:string, suc_cb=null, fail_cb=null, confirmText:string='确定', showCancel:boolean=true, cancelText:string='取消') {
- if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
- tt.showModal({
- title: title,
- content: content,
- confirmText: confirmText,
- showCancel: showCancel,
- cancelText: cancelText,
- success(res) { if(suc_cb) { suc_cb(res) } },
- fail(err) { if(fail_cb){ fail_cb(err) } },
- });
- }
- else if(sys.platform == sys.Platform.WECHAT_GAME) {
- if(SdkUtil.KS_GAME) {
- ks.showModal({
- title: title,
- content: content,
- confirmText: confirmText,
- showCancel: showCancel,
- cancelText: cancelText,
- success(res) { if(suc_cb) { suc_cb(res) } },
- fail(err) { if(fail_cb){ fail_cb(err) } },
- });
- } else {
- wx.showModal({
- title: title,
- content: content,
- confirmText: confirmText,
- showCancel: showCancel,
- cancelText: cancelText,
- success(res) { if(suc_cb) { suc_cb(res) } },
- fail(err) { if(fail_cb){ fail_cb(err) } },
- });
- }
- } else {
- if(suc_cb) {
- suc_cb({'confirm':true})
- }
- }
- }
-
- // 展示actionSheet (点击的索引:`res.tapIndex`)
- public static showActionSheet(item_list:string[], suc_cb=null, fail_cb=null) {
- if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
- tt.showActionSheet({
- item_list,
- success(res) { if(suc_cb) { suc_cb(res) } },
- fail(err) { if(fail_cb) { fail_cb(err) } },
- });
- }
- else if(sys.platform == sys.Platform.WECHAT_GAME) {
- if(SdkUtil.KS_GAME) {
- ks.showActionSheet({
- item_list,
- success(res) { if(suc_cb) { suc_cb(res) } },
- fail(err) { if(fail_cb) { fail_cb(err) } },
- });
- } else {
- wx.showActionSheet({
- item_list,
- success(res) { if(suc_cb) { suc_cb(res) } },
- fail(err) { if(fail_cb) { fail_cb(err) } },
- });
- }
- }
- }
- // 选择系统相册
- public static choosSystemImage(call_back) {
- if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
- tt.chooseImage({
- sourceType: ["album"],
- count:1,
- success:(res)=>{
- // console.log('chooseImage调用成功=${res}')
- if(res.tempFilePaths.length>0) { call_back(res.tempFilePaths[0])}
- },
- fail(err) { console.log(`tt_chooseImage调用失败=${err}`); },
- })
- }
- else if(sys.platform == sys.Platform.WECHAT_GAME) {
- if(SdkUtil.KS_GAME) {
- ks.chooseMedia({
- mediaType: ["image"],
- sourceType: ["album"],
- count:1,
- success:(res)=>{
- // console.log('chooseImage调用成功=${res}')
- if(res.tempFilePaths.length>0) { call_back(res.tempFilePaths[0])}
- },
- fail(err) { console.log(`wx_chooseImage调用失败=${err}`); },
- })
- } else {
- wx.chooseMedia({
- mediaType: ["image"],
- sourceType: ["album"],
- count:1,
- success:(res)=>{
- // console.log('chooseImage调用成功=${res}')
- if(res.tempFilePaths.length>0) { call_back(res.tempFilePaths[0])}
- },
- fail(err) { console.log(`wx_chooseImage调用失败=${err}`); },
- })
- }
- }
- }
- // 检测显示添加桌面
- public static checkIsShowAddDesktop():boolean {
- if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
- if(SdkUtil.tt_systemInfo.appName=='Douyin' || SdkUtil.tt_systemInfo.appName=='douyin_lite') {
- return true
- }
- }
- return false
- }
- // 分享游戏
- public static shareGame(title: string, desc:string, call_back=null) {
- if(desc==undefined||desc==null) { desc = config.gameName}
- if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
- SdkUtil.ttShare(title,desc, ()=>{
- call_back(true)
- }, ()=>{
- this.showToast('分享失败')
- })
- } else if(sys.platform == sys.Platform.WECHAT_GAME) {
- if(SdkUtil.KS_GAME) {
- SdkUtil.ksShare(desc, '', ()=>{
- call_back(true)
- }, ()=>{
- this.showToast('分享失败')
- })
- } else {
- SdkUtil.wxShare(desc, '', ()=>{
- call_back(true)
- },()=>{
- this.showToast('分享失败')
- })
- }
- }else{
- call_back && call_back(true)
- }
- }
- public static shareGameVideo() {
- if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
- let videoPath = SdkUtil.ttGetScreenRecordingVideoPath()
- uiManager.Instance().showLoading()
- this.ttShareScreenRecordVideo(config.gameName,videoPath,()=>{
- uiManager.Instance().hideLoading()
- }, ()=>{
- uiManager.Instance().hideLoading()
- })
- }
- }
- // 获取广告id
- public static getAdId(ad_type = config.ADS_TYPE.UNKNOWN):string {
- let ad_id = ""
- if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
- if(ad_type==config.ADS_TYPE.GAME_INFINITE_DEGREE_VIDEO) {
- ad_id = config.TT_CONFIG.ADS_ID_INFINITE_DEGREE_VIDEO
- } else if(ad_type==config.ADS_TYPE.GAME_RELIFE_VIDEO) {
- ad_id = config.TT_CONFIG.ADS_ID_RELIFE_VIDEO
- } else if(ad_type==config.ADS_TYPE.GAME_RESTART) {
- ad_id = config.TT_CONFIG.ADS_ID_RESTART
- } else if(ad_type==config.ADS_TYPE.GAME_SIGN_DOUBLE) {
- ad_id = config.TT_CONFIG.ADS_ID_SIGN_DOUBLE
- } else if(ad_type==config.ADS_TYPE.GAME_SIGN_BUQIAN) {
- ad_id = config.TT_CONFIG.ADS_ID_SIGN_BUQIAN
- } else if(ad_type==config.ADS_TYPE.GAME_GET_SUIPIAN) {
- ad_id = config.TT_CONFIG.ADS_ID_GET_SUIPIAN
- }
- } else if (sys.platform == sys.Platform.WECHAT_GAME) {
- if(SdkUtil.KS_GAME) {
- if(ad_type==config.ADS_TYPE.GAME_INFINITE_DEGREE_VIDEO) {
- ad_id = config.KS_CONFIG.ADS_ID_INFINITE_DEGREE_VIDEO
- } else if(ad_type==config.ADS_TYPE.GAME_RELIFE_VIDEO) {
- ad_id = config.KS_CONFIG.ADS_ID_RELIFE_VIDEO
- } else if(ad_type==config.ADS_TYPE.GAME_RESTART) {
- ad_id = config.KS_CONFIG.ADS_ID_RESTART
- } else if(ad_type==config.ADS_TYPE.GAME_SIGN_DOUBLE) {
- ad_id = config.KS_CONFIG.ADS_ID_SIGN_DOUBLE
- } else if(ad_type==config.ADS_TYPE.GAME_SIGN_BUQIAN) {
- ad_id = config.KS_CONFIG.ADS_ID_SIGN_BUQIAN
- } else if(ad_type==config.ADS_TYPE.GAME_GET_SUIPIAN) {
- ad_id = config.KS_CONFIG.ADS_ID_GET_SUIPIAN
- }
- } else {
- if(ad_type==config.ADS_TYPE.GAME_INFINITE_DEGREE_VIDEO) {
- ad_id = config.WX_CONFIG.ADS_ID_INFINITE_DEGREE_VIDEO
- } else if(ad_type==config.ADS_TYPE.GAME_RELIFE_VIDEO) {
- ad_id = config.WX_CONFIG.ADS_ID_RELIFE_VIDEO
- } else if(ad_type==config.ADS_TYPE.GAME_RESTART) {
- ad_id = config.WX_CONFIG.ADS_ID_RESTART
- } else if(ad_type==config.ADS_TYPE.GAME_SIGN_DOUBLE) {
- ad_id = config.WX_CONFIG.ADS_ID_SIGN_DOUBLE
- } else if(ad_type==config.ADS_TYPE.GAME_SIGN_BUQIAN) {
- ad_id = config.WX_CONFIG.ADS_ID_SIGN_BUQIAN
- } else if(ad_type==config.ADS_TYPE.GAME_GET_SUIPIAN) {
- ad_id = config.WX_CONFIG.ADS_ID_GET_SUIPIAN
- }
- }
- }
- return ad_id
- }
-
- // 显示激励视频广告
- public static showVideoAd(_adUnitId: string, call_back) {
- if(sys.platform==sys.Platform.BYTEDANCE_MINI_GAME) {
- uiManager.Instance().showLoading()
- SdkUtil.videoAd = tt.createRewardedVideoAd({adUnitId: _adUnitId});
- }
- else if(sys.platform==sys.Platform.WECHAT_GAME) {
- call_back && ({"isEnded":true})
- return
- // if(SdkUtil.KS_GAME) {
- // uiManager.Instance().showLoading()
- // SdkUtil.videoAd = ks.createRewardedVideoAd({adUnitId: _adUnitId});
- // }
- // else {
- // console.log('wx ad')
- // call_back({"isEnded":true})
- // // gameManager.Singleton.showLoadingLevel()
- // // SdkUtil.videoAd = wx.createRewardedVideoAd({adUnitId: _adUnitId});
- // return
- // }
- }
- else {
- call_back && call_back({"isEnded":true})
- return
- }
- if(SdkUtil.videoAd==null){
- uiManager.Instance().hideLoading()
- return
- }
- if(SdkUtil.KS_GAME) {
- SdkUtil.videoAd.show().then(()=>{
- console.log("ks 广告加载完成");
- SdkUtil.isLookAd = true
- })
- }
- SdkUtil.videoAd.onLoad(() => {
- console.log("广告加载完成");
- SdkUtil.isLookAd = true
- SdkUtil.videoAd.show();
- });
- SdkUtil.videoAd.onClose((res) => {
- console.log('广告关闭=',res)
- uiManager.Instance().hideLoading()
- SdkUtil.isLookAd = false
- SdkUtil.videoAd.destroy()
- call_back && call_back(res)
- });
- SdkUtil.videoAd.onError((res) => {
- console.log('广告加载失败=',res)
- uiManager.Instance().hideLoading()
- let errorString = res.errCode + '-' + res.errMsg
- call_back && call_back({isEnded:false,errorString:errorString})
- SdkUtil.isLookAd = false
- SdkUtil.videoAd.destroy()
- });
- if(sys.platform==sys.Platform.BYTEDANCE_MINI_GAME) {
- SdkUtil.videoAd.load()
- }
- }
- //------------------------------ 微信相关 ------------------------------//
- // 微信检查授权用户信息
- public static wxCheckAuthUserInfo(cb) {
- wx.getSetting({
- success(res) {
- if(res.authSetting['scope.userInfo'] === true) { // 已经授权
- cb(true)
- } else {
- cb(false)
- }
- },
- fail(err) {
- cb(false)
- }
- })
- }
- // 微信分享
- public static wxShare(title: string, imageUrl: string='', success_cb, fail_cb) {
- // console.log('wx分享=',title, 'imageUrl=',imageUrl)
- wx.showShareMenu({
- withShareTicket: true,
- // shareAppMessage(可以删除):显示分享给好友选项,shareTimeline(可以删除):显示分享至朋友圈选项
- // 可以只开启前者。如果要开启后者,则两者必须都开启才能生效。
- // menus: ['shareAppMessage', 'shareTimeline'],
- menus: ['shareAppMessage'],
- success:()=>{
- success_cb && success_cb()
- },
- fail:()=>{
- fail_cb && fail_cb()
- },
- });
- // 主动分享
- wx.shareAppMessage({
- title: title,
- imageUrl: imageUrl
- });
- }
- //------------------------------ 快手相关 ------------------------------//
- // 快手分享
- public static ksShare(title: string, imageUrl:string='', success_cb = null, fail_cb = null) {
- // console.log('ks分享=',title, 'imageUrl=',imageUrl)
- ks.shareAppMessage({
- success:(res)=>{ if(success_cb){ success_cb(res) } },
- fail:(err)=>{ if(fail_cb){ fail_cb(err) }}
- });
- }
- //------------------------------ 抖音相关 ------------------------------//
- // 抖音获取系统信息
- public static ttGetSystemInfo(callback) {
- if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
- tt.getSystemInfo({
- success:(res) => {
- // console.log('tt.getSystemInfo=',res)
- // appName: "Douyin" appName: "douyin_lite"
- SdkUtil.tt_systemInfo = res
- callback()
- }
- })
- }
- }
- // 分享
- public static ttShare(title:string, desc:string, sucess_cb=null, fail_cb=null) {
- if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
- tt.shareAppMessage({
- title: title,
- desc: desc,
- success() {
- console.log("分享成功")
- // this.showToast('分享成功')
- if(sucess_cb) { sucess_cb() }
- },
- fail(e) {
- console.log("分享失败",e)
- if(fail_cb) { fail_cb() }
- },
- });
- }
- }
- // 抖音添加快捷键(目前仅支持:抖音(Douyin) 和 抖音极速版(douyin_lite))
- public static ttAddShortcut(onSuccess:Function = null, onFail:Function = null) {
- if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
- if(SdkUtil.tt_systemInfo.appName=='Douyin'||SdkUtil.tt_systemInfo.appName=='douyin_lite') {
- if(SdkUtil.tt_systemInfo.brand=='Apple') {
- tt.addShortcut({
- success() {
- console.log("添加桌面成功");
- onSuccess && onSuccess(null)
- },
- fail(err) {
- console.log("添加桌面失败", err.errMsg);
- onFail && onFail(err)
- },
- });
- } else if(SdkUtil.tt_systemInfo.brand=='Android') {
- // 检测只支持安卓
- tt.checkShortcut({
- success(res) {
- console.log("检查快捷方式", res.status);
- if(res.status.exist==false||res.status.needUpdate==true) {
- tt.addShortcut({
- success() {
- console.log("添加桌面成功");
- onSuccess && onSuccess(null)
- },
- fail(err) {
- console.log("添加桌面失败", err.errMsg);
- onFail && onFail(err)
- },
- });
- }
- },
- fail(err) {
- console.log("检查快捷方式失败", err.errMsg);
- onFail && onFail(err)
- },
- });
- }
- }
- }
- }
- // 抖音注册信息
- public static ttRegisterInfo() {
- if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
- tt.onShow((res) => {
- console.log('tt.onShow =', res)
- // console.log('res=',res)
- if(res.scene == '021036' || res.scene == '101036') {
- SdkUtil.tt_isToEnterFromSidebar = true
- }
- if(res.scene.launch_from == 'homepage' && res.scene.location == 'sidebar_card') {
- SdkUtil.tt_isToEnterFromSidebar = true
- }
- });
- tt.onHide(()=>{
- console.log('tt.onHide')
- if(SdkUtil.isLookAd==false) {
- // statisticsManager.uploadRecordUserLevel(false)
- }
- })
-
- tt.checkScene({
- scene: "sidebar",
- success: (res) => {
- console.log("check scene success: ", res.isExist);
- if(res.isExist != undefined || res.isExist != null) {
- SdkUtil.tt_isSupportSidebar = res.isExist
- }
- },
- fail: (res) => {
- console.log("check scene fail:", res);
- }
- });
- let options = tt.getLaunchOptionsSync()
- console.log('getLaunchOptionsSync=', options)
- if(options.scene == '021036' || options.scene == '101036') {
- SdkUtil.tt_isToEnterFromSidebar = true
- }
- }
- }
- // 抖音检测是否显示奖励
- public static ttCheckSceneShowRewards():boolean {
- return SdkUtil.tt_isSupportSidebar
- }
- // 抖音检测是否从侧边栏进入
- public static ttCheckToEnterFromSidebar():boolean {
- return SdkUtil.tt_isToEnterFromSidebar
- }
- // 抖音导航到侧边栏场景
- public static ttNavToSidebarScene() {
- if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
- tt.navigateToScene({
- scene: "sidebar",
- success: (res) => {
- // console.log("navigate to scene success");
- },
- fail: (res) => {
- // console.log("navigate to scene fail: ", res);
- },
- });
- }
- }
- // 抖音开启屏幕录制
- public static ttStartScreenRecording() {
- if(sys.platform!=sys.Platform.BYTEDANCE_MINI_GAME) {
- return
- }
- if(this.tt_systemInfo.platform == 'devtools') {
- console.log('抖音模拟器')
- return
- }
- if(this.tt_isRecording==true) {
- this.ttStopScreenRecording()
- }
-
- if(!this.tt_gameRecorder) {
- this.tt_gameRecorder = tt.getGameRecorderManager()
- }
- this.tt_gameRecorder.start({duration: this.tt_totalRecord})
- this.tt_gameRecorder.onStart(()=> {
- this.tt_isRecording = true
- // console.log('GameRecorder onStart onStart onStart')
- })
- this.tt_gameRecorder.onStop((res)=> {
- // console.log('GameRecorder onStop onStop onStop=',res)
- this.tt_isRecording = false
- this.tt_recordVideoPath = res.videoPath
- })
- this.tt_gameRecorder.onError((e)=> {
- console.log('ttGameRecord error:',e)
- })
-
- }
- // 抖音关闭屏幕录制
- public static ttStopScreenRecording(isClearVideoPath:boolean = false) {
- if(sys.platform!=sys.Platform.BYTEDANCE_MINI_GAME) {
- return
- }
- if(this.tt_gameRecorder == null) {
- return
- }
- if(isClearVideoPath) {
- this.tt_recordVideoPath = "";
- }
-
- this.tt_gameRecorder.stop()
- }
- // 抖音获取屏幕录制视频文件
- public static ttGetScreenRecordingVideoPath():string {
- return this.tt_recordVideoPath;
- }
- // 抖音分享屏幕录制视频
- private static ttShareScreenRecordVideo(title: string, videoPath: string, onSuccess: Function = null, onFail: Function = null) {
- console.log('tt_录制视频路径=',videoPath)
- if(videoPath.length<=0) {
- return
- }
- tt.shareAppMessage({
- title: title,
- templateId: config.TT_CONFIG.SHARE_RECORD_VIDEO_ID,
- channel: "video",
- extra: {
- videoTopics: [config.gameName],
- hashtag_list: ['小游戏','小程序'],
- videoPath: videoPath,
- withVideoId: true,
- },
- success: (res) => {
- console.log('抖音分享屏幕录制视频,成功=',res)
- onSuccess && onSuccess();
- },
- fail: (e) => {
- // 当前今日头条ios无法获得分享成功回调 if(res.platform === 'ios' && res.appName === 'Toutiao')
- console.log('抖音分享屏幕录制视频,失败=',e)
- onFail && onFail()
- }
- })
- }
- }
|