@jolibox/implement 1.1.13-beta.1 → 1.1.13-beta.3
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 +16 -33
- package/.rush/temp/shrinkwrap-deps.json +1 -1
- package/dist/index.js +3 -3
- package/dist/index.native.js +6 -6
- package/dist/native/api/keyboard.d.ts +1 -1
- package/implement.build.log +2 -2
- package/package.json +4 -3
- package/src/common/ads/index.ts +51 -33
- package/src/native/api/ads.ts +1 -1
- package/src/native/api/get-system-info.ts +1 -1
- package/src/native/api/keyboard.ts +1 -1
- package/src/native/api/lifecycle.ts +1 -1
- package/src/native/api/login.ts +1 -1
- package/src/native/api/navigate.ts +1 -1
- package/src/native/api/storage.ts +1 -1
- package/src/native/bootstrap/index.ts +13 -6
- package/src/native/network/create-fetch.ts +1 -1
- package/src/native/report/errors/index.ts +1 -1
- package/src/native/report/index.ts +1 -1
- package/src/native/report/task-tracker.ts +1 -1
- package/src/native/ui/retention.ts +1 -1
- package/dist/native/bootstrap/bridge.d.ts +0 -4
- package/dist/native/js-bridge/const.d.ts +0 -6
- package/dist/native/js-bridge/index.d.ts +0 -2
- package/dist/native/js-bridge/invoke.d.ts +0 -21
- package/dist/native/js-bridge/js-bridge.d.ts +0 -6
- package/dist/native/js-bridge/publish.d.ts +0 -1
- package/dist/native/js-bridge/report.d.ts +0 -63
- package/dist/native/js-bridge/subscribe.d.ts +0 -10
- package/dist/native/js-bridge/types.d.ts +0 -18
- package/dist/native/js-bridge/utils.d.ts +0 -17
- package/dist/native/js-core/index.d.ts +0 -3
- package/dist/native/js-core/jolibox-js-core.d.ts +0 -50
- package/dist/native/js-core/message-port.d.ts +0 -12
- package/dist/native/js-core/utils.d.ts +0 -7
- package/src/native/bootstrap/bridge.ts +0 -68
- package/src/native/js-bridge/const.ts +0 -13
- package/src/native/js-bridge/index.ts +0 -2
- package/src/native/js-bridge/invoke.ts +0 -208
- package/src/native/js-bridge/js-bridge.ts +0 -28
- package/src/native/js-bridge/publish.ts +0 -44
- package/src/native/js-bridge/report.ts +0 -311
- package/src/native/js-bridge/subscribe.ts +0 -74
- package/src/native/js-bridge/types.ts +0 -36
- package/src/native/js-bridge/utils.ts +0 -116
- package/src/native/js-core/index.ts +0 -4
- package/src/native/js-core/jolibox-js-core.ts +0 -192
- package/src/native/js-core/message-port.ts +0 -52
- package/src/native/js-core/utils.ts +0 -9
- package/src/native/types/global.d.ts +0 -27
- package/src/native/types/native-method-map.d.ts +0 -329
- package/src/native/types/native-method.d.ts +0 -30
|
@@ -1,116 +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
|
-
|
|
11
|
-
interface NativeBufferElement {
|
|
12
|
-
key: string;
|
|
13
|
-
value?: ArrayBuffer;
|
|
14
|
-
base64?: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function isNativeBuffers(
|
|
18
|
-
x: unknown & { __nativeBuffers__?: NativeBufferElement[] | undefined }
|
|
19
|
-
): x is { __nativeBuffers__?: NativeBufferElement[]; [k: string]: unknown } {
|
|
20
|
-
return Boolean(x?.__nativeBuffers__);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* decodeFromUi8Base64
|
|
25
|
-
*/
|
|
26
|
-
const decodeFromUi8Base64 = (string: string): ArrayBuffer => {
|
|
27
|
-
const base64String = atob(string);
|
|
28
|
-
const len = base64String.length;
|
|
29
|
-
const ui8aReader = new Uint8Array(len);
|
|
30
|
-
for (let i = 0; i < len; i++) {
|
|
31
|
-
ui8aReader[i] = base64String.charCodeAt(i);
|
|
32
|
-
}
|
|
33
|
-
return ui8aReader.buffer;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export function unpack(data: unknown): DataObj {
|
|
37
|
-
if (typeof data === 'string') {
|
|
38
|
-
try {
|
|
39
|
-
data = JSON.parse(data);
|
|
40
|
-
} catch {
|
|
41
|
-
return {};
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (typeof data !== 'object' || data === null) {
|
|
45
|
-
return {};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (!isNativeBuffers(data)) return data as DataObj;
|
|
49
|
-
|
|
50
|
-
const nativeBuffers = data.__nativeBuffers__;
|
|
51
|
-
delete data.__nativeBuffers__;
|
|
52
|
-
|
|
53
|
-
if (nativeBuffers) {
|
|
54
|
-
for (let i = 0; i < nativeBuffers.length; i++) {
|
|
55
|
-
const item = nativeBuffers[i];
|
|
56
|
-
if (item) {
|
|
57
|
-
let tmp;
|
|
58
|
-
if (item.value) {
|
|
59
|
-
// Arraybuffer
|
|
60
|
-
tmp = item.value;
|
|
61
|
-
} else if (item.base64) {
|
|
62
|
-
tmp = decodeFromUi8Base64(item.base64);
|
|
63
|
-
}
|
|
64
|
-
if (typeof tmp !== 'undefined' && tmp instanceof ArrayBuffer) {
|
|
65
|
-
data[item.key] = tmp;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return data;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const encodeToUi8Base64 = (arrayBuffer: ArrayBuffer): string => {
|
|
75
|
-
let string = '';
|
|
76
|
-
const ui8aReader = new Uint8Array(arrayBuffer);
|
|
77
|
-
const len = ui8aReader.byteLength;
|
|
78
|
-
for (let i = 0; i < len; i++) {
|
|
79
|
-
string += String.fromCharCode(ui8aReader[i]);
|
|
80
|
-
}
|
|
81
|
-
return btoa(string);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
export function pack(_data = {}, useArrayBuffer = false): Record<string, unknown> {
|
|
85
|
-
const data = _data as Record<string, unknown>;
|
|
86
|
-
type ArrayBufferType =
|
|
87
|
-
| {
|
|
88
|
-
value: ArrayBuffer;
|
|
89
|
-
key: string;
|
|
90
|
-
base64?: undefined;
|
|
91
|
-
}
|
|
92
|
-
| {
|
|
93
|
-
base64: string;
|
|
94
|
-
key: string;
|
|
95
|
-
value?: undefined;
|
|
96
|
-
};
|
|
97
|
-
const needTransAttrs: ArrayBufferType[] = [];
|
|
98
|
-
for (const [key, item] of Object.entries(data)) {
|
|
99
|
-
if (item !== undefined && item instanceof ArrayBuffer && item.byteLength !== undefined) {
|
|
100
|
-
const obj: ArrayBufferType = useArrayBuffer
|
|
101
|
-
? { value: item, key }
|
|
102
|
-
: {
|
|
103
|
-
base64: encodeToUi8Base64(item),
|
|
104
|
-
key
|
|
105
|
-
};
|
|
106
|
-
needTransAttrs.push(obj);
|
|
107
|
-
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
108
|
-
delete data[key];
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (needTransAttrs.length > 0) {
|
|
113
|
-
data.__nativeBuffers__ = needTransAttrs;
|
|
114
|
-
}
|
|
115
|
-
return data;
|
|
116
|
-
}
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import { InternalInvokeNativeError } from '@jolibox/common';
|
|
2
|
-
import { normalizeParams } from './utils';
|
|
3
|
-
import { Env } from '@jolibox/types';
|
|
4
|
-
import { reportError } from '@/common/report/errors/report';
|
|
5
|
-
|
|
6
|
-
declare const globalThis: {
|
|
7
|
-
joliboxJSCore?: JoliboxJSCore;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
interface JoliboxJSCore {
|
|
11
|
-
// publish: (event: string, params: string, webviewIds: string) => void;
|
|
12
|
-
invoke: (method: string, params: string, callbackId: number) => string | void;
|
|
13
|
-
/** 安卓: webview 没有 call, service 有 */
|
|
14
|
-
call?: (method: string, params: Record<string, unknown>, callbackId: number) => string | void;
|
|
15
|
-
onDocumentReady: (path: string) => void;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export let joliboxJSCore: jsb.JSCore | undefined;
|
|
19
|
-
|
|
20
|
-
declare global {
|
|
21
|
-
interface Window {
|
|
22
|
-
JoliAndroidSDKBridge?: {
|
|
23
|
-
invoke: (invokeString: string) => void;
|
|
24
|
-
onDocumentReady: (paramsstr: string) => void;
|
|
25
|
-
doExit: (uuidString: string) => void;
|
|
26
|
-
publish: (params: { event: string; webviewIds: number[] | '*'; paramsString: string }) => void;
|
|
27
|
-
};
|
|
28
|
-
webkit?: {
|
|
29
|
-
messageHandlers: {
|
|
30
|
-
invoke: {
|
|
31
|
-
postMessage: (params: { event: string; callbackId: number; paramsString: string }) => void;
|
|
32
|
-
};
|
|
33
|
-
publish: {
|
|
34
|
-
postMessage: (params: { event: string; webviewIds: number[] | '*'; paramsString: string }) => void;
|
|
35
|
-
};
|
|
36
|
-
onDocumentReady: {
|
|
37
|
-
postMessage: (params: { path: string }) => void;
|
|
38
|
-
};
|
|
39
|
-
doExit: {
|
|
40
|
-
postMessage: (params: { uuid: string; shouldInterrupt: boolean }) => void;
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export const RuntimeLoader = {
|
|
48
|
-
trigger() {
|
|
49
|
-
// noop
|
|
50
|
-
},
|
|
51
|
-
exit(): Promise<boolean> {
|
|
52
|
-
//noop
|
|
53
|
-
return Promise.resolve(false); // 默认不打断退出
|
|
54
|
-
},
|
|
55
|
-
onReady(fn: () => void) {
|
|
56
|
-
RuntimeLoader.trigger = fn;
|
|
57
|
-
},
|
|
58
|
-
doExit(fn: () => Promise<boolean>) {
|
|
59
|
-
RuntimeLoader.exit = fn;
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const env = (): Env | undefined => {
|
|
64
|
-
const res = window.prompt(
|
|
65
|
-
'invoke',
|
|
66
|
-
JSON.stringify({
|
|
67
|
-
event: 'envSync',
|
|
68
|
-
paramsString: JSON.stringify({})
|
|
69
|
-
})
|
|
70
|
-
);
|
|
71
|
-
if (!res) {
|
|
72
|
-
reportError(new InternalInvokeNativeError(`native env failed`));
|
|
73
|
-
} else {
|
|
74
|
-
const { data } = JSON.parse(res);
|
|
75
|
-
return data ?? undefined;
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
if (window.webkit) {
|
|
80
|
-
const _joliboxJSCore = window.webkit.messageHandlers;
|
|
81
|
-
const onDocumentReady = (path = '') => {
|
|
82
|
-
RuntimeLoader.trigger();
|
|
83
|
-
_joliboxJSCore.onDocumentReady.postMessage({ path });
|
|
84
|
-
};
|
|
85
|
-
const doExit = async (uuid: string) => {
|
|
86
|
-
const shouldInterrupt = await RuntimeLoader.exit();
|
|
87
|
-
_joliboxJSCore.doExit.postMessage({ uuid, shouldInterrupt: shouldInterrupt });
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
joliboxJSCore = {
|
|
91
|
-
onDocumentReady,
|
|
92
|
-
doExit,
|
|
93
|
-
invoke(method, params, callbackId) {
|
|
94
|
-
_joliboxJSCore.invoke.postMessage({
|
|
95
|
-
event: method,
|
|
96
|
-
paramsString: params,
|
|
97
|
-
callbackId
|
|
98
|
-
});
|
|
99
|
-
},
|
|
100
|
-
publish(event, params, webviewIds) {
|
|
101
|
-
const data = normalizeParams(params as Record<string, unknown>, 'joliboxJSCore');
|
|
102
|
-
window.prompt(
|
|
103
|
-
'publish',
|
|
104
|
-
JSON.stringify({
|
|
105
|
-
event,
|
|
106
|
-
paramsString: JSON.stringify(data),
|
|
107
|
-
webviewIds
|
|
108
|
-
})
|
|
109
|
-
);
|
|
110
|
-
},
|
|
111
|
-
call(method: string, params: Record<string, unknown>, callbackId) {
|
|
112
|
-
const res = window.prompt(
|
|
113
|
-
'invoke',
|
|
114
|
-
JSON.stringify({
|
|
115
|
-
event: method,
|
|
116
|
-
paramsString: JSON.stringify(params),
|
|
117
|
-
callbackId
|
|
118
|
-
})
|
|
119
|
-
);
|
|
120
|
-
if (res) {
|
|
121
|
-
return JSON.parse(res);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
// do not expose invoke/ publish to user
|
|
127
|
-
const devCore = { onDocumentReady, env };
|
|
128
|
-
|
|
129
|
-
//eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
130
|
-
// @ts-ignore
|
|
131
|
-
globalThis.joliboxJSCore = {
|
|
132
|
-
...devCore
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// Android
|
|
137
|
-
if (window.JoliAndroidSDKBridge) {
|
|
138
|
-
const _joliboxJSCore = window.JoliAndroidSDKBridge;
|
|
139
|
-
const onDocumentReady = (path = '') => {
|
|
140
|
-
RuntimeLoader.trigger();
|
|
141
|
-
_joliboxJSCore.onDocumentReady(JSON.stringify({ path }));
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
const doExit = async (uuid: string) => {
|
|
145
|
-
const shouldInterrupt = await RuntimeLoader.exit();
|
|
146
|
-
_joliboxJSCore.doExit(JSON.stringify({ uuid, shouldInterrupt }));
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
joliboxJSCore = {
|
|
150
|
-
onDocumentReady,
|
|
151
|
-
invoke(method, params, callbackId) {
|
|
152
|
-
_joliboxJSCore.invoke(
|
|
153
|
-
JSON.stringify({
|
|
154
|
-
event: method,
|
|
155
|
-
paramsString: params,
|
|
156
|
-
callbackId
|
|
157
|
-
})
|
|
158
|
-
);
|
|
159
|
-
},
|
|
160
|
-
doExit,
|
|
161
|
-
publish(event, params, webviewIds) {
|
|
162
|
-
const data = normalizeParams(params as Record<string, unknown>, 'joliboxJSCore');
|
|
163
|
-
_joliboxJSCore.publish({
|
|
164
|
-
event,
|
|
165
|
-
paramsString: JSON.stringify(data),
|
|
166
|
-
webviewIds
|
|
167
|
-
});
|
|
168
|
-
},
|
|
169
|
-
call(method: string, params: Record<string, unknown>, callbackId) {
|
|
170
|
-
const res = window.prompt(
|
|
171
|
-
'invoke',
|
|
172
|
-
JSON.stringify({
|
|
173
|
-
event: method,
|
|
174
|
-
paramsString: JSON.stringify(params),
|
|
175
|
-
callbackId
|
|
176
|
-
})
|
|
177
|
-
);
|
|
178
|
-
if (res) {
|
|
179
|
-
return JSON.parse(res);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
// do not expose invoke/ publish to user
|
|
185
|
-
const devCore = { onDocumentReady, env };
|
|
186
|
-
|
|
187
|
-
//eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
188
|
-
// @ts-ignore
|
|
189
|
-
globalThis.joliboxJSCore = {
|
|
190
|
-
...devCore
|
|
191
|
-
};
|
|
192
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { normalizeParams } from './utils';
|
|
2
|
-
import { AnyFunction } from '@jolibox/types';
|
|
3
|
-
|
|
4
|
-
declare const globalThis: {
|
|
5
|
-
onmessage?: (msg: MessageEvent) => void;
|
|
6
|
-
ttJSBridge: {
|
|
7
|
-
invokeHandler: AnyFunction;
|
|
8
|
-
subscribeHandler: AnyFunction;
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
interface MessageEvent {
|
|
13
|
-
data: string;
|
|
14
|
-
ports: MessagePort[];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface MessagePort {
|
|
18
|
-
onmessage: (msg: MessageEvent) => void;
|
|
19
|
-
postMessage: (msg: string) => void;
|
|
20
|
-
publish: (event: string, data: Record<string, unknown>) => void;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
type PublishEvent = ['publish', string, string];
|
|
24
|
-
type InvokeEvent = ['invoke', number, string];
|
|
25
|
-
|
|
26
|
-
export let messagePort: MessagePort | undefined;
|
|
27
|
-
|
|
28
|
-
export function initMessagePort() {
|
|
29
|
-
globalThis.onmessage = function (msg) {
|
|
30
|
-
if (msg.data !== 'msg:setup') {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
[messagePort] = msg.ports;
|
|
35
|
-
messagePort.onmessage = function (message) {
|
|
36
|
-
const data: PublishEvent | InvokeEvent = JSON.parse(message.data);
|
|
37
|
-
if (data[0] === 'publish') {
|
|
38
|
-
globalThis.ttJSBridge.subscribeHandler(data[1], data[2]);
|
|
39
|
-
} else if (data[0] === 'invoke') {
|
|
40
|
-
globalThis.ttJSBridge.invokeHandler(data[1], data[2]);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
messagePort.publish = function (event, params) {
|
|
45
|
-
const data = normalizeParams(params as Record<string, unknown>, 'messagePort');
|
|
46
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
47
|
-
messagePort!.postMessage(JSON.stringify(['publish', event, JSON.stringify(data)]));
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
messagePort.postMessage('msg:setup:ok');
|
|
51
|
-
};
|
|
52
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
declare global {
|
|
2
|
-
namespace jsb {
|
|
3
|
-
interface JSCore {
|
|
4
|
-
invoke: (method: string, params: string, callbackId: number) => string | Record<string, unknown> | void;
|
|
5
|
-
|
|
6
|
-
// publish: (event: string, data: Record<string, unknown>, webviewIds: number[]) => void;
|
|
7
|
-
|
|
8
|
-
// 安卓 Webview 没有call
|
|
9
|
-
call?: (
|
|
10
|
-
method: string,
|
|
11
|
-
params: Record<string, unknown>,
|
|
12
|
-
callbackId: number
|
|
13
|
-
) => string | Record<string, unknown> | void;
|
|
14
|
-
|
|
15
|
-
onDocumentReady: (path: string) => void;
|
|
16
|
-
doExit: (uuid: string) => void;
|
|
17
|
-
bind?: (id: number, handler: (...args: unknown[]) => unknown) => void;
|
|
18
|
-
publish: (event: string, data: unknown, webviewIds: number[] | '*') => void;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
type ApplyNativeReturn<T> = T extends Promise<infer U>
|
|
22
|
-
? Promise<Omit<U, 'errMsg' | 'errNo'>>
|
|
23
|
-
: Omit<T, 'errMsg' | 'errNo'>;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export {};
|