@jolibox/implement 1.1.50 → 1.1.52-beta.1
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/.rush/temp/package-deps_build.json +14 -12
- package/CHANGELOG.json +11 -0
- package/CHANGELOG.md +9 -0
- package/dist/common/report/task-track/index.d.ts +2 -1
- package/dist/index.js +9 -9
- package/dist/index.native.js +32 -32
- package/implement.build.log +2 -2
- package/implementation.build.log +9 -0
- package/package.json +6 -6
- package/src/common/report/task-track/index.ts +4 -1
- package/src/common/rewards/fetch-reward.ts +8 -7
- package/src/common/rewards/registers/use-ads.ts +6 -2
- package/src/common/rewards/registers/utils/coins/index.ts +13 -8
- package/src/h5/api/ads.ts +5 -13
- package/src/h5/api/task.ts +42 -11
- package/src/h5/report/task-tracker.ts +13 -9
- package/src/native/api/base.ts +4 -1
- package/src/native/api/call-host-method.ts +37 -4
- package/src/native/api/task.ts +43 -7
- package/src/native/report/task-tracker.ts +4 -1
package/implement.build.log
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Invoking: npm run clean && npm run build:esm && tsc
|
|
2
2
|
|
|
3
|
-
> @jolibox/implement@1.1.
|
|
3
|
+
> @jolibox/implement@1.1.52-beta.1 clean
|
|
4
4
|
> rimraf ./dist
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
> @jolibox/implement@1.1.
|
|
7
|
+
> @jolibox/implement@1.1.52-beta.1 build:esm
|
|
8
8
|
> BUILD_VERSION=$(node -p "require('./package.json').version") node esbuild.config.js --format=esm
|
|
9
9
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Invoking: npm run clean && npm run build:esm && tsc
|
|
2
|
+
|
|
3
|
+
> @jolibox/implementation@1.1.4-beta.3 clean
|
|
4
|
+
> rimraf ./dist
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
> @jolibox/implementation@1.1.4-beta.3 build:esm
|
|
8
|
+
> BUILD_VERSION=$(node -p "require('./package.json').version") node esbuild.config.js --format=esm
|
|
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.
|
|
4
|
+
"version": "1.1.52-beta.1",
|
|
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.
|
|
10
|
-
"@jolibox/types": "1.1.
|
|
11
|
-
"@jolibox/native-bridge": "1.1.
|
|
12
|
-
"@jolibox/ads": "1.1.
|
|
9
|
+
"@jolibox/common": "1.1.52-beta.1",
|
|
10
|
+
"@jolibox/types": "1.1.52-beta.1",
|
|
11
|
+
"@jolibox/native-bridge": "1.1.52-beta.1",
|
|
12
|
+
"@jolibox/ads": "1.1.52-beta.1",
|
|
13
13
|
"localforage": "1.10.0",
|
|
14
14
|
"@jolibox/ui": "1.0.0",
|
|
15
15
|
"web-vitals": "4.2.4"
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@types/jest": "28.1.1",
|
|
20
20
|
"rimraf": "6.0.1",
|
|
21
21
|
"esbuild": "0.24.2",
|
|
22
|
-
"@jolibox/eslint-config": "1.0.
|
|
22
|
+
"@jolibox/eslint-config": "1.0.1-beta.6"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
25
|
"clean": "rimraf ./dist",
|
|
@@ -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;
|
|
@@ -2,14 +2,14 @@ import { IHttpClient } from '../http';
|
|
|
2
2
|
import { RewardsHelper, RewardType } from './reward-helper';
|
|
3
3
|
import { IJolicoinRewardOption } from './type';
|
|
4
4
|
import {
|
|
5
|
-
IUseModalFrequencyConfig,
|
|
6
5
|
UnlockOptionsEventName,
|
|
7
6
|
UseModalFrequencyEventName,
|
|
8
7
|
rewardsEmitter,
|
|
9
8
|
DefaltJoliCoinUseAndCharge,
|
|
10
|
-
DefaltLoginGuide
|
|
9
|
+
DefaltLoginGuide,
|
|
10
|
+
IUseModalFrequencyConfig
|
|
11
11
|
} from './reward-emitter';
|
|
12
|
-
import { StandardResponse } from '@jolibox/types';
|
|
12
|
+
import { StandardResponse, GlobalConfig } from '@jolibox/types';
|
|
13
13
|
import { hostEmitter } from '@jolibox/common';
|
|
14
14
|
|
|
15
15
|
const priority = () => {
|
|
@@ -55,7 +55,7 @@ export const createRewardFetcher = (rewardsHelper: RewardsHelper) => {
|
|
|
55
55
|
|
|
56
56
|
export const createRewardFrequencyConfigFetcher = (rewardsHelper: RewardsHelper) => {
|
|
57
57
|
rewardsHelper.registerRewardFrequencyConfigFetcher(async (httpClient: IHttpClient) => {
|
|
58
|
-
const res = await httpClient.get<StandardResponse<IUseModalFrequencyConfig>>(
|
|
58
|
+
const res = await httpClient.get<StandardResponse<GlobalConfig & IUseModalFrequencyConfig>>(
|
|
59
59
|
'/api/fe-configs/web-common/global-config',
|
|
60
60
|
{}
|
|
61
61
|
);
|
|
@@ -65,9 +65,10 @@ export const createRewardFrequencyConfigFetcher = (rewardsHelper: RewardsHelper)
|
|
|
65
65
|
loginGuide: res.data?.loginGuide || DefaltLoginGuide
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
res.data &&
|
|
69
|
+
hostEmitter.emit('onGlobalConfigChanged', {
|
|
70
|
+
globalConfig: res.data
|
|
71
|
+
});
|
|
71
72
|
|
|
72
73
|
return {
|
|
73
74
|
joliCoinUseAndCharge: res.data?.joliCoinUseAndCharge || DefaltJoliCoinUseAndCharge,
|
|
@@ -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
|
-
|
|
8
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
params
|
|
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
|
package/src/h5/api/ads.ts
CHANGED
|
@@ -127,11 +127,6 @@ const adsContext: IAdsContext<'GAME'> = {
|
|
|
127
127
|
}
|
|
128
128
|
};
|
|
129
129
|
|
|
130
|
-
const handleUnlockSuccess = (params: { quantity: number; balance: number }) => {
|
|
131
|
-
notifyCustomEvent('JOLIBOX_CUSTOM_REWARDS_EVENT', {
|
|
132
|
-
JOLI_COIN: params
|
|
133
|
-
});
|
|
134
|
-
};
|
|
135
130
|
|
|
136
131
|
const adsManager = new H5AdsManager(adsContext);
|
|
137
132
|
const adsHandler = adsManager.getAdsHandler(context.sdkEnvironment);
|
|
@@ -140,14 +135,11 @@ rewardsHelper.registerRewardHandler('ADS', createAdsRewardHandler(adsHandler.get
|
|
|
140
135
|
rewardsHelper.registerRewardHandler(
|
|
141
136
|
'JOLI_COIN',
|
|
142
137
|
createJolicoinRewardHandler(httpClient, {
|
|
143
|
-
onUnlockSuccess:
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
'JOLI_COIN_ONLY',
|
|
149
|
-
createJolicoinOnlyRewardHandler(httpClient, {
|
|
150
|
-
onUnlockSuccess: handleUnlockSuccess.bind(this)
|
|
138
|
+
onUnlockSuccess: (params: { quantity: number; balance: number }) => {
|
|
139
|
+
notifyCustomEvent('JOLIBOX_CUSTOM_REWARDS_EVENT', {
|
|
140
|
+
JOLI_COIN: params
|
|
141
|
+
});
|
|
142
|
+
}
|
|
151
143
|
}) as unknown as (params?: unknown) => Promise<boolean>
|
|
152
144
|
);
|
|
153
145
|
|
package/src/h5/api/task.ts
CHANGED
|
@@ -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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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) {
|
package/src/native/api/base.ts
CHANGED
|
@@ -9,5 +9,8 @@ import { registerCanIUseContext } from '@jolibox/native-bridge';
|
|
|
9
9
|
import { context } from '@/common/context';
|
|
10
10
|
export { t };
|
|
11
11
|
|
|
12
|
-
export const { canIUseNative } = registerCanIUseContext(
|
|
12
|
+
export const { canIUseNative } = registerCanIUseContext(
|
|
13
|
+
() => context.sdkInfo.nativeSDKVersionCode,
|
|
14
|
+
() => context.platform
|
|
15
|
+
);
|
|
13
16
|
export { convertVersionCodeToVString } from './utils';
|
|
@@ -1,14 +1,47 @@
|
|
|
1
|
-
import { createAPI, registerCanIUse, t } from './base';
|
|
2
|
-
import {
|
|
1
|
+
import { canIUseNative, createAPI, registerCanIUse, t } from './base';
|
|
2
|
+
import { invokeNative } from '@jolibox/native-bridge';
|
|
3
3
|
import { hostEmitter, UserCustomError } from '@jolibox/common';
|
|
4
4
|
import { createCommands } from '@jolibox/common';
|
|
5
|
+
import { context } from '@/common/context';
|
|
5
6
|
|
|
6
7
|
const commands = createCommands();
|
|
7
8
|
let supportedMethods: string[] = [];
|
|
8
9
|
let isInitialized = false;
|
|
9
10
|
|
|
11
|
+
const formatSupportedMethods = (
|
|
12
|
+
methods: (
|
|
13
|
+
| string
|
|
14
|
+
| {
|
|
15
|
+
method: string;
|
|
16
|
+
platforms?: string[];
|
|
17
|
+
nativeVersionCode?: number;
|
|
18
|
+
}
|
|
19
|
+
)[]
|
|
20
|
+
) => {
|
|
21
|
+
const platform = context.platform;
|
|
22
|
+
const nativeVersionCode = context.sdkInfo.nativeSDKVersionCode ?? 0;
|
|
23
|
+
return methods.reduce((acc, method) => {
|
|
24
|
+
if (typeof method === 'string') {
|
|
25
|
+
acc.push(method);
|
|
26
|
+
} else {
|
|
27
|
+
const { method: platformMethod, platforms, nativeVersionCode: methodNativeVersionCode } = method;
|
|
28
|
+
let canUse = true;
|
|
29
|
+
if (platforms && !platforms.includes(platform)) {
|
|
30
|
+
canUse = false;
|
|
31
|
+
}
|
|
32
|
+
if (methodNativeVersionCode && methodNativeVersionCode > nativeVersionCode) {
|
|
33
|
+
canUse = false;
|
|
34
|
+
}
|
|
35
|
+
if (canUse) {
|
|
36
|
+
acc.push(platformMethod);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return acc;
|
|
40
|
+
}, [] as string[]);
|
|
41
|
+
};
|
|
42
|
+
|
|
10
43
|
hostEmitter.on('onGlobalConfigChanged', (params) => {
|
|
11
|
-
supportedMethods = params.globalConfig
|
|
44
|
+
supportedMethods = formatSupportedMethods(params.globalConfig?.supportedHostMethods ?? []);
|
|
12
45
|
isInitialized = true;
|
|
13
46
|
});
|
|
14
47
|
|
|
@@ -18,7 +51,7 @@ const getSupportedMethods = (): Promise<string[]> => {
|
|
|
18
51
|
resolve(supportedMethods);
|
|
19
52
|
} else {
|
|
20
53
|
const handler = (params: any) => {
|
|
21
|
-
supportedMethods = params.globalConfig.supportedHostMethods ?? [];
|
|
54
|
+
supportedMethods = formatSupportedMethods(params.globalConfig.supportedHostMethods ?? []);
|
|
22
55
|
isInitialized = true;
|
|
23
56
|
hostEmitter.off('onGlobalConfigChanged', handler);
|
|
24
57
|
resolve(supportedMethods);
|
package/src/native/api/task.ts
CHANGED
|
@@ -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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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`, {
|