MCPcopy Create free account
hub / github.com/msgbyte/tailchat / forwardSharedEvent

Function forwardSharedEvent

client/web/plugins/com.msgbyte.env.rn/src/utils.ts:6–35  ·  view source on GitHub ↗
(
  eventName: string,
  processPayload?: (payload: any) => Promise<{ type: string; payload: any }>
)

Source from the content-addressed store, hash-verified

4 * 转发事件
5 */
6export 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}

Callers 1

index.tsxFile · 0.90

Calls 1

onMethod · 0.80

Tested by

no test coverage detected