iframe-ipc
v2.4.1
Published
iframe ipc
Downloads
21
Readme
iframe-ipc
跨iframe通讯,对齐promise调用体验
Install
npm install iframe-ipc --save
Usage
支持promise编程
import { IframeIPC } from 'iframe-ipc';
const iframeIpc = new IframeIPC('namespace');
const serverApi = iframeIpc.defServerAPI('api123', async (args: number): Promise<string> => {
return '' + args;
});
// top 外层 ifreame
iframeIpc.initFrameServer();
// client 内层 iframe
serverApi(1234).then((result) => console.log(result));
支持传递回调函数
import { IframeIPC } from 'iframe-ipc';
const iframeIpc = new IframeIPC('namespace');
const funcid = iframeIpc.defTempAPI((info, arg1) => {
// info 中有onmessage的event对象
});
const serverApi2 = iframeIpc.defServerAPIExt('serverApi2', async function({ handlers }, arg11) {
// hanlders 中有使用funcid解析后额函数
const ret = await handlers[arg11.click_funcid](arg22);
// ...
});
serverApi2({ funcids: [funcid] }, arg11);