Function
forwardSharedEvent
(
eventName: string,
processPayload?: (payload: any) => Promise<{ type: string; payload: any }>
)
Source from the content-addressed store, hash-verified
| 4 | * 转发事件 |
| 5 | */ |
| 6 | export function forwardSharedEvent( |
| 7 | eventName: string, |
| 8 | processPayload?: (payload: any) => Promise<{ type: string; payload: any }> |
| 9 | ) { |
| 10 | if (!(window as any).ReactNativeWebView) { |
| 11 | return; |
| 12 | } |
| 13 | |
| 14 | sharedEvent.on(eventName, async (payload: any) => { |
| 15 | let type = eventName; |
| 16 | if (processPayload) { |
| 17 | const res = await processPayload(payload); |
| 18 | if (!res) { |
| 19 | // Skip if res is undefined |
| 20 | return; |
| 21 | } |
| 22 | |
| 23 | payload = res.payload; |
| 24 | type = res.type; |
| 25 | } |
| 26 | |
| 27 | (window as any).ReactNativeWebView.postMessage( |
| 28 | JSON.stringify({ |
| 29 | _isTailchat: true, |
| 30 | type, |
| 31 | payload, |
| 32 | }) |
| 33 | ); |
| 34 | }); |
| 35 | } |
Tested by
no test coverage detected