@jolibox/implement 1.1.50 → 1.1.51

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,9 +1,9 @@
1
1
  Invoking: npm run clean && npm run build:esm && tsc
2
2
 
3
- > @jolibox/implement@1.1.50 clean
3
+ > @jolibox/implement@1.1.51 clean
4
4
  > rimraf ./dist
5
5
 
6
6
 
7
- > @jolibox/implement@1.1.50 build:esm
7
+ > @jolibox/implement@1.1.51 build:esm
8
8
  > BUILD_VERSION=$(node -p "require('./package.json').version") node esbuild.config.js --format=esm
9
9
 
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@jolibox/implement",
3
3
  "description": "This project is Jolibox JS-SDk implement for Native && H5",
4
- "version": "1.1.50",
4
+ "version": "1.1.51",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
7
7
  "license": "MIT",
8
8
  "dependencies": {
9
- "@jolibox/common": "1.1.50",
10
- "@jolibox/types": "1.1.50",
11
- "@jolibox/native-bridge": "1.1.50",
12
- "@jolibox/ads": "1.1.50",
9
+ "@jolibox/common": "1.1.51",
10
+ "@jolibox/types": "1.1.51",
11
+ "@jolibox/native-bridge": "1.1.51",
12
+ "@jolibox/ads": "1.1.51",
13
13
  "localforage": "1.10.0",
14
14
  "@jolibox/ui": "1.0.0",
15
15
  "web-vitals": "4.2.4"
@@ -9,10 +9,13 @@ type TaskEvent =
9
9
  | 'USE_GAME_ITEM' // TODO: deprecate
10
10
  | 'IN_GAME_PURCHASES' // 游戏内购
11
11
  | 'ADS_UNLOCK_GAME' // 广告解锁
12
- | 'GAME_TASK_EVENT'; // 关卡行为
12
+ | 'GAME_TASK_EVENT' // 关卡行为
13
+ | 'GAME_ENDED' // 游戏结束
14
+ | 'GAME_LEVEL_UP'; // 游戏关卡升级
13
15
  export type TaskPoint = {
14
16
  event: TaskEvent;
15
17
  params?: Record<string, unknown>;
18
+ extraParams?: Record<string, unknown>;
16
19
  };
17
20
  export abstract class TaskTracker {
18
21
  interval: number;
@@ -4,8 +4,12 @@ import { JoliboxAdsForGame } from '@jolibox/ads';
4
4
  export type AdsRewardsHandler = (params: IRewardParams) => Promise<boolean>;
5
5
  export const createAdsRewardHandler = (ads: JoliboxAdsForGame): AdsRewardsHandler => {
6
6
  return async (params: IRewardParams) => {
7
- console.log('trigger @jolibox/ads reward', params);
8
- ads.adBreak(params);
7
+ try {
8
+ console.log('trigger @jolibox/ads reward', params);
9
+ await ads.adBreak(params);
10
+ } catch (e) {
11
+ console.error('-----createAdsRewardHandler error-----', e);
12
+ }
9
13
  return true;
10
14
  };
11
15
  };
@@ -97,15 +97,20 @@ export const createCommonJolicoinRewardHandler = (
97
97
 
98
98
  console.log('-----unlockWithJolicoin request result-----', unlockWithJolicoin);
99
99
  if (unlockWithJolicoin.code == 'SUCCESS') {
100
- params.adBreakDone?.({
101
- breakType: params.type,
102
- breakName: 'name' in params ? params.name ?? '' : '',
103
- breakFormat: 'reward',
104
- breakStatus: 'viewed'
105
- });
106
- if ('adViewed' in params) {
107
- params.adViewed?.();
100
+ try {
101
+ params.adBreakDone?.({
102
+ breakType: params.type,
103
+ breakName: 'name' in params ? params.name ?? '' : '',
104
+ breakFormat: 'reward',
105
+ breakStatus: 'viewed'
106
+ });
107
+ if ('adViewed' in params) {
108
+ params.adViewed?.();
109
+ }
110
+ } catch (e) {
111
+ console.error('-----unlockWithJolicoin adBreakDone error-----', e);
108
112
  }
113
+
109
114
  handleUnlockSuccess?.({
110
115
  quantity: unlockWithJolicoin.data.quantity,
111
116
  balance: unlockWithJolicoin.data.balance
@@ -19,7 +19,15 @@ const onLevelFinished = createAPI('levelFinished', {
19
19
  logger.info(`onLevelFinished`, duration, rating, score, variation);
20
20
  await Promise.all([
21
21
  taskTracker.reporter({
22
- event: 'COMPLETE_GAME_LEVEL'
22
+ event: 'COMPLETE_GAME_LEVEL',
23
+ extraParams: {
24
+ inGameInfo: {
25
+ levelId,
26
+ duration,
27
+ rating,
28
+ score
29
+ }
30
+ }
23
31
  }),
24
32
  taskTracker.tracker('LevelFinished', {
25
33
  levelId,
@@ -44,12 +52,24 @@ const onGamePlayEnded = createAPI('gamePlayEnded', {
44
52
  implement: async (params) => {
45
53
  const { duration, rating, score, variation } = params;
46
54
  logger.info(`onGamePlayEnded`, duration, rating, score, variation);
47
- return taskTracker.tracker('GamePlayEnded', {
48
- duration,
49
- rating,
50
- score,
51
- variation
52
- });
55
+ await Promise.all([
56
+ taskTracker.tracker('GamePlayEnded', {
57
+ duration,
58
+ rating,
59
+ score,
60
+ variation
61
+ }),
62
+ taskTracker.reporter({
63
+ event: 'GAME_ENDED',
64
+ extraParams: {
65
+ inGameInfo: {
66
+ duration,
67
+ rating,
68
+ score
69
+ }
70
+ }
71
+ })
72
+ ]);
53
73
  }
54
74
  });
55
75
 
@@ -61,10 +81,21 @@ const onLevelUpgrade = createAPI('levelUpgrade', {
61
81
  })
62
82
  ),
63
83
  implement: async ({ levelId, name }) => {
64
- return taskTracker.tracker('LevelUpgrade', {
65
- name,
66
- levelId
67
- });
84
+ await Promise.all([
85
+ taskTracker.tracker('LevelUpgrade', {
86
+ name,
87
+ levelId
88
+ }),
89
+ taskTracker.reporter({
90
+ event: 'GAME_LEVEL_UP',
91
+ extraParams: {
92
+ inGameInfo: {
93
+ levelId,
94
+ levelName: name
95
+ }
96
+ }
97
+ })
98
+ ]);
68
99
  }
69
100
  });
70
101
 
@@ -23,16 +23,20 @@ export class H5TaskTracker extends TaskTracker {
23
23
  }
24
24
 
25
25
  async reporter(point: TaskPoint): Promise<void> {
26
- const { event, params } = point;
27
- await this.httpClient.post(`/api/base/app-event`, {
28
- data: {
29
- eventType: event,
30
- gameInfo: {
31
- gameId: this.gameId,
32
- sessionId: this.sessionId,
33
- ...params
34
- }
26
+ const { event, params, extraParams } = point;
27
+ const reportBody = {
28
+ eventType: event,
29
+ gameInfo: {
30
+ gameId: this.gameId,
31
+ sessionId: this.sessionId,
32
+ ...params
35
33
  }
34
+ };
35
+ if (extraParams) {
36
+ Object.assign(reportBody, extraParams);
37
+ }
38
+ await this.httpClient.post(`/api/base/app-event`, {
39
+ data: reportBody
36
40
  });
37
41
  }
38
42
  tracker(event: TrackEvent, info: Record<string, unknown> | null = null) {
@@ -29,7 +29,15 @@ const onLevelFinished = createAPI('levelFinished', {
29
29
 
30
30
  tasks.push(
31
31
  taskTracker.reporter({
32
- event: 'COMPLETE_GAME_LEVEL'
32
+ event: 'COMPLETE_GAME_LEVEL',
33
+ extraParams: {
34
+ inGameInfo: {
35
+ levelId,
36
+ duration,
37
+ rating,
38
+ score
39
+ }
40
+ }
33
41
  })
34
42
  );
35
43
  await Promise.all(tasks);
@@ -47,12 +55,29 @@ const onGamePlayEnded = createAPI('gamePlayEnded', {
47
55
  ),
48
56
  implement: async (params) => {
49
57
  const { duration, rating, score, variation } = params;
50
- return taskTracker.tracker('GamePlayEnded', {
51
- duration,
52
- rating,
53
- score,
54
- variation
55
- });
58
+ const tasks = [];
59
+ tasks.push(
60
+ taskTracker.tracker('GamePlayEnded', {
61
+ duration,
62
+ rating,
63
+ score,
64
+ variation
65
+ })
66
+ );
67
+
68
+ tasks.push(
69
+ taskTracker.reporter({
70
+ event: 'GAME_ENDED',
71
+ extraParams: {
72
+ inGameInfo: {
73
+ duration,
74
+ rating,
75
+ score
76
+ }
77
+ }
78
+ })
79
+ );
80
+ await Promise.all(tasks);
56
81
  }
57
82
  });
58
83
 
@@ -71,6 +96,17 @@ const onLevelUpgrade = createAPI('levelUpgrade', {
71
96
  levelId
72
97
  })
73
98
  );
99
+ tasks.push(
100
+ taskTracker.reporter({
101
+ event: 'GAME_LEVEL_UP',
102
+ extraParams: {
103
+ inGameInfo: {
104
+ levelId,
105
+ levelName: name
106
+ }
107
+ }
108
+ })
109
+ );
74
110
  await Promise.all(tasks);
75
111
  }
76
112
  });
@@ -41,7 +41,7 @@ export class NativeTaskTracker extends TaskTracker {
41
41
  : 'https://api.jolibox.com/api/base/app-event';
42
42
  }
43
43
  async reporter(point: TaskPoint): Promise<void> {
44
- const { event, params } = point;
44
+ const { event, params, extraParams } = point;
45
45
 
46
46
  const reportBody = {
47
47
  eventType: event,
@@ -51,6 +51,9 @@ export class NativeTaskTracker extends TaskTracker {
51
51
  ...params
52
52
  }
53
53
  };
54
+ if (extraParams) {
55
+ Object.assign(reportBody, extraParams);
56
+ }
54
57
  const reportTask =
55
58
  context.platform === 'android'
56
59
  ? fetch(`/api/base/app-event`, {