|
@@ -1,5 +1,6 @@
|
|
|
import { _decorator, SpriteFrame, sys } from "cc";
|
|
|
import { gameManager } from "./run/gameManager";
|
|
|
+import { config } from "./config";
|
|
|
//管理广告、分享、SDK相关内容的组件
|
|
|
export class SdkUtil {
|
|
|
public static platform: string = 'cocos'; //平台
|
|
@@ -22,10 +23,10 @@ export class SdkUtil {
|
|
|
public static tt_isSupportSidebar:boolean = false; //抖音_是否支持侧边栏
|
|
|
public static tt_isToEnterFromSidebar:boolean = false; //抖音_是否从侧边栏进入
|
|
|
|
|
|
- private static ttGameRecorder:any = null; //抖音游戏录制
|
|
|
- private static ttRecordVideoPath:string = ''; //抖音录制视频路径
|
|
|
- private static ttTotalRecord:number = 300; //抖音总录制时间
|
|
|
- private static ttIsRecording:boolean = false; //抖音是否录制中
|
|
|
+ private static tt_gameRecorder:any = null; //抖音游戏录制
|
|
|
+ private static tt_recordVideoPath:string = ''; //抖音录制视频路径
|
|
|
+ private static tt_totalRecord:number = 300; //抖音总录制时间
|
|
|
+ private static tt_isRecording:boolean = false; //抖音是否录制中
|
|
|
|
|
|
/**
|
|
|
* 自定义事件统计
|
|
@@ -59,50 +60,58 @@ export class SdkUtil {
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 微信分享
|
|
|
+ * 抖音/微信分享
|
|
|
*
|
|
|
* @static
|
|
|
* @param {string} title
|
|
|
* @param {string} imageUrl
|
|
|
+ * @param {string} videoPath
|
|
|
* @returns
|
|
|
* @memberof SdkUtil
|
|
|
*/
|
|
|
- public static shareGame(title: string, imageUrl: string) {
|
|
|
- //@ts-ignore
|
|
|
- if (!window.wx) {
|
|
|
- return;
|
|
|
+ public static shareGame(title: string, imageUrl: string, videoPath: string) {
|
|
|
+ if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
|
|
|
+ if(videoPath!="") {
|
|
|
+ this.ttShareScreenRecordVideo(title,videoPath)
|
|
|
+ }
|
|
|
+ } else if(sys.platform == sys.Platform.WECHAT_GAME) {
|
|
|
+ // 微信分享
|
|
|
}
|
|
|
+ // //@ts-ignore
|
|
|
+ // if (!window.wx) {
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
|
|
|
- //@ts-ignore
|
|
|
- wx.showShareMenu({
|
|
|
- withShareTicket: true,
|
|
|
- complete: () => {
|
|
|
+ // //@ts-ignore
|
|
|
+ // wx.showShareMenu({
|
|
|
+ // withShareTicket: true,
|
|
|
+ // complete: () => {
|
|
|
|
|
|
- }
|
|
|
- });
|
|
|
+ // }
|
|
|
+ // });
|
|
|
|
|
|
- //@ts-ignore
|
|
|
- if (wx.aldOnShareAppMessage) {
|
|
|
- //@ts-ignore
|
|
|
- wx.aldOnShareAppMessage(function () {
|
|
|
- // 用户点击了“转发”按钮
|
|
|
- return {
|
|
|
- title: title,
|
|
|
- imageUrl: imageUrl,
|
|
|
+ // //@ts-ignore
|
|
|
+ // if (wx.aldOnShareAppMessage) {
|
|
|
+ // //@ts-ignore
|
|
|
+ // wx.aldOnShareAppMessage(function () {
|
|
|
+ // // 用户点击了“转发”按钮
|
|
|
+ // return {
|
|
|
+ // title: title,
|
|
|
+ // imageUrl: imageUrl,
|
|
|
|
|
|
- };
|
|
|
- });
|
|
|
- } else {
|
|
|
- //@ts-ignore
|
|
|
- wx.onShareAppMessage(function () {
|
|
|
- // 用户点击了“转发”按钮
|
|
|
- return {
|
|
|
- title: title,
|
|
|
- imageUrl: imageUrl,
|
|
|
+ // };
|
|
|
+ // });
|
|
|
+ // } else {
|
|
|
+ // //@ts-ignore
|
|
|
+ // wx.onShareAppMessage(function () {
|
|
|
+ // // 用户点击了“转发”按钮
|
|
|
+ // return {
|
|
|
+ // title: title,
|
|
|
+ // imageUrl: imageUrl,
|
|
|
|
|
|
- };
|
|
|
- });
|
|
|
- }
|
|
|
+ // };
|
|
|
+ // });
|
|
|
+ // }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -221,7 +230,6 @@ export class SdkUtil {
|
|
|
|
|
|
// 抖音开启屏幕录制
|
|
|
public static ttStartScreenRecording() {
|
|
|
- return
|
|
|
if(sys.platform!=sys.Platform.BYTEDANCE_MINI_GAME) {
|
|
|
return
|
|
|
}
|
|
@@ -230,57 +238,60 @@ export class SdkUtil {
|
|
|
this.ttStopScreenRecording()
|
|
|
}
|
|
|
|
|
|
- this.ttIsRecording = true
|
|
|
- if(!this.ttGameRecorder) {
|
|
|
- this.ttGameRecorder = tt.getGameRecorderManager()
|
|
|
+ if(!this.tt_gameRecorder) {
|
|
|
+ this.tt_gameRecorder = tt.getGameRecorderManager()
|
|
|
}
|
|
|
- this.ttGameRecorder.start({duration: this.ttTotalRecord})
|
|
|
- this.ttGameRecorder.onStart(()=> {
|
|
|
+ this.tt_gameRecorder.start({duration: this.tt_totalRecord})
|
|
|
+ this.tt_gameRecorder.onStart(()=> {
|
|
|
+ this.tt_isRecording = true
|
|
|
console.log('GameRecorder onStart onStart onStart')
|
|
|
})
|
|
|
- this.ttGameRecorder.onStop((res)=> {
|
|
|
+ this.tt_gameRecorder.onStop((res)=> {
|
|
|
console.log('GameRecorder onStop onStop onStop=',res)
|
|
|
- this.ttIsRecording = false
|
|
|
- this.ttRecordVideoPath = res.videoPath
|
|
|
- SdkUtil.ttShareScreenRecordVideo('测试测试',res.videoPath)
|
|
|
+ this.tt_isRecording = false
|
|
|
+ this.tt_recordVideoPath = res.videoPath
|
|
|
})
|
|
|
- this.ttGameRecorder.onError((e)=> {
|
|
|
+ this.tt_gameRecorder.onError((e)=> {
|
|
|
console.log('ttGameRecord error:',e)
|
|
|
})
|
|
|
}
|
|
|
|
|
|
// 抖音关闭屏幕录制
|
|
|
- public static ttStopScreenRecording() {
|
|
|
- return
|
|
|
+ public static ttStopScreenRecording(isClearVideoPath:boolean = false) {
|
|
|
if(sys.platform!=sys.Platform.BYTEDANCE_MINI_GAME) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if(this.ttGameRecorder == null) {
|
|
|
+ if(this.tt_gameRecorder == null) {
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+ if(isClearVideoPath) {
|
|
|
+ this.tt_recordVideoPath = "";
|
|
|
+ }
|
|
|
|
|
|
- this.ttGameRecorder.stop()
|
|
|
+ this.tt_gameRecorder.stop()
|
|
|
}
|
|
|
|
|
|
// 抖音是否屏幕录制
|
|
|
public static ttIsScreenRecording():boolean {
|
|
|
- return this.ttIsRecording;
|
|
|
+ return this.tt_isRecording;
|
|
|
}
|
|
|
|
|
|
// 抖音获取屏幕录制视频文件
|
|
|
public static ttGetScreenRecordingVideoPath():string {
|
|
|
- return this.ttRecordVideoPath;
|
|
|
+ return this.tt_recordVideoPath;
|
|
|
}
|
|
|
|
|
|
// 抖音分享屏幕录制视频
|
|
|
- public static ttShareScreenRecordVideo(title: string, videoPath: string, onSuccess: Function = null, onFail: Function = null) {
|
|
|
+ private static ttShareScreenRecordVideo(title: string, videoPath: string, onSuccess: Function = null, onFail: Function = null) {
|
|
|
tt.shareAppMessage({
|
|
|
title: title,
|
|
|
+ templateId: config.TT_SHARE_TEMPLATEID,
|
|
|
channel: "video",
|
|
|
extra: {
|
|
|
- videoTopics: [],
|
|
|
- hashtag_list: [],
|
|
|
+ videoTopics: [config.gameName],
|
|
|
+ hashtag_list: ['小游戏','小程序'],
|
|
|
videoPath: videoPath,
|
|
|
withVideoId: true,
|
|
|
},
|
|
@@ -289,13 +300,8 @@ export class SdkUtil {
|
|
|
onSuccess && onSuccess();
|
|
|
},
|
|
|
fail: (e) => {
|
|
|
- console.log('抖音分享屏幕录制视频,失败=',e)
|
|
|
- // if(this.checkAppName()){
|
|
|
- // onSuccess && onSuccess();
|
|
|
- // }else{
|
|
|
- // onFail && onFail();
|
|
|
- // }
|
|
|
// 当前今日头条ios无法获得分享成功回调 if(res.platform === 'ios' && res.appName === 'Toutiao')
|
|
|
+ console.log('抖音分享屏幕录制视频,失败=',e)
|
|
|
onFail && onFail()
|
|
|
}
|
|
|
})
|