Onirix Embed SDK
This library acts as a wrapper of window.postMessage for simplifying communication with Onirix iframes.
Full documentation available at Onirix Docs.
Usage
Using a bundler (Webpack, Rollup):
- Install the dependency:
npm install @onirix/embed-sdk
- Import and use it within your code:
const iframeElement = document.getElementById("<iframe_element_id>");
const embedSDK = new OnirixEmbedSDK(iframeElement);
embedSDK.connect().then(() => {
// Ready to subscribe to events and/or execute actions
});
Using plain HTML
- Include the dependency within the HTML head tag:
<head>
...
<script src="https://unpkg.com/@onirix/embed-sdk@latest/dist/ox-embed-sdk.umd.js">
...
</head>
- Use it from any other script:
<script>
const iframeElement = document.getElementById("<iframe_element_id>");
const embedSDK = new OnirixEmbedSDK(iframeElement);
embedSDK.connect().then(() => {
// Ready to subscribe to events and/or execute actions
});
</script>
- As ESM modules:
import OnirixEmbedSDK from "https://unpkg.com/@onirix/embed-sdk@latest/dist/ox-embed-sdk.umd.js";
const embedSDK = new OnirixEmbedSDK();
await embedSDK.connect();
embedSDK.subscribe(OnirixEmbedSDK.Events.ELEMENT_CLICK, (params) => {
console.log('somebodey clicks me!', params);
});