1.0.4 • Published 8 months ago

iframe-rpc-util v1.0.4

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

iframe-rpc-util

npm

RPC between cross-origin iframe using postMessage

Installation

$ npm install iframe-rpc-util

$ yarn add iframe-rpc-util

$ pnpm install iframe-rpc-util

Usage

Parent Iframe

<iframe src="xx" id="iframeNode"></iframe>
import iframeRpc from 'iframe-rpc-util'

// init rpc instance
const iframeProxy = iframeRpc('iframeNode')

// iframe init event
iframeProxy.onReady = (data) => {
    // get rpc register function
    iframeProxy.getKeys().then((data) => {
        console.log('parent getKeys', data)
    })

    // call children function
    iframeProxy.childrenFunc('parent params').then((data) => {
        console.log('parent', data)
    })
}

// register function
iframeProxy.parentFunc = (data) => {
    // return remote data
    return 'parent function'
}

Children Iframe

import iframeRpc from 'iframe-rpc-util'

const iframeProxy = iframeRpc()

// register function
iframeProxy.childrenFunc = (data) => {
    // return remote data
    return 'children function'
}

iframeProxy.parentFunc('children params').then((data) => {
    console.log('children', data)
})

If you like it, please star it

1.0.4

8 months ago

1.0.3

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago