Auto-publish WXSDK.

This commit is contained in:
nebulaliu 2024-03-05 15:27:49 +08:00
parent 95043afbae
commit 940d8b69ba
17 changed files with 206 additions and 120 deletions

View File

@ -6,14 +6,25 @@ Removed - 删除功能/接口
Fixed - 修复问题 Fixed - 修复问题
Others - 其他 Others - 其他
--> -->
## 2024-3-5 【普通更新】
* 普通WXAssetBundle支持切换CDN
* 普通优化VideoPlayer组件
* 普通:更新小游戏模板捕获全局错误
* 普通:高性能+模式不再限制需要iOS>15.0
### Fixed
* 普通修复wx.onBluetoothDeviceFound
* 普通修复wx.onUserCaptureScreen
* 普通修复wx.getAppAuthorizeSetting
* 普通修复fs.stat
* 普通:修复截屏回调
* 普通unity21.3网络超时时间设置
## 2024-1-18 【普通更新】 ## 2024-1-18 【普通更新】
包含重要bugfix、特性支持
* 普通更新适配插件版本到1.2.38 * 普通更新适配插件版本到1.2.38
### Fixed ### Fixed
* 普通不支持WebGL2的旧Android微信版本提供升级指引 * 普通不支持WebGL2的旧Android微信版本提供升级指引
## 2024-1-15 【普通更新】 ## 2024-1-15 【普通更新】
包含重要bugfix、特性支持
### Feature ### Feature
* 重要增加iOS高性能+(iOSPerformancePlus)选项,请查阅[高性能+模式](https://developers.weixin.qq.com/minigame/dev/guide/performance/perf-high-performance-plus.html)有助于提升渲染兼容性、降低WebContent进程内存 * 重要增加iOS高性能+(iOSPerformancePlus)选项,请查阅[高性能+模式](https://developers.weixin.qq.com/minigame/dev/guide/performance/perf-high-performance-plus.html)有助于提升渲染兼容性、降低WebContent进程内存
* 普通陀螺仪去json性能优化 * 普通陀螺仪去json性能优化

View File

@ -93,6 +93,7 @@ namespace WeChatWASM
Debug.LogError("若游戏曾使用旧版本微信SDK需删除 Assets/WX-WASM-SDK 文件夹后再导入最新工具包。"); Debug.LogError("若游戏曾使用旧版本微信SDK需删除 Assets/WX-WASM-SDK 文件夹后再导入最新工具包。");
return WXExportError.BUILD_WEBGL_FAILED; return WXExportError.BUILD_WEBGL_FAILED;
} }
CheckBuildTarget();
Init(); Init();
// JSLib // JSLib
SettingWXTextureMinJSLib(); SettingWXTextureMinJSLib();
@ -159,6 +160,20 @@ namespace WeChatWASM
return WXExportError.SUCCEED; return WXExportError.SUCCEED;
} }
private static void CheckBuildTarget()
{
if (UnityUtil.GetEngineVersion() == UnityUtil.EngineVersion.Unity)
{
EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.WebGL, BuildTarget.WebGL);
}
else
{
#if TUANJIE_2022_3_OR_NEWER
EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.WeixinMiniGame, BuildTarget.WeixinMiniGame);
#endif
}
}
public static void UpdateGraphicAPI() public static void UpdateGraphicAPI()
{ {
GraphicsDeviceType[] targets = new GraphicsDeviceType[] { }; GraphicsDeviceType[] targets = new GraphicsDeviceType[] { };

View File

@ -2,7 +2,7 @@
{ {
public class WXPluginVersion public class WXPluginVersion
{ {
public static string pluginVersion = "202401191135"; // 这一行不要改他,导出的时候会自动替换 public static string pluginVersion = "202403051510"; // 这一行不要改他,导出的时候会自动替换
} }
public class WXPluginConf public class WXPluginConf

Binary file not shown.

View File

@ -54,7 +54,7 @@ var WXAssetBundleLibrary = {
WXFS.fs = wx.getFileSystemManager(); WXFS.fs = wx.getFileSystemManager();
WXFS.nowfd = FS.MAX_OPEN_FDS + 1; WXFS.nowfd = FS.MAX_OPEN_FDS + 1;
WXFS.isWXAssetBundle = function(url){ WXFS.isWXAssetBundle = function(url){
if(url.startsWith(GameGlobal.unityNamespace.DATA_CDN)||url.startsWith('/vfs_streamingassets')){ if(WXFS._url2path.has(url)||url.startsWith(GameGlobal.unityNamespace.DATA_CDN)||url.startsWith('/vfs_streamingassets')){
return unityNamespace.isWXAssetBundle(WXFS.url2path(url)); return unityNamespace.isWXAssetBundle(WXFS.url2path(url));
} }
return unityNamespace.isWXAssetBundle(url); return unityNamespace.isWXAssetBundle(url);

Binary file not shown.

View File

@ -38,8 +38,8 @@ const isLibVersionValid = compareVersion(SDKVersion, '2.17.0');
const isH5LibVersionValid = compareVersion(SDKVersion, '2.23.1'); const isH5LibVersionValid = compareVersion(SDKVersion, '2.23.1');
// 压缩纹理需要iOS系统版本>=14.0,检测到不支持压缩纹理时会提示升级系统 // 压缩纹理需要iOS系统版本>=14.0,检测到不支持压缩纹理时会提示升级系统
const isIOSH5SystemVersionValid = compareVersion(systemVersion, '14.0'); const isIOSH5SystemVersionValid = compareVersion(systemVersion, '14.0');
// iOS系统版本>=15支持webgl2 // iOS系统版本>=15支持webgl2,高性能模式+无此系统要求
const isIOSWebgl2SystemVersionValid = compareVersion(systemVersion, '15.0'); const isIOSWebgl2SystemVersionValid = compareVersion(systemVersion, '15.0') || GameGlobal.isIOSHighPerformanceModePlus;
// Android客户端版本>=8.0.19支持webgl2 // Android客户端版本>=8.0.19支持webgl2
const isAndroidWebGL2ClientVersionValid = compareVersion(version, '8.0.19'); const isAndroidWebGL2ClientVersionValid = compareVersion(version, '8.0.19');
// 是否用了webgl2 // 是否用了webgl2

View File

@ -79,6 +79,10 @@ checkVersion().then((enable) => {
}).default; }).default;
} }
catch (error) { catch (error) {
GameGlobal.realtimeLogManager.error(error);
// logManager不支持自动处理错误对象
GameGlobal.logmanager.warn(error.stack);
console.error('requirePlugin:', error);
if (error.message.indexOf('not defined') !== -1) { if (error.message.indexOf('not defined') !== -1) {
console.error('!!!插件需要申请才可使用\n请勿使用测试AppID并登录 https://mp.weixin.qq.com/ 并前往:能力地图-开发提效包-快适配 开通\n阅读文档获取详情:https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/blob/main/Design/Transform.md'); console.error('!!!插件需要申请才可使用\n请勿使用测试AppID并登录 https://mp.weixin.qq.com/ 并前往:能力地图-开发提效包-快适配 开通\n阅读文档获取详情:https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/blob/main/Design/Transform.md');
} }
@ -144,6 +148,7 @@ checkVersion().then((enable) => {
}, },
}); });
GameGlobal.managerConfig = managerConfig; GameGlobal.managerConfig = managerConfig;
// 显示启动封面
const gameManager = new UnityManager(managerConfig); const gameManager = new UnityManager(managerConfig);
gameManager.onLaunchProgress((e) => { gameManager.onLaunchProgress((e) => {
// interface LaunchEvent { // interface LaunchEvent {
@ -185,30 +190,11 @@ checkVersion().then((enable) => {
gameManager.assetPath = `${(managerConfig.DATA_CDN || '').replace(/\/$/, '')}/Assets`; gameManager.assetPath = `${(managerConfig.DATA_CDN || '').replace(/\/$/, '')}/Assets`;
preloadWxCommonFont(); preloadWxCommonFont();
}); });
// 上报初始化信息 // 插件捕获到引擎错误后,会通过此事件抛给游戏
const systeminfo = wx.getSystemInfoSync();
const bootinfo = {
renderer: systeminfo.renderer || '',
isH5Plus: GameGlobal.isIOSHighPerformanceModePlus || false,
abi: systeminfo.abi || '',
brand: systeminfo.brand,
model: systeminfo.model,
platform: systeminfo.platform,
system: systeminfo.system,
version: systeminfo.version,
SDKVersion: systeminfo.SDKVersion,
benchmarkLevel: systeminfo.benchmarkLevel,
};
wx.getRealtimeLogManager().info('game starting', bootinfo);
wx.getLogManager({ level: 0 }).info('game starting', bootinfo);
console.info('game starting', bootinfo);
// 默认上报小游戏实时日志与用户反馈日志(所有error日志+小程序框架异常)
wx.onError((result) => {
gameManager.printErr(result.message);
});
gameManager.onLogError = function (err) { gameManager.onLogError = function (err) {
GameGlobal.realtimeLogManager.error(err); GameGlobal.realtimeLogManager.error(err);
GameGlobal.logmanager.warn(err); const isErrorObj = err && err.stack;
GameGlobal.logmanager.warn(isErrorObj ? err.stack : err);
}; };
// iOS高性能模式定期GC // iOS高性能模式定期GC
if (GameGlobal.canUseiOSAutoGC && unityNamespace.iOSAutoGCInterval !== 0) { if (GameGlobal.canUseiOSAutoGC && unityNamespace.iOSAutoGCInterval !== 0) {
@ -216,6 +202,7 @@ checkVersion().then((enable) => {
wx.triggerGC(); wx.triggerGC();
}, unityNamespace.iOSAutoGCInterval); }, unityNamespace.iOSAutoGCInterval);
} }
// 开始执行游戏启动流程
gameManager.startGame(); gameManager.startGame();
GameGlobal.manager = gameManager; GameGlobal.manager = gameManager;
GameGlobal.events.on('launchOperaPushMsgToWasm', (callback, args) => GameGlobal.WXWASMSDK.WXLaunchOperaBridgeToC(callback, args)); GameGlobal.events.on('launchOperaPushMsgToWasm', (callback, args) => GameGlobal.WXWASMSDK.WXLaunchOperaBridgeToC(callback, args));

View File

@ -23,7 +23,7 @@
], ],
"plugins": { "plugins": {
"UnityPlugin": { "UnityPlugin": {
"version": "1.2.39", "version": "1.2.41",
"provider": "wxe5a48f1ed5f544b7", "provider": "wxe5a48f1ed5f544b7",
"contexts": [ "contexts": [
{ {

View File

@ -99,25 +99,69 @@ unityNamespace.isErasableFile = function (info) {
} }
return true; return true;
}; };
const { version, SDKVersion, platform, renderer, system } = wx.getSystemInfoSync();
unityNamespace.version = version;
unityNamespace.SDKVersion = SDKVersion;
unityNamespace.platform = platform;
unityNamespace.renderer = renderer;
unityNamespace.system = system;
unityNamespace.isPc = platform === 'windows' || platform === 'mac';
unityNamespace.isDevtools = platform === 'devtools';
unityNamespace.isMobile = !unityNamespace.isPc && !unityNamespace.isDevtools;
unityNamespace.isH5Renderer = unityNamespace.isMobile && unityNamespace.renderer === 'h5';
unityNamespace.isIOS = platform === 'ios';
unityNamespace.isAndroid = platform === 'android';
GameGlobal.WebAssembly = GameGlobal.WXWebAssembly; GameGlobal.WebAssembly = GameGlobal.WXWebAssembly;
GameGlobal.unityNamespace = GameGlobal.unityNamespace || unityNamespace; GameGlobal.unityNamespace = GameGlobal.unityNamespace || unityNamespace;
GameGlobal.realtimeLogManager = wx.getRealtimeLogManager(); GameGlobal.realtimeLogManager = wx.getRealtimeLogManager();
GameGlobal.logmanager = wx.getLogManager({ level: 0 }); GameGlobal.logmanager = wx.getLogManager({ level: 0 });
// 提前监听错误并打日志
function bindGloblException() {
// 默认上报小游戏实时日志与用户反馈日志(所有error日志+小程序框架异常)
wx.onError((result) => {
// 若manager已初始化则直接用manager打日志即可
if (GameGlobal.manager) {
GameGlobal.manager.printErr(result.message);
}
else {
GameGlobal.realtimeLogManager.error(result);
const isErrorObj = result && result.stack;
GameGlobal.logmanager.warn(isErrorObj ? result.stack : result);
console.error('onError:', result);
}
});
wx.onUnhandledRejection((result) => {
GameGlobal.realtimeLogManager.error(result);
const isErrorObj = result && result.reason && result.reason.stack;
GameGlobal.logmanager.warn(isErrorObj ? result.reason.stack : result.reason);
console.error('unhandledRejection:', result.reason);
});
// 上报初始信息
function printSystemInfo(systemInfo) {
GameGlobal.systemInfoCached = systemInfo;
const bootinfo = {
renderer: systemInfo.renderer || '',
isH5Plus: GameGlobal.isIOSHighPerformanceModePlus || false,
abi: systemInfo.abi || '',
brand: systemInfo.brand,
model: systemInfo.model,
platform: systemInfo.platform,
system: systemInfo.system,
version: systemInfo.version,
SDKVersion: systemInfo.SDKVersion,
benchmarkLevel: systemInfo.benchmarkLevel,
};
GameGlobal.realtimeLogManager.info('game starting', bootinfo);
GameGlobal.logmanager.info('game starting', bootinfo);
console.info('game starting', bootinfo);
}
const systemInfoSync = wx.getSystemInfoSync();
const isEmptySystemInfo = systemInfoSync && Object.keys(systemInfoSync).length === 0;
// iOS会出现getSystemInfoSync返回空对象的情况使用异步方法替代
if (isEmptySystemInfo) {
wx.getSystemInfo({
success(systemInfo) {
printSystemInfo(systemInfo);
},
});
}
else {
printSystemInfo(systemInfoSync);
}
}
bindGloblException();
// eslint-disable-next-line no-multi-assign // eslint-disable-next-line no-multi-assign
GameGlobal.onCrash = GameGlobal.unityNamespace.onCrash = function () { GameGlobal.onCrash = GameGlobal.unityNamespace.onCrash = function () {
GameGlobal.manager.showAbort(); GameGlobal.manager.showAbort();
// 避免已经修改屏幕尺寸故不使用缓存的systeminfo
const sysInfo = wx.getSystemInfoSync(); const sysInfo = wx.getSystemInfoSync();
wx.createFeedbackButton({ wx.createFeedbackButton({
type: 'text', type: 'text',

View File

@ -1,4 +1,4 @@
import { convertDataToPointer } from "../utils"; import { convertDataToPointer } from '../utils';
let wxOnBLECharacteristicValueChangeCallback; let wxOnBLECharacteristicValueChangeCallback;
const OnBLECharacteristicValueChange = (res) => { const OnBLECharacteristicValueChange = (res) => {
const deviceIdPtr = convertDataToPointer(res.deviceId); const deviceIdPtr = convertDataToPointer(res.deviceId);

View File

@ -411,8 +411,15 @@ export default {
}, },
WX_FileSystemManagerStatSync(path, recursive) { WX_FileSystemManagerStatSync(path, recursive) {
const fs = wx.getFileSystemManager(); const fs = wx.getFileSystemManager();
const res = fs.statSync(path, recursive);
return JSON.stringify(fs.statSync(path, recursive)); let resArray;
if (Array.isArray(res)) {
resArray = res;
}
else {
resArray = [res];
}
return JSON.stringify(resArray);
}, },
WX_FileSystemManagerWriteSync(option, data) { WX_FileSystemManagerWriteSync(option, data) {
const fs = wx.getFileSystemManager(); const fs = wx.getFileSystemManager();

View File

@ -1,6 +1,6 @@
import moduleHelper from './module-helper'; import moduleHelper from './module-helper';
import { uid, formatResponse, formatJsonStr, onEventCallback, offEventCallback, getListObject } from './utils'; import { uid, formatResponse, formatJsonStr, onEventCallback, offEventCallback, getListObject, stringifyRes } from './utils';
let OnAccelerometerChangeList; let OnAccelerometerChangeList;
let OnAudioInterruptionBeginList; let OnAudioInterruptionBeginList;
let OnAudioInterruptionEndList; let OnAudioInterruptionEndList;
@ -3331,7 +3331,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnAccelerometerChangeListenerResult', res); formatResponse('OnAccelerometerChangeListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnAccelerometerChangeCallback', resStr); moduleHelper.send('_OnAccelerometerChangeCallback', resStr);
}; };
OnAccelerometerChangeList.push(callback); OnAccelerometerChangeList.push(callback);
@ -3348,7 +3348,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('GeneralCallbackResult', res); formatResponse('GeneralCallbackResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnAudioInterruptionBeginCallback', resStr); moduleHelper.send('_OnAudioInterruptionBeginCallback', resStr);
}; };
OnAudioInterruptionBeginList.push(callback); OnAudioInterruptionBeginList.push(callback);
@ -3365,7 +3365,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('GeneralCallbackResult', res); formatResponse('GeneralCallbackResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnAudioInterruptionEndCallback', resStr); moduleHelper.send('_OnAudioInterruptionEndCallback', resStr);
}; };
OnAudioInterruptionEndList.push(callback); OnAudioInterruptionEndList.push(callback);
@ -3382,7 +3382,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnBLEConnectionStateChangeListenerResult', res); formatResponse('OnBLEConnectionStateChangeListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnBLEConnectionStateChangeCallback', resStr); moduleHelper.send('_OnBLEConnectionStateChangeCallback', resStr);
}; };
OnBLEConnectionStateChangeList.push(callback); OnBLEConnectionStateChangeList.push(callback);
@ -3399,7 +3399,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnBLEMTUChangeListenerResult', res); formatResponse('OnBLEMTUChangeListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnBLEMTUChangeCallback', resStr); moduleHelper.send('_OnBLEMTUChangeCallback', resStr);
}; };
OnBLEMTUChangeList.push(callback); OnBLEMTUChangeList.push(callback);
@ -3416,7 +3416,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnBLEPeripheralConnectionStateChangedListenerResult', res); formatResponse('OnBLEPeripheralConnectionStateChangedListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnBLEPeripheralConnectionStateChangedCallback', resStr); moduleHelper.send('_OnBLEPeripheralConnectionStateChangedCallback', resStr);
}; };
OnBLEPeripheralConnectionStateChangedList.push(callback); OnBLEPeripheralConnectionStateChangedList.push(callback);
@ -3430,7 +3430,7 @@ export default {
WX_OnBackgroundFetchData() { WX_OnBackgroundFetchData() {
const callback = (res) => { const callback = (res) => {
formatResponse('OnBackgroundFetchDataListenerResult', res); formatResponse('OnBackgroundFetchDataListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnBackgroundFetchDataCallback', resStr); moduleHelper.send('_OnBackgroundFetchDataCallback', resStr);
}; };
wx.onBackgroundFetchData(callback); wx.onBackgroundFetchData(callback);
@ -3441,7 +3441,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnBeaconServiceChangeListenerResult', res); formatResponse('OnBeaconServiceChangeListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnBeaconServiceChangeCallback', resStr); moduleHelper.send('_OnBeaconServiceChangeCallback', resStr);
}; };
OnBeaconServiceChangeList.push(callback); OnBeaconServiceChangeList.push(callback);
@ -3458,7 +3458,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnBeaconUpdateListenerResult', res); formatResponse('OnBeaconUpdateListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnBeaconUpdateCallback', resStr); moduleHelper.send('_OnBeaconUpdateCallback', resStr);
}; };
OnBeaconUpdateList.push(callback); OnBeaconUpdateList.push(callback);
@ -3475,7 +3475,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnBluetoothAdapterStateChangeListenerResult', res); formatResponse('OnBluetoothAdapterStateChangeListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnBluetoothAdapterStateChangeCallback', resStr); moduleHelper.send('_OnBluetoothAdapterStateChangeCallback', resStr);
}; };
OnBluetoothAdapterStateChangeList.push(callback); OnBluetoothAdapterStateChangeList.push(callback);
@ -3492,7 +3492,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnBluetoothDeviceFoundListenerResult', res); formatResponse('OnBluetoothDeviceFoundListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnBluetoothDeviceFoundCallback', resStr); moduleHelper.send('_OnBluetoothDeviceFoundCallback', resStr);
}; };
OnBluetoothDeviceFoundList.push(callback); OnBluetoothDeviceFoundList.push(callback);
@ -3509,7 +3509,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnCompassChangeListenerResult', res); formatResponse('OnCompassChangeListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnCompassChangeCallback', resStr); moduleHelper.send('_OnCompassChangeCallback', resStr);
}; };
OnCompassChangeList.push(callback); OnCompassChangeList.push(callback);
@ -3526,7 +3526,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnDeviceMotionChangeListenerResult', res); formatResponse('OnDeviceMotionChangeListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnDeviceMotionChangeCallback', resStr); moduleHelper.send('_OnDeviceMotionChangeCallback', resStr);
}; };
OnDeviceMotionChangeList.push(callback); OnDeviceMotionChangeList.push(callback);
@ -3543,7 +3543,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnDeviceOrientationChangeListenerResult', res); formatResponse('OnDeviceOrientationChangeListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnDeviceOrientationChangeCallback', resStr); moduleHelper.send('_OnDeviceOrientationChangeCallback', resStr);
}; };
OnDeviceOrientationChangeList.push(callback); OnDeviceOrientationChangeList.push(callback);
@ -3560,7 +3560,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('Error', res); formatResponse('Error', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnErrorCallback', resStr); moduleHelper.send('_OnErrorCallback', resStr);
}; };
OnErrorList.push(callback); OnErrorList.push(callback);
@ -3577,7 +3577,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('GeneralCallbackResult', res); formatResponse('GeneralCallbackResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnHideCallback', resStr); moduleHelper.send('_OnHideCallback', resStr);
}; };
OnHideList.push(callback); OnHideList.push(callback);
@ -3610,7 +3610,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnKeyDownListenerResult', res); formatResponse('OnKeyDownListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnKeyDownCallback', resStr); moduleHelper.send('_OnKeyDownCallback', resStr);
}; };
OnKeyDownList.push(callback); OnKeyDownList.push(callback);
@ -3627,7 +3627,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnKeyDownListenerResult', res); formatResponse('OnKeyDownListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnKeyUpCallback', resStr); moduleHelper.send('_OnKeyUpCallback', resStr);
}; };
OnKeyUpList.push(callback); OnKeyUpList.push(callback);
@ -3644,7 +3644,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnKeyboardInputListenerResult', res); formatResponse('OnKeyboardInputListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnKeyboardCompleteCallback', resStr); moduleHelper.send('_OnKeyboardCompleteCallback', resStr);
}; };
OnKeyboardCompleteList.push(callback); OnKeyboardCompleteList.push(callback);
@ -3661,7 +3661,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnKeyboardInputListenerResult', res); formatResponse('OnKeyboardInputListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnKeyboardConfirmCallback', resStr); moduleHelper.send('_OnKeyboardConfirmCallback', resStr);
}; };
OnKeyboardConfirmList.push(callback); OnKeyboardConfirmList.push(callback);
@ -3678,7 +3678,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnKeyboardHeightChangeListenerResult', res); formatResponse('OnKeyboardHeightChangeListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnKeyboardHeightChangeCallback', resStr); moduleHelper.send('_OnKeyboardHeightChangeCallback', resStr);
}; };
OnKeyboardHeightChangeList.push(callback); OnKeyboardHeightChangeList.push(callback);
@ -3695,7 +3695,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnKeyboardInputListenerResult', res); formatResponse('OnKeyboardInputListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnKeyboardInputCallback', resStr); moduleHelper.send('_OnKeyboardInputCallback', resStr);
}; };
OnKeyboardInputList.push(callback); OnKeyboardInputList.push(callback);
@ -3712,7 +3712,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnMemoryWarningListenerResult', res); formatResponse('OnMemoryWarningListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnMemoryWarningCallback', resStr); moduleHelper.send('_OnMemoryWarningCallback', resStr);
}; };
OnMemoryWarningList.push(callback); OnMemoryWarningList.push(callback);
@ -3736,7 +3736,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnMouseDownListenerResult', res); formatResponse('OnMouseDownListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnMouseDownCallback', resStr); moduleHelper.send('_OnMouseDownCallback', resStr);
}; };
OnMouseDownList.push(callback); OnMouseDownList.push(callback);
@ -3753,7 +3753,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnMouseMoveListenerResult', res); formatResponse('OnMouseMoveListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnMouseMoveCallback', resStr); moduleHelper.send('_OnMouseMoveCallback', resStr);
}; };
OnMouseMoveList.push(callback); OnMouseMoveList.push(callback);
@ -3770,7 +3770,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnMouseDownListenerResult', res); formatResponse('OnMouseDownListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnMouseUpCallback', resStr); moduleHelper.send('_OnMouseUpCallback', resStr);
}; };
OnMouseUpList.push(callback); OnMouseUpList.push(callback);
@ -3787,7 +3787,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnNetworkStatusChangeListenerResult', res); formatResponse('OnNetworkStatusChangeListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnNetworkStatusChangeCallback', resStr); moduleHelper.send('_OnNetworkStatusChangeCallback', resStr);
}; };
OnNetworkStatusChangeList.push(callback); OnNetworkStatusChangeList.push(callback);
@ -3804,7 +3804,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnNetworkWeakChangeListenerResult', res); formatResponse('OnNetworkWeakChangeListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnNetworkWeakChangeCallback', resStr); moduleHelper.send('_OnNetworkWeakChangeCallback', resStr);
}; };
OnNetworkWeakChangeList.push(callback); OnNetworkWeakChangeList.push(callback);
@ -3821,7 +3821,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnScreenRecordingStateChangedListenerResult', res); formatResponse('OnScreenRecordingStateChangedListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnScreenRecordingStateChangedCallback', resStr); moduleHelper.send('_OnScreenRecordingStateChangedCallback', resStr);
}; };
OnScreenRecordingStateChangedList.push(callback); OnScreenRecordingStateChangedList.push(callback);
@ -3835,7 +3835,7 @@ export default {
WX_OnShareMessageToFriend() { WX_OnShareMessageToFriend() {
const callback = (res) => { const callback = (res) => {
formatResponse('OnShareMessageToFriendListenerResult', res); formatResponse('OnShareMessageToFriendListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnShareMessageToFriendCallback', resStr); moduleHelper.send('_OnShareMessageToFriendCallback', resStr);
}; };
wx.onShareMessageToFriend(callback); wx.onShareMessageToFriend(callback);
@ -3846,7 +3846,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnShowListenerResult', res); formatResponse('OnShowListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnShowCallback', resStr); moduleHelper.send('_OnShowCallback', resStr);
}; };
OnShowList.push(callback); OnShowList.push(callback);
@ -3863,7 +3863,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnUnhandledRejectionListenerResult', res); formatResponse('OnUnhandledRejectionListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnUnhandledRejectionCallback', resStr); moduleHelper.send('_OnUnhandledRejectionCallback', resStr);
}; };
OnUnhandledRejectionList.push(callback); OnUnhandledRejectionList.push(callback);
@ -3880,7 +3880,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('GeneralCallbackResult', res); formatResponse('GeneralCallbackResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnUserCaptureScreenCallback', resStr); moduleHelper.send('_OnUserCaptureScreenCallback', resStr);
}; };
OnUserCaptureScreenList.push(callback); OnUserCaptureScreenList.push(callback);
@ -3897,7 +3897,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnVoIPChatInterruptedListenerResult', res); formatResponse('OnVoIPChatInterruptedListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnVoIPChatInterruptedCallback', resStr); moduleHelper.send('_OnVoIPChatInterruptedCallback', resStr);
}; };
OnVoIPChatInterruptedList.push(callback); OnVoIPChatInterruptedList.push(callback);
@ -3914,7 +3914,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnVoIPChatMembersChangedListenerResult', res); formatResponse('OnVoIPChatMembersChangedListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnVoIPChatMembersChangedCallback', resStr); moduleHelper.send('_OnVoIPChatMembersChangedCallback', resStr);
}; };
OnVoIPChatMembersChangedList.push(callback); OnVoIPChatMembersChangedList.push(callback);
@ -3931,7 +3931,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnVoIPChatSpeakersChangedListenerResult', res); formatResponse('OnVoIPChatSpeakersChangedListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnVoIPChatSpeakersChangedCallback', resStr); moduleHelper.send('_OnVoIPChatSpeakersChangedCallback', resStr);
}; };
OnVoIPChatSpeakersChangedList.push(callback); OnVoIPChatSpeakersChangedList.push(callback);
@ -3948,7 +3948,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnVoIPChatStateChangedListenerResult', res); formatResponse('OnVoIPChatStateChangedListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnVoIPChatStateChangedCallback', resStr); moduleHelper.send('_OnVoIPChatStateChangedCallback', resStr);
}; };
OnVoIPChatStateChangedList.push(callback); OnVoIPChatStateChangedList.push(callback);
@ -3965,7 +3965,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnWheelListenerResult', res); formatResponse('OnWheelListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnWheelCallback', resStr); moduleHelper.send('_OnWheelCallback', resStr);
}; };
OnWheelList.push(callback); OnWheelList.push(callback);
@ -3982,7 +3982,7 @@ export default {
} }
const callback = (res) => { const callback = (res) => {
formatResponse('OnWindowResizeListenerResult', res); formatResponse('OnWindowResizeListenerResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnWindowResizeCallback', resStr); moduleHelper.send('_OnWindowResizeCallback', resStr);
}; };
OnWindowResizeList.push(callback); OnWindowResizeList.push(callback);
@ -3995,7 +3995,7 @@ export default {
}, },
WX_OnAddToFavorites() { WX_OnAddToFavorites() {
const callback = (res) => { const callback = (res) => {
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnAddToFavoritesCallback', resStr); moduleHelper.send('_OnAddToFavoritesCallback', resStr);
return wxOnAddToFavoritesResolveConf; return wxOnAddToFavoritesResolveConf;
}; };
@ -4015,7 +4015,7 @@ export default {
}, },
WX_OnCopyUrl() { WX_OnCopyUrl() {
const callback = (res) => { const callback = (res) => {
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnCopyUrlCallback', resStr); moduleHelper.send('_OnCopyUrlCallback', resStr);
return wxOnCopyUrlResolveConf; return wxOnCopyUrlResolveConf;
}; };
@ -4035,7 +4035,7 @@ export default {
}, },
WX_OnHandoff() { WX_OnHandoff() {
const callback = (res) => { const callback = (res) => {
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnHandoffCallback', resStr); moduleHelper.send('_OnHandoffCallback', resStr);
return wxOnHandoffResolveConf; return wxOnHandoffResolveConf;
}; };
@ -4055,7 +4055,7 @@ export default {
}, },
WX_OnShareTimeline() { WX_OnShareTimeline() {
const callback = (res) => { const callback = (res) => {
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnShareTimelineCallback', resStr); moduleHelper.send('_OnShareTimelineCallback', resStr);
return wxOnShareTimelineResolveConf; return wxOnShareTimelineResolveConf;
}; };
@ -4076,7 +4076,7 @@ export default {
WX_OnGameLiveStateChange() { WX_OnGameLiveStateChange() {
const callback = (res) => { const callback = (res) => {
formatResponse('OnGameLiveStateChangeCallbackResult', res); formatResponse('OnGameLiveStateChangeCallbackResult', res);
const resStr = JSON.stringify(res); const resStr = stringifyRes(res);
moduleHelper.send('_OnGameLiveStateChangeCallback', resStr); moduleHelper.send('_OnGameLiveStateChangeCallback', resStr);
return wxOnGameLiveStateChangeResolveConf; return wxOnGameLiveStateChangeResolveConf;
}; };

View File

@ -79,9 +79,14 @@ export function formatResponse(type, data, id) {
Object.keys(conf).forEach((key) => { Object.keys(conf).forEach((key) => {
if (data[key] === null || typeof data[key] === 'undefined') { if (data[key] === null || typeof data[key] === 'undefined') {
if (typeof typeMap[conf[key]] === 'undefined') { if (typeof typeMap[conf[key]] === 'undefined') {
data[key] = {}; if (conf[key].indexOf('[]') > -1) {
if (ResType[conf[key]]) { data[key] = [];
formatResponse(conf[key], data[key]); }
else {
data[key] = {};
if (ResType[conf[key]]) {
formatResponse(conf[key], data[key]);
}
} }
} }
else { else {
@ -100,11 +105,20 @@ export function formatResponse(type, data, id) {
else if (conf[key] === 'bool' && (typeof data[key] === 'number' || typeof data[key] === 'string')) { else if (conf[key] === 'bool' && (typeof data[key] === 'number' || typeof data[key] === 'string')) {
data[key] = !!data[key]; data[key] = !!data[key];
} }
else if (conf[key] === 'arrayBuffer' && id) { else if (conf[key] === 'arrayBuffer') {
if (id) {
cacheArrayBuffer(id, data[key]);
data.arrayBufferLength = data[key].byteLength; cacheArrayBuffer(id, data[key]);
data[key] = []; data.arrayBufferLength = data[key].byteLength;
data[key] = [];
}
else if (data[key] instanceof ArrayBuffer) {
data[key] = new Uint8Array(data[key]);
data[key] = Array.from(data[key]);
}
else {
data[key] = [];
}
} }
else if (typeof data[key] === 'object' && conf[key] === 'object') { else if (typeof data[key] === 'object' && conf[key] === 'object') {
Object.keys(data[key]).forEach((v) => { Object.keys(data[key]).forEach((v) => {
@ -343,3 +357,9 @@ function infoToUint8Array(info) {
export function convertInfoToPointer(info) { export function convertInfoToPointer(info) {
return allocateAndSet(infoToUint8Array(info)); return allocateAndSet(infoToUint8Array(info));
} }
export function stringifyRes(obj) {
if (!obj) {
return '{}';
}
return JSON.stringify(obj);
}

View File

@ -2,6 +2,8 @@ import { isH5Renderer, isSupportVideoPlayer, isPc, isDevtools } from '../../chec
let FrameworkData = null; let FrameworkData = null;
const isWebVideo = isH5Renderer || isPc || isDevtools; const isWebVideo = isH5Renderer || isPc || isDevtools;
const isDebug = false; const isDebug = false;
const needCache = true;
const cacheVideoDecoder = [];
const videoInstances = {}; const videoInstances = {};
function _JS_Video_CanPlayFormat(format, data) { function _JS_Video_CanPlayFormat(format, data) {
@ -45,10 +47,16 @@ function _JS_Video_Create(url) {
videoInstances[++videoInstanceIdCounter] = video; videoInstances[++videoInstanceIdCounter] = video;
} }
else { else {
let videoDecoder;
const videoDecoder = wx.createVideoDecoder({ if (cacheVideoDecoder.length > 0) {
type: 'wemedia', videoDecoder = cacheVideoDecoder.pop();
}); }
else {
videoDecoder = wx.createVideoDecoder({
type: 'wemedia',
});
}
const videoInstance = { const videoInstance = {
videoDecoder, videoDecoder,
@ -122,10 +130,17 @@ function _JS_Video_Create(url) {
}; };
videoInstance.play(); videoInstance.play();
videoInstance.destroy = () => { videoInstance.destroy = () => {
videoDecoder.remove(); if (needCache) {
videoDecoder.stop();
cacheVideoDecoder.push(videoDecoder);
}
else {
videoDecoder.remove();
}
if (videoInstance.loopEndPollInterval) { if (videoInstance.loopEndPollInterval) {
clearInterval(videoInstance.loopEndPollInterval); clearInterval(videoInstance.loopEndPollInterval);
} }
delete videoInstance.videoDecoder;
delete videoInstance.onendedCallback; delete videoInstance.onendedCallback;
delete videoInstance.frameData; delete videoInstance.frameData;
videoInstance.paused = false; videoInstance.paused = false;
@ -314,9 +329,9 @@ function _JS_Video_SetReadyHandler(video, ref, onready) {
const fn = () => { const fn = () => {
console.log('_JS_Video_SetReadyHandler onCanPlay'); console.log('_JS_Video_SetReadyHandler onCanPlay');
dynCall_vi(onready, ref); dynCall_vi(onready, ref);
v.videoDecoder.off('bufferchange', fn); v.videoDecoder?.off('bufferchange', fn);
}; };
v.videoDecoder.on('bufferchange', fn); v.videoDecoder?.on('bufferchange', fn);
} }
} }
function _JS_Video_SetSeekedOnceHandler(video, ref, onseeked) { function _JS_Video_SetSeekedOnceHandler(video, ref, onseeked) {
@ -330,7 +345,7 @@ function _JS_Video_SetSeekedOnceHandler(video, ref, onseeked) {
}); });
} }
else { else {
v.videoDecoder.on('seek', () => { v.videoDecoder?.on('seek', () => {
dynCall_vi(onseeked, ref); dynCall_vi(onseeked, ref);
}); });
} }
@ -406,7 +421,7 @@ function _JS_Video_SetSeekedHandler(video, ref, onseeked) {
}); });
} }
else { else {
v.videoDecoder.on('seek', () => { v.videoDecoder?.on('seek', () => {
dynCall_vi(onseeked, ref); dynCall_vi(onseeked, ref);
}); });
} }

View File

@ -1,14 +1 @@
{ {"name":"com.qq.weixin.minigame","displayName":"WXSDK","description":"WeChat Mini Game Tuanjie Engine Adapter SDK Package.","version":"0.1.1","unity":"2019.4","unityRelease":"29f1","keywords":["Tuanjie","WX"],"dependencies":{}}
"name": "com.qq.weixin.minigame",
"displayName": "WXSDK",
"description": "WeChat Mini Game Tuanjie Engine Adapter SDK Package.",
"version": "0.1.0",
"unity": "2019.4",
"unityRelease": "29f1",
"keywords": [
"Tuanjie",
"WX"
],
"dependencies": {
}
}