Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

electron-ipc-promise

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electron-ipc-promise

electron ipc promise

  • 0.1.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

/*
 * -- in main.js
 */
var ipcMain = require('electron').ipcMain;
var ipcPromise = require('electron-ipc-promise').mainHost();

// create your new BrowserWindow before initializing ipcMain
var ipc = ipcPromise.ipcMain(ipcMain, mainWindow.webContents);

ipc.onAsk(function (cmd, args) {
  return {
    data: cmd + ' done',
    err: null
  };
});

ipc.ask('COMMAND', args);


/*
 * -- in renderer.js
 */
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


/*
 * -- in renderer.js
 */
var ipcPromise = require('electron-ipc-promise').guestHost();

// get the webview reference before initializing ipcHost
var ipc = ipcPromise.ipcHost(webview);

ipc.onAsk(function (cmd, args) {
  return {
    data: cmd + ' done',
    err: null
  };
});

ipc.ask('COMMAND', args);


/*
 * -- in webview.js
 */
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

// pass a uid to initialize function

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

Keywords

FAQs

Package last updated on 08 Dec 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc