-
Notifications
You must be signed in to change notification settings - Fork 9
Windtalk API
Preet edited this page Apr 15, 2018
·
11 revisions
Load windtalk in both the windows/iframes
<script src="../dist/windtalk.min.js"></script>
This will set up a windtalk object in your namespace.
Or import the UMD module in your node project:
const windtalk = require('windtalk');
windtalk supports the following methods:
In the iframe/window call expose to expose an object/function to the other window.
target is the object/function to expose
endPoint (Optional) is the window that owns that object. Default value is 'self'. For most cases, you do not need to set this argument.
const color = {
red: 0,
green: 0,
blue: 0,
update: function () {
// update the ui
}
};
windtalk.expose(color);
function doAdd(a, b) {
retudn a + b;
}
windtalk.expose(doAdd);
Creates a proxy reference to the object/function exposed by the window (endPoint).
endPoint is the window that exposes an object/function.
const color = windtalk.link(iframe.contentWindow);
color.red = 200;
color.green = 150;
color.blue = 10;
color.update();
const doAdd = windtalk.link(win1);
let result = await doAdd(2, 3);
console.log(result); // 5
Check out the examples page.
If you have any questions/comments, add them to issues.
Or tweet me.