@jolibox/implement 1.4.2 → 1.4.3

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.4.2 clean
3
+ > @jolibox/implement@1.4.3 clean
4
4
  > rimraf ./dist
5
5
 
6
6
 
7
- > @jolibox/implement@1.4.2 build:esm
7
+ > @jolibox/implement@1.4.3 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,17 +1,17 @@
1
1
  {
2
2
  "name": "@jolibox/implement",
3
3
  "description": "This project is Jolibox JS-SDk implement for Native && H5",
4
- "version": "1.4.2",
4
+ "version": "1.4.3",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
7
7
  "license": "MIT",
8
8
  "dependencies": {
9
- "@jolibox/common": "1.4.2",
10
- "@jolibox/types": "1.4.2",
11
- "@jolibox/native-bridge": "1.4.2",
12
- "@jolibox/ads": "1.4.2",
9
+ "@jolibox/common": "1.4.3",
10
+ "@jolibox/types": "1.4.3",
11
+ "@jolibox/native-bridge": "1.4.3",
12
+ "@jolibox/ads": "1.4.3",
13
13
  "localforage": "1.10.0",
14
- "@jolibox/ui": "1.4.2",
14
+ "@jolibox/ui": "1.4.3",
15
15
  "web-vitals": "4.2.4"
16
16
  },
17
17
  "devDependencies": {
@@ -1,7 +1,7 @@
1
1
  import { createCommands } from '@jolibox/common';
2
- import { createAPI, registerCanIUse, t } from './base';
2
+ import { createAPI, registerCanIUse, t, canIUseNative } from './base';
3
3
  import { taskTracker } from '../report';
4
- import { emitNative } from '@jolibox/native-bridge';
4
+ import { emitNative, invokeNative } from '@jolibox/native-bridge';
5
5
  import { context } from '@/common/context';
6
6
 
7
7
  const commands = createCommands();
@@ -35,6 +35,15 @@ function throttledEmitScore(data: any) {
35
35
  }
36
36
  }
37
37
 
38
+ function reportTaskGameInfo(
39
+ event: 'COMPLETE_GAME_LEVEL' | 'GAME_ENDED' | 'GAME_LEVEL_UP',
40
+ inGameInfo: Record<string, any>
41
+ ) {
42
+ return canIUseNative('notifyTaskGameInfoAsync')
43
+ ? invokeNative('notifyTaskGameInfoAsync', { event, inGameInfo })
44
+ : taskTracker.reporter({ event, extraParams: { inGameInfo } });
45
+ }
46
+
38
47
  const onLevelFinished = createAPI('levelFinished', {
39
48
  paramsSchema: t.tuple(
40
49
  t.object({
@@ -59,16 +68,11 @@ const onLevelFinished = createAPI('levelFinished', {
59
68
  );
60
69
 
61
70
  tasks.push(
62
- taskTracker.reporter({
63
- event: 'COMPLETE_GAME_LEVEL',
64
- extraParams: {
65
- inGameInfo: {
66
- levelId,
67
- duration,
68
- rating,
69
- score
70
- }
71
- }
71
+ reportTaskGameInfo('COMPLETE_GAME_LEVEL', {
72
+ levelId,
73
+ duration,
74
+ rating,
75
+ score
72
76
  })
73
77
  );
74
78
  throttledEmitScore({ levelId, duration, rating, score });
@@ -98,15 +102,10 @@ const onGamePlayEnded = createAPI('gamePlayEnded', {
98
102
  );
99
103
 
100
104
  tasks.push(
101
- taskTracker.reporter({
102
- event: 'GAME_ENDED',
103
- extraParams: {
104
- inGameInfo: {
105
- duration,
106
- rating,
107
- score
108
- }
109
- }
105
+ reportTaskGameInfo('GAME_ENDED', {
106
+ duration,
107
+ rating,
108
+ score
110
109
  })
111
110
  );
112
111
  throttledEmitScore({ duration, rating, score });
@@ -130,14 +129,9 @@ const onLevelUpgrade = createAPI('levelUpgrade', {
130
129
  })
131
130
  );
132
131
  tasks.push(
133
- taskTracker.reporter({
134
- event: 'GAME_LEVEL_UP',
135
- extraParams: {
136
- inGameInfo: {
137
- levelId,
138
- levelName: name
139
- }
140
- }
132
+ reportTaskGameInfo('GAME_LEVEL_UP', {
133
+ levelId,
134
+ levelName: name
141
135
  })
142
136
  );
143
137
  emitNative('cpUpdateScoreEvent', { levelId }, context.webviewId);