@maoyugames/phaser-framework 1.0.10 → 1.0.12

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.
@@ -1,4 +1,4 @@
1
- import { d as IPlatform, p as PlatformName, S as SafeArea, t as SystemInfo, L as LaunchOptions, j as IPlatformNet, m as IPlatformStorage, i as IPlatformLifecycle, g as IPlatformAuth, e as IPlatformAds, k as IPlatformPayment, h as IPlatformDevice, f as IPlatformAnalytics, P as PlatformInfo } from './types-DtcRFbM0.js';
1
+ import { d as IPlatform, r as PlatformName, S as SafeArea, v as SystemInfo, L as LaunchOptions, k as IPlatformNet, o as IPlatformStorage, i as IPlatformLifecycle, g as IPlatformAuth, e as IPlatformAds, l as IPlatformPayment, h as IPlatformDevice, f as IPlatformAnalytics, m as IPlatformShortcut, j as IPlatformMission, P as PlatformInfo } from './types-WJYVtDfo.js';
2
2
 
3
3
  /**
4
4
  * 平台抽象基类:封装"有 DOM/BOM 的环境"通用实现,供
@@ -35,6 +35,8 @@ declare abstract class BasePlatform implements IPlatform {
35
35
  readonly payment?: IPlatformPayment;
36
36
  readonly device?: IPlatformDevice;
37
37
  readonly analytics?: IPlatformAnalytics;
38
+ readonly shortcut?: IPlatformShortcut;
39
+ readonly mission?: IPlatformMission;
38
40
  get info(): PlatformInfo;
39
41
  abstract init(): Promise<void>;
40
42
  getLaunchOptions(): LaunchOptions;
@@ -161,6 +161,8 @@ var BasePlatform = class {
161
161
  __publicField(this, "payment");
162
162
  __publicField(this, "device");
163
163
  __publicField(this, "analytics");
164
+ __publicField(this, "shortcut");
165
+ __publicField(this, "mission");
164
166
  }
165
167
  get info() {
166
168
  return {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { b as HttpRequestOptions, U as Unsubscribe, H as Handler, n as LogLevel, A as AdResult, r as PurchaseResult, o as LoginResult, d as IPlatform, i as IPlatformLifecycle, S as SafeArea } from './types-DtcRFbM0.js';
2
- export { a as HttpMethod, c as HttpResponse, I as IDisposable, e as IPlatformAds, f as IPlatformAnalytics, g as IPlatformAuth, h as IPlatformDevice, j as IPlatformNet, k as IPlatformPayment, l as IPlatformSocket, m as IPlatformStorage, L as LaunchOptions, P as PlatformInfo, p as PlatformName, q as PlatformUnsupportedError, R as Result, s as SocketOptions, t as SystemInfo, V as Vec2, u as err, v as ok } from './types-DtcRFbM0.js';
1
+ import { b as HttpRequestOptions, U as Unsubscribe, H as Handler, p as LogLevel, A as AdResult, t as PurchaseResult, q as LoginResult, d as IPlatform, i as IPlatformLifecycle, S as SafeArea } from './types-WJYVtDfo.js';
2
+ export { a as HttpMethod, c as HttpResponse, I as IDisposable, e as IPlatformAds, f as IPlatformAnalytics, g as IPlatformAuth, h as IPlatformDevice, j as IPlatformMission, k as IPlatformNet, l as IPlatformPayment, m as IPlatformShortcut, n as IPlatformSocket, o as IPlatformStorage, L as LaunchOptions, P as PlatformInfo, r as PlatformName, s as PlatformUnsupportedError, R as Result, u as SocketOptions, v as SystemInfo, V as Vec2, w as err, x as ok } from './types-WJYVtDfo.js';
3
3
  import Phaser from 'phaser';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { p as PlatformName, h as IPlatformDevice, i as IPlatformLifecycle } from '../types-DtcRFbM0.js';
2
- import { B as BasePlatform } from '../BasePlatform-BCOkvvDW.js';
1
+ import { r as PlatformName, h as IPlatformDevice, i as IPlatformLifecycle } from '../types-WJYVtDfo.js';
2
+ import { B as BasePlatform } from '../BasePlatform-CwVOo3_q.js';
3
3
 
4
4
  /**
5
5
  * Capacitor(原生 WebView 容器)平台适配器。
@@ -1,4 +1,4 @@
1
- import { BasePlatform, DomLifecycle } from '../chunk-H5CUVYCN.js';
1
+ import { BasePlatform, DomLifecycle } from '../chunk-PDESBWLX.js';
2
2
  import { PlatformUnsupportedError } from '../chunk-II3JM4R3.js';
3
3
  import { __publicField } from '../chunk-PKBMQBKP.js';
4
4
 
@@ -1,5 +1,5 @@
1
- import { p as PlatformName, m as IPlatformStorage, g as IPlatformAuth, e as IPlatformAds, k as IPlatformPayment, h as IPlatformDevice, i as IPlatformLifecycle } from '../types-DtcRFbM0.js';
2
- import { B as BasePlatform } from '../BasePlatform-BCOkvvDW.js';
1
+ import { r as PlatformName, o as IPlatformStorage, g as IPlatformAuth, e as IPlatformAds, l as IPlatformPayment, h as IPlatformDevice, i as IPlatformLifecycle } from '../types-WJYVtDfo.js';
2
+ import { B as BasePlatform } from '../BasePlatform-CwVOo3_q.js';
3
3
 
4
4
  /**
5
5
  * Facebook Instant Games 平台适配器。
@@ -1,4 +1,4 @@
1
- import { BasePlatform, DomLifecycle } from '../chunk-H5CUVYCN.js';
1
+ import { BasePlatform, DomLifecycle } from '../chunk-PDESBWLX.js';
2
2
  import { PlatformUnsupportedError } from '../chunk-II3JM4R3.js';
3
3
  import { __publicField } from '../chunk-PKBMQBKP.js';
4
4
 
@@ -1,5 +1,5 @@
1
- import { p as PlatformName, g as IPlatformAuth, e as IPlatformAds, k as IPlatformPayment, h as IPlatformDevice, f as IPlatformAnalytics, i as IPlatformLifecycle } from '../types-DtcRFbM0.js';
2
- import { B as BasePlatform } from '../BasePlatform-BCOkvvDW.js';
1
+ import { r as PlatformName, g as IPlatformAuth, e as IPlatformAds, l as IPlatformPayment, h as IPlatformDevice, f as IPlatformAnalytics, m as IPlatformShortcut, j as IPlatformMission, i as IPlatformLifecycle } from '../types-WJYVtDfo.js';
2
+ import { B as BasePlatform } from '../BasePlatform-CwVOo3_q.js';
3
3
 
4
4
  /**
5
5
  * TikTok Mini Games(Minis)平台适配器。
@@ -23,6 +23,8 @@ declare class TikTokPlatform extends BasePlatform {
23
23
  readonly payment: IPlatformPayment;
24
24
  readonly device: IPlatformDevice;
25
25
  readonly analytics: IPlatformAnalytics;
26
+ readonly shortcut: IPlatformShortcut;
27
+ readonly mission: IPlatformMission;
26
28
  readonly lifecycle: IPlatformLifecycle;
27
29
  init(): Promise<void>;
28
30
  }
@@ -1,4 +1,4 @@
1
- import { BasePlatform } from '../chunk-H5CUVYCN.js';
1
+ import { BasePlatform } from '../chunk-PDESBWLX.js';
2
2
  import { PlatformUnsupportedError } from '../chunk-II3JM4R3.js';
3
3
  import { __publicField } from '../chunk-PKBMQBKP.js';
4
4
 
@@ -10,40 +10,183 @@ 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 {
26
- async preloadRewarded(adUnitId) {
27
- requireTT("ads.preloadRewarded");
28
- await TTMinis.game.preloadRewardedVideo(adUnitId ? { adUnitId } : void 0);
36
+ // TikTok H5 SDK 只有 createRewardedVideoAd(没有 preload/show/Interstitial 单独 API,
37
+ // 实测 2026-05-28 反编译 connect.tiktok-minis.com/game/sdk.js 36 个 game.* 方法确认)
38
+ // 之前 framework preloadRewardedVideo / showRewardedVideo / showInterstitialAd 全部
39
+ // throw TypeError,被 try-catch 吞掉返 'failed',审核因此判"未集成有效营收功能"。
40
+ //
41
+ // 修复:统一走 createRewardedVideoAd(优先同步签名拿 ad 实例,失败试异步 callback 签名),
42
+ // ad.onClose 等结果后 ad.show 触发展示;preloadRewarded 退化为 noop(SDK 自身管预加载)。
43
+ async preloadRewarded(_adUnitId) {
29
44
  }
30
- async showRewarded(adUnitId) {
45
+ showRewarded(adUnitId) {
31
46
  requireTT("ads.showRewarded");
47
+ return new Promise((resolve) => {
48
+ const onResult = (isEnded) => resolve(isEnded ? "completed" : "skipped");
49
+ const onError = (msg) => {
50
+ console.warn("[ads.showRewarded] error:", msg);
51
+ resolve("failed");
52
+ };
53
+ try {
54
+ const adSync = TTMinis.game.createRewardedVideoAd({ adUnitId });
55
+ if (adSync && typeof adSync.show === "function") {
56
+ this.wireAd(adSync, onResult, onError);
57
+ return;
58
+ }
59
+ } catch (e) {
60
+ console.warn("[ads] sync createRewardedVideoAd failed, try async:", e?.message);
61
+ }
62
+ try {
63
+ TTMinis.game.createRewardedVideoAd((res) => {
64
+ if (res?.is_success && res.rewardedVideoAd) {
65
+ this.wireAd(res.rewardedVideoAd, onResult, onError);
66
+ } else {
67
+ onError(JSON.stringify(res?.error ?? "create failed"));
68
+ }
69
+ }, { adUnitId });
70
+ } catch (e) {
71
+ onError(e?.message ?? "createRewardedVideoAd both signatures failed");
72
+ }
73
+ });
74
+ }
75
+ wireAd(ad, onResult, onError) {
76
+ let settled = false;
32
77
  try {
33
- const res = await TTMinis.game.showRewardedVideo(adUnitId ? { adUnitId } : void 0);
34
- return res?.isEnded ? "completed" : "skipped";
35
- } catch {
36
- return "failed";
78
+ ad.onClose((res) => {
79
+ if (settled) return;
80
+ settled = true;
81
+ onResult(!!res?.isEnded);
82
+ });
83
+ } catch (e) {
84
+ onError(`onClose unsupported: ${e?.message}`);
85
+ return;
37
86
  }
87
+ if (typeof ad.onError === "function") {
88
+ try {
89
+ ad.onError((res) => {
90
+ if (settled) return;
91
+ settled = true;
92
+ onError(res?.error?.error_msg ?? "ad error");
93
+ });
94
+ } catch {
95
+ }
96
+ }
97
+ void ad.show().catch((e) => {
98
+ if (settled) return;
99
+ settled = true;
100
+ onError(e?.message ?? "show rejected");
101
+ });
38
102
  }
39
- async showInterstitial(adUnitId) {
40
- requireTT("ads.showInterstitial");
41
- try {
42
- await TTMinis.game.showInterstitialAd(adUnitId ? { adUnitId } : void 0);
43
- return "closed";
44
- } catch {
45
- return "failed";
103
+ async showInterstitial(_adUnitId) {
104
+ return "failed";
105
+ }
106
+ };
107
+ var TikTokShortcut = class {
108
+ // SDK callback-style API;每个都用 typeof 检测 + 静默降级,避免老 SDK 没此方法 throw 阻断业务。
109
+ check() {
110
+ if (!hasTT() || typeof TTMinis.game.checkShortcut !== "function") return Promise.resolve(false);
111
+ return new Promise((resolve) => {
112
+ try {
113
+ TTMinis.game.checkShortcut({
114
+ success: (res) => resolve(!!res?.exist),
115
+ fail: () => resolve(false)
116
+ });
117
+ } catch {
118
+ resolve(false);
119
+ }
120
+ });
121
+ }
122
+ add() {
123
+ if (!hasTT() || typeof TTMinis.game.addShortcut !== "function") return Promise.resolve(false);
124
+ return new Promise((resolve) => {
125
+ try {
126
+ TTMinis.game.addShortcut({
127
+ success: () => resolve(true),
128
+ fail: () => resolve(false)
129
+ });
130
+ } catch {
131
+ resolve(false);
132
+ }
133
+ });
134
+ }
135
+ getMissionReward() {
136
+ if (!hasTT() || typeof TTMinis.game.getShortcutMissionReward !== "function") {
137
+ return Promise.resolve({ canReceive: false });
46
138
  }
139
+ return new Promise((resolve) => {
140
+ try {
141
+ TTMinis.game.getShortcutMissionReward({
142
+ success: (res) => resolve({ canReceive: !!res?.canReceiveReward }),
143
+ fail: () => resolve({ canReceive: false })
144
+ });
145
+ } catch {
146
+ resolve({ canReceive: false });
147
+ }
148
+ });
149
+ }
150
+ };
151
+ var TikTokMission = class {
152
+ startEntrance() {
153
+ if (!hasTT() || typeof TTMinis.game.startEntranceMission !== "function") return Promise.resolve({ ok: false });
154
+ return new Promise((resolve) => {
155
+ try {
156
+ TTMinis.game.startEntranceMission({
157
+ success: () => resolve({ ok: true }),
158
+ fail: () => resolve({ ok: false })
159
+ });
160
+ } catch {
161
+ resolve({ ok: false });
162
+ }
163
+ });
164
+ }
165
+ getEntranceReward() {
166
+ if (!hasTT() || typeof TTMinis.game.getEntranceMissionReward !== "function") return Promise.resolve({ canReceive: false });
167
+ return new Promise((resolve) => {
168
+ try {
169
+ TTMinis.game.getEntranceMissionReward({
170
+ success: (res) => resolve({ canReceive: !!res?.canReceiveReward }),
171
+ fail: () => resolve({ canReceive: false })
172
+ });
173
+ } catch {
174
+ resolve({ canReceive: false });
175
+ }
176
+ });
177
+ }
178
+ getFyfReward() {
179
+ if (!hasTT() || typeof TTMinis.game.getFyfMissionReward !== "function") return Promise.resolve({ canReceive: false });
180
+ return new Promise((resolve) => {
181
+ try {
182
+ TTMinis.game.getFyfMissionReward({
183
+ success: (res) => resolve({ canReceive: !!res?.canReceiveReward }),
184
+ fail: () => resolve({ canReceive: false })
185
+ });
186
+ } catch {
187
+ resolve({ canReceive: false });
188
+ }
189
+ });
47
190
  }
48
191
  };
49
192
  var TikTokPayment = class {
@@ -141,6 +284,8 @@ var TikTokPlatform = class extends BasePlatform {
141
284
  __publicField(this, "payment", new TikTokPayment());
142
285
  __publicField(this, "device", new TikTokDevice());
143
286
  __publicField(this, "analytics", new TikTokAnalytics());
287
+ __publicField(this, "shortcut", new TikTokShortcut());
288
+ __publicField(this, "mission", new TikTokMission());
144
289
  // 用 TTMinis 桥接的生命周期,缺失时由其内部退回 noop;DOM 退路在 init 中按需补
145
290
  __publicField(this, "lifecycle", new TikTokLifecycle());
146
291
  }
@@ -1,5 +1,5 @@
1
- import { p as PlatformName, h as IPlatformDevice } from '../types-DtcRFbM0.js';
2
- import { B as BasePlatform } from '../BasePlatform-BCOkvvDW.js';
1
+ import { r as PlatformName, h as IPlatformDevice } from '../types-WJYVtDfo.js';
2
+ import { B as BasePlatform } from '../BasePlatform-CwVOo3_q.js';
3
3
 
4
4
  /**
5
5
  * Web(普通浏览器 / H5)平台适配器。
@@ -1,4 +1,4 @@
1
- import { BasePlatform } from '../chunk-H5CUVYCN.js';
1
+ import { BasePlatform } from '../chunk-PDESBWLX.js';
2
2
  import { __publicField } from '../chunk-PKBMQBKP.js';
3
3
 
4
4
  // src/platform/impl/web/WebPlatform.ts
@@ -1,4 +1,4 @@
1
- import { d as IPlatform, j as IPlatformNet, m as IPlatformStorage, i as IPlatformLifecycle, g as IPlatformAuth, e as IPlatformAds, k as IPlatformPayment, h as IPlatformDevice, P as PlatformInfo, L as LaunchOptions } from '../types-DtcRFbM0.js';
1
+ import { d as IPlatform, k as IPlatformNet, o as IPlatformStorage, i as IPlatformLifecycle, g as IPlatformAuth, e as IPlatformAds, l as IPlatformPayment, h as IPlatformDevice, P as PlatformInfo, L as LaunchOptions } from '../types-WJYVtDfo.js';
2
2
 
3
3
  /**
4
4
  * 微信小游戏平台适配器。
@@ -207,6 +207,32 @@ interface IPlatformDevice {
207
207
  query?: string;
208
208
  }): Promise<void>;
209
209
  }
210
+ /** 桌面快捷方式(TikTok minigame 审核硬性要求;不支持的平台为 undefined) */
211
+ interface IPlatformShortcut {
212
+ /** 是否已添加到桌面(平台不支持时 resolve false) */
213
+ check(): Promise<boolean>;
214
+ /** 触发平台原生"添加到桌面"系统提示,resolve 表示添加成功 */
215
+ add(): Promise<boolean>;
216
+ /** 查询"添加桌面快捷方式"任务奖励状态(可领取且未领取返 true) */
217
+ getMissionReward?(): Promise<{
218
+ canReceive: boolean;
219
+ }>;
220
+ }
221
+ /** 任务系统(TikTok minigame 审核硬性要求 - 侧边栏入口任务) */
222
+ interface IPlatformMission {
223
+ /** 触发侧边栏入口任务(SDK 把用户带到 TikTok profile sidebar 完成教育流程) */
224
+ startEntrance(): Promise<{
225
+ ok: boolean;
226
+ }>;
227
+ /** 查询入口任务奖励状态 */
228
+ getEntranceReward(): Promise<{
229
+ canReceive: boolean;
230
+ }>;
231
+ /** 查询"For You Feed 入口"任务奖励状态(若启用) */
232
+ getFyfReward?(): Promise<{
233
+ canReceive: boolean;
234
+ }>;
235
+ }
210
236
  /** 平台原生埋点(可选;通常业务用 AnalyticsManager 统一上报) */
