@jolibox/implement 1.1.13-beta.1 → 1.1.13-beta.11

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.
Files changed (76) hide show
  1. package/.rush/temp/package-deps_build.json +30 -39
  2. package/.rush/temp/shrinkwrap-deps.json +1 -1
  3. package/dist/common/ads/anti-cheating.d.ts +5 -0
  4. package/dist/common/rewards/__tests__/can-use-jolicoin.test.d.ts +1 -0
  5. package/dist/common/rewards/fetch-reward.d.ts +2 -0
  6. package/dist/common/rewards/index.d.ts +18 -0
  7. package/dist/common/rewards/registers/use-ads.d.ts +3 -0
  8. package/dist/common/rewards/registers/use-jolicoin.d.ts +10 -0
  9. package/dist/common/rewards/registers/utils/index.d.ts +2 -0
  10. package/dist/common/rewards/reward-helper.d.ts +14 -0
  11. package/dist/common/rewards/type.d.ts +23 -0
  12. package/dist/common/utils/index.d.ts +7 -0
  13. package/dist/index.js +3 -3
  14. package/dist/index.native.js +28 -7
  15. package/dist/native/api/keyboard.d.ts +1 -1
  16. package/implement.build.log +2 -2
  17. package/package.json +4 -3
  18. package/src/common/ads/anti-cheating.test.ts +4 -2
  19. package/src/common/ads/anti-cheating.ts +12 -4
  20. package/src/common/ads/index.ts +51 -33
  21. package/src/common/rewards/__tests__/can-use-jolicoin.test.ts +94 -0
  22. package/src/common/rewards/fetch-reward.ts +39 -0
  23. package/src/common/rewards/index.ts +20 -0
  24. package/src/common/rewards/registers/use-ads.ts +9 -0
  25. package/src/common/rewards/registers/use-jolicoin.ts +96 -0
  26. package/src/common/rewards/registers/utils/index.ts +11 -0
  27. package/src/common/rewards/reward-helper.ts +56 -0
  28. package/src/common/rewards/type.ts +25 -0
  29. package/src/common/utils/index.ts +7 -0
  30. package/src/h5/api/ads.ts +20 -1
  31. package/src/h5/api/get-system-info.ts +1 -1
  32. package/src/h5/http/utils/__tests__/xua.test.ts +1 -1
  33. package/src/native/api/ads.ts +31 -3
  34. package/src/native/api/get-system-info.ts +2 -2
  35. package/src/native/api/keyboard.ts +1 -1
  36. package/src/native/api/lifecycle.ts +1 -1
  37. package/src/native/api/login.ts +1 -1
  38. package/src/native/api/navigate.ts +1 -1
  39. package/src/native/api/storage.ts +1 -1
  40. package/src/native/bootstrap/index.ts +13 -6
  41. package/src/native/network/create-fetch.ts +6 -2
  42. package/src/native/report/errors/index.ts +1 -1
  43. package/src/native/report/index.ts +1 -1
  44. package/src/native/report/task-tracker.ts +1 -1
  45. package/src/native/ui/retention.ts +4 -3
  46. package/dist/native/bootstrap/bridge.d.ts +0 -4
  47. package/dist/native/js-bridge/const.d.ts +0 -6
  48. package/dist/native/js-bridge/index.d.ts +0 -2
  49. package/dist/native/js-bridge/invoke.d.ts +0 -21
  50. package/dist/native/js-bridge/js-bridge.d.ts +0 -6
  51. package/dist/native/js-bridge/publish.d.ts +0 -1
  52. package/dist/native/js-bridge/report.d.ts +0 -63
  53. package/dist/native/js-bridge/subscribe.d.ts +0 -10
  54. package/dist/native/js-bridge/types.d.ts +0 -18
  55. package/dist/native/js-bridge/utils.d.ts +0 -17
  56. package/dist/native/js-core/index.d.ts +0 -3
  57. package/dist/native/js-core/jolibox-js-core.d.ts +0 -50
  58. package/dist/native/js-core/message-port.d.ts +0 -12
  59. package/dist/native/js-core/utils.d.ts +0 -7
  60. package/src/native/bootstrap/bridge.ts +0 -68
  61. package/src/native/js-bridge/const.ts +0 -13
  62. package/src/native/js-bridge/index.ts +0 -2
  63. package/src/native/js-bridge/invoke.ts +0 -208
  64. package/src/native/js-bridge/js-bridge.ts +0 -28
  65. package/src/native/js-bridge/publish.ts +0 -44
  66. package/src/native/js-bridge/report.ts +0 -311
  67. package/src/native/js-bridge/subscribe.ts +0 -74
  68. package/src/native/js-bridge/types.ts +0 -36
  69. package/src/native/js-bridge/utils.ts +0 -116
  70. package/src/native/js-core/index.ts +0 -4
  71. package/src/native/js-core/jolibox-js-core.ts +0 -192
  72. package/src/native/js-core/message-port.ts +0 -52
  73. package/src/native/js-core/utils.ts +0 -9
  74. package/src/native/types/global.d.ts +0 -27
  75. package/src/native/types/native-method-map.d.ts +0 -329
  76. package/src/native/types/native-method.d.ts +0 -30
