@jolibox/sdk 1.1.27 → 1.1.28
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 +15 -15
- package/.rush/temp/shrinkwrap-deps.json +7 -2
- package/dist/api/can-i-use.d.ts +27 -0
- package/dist/api/get-system-info.d.ts +26 -2
- package/dist/api/login.d.ts +31 -4
- package/dist/api/on-custom-event.d.ts +27 -2
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +126 -7
- package/dist/index.esm.js +1 -1
- package/dist/index.iife.js +1 -1
- package/dist/index.js +224 -9
- package/dist/sdks/ads.d.ts +11 -2
- package/dist/sdks/keyboard.d.ts +7 -3
- package/dist/sdks/lifecycle.d.ts +37 -2
- package/dist/sdks/router.d.ts +47 -6
- package/dist/sdks/runtime.d.ts +2 -2
- package/dist/sdks/sdk.d.ts +8 -0
- package/dist/sdks/storage.d.ts +34 -3
- package/dist/sdks/task.d.ts +6 -0
- package/package.json +14 -3
- package/sdk.build.log +4 -4
- package/src/api/can-i-use.ts +27 -0
- package/src/api/get-system-info.ts +28 -2
- package/src/api/login.ts +37 -5
- package/src/api/on-custom-event.ts +40 -9
- package/src/index.ts +137 -2
- package/src/sdks/ads.ts +14 -1
- package/src/sdks/keyboard.ts +7 -3
- package/src/sdks/lifecycle.ts +41 -4
- package/src/sdks/router.ts +59 -10
- package/src/sdks/runtime.ts +2 -1
- package/src/sdks/sdk.ts +9 -0
- package/src/sdks/storage.ts +38 -7
- package/src/sdks/task.ts +6 -0
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jolibox/sdk",
|
|
3
3
|
"description": "This project is common Jolibox JS-SDk interfere",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.28",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
7
7
|
"typings": "dist/index.d.ts",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@jolibox/common": "1.1.
|
|
11
|
-
"@jolibox/types": "1.1.
|
|
10
|
+
"@jolibox/common": "1.1.28",
|
|
11
|
+
"@jolibox/types": "1.1.28"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"typescript": "5.7.3",
|
|
@@ -20,6 +20,17 @@
|
|
|
20
20
|
"@babel/preset-env": "7.23.3",
|
|
21
21
|
"@babel/preset-typescript": "7.23.3"
|
|
22
22
|
},
|
|
23
|
+
"typedocOptions": {
|
|
24
|
+
"entryPoints": [
|
|
25
|
+
"src/index.ts",
|
|
26
|
+
"src/sdks/ads.ts",
|
|
27
|
+
"src/sdks/lifecycle.ts",
|
|
28
|
+
"src/sdks/runtime.ts",
|
|
29
|
+
"src/sdks/task.ts",
|
|
30
|
+
"src/api/*.ts"
|
|
31
|
+
],
|
|
32
|
+
"name": "Jolibox SDK Document"
|
|
33
|
+
},
|
|
23
34
|
"scripts": {
|
|
24
35
|
"clean": "rimraf ./dist",
|
|
25
36
|
"build": "npm run clean && npm run build:cjs && npm run build:esm && npm run build:iife && tsc",
|
package/sdk.build.log
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
Invoking: npm run clean && npm run build:cjs && npm run build:esm && npm run build:iife && tsc
|
|
2
2
|
|
|
3
|
-
> @jolibox/sdk@1.1.
|
|
3
|
+
> @jolibox/sdk@1.1.28 clean
|
|
4
4
|
> rimraf ./dist
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
> @jolibox/sdk@1.1.
|
|
7
|
+
> @jolibox/sdk@1.1.28 build:cjs
|
|
8
8
|
> BUILD_VERSION=$(node -p "require('./package.json').version") node esbuild.config.js --format=cjs
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
> @jolibox/sdk@1.1.
|
|
11
|
+
> @jolibox/sdk@1.1.28 build:esm
|
|
12
12
|
> BUILD_VERSION=$(node -p "require('./package.json').version") node esbuild.config.js --format=esm
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
> @jolibox/sdk@1.1.
|
|
15
|
+
> @jolibox/sdk@1.1.28 build:iife
|
|
16
16
|
> BUILD_VERSION=$(node -p "require('./package.json').version") node esbuild.config.js --format=iife
|
|
17
17
|
|
package/src/api/can-i-use.ts
CHANGED
|
@@ -3,6 +3,33 @@ import { getCanIUseConfig, get } from '../utils/can-i-use';
|
|
|
3
3
|
|
|
4
4
|
const __VERSION__ = '__JOLIBOX_LOCAL_SDK_VERSION__'; // mock
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
* Checks if a specific API, component, or capability is available in the current environment.
|
|
9
|
+
* @param schema - The schema string to check (e.g., "component.button", "api.request").
|
|
10
|
+
* @returns True if available, false otherwise. Returns false if the underlying command execution fails.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // Check if a basic API is available
|
|
15
|
+
* if (canIUse('api.request')) {
|
|
16
|
+
* console.log('Request API is available.');
|
|
17
|
+
* } else {
|
|
18
|
+
* console.log('Request API is not available.');
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* // Check for a component
|
|
22
|
+
* if (canIUse('component.button')) {
|
|
23
|
+
* console.log('Button component is supported.');
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* // Check for a specific method or property on an API
|
|
27
|
+
* // The schema format "ads:showInterstitialAd" is a common pattern for such checks.
|
|
28
|
+
* if (canIUse('ads:showInterstitialAd')) {
|
|
29
|
+
* console.log('Showing interstitial ads is supported.');
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
6
33
|
export function canIUse(schema: string): boolean {
|
|
7
34
|
const [name, ...rest] = schema.split(':');
|
|
8
35
|
|
|
@@ -1,11 +1,37 @@
|
|
|
1
1
|
import { createCommands } from '@jolibox/common';
|
|
2
|
+
import type { ISystemInfo, Env, StandardResponse } from '@jolibox/types';
|
|
3
|
+
// It's good practice to import specific types if known, e.g.:
|
|
4
|
+
// import type { ISystemInfo, IEnvInfo } from '@jolibox/types';
|
|
2
5
|
|
|
3
6
|
const commands = createCommands();
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
* Synchronously retrieves system information.
|
|
11
|
+
* The specific structure of the returned system information object depends on the Jolibox environment.
|
|
12
|
+
* @returns {StandardResponse<ISystemInfo>} An object containing system information, wrapped in a StandardResponse.
|
|
13
|
+
* @see {@link ISystemInfo}
|
|
14
|
+
* @type {ISystemInfo}
|
|
15
|
+
* check IsystemInfo for more details
|
|
16
|
+
*/
|
|
17
|
+
export function getSystemInfoSync(): StandardResponse<ISystemInfo> {
|
|
6
18
|
return commands.excuteCommandSync('API.getSystemInfoSync');
|
|
7
19
|
}
|
|
8
20
|
|
|
9
|
-
|
|
21
|
+
/**
|
|
22
|
+
* @public
|
|
23
|
+
* Synchronously retrieves environment-specific information.
|
|
24
|
+
* This can include details about the host environment, application versions, etc., excluding 'hostUserInfo' and 'schema' from the full Env type.
|
|
25
|
+
* @returns {StandardResponse<Omit<Omit<Env, 'hostUserInfo'>, 'schema'>>} An object containing filtered environment information, wrapped in a StandardResponse.
|
|
26
|
+
* @see {@link Env}
|
|
27
|
+
* @type {Omit<Omit<Env, 'hostUserInfo'>, 'schema'>}
|
|
28
|
+
* check Env for more details
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const envInfo = getEnvSync();
|
|
32
|
+
* console.log(envInfo);
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export function env(): StandardResponse<Omit<Omit<Env, 'hostUserInfo'>, 'schema'>> {
|
|
10
36
|
return commands.excuteCommandSync('API.env');
|
|
11
37
|
}
|
package/src/api/login.ts
CHANGED
|
@@ -1,24 +1,56 @@
|
|
|
1
1
|
import { createCommands } from '@jolibox/common';
|
|
2
2
|
import { canIUse } from './can-i-use';
|
|
3
|
-
import { ResponseType } from '@jolibox/types';
|
|
3
|
+
import { ResponseType, StandardResponse } from '@jolibox/types';
|
|
4
4
|
|
|
5
5
|
const commands = createCommands();
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Data structure for successful login.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export interface ILoginSuccessData {
|
|
12
|
+
isLogin: boolean;
|
|
13
|
+
token?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @public
|
|
18
|
+
* Initiates the Jolibox login process.
|
|
19
|
+
* @returns A promise that resolves with the standard response containing login status and token if successful, or an error-like object if platform does not support login.
|
|
20
|
+
*/
|
|
21
|
+
export async function login(): Promise<
|
|
22
|
+
StandardResponse<ILoginSuccessData> | { code: ResponseType; message: string }
|
|
23
|
+
> {
|
|
7
24
|
if (!canIUse('login')) {
|
|
8
25
|
return {
|
|
9
26
|
code: 'FAILURE' as ResponseType,
|
|
10
27
|
message: '[Jolibox SDK]login is not supported in this platform'
|
|
11
28
|
};
|
|
12
29
|
}
|
|
13
|
-
return await commands.executeCommand('API.login')
|
|
30
|
+
return (await commands.executeCommand('API.login')) as StandardResponse<ILoginSuccessData>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Data structure for successful session check.
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
export interface ICheckSessionSuccessData {
|
|
38
|
+
isLogin: boolean;
|
|
14
39
|
}
|
|
15
40
|
|
|
16
|
-
|
|
41
|
+
/**
|
|
42
|
+
* @public
|
|
43
|
+
* Checks the current session status.
|
|
44
|
+
* @returns A promise that resolves with the standard response containing session status if successful, or an error-like object if platform does not support checkSession.
|
|
45
|
+
*/
|
|
46
|
+
export async function checkSession(): Promise<
|
|
47
|
+
StandardResponse<ICheckSessionSuccessData> | { code: ResponseType; message: string }
|
|
48
|
+
> {
|
|
17
49
|
if (!canIUse('checkSession')) {
|
|
18
50
|
return {
|
|
19
51
|
code: 'FAILURE' as ResponseType,
|
|
20
52
|
message: '[Jolibox SDK]checkSession is not supported in this platform'
|
|
21
53
|
};
|
|
22
54
|
}
|
|
23
|
-
return await commands.executeCommand('API.checkSession')
|
|
55
|
+
return (await commands.executeCommand('API.checkSession')) as StandardResponse<ICheckSessionSuccessData>;
|
|
24
56
|
}
|
|
@@ -3,31 +3,62 @@ import { hostEmitter } from '@jolibox/common';
|
|
|
3
3
|
import { HostEventParamsMap } from '@jolibox/types';
|
|
4
4
|
import { APIError } from '@jolibox/common';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Defines the supported custom event names.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export type CustomEventType = 'onI18nChanged' | 'onBackPress';
|
|
8
11
|
|
|
9
|
-
const supportedEvents = ['onI18nChanged', 'onBackPress'];
|
|
12
|
+
const supportedEvents: CustomEventType[] = ['onI18nChanged', 'onBackPress'];
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
/**
|
|
15
|
+
* @public
|
|
16
|
+
* Registers a listener for a supported custom event.
|
|
17
|
+
* The callback will receive parameters specific to the event, as defined in {@link HostEventParamsMap}.
|
|
18
|
+
* @template T - The type of the event name, constrained to {@link CustomEventType}.
|
|
19
|
+
* @param event - The name of the event to listen for.
|
|
20
|
+
* @param callback - The callback function to execute when the event is triggered. Its parameters depend on the event type.
|
|
21
|
+
*/
|
|
22
|
+
export const onCustomEvent = <T extends CustomEventType>(event: T, callback: HostEventParamsMap[T]): void => {
|
|
12
23
|
if (!supportedEvents.includes(event)) {
|
|
13
24
|
reportError(new APIError(`[onCustomEvent] Unsupported event: ${event}`, 2000));
|
|
25
|
+
return; // It's good practice to return after reporting an error if proceeding is problematic
|
|
14
26
|
}
|
|
15
|
-
|
|
16
27
|
hostEmitter.on(event, callback);
|
|
17
28
|
};
|
|
18
29
|
|
|
19
|
-
|
|
30
|
+
/**
|
|
31
|
+
* @public
|
|
32
|
+
* Unregisters a listener for a custom event.
|
|
33
|
+
* @template T - The type of the event name, constrained to {@link CustomEventType}.
|
|
34
|
+
* @param event - The name of the event.
|
|
35
|
+
* @param callback - The specific callback to remove. If not provided, all listeners for the event might be removed (depending on hostEmitter implementation, though typically a specific callback is required by EventEmitter.off).
|
|
36
|
+
*/
|
|
37
|
+
export const offCustomEvent = <T extends CustomEventType>(
|
|
38
|
+
event: T,
|
|
39
|
+
callback: HostEventParamsMap[T]
|
|
40
|
+
): void => {
|
|
20
41
|
if (!supportedEvents.includes(event)) {
|
|
21
42
|
reportError(new APIError(`[offCustomEvent] Unsupported event: ${event}`, 2000));
|
|
43
|
+
return;
|
|
22
44
|
}
|
|
23
|
-
|
|
24
45
|
hostEmitter.off(event, callback);
|
|
25
46
|
};
|
|
26
47
|
|
|
27
|
-
|
|
48
|
+
/**
|
|
49
|
+
* @public
|
|
50
|
+
* Registers a one-time listener for a custom event. The listener is automatically removed after being invoked once.
|
|
51
|
+
* @template T - The type of the event name, constrained to {@link CustomEventType}.
|
|
52
|
+
* @param event - The name of the event to listen for.
|
|
53
|
+
* @param callback - The callback function to execute. Its parameters depend on the event type from {@link HostEventParamsMap}.
|
|
54
|
+
*/
|
|
55
|
+
export const onceCustomEvent = <T extends CustomEventType>(
|
|
56
|
+
event: T,
|
|
57
|
+
callback: HostEventParamsMap[T]
|
|
58
|
+
): void => {
|
|
28
59
|
if (!supportedEvents.includes(event)) {
|
|
29
60
|
reportError(new APIError(`[onceCustomEvent] Unsupported event: ${event}`, 2000));
|
|
61
|
+
return;
|
|
30
62
|
}
|
|
31
|
-
|
|
32
63
|
hostEmitter.once(event, callback);
|
|
33
64
|
};
|
package/src/index.ts
CHANGED
|
@@ -28,7 +28,7 @@ import { RouterSDK } from './sdks/router';
|
|
|
28
28
|
|
|
29
29
|
declare global {
|
|
30
30
|
interface Window {
|
|
31
|
-
JoliboxSDK: typeof JoliboxSDK;
|
|
31
|
+
JoliboxSDK: typeof JoliboxSDK;
|
|
32
32
|
joliboxsdk: {
|
|
33
33
|
runtime: InstanceType<typeof RuntimeSDK>;
|
|
34
34
|
ads: InstanceType<typeof JoliboxAds>;
|
|
@@ -41,28 +41,159 @@ declare global {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* @public
|
|
46
|
+
* The main entry point and facade for the Jolibox JavaScript SDK.
|
|
47
|
+
* Provides access to various SDK modules and global API functions.
|
|
48
|
+
* This class is a singleton.
|
|
49
|
+
*/
|
|
44
50
|
export class JoliboxSDK {
|
|
45
51
|
private static instance: JoliboxSDK | null = null;
|
|
46
52
|
|
|
53
|
+
/**
|
|
54
|
+
* @public
|
|
55
|
+
* @readonly
|
|
56
|
+
* The current version of the Jolibox JSSDK.
|
|
57
|
+
*/
|
|
47
58
|
readonly jssdkVersion = '__JOLIBOX_LOCAL_SDK_VERSION__';
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @public
|
|
62
|
+
* @readonly
|
|
63
|
+
* Access to the Runtime SDK module.
|
|
64
|
+
* @see {@link RuntimeSDK} for more details.
|
|
65
|
+
* @type {RuntimeSDK}
|
|
66
|
+
*/
|
|
48
67
|
readonly runtime = new RuntimeSDK();
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @public
|
|
71
|
+
* @readonly
|
|
72
|
+
* Access to the Ads SDK module.
|
|
73
|
+
* @see {@link JoliboxAds} for more details.
|
|
74
|
+
* @type {JoliboxAds}
|
|
75
|
+
*/
|
|
49
76
|
readonly ads = new JoliboxAds();
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @public
|
|
80
|
+
* @readonly
|
|
81
|
+
* Access to the Lifecycle SDK module.
|
|
82
|
+
* @see {@link LifecycleSDK} for more details.
|
|
83
|
+
* @type {LifecycleSDK}
|
|
84
|
+
*/
|
|
50
85
|
readonly lifecycle = new LifecycleSDK();
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @private
|
|
89
|
+
* @readonly
|
|
90
|
+
* Access to the Storage SDK module.
|
|
91
|
+
* @see {@link StorageSDK} for more details.
|
|
92
|
+
* @type {StorageSDK}
|
|
93
|
+
*/
|
|
51
94
|
readonly storage = new StorageSDK();
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @private
|
|
98
|
+
* @readonly
|
|
99
|
+
* Access to the Keyboard SDK module.
|
|
100
|
+
* @see {@link KeyboardSDK} for more details.
|
|
101
|
+
* @type {KeyboardSDK}
|
|
102
|
+
*/
|
|
52
103
|
readonly keyboard = new KeyboardSDK();
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @public
|
|
107
|
+
* @readonly
|
|
108
|
+
* Access to the Task Tracker SDK module.
|
|
109
|
+
* @see {@link TaskTrackerSDK} for more details.
|
|
110
|
+
* @type {TaskTrackerSDK}
|
|
111
|
+
*/
|
|
53
112
|
readonly task = new TaskTrackerSDK();
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @private
|
|
116
|
+
* @readonly
|
|
117
|
+
* Access to the Router SDK module.
|
|
118
|
+
* @see {@link RouterSDK} for more details.
|
|
119
|
+
* @type {RouterSDK}
|
|
120
|
+
*/
|
|
54
121
|
readonly router = new RouterSDK();
|
|
55
122
|
|
|
56
123
|
//global API
|
|
124
|
+
/**
|
|
125
|
+
* @public
|
|
126
|
+
* Synchronously gets system information.
|
|
127
|
+
* @see {@link getSystemInfoSync} for more details.
|
|
128
|
+
* @returns {ISystemInfo} The system information.
|
|
129
|
+
*/
|
|
57
130
|
getSystemInfoSync = getSystemInfoSync.bind(this);
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @public
|
|
134
|
+
* Checks if a specific API, component, or capability is available in the current environment.
|
|
135
|
+
* @see {@link canIUse} for more details.
|
|
136
|
+
* @param {string} schema - The schema string to check (e.g., "component.button", "api.request").
|
|
137
|
+
* @returns {boolean} True if available, false otherwise.
|
|
138
|
+
*/
|
|
58
139
|
canIUse = canIUse.bind(this);
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @public
|
|
143
|
+
* Initiates the login process.
|
|
144
|
+
* @see {@link login} for more details.
|
|
145
|
+
* @returns {Promise<ILoginSuccessData>} A promise that resolves with login success data.
|
|
146
|
+
*/
|
|
59
147
|
login = login.bind(this);
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* @public
|
|
151
|
+
* Checks the current session status.
|
|
152
|
+
* @see {@link checkSession} for more details.
|
|
153
|
+
* @returns {Promise<ICheckSessionSuccessData>} A promise that resolves with session status data.
|
|
154
|
+
*/
|
|
60
155
|
checkSession = checkSession.bind(this);
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* @private
|
|
159
|
+
* Makes an HTTP request.
|
|
160
|
+
* @see {@link request} for more details.
|
|
161
|
+
* @param {IRequestParams} params - Parameters for the HTTP request.
|
|
162
|
+
* @returns {Promise<IRequestSuccessData>} A promise that resolves with the request response.
|
|
163
|
+
*/
|
|
61
164
|
request = request.bind(this);
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* @public
|
|
168
|
+
* Registers a listener for a custom event.
|
|
169
|
+
* @see {@link onCustomEvent} for more details.
|
|
170
|
+
* @param {string} eventName - The name of the event to listen for.
|
|
171
|
+
* @param {(data: any) => void} callback - The callback function to execute when the event is triggered.
|
|
172
|
+
*/
|
|
62
173
|
on = onCustomEvent.bind(this);
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* @public
|
|
177
|
+
* Unregisters a listener for a custom event.
|
|
178
|
+
* @see {@link offCustomEvent} for more details.
|
|
179
|
+
* @param {string} eventName - The name of the event.
|
|
180
|
+
* @param {(data: any) => void} [callback] - The specific callback to remove. If not provided, all listeners for the event are removed.
|
|
181
|
+
*/
|
|
63
182
|
off = offCustomEvent.bind(this);
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* @public
|
|
186
|
+
* Registers a one-time listener for a custom event. The listener is automatically removed after being invoked once.
|
|
187
|
+
* @see {@link onceCustomEvent} for more details.
|
|
188
|
+
* @param {string} eventName - The name of the event to listen for.
|
|
189
|
+
* @param {(data: any) => void} callback - The callback function to execute.
|
|
190
|
+
*/
|
|
64
191
|
once = onceCustomEvent.bind(this);
|
|
65
192
|
|
|
193
|
+
/**
|
|
194
|
+
* @public
|
|
195
|
+
* Constructs a new JoliboxSDK instance or returns the existing singleton instance.
|
|
196
|
+
*/
|
|
66
197
|
constructor() {
|
|
67
198
|
if (JoliboxSDK.instance) {
|
|
68
199
|
return JoliboxSDK.instance;
|
|
@@ -82,7 +213,11 @@ export class JoliboxSDK {
|
|
|
82
213
|
console.log(`JoliboxSDK ${this.jssdkVersion} init`);
|
|
83
214
|
}
|
|
84
215
|
|
|
85
|
-
|
|
216
|
+
/**
|
|
217
|
+
* @public
|
|
218
|
+
* Gets the singleton instance of the JoliboxSDK.
|
|
219
|
+
* @returns {JoliboxSDK} The singleton JoliboxSDK instance.
|
|
220
|
+
*/
|
|
86
221
|
public static getInstance(): JoliboxSDK {
|
|
87
222
|
if (!JoliboxSDK.instance) {
|
|
88
223
|
JoliboxSDK.instance = new JoliboxSDK();
|
package/src/sdks/ads.ts
CHANGED
|
@@ -7,8 +7,12 @@ import type {
|
|
|
7
7
|
} from '@jolibox/types/dist/sdks/ads';
|
|
8
8
|
import { BaseSDK, BaseSDKEventMap } from './sdk';
|
|
9
9
|
|
|
10
|
-
type JoliboxAdsEventMap = BaseSDKEventMap
|
|
10
|
+
export type JoliboxAdsEventMap = BaseSDKEventMap;
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* @public
|
|
14
|
+
* Manages advertising functionalities within the Jolibox ecosystem.
|
|
15
|
+
*/
|
|
12
16
|
export class JoliboxAds extends BaseSDK<JoliboxAdsEventMap> implements IJoliboxAds {
|
|
13
17
|
constructor() {
|
|
14
18
|
super();
|
|
@@ -29,4 +33,13 @@ export class JoliboxAds extends BaseSDK<JoliboxAdsEventMap> implements IJoliboxA
|
|
|
29
33
|
adUnit = (params: IAdUnitParams) => {
|
|
30
34
|
this.commands.executeCommand('AdsSDK.adUnit', params);
|
|
31
35
|
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Initializes a new ad unit.
|
|
39
|
+
* @param unitId - The ID of the ad unit.
|
|
40
|
+
* @returns A promise that resolves when the ad is loaded.
|
|
41
|
+
*/
|
|
42
|
+
public async initAd(unitId: string): Promise<void> {
|
|
43
|
+
// ...
|
|
44
|
+
}
|
|
32
45
|
}
|
package/src/sdks/keyboard.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { BaseSDK } from './sdk';
|
|
2
2
|
import { Keyboard, ResponseType } from '@jolibox/types';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @private
|
|
6
|
+
* Manages keyboard functionalities within the Jolibox ecosystem. Only Support in Native App
|
|
7
|
+
*/
|
|
4
8
|
export class KeyboardSDK extends BaseSDK implements Keyboard {
|
|
5
9
|
/**
|
|
6
|
-
*
|
|
10
|
+
* Show the keyboard
|
|
7
11
|
* @param params
|
|
8
12
|
* @returns
|
|
9
13
|
*/
|
|
@@ -15,7 +19,7 @@ export class KeyboardSDK extends BaseSDK implements Keyboard {
|
|
|
15
19
|
this.commands.executeCommand('KeyboardSDK.showKeyboard', params);
|
|
16
20
|
}
|
|
17
21
|
/**
|
|
18
|
-
*
|
|
22
|
+
* Update the keyboard
|
|
19
23
|
* @param value
|
|
20
24
|
* @returns
|
|
21
25
|
*/
|
|
@@ -27,7 +31,7 @@ export class KeyboardSDK extends BaseSDK implements Keyboard {
|
|
|
27
31
|
this.commands.executeCommand('KeyboardSDK.updateKeyboard', { value });
|
|
28
32
|
}
|
|
29
33
|
/**
|
|
30
|
-
*
|
|
34
|
+
* Hide the keyboard
|
|
31
35
|
* @returns
|
|
32
36
|
*/
|
|
33
37
|
hideKeyboard() {
|
package/src/sdks/lifecycle.ts
CHANGED
|
@@ -2,15 +2,32 @@ import { Env, Lifecycle } from '@jolibox/types';
|
|
|
2
2
|
import { BaseSDK, BaseSDKEventMap } from './sdk';
|
|
3
3
|
|
|
4
4
|
const LIFECYCLE_ON_READY = 'LifecycleSDK.onReady';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
* Defines the event map specific to the LifecycleSDK, extending BaseSDKEventMap.
|
|
9
|
+
*/
|
|
5
10
|
interface LifecycleSDKEventMap extends BaseSDKEventMap {
|
|
6
11
|
[LIFECYCLE_ON_READY]: Env['hostUserInfo'] | undefined;
|
|
7
12
|
}
|
|
8
13
|
|
|
14
|
+
/**
|
|
15
|
+
* @public
|
|
16
|
+
* Manages lifecycle events and functionalities within the Jolibox SDK.
|
|
17
|
+
* This includes handling application readiness, exit procedures, and visibility changes.
|
|
18
|
+
*/
|
|
9
19
|
export class LifecycleSDK extends BaseSDK<LifecycleSDKEventMap> implements Lifecycle {
|
|
10
20
|
constructor() {
|
|
11
21
|
super();
|
|
12
22
|
}
|
|
13
23
|
|
|
24
|
+
/**
|
|
25
|
+
* @public
|
|
26
|
+
* Registers a callback to be invoked when the Jolibox environment is ready.
|
|
27
|
+
* This typically signifies that the main application or game can start its operations.
|
|
28
|
+
* @param callback - A function to call when the environment is ready. It may receive host user information as a parameter.
|
|
29
|
+
* @event LifecycleSDK.onReady Dispatched after the provided callback is executed, with host user info.
|
|
30
|
+
*/
|
|
14
31
|
onReady(callback: (info?: Env['hostUserInfo']) => void) {
|
|
15
32
|
const wrappedOnReady = (info?: Env['hostUserInfo']) => {
|
|
16
33
|
callback.call(this, info);
|
|
@@ -19,6 +36,15 @@ export class LifecycleSDK extends BaseSDK<LifecycleSDKEventMap> implements Lifec
|
|
|
19
36
|
this.commands.executeCommand('LifecycleSDK.onReady', wrappedOnReady.bind(this));
|
|
20
37
|
}
|
|
21
38
|
|
|
39
|
+
/**
|
|
40
|
+
* @private
|
|
41
|
+
* Initiates the process to exit the Jolibox application or game.
|
|
42
|
+
* Allows registering a callback to be executed before the exit occurs.
|
|
43
|
+
* @param params - An object containing:
|
|
44
|
+
* - `onBeforeExit`: A function to call before the application exits.
|
|
45
|
+
* - `shouldStay` (optional): A boolean indicating if the application should attempt to prevent the exit. The exact behavior may depend on the host environment.
|
|
46
|
+
* @returns {object | undefined} An error object if the 'lifeCycle.exit' capability is not available, otherwise undefined.
|
|
47
|
+
*/
|
|
22
48
|
exit(params: { onBeforeExit: () => void; shouldStay?: boolean }) {
|
|
23
49
|
const errMsg = this.canIUseIfThrow('lifeCycle.exit');
|
|
24
50
|
if (errMsg) {
|
|
@@ -27,10 +53,21 @@ export class LifecycleSDK extends BaseSDK<LifecycleSDKEventMap> implements Lifec
|
|
|
27
53
|
this.commands.executeCommand('LifecycleSDK.exit', params.onBeforeExit, params.shouldStay);
|
|
28
54
|
}
|
|
29
55
|
|
|
30
|
-
|
|
31
|
-
|
|
56
|
+
/**
|
|
57
|
+
* @public
|
|
58
|
+
* Registers a callback to be invoked when the Jolibox application is hidden (e.g., moved to the background).
|
|
59
|
+
* @param callback - A function to call when the application is hidden.
|
|
60
|
+
*/
|
|
61
|
+
onJoliboxHide(callback: () => void) {
|
|
62
|
+
this.commands.executeCommand('LifecycleSDK.onJoliboxHide', callback.bind(this));
|
|
32
63
|
}
|
|
33
|
-
|
|
34
|
-
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @public
|
|
67
|
+
* Registers a callback to be invoked when the Jolibox application is shown (e.g., brought to the foreground).
|
|
68
|
+
* @param callback - A function to call when the application is shown.
|
|
69
|
+
*/
|
|
70
|
+
onJoliboxShow(callback: () => void) {
|
|
71
|
+
this.commands.executeCommand('LifecycleSDK.onJoliboxShow', callback.bind(this));
|
|
35
72
|
}
|
|
36
73
|
}
|