@harmonia/app-client v1.0.4
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 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago