1.4.0 • Published 7 years ago
@rhoffmann/iframe-communicator v1.4.0
iframe-communicator
TODO
write some sentences about:
can be used on both sides of the communication process.
both should be configured on the same namespace and with the same message protocol.
multiple instances with different namespaces / message formats are possible.
example
const communicator = require('@rhoffmann/iframe-communicator')({
commandSeparator: '$',
defaultInterval: 1000,
namespace: 'ifcomm',
origin: '*',
target: window.parent
});
// sender
communicator.send({
type: 'someMessage',
data: { 'some': 'value'}
});
// receiver
communicator.on('someMessage', (data) => {
console.log(data);
});
communicator.start(); // IMPORTANT: starts event listeners
api
communicator.on(messageType, fn(data))
communicator.off(messageType)
communicator.send(MsgObj | fn: MsgObj)
communicator.sendInterval(ID, MsgObj | fn: MsgObj, interval)
communicator.start();
start event handling on window
communicator.stop();
stop all intervals and remove listeners
MsgObj
{
type: string,
data: value | object
}