1.0.4 • Published 1 year ago

@harmonia/app-client v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Harmonia - App Client

Harmonia packages allow communication between apps inside of iframes and their parent window.

@harmonia/app-client should be used inside the iframe to communicate with the parent window.

Installing

> npm install @harmonia/app-client

or

> yarn add @harmonia/app-client

Usage

Connecting

First of all, a connection to the HostApp needs to be completed.

 const Harmonia = require('@harmonia/app-client')
 const hostApp = await Harmonia.HostApp.connect()
  
 const payload = hostApp.initPayload

The connect() method will return a initPayload that may have required data to initiate the application.

:warning: Note that if there is no HostApp to connect, an error will be thrown. In case this is not desirable for you, you should use a try-catch to wrap Harmonia.HostApp.connect()

Communicating

Receivig Events

Use method on to listen to events sended from host app.

hostApp.on('init', (event) => {
  console.log(event)
})

Sending Events

To send events, use hostApp.publish(event).

hostApp.publish({
  type: 'my-event-type',
  data: {
    foo: {},
  },
})

:information_source: You can import and use NativeEventType to use Harmonia predefined event types, for example, type: NativeEventType.RESIZE

1.0.2

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

1.0.0-beta.7

1 year ago

1.0.0-beta.6

1 year ago

1.0.0-beta.5

1 year ago

1.0.0-beta.4

2 years ago

1.0.0-beta.3

2 years ago

1.0.0-beta.2

2 years ago