open-index/open-npm huggingface dataset:
npm package: @rhoffmann/iframe-communicator
Description: communicates events between iframes (or any context)
Author: Richard Hoffmann
Latest version: 1.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

```javascript
  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
  }
```