Send data from main process to renderer


Hey! How to send data from main process to renderer process?
My main process getting data from websockets and processes it. Sometimes I need to send these data to renderer process and show.



You use the ipcMain and ipcRenderer modules.


I cant emit event from ipcMain like ipcRenderer.send(channel[, arg1][, arg2][, ...])
I this case I have to call ipcMain from renderer, but have no event in renderer to call ipcMain. Is there some function like ipcRenderer.send, but in ipcMain?


You use ipcRenderer.send() to send data from the renderer process to the main process. Once the main process has a target, as demonstrated in the first example on the ipcMain documentation page, then you can send a signal back using the .send() method on that target.

If your app is only using one renderer process, then you can easily have it initialize a connection and have the main process store the resulting object somewhere that you can call it easily.