@@ -1,5 +1,6 @@
1
- import { createCommands, logger } from '@jolibox/common';
1
+ import { createCommands } from '@jolibox/common';
2
2
  import { createSyncAPI, registerCanIUse } from './base';
3
+ import { createToast } from '@jolibox/ui';
3
4
 
4
5
  const commands = createCommands();
5
6
 
@@ -7,7 +8,8 @@ import { IAdsInitParams, JoliboxAdsImpl, IAdConfigParams, IAdBreakParams, IAdUni
7
8
  import { track } from '../report';
8
9
 
9
10
  import { innerFetch as fetch } from '../network';
10
- import { invokeNative } from '../bootstrap/bridge';
11
+ import { invokeNative } from '@jolibox/native-bridge';
12
+ import { rewardsHelper, createAdsRewardHandler, createJolicoinRewardHandler } from '@/common/rewards';
11
13
 
12
14
  const checkNetworkStatus = () => {
13
15
  const { data } = invokeNative('getNetworkStatusSync');
@@ -34,6 +36,26 @@ const ads = new JoliboxAdsImpl(
34
36
  checkNetworkStatus
35
37
  );
36
38
 
39
+ rewardsHelper.registerRewardHandler('ADS', createAdsRewardHandler(ads));
40
+ rewardsHelper.registerRewardHandler(
41
+ 'JOLI_COIN',
42
+ createJolicoinRewardHandler(ads.httpClient, {
43
+ onUnlockSuccess: (params) => {
44
+ const { quantity, balance } = params;
45
+ const balanceStr = balance >= 1000 ? '999+' : balance;
46
+ createToast(`{slot-checkmark} −${quantity} {slot-coin} | Balance: ${balanceStr} {slot-coin}`, {
47
+ customStyle: {
48
+ mark: {
49
+ marginRight: '8px'
50
+ }
51
+ }
52
+ });
53
+ },
54
+ onUnlockFailed: () => {
55
+ console.log('onUnlockFailed');
56
+ }
57
+ }) as unknown as (params?: unknown) => Promise<boolean>
58
+ );
37
59
  const adInit = createSyncAPI('adInit', {
38
60
  implement: (config?: IAdsInitParams) => {
39
61
  ads.init(config);
@@ -48,7 +70,13 @@ const adConfig = createSyncAPI('adConfig', {
48
70
 
49
71
  const adBreak = createSyncAPI('adBreak', {
50
72
  implement: (params: IAdBreakParams) => {
51
- ads.adBreak(params);
73
+ if (params.type === 'reward') {
74
+ rewardsHelper.getRewardsTypes(ads.httpClient).then((rewardsTypes) => {
75
+ rewardsHelper.handleReward(rewardsTypes, params);
76
+ });
77
+ } else {
78
+ ads.adBreak(params);
79
+ }
52
80
  }
53
81
  });
54
82
 
@@ -1,6 +1,6 @@
1
1
  import { createCommands } from '@jolibox/common';
2
2
  import { createSyncAPI, registerCanIUse } from './base';
3
- import { invokeNative } from '../bootstrap/bridge';
3
+ import { invokeNative } from '@jolibox/native-bridge';
4
4
 
5
5
  const commands = createCommands();
6
6
 
@@ -13,7 +13,7 @@ const getSystemInfoSync = createSyncAPI(API_GET_SYSTEM_SYNC, {
13
13
  const { data } = res;
14
14
  return {
15
15
  system: data.deviceInfo.system,
16
- platform: data.deviceInfo.platform,
16
+ platform: data.deviceInfo.platform.toLowerCase() as 'h5' | 'android' | 'ios',
17
17
  version: data.sdkInfo.jssdkVersion,
18
18
  pixelRatio: data.deviceInfo.pixelRatio,
19
19
  language: data.deviceInfo.lang,
@@ -1,5 +1,5 @@
1
1
  import { createCommands } from '@jolibox/common';
2
- import { invokeNative } from '../bootstrap/bridge';
2
+ import { invokeNative } from '@jolibox/native-bridge';
3
3
  import { createSyncAPI, registerCanIUse, t } from './base';
4
4
 
5
5
  export const showKeyboard = createSyncAPI('showKeyboard', {
@@ -1,7 +1,7 @@
1
1
  import { BaseError, createCommands, wrapUserFunction, hostEmitter, isBoolean } from '@jolibox/common';
2
2
  import { createAPI, createSyncAPI, registerCanIUse, t } from './base';
3
3
  import { reportError } from '@/common/report/errors/report';
4
- import { applyNative, onNative, publish } from '../bootstrap/bridge';
4
+ import { applyNative, onNative, publish } from '@jolibox/native-bridge';
5
5
  import { nativeTaskEmitter } from '../report';
6
6
  import { context } from '@/common/context';
7
7
 
@@ -1,5 +1,5 @@
1
1
  import { context } from '@/common/context';
2
- import { applyNative, invokeNative, onNative } from '../bootstrap/bridge';
2
+ import { applyNative, invokeNative, onNative } from '@jolibox/native-bridge';
3
3
  import { createAPI, t, registerCanIUse } from './base';
4
4
  import { createCommands, Deferred, hostEmitter } from '@jolibox/common';
5
5
  import { createAPIError } from '@/common/report/errors';
@@ -1,5 +1,5 @@
1
1
  import { createCommands, UserCustomError } from '@jolibox/common';
2
- import { invokeNative } from '../bootstrap/bridge';
2
+ import { invokeNative } from '@jolibox/native-bridge';
3
3
  import { createSyncAPI, t, registerCanIUse } from './base';
4
4
  import { context } from '@/common/context';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { createAPI, createSyncAPI, registerCanIUse, t } from './base';
2
- import { applyNative, invokeNative } from '../bootstrap/bridge';
2
+ import { applyNative, invokeNative } from '@jolibox/native-bridge';
3
3
  import { createCommands } from '@jolibox/common';
4
4
  import { innerFetch as fetch } from '../network';
5
5
  import { context } from '@/common/context';
@@ -1,5 +1,4 @@
1
- import { invokeNative, onNative, RuntimeLoader } from './bridge';
2
- import { joliboxJSCore } from '../js-core';
1
+ import { invokeNative, onNative, RuntimeLoader } from '@jolibox/native-bridge';
3
2
  import { context } from '@/common/context';
4
3
  import { hostEmitter, isBoolean } from '@jolibox/common';
5
4
  import { taskTracker, track } from '../report';
@@ -7,11 +6,19 @@ import { initializeNativeEnv } from './init-env';
7
6
  import { adEventEmitter } from '@/common/ads';
8
7
  import { openRetentionSchema } from '../ui/retention';
9
8
  import { innerFetch } from '../network';
10
-
9
+ import { Env } from '@jolibox/types';
11
10
  interface IBasicMetaConfig {
12
11
  canShowRecommended: boolean;
13
12
  }
14
13
 
14
+ declare const globalThis: {
15
+ joliboxJSCore: {
16
+ doExit: (uuid: string) => void;
17
+ onDocumentReady: (path: string) => void;
18
+ env: (params: { onError: (error: Error) => void }) => Env | undefined;
19
+ };
20
+ };
21
+
15
22
  /**
16
23
  * 全局变量
17
24
  */
@@ -58,7 +65,7 @@ function addShowAdListener() {
58
65
  */
59
66
  function addWebviewReadyListener() {
60
67
  hostEmitter.on('onDocumentReady', () => {
61
- joliboxJSCore?.onDocumentReady(window.location.href);
68
+ globalThis.joliboxJSCore?.onDocumentReady(window.location.href);
62
69
  track('onDocumentReady', {
63
70
  start_timestamp,
64
71
  timestamp: Date.now()
@@ -89,7 +96,7 @@ function addGameServiceReadyListener() {
89
96
  });
90
97
 
91
98
  onNative('onBeforeExit', ({ uuid }) => {
92
- joliboxJSCore?.doExit(uuid);
99
+ globalThis.joliboxJSCore?.doExit(uuid);
93
100
  });
94
101
  }
95
102
 
@@ -111,7 +118,7 @@ function addDoExitLoader() {
111
118
  taskTracker.close(Date.now() - start_timestamp);
112
119
  };
113
120
 
114
- RuntimeLoader.doExit(async () => {
121
+ RuntimeLoader.onDoExit(async () => {
115
122
  if (isAdShowing) {
116
123
  return true; // Forbid exit on watching ads
117
124
  }
@@ -2,7 +2,7 @@ import { isString, logger, Deferred, isObject, hostEmitter } from '@jolibox/comm
2
2
  import { reportNetworkAPI } from './report';
3
3
  import { RequestFrom } from './types';
4
4
  import { FetchResponse, FetchOptions } from './types';
5
- import { invokeNative, onNative } from '@/native/bootstrap/bridge';
5
+ import { invokeNative, onNative } from '@jolibox/native-bridge';
6
6
  import { AnyFunction } from '@jolibox/types';
7
7
  import { reportError } from '@/common/report/errors/report';
8
8
  import { createAPIError } from '@/common/report/errors';
@@ -82,7 +82,11 @@ export function createFetch(
82
82
 
83
83
  if (res.state === 'success') {
84
84
  const { requestTaskId, state, ...rest } = res;
85
- task.resolve(rest);
85
+ if (res.statusCode === 200) {
86
+ task.resolve(rest);
87
+ } else {
88
+ task.reject(rest);
89
+ }
86
90
  promiseMap.delete(requestTaskId);
87
91
  } else if (res.state === 'fail') {
88
92
  const { requestTaskId, state, ...rest } = res;
@@ -5,7 +5,7 @@ import '@/common/report/errors/report/listeners';
5
5
  import { errorReportEmitter } from '@/common/report/errors';
6
6
  import { ErrorData } from '@/common/report/errors/report';
7
7
  import { logger } from '@jolibox/common';
8
- import { applyNative, invokeNative } from '@/native/bootstrap/bridge';
8
+ import { invokeNative } from '@jolibox/native-bridge';
9
9
 
10
10
  errorReportEmitter.on('GLOBAL_ERROR', (error, errorData: ErrorData) => {
11
11
  const extra = {
@@ -4,7 +4,7 @@ export * from '../../common/report/types';
4
4
  import { createTracks, ReportHandler } from '@/common/report';
5
5
  import { context } from '@/common/context';
6
6
  import { NativeTaskTracker } from './task-tracker';
7
- import { invokeNative } from '../bootstrap/bridge';
7
+ import { invokeNative } from '@jolibox/native-bridge';
8
8
 
9
9
  const reportNative: ReportHandler = (event, data, webviewId) => {
10
10
  const _data = data as Record<string, unknown>;
@@ -6,7 +6,7 @@ import { context } from '@/common/context';
6
6
  import { TaskTracker, TaskPoint } from '@/common/report/task-track';
7
7
  import { EventEmitter } from '@jolibox/common';
8
8
  import { innerFetch as fetch } from '../network';
9
- import { applyNative } from '../bootstrap/bridge';
9
+ import { applyNative } from '@jolibox/native-bridge';
10
10
  import type { Track } from '.';
11
11
  import type { TrackEvent } from '@jolibox/types';
12
12
 
@@ -1,5 +1,5 @@
1
1
  import { context } from '@/common/context';
2
- import { invokeNative, subscribe } from '../bootstrap/bridge';
2
+ import { invokeNative, subscribe } from '@jolibox/native-bridge';
3
3
  import { Deferred } from '@jolibox/common';
4
4
  import { createRecommendModal, IGame, IRecommendationButton, RecommendModalOnCloseParams } from '@jolibox/ui';
5
5
  import { innerFetch as fetch } from '../network';
@@ -50,10 +50,11 @@ const openGameSchema = (game: IGame) => {
50
50
  // Parse the original URL to preserve its structure
51
51
 
52
52
  const url = new URL(data.schema);
53
+ const originalPath = url.pathname;
53
54
  const originalSearch = new URLSearchParams(url.search);
54
55
 
55
56
  // Set or replace gameId and joliSource parameters
56
- originalSearch.set('gameId', game.gameId);
57
+ originalSearch.set('gameId', context.mpId);
57
58
  originalSearch.set(
58
59
  'joliSource',
59
60
  context.encodeJoliSourceQuery({
@@ -64,7 +65,7 @@ const openGameSchema = (game: IGame) => {
64
65
 
65
66
  const host = `https://${game.gameId}.content.jolibox.com/`;
66
67
  // Construct the final schema URL
67
- const schema = `${host}index.html?${originalSearch.toString()}`;
68
+ const schema = `${host}${originalPath}?${originalSearch.toString()}`;
68
69
 
69
70
  invokeNative('openSchemaSync', {
70
71
  schema
@@ -1,4 +0,0 @@
1
- import { On } from '../js-bridge';
2
- export declare const applyNative: jsb.service.ApplyNative, invokeNative: jsb.service.InvokeNative, onNative: jsb.service.OnNative, offNative: jsb.service.OnNative, subscribeHandler: import("../js-bridge").SubscribeHandler, publish: import("../js-bridge").Publish, subscribe: On, unsubscribe: import("../js-bridge").Off;
3
- export declare const onNativeWithError: On;
4
- export { RuntimeLoader } from '../js-core';
@@ -1,6 +0,0 @@
1
- export declare const CUSTOM_EVENT_PREFIX = "custom_event_";
2
- export declare const HOST_EVENT_PREFIX = "host_event_";
3
- export declare const BUFFER_METHODS: string[];
4
- export declare const BACKGROUND_FORBIDDEN_METHODS: string[];
5
- export declare const SYNC_METHODS: string[];
6
- export declare const BATCH_EVENT = "__batch_event__";
@@ -1,2 +0,0 @@
1
- export { createBridge } from './js-bridge';
2
- export * from './types';
@@ -1,21 +0,0 @@
1
- import { InvokeHandler, On } from './types';
2
- interface Invokes {
3
- /** 暴露给宿主, 触发调用的方法 */
4
- invokeHandler: InvokeHandler;
5
- /** 基础库内部, 调用宿主的方法, 返回 native 返回对象 */
6
- invokeNative: (method: string, args?: Record<string, unknown>, webviewId?: number) => any;
7
- /** 基础库内部, 调用宿主的方法, 会根据 errMsg throwError */
8
- applyNative: (method: string, args?: Record<string, unknown>, webviewId?: number) => any;
9
- }
10
- export declare function createInvoke(jsCore: jsb.JSCore, onNative: On): Invokes;
11
- export declare function ifThrowError(method: string, res: {
12
- errMsg?: string;
13
- errNo?: number;
14
- errorType?: string;
15
- errorCode?: number;
16
- }): {} | undefined;
17
- export declare class ApplyNativeError extends Error {
18
- readonly errNo?: number | undefined;
19
- constructor(message: string, errNo?: number | undefined);
20
- }
21
- export {};
@@ -1,6 +0,0 @@
1
- import { JSBridge } from './types';
2
- /**
3
- * build js-bridge
4
- * @param jsCore jsCore function inject by native
5
- */
6
- export declare function createBridge(jsCore: jsb.JSCore): JSBridge;
@@ -1 +0,0 @@
1
- export declare function createPublish(jsCore: jsb.JSCore): (event: string, data: Record<string, unknown>, webviewId?: number, force?: boolean) => void;
@@ -1,63 +0,0 @@
1
- import { On } from './types';
2
- type MetricReporter = (points: unknown) => unknown;
3
- interface MetricCache {
4
- [props: string]: MetricCache | (number | string)[];
5
- }
6
- interface PVMetricCache {
7
- [props: string]: PVMetricCache | number;
8
- }
9
- type MetricCacheType = MetricCache | PVMetricCache;
10
- type MetricType = 'pv' | 'default';
11
- type Prettier<T> = T extends Record<string, unknown> ? {
12
- [K in keyof T]: T[K];
13
- } : T;
14
- type MetricPoint<Tag extends string, Name extends string> = Prettier<{
15
- [k in Tag]: string;
16
- } & {
17
- [K in Name]: number | string;
18
- }>;
19
- interface PVPoint {
20
- [props: string]: string | JSON;
21
- }
22
- interface MetricConfig<Tag extends string, Name extends string, Type extends string> {
23
- reporter: MetricReporter;
24
- interval?: number;
25
- eventName: string;
26
- tagNameOrder: Tag[];
27
- metricName: Name;
28
- type?: Type;
29
- }
30
- export declare class MetricsMonitor<Tag extends string, Name extends string, Type extends string> {
31
- reporter: MetricReporter;
32
- interval: number;
33
- lastReportTime: number;
34
- cache: MetricCacheType;
35
- eventName: string;
36
- tagNameOrder: Tag[];
37
- metricName: Name;
38
- type: MetricType;
39
- constructor(config: MetricConfig<Tag, Name, Type>);
40
- report(point: Type extends 'pv' ? PVPoint : MetricPoint<Tag, Name>): void;
41
- flush(): void;
42
- private tryReport;
43
- private addPoint;
44
- private addPVPoint;
45
- private processPoints;
46
- private clearPoints;
47
- }
48
- interface InvokeMetrics {
49
- errMsg: string;
50
- errNo?: number;
51
- __timing?: {
52
- receiveJSInvoke: number;
53
- invokeCallback: number;
54
- };
55
- method: string;
56
- startTime: number;
57
- args?: Record<string, unknown>;
58
- isForeground: string;
59
- [prop: string]: unknown;
60
- }
61
- export type reportInvokeFn = (invokeMetrics: InvokeMetrics) => void;
62
- export declare function createReportInvokeMetrics(jsCore: jsb.JSCore, onNative: On): reportInvokeFn;
63
- export {};
@@ -1,10 +0,0 @@
1
- import { Off, On } from './types';
2
- import { AnyFunction } from '@jolibox/types';
3
- export interface Subscribes {
4
- onNative: On;
5
- offNative: Off;
6
- subscribeHandler: AnyFunction;
7
- subscribe: On;
8
- unsubscribe: Off;
9
- }
10
- export declare function createSubscribe(jsCore: jsb.JSCore): Subscribes;
@@ -1,18 +0,0 @@
1
- export type Listener = (...args: any[]) => any;
2
- export type On = <T extends string>(event: T, handler: Listener) => void;
3
- export type Off = <T extends string>(event: T, handler: Listener) => void;
4
- export type InvokeHandler = (callbackId: string | number, data: string | Record<string, unknown>) => void;
5
- export type Publish = (event: string, data: Record<string, unknown>, webviewId?: number, force?: boolean) => void;
6
- export type SubscribeHandler = (event: string, data: string | Record<string, unknown>, webviewId?: number) => void;
7
- export type AnyFunction = (...args: any[]) => any;
8
- export interface JSBridge {
9
- invokeHandler: InvokeHandler;
10
- subscribeHandler: SubscribeHandler;
11
- invokeNative: jsb.service.InvokeNative;
12
- applyNative: jsb.service.ApplyNative;
13
- onNative: jsb.service.OnNative;
14
- offNative: jsb.service.OffNative;
15
- publish: Publish;
16
- subscribe: On;
17
- unsubscribe: Off;
18
- }
@@ -1,17 +0,0 @@
1
- export interface DataObj {
2
- params?: Record<string, unknown>;
3
- errorCode?: number;
4
- __extra?: {
5
- startTime: number;
6
- type: string;
7
- };
8
- __nativeBuffers__?: NativeBufferElement[] | undefined;
9
- }
10
- interface NativeBufferElement {
11
- key: string;
12
- value?: ArrayBuffer;
13
- base64?: string;
14
- }
15
- export declare function unpack(data: unknown): DataObj;
16
- export declare function pack(_data?: {}, useArrayBuffer?: boolean): Record<string, unknown>;
17
- export {};
@@ -1,3 +0,0 @@
1
- export { joliboxJSCore, RuntimeLoader } from './jolibox-js-core';
2
- export { messagePort, initMessagePort } from './message-port';
3
- export { normalizeParams } from './utils';
@@ -1,50 +0,0 @@
1
- export declare let joliboxJSCore: jsb.JSCore | undefined;
2
- declare global {
3
- interface Window {
4
- JoliAndroidSDKBridge?: {
5
- invoke: (invokeString: string) => void;
6
- onDocumentReady: (paramsstr: string) => void;
7
- doExit: (uuidString: string) => void;
8
- publish: (params: {
9
- event: string;
10
- webviewIds: number[] | '*';
11
- paramsString: string;
12
- }) => void;
13
- };
14
- webkit?: {
15
- messageHandlers: {
16
- invoke: {
17
- postMessage: (params: {
18
- event: string;
19
- callbackId: number;
20
- paramsString: string;
21
- }) => void;
22
- };
23
- publish: {
24
- postMessage: (params: {
25
- event: string;
26
- webviewIds: number[] | '*';
27
- paramsString: string;
28
- }) => void;
29
- };
30
- onDocumentReady: {
31
- postMessage: (params: {
32
- path: string;
33
- }) => void;
34
- };
35
- doExit: {
36
- postMessage: (params: {
37
- uuid: string;
38
- shouldInterrupt: boolean;
39
- }) => void;
40
- };
41
- };
42
- };
43
- }
44
- }
45
- export declare const RuntimeLoader: {
46
- trigger(): void;
47
- exit(): Promise<boolean>;
48
- onReady(fn: () => void): void;
49
- doExit(fn: () => Promise<boolean>): void;
50
- };
@@ -1,12 +0,0 @@
1
- interface MessageEvent {
2
- data: string;
3
- ports: MessagePort[];
4
- }
5
- interface MessagePort {
6
- onmessage: (msg: MessageEvent) => void;
7
- postMessage: (msg: string) => void;
8
- publish: (event: string, data: Record<string, unknown>) => void;
9
- }
10
- export declare let messagePort: MessagePort | undefined;
11
- export declare function initMessagePort(): void;
12
- export {};
@@ -1,7 +0,0 @@
1
- export declare function normalizeParams(params: Record<string, unknown>, type: string): {
2
- params: Record<string, unknown>;
3
- __extra: {
4
- startTime: number;
5
- type: string;
6
- };
7
- };
@@ -1,68 +0,0 @@
1
- import { createBridge, On } from '../js-bridge';
2
-
3
- import { joliboxJSCore, initMessagePort } from '../js-core';
4
-
5
- import { formatErrorCode } from '../../common/report/errors';
6
- import { AnyFunction } from '@jolibox/types';
7
- import { InternalJSCoreNotFoundError } from '@jolibox/common';
8
-
9
- declare const globalThis: {
10
- joliboxJSBridge?: {
11
- callHandler: AnyFunction;
12
- invokeHandler: AnyFunction;
13
- subscribeHandler: AnyFunction;
14
- };
15
- };
16
-
17
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
18
- const jsCore = joliboxJSCore!;
19
-
20
- if (!jsCore) {
21
- throw new InternalJSCoreNotFoundError('No joliboxJScore is found, native bridge not found.');
22
- }
23
-
24
- initMessagePort();
25
-
26
- const core: jsb.JSCore = {
27
- ...jsCore
28
- // publish(event: string, params: Record<string, unknown>, webviewIds: number[]) {
29
- // if (messagePort) {
30
- // messagePort.publish(event, params);
31
- // return;
32
- // }
33
- // jsCore.publish(event, params, webviewIds);
34
- // }
35
- };
36
-
37
- const bridge = createBridge(core);
38
-
39
- const { invokeHandler } = bridge;
40
-
41
- export const {
42
- applyNative,
43
- invokeNative,
44
- onNative,
45
- offNative,
46
- subscribeHandler,
47
- publish,
48
- subscribe,
49
- unsubscribe
50
- } = bridge;
51
-
52
- export const onNativeWithError: On = (event, handler) => {
53
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
54
- onNative(event as keyof jsb.service.NativeEventMap, (...rest: any) => {
55
- if (rest[0]?.errorCode) {
56
- rest[0].errorCode = formatErrorCode(event, rest[0].errorCode);
57
- }
58
- handler(...rest);
59
- });
60
- };
61
-
62
- globalThis.joliboxJSBridge = {
63
- callHandler: invokeHandler,
64
- invokeHandler,
65
- subscribeHandler
66
- };
67
-
68
- export { RuntimeLoader } from '../js-core';
@@ -1,13 +0,0 @@
1
- export const CUSTOM_EVENT_PREFIX = 'custom_event_';
2
-
3
- export const HOST_EVENT_PREFIX = 'host_event_';
4
-
5
- //TODO: add buffer supported method
6
- export const BUFFER_METHODS: string[] = [];
7
-
8
- // TODO: add method cannot invoke background
9
- export const BACKGROUND_FORBIDDEN_METHODS: string[] = [];
10
-
11
- export const SYNC_METHODS: string[] = ['env', 'createRequestTask', 'login'];
12
-
13
- export const BATCH_EVENT = '__batch_event__';
@@ -1,2 +0,0 @@
1
- export { createBridge } from './js-bridge';
2
- export * from './types';