@chiyou/minigame-framework 1.3.2 → 1.3.4
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/package.json +1 -1
- package/src/Framework/Definition/AnalyticsDefinition.ts +1 -46
- package/src/Framework/Definition/FrameworkBase.ts +2 -0
- package/src/Framework/Definition/UserDefinition.ts +0 -12
- package/src/Framework/Manager/AnalyticsMgr.ts +22 -22
- package/src/Framework/Manager/UserMgr.ts +5 -145
- package/src/Framework/SDK/Umeng/umtrack-wx-game.ts +8 -38
package/package.json
CHANGED
|
@@ -24,52 +24,6 @@ export interface UmengConfig {
|
|
|
24
24
|
debug?: boolean;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
/** 统计分析总配置 */
|
|
28
|
-
export interface AnalyticsConfig {
|
|
29
|
-
/** 是否启用统计功能 */
|
|
30
|
-
enable: boolean;
|
|
31
|
-
/** 友盟配置 */
|
|
32
|
-
umeng?: UmengConfig;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// ==================== 用户相关 ====================
|
|
36
|
-
|
|
37
|
-
/** 用户属性 */
|
|
38
|
-
export interface UserProperties {
|
|
39
|
-
userId?: string;
|
|
40
|
-
provider?: string;
|
|
41
|
-
nickName?: string;
|
|
42
|
-
avatarUrl?: string;
|
|
43
|
-
gender?: number;
|
|
44
|
-
country?: string;
|
|
45
|
-
province?: string;
|
|
46
|
-
city?: string;
|
|
47
|
-
[key: string]: any;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// ==================== 友盟 SDK 接口 ====================
|
|
51
|
-
|
|
52
|
-
/** 友盟 SDK 实例方法 */
|
|
53
|
-
export interface UmengSDK {
|
|
54
|
-
init(config: UmengConfig): void;
|
|
55
|
-
resume(options?: any): void;
|
|
56
|
-
pause(): void;
|
|
57
|
-
trackEvent(eventName: string, params?: object | string): void;
|
|
58
|
-
trackShare(shareOptions: object): object;
|
|
59
|
-
trackPageStart(pageName: string): void;
|
|
60
|
-
trackPageEnd(pageName: string): void;
|
|
61
|
-
setOpenid(openid: string): void;
|
|
62
|
-
setUnionid(unionid: string): void;
|
|
63
|
-
setUserid(userid: string, provider?: string): void;
|
|
64
|
-
removeUserid(): void;
|
|
65
|
-
setUserInfo(userInfo: object): void;
|
|
66
|
-
setAnonymousid(anonymousid: string): void;
|
|
67
|
-
setAppVersion(version: string): void;
|
|
68
|
-
setSuperProperty(property: string): void;
|
|
69
|
-
onShareAppMessage(callback: () => object): void;
|
|
70
|
-
shareAppMessage(options: object): void;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
27
|
// ==================== 预定义事件 ID ====================
|
|
74
28
|
|
|
75
29
|
/** 预定义事件 ID */
|
|
@@ -102,6 +56,7 @@ export enum AnalyticsParamKey {
|
|
|
102
56
|
Price = 'price',
|
|
103
57
|
Currency = 'currency',
|
|
104
58
|
ShareType = 'share_type',
|
|
59
|
+
ShareContent = 'share_content',
|
|
105
60
|
ErrorCode = 'error_code',
|
|
106
61
|
ErrorMsg = 'error_msg',
|
|
107
62
|
}
|
|
@@ -21,5 +21,7 @@ export class FrameworkBase {
|
|
|
21
21
|
static readonly Message = class {
|
|
22
22
|
static readonly LifeCycle_onGameHide: string = "LifeCycle_onGameHide";
|
|
23
23
|
static readonly LifeCycle_onGameShow: string = "LifeCycle_onGameShow";
|
|
24
|
+
|
|
25
|
+
static readonly UserMgr_PlatformOpenId_Ready: string = "UserMgr_PlatformOpenId_Ready";
|
|
24
26
|
}
|
|
25
27
|
}
|
|
@@ -76,16 +76,4 @@ export enum UpdateUserDataResult {
|
|
|
76
76
|
Result_NoNeed = -1,
|
|
77
77
|
Result_Success = 0,
|
|
78
78
|
Result_Fail = 1,
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export enum LoginResultType {
|
|
82
|
-
Type_SessionAvailable = 0,
|
|
83
|
-
Type_LoginSuccess_Auth_Code = 1,
|
|
84
|
-
Type_LoginSuccess_Auth_AccountID = 2,
|
|
85
|
-
Type_LoginFail_ContinueGame = 3,
|
|
86
|
-
Type_LoginFail_ExitGame = 4,
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export type LoginResult = {
|
|
90
|
-
type: LoginResultType;
|
|
91
79
|
}
|
|
@@ -3,8 +3,10 @@ import { LogUtils } from "../Utils/LogUtils";
|
|
|
3
3
|
import { ServiceLocator } from "../Utils/ServiceLocator";
|
|
4
4
|
import { FwkErrorCode } from "../Definition/FwkErrorDefinition";
|
|
5
5
|
import { PlatformID } from "../Definition/SystemDefinition";
|
|
6
|
-
import { UmengConfig, EventParams,
|
|
6
|
+
import { UmengConfig, EventParams, AnalyticsEventId, AnalyticsParamKey } from "../Definition/AnalyticsDefinition";
|
|
7
7
|
import { UmaInitConfig, UmaSDK, uma as wxUma } from "../SDK/Umeng/umtrack-wx-game";
|
|
8
|
+
import { EventMgr } from "./EventMgr";
|
|
9
|
+
import { FrameworkBase } from "../Definition/FrameworkBase";
|
|
8
10
|
// 后续新增平台 SDK 在此导入,例如:
|
|
9
11
|
// import { uma as ttUma } from "../SDK/Umeng/umtrack-tt-game";
|
|
10
12
|
|
|
@@ -53,9 +55,13 @@ export class AnalyticsMgr extends BaseMgr {
|
|
|
53
55
|
|
|
54
56
|
// 注意:SDK 内部已注册 wx.onShow/onHide 自动调用 resume/pause
|
|
55
57
|
// 无需在 AnalyticsMgr 监听生命周期事件
|
|
58
|
+
|
|
59
|
+
EventMgr.Instance.on(FrameworkBase.Message.UserMgr_PlatformOpenId_Ready, this._onPlatformOpenIdReady, this);
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
onDestroy(): void {
|
|
63
|
+
EventMgr.Instance.off(FrameworkBase.Message.UserMgr_PlatformOpenId_Ready, this._onPlatformOpenIdReady, this);
|
|
64
|
+
|
|
59
65
|
super.onDestroy();
|
|
60
66
|
}
|
|
61
67
|
|
|
@@ -92,8 +98,7 @@ export class AnalyticsMgr extends BaseMgr {
|
|
|
92
98
|
if (appKey && sdk) {
|
|
93
99
|
this._appKey = appKey;
|
|
94
100
|
this._sdk = sdk;
|
|
95
|
-
this._isEnabled =
|
|
96
|
-
this._initUmeng();
|
|
101
|
+
this._isEnabled = this._initUmeng();
|
|
97
102
|
} else {
|
|
98
103
|
this._isEnabled = false;
|
|
99
104
|
if (!sdk) {
|
|
@@ -114,6 +119,14 @@ export class AnalyticsMgr extends BaseMgr {
|
|
|
114
119
|
});
|
|
115
120
|
}
|
|
116
121
|
|
|
122
|
+
private _onPlatformOpenIdReady(platformOpenId: string): void {
|
|
123
|
+
if (!this._isEnabled) return;
|
|
124
|
+
|
|
125
|
+
if (this._umengConfig && this._umengConfig.useOpenid && !this._umengConfig.autoGetOpenid) {
|
|
126
|
+
this.setOpenId(platformOpenId);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
117
130
|
// ==================== 生命周期 ====================
|
|
118
131
|
// 注意:SDK 内部已自动处理 wx.onShow/onHide 的 resume/pause 调用
|
|
119
132
|
|
|
@@ -222,23 +235,6 @@ export class AnalyticsMgr extends BaseMgr {
|
|
|
222
235
|
}
|
|
223
236
|
}
|
|
224
237
|
|
|
225
|
-
/**
|
|
226
|
-
* 设置用户属性
|
|
227
|
-
* @param properties 用户属性
|
|
228
|
-
*/
|
|
229
|
-
public setUserProperties(properties: UserProperties): void {
|
|
230
|
-
if (!this._isEnabled) return;
|
|
231
|
-
try {
|
|
232
|
-
this._sdk.setUserInfo(properties);
|
|
233
|
-
LogUtils.Instance.info(AnalyticsMgr.TAG, "设置用户属性");
|
|
234
|
-
} catch (e) {
|
|
235
|
-
LogUtils.Instance.error(AnalyticsMgr.TAG, FwkErrorCode.Analytics.SDKCallFailed, {
|
|
236
|
-
operation: "setUserProperties",
|
|
237
|
-
reason: String(e),
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
238
|
// ==================== 游戏特定事件 ====================
|
|
243
239
|
|
|
244
240
|
/** 关卡开始 */
|
|
@@ -295,7 +291,7 @@ export class AnalyticsMgr extends BaseMgr {
|
|
|
295
291
|
public trackShare(shareType: string, shareContent?: string): void {
|
|
296
292
|
const params: Record<string, any> = {
|
|
297
293
|
[AnalyticsParamKey.ShareType]: shareType,
|
|
298
|
-
...(shareContent ? { [AnalyticsParamKey.
|
|
294
|
+
...(shareContent ? { [AnalyticsParamKey.ShareContent]: shareContent } : {}),
|
|
299
295
|
};
|
|
300
296
|
this.trackEvent(AnalyticsEventId.Share, params);
|
|
301
297
|
}
|
|
@@ -317,7 +313,7 @@ export class AnalyticsMgr extends BaseMgr {
|
|
|
317
313
|
// ==================== 私有方法 ====================
|
|
318
314
|
|
|
319
315
|
/** 初始化友盟 SDK */
|
|
320
|
-
private _initUmeng():
|
|
316
|
+
private _initUmeng(): boolean {
|
|
321
317
|
try {
|
|
322
318
|
const sdkConfig: UmaInitConfig = {
|
|
323
319
|
appKey: this._appKey,
|
|
@@ -331,12 +327,16 @@ export class AnalyticsMgr extends BaseMgr {
|
|
|
331
327
|
useOpenid: sdkConfig.useOpenid,
|
|
332
328
|
debug: sdkConfig.debug,
|
|
333
329
|
});
|
|
330
|
+
|
|
331
|
+
return true;
|
|
334
332
|
} catch (e) {
|
|
335
333
|
LogUtils.Instance.error(AnalyticsMgr.TAG, FwkErrorCode.Analytics.SDKInitFailed, {
|
|
336
334
|
operation: "_initUmeng",
|
|
337
335
|
reason: String(e),
|
|
338
336
|
appKey: this._appKey,
|
|
339
337
|
});
|
|
338
|
+
|
|
339
|
+
return false;
|
|
340
340
|
}
|
|
341
341
|
}
|
|
342
342
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FrameworkBase } from "../Definition/FrameworkBase";
|
|
2
|
-
import { EnhanceLoginResult, LocalLoginResult,
|
|
2
|
+
import { EnhanceLoginResult, LocalLoginResult, ServerGetUserDataResult, ServerLoginResult, ServerUpdateUserDataResult, UpdateUserDataResult, UserBehaviorPlatformInfo, UserDataCategory, UserDataInfo, UserDataKey, UserDataType } from "../Definition/UserDefinition";
|
|
3
3
|
import { FwkErrorCode } from "../Definition/FwkErrorDefinition";
|
|
4
4
|
import { LogUtils } from "../Utils/LogUtils";
|
|
5
5
|
import { BaseMgr } from "./BaseMgr";
|
|
@@ -240,150 +240,6 @@ export class UserMgr extends BaseMgr {
|
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
-
/**
|
|
244
|
-
* 登录
|
|
245
|
-
* @param needForceLogin 是否强制登录
|
|
246
|
-
* @param callback 登录回调
|
|
247
|
-
*/
|
|
248
|
-
public login(needForceLogin: boolean, callback: Function): void {
|
|
249
|
-
if (callback === null) {
|
|
250
|
-
LogUtils.Instance.error(UserMgr.TAG, FwkErrorCode.User.InvalidData, {
|
|
251
|
-
operation: "login",
|
|
252
|
-
reason: "回调函数为空"
|
|
253
|
-
});
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
if (this.currentPlatformAdapter === null) {
|
|
258
|
-
LogUtils.Instance.error(UserMgr.TAG, FwkErrorCode.User.NotInit, {
|
|
259
|
-
operation: "login",
|
|
260
|
-
reason: "平台适配器未初始化"
|
|
261
|
-
});
|
|
262
|
-
callback({
|
|
263
|
-
type: LoginResultType.Type_LoginFail_ContinueGame,
|
|
264
|
-
});
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
if (this.currentPlatformId === PlatformID.ID_H5_DesktopBrowser ||
|
|
269
|
-
this.currentPlatformId === PlatformID.ID_MiniGame_ZhiFuBao ||
|
|
270
|
-
this.currentPlatformId === PlatformID.ID_QuickGame_HuaWei ||
|
|
271
|
-
this.currentPlatformId === PlatformID.ID_QuickGame_Honor ||
|
|
272
|
-
this.currentPlatformId === PlatformID.ID_QuickGame_Vivo ||
|
|
273
|
-
this.currentPlatformId === PlatformID.ID_QuickGame_XiaoMi ||
|
|
274
|
-
this.currentPlatformId === PlatformID.ID_QuickGame_Oppo
|
|
275
|
-
) {
|
|
276
|
-
needForceLogin = true;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
LogUtils.Instance.info(UserMgr.TAG, "开始登录", {
|
|
280
|
-
needForceLogin: needForceLogin,
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
if (!needForceLogin) {
|
|
284
|
-
this._checkSession().then((loginResult: LoginResult) => {
|
|
285
|
-
callback(loginResult);
|
|
286
|
-
}).catch(() => {
|
|
287
|
-
this._login().then((loginResult: LoginResult) => {
|
|
288
|
-
callback(loginResult);
|
|
289
|
-
}).catch((loginResult: LoginResult) => {
|
|
290
|
-
LogUtils.Instance.info(UserMgr.TAG, "用户登录失败(Session检查失败后重试登录)", {
|
|
291
|
-
resultType: loginResult.type,
|
|
292
|
-
canContinue: loginResult.type === LoginResultType.Type_LoginFail_ContinueGame,
|
|
293
|
-
});
|
|
294
|
-
callback(loginResult);
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
} else {
|
|
298
|
-
this._login().then((loginResult: LoginResult) => {
|
|
299
|
-
callback(loginResult);
|
|
300
|
-
}).catch((loginResult: LoginResult) => {
|
|
301
|
-
LogUtils.Instance.info(UserMgr.TAG, "用户登录失败(强制登录模式)", {
|
|
302
|
-
resultType: loginResult.type,
|
|
303
|
-
canContinue: loginResult.type === LoginResultType.Type_LoginFail_ContinueGame
|
|
304
|
-
});
|
|
305
|
-
callback(loginResult);
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/** 检查 Session(内部方法) */
|
|
311
|
-
private _checkSession(): Promise<LoginResult> {
|
|
312
|
-
return new Promise((resolve, reject) => {
|
|
313
|
-
if (this.currentPlatformAdapter === null) {
|
|
314
|
-
reject();
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
this.currentPlatformAdapter.checkSession(
|
|
319
|
-
(isValid: boolean) => {
|
|
320
|
-
LogUtils.Instance.info(UserMgr.TAG, "_checkSession()结果", {
|
|
321
|
-
isValid: isValid,
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
if (isValid) {
|
|
325
|
-
resolve({
|
|
326
|
-
type: LoginResultType.Type_SessionAvailable,
|
|
327
|
-
});
|
|
328
|
-
} else {
|
|
329
|
-
reject();
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
/** 登录(内部方法) */
|
|
336
|
-
private _login(): Promise<LoginResult> {
|
|
337
|
-
return new Promise((resolve, reject) => {
|
|
338
|
-
if (this.currentPlatformAdapter === null) {
|
|
339
|
-
reject("");
|
|
340
|
-
return;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
this.currentPlatformAdapter.login(
|
|
344
|
-
(res) => {
|
|
345
|
-
// 华为:playerId
|
|
346
|
-
// 小米:appAccountId
|
|
347
|
-
// 其他平台:code
|
|
348
|
-
LogUtils.Instance.info(UserMgr.TAG, "_login()成功", {
|
|
349
|
-
res: res,
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
if (res) {
|
|
353
|
-
if (res.code) {
|
|
354
|
-
resolve({
|
|
355
|
-
type: LoginResultType.Type_LoginSuccess_Auth_Code,
|
|
356
|
-
});
|
|
357
|
-
} else if (res.playerId || res.appAccountId) {
|
|
358
|
-
resolve({
|
|
359
|
-
type: LoginResultType.Type_LoginSuccess_Auth_AccountID,
|
|
360
|
-
});
|
|
361
|
-
} else {
|
|
362
|
-
reject({
|
|
363
|
-
type: LoginResultType.Type_LoginFail_ContinueGame,
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
} else {
|
|
367
|
-
reject({
|
|
368
|
-
type: LoginResultType.Type_LoginFail_ContinueGame,
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
}, () => {
|
|
372
|
-
LogUtils.Instance.info(UserMgr.TAG, "_login()失败", {});
|
|
373
|
-
|
|
374
|
-
if (this.currentPlatformId === PlatformID.ID_QuickGame_HuaWei) {
|
|
375
|
-
reject({
|
|
376
|
-
type: LoginResultType.Type_LoginFail_ExitGame,
|
|
377
|
-
});
|
|
378
|
-
} else {
|
|
379
|
-
reject({
|
|
380
|
-
type: LoginResultType.Type_LoginFail_ContinueGame,
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
});
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
|
|
387
243
|
public async enhanceLogin(
|
|
388
244
|
loginCallbackFunc: (result: EnhanceLoginResult) => void,
|
|
389
245
|
): Promise<void> {
|
|
@@ -468,6 +324,10 @@ export class UserMgr extends BaseMgr {
|
|
|
468
324
|
}
|
|
469
325
|
}
|
|
470
326
|
|
|
327
|
+
if (this.platformOpenId !== "") {
|
|
328
|
+
EventMgr.Instance.emit(FrameworkBase.Message.UserMgr_PlatformOpenId_Ready, this.platformOpenId);
|
|
329
|
+
}
|
|
330
|
+
|
|
471
331
|
let needServerUserData: boolean = false;
|
|
472
332
|
if (this.uid !== "" && this.userBehaviorPlatformInfo.supportServerUserData) {
|
|
473
333
|
needServerUserData = true;
|
|
@@ -32,23 +32,16 @@ export interface UmaInitConfig {
|
|
|
32
32
|
debug?: boolean;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
/**
|
|
36
|
-
* 用户信息
|
|
37
|
-
*/
|
|
38
|
-
export interface UmaUserInfo {
|
|
39
|
-
nickName?: string;
|
|
40
|
-
avatarUrl?: string;
|
|
41
|
-
gender?: number;
|
|
42
|
-
country?: string;
|
|
43
|
-
province?: string;
|
|
44
|
-
city?: string;
|
|
45
|
-
language?: string;
|
|
46
|
-
age?: number;
|
|
47
|
-
constellation?: string;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
35
|
/**
|
|
51
36
|
* 友盟 SDK 接口定义
|
|
37
|
+
*
|
|
38
|
+
* 注意:仅包含实际可用的方法(共12个)
|
|
39
|
+
* - installApi 代理(11个):resume, pause, trackEvent, trackPageStart, trackPageEnd,
|
|
40
|
+
* trackShare, setUserid, setOpenid, setUnionid, onShareAppMessage, shareAppMessage
|
|
41
|
+
* - pe 直接定义(1个):init
|
|
42
|
+
* - 不可用方法(定义在 re 类但未代理到 pe):removeUserid, setUserInfo, setAnonymousid,
|
|
43
|
+
* setAppVersion, setSuperProperty
|
|
44
|
+
* - 插件方法(通过 pe.use 安装):revenue, stage, level, rc(已移除,不在接口中)
|
|
52
45
|
*/
|
|
53
46
|
export interface UmaSDK {
|
|
54
47
|
/** 初始化 */
|
|
@@ -71,33 +64,10 @@ export interface UmaSDK {
|
|
|
71
64
|
setUnionid(unionid: string): void;
|
|
72
65
|
/** 设置用户 ID */
|
|
73
66
|
setUserid(userid: string, provider?: string): void;
|
|
74
|
-
/** 移除用户 ID */
|
|
75
|
-
removeUserid(): void;
|
|
76
|
-
/** 设置用户信息 */
|
|
77
|
-
setUserInfo(userInfo: UmaUserInfo): void;
|
|
78
|
-
/** 设置匿名 ID */
|
|
79
|
-
setAnonymousid(anonymousid: string): void;
|
|
80
|
-
/** 设置应用版本 */
|
|
81
|
-
setAppVersion(version: string): void;
|
|
82
|
-
/** 设置超级属性 */
|
|
83
|
-
setSuperProperty(property: string): void;
|
|
84
67
|
/** 注册分享回调 */
|
|
85
68
|
onShareAppMessage(callback: () => object): void;
|
|
86
69
|
/** 调用分享 */
|
|
87
70
|
shareAppMessage(options: object): void;
|
|
88
|
-
/** 收入事件 */
|
|
89
|
-
revenue?: (params: { group: string; [key: string]: any }) => void;
|
|
90
|
-
/** 关卡事件 */
|
|
91
|
-
stage?: {
|
|
92
|
-
onStart: (params: { [key: string]: any }) => void;
|
|
93
|
-
onEnd: (params: { event: string; [key: string]: any }) => void;
|
|
94
|
-
onRunning: (params: { event: string; [key: string]: any }) => void;
|
|
95
|
-
};
|
|
96
|
-
/** 等级事件 */
|
|
97
|
-
level?: {
|
|
98
|
-
onInitLevel: (params: { [key: string]: any }) => void;
|
|
99
|
-
onSetLevel: (params: { [key: string]: any }) => void;
|
|
100
|
-
};
|
|
101
71
|
}
|
|
102
72
|
|
|
103
73
|
// ============================================
|