211
237
  interface IPlatformAnalytics {
212
238
  reportEvent(name: string, params?: Record<string, unknown>): void;
@@ -234,6 +260,8 @@ interface IPlatform {
234
260
  readonly payment?: IPlatformPayment;
235
261
  readonly device?: IPlatformDevice;
236
262
  readonly analytics?: IPlatformAnalytics;
263
+ readonly shortcut?: IPlatformShortcut;
264
+ readonly mission?: IPlatformMission;
237
265
  }
238
266
 
239
- export { type AdResult as A, type Handler as H, type IDisposable as I, type LaunchOptions as L, type PlatformInfo as P, type Result as R, type SafeArea as S, type Unsubscribe as U, type Vec2 as V, type HttpMethod as a, type HttpRequestOptions as b, type HttpResponse as c, type IPlatform as d, type IPlatformAds as e, type IPlatformAnalytics as f, type IPlatformAuth as g, type IPlatformDevice as h, type IPlatformLifecycle as i, type IPlatformNet as j, type IPlatformPayment as k, type IPlatformSocket as l, type IPlatformStorage as m, LogLevel as n, type LoginResult as o, type PlatformName as p, PlatformUnsupportedError as q, type PurchaseResult as r, type SocketOptions as s, type SystemInfo as t, err as u, ok as v };
267
+ export { type AdResult as A, type Handler as H, type IDisposable as I, type LaunchOptions as L, type PlatformInfo as P, type Result as R, type SafeArea as S, type Unsubscribe as U, type Vec2 as V, type HttpMethod as a, type HttpRequestOptions as b, type HttpResponse as c, type IPlatform as d, type IPlatformAds as e, type IPlatformAnalytics as f, type IPlatformAuth as g, type IPlatformDevice as h, type IPlatformLifecycle as i, type IPlatformMission as j, type IPlatformNet as k, type IPlatformPayment as l, type IPlatformShortcut as m, type IPlatformSocket as n, type IPlatformStorage as o, LogLevel as p, type LoginResult as q, type PlatformName as r, PlatformUnsupportedError as s, type PurchaseResult as t, type SocketOptions as u, type SystemInfo as v, err as w, ok as x };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maoyugames/phaser-framework",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "多平台 Phaser 游戏框架:业务/底层分离,HTTP/WebSocket/KCP,Web/TikTok/微信/Facebook/App 隔离打包",
5
5
  "type": "module",
6
6
  "license": "MIT",