feat(iframe-bridge): implement iframe communication bridge and language sync
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { useEffect, useMemo, useRef } from 'react';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
import { createPenpalHostBridge } from '@teres/iframe-bridge';
|
||||
import { setChildPromise, clearChildPromise } from '@/iframe/bridgeManager';
|
||||
import logger from '@/utils/logger';
|
||||
|
||||
export default function RagflowAgentPage() {
|
||||
@@ -14,7 +15,7 @@ export default function RagflowAgentPage() {
|
||||
useEffect(() => {
|
||||
const el = iframeRef.current;
|
||||
if (!el) return;
|
||||
const { destroy } = createPenpalHostBridge({
|
||||
const { destroy, child } = createPenpalHostBridge({
|
||||
iframe: el,
|
||||
methods: {
|
||||
navigate: (to: string) => navigate(to),
|
||||
@@ -24,7 +25,11 @@ export default function RagflowAgentPage() {
|
||||
},
|
||||
},
|
||||
});
|
||||
return () => destroy();
|
||||
setChildPromise(child);
|
||||
return () => {
|
||||
clearChildPromise();
|
||||
destroy();
|
||||
};
|
||||
}, [navigate]);
|
||||
|
||||
// 如需兼容旧的 postMessage 事件,可保留以下监听;为了纯 Penpal,此处移除
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { useLocation, useNavigate } from 'react-router-dom';
|
||||
import { createPenpalHostBridge, toChildPath } from '@teres/iframe-bridge';
|
||||
import { setChildPromise, clearChildPromise } from '@/iframe/bridgeManager';
|
||||
|
||||
export default function RagflowIframePage() {
|
||||
const location = useLocation();
|
||||
@@ -13,7 +14,7 @@ export default function RagflowIframePage() {
|
||||
useEffect(() => {
|
||||
const el = iframeRef.current;
|
||||
if (!el) return;
|
||||
const { destroy } = createPenpalHostBridge({
|
||||
const { destroy, child } = createPenpalHostBridge({
|
||||
iframe: el,
|
||||
methods: {
|
||||
navigate: (to: string) => navigate(to),
|
||||
@@ -23,7 +24,11 @@ export default function RagflowIframePage() {
|
||||
},
|
||||
},
|
||||
});
|
||||
return () => destroy();
|
||||
setChildPromise(child);
|
||||
return () => {
|
||||
clearChildPromise();
|
||||
destroy();
|
||||
};
|
||||
}, [navigate, src]);
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user