@jolibox/implement 1.1.11-beta.2 → 1.1.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.
- package/.rush/temp/package-deps_build.json +14 -17
- package/dist/common/context/index.d.ts +0 -4
- package/dist/common/context/url-parse.d.ts +1 -8
- package/dist/index.js +3 -3
- package/dist/index.native.js +4 -4
- package/dist/native/api/index.d.ts +0 -1
- package/dist/native/bootstrap/bridge.d.ts +1 -1
- package/dist/native/js-bridge/const.d.ts +0 -1
- package/dist/native/js-bridge/subscribe.d.ts +0 -2
- package/dist/native/js-bridge/types.d.ts +0 -4
- package/dist/native/js-core/jolibox-js-core.d.ts +3 -8
- package/implement.build.log +2 -2
- package/package.json +3 -3
- package/src/common/context/index.ts +3 -20
- package/src/common/context/url-parse.ts +1 -21
- package/src/native/api/index.ts +0 -1
- package/src/native/api/lifecycle.ts +4 -16
- package/src/native/bootstrap/bridge.ts +1 -10
- package/src/native/bootstrap/index.ts +2 -32
- package/src/native/js-bridge/const.ts +0 -2
- package/src/native/js-bridge/js-bridge.ts +2 -7
- package/src/native/js-bridge/subscribe.ts +1 -25
- package/src/native/js-bridge/types.ts +0 -10
- package/src/native/js-core/jolibox-js-core.ts +25 -29
- package/src/native/types/global.d.ts +0 -1
- package/src/native/types/native-method-map.d.ts +0 -12
- package/dist/native/api/navigate.d.ts +0 -1
- package/dist/native/bootstrap/retention.d.ts +0 -1
- package/dist/native/js-bridge/publish.d.ts +0 -1
- package/src/native/api/navigate.ts +0 -23
- package/src/native/bootstrap/retention.ts +0 -40
- package/src/native/js-bridge/publish.ts +0 -44
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { BaseError, createCommands, wrapUserFunction, hostEmitter
|
|
1
|
+
import { BaseError, createCommands, wrapUserFunction, hostEmitter } 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
|
|
4
|
+
import { applyNative, onNative } from '../bootstrap/bridge';
|
|
5
5
|
import { nativeTaskEmitter } from '../report';
|
|
6
|
-
import { context } from '@/common/context';
|
|
7
6
|
|
|
8
7
|
const EXIT_GAME = 'exitGame';
|
|
9
8
|
const ON_READY = 'onReady';
|
|
@@ -14,22 +13,11 @@ const commands = createCommands();
|
|
|
14
13
|
|
|
15
14
|
const safeCallbackWrapper = wrapUserFunction(reportError as (err: Error | BaseError) => void);
|
|
16
15
|
const exitGame = createAPI(EXIT_GAME, {
|
|
17
|
-
paramsSchema: t.tuple(t.function()
|
|
18
|
-
implement: async (onBeforeExit: () => void
|
|
16
|
+
paramsSchema: t.tuple(t.function()),
|
|
17
|
+
implement: async (onBeforeExit: () => void) => {
|
|
19
18
|
const safeCallback = safeCallbackWrapper(onBeforeExit);
|
|
20
19
|
// 集中上报
|
|
21
20
|
safeCallback.call(this);
|
|
22
|
-
// 透传context.shouldInterupt 且值为false时,为内部小程序。广播onRetentionResult
|
|
23
|
-
if (isBoolean(context.shouldInterupt) && !context.shouldInterupt && context.from) {
|
|
24
|
-
publish(
|
|
25
|
-
'onRetentionResult',
|
|
26
|
-
{
|
|
27
|
-
shouldStay
|
|
28
|
-
},
|
|
29
|
-
context.from,
|
|
30
|
-
true
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
21
|
await applyNative('exitAppAsync');
|
|
34
22
|
}
|
|
35
23
|
});
|
|
@@ -38,16 +38,7 @@ const bridge = createBridge(core);
|
|
|
38
38
|
|
|
39
39
|
const { invokeHandler } = bridge;
|
|
40
40
|
|
|
41
|
-
export const {
|
|
42
|
-
applyNative,
|
|
43
|
-
invokeNative,
|
|
44
|
-
onNative,
|
|
45
|
-
offNative,
|
|
46
|
-
subscribeHandler,
|
|
47
|
-
publish,
|
|
48
|
-
subscribe,
|
|
49
|
-
unsubscribe
|
|
50
|
-
} = bridge;
|
|
41
|
+
export const { applyNative, invokeNative, onNative, offNative, subscribeHandler } = bridge;
|
|
51
42
|
|
|
52
43
|
export const onNativeWithError: On = (event, handler) => {
|
|
53
44
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -1,56 +1,26 @@
|
|
|
1
|
-
import { invokeNative, onNative, RuntimeLoader
|
|
1
|
+
import { invokeNative, onNative, RuntimeLoader } from './bridge';
|
|
2
2
|
import { joliboxJSCore } from '../js-core';
|
|
3
3
|
import { context } from '@/common/context';
|
|
4
4
|
import { hostEmitter, isBoolean } from '@jolibox/common';
|
|
5
5
|
import { taskTracker, track } from '../report';
|
|
6
6
|
import { initializeNativeEnv } from './init-env';
|
|
7
7
|
import { adEventEmitter } from '@/common/ads';
|
|
8
|
-
import { openRetentionSchema } from './retention';
|
|
9
8
|
|
|
10
9
|
let cleanStyles: () => void;
|
|
11
10
|
RuntimeLoader.onReady(() => {
|
|
12
11
|
// TODO: merge some env config
|
|
13
12
|
});
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
RuntimeLoader.doExit(() => {
|
|
16
15
|
//埋点上报
|
|
17
16
|
track('onBeforeExit', {
|
|
18
17
|
timestamp: Date.now()
|
|
19
18
|
});
|
|
20
19
|
cleanStyles?.();
|
|
21
20
|
taskTracker.close(Date.now() - start_timestamp);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* 退出逻辑
|
|
26
|
-
* 1. 如果正在展示广告,则禁止退出
|
|
27
|
-
* 2. 如果指定退出挽留逻辑,则按照指定逻辑运行
|
|
28
|
-
* 3. 如果退出挽留逻辑返回 true,则按照指定逻辑运行
|
|
29
|
-
* 4. 否则,按照默认逻辑运行
|
|
30
|
-
*/
|
|
31
|
-
RuntimeLoader.doExit(async () => {
|
|
32
21
|
if (isAdShowing) {
|
|
33
22
|
return true; // Forbid exit on watching ads
|
|
34
23
|
}
|
|
35
|
-
|
|
36
|
-
// 指定退出挽留逻辑,则按照指定逻辑运行
|
|
37
|
-
if (isBoolean(context.shouldInterupt)) {
|
|
38
|
-
// 不需要打断退出,上报埋点
|
|
39
|
-
if (!context.shouldInterupt) {
|
|
40
|
-
doActualExit();
|
|
41
|
-
}
|
|
42
|
-
return context.shouldInterupt;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// const stay = await openRetentionSchema();
|
|
46
|
-
// if (stay) {
|
|
47
|
-
// // 挽留成功,打断退出
|
|
48
|
-
// return true;
|
|
49
|
-
// }
|
|
50
|
-
|
|
51
|
-
// 退出,对应上报
|
|
52
|
-
//埋点上报
|
|
53
|
-
doActualExit();
|
|
54
24
|
return false;
|
|
55
25
|
});
|
|
56
26
|
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { createInvoke } from './invoke';
|
|
2
2
|
import { createSubscribe } from './subscribe';
|
|
3
3
|
import { JSBridge } from './types';
|
|
4
|
-
import { createPublish } from './publish';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* build js-bridge
|
|
8
7
|
* @param jsCore jsCore function inject by native
|
|
9
8
|
*/
|
|
10
9
|
export function createBridge(jsCore: jsb.JSCore): JSBridge {
|
|
11
|
-
const { subscribeHandler, onNative, offNative
|
|
10
|
+
const { subscribeHandler, onNative, offNative } = createSubscribe(jsCore);
|
|
12
11
|
|
|
13
12
|
const { invokeNative, invokeHandler, applyNative } = createInvoke(jsCore, onNative);
|
|
14
|
-
const publish = createPublish(jsCore);
|
|
15
13
|
|
|
16
14
|
return {
|
|
17
15
|
// 宿主调用
|
|
@@ -20,9 +18,6 @@ export function createBridge(jsCore: jsb.JSCore): JSBridge {
|
|
|
20
18
|
applyNative,
|
|
21
19
|
invokeNative,
|
|
22
20
|
onNative,
|
|
23
|
-
offNative
|
|
24
|
-
publish,
|
|
25
|
-
subscribe,
|
|
26
|
-
unsubscribe
|
|
21
|
+
offNative
|
|
27
22
|
};
|
|
28
23
|
}
|
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
import { EventEmitter
|
|
1
|
+
import { EventEmitter } from '@jolibox/common';
|
|
2
2
|
import { DataObj, unpack } from './utils';
|
|
3
3
|
import { Off, On } from './types';
|
|
4
4
|
import { AnyFunction } from '@jolibox/types';
|
|
5
5
|
import { MetricsMonitor } from './report';
|
|
6
|
-
import { BATCH_EVENT, CUSTOM_EVENT_PREFIX } from './const';
|
|
7
6
|
|
|
8
7
|
export interface Subscribes {
|
|
9
8
|
onNative: On;
|
|
10
9
|
offNative: Off;
|
|
11
10
|
subscribeHandler: AnyFunction;
|
|
12
|
-
subscribe: On;
|
|
13
|
-
unsubscribe: Off;
|
|
14
11
|
}
|
|
15
12
|
|
|
16
13
|
export function createSubscribe(jsCore: jsb.JSCore): Subscribes {
|
|
17
14
|
const nativeEmitter = new EventEmitter();
|
|
18
|
-
const customEmitter = new EventEmitter();
|
|
19
15
|
const publishMonitor = new MetricsMonitor({
|
|
20
16
|
eventName: 'jolibox_publish',
|
|
21
17
|
tagNameOrder: ['type', 'event'],
|
|
@@ -32,8 +28,6 @@ export function createSubscribe(jsCore: jsb.JSCore): Subscribes {
|
|
|
32
28
|
return {
|
|
33
29
|
onNative: nativeEmitter.on.bind(nativeEmitter),
|
|
34
30
|
offNative: nativeEmitter.off.bind(nativeEmitter),
|
|
35
|
-
subscribe: customEmitter.on.bind(customEmitter),
|
|
36
|
-
unsubscribe: customEmitter.off.bind(customEmitter),
|
|
37
31
|
subscribeHandler(event, data, webviewId) {
|
|
38
32
|
// ios: jsc 端基于系统方法,前端接受到的 data 总是 string 类型, webview 基于 evaluateJavascript,前端接受到的 data 总是 object 类型
|
|
39
33
|
// android: 传入为 string 则接收到 string,传入为可序列化成功的 object,则接收到 object
|
|
@@ -50,24 +44,6 @@ export function createSubscribe(jsCore: jsb.JSCore): Subscribes {
|
|
|
50
44
|
} else {
|
|
51
45
|
originalParams = unpackedData;
|
|
52
46
|
}
|
|
53
|
-
|
|
54
|
-
if (event === BATCH_EVENT) {
|
|
55
|
-
const list = originalParams as [event: string, data: unknown][];
|
|
56
|
-
list.forEach((item) => {
|
|
57
|
-
const [_event, _data] = item;
|
|
58
|
-
try {
|
|
59
|
-
customEmitter.emit(_event.slice(CUSTOM_EVENT_PREFIX.length), _data, webviewId);
|
|
60
|
-
} catch {
|
|
61
|
-
// 忽略
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (event.startsWith(CUSTOM_EVENT_PREFIX)) {
|
|
68
|
-
customEmitter.emit(event.slice(CUSTOM_EVENT_PREFIX.length), originalParams, webviewId);
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
47
|
nativeEmitter.emit(event, originalParams, webviewId);
|
|
72
48
|
}
|
|
73
49
|
};
|
|
@@ -7,13 +7,6 @@ export type Off = <T extends string>(event: T, handler: Listener) => void;
|
|
|
7
7
|
|
|
8
8
|
export type InvokeHandler = (callbackId: string | number, data: string | Record<string, unknown>) => void;
|
|
9
9
|
|
|
10
|
-
export type Publish = (
|
|
11
|
-
event: string,
|
|
12
|
-
data: Record<string, unknown>,
|
|
13
|
-
webviewId?: number,
|
|
14
|
-
force?: boolean
|
|
15
|
-
) => void;
|
|
16
|
-
|
|
17
10
|
export type SubscribeHandler = (
|
|
18
11
|
event: string,
|
|
19
12
|
data: string | Record<string, unknown>,
|
|
@@ -30,7 +23,4 @@ export interface JSBridge {
|
|
|
30
23
|
applyNative: jsb.service.ApplyNative;
|
|
31
24
|
onNative: jsb.service.OnNative;
|
|
32
25
|
offNative: jsb.service.OffNative;
|
|
33
|
-
publish: Publish;
|
|
34
|
-
subscribe: On;
|
|
35
|
-
unsubscribe: Off;
|
|
36
26
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { InternalInvokeNativeError } from '@jolibox/common';
|
|
2
|
-
import { normalizeParams } from './utils';
|
|
2
|
+
// import { normalizeParams } from './utils';
|
|
3
3
|
import { Env } from '@jolibox/types';
|
|
4
4
|
import { reportError } from '@/common/report/errors/report';
|
|
5
5
|
|
|
@@ -23,7 +23,6 @@ declare global {
|
|
|
23
23
|
invoke: (invokeString: string) => void;
|
|
24
24
|
onDocumentReady: (paramsstr: string) => void;
|
|
25
25
|
doExit: (uuidString: string) => void;
|
|
26
|
-
publish: (params: { event: string; webviewIds: number[] | '*'; paramsString: string }) => void;
|
|
27
26
|
};
|
|
28
27
|
webkit?: {
|
|
29
28
|
messageHandlers: {
|
|
@@ -31,7 +30,7 @@ declare global {
|
|
|
31
30
|
postMessage: (params: { event: string; callbackId: number; paramsString: string }) => void;
|
|
32
31
|
};
|
|
33
32
|
publish: {
|
|
34
|
-
postMessage: (params: { event: string; webviewIds:
|
|
33
|
+
postMessage: (params: { event: string; webviewIds: string; paramsString: string }) => void;
|
|
35
34
|
};
|
|
36
35
|
onDocumentReady: {
|
|
37
36
|
postMessage: (params: { path: string }) => void;
|
|
@@ -48,14 +47,14 @@ export const RuntimeLoader = {
|
|
|
48
47
|
trigger() {
|
|
49
48
|
// noop
|
|
50
49
|
},
|
|
51
|
-
exit():
|
|
50
|
+
exit(): boolean {
|
|
52
51
|
//noop
|
|
53
|
-
return
|
|
52
|
+
return false; // 默认不打断退出
|
|
54
53
|
},
|
|
55
54
|
onReady(fn: () => void) {
|
|
56
55
|
RuntimeLoader.trigger = fn;
|
|
57
56
|
},
|
|
58
|
-
doExit(fn: () =>
|
|
57
|
+
doExit(fn: () => boolean) {
|
|
59
58
|
RuntimeLoader.exit = fn;
|
|
60
59
|
}
|
|
61
60
|
};
|
|
@@ -82,8 +81,8 @@ if (window.webkit) {
|
|
|
82
81
|
RuntimeLoader.trigger();
|
|
83
82
|
_joliboxJSCore.onDocumentReady.postMessage({ path });
|
|
84
83
|
};
|
|
85
|
-
const doExit =
|
|
86
|
-
const shouldInterrupt =
|
|
84
|
+
const doExit = (uuid: string) => {
|
|
85
|
+
const shouldInterrupt = RuntimeLoader.exit();
|
|
87
86
|
_joliboxJSCore.doExit.postMessage({ uuid, shouldInterrupt });
|
|
88
87
|
};
|
|
89
88
|
|
|
@@ -97,17 +96,14 @@ if (window.webkit) {
|
|
|
97
96
|
callbackId
|
|
98
97
|
});
|
|
99
98
|
},
|
|
100
|
-
publish(event, params, webviewIds) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
})
|
|
109
|
-
);
|
|
110
|
-
},
|
|
99
|
+
// publish(event, params, webviewIds) {
|
|
100
|
+
// const data = normalizeParams(params as Record<string, unknown>, 'joliboxJSCore');
|
|
101
|
+
// _joliboxJSCore.publish.postMessage({
|
|
102
|
+
// event,
|
|
103
|
+
// paramsString: JSON.stringify(data),
|
|
104
|
+
// webviewIds: JSON.stringify(webviewIds)
|
|
105
|
+
// });
|
|
106
|
+
// },
|
|
111
107
|
call(method: string, params: Record<string, unknown>, callbackId) {
|
|
112
108
|
const res = window.prompt(
|
|
113
109
|
'invoke',
|
|
@@ -141,8 +137,8 @@ if (window.JoliAndroidSDKBridge) {
|
|
|
141
137
|
_joliboxJSCore.onDocumentReady(JSON.stringify({ path }));
|
|
142
138
|
};
|
|
143
139
|
|
|
144
|
-
const doExit =
|
|
145
|
-
const shouldInterrupt =
|
|
140
|
+
const doExit = (uuid: string) => {
|
|
141
|
+
const shouldInterrupt = RuntimeLoader.exit();
|
|
146
142
|
_joliboxJSCore.doExit(JSON.stringify({ uuid, shouldInterrupt }));
|
|
147
143
|
};
|
|
148
144
|
|
|
@@ -158,14 +154,14 @@ if (window.JoliAndroidSDKBridge) {
|
|
|
158
154
|
);
|
|
159
155
|
},
|
|
160
156
|
doExit,
|
|
161
|
-
publish(event, params, webviewIds) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
},
|
|
157
|
+
// publish(event, params, webviewIds) {
|
|
158
|
+
// const data = normalizeParams(params as Record<string, unknown>, 'joliboxJSCore');
|
|
159
|
+
// _joliboxJSCore.publish({
|
|
160
|
+
// event,
|
|
161
|
+
// paramsString: JSON.stringify(data),
|
|
162
|
+
// webviewIds: JSON.stringify(webviewIds)
|
|
163
|
+
// });
|
|
164
|
+
// },
|
|
169
165
|
call(method: string, params: Record<string, unknown>, callbackId) {
|
|
170
166
|
const res = window.prompt(
|
|
171
167
|
'invoke',
|
|
@@ -15,7 +15,6 @@ declare global {
|
|
|
15
15
|
onDocumentReady: (path: string) => void;
|
|
16
16
|
doExit: (uuid: string) => void;
|
|
17
17
|
bind?: (id: number, handler: (...args: unknown[]) => unknown) => void;
|
|
18
|
-
publish: (event: string, data: unknown, webviewIds: number[] | '*') => void;
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
type ApplyNativeReturn<T> = T extends Promise<infer U>
|
|
@@ -255,13 +255,6 @@ declare global {
|
|
|
255
255
|
/** 错误码 */
|
|
256
256
|
errNo?: number;
|
|
257
257
|
};
|
|
258
|
-
|
|
259
|
-
openSchemaSync: (params: { schema: string }) => {
|
|
260
|
-
/** 错误消息 */
|
|
261
|
-
errMsg: string;
|
|
262
|
-
/** 错误码 */
|
|
263
|
-
errNo?: number;
|
|
264
|
-
};
|
|
265
258
|
}
|
|
266
259
|
|
|
267
260
|
interface NativeEventMap {
|
|
@@ -300,11 +293,6 @@ declare global {
|
|
|
300
293
|
token?: string;
|
|
301
294
|
}
|
|
302
295
|
];
|
|
303
|
-
onInfoTapped: [
|
|
304
|
-
{
|
|
305
|
-
uuid: string;
|
|
306
|
-
}
|
|
307
|
-
];
|
|
308
296
|
}
|
|
309
297
|
}
|
|
310
298
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function openRetentionSchema(): Promise<boolean>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function createPublish(jsCore: jsb.JSCore): (event: string, data: Record<string, unknown>, webviewId?: number, force?: boolean) => void;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { createCommands, UserCustomError } from '@jolibox/common';
|
|
2
|
-
import { invokeNative } from '../bootstrap/bridge';
|
|
3
|
-
import { createSyncAPI, t, registerCanIUse } from './base';
|
|
4
|
-
|
|
5
|
-
const commands = createCommands();
|
|
6
|
-
|
|
7
|
-
const openSchemaSync = createSyncAPI('openSchemaSync', {
|
|
8
|
-
paramsSchema: t.tuple(t.string()),
|
|
9
|
-
implement: (schema) => {
|
|
10
|
-
const res = invokeNative('openSchemaSync', {
|
|
11
|
-
schema
|
|
12
|
-
});
|
|
13
|
-
if (res.errNo !== 0) {
|
|
14
|
-
throw new UserCustomError(res.errMsg, res.errNo);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
commands.registerCommand('API.openSchemaSync', openSchemaSync);
|
|
20
|
-
|
|
21
|
-
registerCanIUse('openSchemaSync', {
|
|
22
|
-
version: '1.1.9'
|
|
23
|
-
});
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { context } from '@/common/context';
|
|
2
|
-
import { invokeNative, subscribe } from './bridge';
|
|
3
|
-
import { Deferred } from '@jolibox/common';
|
|
4
|
-
|
|
5
|
-
export async function openRetentionSchema() {
|
|
6
|
-
const { data } = invokeNative('envSync');
|
|
7
|
-
const { orientation, webviewId } = data;
|
|
8
|
-
let joliPayload: Record<string, unknown> = {
|
|
9
|
-
__mpType: 'miniApp',
|
|
10
|
-
__transparent: true,
|
|
11
|
-
// set entryPath
|
|
12
|
-
__orientation: orientation ?? 'VERTICAL', // 默认竖屏
|
|
13
|
-
__showStatusBar: false,
|
|
14
|
-
__shouldInterupt: false
|
|
15
|
-
};
|
|
16
|
-
if (webviewId) {
|
|
17
|
-
joliPayload = {
|
|
18
|
-
...joliPayload,
|
|
19
|
-
__from: webviewId
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const joliSource = context.encodeJoliSourceQuery(joliPayload);
|
|
24
|
-
|
|
25
|
-
const host = context.testMode ? 'stg-game.jolibox.com' : 'game.jolibox.com';
|
|
26
|
-
const retentionSchema = `https://${host}/game/G32115508989327465281365749294/?appId=G32115508989327465281365749294&joliSource=${joliSource}`;
|
|
27
|
-
|
|
28
|
-
const quitResultDeffer = new Deferred<boolean>();
|
|
29
|
-
|
|
30
|
-
subscribe('onRetentionResult', ({ shouldStay }) => {
|
|
31
|
-
quitResultDeffer.resolve(shouldStay);
|
|
32
|
-
});
|
|
33
|
-
// 异步
|
|
34
|
-
setTimeout(() => {
|
|
35
|
-
invokeNative('openSchemaSync', {
|
|
36
|
-
schema: retentionSchema
|
|
37
|
-
});
|
|
38
|
-
}, 0);
|
|
39
|
-
return quitResultDeffer.promise;
|
|
40
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { CUSTOM_EVENT_PREFIX, BATCH_EVENT } from './const';
|
|
2
|
-
|
|
3
|
-
type BatchEvent = [event: string, data: unknown];
|
|
4
|
-
type BatchEvents = BatchEvent[];
|
|
5
|
-
|
|
6
|
-
export function createPublish(jsCore: jsb.JSCore) {
|
|
7
|
-
const eventsMap = new Map<number | undefined, BatchEvents>();
|
|
8
|
-
let batchTask: Promise<void> | undefined;
|
|
9
|
-
const publish = (event: string, data: Record<string, unknown>, webviewId?: number, force?: boolean) => {
|
|
10
|
-
if (force) {
|
|
11
|
-
const ids = webviewId ? [webviewId] : '*';
|
|
12
|
-
jsCore.publish(`${CUSTOM_EVENT_PREFIX}${event}`, data, ids);
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (!batchTask) {
|
|
17
|
-
batchTask = Promise.resolve().then(() => {
|
|
18
|
-
eventsMap.forEach((data, webviewId) => {
|
|
19
|
-
try {
|
|
20
|
-
const ids = webviewId ? [webviewId] : '*';
|
|
21
|
-
jsCore.publish(BATCH_EVENT, data, ids);
|
|
22
|
-
} catch {
|
|
23
|
-
// 避免一组 webview publish 的报错影响其他 webview publish
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
// reset
|
|
28
|
-
batchTask = undefined;
|
|
29
|
-
eventsMap.clear();
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
let events = eventsMap.get(webviewId);
|
|
34
|
-
|
|
35
|
-
if (!events) {
|
|
36
|
-
events = [];
|
|
37
|
-
eventsMap.set(webviewId, events);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
events.push([`${CUSTOM_EVENT_PREFIX}${event}`, data]);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
return publish;
|
|
44
|
-
}
|