Creates an EventBus to enable cross-origin communication.
import { crossOrigin } from '@paychex/platform-browser';
const bus = crossOrigin.bus({ url: 'http://some.other-domain.com' });
// listen for messages from some.other-domain.com
bus.on('some-message', async function handle(arg1, arg2) { ... });
// send messages to some.other-domain.com and process return values
await bus.fire('some-event', 'abc', 123)
.then((results) => { ... });
IMPORTANT! Message arguments must be serializable as JSON. If not, the fire
method will return a rejected Promise. For example:
await bus.fire('message', undefined); // throws error
await bus.fire('message', null); // okay
await bus.fire('message', { key: undefined }); // okay
Values used to customize the EventBus's behavior.
An EventBus that can be used to send messages between the two origins. The
bus will have a new method, dispose
, that can be used to tear down the connection.
Contains utilities to assist with cross-origin communication.
Importing