Electron IPC promise
It's a handy tool for electron ipc communication between ipcMain, ipcRender and webview.
Install
npm install electron-ipc-promise --save
Usage
ipc between ipcMain and ipcRenderer
var ipcMain = require('electron').ipcMain;
var ipcPromise = require('electron-ipc-promise').mainHost();
var ipc = ipcPromise.ipcMain(ipcMain, mainWindow.webContents);
ipc.onAsk(function (cmd, args) {
return {
data: cmd + ' done',
err: null
};
});
ipc.ask('COMMAND', args);
var ipcRenderer = require('electron').ipcRenderer;
var ipcPromise = require('electron-ipc-promise').mainHost();
var ipc = ipcPromise.ipcHost(ipcRenderer);
ipc.onAsk(function (cmd, args) {
return {
data: cmd + ' done',
err: null
};
});
ipc.ask('COMMAND', args);
ipc between ipcRenderer and Webview
var ipcPromise = require('electron-ipc-promise').guestHost();
var ipc = ipcPromise.ipcHost(webview);
ipc.onAsk(function (cmd, args) {
return {
data: cmd + ' done',
err: null
};
});
ipc.ask('COMMAND', args);
var ipcRenderer = require('electron').ipcRenderer;
var ipcPromise = require('electron-ipc-promise').guestHost();
var ipc = ipcPromise.ipcGuest(ipcRenderer);
ipc.onAsk(function (cmd, args) {
return {
data: cmd + ' done',
err: null
};
});
ipc.ask('COMMAND', args);
multiple channels
var ipcGH = require('electron-ipc-promise').guestHost('PAGE_1');
var ipcMH = require('electron-ipc-promise').mainHost('HOST_1');
TODO
- ipc pipe
- one renderer directly with another renderer)
- main directly with webview