@maoyugames/phaser-framework 1.0.7 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/index.js CHANGED
@@ -475,8 +475,20 @@ function renderTikTokHtml(cfg, scriptSrc) {
475
475
  const initTag = sdkUrl ? `<script>
476
476
  window.TTMinis = TTMinis;
477
477
  TTMinis.game.init({ clientKey: "${escapeAttr(clientKey)}" });
478
- try { TTMinis.game.setLoadingProgress({ progress: 100 }); } catch (e) {}
479
- try { TTMinis.game.setLoadingProgress(function () {}, { progress: 100 }); } catch (e) {}
478
+ (function () {
479
+ function report(p) {
480
+ try {
481
+ TTMinis.game.setLoadingProgress({
482
+ progress: p,
483
+ fail: function (e) { console.warn('[setLoadingProgress fail]', e && e.error); },
484
+ });
485
+ } catch (e) { console.warn('[setLoadingProgress throw]', e); }
486
+ }
487
+ // \u5F02\u6B65\u89E6\u53D1,\u8BA9 SDK \u7684 De \u901A\u9053\u6709\u4E00\u62CD\u65F6\u95F4\u5C31\u7EEA
488
+ setTimeout(function () { report(0.3); }, 0);
489
+ document.addEventListener('DOMContentLoaded', function () { report(0.7); });
490
+ window.addEventListener('load', function () { report(1); });
491
+ })();
480
492
  </script>` : "";
481
493
  return `<!doctype html>
482
494
  <html lang="en">
@@ -10,16 +10,26 @@ function requireTT(capability) {
10
10
  if (!hasTT()) throw new PlatformUnsupportedError("tiktok", capability);
11
11
  }
12
12
  var TikTokAuth = class {
13
+ // TikTok H5 SDK 实测(2026-05-28 反编译 connect.tiktok-minis.com/game/sdk.js)
14
+ // **没有 game.login 也没有 game.getUserInfo**——这两个 API 是抖音(国内)小游戏的协议,
15
+ // TikTok 海外走 OAuth code 流程:authorizeOpenContext({get_status_only:false}) 弹授权页拿 code,
16
+ // 后端用 code + client_secret 调 open.tiktokapis.com/v2/oauth/token/ + /v2/user/info/ 拿 user info。
13
17
  async login() {
14
18
  requireTT("auth.login");
15
- const res = await TTMinis.game.login();
16
- return { code: res.code, openId: res.openId, raw: res };
19
+ let res = await TTMinis.game.authorizeOpenContext({ get_status_only: true });
20
+ if (!res?.is_success || !res?.code) {
21
+ res = await TTMinis.game.authorizeOpenContext({ get_status_only: false });
22
+ }
23
+ if (!res?.is_success || !res?.code) {
24
+ const e = res?.error;
25
+ throw new Error(`TikTok authorize failed: ${e?.error_msg ?? "unknown"} (code=${e?.error_code ?? "NA"})`);
26
+ }
27
+ return { code: res.code, raw: res };
17
28
  }
29
+ // TikTok H5 SDK 没有客户端 user info API。nickname/avatar 必须由后端用 access_token 调
30
+ // /v2/user/info/ 取(scope=user.info.basic),客户端拿到的 user 已含这些字段。
18
31
  async getProfile() {
19
- requireTT("auth.getProfile");
20
- const info = await TTMinis.game.getUserInfo();
21
- if (!info) return null;
22
- return { nickname: info.nickName ?? "", avatarUrl: info.avatarUrl ?? "" };
32
+ return null;
23
33
  }
24
34
  };
25
35
  var TikTokAds = class {
@@ -71,13 +81,23 @@ var TikTokPayment = class {
71
81
  }
72
82
  };
73
83
  var TikTokDevice = class {
84
+ // 注:TikTok H5 minigame SDK 实测(2026-05-27)**完全没有** vibrateShort/vibrateLong
85
+ // 方法(navigator.vibrate 也被禁,SDK 内部只 console.error 替换)。业务高频调用
86
+ // (如棋盘 tap 反馈)如果不做存在性检测会持续 throw TypeError 打断游戏流程。
87
+ // 这里 typeof 检测后静默 noop——震动不是关键能力,SDK 没有就算了。
74
88
  vibrateShort() {
75
- if (!hasTT()) return;
76
- TTMinis.game.vibrateShort();
89
+ if (!hasTT() || typeof TTMinis.game.vibrateShort !== "function") return;
90
+ try {
91
+ TTMinis.game.vibrateShort();
92
+ } catch {
93
+ }
77
94
  }
78
95
  vibrateLong() {
79
- if (!hasTT()) return;
80
- TTMinis.game.vibrateLong();
96
+ if (!hasTT() || typeof TTMinis.game.vibrateLong !== "function") return;
97
+ try {
98
+ TTMinis.game.vibrateLong();
99
+ } catch {
100
+ }
81
101
  }
82
102
  async setClipboard(text) {
83
103
  requireTT("device.setClipboard");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maoyugames/phaser-framework",
3
- "version": "1.0.7",
3
+ "version": "1.0.11",
4
4
  "description": "多平台 Phaser 游戏框架:业务/底层分离,HTTP/WebSocket/KCP,Web/TikTok/微信/Facebook/App 隔离打包",
5
5
  "type": "module",
6
6
  "license": "MIT",