Electronic ipc connection between two windows

There is an ipc implementation for the electron, it is called ipcrenderer and ipcmain, they are intended for the main processing of the process, and it does not work for communication between two windows (even through an emitter instance).

I think with a real example it will be more clear ( https://github.com/linuxenko/usprited ). I would make a toolbar and a main window for two different windows. The only problem is the connection between the two windows, ipc is not working, have not tried postmessage yet. What can you recommend for this occasion? How or which eventemitter, implementation, to use for communication between windows of an electronic application?

+5
source share
1 answer

I think your choice of IPC method will depend on what data you need to share between windows and how you manage windows. For example, if you manage your windows from the main process, you can use the Main process as a central hub for sending messages using the Electron 'ipc' modules. If your windows know about each other, it might be better to exchange messages directly between them without going through the main process.

If you open one window from another using Electron window.open , you can then use postMessage in the window's proxy (in the child window, use window.opener.postMessage ) to send messages.

Of course, you can also open a socket between two windows or use any other form of IPC, especially if you need to transfer a lot of data. For simple messages and events, postMessage should be fine, though.

+1
source

Source: https://habr.com/ru/post/1245064/


All Articles