@jolibox/implement 1.1.4-beta.10
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/.eslintrc.js +13 -0
- package/.rush/temp/package-deps_build.json +105 -0
- package/.rush/temp/shrinkwrap-deps.json +79 -0
- package/README.md +1 -0
- package/dist/common/api-factory/index.d.ts +21 -0
- package/dist/common/api-factory/validator/__tests__/validate/any.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/array.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/arraybuffer.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/boolean.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/enum.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/function.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/literal.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/nullish.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/number.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/object.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/or.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/record.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/string.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/symbol.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/tuple.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/type-asserts.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/utils.test.d.ts +1 -0
- package/dist/common/api-factory/validator/index.d.ts +29 -0
- package/dist/common/api-factory/validator/validate.d.ts +119 -0
- package/dist/common/can-i-use.d.ts +2 -0
- package/dist/common/context/index.d.ts +16 -0
- package/dist/common/context/types.d.ts +5 -0
- package/dist/common/context/url-parse.d.ts +22 -0
- package/dist/common/http/index.d.ts +13 -0
- package/dist/common/http/uuid.d.ts +2 -0
- package/dist/common/http/xua.d.ts +17 -0
- package/dist/common/report/base-tracker.d.ts +13 -0
- package/dist/common/report/create-trace.d.ts +7 -0
- package/dist/common/report/errors/error-types.d.ts +122 -0
- package/dist/common/report/errors/index.d.ts +13 -0
- package/dist/common/report/errors/report/index.d.ts +51 -0
- package/dist/common/report/errors/report/listeners.d.ts +1 -0
- package/dist/common/report/index.d.ts +3 -0
- package/dist/common/report/task-track/index.d.ts +25 -0
- package/dist/common/report/track.d.ts +3 -0
- package/dist/common/report/types.d.ts +75 -0
- package/dist/h5/ads/ads-action-detection.d.ts +6 -0
- package/dist/h5/ads/anti-cheating.d.ts +61 -0
- package/dist/h5/ads/index.d.ts +275 -0
- package/dist/h5/api/base.d.ts +13 -0
- package/dist/h5/api/get-system-info.d.ts +1 -0
- package/dist/h5/api/index.d.ts +4 -0
- package/dist/h5/api/lifecycle.d.ts +1 -0
- package/dist/h5/api/storage.d.ts +27 -0
- package/dist/h5/api/task.d.ts +1 -0
- package/dist/h5/bootstrap/index.d.ts +1 -0
- package/dist/h5/http/index.d.ts +33 -0
- package/dist/h5/http/utils/__tests__/uuid.test.d.ts +1 -0
- package/dist/h5/http/utils/__tests__/xua.test.d.ts +1 -0
- package/dist/h5/http/utils/index.d.ts +14 -0
- package/dist/h5/http/utils/session.d.ts +1 -0
- package/dist/h5/report/errors/index.d.ts +4 -0
- package/dist/h5/report/event-tracker.d.ts +8 -0
- package/dist/h5/report/index.d.ts +10 -0
- package/dist/h5/report/task-tracker.d.ts +18 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +13 -0
- package/dist/index.native.d.ts +2 -0
- package/dist/index.native.js +3 -0
- package/dist/native/api/ads.d.ts +1 -0
- package/dist/native/api/base.d.ts +13 -0
- package/dist/native/api/get-system-info.d.ts +1 -0
- package/dist/native/api/index.d.ts +8 -0
- package/dist/native/api/keyboard.d.ts +9 -0
- package/dist/native/api/lifecycle.d.ts +1 -0
- package/dist/native/api/login.d.ts +1 -0
- package/dist/native/api/request.d.ts +1 -0
- package/dist/native/api/storage.d.ts +25 -0
- package/dist/native/api/task.d.ts +1 -0
- package/dist/native/bootstrap/bridge.d.ts +4 -0
- package/dist/native/bootstrap/index.d.ts +1 -0
- package/dist/native/js-bridge/const.d.ts +5 -0
- package/dist/native/js-bridge/index.d.ts +2 -0
- package/dist/native/js-bridge/invoke.d.ts +21 -0
- package/dist/native/js-bridge/js-bridge.d.ts +6 -0
- package/dist/native/js-bridge/report.d.ts +63 -0
- package/dist/native/js-bridge/subscribe.d.ts +8 -0
- package/dist/native/js-bridge/types.d.ts +14 -0
- package/dist/native/js-bridge/utils.d.ts +17 -0
- package/dist/native/js-core/index.d.ts +3 -0
- package/dist/native/js-core/jolibox-js-core.d.ts +45 -0
- package/dist/native/js-core/message-port.d.ts +12 -0
- package/dist/native/js-core/utils.d.ts +7 -0
- package/dist/native/network/create-fetch.d.ts +27 -0
- package/dist/native/network/index.d.ts +11 -0
- package/dist/native/network/report.d.ts +15 -0
- package/dist/native/network/types.d.ts +61 -0
- package/dist/native/network/utils.d.ts +9 -0
- package/dist/native/report/errors/index.d.ts +4 -0
- package/dist/native/report/index.d.ts +10 -0
- package/dist/native/report/task-tracker.d.ts +24 -0
- package/dist/utils/index.d.ts +0 -0
- package/esbuild.config.js +66 -0
- package/implement.build.log +9 -0
- package/package.json +30 -0
- package/src/common/api-factory/index.ts +188 -0
- package/src/common/api-factory/validator/__tests__/validate/any.test.ts +68 -0
- package/src/common/api-factory/validator/__tests__/validate/array.test.ts +402 -0
- package/src/common/api-factory/validator/__tests__/validate/arraybuffer.test.ts +48 -0
- package/src/common/api-factory/validator/__tests__/validate/boolean.test.ts +27 -0
- package/src/common/api-factory/validator/__tests__/validate/enum.test.ts +106 -0
- package/src/common/api-factory/validator/__tests__/validate/function.test.ts +54 -0
- package/src/common/api-factory/validator/__tests__/validate/literal.test.ts +130 -0
- package/src/common/api-factory/validator/__tests__/validate/nullish.test.ts +41 -0
- package/src/common/api-factory/validator/__tests__/validate/number.test.ts +147 -0
- package/src/common/api-factory/validator/__tests__/validate/object.test.ts +131 -0
- package/src/common/api-factory/validator/__tests__/validate/or.test.ts +96 -0
- package/src/common/api-factory/validator/__tests__/validate/record.test.ts +274 -0
- package/src/common/api-factory/validator/__tests__/validate/string.test.ts +187 -0
- package/src/common/api-factory/validator/__tests__/validate/symbol.test.ts +23 -0
- package/src/common/api-factory/validator/__tests__/validate/tuple.test.ts +86 -0
- package/src/common/api-factory/validator/__tests__/validate/type-asserts.test.ts +13 -0
- package/src/common/api-factory/validator/__tests__/validate/utils.test.ts +44 -0
- package/src/common/api-factory/validator/index.ts +107 -0
- package/src/common/api-factory/validator/validate.ts +641 -0
- package/src/common/can-i-use.ts +19 -0
- package/src/common/context/index.ts +85 -0
- package/src/common/context/types.ts +5 -0
- package/src/common/context/url-parse.ts +63 -0
- package/src/common/http/index.ts +29 -0
- package/src/common/http/uuid.ts +11 -0
- package/src/common/http/xua.ts +79 -0
- package/src/common/report/base-tracker.ts +134 -0
- package/src/common/report/create-trace.ts +17 -0
- package/src/common/report/errors/error-types.ts +206 -0
- package/src/common/report/errors/index.ts +20 -0
- package/src/common/report/errors/report/index.ts +63 -0
- package/src/common/report/errors/report/listeners.ts +80 -0
- package/src/common/report/index.ts +3 -0
- package/src/common/report/task-track/index.ts +102 -0
- package/src/common/report/track.ts +49 -0
- package/src/common/report/types.ts +90 -0
- package/src/h5/ads/ads-action-detection.ts +31 -0
- package/src/h5/ads/anti-cheating.ts +244 -0
- package/src/h5/ads/index.ts +658 -0
- package/src/h5/api/base.ts +9 -0
- package/src/h5/api/get-system-info.ts +59 -0
- package/src/h5/api/index.ts +4 -0
- package/src/h5/api/lifecycle.ts +95 -0
- package/src/h5/api/storage.ts +173 -0
- package/src/h5/api/task.ts +190 -0
- package/src/h5/bootstrap/index.ts +16 -0
- package/src/h5/http/index.ts +189 -0
- package/src/h5/http/utils/__tests__/uuid.test.ts +16 -0
- package/src/h5/http/utils/__tests__/xua.test.ts +27 -0
- package/src/h5/http/utils/index.ts +19 -0
- package/src/h5/http/utils/session.ts +10 -0
- package/src/h5/report/errors/index.ts +40 -0
- package/src/h5/report/event-tracker.ts +40 -0
- package/src/h5/report/index.ts +56 -0
- package/src/h5/report/task-tracker.ts +42 -0
- package/src/index.native.ts +7 -0
- package/src/index.ts +9 -0
- package/src/native/api/ads.ts +52 -0
- package/src/native/api/base.ts +8 -0
- package/src/native/api/get-system-info.ts +44 -0
- package/src/native/api/index.ts +8 -0
- package/src/native/api/keyboard.ts +75 -0
- package/src/native/api/lifecycle.ts +76 -0
- package/src/native/api/login.ts +73 -0
- package/src/native/api/request.ts +154 -0
- package/src/native/api/storage.ts +287 -0
- package/src/native/api/task.ts +227 -0
- package/src/native/bootstrap/bridge.ts +59 -0
- package/src/native/bootstrap/index.ts +59 -0
- package/src/native/js-bridge/const.ts +11 -0
- package/src/native/js-bridge/index.ts +2 -0
- package/src/native/js-bridge/invoke.ts +210 -0
- package/src/native/js-bridge/js-bridge.ts +23 -0
- package/src/native/js-bridge/report.ts +311 -0
- package/src/native/js-bridge/subscribe.ts +50 -0
- package/src/native/js-bridge/types.ts +26 -0
- package/src/native/js-bridge/utils.ts +116 -0
- package/src/native/js-core/index.ts +4 -0
- package/src/native/js-core/jolibox-js-core.ts +188 -0
- package/src/native/js-core/message-port.ts +52 -0
- package/src/native/js-core/utils.ts +9 -0
- package/src/native/network/create-fetch.ts +237 -0
- package/src/native/network/index.ts +15 -0
- package/src/native/network/report.ts +58 -0
- package/src/native/network/types.ts +77 -0
- package/src/native/network/utils.ts +90 -0
- package/src/native/report/errors/index.ts +27 -0
- package/src/native/report/index.ts +51 -0
- package/src/native/report/task-tracker.ts +72 -0
- package/src/native/types/global.d.ts +26 -0
- package/src/native/types/native-method-map.d.ts +282 -0
- package/src/native/types/native-method.d.ts +30 -0
- package/src/utils/index.ts +0 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { context } from '@/common/context';
|
|
2
|
+
import { createSyncAPI, registerCanIUse } from './base';
|
|
3
|
+
import { createCommands } from '@jolibox/common';
|
|
4
|
+
import { ISystemInfo } from '@jolibox/types';
|
|
5
|
+
|
|
6
|
+
const commands = createCommands();
|
|
7
|
+
|
|
8
|
+
const API_ENV = 'env';
|
|
9
|
+
const API_GET_SYSTEM_SYNC = 'getSystemInfoSync';
|
|
10
|
+
|
|
11
|
+
const getSystemInfo = () => {
|
|
12
|
+
let config = {
|
|
13
|
+
system: context.deviceInfo.system,
|
|
14
|
+
platform: context.deviceInfo.platform,
|
|
15
|
+
brand: context.deviceInfo.brand,
|
|
16
|
+
pixelRatio: context.deviceInfo.pixelRatio,
|
|
17
|
+
language: context.deviceInfo.lang,
|
|
18
|
+
version: context.sdkInfo.jssdkVersion,
|
|
19
|
+
appName: context.hostInfo?.appName,
|
|
20
|
+
SDKVersion: context.sdkInfo.nativeSDKVersion
|
|
21
|
+
} as ISystemInfo;
|
|
22
|
+
|
|
23
|
+
const version = context.hostInfo?.version;
|
|
24
|
+
version && (config = { ...config, version });
|
|
25
|
+
|
|
26
|
+
const appName = context.hostInfo?.appName;
|
|
27
|
+
appName && (config = { ...config, appName });
|
|
28
|
+
|
|
29
|
+
const SDKVersion = context.sdkInfo?.jssdkVersion;
|
|
30
|
+
SDKVersion && (config = { ...config, SDKVersion });
|
|
31
|
+
|
|
32
|
+
return config;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const getSystemInfoSync = createSyncAPI(API_GET_SYSTEM_SYNC, {
|
|
36
|
+
implement: getSystemInfo
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const getEnv = createSyncAPI(API_ENV, {
|
|
40
|
+
implement: () => {
|
|
41
|
+
return {
|
|
42
|
+
...context.hostInfo,
|
|
43
|
+
sdkInfo: context.sdkInfo,
|
|
44
|
+
platform: context.platform,
|
|
45
|
+
deviceInfo: context.deviceInfo
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
commands.registerCommand(`API.env`, getEnv);
|
|
51
|
+
commands.registerCommand(`API.getSystemInfoSync`, getSystemInfoSync);
|
|
52
|
+
|
|
53
|
+
registerCanIUse('env', {
|
|
54
|
+
version: '1.0.0'
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
registerCanIUse('getSystemInfoSync', {
|
|
58
|
+
version: '1.0.0'
|
|
59
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { BaseError, createCommands, hostEmitter, wrapUserFunction } from '@jolibox/common';
|
|
2
|
+
import { createSyncAPI, registerCanIUse, t } from './base';
|
|
3
|
+
import { reportError } from '@/common/report/errors/report';
|
|
4
|
+
import { h5TaskEmitter } from '../report';
|
|
5
|
+
|
|
6
|
+
const ON_SHOW = 'onJoliboxShow';
|
|
7
|
+
const ON_HIDE = 'onJoliboxHide';
|
|
8
|
+
const ON_READY = 'onReady';
|
|
9
|
+
|
|
10
|
+
const commands = createCommands();
|
|
11
|
+
|
|
12
|
+
const safeCallbackWrapper = wrapUserFunction(reportError as (err: Error | BaseError) => void);
|
|
13
|
+
|
|
14
|
+
let isPageVisible = true;
|
|
15
|
+
let isPageFocused = true;
|
|
16
|
+
let lastEventTime = 0;
|
|
17
|
+
|
|
18
|
+
const visibleEmitter = h5TaskEmitter;
|
|
19
|
+
|
|
20
|
+
// 防止交叉触发
|
|
21
|
+
function handleVisibilityChange() {
|
|
22
|
+
const currentTime = Date.now();
|
|
23
|
+
if (currentTime - lastEventTime < 100) return; // 忽略100ms内的重复触发
|
|
24
|
+
lastEventTime = currentTime;
|
|
25
|
+
|
|
26
|
+
const currentState = document.visibilityState === 'visible';
|
|
27
|
+
if (currentState !== isPageVisible) {
|
|
28
|
+
isPageVisible = currentState;
|
|
29
|
+
visibleEmitter.emit('visible', isPageVisible);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function handleFocusBlur(eventType: string) {
|
|
34
|
+
const currentTime = Date.now();
|
|
35
|
+
if (currentTime - lastEventTime < 100) return; // 忽略100ms内的重复触发
|
|
36
|
+
lastEventTime = currentTime;
|
|
37
|
+
|
|
38
|
+
if (eventType === 'focus' && !isPageFocused) {
|
|
39
|
+
isPageFocused = true;
|
|
40
|
+
} else if (eventType === 'blur' && isPageFocused) {
|
|
41
|
+
isPageFocused = false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
visibleEmitter.emit('visible', isPageFocused);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
document.addEventListener('visibilitychange', handleVisibilityChange);
|
|
48
|
+
window.addEventListener('focus', () => handleFocusBlur('focus'));
|
|
49
|
+
window.addEventListener('blur', () => handleFocusBlur('blur'));
|
|
50
|
+
|
|
51
|
+
const onShow = createSyncAPI(ON_SHOW, {
|
|
52
|
+
paramsSchema: t.tuple(t.function()),
|
|
53
|
+
implement(callback) {
|
|
54
|
+
const safeCallback = safeCallbackWrapper(callback);
|
|
55
|
+
visibleEmitter.on('visible', (visible) => {
|
|
56
|
+
visible && safeCallback();
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const onHide = createSyncAPI(ON_HIDE, {
|
|
62
|
+
paramsSchema: t.tuple(t.function()),
|
|
63
|
+
implement(callback) {
|
|
64
|
+
const safeCallback = safeCallbackWrapper(callback);
|
|
65
|
+
visibleEmitter.on('visible', (visible) => {
|
|
66
|
+
!visible && safeCallback();
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const onReadyHandler = createSyncAPI(ON_READY, {
|
|
72
|
+
paramsSchema: t.tuple(t.function()),
|
|
73
|
+
implement(callback) {
|
|
74
|
+
const safeCallback = safeCallbackWrapper(callback);
|
|
75
|
+
hostEmitter.on('LifecycleEvent.onReady', (info) => {
|
|
76
|
+
safeCallback(info);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
commands.registerCommand('LifecycleSDK.onReady', onReadyHandler);
|
|
82
|
+
commands.registerCommand('LifecycleSDK.onJoliboxShow', onShow);
|
|
83
|
+
commands.registerCommand('LifecycleSDK.onJoliboxHide', onHide);
|
|
84
|
+
|
|
85
|
+
registerCanIUse('lifeCycle.onReady', {
|
|
86
|
+
version: '1.0.0' // mock
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
registerCanIUse('lifeCycle.onJoliboxShow', {
|
|
90
|
+
version: '1.0.0' // mock
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
registerCanIUse('lifeCycle.onJoliboxHide', {
|
|
94
|
+
version: '1.0.0' // mock
|
|
95
|
+
});
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { createAPI, t, registerCanIUse } from './base';
|
|
2
|
+
import { createCommands, isBoolean, isNumber, isString } from '@jolibox/common';
|
|
3
|
+
import JoliboxHttpClient from '@/h5/http';
|
|
4
|
+
import { context } from '@/common/context';
|
|
5
|
+
import { API_CODE, StorageResponse } from '@jolibox/types';
|
|
6
|
+
import localForage from 'localforage';
|
|
7
|
+
|
|
8
|
+
const commands = createCommands();
|
|
9
|
+
|
|
10
|
+
export class JoliboxCloudStorage {
|
|
11
|
+
private gameId: string;
|
|
12
|
+
private httpClient: JoliboxHttpClient;
|
|
13
|
+
private gameStore: LocalForage;
|
|
14
|
+
constructor() {
|
|
15
|
+
this.gameId = this.getGameId();
|
|
16
|
+
this.httpClient = new JoliboxHttpClient({
|
|
17
|
+
baseUrl: context.testMode ? 'https://stg-api.jolibox.com' : 'https://api.jolibox.com'
|
|
18
|
+
});
|
|
19
|
+
//没有game的情况使用全局空间
|
|
20
|
+
this.gameStore = localForage.createInstance({
|
|
21
|
+
name: this.gameId.length ? this.gameId : 'default'
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Cloud storage getItem api
|
|
26
|
+
*/
|
|
27
|
+
private getGameId = () => context.mpId;
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @param key getItem key
|
|
31
|
+
*/
|
|
32
|
+
getItem = async (key: string): Promise<StorageResponse<string | null>> => {
|
|
33
|
+
const {
|
|
34
|
+
code,
|
|
35
|
+
data: originData,
|
|
36
|
+
message
|
|
37
|
+
} = await this.httpClient.get<
|
|
38
|
+
StorageResponse<{
|
|
39
|
+
key: string;
|
|
40
|
+
value: string | null;
|
|
41
|
+
}>
|
|
42
|
+
>(`/api/games/user-storage/${this.gameId}`, {
|
|
43
|
+
query: {
|
|
44
|
+
key
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
let data = originData?.value;
|
|
48
|
+
let fallbackmsg = message;
|
|
49
|
+
if (code !== 'SUCCESS') {
|
|
50
|
+
// Only when data cannot be retrieved from the cloud should it be read locally.
|
|
51
|
+
data = await this.gameStore.getItem<string>(key);
|
|
52
|
+
console.info('[SDK] cloud storage getItem failed, read from localstorage', data);
|
|
53
|
+
fallbackmsg += 'fallback to localstorage';
|
|
54
|
+
}
|
|
55
|
+
const res = {
|
|
56
|
+
code,
|
|
57
|
+
message: fallbackmsg,
|
|
58
|
+
data: data && data !== 'undefined' ? data : null
|
|
59
|
+
};
|
|
60
|
+
return res;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Cloud storage setItem api
|
|
65
|
+
* @param progress - The progress of the loading, should be an integer between 0 and 100
|
|
66
|
+
*/
|
|
67
|
+
setItem = async (key: string, value: string | boolean | number): Promise<StorageResponse<void>> => {
|
|
68
|
+
const valueToStore = typeof value == 'string' ? value : String(value);
|
|
69
|
+
//Regardless of whether the cloud operation is successful, corresponding changes should be made locally.
|
|
70
|
+
const { code, message } = await this.httpClient.post(`/api/games/user-storage/${this.gameId}`, {
|
|
71
|
+
data: {
|
|
72
|
+
key,
|
|
73
|
+
value: valueToStore
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
await this.gameStore.setItem(key, valueToStore);
|
|
77
|
+
return {
|
|
78
|
+
code,
|
|
79
|
+
message
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
removeItem = async (key: string): Promise<StorageResponse<void>> => {
|
|
84
|
+
await this.gameStore.removeItem(key);
|
|
85
|
+
const { code, message } = await this.httpClient.post(`/api/games/user-storage/${this.gameId}/remove`, {
|
|
86
|
+
data: {
|
|
87
|
+
key
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
return {
|
|
91
|
+
code,
|
|
92
|
+
message
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
clear = async (): Promise<StorageResponse<void>> => {
|
|
97
|
+
await this.gameStore.clear();
|
|
98
|
+
const { code, message } = await this.httpClient.post(`/api/games/user-storage/${this.gameId}/clear`, {});
|
|
99
|
+
return {
|
|
100
|
+
code,
|
|
101
|
+
message
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const storageImpl = new JoliboxCloudStorage();
|
|
107
|
+
const getStorage = createAPI('getLocalStorage', {
|
|
108
|
+
paramsSchema: t.tuple(t.string()),
|
|
109
|
+
async implement(key) {
|
|
110
|
+
return await storageImpl.getItem(key);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
commands.registerCommand('StorageSDK.getItem', getStorage);
|
|
115
|
+
|
|
116
|
+
registerCanIUse('storage.getItem', {
|
|
117
|
+
version: '1.0.0',
|
|
118
|
+
properties: {
|
|
119
|
+
key: '1.0.0',
|
|
120
|
+
value: '1.0.0'
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const setStorage = createAPI('setStorage', {
|
|
125
|
+
paramsSchema: t.tuple(t.string(), t.or(t.string(), t.boolean(), t.number())),
|
|
126
|
+
async implement(key, value) {
|
|
127
|
+
return await storageImpl.setItem(key, value);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
commands.registerCommand('StorageSDK.setItem', setStorage);
|
|
132
|
+
|
|
133
|
+
registerCanIUse('storage.setItem', {
|
|
134
|
+
version: '1.0.0',
|
|
135
|
+
properties: {
|
|
136
|
+
key: '1.0.0',
|
|
137
|
+
value: '1.0.0'
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 移除指定key
|
|
143
|
+
*/
|
|
144
|
+
export const removeStorage = createAPI('removeStorage', {
|
|
145
|
+
paramsSchema: t.tuple(t.string()),
|
|
146
|
+
async implement(key) {
|
|
147
|
+
return await storageImpl.removeItem(key);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
commands.registerCommand('StorageSDK.removeItem', removeStorage);
|
|
152
|
+
|
|
153
|
+
registerCanIUse('storage.removeItem', {
|
|
154
|
+
version: '1.0.0',
|
|
155
|
+
properties: {
|
|
156
|
+
key: '1.0.0'
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* 清理本地数据缓存
|
|
162
|
+
*/
|
|
163
|
+
const clearStorage = createAPI('clearStorage', {
|
|
164
|
+
async implement() {
|
|
165
|
+
return await storageImpl.clear();
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
commands.registerCommand('StorageSDK.clear', clearStorage);
|
|
170
|
+
|
|
171
|
+
registerCanIUse('storage.clear', {
|
|
172
|
+
version: '1.0.0'
|
|
173
|
+
});
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { createCommands, logger } from '@jolibox/common';
|
|
2
|
+
|
|
3
|
+
import { createAPI, registerCanIUse, t } from './base';
|
|
4
|
+
import { taskTracker } from '../report';
|
|
5
|
+
|
|
6
|
+
const commands = createCommands();
|
|
7
|
+
|
|
8
|
+
const onLevelFinished = createAPI('levelFinished', {
|
|
9
|
+
paramsSchema: t.tuple(
|
|
10
|
+
t.string(),
|
|
11
|
+
t.object({
|
|
12
|
+
result: t.boolean(),
|
|
13
|
+
duration: t.number()
|
|
14
|
+
})
|
|
15
|
+
),
|
|
16
|
+
implement: async (levelId, parmas) => {
|
|
17
|
+
const { result, duration } = parmas;
|
|
18
|
+
logger.info(`onLevelFinished`, result, duration);
|
|
19
|
+
await Promise.all([
|
|
20
|
+
taskTracker.reporter({
|
|
21
|
+
event: 'COMPLETE_GAME_LEVEL'
|
|
22
|
+
}),
|
|
23
|
+
taskTracker.tracker('LevelFinished', {
|
|
24
|
+
levelId,
|
|
25
|
+
result,
|
|
26
|
+
duration
|
|
27
|
+
})
|
|
28
|
+
]);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const onTaskFinished = createAPI('taskFinished', {
|
|
33
|
+
paramsSchema: t.tuple(
|
|
34
|
+
t.string(),
|
|
35
|
+
t.object({
|
|
36
|
+
duration: t.number()
|
|
37
|
+
})
|
|
38
|
+
),
|
|
39
|
+
implement: async (taskId, params) => {
|
|
40
|
+
const { duration } = params;
|
|
41
|
+
await taskTracker.tracker('TaskFinished', {
|
|
42
|
+
duration,
|
|
43
|
+
taskId
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const onLevelUpgrade = createAPI('levelUpgrade', {
|
|
49
|
+
paramsSchema: t.tuple(t.string(), t.string()),
|
|
50
|
+
implement: async (levelId, name) => {
|
|
51
|
+
return await taskTracker.tracker('LevelUpgrade', {
|
|
52
|
+
name,
|
|
53
|
+
levelId
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const onHistoryUserLevel = createAPI('onHistoryUserLevel', {
|
|
59
|
+
paramsSchema: t.tuple(t.number()),
|
|
60
|
+
implement: async (level) => {
|
|
61
|
+
return await taskTracker.tracker('HistoryUserLevel', {
|
|
62
|
+
level
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const onHistoryUserScore = createAPI('onHistoryUserScore', {
|
|
68
|
+
paramsSchema: t.tuple(t.number()),
|
|
69
|
+
implement: async (score) => {
|
|
70
|
+
return await taskTracker.tracker('HistoryUserScore', {
|
|
71
|
+
score
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const onTaskEvent = createAPI('taskEvent', {
|
|
77
|
+
paramsSchema: t.tuple(
|
|
78
|
+
t.string(),
|
|
79
|
+
t.object({
|
|
80
|
+
tools: t
|
|
81
|
+
.array(
|
|
82
|
+
t.object({
|
|
83
|
+
id: t.string(),
|
|
84
|
+
name: t.string(),
|
|
85
|
+
count: t.number(),
|
|
86
|
+
description: t.string().optional(),
|
|
87
|
+
price: t
|
|
88
|
+
.object({
|
|
89
|
+
amount: t.number(),
|
|
90
|
+
unit: t.string()
|
|
91
|
+
})
|
|
92
|
+
.optional()
|
|
93
|
+
})
|
|
94
|
+
)
|
|
95
|
+
.optional(),
|
|
96
|
+
awards: t
|
|
97
|
+
.array(
|
|
98
|
+
t.object({
|
|
99
|
+
id: t.string(),
|
|
100
|
+
name: t.string()
|
|
101
|
+
})
|
|
102
|
+
)
|
|
103
|
+
.optional()
|
|
104
|
+
})
|
|
105
|
+
),
|
|
106
|
+
implement: async (taskId, params) => {
|
|
107
|
+
if (params.tools?.length) {
|
|
108
|
+
await Promise.all([
|
|
109
|
+
taskTracker.reporter({
|
|
110
|
+
event: 'USE_GAME_ITEM'
|
|
111
|
+
}),
|
|
112
|
+
taskTracker.tracker('UseGameItem', {
|
|
113
|
+
taskId,
|
|
114
|
+
...params
|
|
115
|
+
})
|
|
116
|
+
]);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
commands.registerCommand('TaskTrackerSDK.levelFinished', onLevelFinished);
|
|
122
|
+
commands.registerCommand('TaskTrackerSDK.taskFinished', onTaskFinished);
|
|
123
|
+
commands.registerCommand('TaskTrackerSDK.levelUpgrade', onLevelUpgrade);
|
|
124
|
+
commands.registerCommand('TaskTrackerSDK.historyUserLevel', onHistoryUserLevel);
|
|
125
|
+
commands.registerCommand('TaskTrackerSDK.historyUserScore', onHistoryUserScore);
|
|
126
|
+
commands.registerCommand('TaskTrackerSDK.taskEvent', onTaskEvent);
|
|
127
|
+
|
|
128
|
+
registerCanIUse('TaskTrackerSDK.onLevelFinished', {
|
|
129
|
+
version: '1.0.0',
|
|
130
|
+
properties: {
|
|
131
|
+
levelId: '1.0.0',
|
|
132
|
+
params: {
|
|
133
|
+
result: '1.0.0',
|
|
134
|
+
duration: '1.0.0'
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
registerCanIUse('TaskTrackerSDK.onTaskFinished', {
|
|
140
|
+
version: '1.0.0',
|
|
141
|
+
properties: {
|
|
142
|
+
taskId: '1.0.0',
|
|
143
|
+
duration: '1.0.0'
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
registerCanIUse('TaskTrackerSDK.onLevelUpgrade', {
|
|
148
|
+
version: '1.0.0',
|
|
149
|
+
properties: {
|
|
150
|
+
levelId: '1.0.0',
|
|
151
|
+
name: '1.0.0'
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
registerCanIUse('TaskTrackerSDK.onHistoryUserLevel', {
|
|
156
|
+
version: '1.0.0',
|
|
157
|
+
properties: {
|
|
158
|
+
level: '1.0.0'
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
registerCanIUse('TaskTrackerSDK.onHistoryUserScore', {
|
|
163
|
+
version: '1.0.0',
|
|
164
|
+
properties: {
|
|
165
|
+
score: '1.0.0'
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
registerCanIUse('TaskTrackerSDK.onTaskEvent', {
|
|
170
|
+
version: '1.0.0',
|
|
171
|
+
properties: {
|
|
172
|
+
taskId: '1.0.0',
|
|
173
|
+
params: {
|
|
174
|
+
tools: {
|
|
175
|
+
id: '1.0.0',
|
|
176
|
+
name: '1.0.0',
|
|
177
|
+
count: '1.0.0',
|
|
178
|
+
description: '1.0.0',
|
|
179
|
+
price: {
|
|
180
|
+
amount: '1.0.0',
|
|
181
|
+
unit: '1.0.0'
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
awards: {
|
|
185
|
+
id: '1.0.0',
|
|
186
|
+
name: '1.0.0'
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { hostEmitter } from '@jolibox/common';
|
|
2
|
+
import { taskTracker } from '../report';
|
|
3
|
+
|
|
4
|
+
function addDomContentLoaded() {
|
|
5
|
+
hostEmitter.on('onDocumentReady', (startTime: number) => {
|
|
6
|
+
hostEmitter.emit('LifecycleEvent.onReady', {
|
|
7
|
+
isLogin: false
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
taskTracker.start(Date.now() - startTime);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function config(): void {
|
|
15
|
+
addDomContentLoaded();
|
|
16
|
+
}
|