1.4.0 • Published 7 years ago

@rhoffmann/iframe-communicator v1.4.0

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

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
  }
1.4.0

7 years ago

1.3.6

7 years ago

1.3.5

7 years ago

1.3.4

7 years ago

1.3.3

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago