How does different widgets/windows communicate in openfin

318 Views Asked by At

As with openfin we can have separate widgets/windows opened separately, how do they communicate with each other ,searched a lot couldn't find anything on this, please help.

1

There are 1 best solutions below

0
Varun Goel On

You can share a context from main window to all its parent view using customContext

In Window (frame)

const me = fin.Window.getCurrentSync();
me.on('options-changed', async (event) => {
    if (event.diff.customContext) {
        const myViews = await me.getCurrentViews();
        const customContext = event.diff.customContext.newVal;
        myViews.forEach(v => {
            v.updateOptions({ customContext });
        });
    }
})

in View (content)

const me = fin.View.getCurrentSync();
const broadcastContext = async (customContext) => {
    const myWindow = await me.getCurrentWindow()
    await myWindow.updateOptions({ customContext })
};
const addContextListener = async (listener) => {
    await me.on('options-changed', (event) => {
        if (event.diff.customContext) {
            listener(event.diff.customContext.newVal);
        }
    });
}

References - https://cdn.openfin.co/docs/javascript/stable/tutorial-customContext.html