修复 SwitchOverGameData 解析失败致无法跳转子游戏

H5 对 SwitchOverGameData 的 data 字段直接传 JSON 对象(如 {webtype:3,...})。
Android org.json getString 会把嵌套对象强制转为 JSON 字符串再交 handler JSON.parse;
而 ArkTS JSON.parse 保留为对象,handler 再 JSON.parse(对象) 得到 "[object Object]"
→ Invalid Token、解析失败、不发 SWITCH_GAME、不跳转。

- MessageCodec.toArray:新增 coerceToString,对 data/responseData 复刻 org.json
  getString 语义(对象/数组→紧凑 JSON 串,数字/布尔→字符串)。
- NavProvider:webtype 统一 String() 化,避免下游 `webtype !== '2'` 对数字恒真
  把竖屏子游戏错误强制横屏。

对应契约 §11.1 路径A、§2.4 Message。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
lanterngamescn
2026-06-27 01:55:40 +08:00
co-authored by Claude Opus 4.8
parent 5f3161ee49
commit e75f567948
2 changed files with 26 additions and 3 deletions
@@ -60,7 +60,9 @@ export class NavProvider implements CapabilityProvider {
this.log.w(`SwitchOverGameData bad json: ${(e as Error).message}`);
return;
}
const payload: SwitchGamePayload = { webtype: req.webtype, dir: req.Gamedirectory, data: req.data };
// webtype 契约为 "2"竖/"3"横,但 H5 可能发数字(如 3)。统一转字符串,
// 否则下游 `webtype !== '2'` 的严格比较对数字恒为真,会把竖屏子游戏错误强制横屏。
const payload: SwitchGamePayload = { webtype: String(req.webtype), dir: req.Gamedirectory, data: req.data };
EventBus.emit(NavEvents.SWITCH_GAME, payload);
}