@lynx-js/web-worker-runtime 0.11.0 → 0.12.0
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/CHANGELOG.md +18 -0
- package/dist/backgroundThread/background-apis/createBackgroundLynx.d.ts +2 -11
- package/dist/backgroundThread/background-apis/createBackgroundLynx.js +5 -24
- package/dist/common/LynxCrossThreadContext.d.ts +12 -0
- package/dist/common/LynxCrossThreadContext.js +24 -0
- package/dist/mainThread/startMainThread.js +17 -4
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @lynx-js/web-worker-runtime
|
|
2
2
|
|
|
3
|
+
## 0.12.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- feat: fully support MTS ([#569](https://github.com/lynx-family/lynx-stack/pull/569))
|
|
8
|
+
|
|
9
|
+
Now use support the following usage
|
|
10
|
+
|
|
11
|
+
- mainthread event
|
|
12
|
+
- mainthread ref
|
|
13
|
+
- runOnMainThread/runOnBackground
|
|
14
|
+
- ref.current.xx
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [[`f1ca29b`](https://github.com/lynx-family/lynx-stack/commit/f1ca29bd766377dd46583f15e1e75bca447699cd), [`8ca9fcb`](https://github.com/lynx-family/lynx-stack/commit/8ca9fcbbc86b0f0ac05ee4319876cdd5dd08d668), [`efe6fd7`](https://github.com/lynx-family/lynx-stack/commit/efe6fd7de8a3d8119ea550f4d4e939d1fbfee4f0)]:
|
|
17
|
+
- @lynx-js/web-mainthread-apis@0.12.0
|
|
18
|
+
- @lynx-js/web-constants@0.12.0
|
|
19
|
+
- @lynx-js/web-worker-rpc@0.12.0
|
|
20
|
+
|
|
3
21
|
## 0.11.0
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Cloneable, type NativeApp } from '@lynx-js/web-constants';
|
|
2
2
|
import type { Rpc } from '@lynx-js/web-worker-rpc';
|
|
3
|
+
import { LynxCrossThreadContext } from '../../common/LynxCrossThreadContext.js';
|
|
3
4
|
export interface CreateLynxConfig {
|
|
4
5
|
globalProps: unknown;
|
|
5
6
|
customSections: Record<string, Cloneable>;
|
|
6
7
|
}
|
|
7
|
-
export declare class LynxCrossThreadContext extends EventTarget implements LynxContextEventTarget {
|
|
8
|
-
private _config;
|
|
9
|
-
constructor(_config: {
|
|
10
|
-
mainThreadRpc: Rpc;
|
|
11
|
-
dispatchEventEndpoint: typeof dispatchCoreContextEventEndpoint;
|
|
12
|
-
});
|
|
13
|
-
postMessage(...args: any[]): void;
|
|
14
|
-
dispatchEvent(event: Event): number;
|
|
15
|
-
__start(): void;
|
|
16
|
-
}
|
|
17
8
|
export declare function createBackgroundLynx(config: CreateLynxConfig, nativeApp: NativeApp, mainThreadRpc: Rpc): {
|
|
18
9
|
__globalProps: unknown;
|
|
19
10
|
getJSModule(_moduleName: string): any;
|
|
@@ -1,33 +1,14 @@
|
|
|
1
1
|
// Copyright 2023 The Lynx Authors. All rights reserved.
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
import {
|
|
4
|
+
import { dispatchCoreContextOnBackgroundEndpoint, dispatchJSContextOnMainThreadEndpoint, } from '@lynx-js/web-constants';
|
|
5
5
|
import { createGetCustomSection } from './crossThreadHandlers/createGetCustomSection.js';
|
|
6
|
-
|
|
7
|
-
_config;
|
|
8
|
-
constructor(_config) {
|
|
9
|
-
super();
|
|
10
|
-
this._config = _config;
|
|
11
|
-
}
|
|
12
|
-
postMessage(...args) {
|
|
13
|
-
console.error('[lynx-web] postMessage not implemented, args:', ...args);
|
|
14
|
-
}
|
|
15
|
-
// @ts-expect-error
|
|
16
|
-
dispatchEvent(event) {
|
|
17
|
-
super.dispatchEvent(event);
|
|
18
|
-
return DispatchEventResult.CanceledBeforeDispatch;
|
|
19
|
-
}
|
|
20
|
-
__start() {
|
|
21
|
-
const { mainThreadRpc, dispatchEventEndpoint } = this._config;
|
|
22
|
-
mainThreadRpc.registerHandler(dispatchEventEndpoint, (eventType, data) => {
|
|
23
|
-
this.dispatchEvent(new MessageEvent(eventType, { data: data ?? {} }));
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
6
|
+
import { LynxCrossThreadContext } from '../../common/LynxCrossThreadContext.js';
|
|
27
7
|
export function createBackgroundLynx(config, nativeApp, mainThreadRpc) {
|
|
28
8
|
const coreContext = new LynxCrossThreadContext({
|
|
29
|
-
mainThreadRpc,
|
|
30
|
-
|
|
9
|
+
rpc: mainThreadRpc,
|
|
10
|
+
receiveEventEndpoint: dispatchCoreContextOnBackgroundEndpoint,
|
|
11
|
+
sendEventEndpoint: dispatchJSContextOnMainThreadEndpoint,
|
|
31
12
|
});
|
|
32
13
|
return {
|
|
33
14
|
__globalProps: config.globalProps,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type dispatchCoreContextOnBackgroundEndpoint, type LynxContextEventTarget, type Rpc } from '@lynx-js/web-constants';
|
|
2
|
+
export declare class LynxCrossThreadContext extends EventTarget implements LynxContextEventTarget {
|
|
3
|
+
private _config;
|
|
4
|
+
constructor(_config: {
|
|
5
|
+
rpc: Rpc;
|
|
6
|
+
receiveEventEndpoint: typeof dispatchCoreContextOnBackgroundEndpoint;
|
|
7
|
+
sendEventEndpoint: typeof dispatchCoreContextOnBackgroundEndpoint;
|
|
8
|
+
});
|
|
9
|
+
postMessage(...args: any[]): void;
|
|
10
|
+
dispatchEvent(event: ContextCrossThreadEvent): 3;
|
|
11
|
+
__start(): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { DispatchEventResult, } from '@lynx-js/web-constants';
|
|
2
|
+
export class LynxCrossThreadContext extends EventTarget {
|
|
3
|
+
_config;
|
|
4
|
+
constructor(_config) {
|
|
5
|
+
super();
|
|
6
|
+
this._config = _config;
|
|
7
|
+
}
|
|
8
|
+
postMessage(...args) {
|
|
9
|
+
console.error('[lynx-web] postMessage not implemented, args:', ...args);
|
|
10
|
+
}
|
|
11
|
+
// @ts-expect-error
|
|
12
|
+
dispatchEvent(event) {
|
|
13
|
+
const { rpc, sendEventEndpoint } = this._config;
|
|
14
|
+
rpc.invoke(sendEventEndpoint, [event]);
|
|
15
|
+
return DispatchEventResult.CanceledBeforeDispatch;
|
|
16
|
+
}
|
|
17
|
+
__start() {
|
|
18
|
+
const { rpc, receiveEventEndpoint } = this._config;
|
|
19
|
+
rpc.registerHandler(receiveEventEndpoint, ({ type, data }) => {
|
|
20
|
+
super.dispatchEvent(new MessageEvent(type, { data: data ?? {} }));
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=LynxCrossThreadContext.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright 2023 The Lynx Authors. All rights reserved.
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
import { BackgroundThreadStartEndpoint, mainThreadStartEndpoint, flushElementTreeEndpoint, reportErrorEndpoint, publishEventEndpoint, publicComponentEventEndpoint, postExposureEndpoint, postOffscreenEventEndpoint, switchExposureServiceEndpoint, postTimingFlagsEndpoint,
|
|
4
|
+
import { BackgroundThreadStartEndpoint, mainThreadStartEndpoint, flushElementTreeEndpoint, reportErrorEndpoint, publishEventEndpoint, publicComponentEventEndpoint, postExposureEndpoint, postOffscreenEventEndpoint, switchExposureServiceEndpoint, postTimingFlagsEndpoint, dispatchCoreContextOnBackgroundEndpoint, dispatchJSContextOnMainThreadEndpoint, } from '@lynx-js/web-constants';
|
|
5
5
|
import { Rpc } from '@lynx-js/web-worker-rpc';
|
|
6
6
|
import { MainThreadRuntime, switchExposureService, } from '@lynx-js/web-mainthread-apis';
|
|
7
7
|
import { registerCallLepusMethodHandler } from './crossThreadHandlers/registerCallLepusMethodHandler.js';
|
|
@@ -10,13 +10,13 @@ import { createMarkTimingInternal } from './crossThreadHandlers/createMainthread
|
|
|
10
10
|
import { registerUpdateDataHandler } from './crossThreadHandlers/registerUpdateDataHandler.js';
|
|
11
11
|
import { OffscreenDocument } from '@lynx-js/offscreen-document/webworker';
|
|
12
12
|
import { _onEvent, } from '@lynx-js/offscreen-document/webworker';
|
|
13
|
+
import { LynxCrossThreadContext } from '../common/LynxCrossThreadContext.js';
|
|
13
14
|
export function startMainThread(uiThreadPort, backgroundThreadPort) {
|
|
14
15
|
const uiThreadRpc = new Rpc(uiThreadPort, 'main-to-ui');
|
|
15
16
|
const backgroundThreadRpc = new Rpc(backgroundThreadPort, 'main-to-bg');
|
|
16
17
|
const markTimingInternal = createMarkTimingInternal(backgroundThreadRpc);
|
|
17
18
|
const postTimingFlags = backgroundThreadRpc.createCall(postTimingFlagsEndpoint);
|
|
18
19
|
const backgroundStart = backgroundThreadRpc.createCall(BackgroundThreadStartEndpoint);
|
|
19
|
-
const dispatchCoreContextEvent = backgroundThreadRpc.createCall(dispatchCoreContextEventEndpoint);
|
|
20
20
|
const publishEvent = backgroundThreadRpc.createCall(publishEventEndpoint);
|
|
21
21
|
const publicComponentEvent = backgroundThreadRpc.createCall(publicComponentEventEndpoint);
|
|
22
22
|
const postExposure = backgroundThreadRpc.createCall(postExposureEndpoint);
|
|
@@ -38,7 +38,13 @@ export function startMainThread(uiThreadPort, backgroundThreadPort) {
|
|
|
38
38
|
},
|
|
39
39
|
});
|
|
40
40
|
uiThreadRpc.registerHandler(postOffscreenEventEndpoint, docu[_onEvent]);
|
|
41
|
+
const jsContext = new LynxCrossThreadContext({
|
|
42
|
+
rpc: backgroundThreadRpc,
|
|
43
|
+
receiveEventEndpoint: dispatchJSContextOnMainThreadEndpoint,
|
|
44
|
+
sendEventEndpoint: dispatchCoreContextOnBackgroundEndpoint,
|
|
45
|
+
});
|
|
41
46
|
const runtime = new MainThreadRuntime({
|
|
47
|
+
jsContext,
|
|
42
48
|
tagMap,
|
|
43
49
|
browserConfig,
|
|
44
50
|
customSections,
|
|
@@ -76,7 +82,10 @@ export function startMainThread(uiThreadPort, backgroundThreadPort) {
|
|
|
76
82
|
docu.commit();
|
|
77
83
|
if (isFp) {
|
|
78
84
|
isFp = false;
|
|
79
|
-
|
|
85
|
+
jsContext.dispatchEvent({
|
|
86
|
+
type: '__OnNativeAppReady',
|
|
87
|
+
data: undefined,
|
|
88
|
+
});
|
|
80
89
|
}
|
|
81
90
|
markTimingInternal('layout_start', pipelineId);
|
|
82
91
|
markTimingInternal('ui_operation_flush_start', pipelineId);
|
|
@@ -88,7 +97,10 @@ export function startMainThread(uiThreadPort, backgroundThreadPort) {
|
|
|
88
97
|
},
|
|
89
98
|
_ReportError: reportError,
|
|
90
99
|
__OnLifecycleEvent: (data) => {
|
|
91
|
-
|
|
100
|
+
jsContext.dispatchEvent({
|
|
101
|
+
type: '__OnLifecycleEvent',
|
|
102
|
+
data,
|
|
103
|
+
});
|
|
92
104
|
},
|
|
93
105
|
/**
|
|
94
106
|
* Note :
|
|
@@ -103,6 +115,7 @@ export function startMainThread(uiThreadPort, backgroundThreadPort) {
|
|
|
103
115
|
}).globalThis;
|
|
104
116
|
markTimingInternal('decode_end');
|
|
105
117
|
entry(runtime);
|
|
118
|
+
jsContext.__start(); // start the jsContext after the runtime is created
|
|
106
119
|
});
|
|
107
120
|
}
|
|
108
121
|
//# sourceMappingURL=startMainThread.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/web-worker-runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [],
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@lynx-js/offscreen-document": "0.0.0",
|
|
26
|
-
"@lynx-js/web-constants": "0.
|
|
27
|
-
"@lynx-js/web-mainthread-apis": "0.
|
|
28
|
-
"@lynx-js/web-worker-rpc": "0.
|
|
26
|
+
"@lynx-js/web-constants": "0.12.0",
|
|
27
|
+
"@lynx-js/web-mainthread-apis": "0.12.0",
|
|
28
|
+
"@lynx-js/web-worker-rpc": "0.12.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@lynx-js/lynx-core": "0.1.2"
|