@with/hey
v1.0.0
Published
My awesome typescript library
Downloads
4
Readme
@with/hey
Install
npm i @with/hey
Usage
In your parent window
import hey from '@with/hey'
const connection = hey({
isParent: true,
remoteWindow: iframe.contentWindow,
remoteOrigin: '*',
methods: {
helloFromParent( message ) {
return 'pong from parent'
}
}
})
// will wait until child emit `ready` event
await connection.waitFor( 'ready' )
await connection.callRemote( 'helloFromChild', 'ping' ) // -> pong
In your remote window(most likely a child iframe)
import hey from '@with/hey'
const connection = hey({
remoteWindow: window.parent,
remoteOrigin: '*',
methods: {
hello( message ) {
return 'world'
}
}
})
await connection.setMethod( 'helloFromChild', function helloFromChild( message ) {
return 'pong'
} )
connection.emit( 'ready' )
await connection.callRemote( 'helloFromParent', 'ping' ) // -> pong from parent
Modify
remoteOrigin
option for security purpose if needed
License
MIT © fengzilong