Ionic, Electron and IPC


#1

Electron provides a way for users to access data via the use of ipc to communicate asynchronously between the main process to renderer process.

These methods are referred to as ipcMain and ipcRenderer and what I have done in my application is to grab data in ipcMain from Electron and I’m attempting to transfer it to Ionic via ipcRenderer.

The snippet of code from the Electron end looks something like this:

win = new BrowserWindows({
    width: 800,
    height: 600
})

let contents = win.webContents

contents.send("test_channel","ping")

Normally, you will be able to get the data in your renderer.js for Electron by doing this:

const {ipcRenderer} = electron;

ipcRenderer.on("test_channel",function(event,arg){
    console.log(arg); // This should print ping
}

What I am attempting to do is to transfer this data to Ionic, I ran a similar process like so:

    this.ws = electron.ipcRenderer.on("test_channel",function(event,arg){
        console.log(arg); // Does not print ping
    }

So, I was wondering whether or not anyone has any insight into making ipc work across Ionic and Electron? Also, if it is not possible can anyone direct me as to why?

Thank you very much.