2.5.0 • Published 7 months ago

iframe-ipc v2.5.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

iframe-ipc

NPM Version NPM Downloads NPM License

跨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);

Example

click

2.5.0

7 months ago

2.4.1

1 year ago

2.4.0

1 year ago

2.3.0

1 year ago

2.2.0

1 year ago

2.1.1

1 year ago

2.1.0

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.1

1 year ago

0.0.0

1 year ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago