@jolibox/implement 1.3.5-beta.4 → 1.3.5
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 +5 -5
- package/dist/common/report/task-track/index.d.ts +1 -1
- package/dist/index.js +5 -5
- package/dist/index.native.js +79 -79
- package/implement.build.log +2 -2
- package/package.json +6 -6
- package/src/common/report/task-track/index.ts +2 -1
- package/src/h5/api/runtime.ts +1 -1
- package/src/native/api/rewards.ts +151 -1
- package/src/native/bootstrap/index.ts +1 -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.3.5
|
|
3
|
+
> @jolibox/implement@1.3.5 clean
|
|
4
4
|
> rimraf ./dist
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
> @jolibox/implement@1.3.5
|
|
7
|
+
> @jolibox/implement@1.3.5 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.3.5
|
|
4
|
+
"version": "1.3.5",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@jolibox/common": "1.3.5
|
|
10
|
-
"@jolibox/types": "1.3.5
|
|
11
|
-
"@jolibox/native-bridge": "1.3.5
|
|
12
|
-
"@jolibox/ads": "1.3.5
|
|
9
|
+
"@jolibox/common": "1.3.5",
|
|
10
|
+
"@jolibox/types": "1.3.5",
|
|
11
|
+
"@jolibox/native-bridge": "1.3.5",
|
|
12
|
+
"@jolibox/ads": "1.3.5",
|
|
13
13
|
"localforage": "1.10.0",
|
|
14
|
-
"@jolibox/ui": "1.3.5
|
|
14
|
+
"@jolibox/ui": "1.3.5",
|
|
15
15
|
"web-vitals": "4.2.4"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
@@ -11,7 +11,8 @@ type TaskEvent =
|
|
|
11
11
|
| 'ADS_UNLOCK_GAME' // 广告解锁
|
|
12
12
|
| 'GAME_TASK_EVENT' // 关卡行为
|
|
13
13
|
| 'GAME_ENDED' // 游戏结束
|
|
14
|
-
| 'GAME_LEVEL_UP'
|
|
14
|
+
| 'GAME_LEVEL_UP' // 游戏关卡升级
|
|
15
|
+
| 'COMPLETE_WATCH_ADS'; // 完成观看广告
|
|
15
16
|
export type TaskPoint = {
|
|
16
17
|
event: TaskEvent;
|
|
17
18
|
params?: Record<string, unknown>;
|
package/src/h5/api/runtime.ts
CHANGED
|
@@ -7,7 +7,7 @@ const commands = createCommands();
|
|
|
7
7
|
|
|
8
8
|
commands.registerCommand('RuntimeSDK.loadFinishedEvent', () => {
|
|
9
9
|
const duration = performance.now();
|
|
10
|
-
notifyCustomEvent('CP_LOAD_FINISH', {});
|
|
10
|
+
notifyCustomEvent('CP_LOAD_FINISH', { duration });
|
|
11
11
|
track('loadFinished', {
|
|
12
12
|
duration
|
|
13
13
|
});
|
|
@@ -1,9 +1,76 @@
|
|
|
1
1
|
import { BaseError, wrapUserFunction, createCommands } from '@jolibox/common';
|
|
2
|
-
import { canIUseNative, createAPI, registerCanIUse, t } from './base';
|
|
2
|
+
import { canIUseNative, createAPI, createSyncAPI, registerCanIUse, t } from './base';
|
|
3
3
|
import { StandardResponse, ICoinDetailsData } from '@jolibox/types';
|
|
4
4
|
import { context } from '@/common/context';
|
|
5
5
|
import { createAPIError } from '@/common/report/errors';
|
|
6
6
|
import { invokeNative } from '@jolibox/native-bridge';
|
|
7
|
+
import { IAdsContext } from '@jolibox/ads/dist/type/base';
|
|
8
|
+
import { adEventEmitter } from '@/common/ads';
|
|
9
|
+
import { taskTracker, track } from '../report';
|
|
10
|
+
import { JoliboxAdsForGame } from '@jolibox/ads';
|
|
11
|
+
import { innerFetch as fetch } from '../network';
|
|
12
|
+
|
|
13
|
+
const checkNetworkStatus = () => {
|
|
14
|
+
const { data } = invokeNative('getNetworkStatusSync');
|
|
15
|
+
return !!data?.isConnected;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const httpClient = {
|
|
19
|
+
get: <T>(url: string, options?: any) =>
|
|
20
|
+
fetch<T>(url, {
|
|
21
|
+
method: 'GET',
|
|
22
|
+
responseType: 'json',
|
|
23
|
+
appendHostCookie: true,
|
|
24
|
+
...options
|
|
25
|
+
}).then((res) => res.response.data as T),
|
|
26
|
+
post: <T>(url: string, options?: any) =>
|
|
27
|
+
fetch<T>(url, {
|
|
28
|
+
method: 'POST',
|
|
29
|
+
responseType: 'json',
|
|
30
|
+
appendHostCookie: true,
|
|
31
|
+
...options
|
|
32
|
+
}).then((res) => res.response.data as T)
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const adsContext: IAdsContext<'TASK'> = {
|
|
36
|
+
httpClient,
|
|
37
|
+
checkNetwork: checkNetworkStatus,
|
|
38
|
+
track,
|
|
39
|
+
eventEmitter: adEventEmitter,
|
|
40
|
+
getWindowInfo: () => ({
|
|
41
|
+
width: window.innerWidth * window.devicePixelRatio,
|
|
42
|
+
height: window.innerHeight * window.devicePixelRatio,
|
|
43
|
+
statusBarHeight: 30
|
|
44
|
+
}),
|
|
45
|
+
handleLinkClicked: (link) => {
|
|
46
|
+
window.open(link, '_blank');
|
|
47
|
+
},
|
|
48
|
+
getContextInfo: () => {
|
|
49
|
+
return {
|
|
50
|
+
hostAppId: context.hostInfo?.aid ?? '1',
|
|
51
|
+
deviceId: context.deviceInfo.did ?? '',
|
|
52
|
+
adId: context.deviceInfo.adId ?? '',
|
|
53
|
+
sessionId: context.sessionId ?? '',
|
|
54
|
+
userId: context.hostUserInfo?.uid ?? '',
|
|
55
|
+
objectType: 'TASK',
|
|
56
|
+
objectId: context.mpId,
|
|
57
|
+
testAdsMode: context.testAdsMode,
|
|
58
|
+
channel: context.joliSource ?? '',
|
|
59
|
+
deviceBrand: context.deviceInfo.brand,
|
|
60
|
+
deviceModel: context.deviceInfo.model,
|
|
61
|
+
osType: context.platform === 'android' ? 'ANDROID' : context.platform === 'ios' ? 'IOS' : 'PC',
|
|
62
|
+
runtimeType: 'APP',
|
|
63
|
+
platform: 1000, // WebSDK
|
|
64
|
+
joliSource: context.joliSource ?? '',
|
|
65
|
+
deviceInfo: {
|
|
66
|
+
platform: context.platform,
|
|
67
|
+
nativeSDKVersionCode: context.sdkInfo.nativeSDKVersionCode ?? 0
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// const ads = new JoliboxAdsForGame(adsContext);
|
|
7
74
|
|
|
8
75
|
const commands = createCommands();
|
|
9
76
|
|
|
@@ -83,3 +150,86 @@ commands.registerCommand('RewardsSDK.getCoinDetails', getCoinDetails);
|
|
|
83
150
|
registerCanIUse('rewards.getCoinDetails', {
|
|
84
151
|
version: '1.3.2'
|
|
85
152
|
});
|
|
153
|
+
|
|
154
|
+
const createRewardsAdsManager = createAPI('createRewardsAdsManager', {
|
|
155
|
+
implement: async () => {
|
|
156
|
+
try {
|
|
157
|
+
const ads = new JoliboxAdsForGame(adsContext);
|
|
158
|
+
if (context.mpType !== 'miniApp') {
|
|
159
|
+
throw createAPIError({
|
|
160
|
+
code: -1,
|
|
161
|
+
msg: '[JoliboxSDK]: createRewardsAdsManager not supported in games. Only supported in mini apps.'
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
code: 'SUCCESS',
|
|
166
|
+
message: 'Successfully created RewardsAdsManager',
|
|
167
|
+
data: {
|
|
168
|
+
init: async () => {
|
|
169
|
+
await ads.init();
|
|
170
|
+
ads.adConfig({
|
|
171
|
+
preloadAdBreaks: 'on',
|
|
172
|
+
sound: 'off',
|
|
173
|
+
onReady: () => {
|
|
174
|
+
// do nothing
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
},
|
|
178
|
+
showAd: async (callbacks: {
|
|
179
|
+
onAdLoaded?: () => void;
|
|
180
|
+
onAdError?: (error: Error) => void;
|
|
181
|
+
onAdRewarded?: () => void;
|
|
182
|
+
onAdDismissed?: () => void;
|
|
183
|
+
}) => {
|
|
184
|
+
ads.adBreak({
|
|
185
|
+
type: 'reward',
|
|
186
|
+
beforeReward: (showAdFn) => {
|
|
187
|
+
showAdFn();
|
|
188
|
+
callbacks.onAdLoaded?.();
|
|
189
|
+
},
|
|
190
|
+
adDismissed: () => {
|
|
191
|
+
// do nothing
|
|
192
|
+
callbacks.onAdDismissed?.();
|
|
193
|
+
},
|
|
194
|
+
adViewed: () => {
|
|
195
|
+
// do nothing
|
|
196
|
+
},
|
|
197
|
+
adBreakDone: (placementInfo) => {
|
|
198
|
+
const breakStatus = placementInfo.breakStatus;
|
|
199
|
+
const noAdPreloaded =
|
|
200
|
+
breakStatus === 'frequencyCapped' ||
|
|
201
|
+
breakStatus === 'other' ||
|
|
202
|
+
breakStatus === 'error' ||
|
|
203
|
+
breakStatus === 'noAdPreloaded';
|
|
204
|
+
if (breakStatus === 'viewed') {
|
|
205
|
+
// reward should be given to user
|
|
206
|
+
console.log('-----> complete watch ads');
|
|
207
|
+
taskTracker.reporter({
|
|
208
|
+
event: 'COMPLETE_WATCH_ADS'
|
|
209
|
+
});
|
|
210
|
+
callbacks.onAdRewarded?.();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (noAdPreloaded) {
|
|
214
|
+
console.log('-----> no ad preloaded or error occurred', breakStatus);
|
|
215
|
+
callbacks.onAdError?.(new Error('No ad preloaded or error occurred: ' + breakStatus));
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
} catch (error) {
|
|
223
|
+
return {
|
|
224
|
+
code: 'FAILURE',
|
|
225
|
+
message: '[JoliboxSDK]: Failed to create RewardsAdsManager'
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
commands.registerCommand('Rewards.createRewardsAdsManager', createRewardsAdsManager);
|
|
232
|
+
|
|
233
|
+
registerCanIUse('rewards.createRewardsAdsManager', {
|
|
234
|
+
version: '1.3.4'
|
|
235
|
+
});
|
|
@@ -76,7 +76,7 @@ RuntimeLoader.onReady(() => {
|
|
|
76
76
|
function addShowAdListener() {
|
|
77
77
|
adEventEmitter.on('isAdShowing', (isShowing) => {
|
|
78
78
|
isAdShowing = isShowing;
|
|
79
|
-
if (isBoolean(isAdShowing)) {
|
|
79
|
+
if (isBoolean(isAdShowing) && context.mpType === 'game') {
|
|
80
80
|
invokeNative('updateContainerConfigSync', {
|
|
81
81
|
displayCapsuleButton: !isAdShowing,
|
|
82
82
|
webviewId: context.webviewId
|