electron-ipc-plus
Improved IPC for Electron
Features
- Enhance IPC Programming Experience
- Allow sending ipc message to specific window
- Allow sending ipc request and waiting for the reply in callback function
Install
npm install --save electron-ipc-plus
Run The Example
npm start examples/${name}
Usage
Send request from main process to renderer process and wait for reply.
main process
const ipcPlusM = ; ipcPlusM;
renderer process
const ipcPlusR = ; ipcPlusR;
Send request from renderer process to main process and wait for reply.
renderer process
const ipcPlusR = ; ipcPlusR;
main process
const ipcPlusM = ; ipcPlusM;
FAQ
How can I know if an IPC is waiting for reply?
Just check if event.reply
exists:
ipcMain;
Can I reply a message for multiple times?
Only the first reply will be handled, after that the session will be closed and the rest of replies will be ignored.
What happen when the window closed and I still waiting the reply from it.
An error with the code 'EWINCLOSED'
will be sent to your reply handler.
ipcPlus;
What happen when the reply is timed out.
An error with the code 'ETIMEDOUT'
will be sent to your reply handler.
ipcPlus;
Known Issues
ipcPlus.sendToWin could leave wild sessions in main process when the window reload.
I try to solve this problem by the code below:
app;
The problem is 'did-navigate' will be triggerred at the first time we open the window and I disable the above solution and leave this to user. Currently the best way to solve it is wrapping your own reload function, and manually close all sessions in that wrapped function.
Different versions of electron-ipc-plus.
When running an Electron app that has several modules depends on different version of electron-ipc-plus
,
we will receive a warning message.
API Reference
License
MIT © 2017 Johnny Wu