message-event-channel
An event driven fault tolerant library for communicating between contexts using MessageChannel.
Features
- Subscribe to and broadcast events
- Send and receive JSON
- Make requests that return a promise
Installation
Using npm:
npm install message-event-channel --save
Using cdn:
Including
;;
or
const mc = ;const connection = ;
or
Usage
Events
/parent.html
;;;connection.emit'my-event', ;frame.src = "./frame.html";
/frame.html
;;connection.on'my-event',;
Request
/parent.html
;;connection.request'some-data' .thenframe.src = "./frame.html";
/frame.html
;;connection.on'some-payload',;
Emit to all
/parent.html
;;;;;operator.emit'send-to-all';
Close connection
/parent.html
;const connection = frame;connection;
Options
targetOrigin: '*' // limit the connection to a particular origin (reccomended) onload: true // if the connection should be initialised by an onload event or manually using init() timeout: 2000 // default time it takes for requests to timeout debug: false // used to enable useful behind-the-scenes info connectionTimeout: 2000 // will trigger the CONNECTION_TIMEOUT event if a connection hasn't been established by this time, can be set to false. clientInitiates: false // Server setting - waits for a init() trigger from the child frame before initiating.