日志控制

This commit is contained in:
chen wei bo
2025-09-21 20:05:39 +08:00
parent b94d9527a2
commit 23c038fd14
10 changed files with 343 additions and 332 deletions
+7 -6
View File
@@ -7,6 +7,7 @@ import { KSSDK } from "./ksSDK";
import AudioManager from "../Manager/AudioManager"; import AudioManager from "../Manager/AudioManager";
import GlobalValue, { VideoRoleType } from "../Common/GlobalValue"; import GlobalValue, { VideoRoleType } from "../Common/GlobalValue";
import { luffaSDK } from "./luffaSDK"; import { luffaSDK } from "./luffaSDK";
import { logger } from "db://assets/Scripts/Main/Common/Logger";
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@@ -86,9 +87,9 @@ export class SDKManager { //extends Component
this.video_reward_map = {} this.video_reward_map = {}
this.share_reward_map = {} this.share_reward_map = {}
console.log("平台值 wx:",window["wx"], typeof window["wx"]) logger.log("平台值 wx:",window["wx"], typeof window["wx"])
console.log("平台值 ks:",window["ks"], typeof window["ks"]) logger.log("平台值 ks:",window["ks"], typeof window["ks"])
console.log("平台值 tt:",window["tt"], typeof window["tt"]) logger.log("平台值 tt:",window["tt"], typeof window["tt"])
if (typeof window["ks"] !== 'undefined') { if (typeof window["ks"] !== 'undefined') {
this.sdk_channel = E_SDK_Channel.KS this.sdk_channel = E_SDK_Channel.KS
@@ -104,7 +105,7 @@ export class SDKManager { //extends Component
this.sdk = new WebSDK() this.sdk = new WebSDK()
} }
console.log("当前平台:",sys.platform, this.sdk_channel) logger.log("当前平台:",sys.platform, this.sdk_channel)
if (GlobalValue.NpcVideoMod) { if (GlobalValue.NpcVideoMod) {
GlobalValue.NpcVideoMod = this.sdk_channel === E_SDK_Channel.WX || this.sdk_channel === E_SDK_Channel.WEB GlobalValue.NpcVideoMod = this.sdk_channel === E_SDK_Channel.WX || this.sdk_channel === E_SDK_Channel.WEB
} }
@@ -192,12 +193,12 @@ export class SDKManager { //extends Component
} }
//看视频广告前 //看视频广告前
static video_ad_pre() { static video_ad_pre() {
console.log("SDKManager 视频广告前") logger.log("SDKManager 视频广告前")
AudioManager.I.PauseMusic(); AudioManager.I.PauseMusic();
} }
//看视频广告后返回游戏 //看视频广告后返回游戏
static video_ad_back() { static video_ad_back() {
console.log("SDKManager 视频广告后") logger.log("SDKManager 视频广告后")
AudioManager.I.ResumeMusic(); AudioManager.I.ResumeMusic();
} }
+51 -50
View File
@@ -5,6 +5,7 @@ import SubManager from "../../Sub/SubManager"
import Utils from "../Common/Utils" import Utils from "../Common/Utils"
import { InnerMsgCode } from "../Config/InnerMsgCode" import { InnerMsgCode } from "../Config/InnerMsgCode"
import HttpUnit from "../Common/HttpUnit" import HttpUnit from "../Common/HttpUnit"
import { logger } from "db://assets/Scripts/Main/Common/Logger";
//广告ID //广告ID
const AD_AWARD = "1ntrdiqhmdket7v5fe" const AD_AWARD = "1ntrdiqhmdket7v5fe"
@@ -47,7 +48,7 @@ export class ByteDanceSDK{
window['tt'].checkScene({ window['tt'].checkScene({
scene: "sidebar", scene: "sidebar",
success: (res) => { success: (res) => {
console.log("抖音 检测侧边栏功能->", res) logger.log("抖音 检测侧边栏功能->", res)
if (res.isExist == true) { if (res.isExist == true) {
if (ByteDanceSDK._SidebarState == 0) { if (ByteDanceSDK._SidebarState == 0) {
ByteDanceSDK._SidebarState = 1 ByteDanceSDK._SidebarState = 1
@@ -56,22 +57,22 @@ export class ByteDanceSDK{
cb && cb(res.isExist == true); cb && cb(res.isExist == true);
}, },
fail: (res) => { fail: (res) => {
console.log("抖音 检测侧边栏功能失败->", res) logger.log("抖音 检测侧边栏功能失败->", res)
cb && cb(false); cb && cb(false);
} }
}) })
} }
/**前往侧边栏 */ /**前往侧边栏 */
public static GotoSidebar(cb:Function = null){ public static GotoSidebar(cb:Function = null){
console.log("抖音 正在前往侧边栏...") logger.log("抖音 正在前往侧边栏...")
window["tt"].navigateToScene({ window["tt"].navigateToScene({
scene: "sidebar", scene: "sidebar",
success(res) { success(res) {
console.log("抖音 前往侧边栏 成功") logger.log("抖音 前往侧边栏 成功")
cb && cb(true); cb && cb(true);
}, },
fail(res) { fail(res) {
console.log("抖音 前往侧边栏 失败", res) logger.log("抖音 前往侧边栏 失败", res)
} }
}) })
} }
@@ -79,7 +80,7 @@ export class ByteDanceSDK{
//初始化 //初始化
init(cb: Function = null) { init(cb: Function = null) {
console.log("init 抖音 初始化...") logger.log("init 抖音 初始化...")
// 保持屏幕常亮 // 保持屏幕常亮
window["tt"].setKeepScreenOn({ window["tt"].setKeepScreenOn({
keepScreenOn: true, keepScreenOn: true,
@@ -92,14 +93,14 @@ export class ByteDanceSDK{
//小游戏回到前台 //小游戏回到前台
window['tt'].onShow((res)=>{ window['tt'].onShow((res)=>{
console.log("抖音 小游戏回到前台->", res) logger.log("抖音 小游戏回到前台->", res)
if (!res) { if (!res) {
return; return;
} }
// console.log("启动参数:", res.query); // logger.log("启动参数:", res.query);
// console.log("来源信息:", res.refererInfo); // logger.log("来源信息:", res.refererInfo);
// console.log("场景值:", res.scene); // logger.log("场景值:", res.scene);
// console.log("启动场景字段:", res.launch_from, ", ", res.location); // logger.log("启动场景字段:", res.launch_from, ", ", res.location);
//返回小游戏场景值 //返回小游戏场景值
if (res.query && res.query.ShareCode) { if (res.query && res.query.ShareCode) {
@@ -108,7 +109,7 @@ export class ByteDanceSDK{
//从侧边栏返回 //从侧边栏返回
if (res.launch_from == "homepage" && res.location == "sidebar_card") { if (res.launch_from == "homepage" && res.location == "sidebar_card") {
console.log("从侧边栏返回, SidebarState=", ByteDanceSDK._SidebarState) logger.log("从侧边栏返回, SidebarState=", ByteDanceSDK._SidebarState)
if (ByteDanceSDK._SidebarState == 1) { if (ByteDanceSDK._SidebarState == 1) {
ByteDanceSDK._SidebarState = 2 ByteDanceSDK._SidebarState = 2
Utils.sendInnerMsg(InnerMsgCode.UI_BD_Sidebar, {}) Utils.sendInnerMsg(InnerMsgCode.UI_BD_Sidebar, {})
@@ -129,7 +130,7 @@ export class ByteDanceSDK{
if (this.ShareCb) { if (this.ShareCb) {
if (this.ShareSTime) { if (this.ShareSTime) {
let nT = new Date().getTime(); let nT = new Date().getTime();
console.log("分享时间差 计算:",nT, this.ShareSTime); logger.log("分享时间差 计算:",nT, this.ShareSTime);
if (nT - this.ShareSTime > 1500) { if (nT - this.ShareSTime > 1500) {
let cb = this.ShareCb.succ let cb = this.ShareCb.succ
cb && cb() cb && cb()
@@ -144,7 +145,7 @@ export class ByteDanceSDK{
window['tt'].onHide(() => { window['tt'].onHide(() => {
if (this.ShareCb) { if (this.ShareCb) {
this.ShareSTime = new Date().getTime(); this.ShareSTime = new Date().getTime();
console.log("分享时间差 记录:", this.ShareSTime); logger.log("分享时间差 记录:", this.ShareSTime);
} }
}); });
@@ -175,7 +176,7 @@ export class ByteDanceSDK{
window['tt'].authorize({ window['tt'].authorize({
scope: autoKey, scope: autoKey,
success(res:any) { success(res:any) {
console.log("抖音 - 检测权限状态 succ:", JSON.stringify(res)) logger.log("抖音 - 检测权限状态 succ:", JSON.stringify(res))
if (autoKey == "scope.userInfo" && res.data['scope.userInfo']) { if (autoKey == "scope.userInfo" && res.data['scope.userInfo']) {
cb && cb(true) cb && cb(true)
} else { } else {
@@ -183,7 +184,7 @@ export class ByteDanceSDK{
} }
}, },
fail(res:any) { fail(res:any) {
console.log("抖音 - 检测权限状态 fail:",JSON.stringify(res)) logger.log("抖音 - 检测权限状态 fail:",JSON.stringify(res))
cb && cb(false) cb && cb(false)
} }
}) })
@@ -196,11 +197,11 @@ export class ByteDanceSDK{
window["tt"].getUserInfo({ window["tt"].getUserInfo({
force: false, //当宿主未登录时,是否强制拉起登录框 force: false, //当宿主未登录时,是否强制拉起登录框
success(res) { success(res) {
console.log("抖音 - 获取用户信息成功:", res); logger.log("抖音 - 获取用户信息成功:", res);
cb && cb({avatarUrl:res.userInfo.avatarUrl, nickName:res.userInfo.nickName}) //encryptedData cb && cb({avatarUrl:res.userInfo.avatarUrl, nickName:res.userInfo.nickName}) //encryptedData
}, },
fail(res) { fail(res) {
console.log("抖音 - 获取用户信息失败", res); logger.log("抖音 - 获取用户信息失败", res);
}, },
}) })
} }
@@ -211,11 +212,11 @@ export class ByteDanceSDK{
window["tt"].login({ window["tt"].login({
force: false, //未登录时, 是否强制调起登录框 force: false, //未登录时, 是否强制调起登录框
success(res) { success(res) {
console.log(`抖音 - 登录成功 code=${res.code}, anonymousCode=${res.anonymousCode}`); logger.log(`抖音 - 登录成功 code=${res.code}, anonymousCode=${res.anonymousCode}`);
cb && cb({ platform:2, code: res.code }); cb && cb({ platform:2, code: res.code });
}, },
fail(res) { fail(res) {
console.log(`抖音 - 登录失败`, res); logger.log(`抖音 - 登录失败`, res);
cb && cb({ platform:2, code: null }); cb && cb({ platform:2, code: null });
}, },
}) })
@@ -223,7 +224,7 @@ export class ByteDanceSDK{
private init_banner() { private init_banner() {
if (AD_BANNER as any == "test") { if (AD_BANNER as any == "test") {
console.log("抖音 横幅广告id未配置,跳过此类型初始化") logger.log("抖音 横幅广告id未配置,跳过此类型初始化")
return return
} }
@@ -260,10 +261,10 @@ export class ByteDanceSDK{
// bd_banner // bd_banner
// .show() // .show()
// .then(() => { // .then(() => {
// console.log("init_banner 广告显示成功"); // logger.log("init_banner 广告显示成功");
// }) // })
// .catch((err) => { // .catch((err) => {
// console.log("init_banner 广告组件出现问题", err); // logger.log("init_banner 广告组件出现问题", err);
// }); // });
// }) // })
} }
@@ -275,7 +276,7 @@ export class ByteDanceSDK{
private preload_splash() { private preload_splash() {
if (AD_SPLASH as any == "test") { if (AD_SPLASH as any == "test") {
console.log("抖音 插屏广告id未配置,跳过此类型初始化") logger.log("抖音 插屏广告id未配置,跳过此类型初始化")
return return
} }
@@ -290,7 +291,7 @@ export class ByteDanceSDK{
this.bd_splash this.bd_splash
.load() .load()
.catch(err => { .catch(err => {
console.log("preload_splash err:",err); logger.log("preload_splash err:",err);
}) })
} }
} }
@@ -312,14 +313,14 @@ export class ByteDanceSDK{
this.preload_splash() this.preload_splash()
}) })
this.bd_splash.onError(function(err){ this.bd_splash.onError(function(err){
console.log("bd_splash err:",err) logger.log("bd_splash err:",err)
}) })
} }
private init_video() { private init_video() {
if (AD_AWARD as any == "test") { if (AD_AWARD as any == "test") {
console.log("抖音 激励广告id未配置,跳过此类型初始化") logger.log("抖音 激励广告id未配置,跳过此类型初始化")
return return
} }
@@ -346,7 +347,7 @@ export class ByteDanceSDK{
//显示视频广告 //显示视频广告
show_video(callback:Function, tag:number) { show_video(callback:Function, tag:number) {
if (AD_AWARD as any == 'test') { if (AD_AWARD as any == 'test') {
console.log('未接入广告ID,视频广告请求直接返回'); logger.log('未接入广告ID,视频广告请求直接返回');
callback && callback(); callback && callback();
SDKManager.video_ad_back(); SDKManager.video_ad_back();
return; return;
@@ -374,10 +375,10 @@ export class ByteDanceSDK{
if (this.bd_splash && this.bd_splash['custom_load_stautus'] && !this.bd_splash['custom_show_stautus']) { if (this.bd_splash && this.bd_splash['custom_load_stautus'] && !this.bd_splash['custom_show_stautus']) {
this.bd_splash.show().then(() => { this.bd_splash.show().then(() => {
this.bd_splash['custom_show_stautus'] = true this.bd_splash['custom_show_stautus'] = true
console.log("插屏广告展示成功"); logger.log("插屏广告展示成功");
}) })
} else { } else {
console.log("插屏广告展示失败"); logger.log("插屏广告展示失败");
this.preload_splash() this.preload_splash()
} }
@@ -416,18 +417,18 @@ export class ByteDanceSDK{
//主动拉起分享 //主动拉起分享
show_share(rewardCB?:Function) { show_share(rewardCB?:Function) {
// rewardCB && rewardCB() // rewardCB && rewardCB()
console.log("主动拉起分享"); logger.log("主动拉起分享");
let info:any = this.shareInfo(); let info:any = this.shareInfo();
info.succ = rewardCB; info.succ = rewardCB;
info.success = (res) => { info.success = (res) => {
console.log("抖音 主动拉起分享成功", res); logger.log("抖音 主动拉起分享成功", res);
} }
info.fail = (err) => { info.fail = (err) => {
console.log("抖音 主动拉起分享失败", err); logger.log("抖音 主动拉起分享失败", err);
} }
// info.complete = (res) => { // info.complete = (res) => {
// console.log("抖音 主动拉起分享完成", res); // logger.log("抖音 主动拉起分享完成", res);
// } // }
this.ShareCb = info; this.ShareCb = info;
@@ -471,23 +472,23 @@ export class ByteDanceSDK{
const fs = window['tt'].getFileSystemManager(); const fs = window['tt'].getFileSystemManager();
//1.删除上一个音频 //1.删除上一个音频
const lastPath = window['tt'].env.USER_DATA_PATH + `/ordernew${self._iacIdx}.mp3` const lastPath = window['tt'].env.USER_DATA_PATH + `/ordernew${self._iacIdx}.mp3`
console.log("抖音 正在删除上一个音频 ->", lastPath); logger.log("抖音 正在删除上一个音频 ->", lastPath);
fs.removeSavedFile({ fs.removeSavedFile({
filePath: lastPath, filePath: lastPath,
success(res) { success(res) {
console.log("抖音 删除上一个音频成功", res); logger.log("抖音 删除上一个音频成功", res);
}, },
fail(err) { fail(err) {
console.log("抖音 删除上一个音频失败", err); logger.log("抖音 删除上一个音频失败", err);
}, },
complete(res) { complete(res) {
console.log("抖音 删除上一个音频完成", res); logger.log("抖音 删除上一个音频完成", res);
//2.保存当前音频 //2.保存当前音频
//这里需要每次保存时换一下名字的原因是:innerAudioContext设置路径时如果路径相同,会认为还是同一个音频,不会重新加载,所以需要每次保存时换一下名字 //这里需要每次保存时换一下名字的原因是:innerAudioContext设置路径时如果路径相同,会认为还是同一个音频,不会重新加载,所以需要每次保存时换一下名字
self._iacIdx++; self._iacIdx++;
const audioPath = window['tt'].env.USER_DATA_PATH + `/ordernew${self._iacIdx}.mp3` const audioPath = window['tt'].env.USER_DATA_PATH + `/ordernew${self._iacIdx}.mp3`
console.log("抖音 正在保存本次音频 ->", audioPath); logger.log("抖音 正在保存本次音频 ->", audioPath);
fs.writeFile({ fs.writeFile({
filePath: audioPath, filePath: audioPath,
data: substring, data: substring,
@@ -497,18 +498,18 @@ export class ByteDanceSDK{
self._innerAudioContext = window['tt'].createInnerAudioContext(); self._innerAudioContext = window['tt'].createInnerAudioContext();
// 添加播放结束的回调 // 添加播放结束的回调
self._innerAudioContext.onEnded(() => { self._innerAudioContext.onEnded(() => {
console.log("抖音 AI语音播放结束") logger.log("抖音 AI语音播放结束")
self._innerAudioContext.stop(); // 使用 stop 方法停止音频并重置播放状态 self._innerAudioContext.stop(); // 使用 stop 方法停止音频并重置播放状态
self._innerAudioContext.destroy(); // 销毁音频实例 self._innerAudioContext.destroy(); // 销毁音频实例
self._innerAudioContext = null; self._innerAudioContext = null;
}); });
} }
console.log("抖音 播放base64音频", audioPath) logger.log("抖音 播放base64音频", audioPath)
self._innerAudioContext.src = audioPath; self._innerAudioContext.src = audioPath;
self._innerAudioContext.play(); // 开始播放音频 self._innerAudioContext.play(); // 开始播放音频
}, },
fail(err) { fail(err) {
console.log("抖音 保存本次音频失败", err); logger.log("抖音 保存本次音频失败", err);
} }
}) })
} }
@@ -520,7 +521,7 @@ export class ByteDanceSDK{
//微信开发者工具上可以通过「编译模式」下的「下次编译模拟更新」开关来调试 //微信开发者工具上可以通过「编译模式」下的「下次编译模拟更新」开关来调试
qiangzhiUpdata() { qiangzhiUpdata() {
if (window['tt'].getUpdateManager == null) { if (window['tt'].getUpdateManager == null) {
console.log("抖音 没有更新管理器", window['tt'].getUpdateManager) logger.log("抖音 没有更新管理器", window['tt'].getUpdateManager)
return; return;
} }
@@ -529,7 +530,7 @@ export class ByteDanceSDK{
//监听向微信后台请求检查更新结果事件。微信在小程序每次启动(包括热启动)时自动检查更新,不需由开发者主动触发。 //监听向微信后台请求检查更新结果事件。微信在小程序每次启动(包括热启动)时自动检查更新,不需由开发者主动触发。
updateManager.onCheckForUpdate((res) => { updateManager.onCheckForUpdate((res) => {
// 请求完新版本信息的回调 // 请求完新版本信息的回调
console.log("抖音 检查是否有新版本:", res.hasUpdate) logger.log("抖音 检查是否有新版本:", res.hasUpdate)
}); });
//监听小程序有版本更新事件。客户端主动触发下载(无需开发者触发),下载成功后回调 //监听小程序有版本更新事件。客户端主动触发下载(无需开发者触发),下载成功后回调
@@ -548,19 +549,19 @@ export class ByteDanceSDK{
//监听小程序更新失败事件。小程序有新版本,客户端主动触发下载(无需开发者触发),下载失败(可能是网络原因等)时回调 //监听小程序更新失败事件。小程序有新版本,客户端主动触发下载(无需开发者触发),下载失败(可能是网络原因等)时回调
updateManager.onUpdateFailed(function (err) { updateManager.onUpdateFailed(function (err) {
console.log("抖音 新版本下载失败", err) logger.log("抖音 新版本下载失败", err)
}) })
} }
//客服功能是否支持 //客服功能是否支持
kefuSupport() { kefuSupport() {
console.log("抖音 不支持联系客服") logger.log("抖音 不支持联系客服")
return false; return false;
} }
//进入联系客服 //进入联系客服
openKefu() { openKefu() {
console.log("抖音 进入联系客服") logger.log("抖音 进入联系客服")
} }
@@ -573,15 +574,15 @@ export class ByteDanceSDK{
//region 复制到剪贴板 //region 复制到剪贴板
/**复制文本到剪贴板 */ /**复制文本到剪贴板 */
copyToClipboard(text: string, cb?: Function) { copyToClipboard(text: string, cb?: Function) {
console.log("抖音 复制到剪贴板:", text); logger.log("抖音 复制到剪贴板:", text);
window['tt'].setClipboardData({ window['tt'].setClipboardData({
data: text, data: text,
success: () => { success: () => {
console.log("抖音 复制成功"); logger.log("抖音 复制成功");
cb && cb(true); cb && cb(true);
}, },
fail: (err) => { fail: (err) => {
console.log("抖音 复制失败:", err); logger.log("抖音 复制失败:", err);
cb && cb(false); cb && cb(false);
} }
}); });
+72 -71
View File
@@ -6,6 +6,7 @@ import Utils from "../Common/Utils";
import { InnerMsgCode } from "../Config/InnerMsgCode"; import { InnerMsgCode } from "../Config/InnerMsgCode";
import { BgVideo } from "./BgVideo"; import { BgVideo } from "./BgVideo";
import { SceneBgVideoLayer } from "../../Sub/UI/SceneBgVideoLayer"; import { SceneBgVideoLayer } from "../../Sub/UI/SceneBgVideoLayer";
import { logger } from "db://assets/Scripts/Main/Common/Logger";
//广告ID //广告ID
const wx_banner_ad_unit_id = 'test' const wx_banner_ad_unit_id = 'test'
@@ -35,7 +36,7 @@ export class KSSDK{
//获取小游戏冷启动时的参数 热启动参数通过 ks.onShow 接口获取。 //获取小游戏冷启动时的参数 热启动参数通过 ks.onShow 接口获取。
let launchOption = window['ks'].getLaunchOptionsSync(); let launchOption = window['ks'].getLaunchOptionsSync();
KSSDK.g_InGameScene = launchOption.from; KSSDK.g_InGameScene = launchOption.from;
console.log('init 快手 - 进入游戏的场景值', launchOption); logger.log('init 快手 - 进入游戏的场景值', launchOption);
// //显示分享按钮 // //显示分享按钮
// window['ks'].showShareMenu({ // window['ks'].showShareMenu({
@@ -53,10 +54,10 @@ export class KSSDK{
window['ks'].onShow(this.onWxShow.bind(this)); window['ks'].onShow(this.onWxShow.bind(this));
//小游戏被隐藏 记个时间 //小游戏被隐藏 记个时间
window['ks'].onHide(() => { window['ks'].onHide(() => {
console.log("快手 onHide回调:") logger.log("快手 onHide回调:")
if (this.ShareCb) { if (this.ShareCb) {
this.ShareSTime = new Date().getTime(); this.ShareSTime = new Date().getTime();
console.log("分享时间差 记录:", this.ShareSTime); logger.log("分享时间差 记录:", this.ShareSTime);
} }
}); });
@@ -70,7 +71,7 @@ export class KSSDK{
//小游戏回到前台 //小游戏回到前台
onWxShow(data: any) { onWxShow(data: any) {
console.log("快手 onShow回调:", data) logger.log("快手 onShow回调:", data)
if (data) { if (data) {
//启动小游戏时传入的参数 object //启动小游戏时传入的参数 object
if (data.query) { if (data.query) {
@@ -85,7 +86,7 @@ export class KSSDK{
if (this.ShareCb) { if (this.ShareCb) {
if (this.ShareSTime) { if (this.ShareSTime) {
let nT = new Date().getTime(); let nT = new Date().getTime();
console.log("分享时间差 计算:",nT, this.ShareSTime, nT - this.ShareSTime); logger.log("分享时间差 计算:",nT, this.ShareSTime, nT - this.ShareSTime);
if (nT - this.ShareSTime > 1) { //快手的onHide有问题,离onShow很近 if (nT - this.ShareSTime > 1) { //快手的onHide有问题,离onShow很近
let cb = this.ShareCb.succ let cb = this.ShareCb.succ
cb && cb() cb && cb()
@@ -113,7 +114,7 @@ export class KSSDK{
checkAutoSetting(autoKey:string, cb:Function = null) { checkAutoSetting(autoKey:string, cb:Function = null) {
window['ks'].getSetting({ window['ks'].getSetting({
success(res:any) { success(res:any) {
console.log("快手 - 检测权限状态 succ:", res) logger.log("快手 - 检测权限状态 succ:", res)
if (autoKey == "userInfo" && res.authSetting['scope.userInfo']) { if (autoKey == "userInfo" && res.authSetting['scope.userInfo']) {
cb && cb(true) cb && cb(true)
} else { } else {
@@ -121,7 +122,7 @@ export class KSSDK{
} }
}, },
fail(res:any) { fail(res:any) {
console.log("快手 - 检测权限状态 fail:", res) logger.log("快手 - 检测权限状态 fail:", res)
cb && cb(false) cb && cb(false)
} }
}) })
@@ -134,16 +135,16 @@ export class KSSDK{
var self = this; var self = this;
window['ks'].getSetting({ window['ks'].getSetting({
success(res:any) { success(res:any) {
console.log("快手 - 获取授权信息成功:", res); logger.log("快手 - 获取授权信息成功:", res);
let isScope = res.authSetting['scope.userInfo'] let isScope = res.authSetting['scope.userInfo']
if (isScope) { if (isScope) {
window['ks'].getUserInfo({ window['ks'].getUserInfo({
success: (res2) => { success: (res2) => {
console.log("快手 - 获取用户信息成功:", res2); logger.log("快手 - 获取用户信息成功:", res2);
cb && cb({avatarUrl:res2.userInfo.avatarUrl, nickName:res2.userInfo.nickName}) cb && cb({avatarUrl:res2.userInfo.avatarUrl, nickName:res2.userInfo.nickName})
}, },
fail: (error) => { fail: (error) => {
console.log("快手 - 获取用户信息失败:", error); logger.log("快手 - 获取用户信息失败:", error);
} }
}) })
} else { } else {
@@ -151,17 +152,17 @@ export class KSSDK{
window['ks'].authorize({ window['ks'].authorize({
scope: 'scope.userInfo', scope: 'scope.userInfo',
success: (res) => { success: (res) => {
console.log("快手 - 发起授权请求成功:", res); logger.log("快手 - 发起授权请求成功:", res);
self.getUserInfo(cb) self.getUserInfo(cb)
}, },
fail: (error) => { fail: (error) => {
console.log("快手 - 发起授权请求失败: ", error); logger.log("快手 - 发起授权请求失败: ", error);
} }
}) })
} }
}, },
fail: (error) => { fail: (error) => {
console.log("快手 - 获取授权信息失败: ", error); logger.log("快手 - 获取授权信息失败: ", error);
// cb && cb({avatarUrl:"", nickName:""}) // cb && cb({avatarUrl:"", nickName:""})
} }
}) })
@@ -172,11 +173,11 @@ export class KSSDK{
login(cb: Function = null) { login(cb: Function = null) {
window['ks'].login({ window['ks'].login({
success: (res) => { success: (res) => {
console.log('快手 - 登录成功', res.code); logger.log('快手 - 登录成功', res.code);
cb && cb({ platform:3, code: res.code }); cb && cb({ platform:3, code: res.code });
}, },
fail(res: any) { fail(res: any) {
console.log(`快手 login 调用失败`, res); logger.log(`快手 login 调用失败`, res);
cb && cb({ platform:3, code: null }); cb && cb({ platform:3, code: null });
}, },
}); });
@@ -185,7 +186,7 @@ export class KSSDK{
//初始化视频广告 //初始化视频广告
private init_video() { private init_video() {
if (wx_video_ad_unit_id as any == "test") { if (wx_video_ad_unit_id as any == "test") {
console.log("快手 激励广告id未配置,跳过此类型初始化") logger.log("快手 激励广告id未配置,跳过此类型初始化")
return return
} }
@@ -193,10 +194,10 @@ export class KSSDK{
adUnitId: wx_video_ad_unit_id adUnitId: wx_video_ad_unit_id
}); });
this.wx_video.onError((err) => { this.wx_video.onError((err) => {
console.log('onError event emit', err); logger.log('onError event emit', err);
}); });
this.wx_video.onClose(res => { this.wx_video.onClose(res => {
console.log('onClose event emit',res); logger.log('onClose event emit',res);
// 用户点击了【关闭广告】按钮 // 用户点击了【关闭广告】按钮
// 小于 2.1.0 的基础库版本,res 是一个 undefined // 小于 2.1.0 的基础库版本,res 是一个 undefined
if ((res && res.isEnded) || res === undefined) { if ((res && res.isEnded) || res === undefined) {
@@ -217,7 +218,7 @@ export class KSSDK{
//初始化插屏广告 //初始化插屏广告
private init_splash() { private init_splash() {
if (wx_splash_ad_unit_id as any == "test") { if (wx_splash_ad_unit_id as any == "test") {
console.log("快手 插屏广告id未配置,跳过此类型初始化") logger.log("快手 插屏广告id未配置,跳过此类型初始化")
return return
} }
@@ -227,10 +228,10 @@ export class KSSDK{
adUnitId: wx_splash_ad_unit_id adUnitId: wx_splash_ad_unit_id
}); });
this.wx_splash.onError((err) => { this.wx_splash.onError((err) => {
console.log('splash onError event emit', err); logger.log('splash onError event emit', err);
}); });
this.wx_splash.onClose(res => { this.wx_splash.onClose(res => {
console.log('splash onClose event emit', res); logger.log('splash onClose event emit', res);
}); });
} }
} }
@@ -238,7 +239,7 @@ export class KSSDK{
//初始化Banner //初始化Banner
private init_banner() { private init_banner() {
if (wx_banner_ad_unit_id as any == "test") { if (wx_banner_ad_unit_id as any == "test") {
console.log("快手 横幅广告id未配置,跳过此类型初始化") logger.log("快手 横幅广告id未配置,跳过此类型初始化")
return return
} }
@@ -247,7 +248,7 @@ export class KSSDK{
//显示视频广告 //显示视频广告
show_video(callback:Function, tag:number) { show_video(callback:Function, tag:number) {
if (wx_video_ad_unit_id == 'test') { if (wx_video_ad_unit_id == 'test') {
console.log('未接入广告ID,视频广告请求直接返回'); logger.log('未接入广告ID,视频广告请求直接返回');
callback && callback(); callback && callback();
SDKManager.video_ad_back(); SDKManager.video_ad_back();
return; return;
@@ -258,10 +259,10 @@ export class KSSDK{
let p = this.wx_video.show() let p = this.wx_video.show()
p.then(function(result){ p.then(function(result){
// 激励视频展示成功 // 激励视频展示成功
console.log(`快手 show rewarded video ad success, result is ${result}`) logger.log(`快手 show rewarded video ad success, result is ${result}`)
}).catch(function(error){ }).catch(function(error){
// 激励视频展示失败 // 激励视频展示失败
console.log(`快手 show rewarded video ad failed, error is ${error}`) logger.log(`快手 show rewarded video ad failed, error is ${error}`)
}) })
// this.wx_video.load() // this.wx_video.load()
@@ -282,10 +283,10 @@ export class KSSDK{
let p = this.wx_splash.show() let p = this.wx_splash.show()
p.then(function(result){ p.then(function(result){
// 插屏广告展示成功 // 插屏广告展示成功
console.log(`快手 show interstitial ad success, result is ${result}`) logger.log(`快手 show interstitial ad success, result is ${result}`)
}).catch(function(error){ }).catch(function(error){
// 插屏广告展示失败 // 插屏广告展示失败
console.log(`快手 show interstitial ad failed, error is ${error}`) logger.log(`快手 show interstitial ad failed, error is ${error}`)
if (error.code === -10005) { if (error.code === -10005) {
// 表明当前app版本不支持插屏广告,可以提醒用户升级app版本 // 表明当前app版本不支持插屏广告,可以提醒用户升级app版本
} }
@@ -319,7 +320,7 @@ export class KSSDK{
} }
//主动拉起分享 //主动拉起分享
show_share(rewardCB?:Function) { show_share(rewardCB?:Function) {
console.log("主动拉起分享"); logger.log("主动拉起分享");
let info:any = this.shareInfo(); let info:any = this.shareInfo();
info.succ = rewardCB; info.succ = rewardCB;
info.success = null; info.success = null;
@@ -337,13 +338,13 @@ export class KSSDK{
//显示游戏圈 //显示游戏圈
show_gameClub(leftRatio, topRatio, widthRatio, heightRatio) { show_gameClub(leftRatio, topRatio, widthRatio, heightRatio) {
if (true) { if (true) {
console.log("显示游戏圈,快手暂不支持"); logger.log("显示游戏圈,快手暂不支持");
return return
} }
} }
//隐藏游戏圈 //隐藏游戏圈
hide_gameClub() { hide_gameClub() {
console.log("隐藏游戏圈"); logger.log("隐藏游戏圈");
if (this.wx_gameClub) { if (this.wx_gameClub) {
this.wx_gameClub.hide(); this.wx_gameClub.hide();
} }
@@ -359,7 +360,7 @@ export class KSSDK{
private _iacIdx = 0 //音频播放索引 private _iacIdx = 0 //音频播放索引
playBase64Audio(base64, loop) { playBase64Audio(base64, loop) {
if (!this.checkSupportBase64Audio()) { if (!this.checkSupportBase64Audio()) {
console.log("当前平台不支持base64音频播放"); logger.log("当前平台不支持base64音频播放");
return; return;
} }
@@ -373,23 +374,23 @@ export class KSSDK{
const fs = window['ks'].getFileSystemManager(); const fs = window['ks'].getFileSystemManager();
//1.删除上一个音频 //1.删除上一个音频
const lastPath = window['ks'].env.USER_DATA_PATH + `/ordernew${self._iacIdx}.mp3` const lastPath = window['ks'].env.USER_DATA_PATH + `/ordernew${self._iacIdx}.mp3`
console.log("快手 正在删除上一个音频 ->", lastPath); logger.log("快手 正在删除上一个音频 ->", lastPath);
fs.removeSavedFile({ fs.removeSavedFile({
filePath: lastPath, filePath: lastPath,
success(res) { success(res) {
console.log("快手 删除上一个音频成功", res); logger.log("快手 删除上一个音频成功", res);
}, },
fail(err) { fail(err) {
console.log("快手 删除上一个音频失败", err); logger.log("快手 删除上一个音频失败", err);
}, },
complete(res) { complete(res) {
console.log("快手 删除上一个音频完成", res); logger.log("快手 删除上一个音频完成", res);
//2.保存当前音频 //2.保存当前音频
//这里需要每次保存时换一下名字的原因是:innerAudioContext设置路径时如果路径相同,会认为还是同一个音频,不会重新加载,所以需要每次保存时换一下名字 //这里需要每次保存时换一下名字的原因是:innerAudioContext设置路径时如果路径相同,会认为还是同一个音频,不会重新加载,所以需要每次保存时换一下名字
self._iacIdx++; self._iacIdx++;
const audioPath = window['ks'].env.USER_DATA_PATH + `/ordernew${self._iacIdx}.mp3` const audioPath = window['ks'].env.USER_DATA_PATH + `/ordernew${self._iacIdx}.mp3`
console.log("快手 正在保存本次音频 ->", audioPath); logger.log("快手 正在保存本次音频 ->", audioPath);
fs.writeFile({ fs.writeFile({
filePath: audioPath, filePath: audioPath,
data: substring, data: substring,
@@ -399,18 +400,18 @@ export class KSSDK{
self._innerAudioContext = window['ks'].createInnerAudioContext(); self._innerAudioContext = window['ks'].createInnerAudioContext();
// 添加播放结束的回调 // 添加播放结束的回调
self._innerAudioContext.onEnded(() => { self._innerAudioContext.onEnded(() => {
console.log("快手 AI语音播放结束") logger.log("快手 AI语音播放结束")
self._innerAudioContext.stop(); // 使用 stop 方法停止音频并重置播放状态 self._innerAudioContext.stop(); // 使用 stop 方法停止音频并重置播放状态
self._innerAudioContext.destroy(); // 销毁音频实例 self._innerAudioContext.destroy(); // 销毁音频实例
self._innerAudioContext = null; self._innerAudioContext = null;
}); });
} }
console.log("快手 播放base64音频", audioPath) logger.log("快手 播放base64音频", audioPath)
self._innerAudioContext.src = audioPath; self._innerAudioContext.src = audioPath;
self._innerAudioContext.play(); // 开始播放音频 self._innerAudioContext.play(); // 开始播放音频
}, },
fail(err) { fail(err) {
console.log("快手 保存本次音频失败", err); logger.log("快手 保存本次音频失败", err);
} }
}) })
} }
@@ -423,7 +424,7 @@ export class KSSDK{
//微信开发者工具上可以通过「编译模式」下的「下次编译模拟更新」开关来调试 //微信开发者工具上可以通过「编译模式」下的「下次编译模拟更新」开关来调试
qiangzhiUpdata() { qiangzhiUpdata() {
if (window['ks'].getUpdateManager == null) { if (window['ks'].getUpdateManager == null) {
console.log("快手 没有更新管理器", window['ks'].getUpdateManager) logger.log("快手 没有更新管理器", window['ks'].getUpdateManager)
return; return;
} }
@@ -432,7 +433,7 @@ export class KSSDK{
//监听向微信后台请求检查更新结果事件。微信在小程序每次启动(包括热启动)时自动检查更新,不需由开发者主动触发。 //监听向微信后台请求检查更新结果事件。微信在小程序每次启动(包括热启动)时自动检查更新,不需由开发者主动触发。
updateManager.onCheckForUpdate((res) => { updateManager.onCheckForUpdate((res) => {
// 请求完新版本信息的回调 // 请求完新版本信息的回调
console.log("快手 检查是否有新版本:", res.hasUpdate) logger.log("快手 检查是否有新版本:", res.hasUpdate)
}); });
//监听小程序有版本更新事件。客户端主动触发下载(无需开发者触发),下载成功后回调 //监听小程序有版本更新事件。客户端主动触发下载(无需开发者触发),下载成功后回调
@@ -449,19 +450,19 @@ export class KSSDK{
//监听小程序更新失败事件。小程序有新版本,客户端主动触发下载(无需开发者触发),下载失败(可能是网络原因等)时回调 //监听小程序更新失败事件。小程序有新版本,客户端主动触发下载(无需开发者触发),下载失败(可能是网络原因等)时回调
updateManager.onUpdateFailed(function (err) { updateManager.onUpdateFailed(function (err) {
console.log("快手 新版本下载失败", err) logger.log("快手 新版本下载失败", err)
}) })
} }
//客服功能是否支持 //客服功能是否支持
kefuSupport() { kefuSupport() {
console.log("快手 不支持联系客服") logger.log("快手 不支持联系客服")
return false; return false;
} }
//进入联系客服 //进入联系客服
openKefu() { openKefu() {
console.log("快手 进入联系客服") logger.log("快手 进入联系客服")
} }
@@ -471,7 +472,7 @@ export class KSSDK{
private curPlayType: VideoRoleType = VideoRoleType.None //当前播放的视频的类型 private curPlayType: VideoRoleType = VideoRoleType.None //当前播放的视频的类型
playBgAudio(remoteUrl:string, vtype:VideoRoleType, loop:boolean = false, extra:any = {}) { playBgAudio(remoteUrl:string, vtype:VideoRoleType, loop:boolean = false, extra:any = {}) {
if (!window['ks'].createVideo) { if (!window['ks'].createVideo) {
console.log("快手 不支持播放视频") logger.log("快手 不支持播放视频")
return return
} }
if (this._bgVideo && this._bgShow) { if (this._bgVideo && this._bgShow) {
@@ -479,18 +480,18 @@ export class KSSDK{
return return
} }
let self = this; let self = this;
console.log("微信 播放背景视频组件1", remoteUrl); logger.log("微信 播放背景视频组件1", remoteUrl);
this.curPlayType = vtype this.curPlayType = vtype
if (!this._bgVideo) { if (!this._bgVideo) {
this._bgVideo = this.createVideoHandle(); this._bgVideo = this.createVideoHandle();
// this._bgVideo.onPlay(() => { // this._bgVideo.onPlay(() => {
// console.log("微信 背景视频播放开始"); // logger.log("微信 背景视频播放开始");
// }) // })
this._bgVideo.onTimeUpdate((_tinfo:any) =>{ this._bgVideo.onTimeUpdate((_tinfo:any) =>{
// console.log("微信 背景视频播放进度", self._bgShow, _tinfo); // logger.log("微信 背景视频播放进度", self._bgShow, _tinfo);
if (!self._bgShow) { if (!self._bgShow) {
if (_tinfo && _tinfo.position > 0.01) { if (_tinfo && _tinfo.position > 0.01) {
console.log("微信 背景视频1进入视野"); logger.log("微信 背景视频1进入视野");
self.videoMoveIn(self._bgVideo) self.videoMoveIn(self._bgVideo)
self._bgShow = true; self._bgShow = true;
self.removeBgAudioNext() self.removeBgAudioNext()
@@ -521,19 +522,19 @@ export class KSSDK{
private _bgTempShow: boolean = false; private _bgTempShow: boolean = false;
playBgAudioNext(remoteUrl:string, vtype:VideoRoleType, loop:boolean = false, extra:any = {}) { playBgAudioNext(remoteUrl:string, vtype:VideoRoleType, loop:boolean = false, extra:any = {}) {
this.removeBgAudioNext(); this.removeBgAudioNext();
console.log("微信 创建背景视频组件2--->", remoteUrl); logger.log("微信 创建背景视频组件2--->", remoteUrl);
this.curPlayType = vtype this.curPlayType = vtype
let self = this; let self = this;
if (!this._bgTempVideo) { if (!this._bgTempVideo) {
this._bgTempVideo = this.createVideoHandle(); this._bgTempVideo = this.createVideoHandle();
// this._bgTempVideo.onPlay(() => { // this._bgTempVideo.onPlay(() => {
// console.log("微信 临时背景视频播放开始"); // logger.log("微信 临时背景视频播放开始");
// }) // })
this._bgTempVideo.onTimeUpdate((_tinfo:any) =>{ this._bgTempVideo.onTimeUpdate((_tinfo:any) =>{
// console.log("微信 临时背景视频播放进度", self._bgTempShow, _tinfo); // logger.log("微信 临时背景视频播放进度", self._bgTempShow, _tinfo);
if (!self._bgTempShow) { if (!self._bgTempShow) {
if (_tinfo && _tinfo.position > 0.01) { if (_tinfo && _tinfo.position > 0.01) {
console.log("微信 背景视频2进入视野"); logger.log("微信 背景视频2进入视野");
self._bgTempShow = true; self._bgTempShow = true;
self.videoMoveIn(self._bgTempVideo) self.videoMoveIn(self._bgTempVideo)
self.removeBgAudio() self.removeBgAudio()
@@ -569,18 +570,18 @@ export class KSSDK{
return return
} }
let self = this; let self = this;
console.log("微信 播放emo视频1", remoteUrl); logger.log("微信 播放emo视频1", remoteUrl);
this.curPlayType = vtype this.curPlayType = vtype
if (!this._emoVideo) { if (!this._emoVideo) {
this._emoVideo = this.createVideoHandle(); this._emoVideo = this.createVideoHandle();
// this._emoVideo.onPlay(() => { // this._emoVideo.onPlay(() => {
// console.log("微信 背景视频播放开始"); // logger.log("微信 背景视频播放开始");
// }) // })
this._emoVideo.onTimeUpdate((_tinfo:any) =>{ this._emoVideo.onTimeUpdate((_tinfo:any) =>{
// console.log("微信 背景视频播放进度", self._emoShow, _tinfo); // logger.log("微信 背景视频播放进度", self._emoShow, _tinfo);
if (!self._emoShow) { if (!self._emoShow) {
if (_tinfo && _tinfo.position > 0.01) { if (_tinfo && _tinfo.position > 0.01) {
console.log("微信 emo视频1准备好了"); logger.log("微信 emo视频1准备好了");
self._emoShow = true; self._emoShow = true;
self.removeEmoAudioNext() self.removeEmoAudioNext()
self.setEmoReadyAudio(self._emoVideo) self.setEmoReadyAudio(self._emoVideo)
@@ -610,19 +611,19 @@ export class KSSDK{
private _emoTempShow: boolean = false; private _emoTempShow: boolean = false;
playEmoAudioNext(remoteUrl:string, vtype:VideoRoleType, loop:boolean = false, extra:any = {}) { playEmoAudioNext(remoteUrl:string, vtype:VideoRoleType, loop:boolean = false, extra:any = {}) {
this.removeEmoAudioNext(); this.removeEmoAudioNext();
console.log("微信 播放emo视频2--->", remoteUrl); logger.log("微信 播放emo视频2--->", remoteUrl);
this.curPlayType = vtype this.curPlayType = vtype
let self = this; let self = this;
if (!this._emoTempVideo) { if (!this._emoTempVideo) {
this._emoTempVideo = this.createVideoHandle(); this._emoTempVideo = this.createVideoHandle();
// this._emoTempVideo.onPlay(() => { // this._emoTempVideo.onPlay(() => {
// console.log("微信 临时背景视频播放开始"); // logger.log("微信 临时背景视频播放开始");
// }) // })
this._emoTempVideo.onTimeUpdate((_tinfo:any) =>{ this._emoTempVideo.onTimeUpdate((_tinfo:any) =>{
// console.log("微信 临时背景视频播放进度", self._emoTempShow, _tinfo); // logger.log("微信 临时背景视频播放进度", self._emoTempShow, _tinfo);
if (!self._emoTempShow) { if (!self._emoTempShow) {
if (_tinfo && _tinfo.position > 0.01) { if (_tinfo && _tinfo.position > 0.01) {
console.log("微信 emo视频2已准备好"); logger.log("微信 emo视频2已准备好");
self._emoTempShow = true; self._emoTempShow = true;
self.removeEmoAudio() self.removeEmoAudio()
self.setEmoReadyAudio(self._emoTempVideo) self.setEmoReadyAudio(self._emoTempVideo)
@@ -706,19 +707,19 @@ export class KSSDK{
this.videoAdaInfo.x = -(this.videoWidth * ratioh - size.width) / 2 this.videoAdaInfo.x = -(this.videoWidth * ratioh - size.width) / 2
this.videoAdaInfo.y = 0 this.videoAdaInfo.y = 0
} }
console.log("微信 视频适配信息", this.videoAdaInfo, size) logger.log("微信 视频适配信息", this.videoAdaInfo, size)
return this.videoAdaInfo return this.videoAdaInfo
} }
//设置暂停播放的主视频 //设置暂停播放的主视频
private vpWait: any = null; private vpWait: any = null;
setBgAudioPause(wait:any) { setBgAudioPause(wait:any) {
console.log("微信 主视频暂停播放") logger.log("微信 主视频暂停播放")
this.vpWait = wait this.vpWait = wait
this.vpWait.pause() this.vpWait.pause()
} }
replayBgAudioPause() { replayBgAudioPause() {
console.log("微信 主视频继续播放") logger.log("微信 主视频继续播放")
if (this.vpWait) { if (this.vpWait) {
this.vpWait.play() this.vpWait.play()
} }
@@ -727,7 +728,7 @@ export class KSSDK{
//设置准备好要播放的表情视频 //设置准备好要播放的表情视频
private emoReady: any = null; private emoReady: any = null;
setEmoReadyAudio(au: any) { setEmoReadyAudio(au: any) {
console.log("微信 设置emo ready视频") logger.log("微信 设置emo ready视频")
if (this.emoReady) { if (this.emoReady) {
this.emoReady.stop() this.emoReady.stop()
this.videoMoveOut(this.emoReady) this.videoMoveOut(this.emoReady)
@@ -737,7 +738,7 @@ export class KSSDK{
} }
//移除准备好要播放的表情视频 //移除准备好要播放的表情视频
removeEmoReadyAudio() { removeEmoReadyAudio() {
console.log("微信 移除emo ready视频") logger.log("微信 移除emo ready视频")
if (this.emoReady) { if (this.emoReady) {
this.emoReady.stop() this.emoReady.stop()
this.videoMoveOut(this.emoReady) this.videoMoveOut(this.emoReady)
@@ -747,7 +748,7 @@ export class KSSDK{
//播放准备好要播放的表情视频 //播放准备好要播放的表情视频
doPlayEmoReadyAudio():boolean { doPlayEmoReadyAudio():boolean {
if (this.emoReady) { if (this.emoReady) {
console.log("微信 播放emo ready视频") logger.log("微信 播放emo ready视频")
this.emoReady.play() this.emoReady.play()
this.videoMoveIn(this.emoReady) this.videoMoveIn(this.emoReady)
return true return true
@@ -756,7 +757,7 @@ export class KSSDK{
} }
//表情视频播放结束 //表情视频播放结束
doEmoFinish() { doEmoFinish() {
console.log("微信emo ready视频播放结束") logger.log("微信emo ready视频播放结束")
this.removeEmoReadyAudio() this.removeEmoReadyAudio()
this.replayBgAudioPause() this.replayBgAudioPause()
} }
@@ -764,15 +765,15 @@ export class KSSDK{
//region 复制到剪贴板 //region 复制到剪贴板
/**复制文本到剪贴板 */ /**复制文本到剪贴板 */
copyToClipboard(text: string, cb?: Function) { copyToClipboard(text: string, cb?: Function) {
console.log("快手 复制到剪贴板:", text); logger.log("快手 复制到剪贴板:", text);
window['ks'].setClipboardData({ window['ks'].setClipboardData({
data: text, data: text,
success: () => { success: () => {
console.log("快手 复制成功"); logger.log("快手 复制成功");
cb && cb(true); cb && cb(true);
}, },
fail: (err) => { fail: (err) => {
console.log("快手 复制失败:", err); logger.log("快手 复制失败:", err);
cb && cb(false); cb && cb(false);
} }
}); });
+80 -79
View File
@@ -5,6 +5,7 @@ import { I_SDK_UserInfo_Callback, SDKManager } from "./SDKManager";
import Utils from "../Common/Utils"; import Utils from "../Common/Utils";
import uma from "../../../utils/uma.wx.min.js"; import uma from "../../../utils/uma.wx.min.js";
import { InnerMsgCode } from "../Config/InnerMsgCode"; import { InnerMsgCode } from "../Config/InnerMsgCode";
import { logger } from "db://assets/Scripts/Main/Common/Logger";
//广告ID //广告ID
const wx_banner_ad_unit_id = "test"; const wx_banner_ad_unit_id = "test";
@@ -35,7 +36,7 @@ export class luffaSDK {
// 保持屏幕常亮 // 保持屏幕常亮
window["wx"].setKeepScreenOn({ keepScreenOn: true }); window["wx"].setKeepScreenOn({ keepScreenOn: true });
luffaSDK.g_InGameScene = window["wx"].getLaunchOptionsSync().scene; luffaSDK.g_InGameScene = window["wx"].getLaunchOptionsSync().scene;
console.log("init luffa - 进入游戏的场景值", luffaSDK.g_InGameScene); logger.log("init luffa - 进入游戏的场景值", luffaSDK.g_InGameScene);
//this.init_video(); //初始化视频广告 //this.init_video(); //初始化视频广告
//this.init_splash(); //初始化插屏广告 //this.init_splash(); //初始化插屏广告
@@ -50,7 +51,7 @@ export class luffaSDK {
checkAutoSetting(autoKey: string, cb: Function = null) { checkAutoSetting(autoKey: string, cb: Function = null) {
window["wx"].getSetting({ window["wx"].getSetting({
success(res: any) { success(res: any) {
console.log("微信 - 检测权限状态 succ:", JSON.stringify(res)); logger.log("微信 - 检测权限状态 succ:", JSON.stringify(res));
if (autoKey == "userInfo" && res.authSetting["scope.userInfo"]) { if (autoKey == "userInfo" && res.authSetting["scope.userInfo"]) {
cb && cb(true); cb && cb(true);
} else { } else {
@@ -58,7 +59,7 @@ export class luffaSDK {
} }
}, },
fail(res: any) { fail(res: any) {
console.log("微信 - 检测权限状态 fail:", JSON.stringify(res)); logger.log("微信 - 检测权限状态 fail:", JSON.stringify(res));
cb && cb(false); cb && cb(false);
}, },
}); });
@@ -68,11 +69,11 @@ export class luffaSDK {
* 获取个人信息 * 获取个人信息
*/ */
getUserInfo(cb: I_SDK_UserInfo_Callback = null) { getUserInfo(cb: I_SDK_UserInfo_Callback = null) {
console.log("微信 - 正在获取用户信息..."); logger.log("微信 - 正在获取用户信息...");
var self = this; var self = this;
window["wx"].getUserInfo({ window["wx"].getUserInfo({
success: (res) => { success: (res) => {
console.log("微信 - 获取用户信息成功:", res); logger.log("微信 - 获取用户信息成功:", res);
cb && cb &&
cb({ cb({
avatarUrl: res.userInfo.avatarUrl, avatarUrl: res.userInfo.avatarUrl,
@@ -80,7 +81,7 @@ export class luffaSDK {
}); });
}, },
fail: (err) => { fail: (err) => {
console.log("微信 - 获取用户信息失败:", err); logger.log("微信 - 获取用户信息失败:", err);
self.openUserAuthorize(cb); self.openUserAuthorize(cb);
}, },
}); });
@@ -91,7 +92,7 @@ export class luffaSDK {
window["wx"].getSetting({ window["wx"].getSetting({
scope: "scope.userInfo", scope: "scope.userInfo",
success(res: any) { success(res: any) {
console.log("微信 authorize succ:", JSON.stringify(res)); logger.log("微信 authorize succ:", JSON.stringify(res));
if (res.authSetting["scope.userInfo"]) { if (res.authSetting["scope.userInfo"]) {
self.getUserInfo(cb); self.getUserInfo(cb);
@@ -110,21 +111,21 @@ export class luffaSDK {
textAlign: "center", textAlign: "center",
}, },
}); });
console.log("微信 点击开始游戏授权用户信息"); logger.log("微信 点击开始游戏授权用户信息");
button.onTap((res) => { button.onTap((res) => {
button.destroy(); button.destroy();
// if (res.userInfo) { // if (res.userInfo) {
// console.log(res.userInfo) // logger.log(res.userInfo)
// //此时可进行登录操作 // //此时可进行登录操作
// cb && cb(res.userInfo) // cb && cb(res.userInfo)
// } // }
console.log("微信 点击Tap", res); logger.log("微信 点击Tap", res);
self.getUserInfo(cb); self.getUserInfo(cb);
}); });
} }
}, },
fail(err) { fail(err) {
console.log("微信 - authorize fail", err); logger.log("微信 - authorize fail", err);
}, },
}); });
} }
@@ -134,16 +135,16 @@ export class luffaSDK {
window["wx"].login({ window["wx"].login({
success: (res) => { success: (res) => {
if (res.code) { if (res.code) {
console.log("微信 - 登录成功", res.code); logger.log("微信 - 登录成功", res.code);
cb && cb({ platform: 1, code: res.code }); cb && cb({ platform: 1, code: res.code });
} else { } else {
console.log("微信 - 登录失败", res.errMsg); logger.log("微信 - 登录失败", res.errMsg);
cb && cb({ platform: 1, code: null }); cb && cb({ platform: 1, code: null });
} }
}, },
fail(res: any) { fail(res: any) {
console.log(`微信 login 调用失败`); logger.log(`微信 login 调用失败`);
console.log(res.anonymousCode); logger.log(res.anonymousCode);
cb && cb({ platform: 1, code: null }); cb && cb({ platform: 1, code: null });
}, },
}); });
@@ -152,7 +153,7 @@ export class luffaSDK {
//初始化视频广告 //初始化视频广告
private init_video() { private init_video() {
if ((wx_video_ad_unit_id as any) == "test") { if ((wx_video_ad_unit_id as any) == "test") {
console.log("微信 激励广告id未配置,跳过此类型初始化"); logger.log("微信 激励广告id未配置,跳过此类型初始化");
return; return;
} }
@@ -161,13 +162,13 @@ export class luffaSDK {
disableFallbackSharePage: true, // 是否禁用分享页,默认为false disableFallbackSharePage: true, // 是否禁用分享页,默认为false
}); });
this.wx_video.onLoad(() => { this.wx_video.onLoad(() => {
console.log("onLoad event emit"); logger.log("onLoad event emit");
}); });
this.wx_video.onError((err) => { this.wx_video.onError((err) => {
console.log("onError event emit", err); logger.log("onError event emit", err);
}); });
this.wx_video.onClose((res) => { this.wx_video.onClose((res) => {
console.log("onClose event emit", res); logger.log("onClose event emit", res);
// 用户点击了【关闭广告】按钮 // 用户点击了【关闭广告】按钮
// 小于 2.1.0 的基础库版本,res 是一个 undefined // 小于 2.1.0 的基础库版本,res 是一个 undefined
if ((res && res.isEnded) || res === undefined) { if ((res && res.isEnded) || res === undefined) {
@@ -186,7 +187,7 @@ export class luffaSDK {
//初始化插屏广告 //初始化插屏广告
private init_splash() { private init_splash() {
if ((wx_splash_ad_unit_id as any) == "test") { if ((wx_splash_ad_unit_id as any) == "test") {
console.log("微信 插屏广告id未配置,跳过此类型初始化"); logger.log("微信 插屏广告id未配置,跳过此类型初始化");
return; return;
} }
// 创建插屏广告实例,提前初始化 // 创建插屏广告实例,提前初始化
@@ -195,13 +196,13 @@ export class luffaSDK {
adUnitId: wx_splash_ad_unit_id, adUnitId: wx_splash_ad_unit_id,
}); });
this.wx_splash.onLoad(() => { this.wx_splash.onLoad(() => {
console.log("splash onLoad event emit"); logger.log("splash onLoad event emit");
}); });
this.wx_splash.onError((err) => { this.wx_splash.onError((err) => {
console.log("splash onError event emit", err); logger.log("splash onError event emit", err);
}); });
this.wx_splash.onClose((res) => { this.wx_splash.onClose((res) => {
console.log("splash onClose event emit", res); logger.log("splash onClose event emit", res);
}); });
} }
} }
@@ -209,7 +210,7 @@ export class luffaSDK {
//初始化Banner //初始化Banner
private init_banner() { private init_banner() {
if ((wx_banner_ad_unit_id as any) == "test") { if ((wx_banner_ad_unit_id as any) == "test") {
console.log("微信 横幅广告id未配置,跳过此类型初始化"); logger.log("微信 横幅广告id未配置,跳过此类型初始化");
return; return;
} }
let winSize = window["wx"].getSystemInfoSync(); let winSize = window["wx"].getSystemInfoSync();
@@ -237,7 +238,7 @@ export class luffaSDK {
//显示视频广告 //显示视频广告
show_video(callback: Function, tag: number) { show_video(callback: Function, tag: number) {
if ((wx_video_ad_unit_id as any) == "test") { if ((wx_video_ad_unit_id as any) == "test") {
console.log("未接入广告ID,视频广告请求直接返回"); logger.log("未接入广告ID,视频广告请求直接返回");
callback && callback(); callback && callback();
SDKManager.video_ad_back(); SDKManager.video_ad_back();
return; return;
@@ -271,7 +272,7 @@ export class luffaSDK {
this.wx_splash.show(); this.wx_splash.show();
}) })
.catch((err) => { .catch((err) => {
console.log(err); logger.log(err);
}); });
} }
} }
@@ -385,7 +386,7 @@ export class luffaSDK {
let picmap = this.SharePicAry[rand1]; let picmap = this.SharePicAry[rand1];
let rand2 = Utils.getRandomInt(0, this.ShareTextAry.length - 1); let rand2 = Utils.getRandomInt(0, this.ShareTextAry.length - 1);
let text = this.ShareTextAry[rand2]; let text = this.ShareTextAry[rand2];
console.log("分享:", rand1, rand2); logger.log("分享:", rand1, rand2);
return { return {
title: text, title: text,
query: "ShareCode=" + "user_default", //ModelPlayer.I.getPlayerId(), query: "ShareCode=" + "user_default", //ModelPlayer.I.getPlayerId(),
@@ -395,7 +396,7 @@ export class luffaSDK {
} }
//主动拉起分享 //主动拉起分享
show_share(rewardCB?: Function) { show_share(rewardCB?: Function) {
console.log("主动拉起分享"); logger.log("主动拉起分享");
let info: any = this.shareInfo(); let info: any = this.shareInfo();
info.succ = rewardCB; info.succ = rewardCB;
info.fail = null; info.fail = null;
@@ -411,7 +412,7 @@ export class luffaSDK {
//显示游戏圈 //显示游戏圈
show_gameClub(leftRatio, topRatio, widthRatio, heightRatio) { show_gameClub(leftRatio, topRatio, widthRatio, heightRatio) {
console.log("显示游戏圈"); logger.log("显示游戏圈");
if (this.wx_gameClub) { if (this.wx_gameClub) {
this.wx_gameClub.show(); this.wx_gameClub.show();
} else { } else {
@@ -421,7 +422,7 @@ export class luffaSDK {
let w = windowinfo.screenWidth * widthRatio; //按钮宽高 let w = windowinfo.screenWidth * widthRatio; //按钮宽高
let h = windowinfo.screenHeight * heightRatio; let h = windowinfo.screenHeight * heightRatio;
console.log( logger.log(
"游戏圈按钮配置:", "游戏圈按钮配置:",
windowinfo, windowinfo,
leftRatio, leftRatio,
@@ -449,7 +450,7 @@ export class luffaSDK {
} }
//隐藏游戏圈 //隐藏游戏圈
hide_gameClub() { hide_gameClub() {
console.log("隐藏游戏圈"); logger.log("隐藏游戏圈");
if (this.wx_gameClub) { if (this.wx_gameClub) {
this.wx_gameClub.hide(); this.wx_gameClub.hide();
} }
@@ -465,7 +466,7 @@ export class luffaSDK {
private _iacIdx = 0; //音频播放索引 private _iacIdx = 0; //音频播放索引
playBase64Audio(base64, loop) { playBase64Audio(base64, loop) {
if (!this.checkSupportBase64Audio()) { if (!this.checkSupportBase64Audio()) {
console.log("微信平台不支持base64音频播放"); logger.log("微信平台不支持base64音频播放");
return; return;
} }
@@ -480,24 +481,24 @@ export class luffaSDK {
//1.删除上一个音频 //1.删除上一个音频
const lastPath = const lastPath =
window["wx"].env.USER_DATA_PATH + `/ordernew${self._iacIdx}.mp3`; window["wx"].env.USER_DATA_PATH + `/ordernew${self._iacIdx}.mp3`;
console.log("微信 正在删除上一个音频 ->", lastPath); logger.log("微信 正在删除上一个音频 ->", lastPath);
fs.removeSavedFile({ fs.removeSavedFile({
filePath: lastPath, filePath: lastPath,
success(res) { success(res) {
console.log("微信 删除上一个音频成功", res); logger.log("微信 删除上一个音频成功", res);
}, },
fail(err) { fail(err) {
console.log("微信 删除上一个音频失败", err); logger.log("微信 删除上一个音频失败", err);
}, },
complete(res) { complete(res) {
console.log("微信 删除上一个音频完成", res); logger.log("微信 删除上一个音频完成", res);
//2.保存当前音频 //2.保存当前音频
//这里需要每次保存时换一下名字的原因是:innerAudioContext设置路径时如果路径相同,会认为还是同一个音频,不会重新加载,所以需要每次保存时换一下名字 //这里需要每次保存时换一下名字的原因是:innerAudioContext设置路径时如果路径相同,会认为还是同一个音频,不会重新加载,所以需要每次保存时换一下名字
self._iacIdx++; self._iacIdx++;
const audioPath = const audioPath =
window["wx"].env.USER_DATA_PATH + `/ordernew${self._iacIdx}.mp3`; window["wx"].env.USER_DATA_PATH + `/ordernew${self._iacIdx}.mp3`;
console.log("微信 正在保存本次音频 ->", audioPath); logger.log("微信 正在保存本次音频 ->", audioPath);
fs.writeFile({ fs.writeFile({
filePath: audioPath, filePath: audioPath,
data: substring, data: substring,
@@ -507,18 +508,18 @@ export class luffaSDK {
self._innerAudioContext = window["wx"].createInnerAudioContext(); self._innerAudioContext = window["wx"].createInnerAudioContext();
// 添加播放结束的回调 // 添加播放结束的回调
self._innerAudioContext.onEnded(() => { self._innerAudioContext.onEnded(() => {
console.log("微信 AI语音播放结束"); logger.log("微信 AI语音播放结束");
self._innerAudioContext.stop(); // 使用 stop 方法停止音频并重置播放状态 self._innerAudioContext.stop(); // 使用 stop 方法停止音频并重置播放状态
self._innerAudioContext.destroy(); // 销毁音频实例 self._innerAudioContext.destroy(); // 销毁音频实例
self._innerAudioContext = null; self._innerAudioContext = null;
}); });
} }
console.log("微信 播放base64音频", audioPath); logger.log("微信 播放base64音频", audioPath);
self._innerAudioContext.src = audioPath; self._innerAudioContext.src = audioPath;
self._innerAudioContext.play(); // 开始播放音频 self._innerAudioContext.play(); // 开始播放音频
}, },
fail(err) { fail(err) {
console.log("微信 保存本次音频失败", err); logger.log("微信 保存本次音频失败", err);
}, },
}); });
}, },
@@ -533,7 +534,7 @@ export class luffaSDK {
//监听向微信后台请求检查更新结果事件。微信在小程序每次启动(包括热启动)时自动检查更新,不需由开发者主动触发。 //监听向微信后台请求检查更新结果事件。微信在小程序每次启动(包括热启动)时自动检查更新,不需由开发者主动触发。
updateManager.onCheckForUpdate((res) => { updateManager.onCheckForUpdate((res) => {
// 请求完新版本信息的回调 // 请求完新版本信息的回调
console.log("微信 检查是否有新版本:", res.hasUpdate); logger.log("微信 检查是否有新版本:", res.hasUpdate);
}); });
//监听小程序有版本更新事件。客户端主动触发下载(无需开发者触发),下载成功后回调 //监听小程序有版本更新事件。客户端主动触发下载(无需开发者触发),下载成功后回调
@@ -552,7 +553,7 @@ export class luffaSDK {
//监听小程序更新失败事件。小程序有新版本,客户端主动触发下载(无需开发者触发),下载失败(可能是网络原因等)时回调 //监听小程序更新失败事件。小程序有新版本,客户端主动触发下载(无需开发者触发),下载失败(可能是网络原因等)时回调
updateManager.onUpdateFailed(function (err) { updateManager.onUpdateFailed(function (err) {
console.log("微信 新版本下载失败", err); logger.log("微信 新版本下载失败", err);
}); });
} }
@@ -561,7 +562,7 @@ export class luffaSDK {
if (window["wx"].openCustomerServiceConversation) { if (window["wx"].openCustomerServiceConversation) {
return true; return true;
} }
console.log("微信 不支持联系客服"); logger.log("微信 不支持联系客服");
return false; return false;
} }
//进入联系客服 //进入联系客服
@@ -574,10 +575,10 @@ export class luffaSDK {
wx.openCustomerServiceConversation({ wx.openCustomerServiceConversation({
success: (res) => { success: (res) => {
const { path, query } = res; const { path, query } = res;
console.log("微信 进入客服成功", path, query); logger.log("微信 进入客服成功", path, query);
}, },
fail: (res) => { fail: (res) => {
console.log("微信 进入客服失败", res); logger.log("微信 进入客服失败", res);
}, },
}); });
} }
@@ -598,18 +599,18 @@ export class luffaSDK {
return; return;
} }
let self = this; let self = this;
console.log("微信 播放背景视频组件1", remoteUrl); logger.log("微信 播放背景视频组件1", remoteUrl);
this.curPlayType = vtype; this.curPlayType = vtype;
if (!this._bgVideo) { if (!this._bgVideo) {
this._bgVideo = this.createVideoHandle(); this._bgVideo = this.createVideoHandle();
// this._bgVideo.onPlay(() => { // this._bgVideo.onPlay(() => {
// console.log("微信 背景视频播放开始"); // logger.log("微信 背景视频播放开始");
// }) // })
this._bgVideo.onTimeUpdate((_tinfo: any) => { this._bgVideo.onTimeUpdate((_tinfo: any) => {
// console.log("微信 背景视频播放进度", self._bgShow, _tinfo); // logger.log("微信 背景视频播放进度", self._bgShow, _tinfo);
if (!self._bgShow) { if (!self._bgShow) {
if (_tinfo && _tinfo.position > 0.01) { if (_tinfo && _tinfo.position > 0.01) {
console.log("微信 背景视频1进入视野"); logger.log("微信 背景视频1进入视野");
self.videoMoveIn(self._bgVideo); self.videoMoveIn(self._bgVideo);
self._bgShow = true; self._bgShow = true;
self.removeBgAudioNext(); self.removeBgAudioNext();
@@ -645,19 +646,19 @@ export class luffaSDK {
extra: any = {} extra: any = {}
) { ) {
this.removeBgAudioNext(); this.removeBgAudioNext();
console.log("微信 创建背景视频组件2--->", remoteUrl); logger.log("微信 创建背景视频组件2--->", remoteUrl);
this.curPlayType = vtype; this.curPlayType = vtype;
let self = this; let self = this;
if (!this._bgTempVideo) { if (!this._bgTempVideo) {
this._bgTempVideo = this.createVideoHandle(); this._bgTempVideo = this.createVideoHandle();
// this._bgTempVideo.onPlay(() => { // this._bgTempVideo.onPlay(() => {
// console.log("微信 临时背景视频播放开始"); // logger.log("微信 临时背景视频播放开始");
// }) // })
this._bgTempVideo.onTimeUpdate((_tinfo: any) => { this._bgTempVideo.onTimeUpdate((_tinfo: any) => {
// console.log("微信 临时背景视频播放进度", self._bgTempShow, _tinfo); // logger.log("微信 临时背景视频播放进度", self._bgTempShow, _tinfo);
if (!self._bgTempShow) { if (!self._bgTempShow) {
if (_tinfo && _tinfo.position > 0.01) { if (_tinfo && _tinfo.position > 0.01) {
console.log("微信 背景视频2进入视野"); logger.log("微信 背景视频2进入视野");
self._bgTempShow = true; self._bgTempShow = true;
self.videoMoveIn(self._bgTempVideo); self.videoMoveIn(self._bgTempVideo);
self.removeBgAudio(); self.removeBgAudio();
@@ -698,18 +699,18 @@ export class luffaSDK {
return; return;
} }
let self = this; let self = this;
console.log("微信 播放emo视频1", remoteUrl); logger.log("微信 播放emo视频1", remoteUrl);
this.curPlayType = vtype; this.curPlayType = vtype;
if (!this._emoVideo) { if (!this._emoVideo) {
this._emoVideo = this.createVideoHandle(); this._emoVideo = this.createVideoHandle();
// this._emoVideo.onPlay(() => { // this._emoVideo.onPlay(() => {
// console.log("微信 背景视频播放开始"); // logger.log("微信 背景视频播放开始");
// }) // })
this._emoVideo.onTimeUpdate((_tinfo: any) => { this._emoVideo.onTimeUpdate((_tinfo: any) => {
// console.log("微信 背景视频播放进度", self._emoShow, _tinfo); // logger.log("微信 背景视频播放进度", self._emoShow, _tinfo);
if (!self._emoShow) { if (!self._emoShow) {
if (_tinfo && _tinfo.position > 0.01) { if (_tinfo && _tinfo.position > 0.01) {
console.log("微信 emo视频1准备好了"); logger.log("微信 emo视频1准备好了");
self._emoShow = true; self._emoShow = true;
self.removeEmoAudioNext(); self.removeEmoAudioNext();
self.setEmoReadyAudio(self._emoVideo); self.setEmoReadyAudio(self._emoVideo);
@@ -744,19 +745,19 @@ export class luffaSDK {
extra: any = {} extra: any = {}
) { ) {
this.removeEmoAudioNext(); this.removeEmoAudioNext();
console.log("微信 播放emo视频2--->", remoteUrl); logger.log("微信 播放emo视频2--->", remoteUrl);
this.curPlayType = vtype; this.curPlayType = vtype;
let self = this; let self = this;
if (!this._emoTempVideo) { if (!this._emoTempVideo) {
this._emoTempVideo = this.createVideoHandle(); this._emoTempVideo = this.createVideoHandle();
// this._emoTempVideo.onPlay(() => { // this._emoTempVideo.onPlay(() => {
// console.log("微信 临时背景视频播放开始"); // logger.log("微信 临时背景视频播放开始");
// }) // })
this._emoTempVideo.onTimeUpdate((_tinfo: any) => { this._emoTempVideo.onTimeUpdate((_tinfo: any) => {
// console.log("微信 临时背景视频播放进度", self._emoTempShow, _tinfo); // logger.log("微信 临时背景视频播放进度", self._emoTempShow, _tinfo);
if (!self._emoTempShow) { if (!self._emoTempShow) {
if (_tinfo && _tinfo.position > 0.01) { if (_tinfo && _tinfo.position > 0.01) {
console.log("微信 emo视频2已准备好"); logger.log("微信 emo视频2已准备好");
self._emoTempShow = true; self._emoTempShow = true;
self.removeEmoAudio(); self.removeEmoAudio();
self.setEmoReadyAudio(self._emoTempVideo); self.setEmoReadyAudio(self._emoTempVideo);
@@ -839,19 +840,19 @@ export class luffaSDK {
this.videoAdaInfo.x = -(this.videoWidth * ratioh - size.width) / 2; this.videoAdaInfo.x = -(this.videoWidth * ratioh - size.width) / 2;
this.videoAdaInfo.y = 0; this.videoAdaInfo.y = 0;
} }
console.log("微信 视频适配信息", this.videoAdaInfo, size); logger.log("微信 视频适配信息", this.videoAdaInfo, size);
return this.videoAdaInfo; return this.videoAdaInfo;
} }
//设置暂停播放的主视频 //设置暂停播放的主视频
private vpWait: any = null; private vpWait: any = null;
setBgAudioPause(wait: any) { setBgAudioPause(wait: any) {
console.log("微信 主视频暂停播放"); logger.log("微信 主视频暂停播放");
this.vpWait = wait; this.vpWait = wait;
this.vpWait.pause(); this.vpWait.pause();
} }
replayBgAudioPause() { replayBgAudioPause() {
console.log("微信 主视频继续播放"); logger.log("微信 主视频继续播放");
if (this.vpWait) { if (this.vpWait) {
this.vpWait.play(); this.vpWait.play();
} }
@@ -860,7 +861,7 @@ export class luffaSDK {
//设置准备好要播放的表情视频 //设置准备好要播放的表情视频
private emoReady: any = null; private emoReady: any = null;
setEmoReadyAudio(au: any) { setEmoReadyAudio(au: any) {
console.log("微信 设置emo ready视频"); logger.log("微信 设置emo ready视频");
if (this.emoReady) { if (this.emoReady) {
this.emoReady.stop(); this.emoReady.stop();
this.videoMoveOut(this.emoReady); this.videoMoveOut(this.emoReady);
@@ -870,7 +871,7 @@ export class luffaSDK {
} }
//移除准备好要播放的表情视频 //移除准备好要播放的表情视频
removeEmoReadyAudio() { removeEmoReadyAudio() {
console.log("微信 移除emo ready视频"); logger.log("微信 移除emo ready视频");
if (this.emoReady) { if (this.emoReady) {
this.emoReady.stop(); this.emoReady.stop();
this.videoMoveOut(this.emoReady); this.videoMoveOut(this.emoReady);
@@ -880,7 +881,7 @@ export class luffaSDK {
//播放准备好要播放的表情视频 //播放准备好要播放的表情视频
doPlayEmoReadyAudio(): boolean { doPlayEmoReadyAudio(): boolean {
if (this.emoReady) { if (this.emoReady) {
console.log("微信 播放emo ready视频"); logger.log("微信 播放emo ready视频");
this.emoReady.play(); this.emoReady.play();
this.videoMoveIn(this.emoReady); this.videoMoveIn(this.emoReady);
return true; return true;
@@ -889,7 +890,7 @@ export class luffaSDK {
} }
//表情视频播放结束 //表情视频播放结束
doEmoFinish() { doEmoFinish() {
console.log("微信emo ready视频播放结束"); logger.log("微信emo ready视频播放结束");
this.removeEmoReadyAudio(); this.removeEmoReadyAudio();
this.replayBgAudioPause(); this.replayBgAudioPause();
} }
@@ -897,44 +898,44 @@ export class luffaSDK {
//region 微信同声传译 //region 微信同声传译
// private rrmgr: any = null; // private rrmgr: any = null;
// startRecordRecognition() { // startRecordRecognition() {
// console.log("微信 同声传译111") // logger.log("微信 同声传译111")
// if (!this.rrmgr) { // if (!this.rrmgr) {
// const plugin = requirePlugin("WechatSI"); // const plugin = requirePlugin("WechatSI");
// this.rrmgr = plugin.getRecordRecognitionManager(); // this.rrmgr = plugin.getRecordRecognitionManager();
// console.log("微信 同声传译222") // logger.log("微信 同声传译222")
// // 监听识别结果 // // 监听识别结果
// this.rrmgr.onRecognize = (res) => { // this.rrmgr.onRecognize = (res) => {
// console.log("微信 同声传译识别结果:", res.result); // logger.log("微信 同声传译识别结果:", res.result);
// }; // };
// // 监听录音结束 // // 监听录音结束
// this.rrmgr.onStop = (res) => { // this.rrmgr.onStop = (res) => {
// console.log("微信 同声传译录音结束", res); // logger.log("微信 同声传译录音结束", res);
// }; // };
// } // }
// this.rrmgr.start({ lang: "zh_CN" }); // this.rrmgr.start({ lang: "zh_CN" });
// console.log("微信 同声传译333") // logger.log("微信 同声传译333")
// } // }
// stopRecordRecognition() { // stopRecordRecognition() {
// if (this.rrmgr) { // if (this.rrmgr) {
// this.rrmgr.stop(); // this.rrmgr.stop();
// console.log("微信 同声传译444") // logger.log("微信 同声传译444")
// } // }
// } // }
//region 复制到剪贴板 //region 复制到剪贴板
/**复制文本到剪贴板 */ /**复制文本到剪贴板 */
copyToClipboard(text: string, cb?: Function) { copyToClipboard(text: string, cb?: Function) {
console.log("微信 复制到剪贴板:", text); logger.log("微信 复制到剪贴板:", text);
window["wx"].setClipboardData({ window["wx"].setClipboardData({
data: text, data: text,
success: () => { success: () => {
console.log("微信 复制成功"); logger.log("微信 复制成功");
cb && cb(true); cb && cb(true);
}, },
fail: (err) => { fail: (err) => {
console.log("微信 复制失败:", err); logger.log("微信 复制失败:", err);
cb && cb(false); cb && cb(false);
}, },
}); });
@@ -950,7 +951,7 @@ export class luffaSDK {
// debug: true, // debug: true,
// uploadUserInfo: true, // 上传用户信息,上传后可以看到有用户头像和昵称的分享信息 // uploadUserInfo: true, // 上传用户信息,上传后可以看到有用户头像和昵称的分享信息
// }); // });
// console.log("微信 uma 初始化"); // logger.log("微信 uma 初始化");
} }
//友盟统计是否开启 //友盟统计是否开启
umaSwt() { umaSwt() {
@@ -959,6 +960,6 @@ export class luffaSDK {
//友盟事件统计 //友盟事件统计
umaEvent(eventName: string, value: any = {}) { umaEvent(eventName: string, value: any = {}) {
window["wx"].uma.trackEvent(eventName, value); window["wx"].uma.trackEvent(eventName, value);
console.log("微信 uma 统计:", eventName, value); logger.log("微信 uma 统计:", eventName, value);
} }
} }
+12 -11
View File
@@ -6,11 +6,12 @@ import { BgVideo } from "./BgVideo";
import Utils from "../Common/Utils"; import Utils from "../Common/Utils";
import { InnerMsgCode } from "../Config/InnerMsgCode"; import { InnerMsgCode } from "../Config/InnerMsgCode";
import { VideoRoleType } from "../Common/GlobalValue"; import { VideoRoleType } from "../Common/GlobalValue";
import { logger } from "db://assets/Scripts/Main/Common/Logger";
export class WebSDK { export class WebSDK {
//初始化 //初始化
init(cb: Function = null) { init(cb: Function = null) {
console.log("init webSDK"); logger.log("init webSDK");
cb && cb(); cb && cb();
} }
@@ -92,7 +93,7 @@ export class WebSDK {
// 创建音频 URL // 创建音频 URL
const audioUrl = URL.createObjectURL(audioBlob); const audioUrl = URL.createObjectURL(audioBlob);
console.log("web 播放base64音频", audioUrl); logger.log("web 播放base64音频", audioUrl);
// 创建音频元素并播放 // 创建音频元素并播放
if (this._audioInst == null) { if (this._audioInst == null) {
this._audioInst = new Audio(audioUrl); this._audioInst = new Audio(audioUrl);
@@ -104,12 +105,12 @@ export class WebSDK {
//客服功能是否支持 //客服功能是否支持
kefuSupport() { kefuSupport() {
console.log("web 不支持联系客服"); logger.log("web 不支持联系客服");
return false; return false;
} }
//进入联系客服 //进入联系客服
openKefu() { openKefu() {
console.log("web 进入联系客服"); logger.log("web 进入联系客服");
} }
//region 播放主背景视频 //region 播放主背景视频
@@ -147,7 +148,7 @@ export class WebSDK {
return; return;
} }
console.log("web 初始化主背景视频"); logger.log("web 初始化主背景视频");
if (!this.zhuVideo1) { if (!this.zhuVideo1) {
this.zhuVideo1 = bgvideo.getVideoClone(); this.zhuVideo1 = bgvideo.getVideoClone();
this.zhuVideo1.remoteUrl = this.zhuVideo1.remoteUrl =
@@ -323,18 +324,18 @@ export class WebSDK {
//region 复制到剪贴板 //region 复制到剪贴板
/**复制文本到剪贴板 */ /**复制文本到剪贴板 */
copyToClipboard(text: string, cb?: Function) { copyToClipboard(text: string, cb?: Function) {
console.log("web 复制到剪贴板:", text); logger.log("web 复制到剪贴板:", text);
if (navigator.clipboard && window.isSecureContext) { if (navigator.clipboard && window.isSecureContext) {
// 使用现代的 Clipboard API // 使用现代的 Clipboard API
navigator.clipboard navigator.clipboard
.writeText(text) .writeText(text)
.then(() => { .then(() => {
console.log("web 复制成功 (Clipboard API)"); logger.log("web 复制成功 (Clipboard API)");
cb && cb(true); cb && cb(true);
}) })
.catch((err) => { .catch((err) => {
console.log("web 复制失败 (Clipboard API)", err); logger.log("web 复制失败 (Clipboard API)", err);
this.fallbackCopyToClipboard(text, cb); this.fallbackCopyToClipboard(text, cb);
}); });
} else { } else {
@@ -361,14 +362,14 @@ export class WebSDK {
try { try {
const successful = document.execCommand("copy"); const successful = document.execCommand("copy");
if (successful) { if (successful) {
console.log("web 复制成功 (fallback)"); logger.log("web 复制成功 (fallback)");
cb && cb(true); cb && cb(true);
} else { } else {
console.log("web 复制失败 (fallback)"); logger.log("web 复制失败 (fallback)");
cb && cb(false); cb && cb(false);
} }
} catch (err) { } catch (err) {
console.log("web 复制异常 (fallback)", err); logger.log("web 复制异常 (fallback)", err);
cb && cb(false); cb && cb(false);
} }
+83 -82
View File
@@ -5,6 +5,7 @@ import { I_SDK_UserInfo_Callback, SDKManager } from "./SDKManager";
import Utils from "../Common/Utils"; import Utils from "../Common/Utils";
import uma from "../../../utils/uma.wx.min.js"; import uma from "../../../utils/uma.wx.min.js";
import { InnerMsgCode } from "../Config/InnerMsgCode"; import { InnerMsgCode } from "../Config/InnerMsgCode";
import { logger } from "db://assets/Scripts/Main/Common/Logger";
//广告ID //广告ID
const wx_banner_ad_unit_id = "test"; const wx_banner_ad_unit_id = "test";
@@ -35,7 +36,7 @@ export class WXSDK {
// 保持屏幕常亮 // 保持屏幕常亮
window["wx"].setKeepScreenOn({ keepScreenOn: true }); window["wx"].setKeepScreenOn({ keepScreenOn: true });
WXSDK.g_InGameScene = window["wx"].getLaunchOptionsSync().scene; WXSDK.g_InGameScene = window["wx"].getLaunchOptionsSync().scene;
console.log("init 微信 - 进入游戏的场景值", WXSDK.g_InGameScene); logger.log("init 微信 - 进入游戏的场景值", WXSDK.g_InGameScene);
//显示分享按钮 //显示分享按钮
window["wx"].showShareMenu({ window["wx"].showShareMenu({
@@ -55,7 +56,7 @@ export class WXSDK {
window["wx"].onHide(() => { window["wx"].onHide(() => {
if (this.ShareCb) { if (this.ShareCb) {
this.ShareSTime = new Date().getTime(); this.ShareSTime = new Date().getTime();
console.log("分享时间差 记录:", this.ShareSTime); logger.log("分享时间差 记录:", this.ShareSTime);
} }
}); });
@@ -68,7 +69,7 @@ export class WXSDK {
//小游戏回到前台 //小游戏回到前台
onWxShow(data: any) { onWxShow(data: any) {
console.log("onWxShow:" + JSON.stringify(data)); logger.log("onWxShow:" + JSON.stringify(data));
//返回小游戏场景值 //返回小游戏场景值
if (data && data.query && data.query.ShareCode) { if (data && data.query && data.query.ShareCode) {
GlobalValue.ShareTocusid = data.query.ShareCode; GlobalValue.ShareTocusid = data.query.ShareCode;
@@ -77,7 +78,7 @@ export class WXSDK {
if (this.ShareCb) { if (this.ShareCb) {
if (this.ShareSTime) { if (this.ShareSTime) {
let nT = new Date().getTime(); let nT = new Date().getTime();
console.log("分享时间差 计算:", nT, this.ShareSTime); logger.log("分享时间差 计算:", nT, this.ShareSTime);
if (nT - this.ShareSTime > 1500) { if (nT - this.ShareSTime > 1500) {
let cb = this.ShareCb.succ; let cb = this.ShareCb.succ;
cb && cb(); cb && cb();
@@ -104,7 +105,7 @@ export class WXSDK {
checkAutoSetting(autoKey: string, cb: Function = null) { checkAutoSetting(autoKey: string, cb: Function = null) {
window["wx"].getSetting({ window["wx"].getSetting({
success(res: any) { success(res: any) {
console.log("微信 - 检测权限状态 succ:", JSON.stringify(res)); logger.log("微信 - 检测权限状态 succ:", JSON.stringify(res));
if (autoKey == "userInfo" && res.authSetting["scope.userInfo"]) { if (autoKey == "userInfo" && res.authSetting["scope.userInfo"]) {
cb && cb(true); cb && cb(true);
} else { } else {
@@ -112,7 +113,7 @@ export class WXSDK {
} }
}, },
fail(res: any) { fail(res: any) {
console.log("微信 - 检测权限状态 fail:", JSON.stringify(res)); logger.log("微信 - 检测权限状态 fail:", JSON.stringify(res));
cb && cb(false); cb && cb(false);
}, },
}); });
@@ -122,11 +123,11 @@ export class WXSDK {
* 获取个人信息 * 获取个人信息
*/ */
getUserInfo(cb: I_SDK_UserInfo_Callback = null) { getUserInfo(cb: I_SDK_UserInfo_Callback = null) {
console.log("微信 - 正在获取用户信息..."); logger.log("微信 - 正在获取用户信息...");
var self = this; var self = this;
window["wx"].getUserInfo({ window["wx"].getUserInfo({
success: (res) => { success: (res) => {
console.log("微信 - 获取用户信息成功:", res); logger.log("微信 - 获取用户信息成功:", res);
cb && cb &&
cb({ cb({
avatarUrl: res.userInfo.avatarUrl, avatarUrl: res.userInfo.avatarUrl,
@@ -134,7 +135,7 @@ export class WXSDK {
}); });
}, },
fail: (err) => { fail: (err) => {
console.log("微信 - 获取用户信息失败:", err); logger.log("微信 - 获取用户信息失败:", err);
self.openUserAuthorize(cb); self.openUserAuthorize(cb);
}, },
}); });
@@ -145,7 +146,7 @@ export class WXSDK {
window["wx"].getSetting({ window["wx"].getSetting({
scope: "scope.userInfo", scope: "scope.userInfo",
success(res: any) { success(res: any) {
console.log("微信 authorize succ:", JSON.stringify(res)); logger.log("微信 authorize succ:", JSON.stringify(res));
if (res.authSetting["scope.userInfo"]) { if (res.authSetting["scope.userInfo"]) {
self.getUserInfo(cb); self.getUserInfo(cb);
@@ -164,21 +165,21 @@ export class WXSDK {
textAlign: "center", textAlign: "center",
}, },
}); });
console.log("微信 点击开始游戏授权用户信息"); logger.log("微信 点击开始游戏授权用户信息");
button.onTap((res) => { button.onTap((res) => {
button.destroy(); button.destroy();
// if (res.userInfo) { // if (res.userInfo) {
// console.log(res.userInfo) // logger.log(res.userInfo)
// //此时可进行登录操作 // //此时可进行登录操作
// cb && cb(res.userInfo) // cb && cb(res.userInfo)
// } // }
console.log("微信 点击Tap", res); logger.log("微信 点击Tap", res);
self.getUserInfo(cb); self.getUserInfo(cb);
}); });
} }
}, },
fail(err) { fail(err) {
console.log("微信 - authorize fail", err); logger.log("微信 - authorize fail", err);
}, },
}); });
} }
@@ -188,16 +189,16 @@ export class WXSDK {
window["wx"].login({ window["wx"].login({
success: (res) => { success: (res) => {
if (res.code) { if (res.code) {
console.log("微信 - 登录成功", res.code); logger.log("微信 - 登录成功", res.code);
cb && cb({ platform: 1, code: res.code }); cb && cb({ platform: 1, code: res.code });
} else { } else {
console.log("微信 - 登录失败", res.errMsg); logger.log("微信 - 登录失败", res.errMsg);
cb && cb({ platform: 1, code: null }); cb && cb({ platform: 1, code: null });
} }
}, },
fail(res: any) { fail(res: any) {
console.log(`微信 login 调用失败`); logger.log(`微信 login 调用失败`);
console.log(res.anonymousCode); logger.log(res.anonymousCode);
cb && cb({ platform: 1, code: null }); cb && cb({ platform: 1, code: null });
}, },
}); });
@@ -206,7 +207,7 @@ export class WXSDK {
//初始化视频广告 //初始化视频广告
private init_video() { private init_video() {
if ((wx_video_ad_unit_id as any) == "test") { if ((wx_video_ad_unit_id as any) == "test") {
console.log("微信 激励广告id未配置,跳过此类型初始化"); logger.log("微信 激励广告id未配置,跳过此类型初始化");
return; return;
} }
@@ -215,13 +216,13 @@ export class WXSDK {
disableFallbackSharePage: true, // 是否禁用分享页,默认为false disableFallbackSharePage: true, // 是否禁用分享页,默认为false
}); });
this.wx_video.onLoad(() => { this.wx_video.onLoad(() => {
console.log("onLoad event emit"); logger.log("onLoad event emit");
}); });
this.wx_video.onError((err) => { this.wx_video.onError((err) => {
console.log("onError event emit", err); logger.log("onError event emit", err);
}); });
this.wx_video.onClose((res) => { this.wx_video.onClose((res) => {
console.log("onClose event emit", res); logger.log("onClose event emit", res);
// 用户点击了【关闭广告】按钮 // 用户点击了【关闭广告】按钮
// 小于 2.1.0 的基础库版本,res 是一个 undefined // 小于 2.1.0 的基础库版本,res 是一个 undefined
if ((res && res.isEnded) || res === undefined) { if ((res && res.isEnded) || res === undefined) {
@@ -240,7 +241,7 @@ export class WXSDK {
//初始化插屏广告 //初始化插屏广告
private init_splash() { private init_splash() {
if ((wx_splash_ad_unit_id as any) == "test") { if ((wx_splash_ad_unit_id as any) == "test") {
console.log("微信 插屏广告id未配置,跳过此类型初始化"); logger.log("微信 插屏广告id未配置,跳过此类型初始化");
return; return;
} }
// 创建插屏广告实例,提前初始化 // 创建插屏广告实例,提前初始化
@@ -249,13 +250,13 @@ export class WXSDK {
adUnitId: wx_splash_ad_unit_id, adUnitId: wx_splash_ad_unit_id,
}); });
this.wx_splash.onLoad(() => { this.wx_splash.onLoad(() => {
console.log("splash onLoad event emit"); logger.log("splash onLoad event emit");
}); });
this.wx_splash.onError((err) => { this.wx_splash.onError((err) => {
console.log("splash onError event emit", err); logger.log("splash onError event emit", err);
}); });
this.wx_splash.onClose((res) => { this.wx_splash.onClose((res) => {
console.log("splash onClose event emit", res); logger.log("splash onClose event emit", res);
}); });
} }
} }
@@ -263,7 +264,7 @@ export class WXSDK {
//初始化Banner //初始化Banner
private init_banner() { private init_banner() {
if ((wx_banner_ad_unit_id as any) == "test") { if ((wx_banner_ad_unit_id as any) == "test") {
console.log("微信 横幅广告id未配置,跳过此类型初始化"); logger.log("微信 横幅广告id未配置,跳过此类型初始化");
return; return;
} }
let winSize = window["wx"].getSystemInfoSync(); let winSize = window["wx"].getSystemInfoSync();
@@ -291,7 +292,7 @@ export class WXSDK {
//显示视频广告 //显示视频广告
show_video(callback: Function, tag: number) { show_video(callback: Function, tag: number) {
if ((wx_video_ad_unit_id as any) == "test") { if ((wx_video_ad_unit_id as any) == "test") {
console.log("未接入广告ID,视频广告请求直接返回"); logger.log("未接入广告ID,视频广告请求直接返回");
callback && callback(); callback && callback();
SDKManager.video_ad_back(); SDKManager.video_ad_back();
return; return;
@@ -325,7 +326,7 @@ export class WXSDK {
this.wx_splash.show(); this.wx_splash.show();
}) })
.catch((err) => { .catch((err) => {
console.log(err); logger.log(err);
}); });
} }
} }
@@ -439,7 +440,7 @@ export class WXSDK {
let picmap = this.SharePicAry[rand1]; let picmap = this.SharePicAry[rand1];
let rand2 = Utils.getRandomInt(0, this.ShareTextAry.length - 1); let rand2 = Utils.getRandomInt(0, this.ShareTextAry.length - 1);
let text = this.ShareTextAry[rand2]; let text = this.ShareTextAry[rand2];
console.log("分享:", rand1, rand2); logger.log("分享:", rand1, rand2);
return { return {
title: text, title: text,
query: "ShareCode=" + "user_default", //ModelPlayer.I.getPlayerId(), query: "ShareCode=" + "user_default", //ModelPlayer.I.getPlayerId(),
@@ -449,7 +450,7 @@ export class WXSDK {
} }
//主动拉起分享 //主动拉起分享
show_share(rewardCB?: Function) { show_share(rewardCB?: Function) {
console.log("主动拉起分享"); logger.log("主动拉起分享");
let info: any = this.shareInfo(); let info: any = this.shareInfo();
info.succ = rewardCB; info.succ = rewardCB;
info.fail = null; info.fail = null;
@@ -465,7 +466,7 @@ export class WXSDK {
//显示游戏圈 //显示游戏圈
show_gameClub(leftRatio, topRatio, widthRatio, heightRatio) { show_gameClub(leftRatio, topRatio, widthRatio, heightRatio) {
console.log("显示游戏圈"); logger.log("显示游戏圈");
if (this.wx_gameClub) { if (this.wx_gameClub) {
this.wx_gameClub.show(); this.wx_gameClub.show();
} else { } else {
@@ -475,7 +476,7 @@ export class WXSDK {
let w = windowinfo.screenWidth * widthRatio; //按钮宽高 let w = windowinfo.screenWidth * widthRatio; //按钮宽高
let h = windowinfo.screenHeight * heightRatio; let h = windowinfo.screenHeight * heightRatio;
console.log( logger.log(
"游戏圈按钮配置:", "游戏圈按钮配置:",
windowinfo, windowinfo,
leftRatio, leftRatio,
@@ -503,7 +504,7 @@ export class WXSDK {
} }
//隐藏游戏圈 //隐藏游戏圈
hide_gameClub() { hide_gameClub() {
console.log("隐藏游戏圈"); logger.log("隐藏游戏圈");
if (this.wx_gameClub) { if (this.wx_gameClub) {
this.wx_gameClub.hide(); this.wx_gameClub.hide();
} }
@@ -519,7 +520,7 @@ export class WXSDK {
private _iacIdx = 0; //音频播放索引 private _iacIdx = 0; //音频播放索引
playBase64Audio(base64, loop) { playBase64Audio(base64, loop) {
if (!this.checkSupportBase64Audio()) { if (!this.checkSupportBase64Audio()) {
console.log("微信平台不支持base64音频播放"); logger.log("微信平台不支持base64音频播放");
return; return;
} }
@@ -534,24 +535,24 @@ export class WXSDK {
//1.删除上一个音频 //1.删除上一个音频
const lastPath = const lastPath =
window["wx"].env.USER_DATA_PATH + `/ordernew${self._iacIdx}.mp3`; window["wx"].env.USER_DATA_PATH + `/ordernew${self._iacIdx}.mp3`;
console.log("微信 正在删除上一个音频 ->", lastPath); logger.log("微信 正在删除上一个音频 ->", lastPath);
fs.removeSavedFile({ fs.removeSavedFile({
filePath: lastPath, filePath: lastPath,
success(res) { success(res) {
console.log("微信 删除上一个音频成功", res); logger.log("微信 删除上一个音频成功", res);
}, },
fail(err) { fail(err) {
console.log("微信 删除上一个音频失败", err); logger.log("微信 删除上一个音频失败", err);
}, },
complete(res) { complete(res) {
console.log("微信 删除上一个音频完成", res); logger.log("微信 删除上一个音频完成", res);
//2.保存当前音频 //2.保存当前音频
//这里需要每次保存时换一下名字的原因是:innerAudioContext设置路径时如果路径相同,会认为还是同一个音频,不会重新加载,所以需要每次保存时换一下名字 //这里需要每次保存时换一下名字的原因是:innerAudioContext设置路径时如果路径相同,会认为还是同一个音频,不会重新加载,所以需要每次保存时换一下名字
self._iacIdx++; self._iacIdx++;
const audioPath = const audioPath =
window["wx"].env.USER_DATA_PATH + `/ordernew${self._iacIdx}.mp3`; window["wx"].env.USER_DATA_PATH + `/ordernew${self._iacIdx}.mp3`;
console.log("微信 正在保存本次音频 ->", audioPath); logger.log("微信 正在保存本次音频 ->", audioPath);
fs.writeFile({ fs.writeFile({
filePath: audioPath, filePath: audioPath,
data: substring, data: substring,
@@ -561,18 +562,18 @@ export class WXSDK {
self._innerAudioContext = window["wx"].createInnerAudioContext(); self._innerAudioContext = window["wx"].createInnerAudioContext();
// 添加播放结束的回调 // 添加播放结束的回调
self._innerAudioContext.onEnded(() => { self._innerAudioContext.onEnded(() => {
console.log("微信 AI语音播放结束"); logger.log("微信 AI语音播放结束");
self._innerAudioContext.stop(); // 使用 stop 方法停止音频并重置播放状态 self._innerAudioContext.stop(); // 使用 stop 方法停止音频并重置播放状态
self._innerAudioContext.destroy(); // 销毁音频实例 self._innerAudioContext.destroy(); // 销毁音频实例
self._innerAudioContext = null; self._innerAudioContext = null;
}); });
} }
console.log("微信 播放base64音频", audioPath); logger.log("微信 播放base64音频", audioPath);
self._innerAudioContext.src = audioPath; self._innerAudioContext.src = audioPath;
self._innerAudioContext.play(); // 开始播放音频 self._innerAudioContext.play(); // 开始播放音频
}, },
fail(err) { fail(err) {
console.log("微信 保存本次音频失败", err); logger.log("微信 保存本次音频失败", err);
}, },
}); });
}, },
@@ -587,7 +588,7 @@ export class WXSDK {
//监听向微信后台请求检查更新结果事件。微信在小程序每次启动(包括热启动)时自动检查更新,不需由开发者主动触发。 //监听向微信后台请求检查更新结果事件。微信在小程序每次启动(包括热启动)时自动检查更新,不需由开发者主动触发。
updateManager.onCheckForUpdate((res) => { updateManager.onCheckForUpdate((res) => {
// 请求完新版本信息的回调 // 请求完新版本信息的回调
console.log("微信 检查是否有新版本:", res.hasUpdate); logger.log("微信 检查是否有新版本:", res.hasUpdate);
}); });
//监听小程序有版本更新事件。客户端主动触发下载(无需开发者触发),下载成功后回调 //监听小程序有版本更新事件。客户端主动触发下载(无需开发者触发),下载成功后回调
@@ -606,7 +607,7 @@ export class WXSDK {
//监听小程序更新失败事件。小程序有新版本,客户端主动触发下载(无需开发者触发),下载失败(可能是网络原因等)时回调 //监听小程序更新失败事件。小程序有新版本,客户端主动触发下载(无需开发者触发),下载失败(可能是网络原因等)时回调
updateManager.onUpdateFailed(function (err) { updateManager.onUpdateFailed(function (err) {
console.log("微信 新版本下载失败", err); logger.log("微信 新版本下载失败", err);
}); });
} }
@@ -615,7 +616,7 @@ export class WXSDK {
if (window["wx"].openCustomerServiceConversation) { if (window["wx"].openCustomerServiceConversation) {
return true; return true;
} }
console.log("微信 不支持联系客服"); logger.log("微信 不支持联系客服");
return false; return false;
} }
//进入联系客服 //进入联系客服
@@ -628,10 +629,10 @@ export class WXSDK {
wx.openCustomerServiceConversation({ wx.openCustomerServiceConversation({
success: (res) => { success: (res) => {
const { path, query } = res; const { path, query } = res;
console.log("微信 进入客服成功", path, query); logger.log("微信 进入客服成功", path, query);
}, },
fail: (res) => { fail: (res) => {
console.log("微信 进入客服失败", res); logger.log("微信 进入客服失败", res);
}, },
}); });
} }
@@ -651,18 +652,18 @@ export class WXSDK {
return; return;
} }
let self = this; let self = this;
console.log("微信 播放背景视频组件1", remoteUrl); logger.log("微信 播放背景视频组件1", remoteUrl);
//this.curPlayType = vtype; //this.curPlayType = vtype;
if (!this._bgVideo) { if (!this._bgVideo) {
this._bgVideo = this.createVideoHandle(); this._bgVideo = this.createVideoHandle();
// this._bgVideo.onPlay(() => { // this._bgVideo.onPlay(() => {
// console.log("微信 背景视频播放开始"); // logger.log("微信 背景视频播放开始");
// }) // })
this._bgVideo.onTimeUpdate((_tinfo: any) => { this._bgVideo.onTimeUpdate((_tinfo: any) => {
// console.log("微信 背景视频播放进度", self._bgShow, _tinfo); // logger.log("微信 背景视频播放进度", self._bgShow, _tinfo);
if (!self._bgShow) { if (!self._bgShow) {
if (_tinfo && _tinfo.position > 0.01) { if (_tinfo && _tinfo.position > 0.01) {
console.log("微信 背景视频1进入视野"); logger.log("微信 背景视频1进入视野");
self.videoMoveIn(self._bgVideo); self.videoMoveIn(self._bgVideo);
self._bgShow = true; self._bgShow = true;
self.removeBgAudioNext(); self.removeBgAudioNext();
@@ -697,18 +698,18 @@ export class WXSDK {
extra: any = {} extra: any = {}
) { ) {
this.removeBgAudioNext(); this.removeBgAudioNext();
console.log("微信 创建背景视频组件2--->", remoteUrl); logger.log("微信 创建背景视频组件2--->", remoteUrl);
let self = this; let self = this;
if (!this._bgTempVideo) { if (!this._bgTempVideo) {
this._bgTempVideo = this.createVideoHandle(); this._bgTempVideo = this.createVideoHandle();
// this._bgTempVideo.onPlay(() => { // this._bgTempVideo.onPlay(() => {
// console.log("微信 临时背景视频播放开始"); // logger.log("微信 临时背景视频播放开始");
// }) // })
this._bgTempVideo.onTimeUpdate((_tinfo: any) => { this._bgTempVideo.onTimeUpdate((_tinfo: any) => {
// console.log("微信 临时背景视频播放进度", self._bgTempShow, _tinfo); // logger.log("微信 临时背景视频播放进度", self._bgTempShow, _tinfo);
if (!self._bgTempShow) { if (!self._bgTempShow) {
if (_tinfo && _tinfo.position > 0.01) { if (_tinfo && _tinfo.position > 0.01) {
console.log("微信 背景视频2进入视野"); logger.log("微信 背景视频2进入视野");
self._bgTempShow = true; self._bgTempShow = true;
self.videoMoveIn(self._bgTempVideo); self.videoMoveIn(self._bgTempVideo);
self.removeBgAudio(); self.removeBgAudio();
@@ -749,18 +750,18 @@ export class WXSDK {
return; return;
} }
let self = this; let self = this;
console.log("微信 播放emo视频1", remoteUrl); logger.log("微信 播放emo视频1", remoteUrl);
this.curPlayType = vtype; this.curPlayType = vtype;
if (!this._emoVideo) { if (!this._emoVideo) {
this._emoVideo = this.createVideoHandle(); this._emoVideo = this.createVideoHandle();
// this._emoVideo.onPlay(() => { // this._emoVideo.onPlay(() => {
// console.log("微信 背景视频播放开始"); // logger.log("微信 背景视频播放开始");
// }) // })
this._emoVideo.onTimeUpdate((_tinfo: any) => { this._emoVideo.onTimeUpdate((_tinfo: any) => {
// console.log("微信 背景视频播放进度", self._emoShow, _tinfo); // logger.log("微信 背景视频播放进度", self._emoShow, _tinfo);
if (!self._emoShow) { if (!self._emoShow) {
if (_tinfo && _tinfo.position > 0.01) { if (_tinfo && _tinfo.position > 0.01) {
console.log("微信 emo视频1准备好了"); logger.log("微信 emo视频1准备好了");
self._emoShow = true; self._emoShow = true;
self.removeEmoAudioNext(); self.removeEmoAudioNext();
self.setEmoReadyAudio(self._emoVideo); self.setEmoReadyAudio(self._emoVideo);
@@ -795,19 +796,19 @@ export class WXSDK {
extra: any = {} extra: any = {}
) { ) {
this.removeEmoAudioNext(); this.removeEmoAudioNext();
console.log("微信 播放emo视频2--->", remoteUrl); logger.log("微信 播放emo视频2--->", remoteUrl);
this.curPlayType = vtype; this.curPlayType = vtype;
let self = this; let self = this;
if (!this._emoTempVideo) { if (!this._emoTempVideo) {
this._emoTempVideo = this.createVideoHandle(); this._emoTempVideo = this.createVideoHandle();
// this._emoTempVideo.onPlay(() => { // this._emoTempVideo.onPlay(() => {
// console.log("微信 临时背景视频播放开始"); // logger.log("微信 临时背景视频播放开始");
// }) // })
this._emoTempVideo.onTimeUpdate((_tinfo: any) => { this._emoTempVideo.onTimeUpdate((_tinfo: any) => {
// console.log("微信 临时背景视频播放进度", self._emoTempShow, _tinfo); // logger.log("微信 临时背景视频播放进度", self._emoTempShow, _tinfo);
if (!self._emoTempShow) { if (!self._emoTempShow) {
if (_tinfo && _tinfo.position > 0.01) { if (_tinfo && _tinfo.position > 0.01) {
console.log("微信 emo视频2已准备好"); logger.log("微信 emo视频2已准备好");
self._emoTempShow = true; self._emoTempShow = true;
self.removeEmoAudio(); self.removeEmoAudio();
self.setEmoReadyAudio(self._emoTempVideo); self.setEmoReadyAudio(self._emoTempVideo);
@@ -890,19 +891,19 @@ export class WXSDK {
this.videoAdaInfo.x = -(this.videoWidth * ratioh - size.width) / 2; this.videoAdaInfo.x = -(this.videoWidth * ratioh - size.width) / 2;
this.videoAdaInfo.y = 0; this.videoAdaInfo.y = 0;
} }
console.log("微信 视频适配信息", this.videoAdaInfo, size); logger.log("微信 视频适配信息", this.videoAdaInfo, size);
return this.videoAdaInfo; return this.videoAdaInfo;
} }
//设置暂停播放的主视频 //设置暂停播放的主视频
private vpWait: any = null; private vpWait: any = null;
setBgAudioPause(wait: any) { setBgAudioPause(wait: any) {
console.log("微信 主视频暂停播放"); logger.log("微信 主视频暂停播放");
this.vpWait = wait; this.vpWait = wait;
this.vpWait.pause(); this.vpWait.pause();
} }
replayBgAudioPause() { replayBgAudioPause() {
console.log("微信 主视频继续播放"); logger.log("微信 主视频继续播放");
if (this.vpWait) { if (this.vpWait) {
this.vpWait.play(); this.vpWait.play();
} }
@@ -911,7 +912,7 @@ export class WXSDK {
//设置准备好要播放的表情视频 //设置准备好要播放的表情视频
private emoReady: any = null; private emoReady: any = null;
setEmoReadyAudio(au: any) { setEmoReadyAudio(au: any) {
console.log("微信 设置emo ready视频"); logger.log("微信 设置emo ready视频");
if (this.emoReady) { if (this.emoReady) {
this.emoReady.stop(); this.emoReady.stop();
this.videoMoveOut(this.emoReady); this.videoMoveOut(this.emoReady);
@@ -921,7 +922,7 @@ export class WXSDK {
} }
//移除准备好要播放的表情视频 //移除准备好要播放的表情视频
removeEmoReadyAudio() { removeEmoReadyAudio() {
console.log("微信 移除emo ready视频"); logger.log("微信 移除emo ready视频");
if (this.emoReady) { if (this.emoReady) {
this.emoReady.stop(); this.emoReady.stop();
this.videoMoveOut(this.emoReady); this.videoMoveOut(this.emoReady);
@@ -931,7 +932,7 @@ export class WXSDK {
//播放准备好要播放的表情视频 //播放准备好要播放的表情视频
doPlayEmoReadyAudio(): boolean { doPlayEmoReadyAudio(): boolean {
if (this.emoReady) { if (this.emoReady) {
console.log("微信 播放emo ready视频"); logger.log("微信 播放emo ready视频");
this.emoReady.play(); this.emoReady.play();
this.videoMoveIn(this.emoReady); this.videoMoveIn(this.emoReady);
return true; return true;
@@ -940,7 +941,7 @@ export class WXSDK {
} }
//表情视频播放结束 //表情视频播放结束
doEmoFinish() { doEmoFinish() {
console.log("微信emo ready视频播放结束"); logger.log("微信emo ready视频播放结束");
this.removeEmoReadyAudio(); this.removeEmoReadyAudio();
this.replayBgAudioPause(); this.replayBgAudioPause();
} }
@@ -948,44 +949,44 @@ export class WXSDK {
//region 微信同声传译 //region 微信同声传译
// private rrmgr: any = null; // private rrmgr: any = null;
// startRecordRecognition() { // startRecordRecognition() {
// console.log("微信 同声传译111") // logger.log("微信 同声传译111")
// if (!this.rrmgr) { // if (!this.rrmgr) {
// const plugin = requirePlugin("WechatSI"); // const plugin = requirePlugin("WechatSI");
// this.rrmgr = plugin.getRecordRecognitionManager(); // this.rrmgr = plugin.getRecordRecognitionManager();
// console.log("微信 同声传译222") // logger.log("微信 同声传译222")
// // 监听识别结果 // // 监听识别结果
// this.rrmgr.onRecognize = (res) => { // this.rrmgr.onRecognize = (res) => {
// console.log("微信 同声传译识别结果:", res.result); // logger.log("微信 同声传译识别结果:", res.result);
// }; // };
// // 监听录音结束 // // 监听录音结束
// this.rrmgr.onStop = (res) => { // this.rrmgr.onStop = (res) => {
// console.log("微信 同声传译录音结束", res); // logger.log("微信 同声传译录音结束", res);
// }; // };
// } // }
// this.rrmgr.start({ lang: "zh_CN" }); // this.rrmgr.start({ lang: "zh_CN" });
// console.log("微信 同声传译333") // logger.log("微信 同声传译333")
// } // }
// stopRecordRecognition() { // stopRecordRecognition() {
// if (this.rrmgr) { // if (this.rrmgr) {
// this.rrmgr.stop(); // this.rrmgr.stop();
// console.log("微信 同声传译444") // logger.log("微信 同声传译444")
// } // }
// } // }
//region 复制到剪贴板 //region 复制到剪贴板
/**复制文本到剪贴板 */ /**复制文本到剪贴板 */
copyToClipboard(text: string, cb?: Function) { copyToClipboard(text: string, cb?: Function) {
console.log("微信 复制到剪贴板:", text); logger.log("微信 复制到剪贴板:", text);
window["wx"].setClipboardData({ window["wx"].setClipboardData({
data: text, data: text,
success: () => { success: () => {
console.log("微信 复制成功"); logger.log("微信 复制成功");
cb && cb(true); cb && cb(true);
}, },
fail: (err) => { fail: (err) => {
console.log("微信 复制失败:", err); logger.log("微信 复制失败:", err);
cb && cb(false); cb && cb(false);
}, },
}); });
@@ -1001,7 +1002,7 @@ export class WXSDK {
debug: true, debug: true,
uploadUserInfo: true, // 上传用户信息,上传后可以看到有用户头像和昵称的分享信息 uploadUserInfo: true, // 上传用户信息,上传后可以看到有用户头像和昵称的分享信息
}); });
console.log("微信 uma 初始化"); logger.log("微信 uma 初始化");
} }
//友盟统计是否开启 //友盟统计是否开启
umaSwt() { umaSwt() {
@@ -1010,6 +1011,6 @@ export class WXSDK {
//友盟事件统计 //友盟事件统计
umaEvent(eventName: string, value: any = {}) { umaEvent(eventName: string, value: any = {}) {
window["wx"].uma.trackEvent(eventName, value); window["wx"].uma.trackEvent(eventName, value);
console.log("微信 uma 统计:", eventName, value); logger.log("微信 uma 统计:", eventName, value);
} }
} }
+7 -6
View File
@@ -13,6 +13,7 @@ import {
} from "cc"; } from "cc";
import li_EventManager from "./li_EventManager"; import li_EventManager from "./li_EventManager";
import LanguageUtils from "./LanguageUtils"; import LanguageUtils from "./LanguageUtils";
import { logger } from "db://assets/Scripts/Main/Common/Logger";
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@@ -22,21 +23,21 @@ export default class Utils {
public static Log(msg: string | any, ...subst: any[]) { public static Log(msg: string | any, ...subst: any[]) {
let IsLocalCSChanel = true; let IsLocalCSChanel = true;
if (IsLocalCSChanel) { if (IsLocalCSChanel) {
console.log(msg, subst); logger.log(msg, subst);
} }
} }
//警告日志 //警告日志
public static Warning(msg: string | any, ...subst: any[]) { public static Warning(msg: string | any, ...subst: any[]) {
let IsLocalCSChanel = true; let IsLocalCSChanel = true;
if (IsLocalCSChanel) { if (IsLocalCSChanel) {
console.warn(msg, subst); logger.warn(msg, subst);
} }
} }
//错误日志 //错误日志
public static Error(msg: string | any, ...subst: any[]) { public static Error(msg: string | any, ...subst: any[]) {
let IsLocalCSChanel = true; let IsLocalCSChanel = true;
if (IsLocalCSChanel) { if (IsLocalCSChanel) {
console.error(msg, subst); logger.error(msg, subst);
} }
} }
@@ -258,7 +259,7 @@ export default class Utils {
public static getScaleRatio(mod: number = 1) { public static getScaleRatio(mod: number = 1) {
let windowSize = view.getVisibleSize(); let windowSize = view.getVisibleSize();
let designSize = view.getDesignResolutionSize(); let designSize = view.getDesignResolutionSize();
// console.log("游戏分辨率:", windowSize, designSize); // logger.log("游戏分辨率:", windowSize, designSize);
if (mod == 1) { if (mod == 1) {
return windowSize.height / designSize.height; return windowSize.height / designSize.height;
} else { } else {
@@ -367,7 +368,7 @@ export default class Utils {
public static ProfilerTimePrint(key: string = "") { public static ProfilerTimePrint(key: string = "") {
let time = new Date().getTime(); let time = new Date().getTime();
let timecha = time - Utils._eplTime; let timecha = time - Utils._eplTime;
console.log(`${key}消耗时间:${timecha}毫秒`); logger.log(`${key}消耗时间:${timecha}毫秒`);
Utils._eplTime = time; Utils._eplTime = time;
} }
@@ -381,7 +382,7 @@ export default class Utils {
const days = Math.floor(diffSeconds / (60 * 60 * 24)); const days = Math.floor(diffSeconds / (60 * 60 * 24));
const hours = Math.floor((diffSeconds % (60 * 60 * 24)) / 3600); const hours = Math.floor((diffSeconds % (60 * 60 * 24)) / 3600);
const minutes = Math.floor((diffSeconds % 3600) / 60); const minutes = Math.floor((diffSeconds % 3600) / 60);
console.log( logger.log(
"vip失效剩余时间差(秒):", "vip失效剩余时间差(秒):",
diffSeconds, diffSeconds,
"天:", "天:",
+6 -5
View File
@@ -2,6 +2,7 @@ import { _decorator, Node, AudioClip, AudioSource, director, assetManager } from
import PlayerDataManager from "./PlayerDataManager"; import PlayerDataManager from "./PlayerDataManager";
import ResManager from "./ResManager"; import ResManager from "./ResManager";
import Resource from "../Config/Resource"; import Resource from "../Config/Resource";
import { logger } from "db://assets/Scripts/Main/Common/Logger";
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@@ -44,7 +45,7 @@ export default class AudioManager {
if (!cfgs[sound]) return; if (!cfgs[sound]) return;
let path = `Sound/${cfgs[sound].AssetName}` let path = `Sound/${cfgs[sound].AssetName}`
console.log("PlayEffect:", sound, path) logger.log("PlayEffect:", sound, path)
ResManager.I.getBundleAudio(path, (res: AudioClip)=>{ ResManager.I.getBundleAudio(path, (res: AudioClip)=>{
this._audoSource.playOneShot(res, volume) this._audoSource.playOneShot(res, volume)
}); });
@@ -68,7 +69,7 @@ export default class AudioManager {
this.curBgId = sound; this.curBgId = sound;
this.curBgId_confirm = sound; this.curBgId_confirm = sound;
let path = `Music/${cfgs[sound].AssetName}` let path = `Music/${cfgs[sound].AssetName}`
console.log("PlayMusic:", sound, path) logger.log("PlayMusic:", sound, path)
ResManager.I.getBundleAudio(path, (res: AudioClip)=>{ ResManager.I.getBundleAudio(path, (res: AudioClip)=>{
this._audoSource.clip = res this._audoSource.clip = res
this._audoSource.play() this._audoSource.play()
@@ -80,13 +81,13 @@ export default class AudioManager {
/**播放远程背景乐 */ /**播放远程背景乐 */
PlayRemoteMusic(url, loop:boolean = true, volume:number=1.0) { PlayRemoteMusic(url, loop:boolean = true, volume:number=1.0) {
console.log(`下载远程背景乐: url= ${url}`) logger.log(`下载远程背景乐: url= ${url}`)
assetManager.loadRemote<AudioClip>(url, { ext: '.mp3'}, (err, res: AudioClip) => { assetManager.loadRemote<AudioClip>(url, { ext: '.mp3'}, (err, res: AudioClip) => {
if (err) { if (err) {
console.log(err); logger.log(err);
return return
} }
console.log(`播放远程背景乐: res= ${res}`) logger.log(`播放远程背景乐: res= ${res}`)
this.StopMusic() this.StopMusic()
this._audoSource.clip = res this._audoSource.clip = res
this._audoSource.play() this._audoSource.play()
+5 -4
View File
@@ -7,6 +7,7 @@ import SubManager from "../../Sub/SubManager";
import HttpUnit from "../Common/HttpUnit"; import HttpUnit from "../Common/HttpUnit";
import { SDKManager } from "../Channel/SDKManager"; import { SDKManager } from "../Channel/SDKManager";
import { VideoRoleType } from "../Common/GlobalValue"; import { VideoRoleType } from "../Common/GlobalValue";
import { logger } from "db://assets/Scripts/Main/Common/Logger";
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@@ -68,7 +69,7 @@ export default class GameManager {
let resData = JSON.parse(data.data) let resData = JSON.parse(data.data)
if (GameManager.curStage != E_TalkStage.waitNpcTalk) return if (GameManager.curStage != E_TalkStage.waitNpcTalk) return
if (resData.isFinished) { if (resData.isFinished) {
console.log("npc回复:", resData) logger.log("npc回复:", resData)
GameManager.CurNpcTalkData = resData GameManager.CurNpcTalkData = resData
Utils.sendInnerMsg(InnerMsgCode.Data_NpcTalkBack, resData || {}) Utils.sendInnerMsg(InnerMsgCode.Data_NpcTalkBack, resData || {})
} }
@@ -122,7 +123,7 @@ export default class GameManager {
if (umRecords.length > 0 && SDKManager.umaSwt()){ if (umRecords.length > 0 && SDKManager.umaSwt()){
let umr = umRecords.join(',') let umr = umRecords.join(',')
HttpUnit.ins.sendLevelRecord({level_ids:umr}, (_data)=>{ HttpUnit.ins.sendLevelRecord({level_ids:umr}, (_data)=>{
console.log('友盟记录关卡',_data) logger.log('友盟记录关卡',_data)
let userId = HttpUnit.GetID() let userId = HttpUnit.GetID()
let curDate = Utils.GetNowFormatDay() let curDate = Utils.GetNowFormatDay()
for (let i = 0; i < umRecords.length; i++) { for (let i = 0; i < umRecords.length; i++) {
@@ -513,7 +514,7 @@ export default class GameManager {
} }
/**解锁一个私家珍藏id */ /**解锁一个私家珍藏id */
static UnlockZhencang(record_id:string, levelId: string) { static UnlockZhencang(record_id:string, levelId: string) {
console.log("解锁私家珍藏:", record_id, levelId) logger.log("解锁私家珍藏:", record_id, levelId)
HttpUnit.ins.getZhencangList({limit:999, page:1, type:1}, (data) => { HttpUnit.ins.getZhencangList({limit:999, page:1, type:1}, (data) => {
if (data){ if (data){
this._doUnlockZhencang(data.data, record_id, levelId) this._doUnlockZhencang(data.data, record_id, levelId)
@@ -559,7 +560,7 @@ export default class GameManager {
let item = lockAry[randIdx] let item = lockAry[randIdx]
HttpUnit.ins.sendZhencangId({record_id:record_id, level_id:levelId, img:item.id}, (_data) => { HttpUnit.ins.sendZhencangId({record_id:record_id, level_id:levelId, img:item.id}, (_data) => {
if (_data) { if (_data) {
console.log("获得珍藏卡:", item) logger.log("获得珍藏卡:", item)
GameManager.refreshZhencangCanget() GameManager.refreshZhencangCanget()
} }
}) })
+20 -18
View File
@@ -13,6 +13,8 @@ import li_BaseView from "../../Main/Common/li_BaseView";
import ResManager from "../../Main/Manager/ResManager"; import ResManager from "../../Main/Manager/ResManager";
import { DataManager, DataId } from "../../chat18x/data/DataManager"; import { DataManager, DataId } from "../../chat18x/data/DataManager";
import { EnvData } from "../../chat18x/data/EnvData"; import { EnvData } from "../../chat18x/data/EnvData";
import { logger } from "db://assets/Scripts/Main/Common/Logger";
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
//场景背景层 - 视频模式 //场景背景层 - 视频模式
@@ -39,7 +41,7 @@ export class SceneBgVideoLayer extends li_BaseView {
Utils.parseNode(this.node, this._nodeTab); Utils.parseNode(this.node, this._nodeTab);
this.videoPlayer = this._nodeTab.videoPlayer.getComponent(VideoPlayer); this.videoPlayer = this._nodeTab.videoPlayer.getComponent(VideoPlayer);
if (!this.videoPlayer) { if (!this.videoPlayer) {
console.error("SceneBgVideoLayer: video节点未找到或没有VideoPlayer组件"); logger.error("SceneBgVideoLayer: video节点未找到或没有VideoPlayer组件");
} }
this.initVideoEvents(); this.initVideoEvents();
SceneBgVideoLayer.handle = this; SceneBgVideoLayer.handle = this;
@@ -129,13 +131,13 @@ export class SceneBgVideoLayer extends li_BaseView {
const uiTransform = this.videoPlayer.node.getComponent(UITransform); const uiTransform = this.videoPlayer.node.getComponent(UITransform);
if (uiTransform) { if (uiTransform) {
uiTransform.setAnchorPoint(0.5, 0.5); uiTransform.setAnchorPoint(0.5, 0.5);
console.log("SceneBgVideoLayer: 设置视频锚点为 (0.5, 0.5)"); logger.log("SceneBgVideoLayer: 设置视频锚点为 (0.5, 0.5)");
} }
// 立即开始播放,尺寸和位置将在 READY_TO_PLAY 事件中设置 // 立即开始播放,尺寸和位置将在 READY_TO_PLAY 事件中设置
this.videoPlayer.play(); this.videoPlayer.play();
this.isPlaying = true; this.isPlaying = true;
console.log(`SceneBgVideoLayer: 开始加载视频 ${path}, 配置:`, config); logger.log(`SceneBgVideoLayer: 开始加载视频 ${path}, 配置:`, config);
} }
); );
} }
@@ -146,7 +148,7 @@ export class SceneBgVideoLayer extends li_BaseView {
pause() { pause() {
if (this.videoPlayer && this.isPlaying) { if (this.videoPlayer && this.isPlaying) {
this.videoPlayer.pause(); this.videoPlayer.pause();
console.log("SceneBgVideoLayer: 暂停视频"); logger.log("SceneBgVideoLayer: 暂停视频");
} }
} }
@@ -156,7 +158,7 @@ export class SceneBgVideoLayer extends li_BaseView {
resume() { resume() {
if (this.videoPlayer && !this.videoPlayer.isPlaying) { if (this.videoPlayer && !this.videoPlayer.isPlaying) {
this.videoPlayer.play(); this.videoPlayer.play();
console.log("SceneBgVideoLayer: 继续播放视频"); logger.log("SceneBgVideoLayer: 继续播放视频");
} }
} }
@@ -167,7 +169,7 @@ export class SceneBgVideoLayer extends li_BaseView {
if (this.videoPlayer) { if (this.videoPlayer) {
this.videoPlayer.stop(); this.videoPlayer.stop();
this.clearVideoState(); this.clearVideoState();
console.log("SceneBgVideoLayer: 停止视频"); logger.log("SceneBgVideoLayer: 停止视频");
} }
} }
@@ -179,10 +181,10 @@ export class SceneBgVideoLayer extends li_BaseView {
if (this.videoPlayer) { if (this.videoPlayer) {
if (typeof scale === "number") { if (typeof scale === "number") {
this.videoPlayer.node.setScale(new Vec3(scale, scale, 1)); this.videoPlayer.node.setScale(new Vec3(scale, scale, 1));
console.log(`SceneBgVideoLayer: 设置视频缩放 ${scale}`); logger.log(`SceneBgVideoLayer: 设置视频缩放 ${scale}`);
} else { } else {
this.videoPlayer.node.setScale(scale); this.videoPlayer.node.setScale(scale);
console.log( logger.log(
`SceneBgVideoLayer: 设置视频缩放 (${scale.x}, ${scale.y}, ${scale.z})` `SceneBgVideoLayer: 设置视频缩放 (${scale.x}, ${scale.y}, ${scale.z})`
); );
} }
@@ -209,7 +211,7 @@ export class SceneBgVideoLayer extends li_BaseView {
size: targetSize, size: targetSize,
position: position, position: position,
}; };
console.log("SceneBgVideoLayer: 视频未准备好,配置已存储等待应用"); logger.log("SceneBgVideoLayer: 视频未准备好,配置已存储等待应用");
} }
} }
@@ -248,7 +250,7 @@ export class SceneBgVideoLayer extends li_BaseView {
targetWorldPos = new Vec3(pos.x, pos.y, pos.z || 0); targetWorldPos = new Vec3(pos.x, pos.y, pos.z || 0);
} }
this.videoPlayer.node.setWorldPosition(targetWorldPos); this.videoPlayer.node.setWorldPosition(targetWorldPos);
console.log( logger.log(
`SceneBgVideoLayer: 设置视频位置 (${targetWorldPos.x}, ${targetWorldPos.y}, ${targetWorldPos.z})` `SceneBgVideoLayer: 设置视频位置 (${targetWorldPos.x}, ${targetWorldPos.y}, ${targetWorldPos.z})`
); );
} }
@@ -270,34 +272,34 @@ export class SceneBgVideoLayer extends li_BaseView {
const scale = Math.max(scaleX, scaleY); const scale = Math.max(scaleX, scaleY);
this.videoPlayer.node.setScale(new Vec3(scale, scale, 1)); this.videoPlayer.node.setScale(new Vec3(scale, scale, 1));
console.log( logger.log(
`SceneBgVideoLayer: 设置视频缩放 ${scale} (原始尺寸: ${videoSize.width}x${videoSize.height}, 目标尺寸: ${targetWidth}x${targetHeight})` `SceneBgVideoLayer: 设置视频缩放 ${scale} (原始尺寸: ${videoSize.width}x${videoSize.height}, 目标尺寸: ${targetWidth}x${targetHeight})`
); );
} else { } else {
console.warn("SceneBgVideoLayer: 无法获取视频尺寸,跳过缩放设置"); logger.warn("SceneBgVideoLayer: 无法获取视频尺寸,跳过缩放设置");
} }
} else if (config.scale) { } else if (config.scale) {
// 如果显式传入了 scale 参数,直接应用 // 如果显式传入了 scale 参数,直接应用
if (typeof config.scale === "number") { if (typeof config.scale === "number") {
this.videoPlayer.node.setScale(new Vec3(config.scale, config.scale, 1)); this.videoPlayer.node.setScale(new Vec3(config.scale, config.scale, 1));
console.log(`SceneBgVideoLayer: 设置显式缩放 ${config.scale}`); logger.log(`SceneBgVideoLayer: 设置显式缩放 ${config.scale}`);
} else { } else {
this.videoPlayer.node.setScale(config.scale); this.videoPlayer.node.setScale(config.scale);
console.log( logger.log(
`SceneBgVideoLayer: 设置显式缩放 (${config.scale.x}, ${config.scale.y}, ${config.scale.z})` `SceneBgVideoLayer: 设置显式缩放 (${config.scale.x}, ${config.scale.y}, ${config.scale.z})`
); );
} }
} else { } else {
// 没有指定尺寸或缩放,保持原始缩放 // 没有指定尺寸或缩放,保持原始缩放
this.videoPlayer.node.setScale(Vec3.ONE); this.videoPlayer.node.setScale(Vec3.ONE);
console.log("SceneBgVideoLayer: 保持默认缩放 (1, 1, 1)"); logger.log("SceneBgVideoLayer: 保持默认缩放 (1, 1, 1)");
} }
} }
//================== 事件回调 ================== //================== 事件回调 ==================
private onVideoReadyToPlay = () => { private onVideoReadyToPlay = () => {
console.log("SceneBgVideoLayer: 视频准备完成"); logger.log("SceneBgVideoLayer: 视频准备完成");
// 应用待处理的视频配置 // 应用待处理的视频配置
if (this.pendingVideoConfig) { if (this.pendingVideoConfig) {
@@ -312,12 +314,12 @@ export class SceneBgVideoLayer extends li_BaseView {
private onVideoEvent = (event: any, eventType: string) => { private onVideoEvent = (event: any, eventType: string) => {
switch (eventType) { switch (eventType) {
case "completed": case "completed":
console.log("SceneBgVideoLayer: 视频播放完成"); logger.log("SceneBgVideoLayer: 视频播放完成");
this.clearVideoState(); this.clearVideoState();
this.onVideoEnd(); this.onVideoEnd();
break; break;
case "error": case "error":
console.error("SceneBgVideoLayer: 视频播放错误"); logger.error("SceneBgVideoLayer: 视频播放错误");
this.clearVideoState(); this.clearVideoState();
this.onVideoError(); this.onVideoError();
break; break;