feat(iframe-bridge): implement iframe communication bridge and language sync
This commit is contained in:
23
src/iframe/bridgeManager.ts
Normal file
23
src/iframe/bridgeManager.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import type { ChildApi } from '@teres/iframe-bridge';
|
||||
import logger from '@/utils/logger';
|
||||
|
||||
let childPromise: Promise<ChildApi> | null = null;
|
||||
|
||||
export function setChildPromise(promise: Promise<ChildApi>) {
|
||||
childPromise = promise;
|
||||
}
|
||||
|
||||
export function clearChildPromise() {
|
||||
childPromise = null;
|
||||
}
|
||||
|
||||
export async function changeChildLanguage(lng: string) {
|
||||
if (!childPromise) return;
|
||||
try {
|
||||
const child = await childPromise;
|
||||
// @ts-ignore
|
||||
await child?.changeLanguage?.(lng);
|
||||
} catch (err) {
|
||||
logger.warn('changeChildLanguage failed', err);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user