Skip to content

compulim/electron-ipcmain-messageport

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

electron-ipcmain-messageport

npm version Build Status

Turns Electron IPCMain into MessagePort.

Background

Instead of learning/using different API for different communication channels, we should unite them into a single interface pattern, either MessagePort or WebSocket.

This package is expected to work in pair with electron-ipcrenderer-messageport.

How to use

const IPCMainMessagePort = require('electron-ipcmain-messageport');
const { BrowserWindow, ipcMain } = require('electron');
const window = new BrowserWindow();
const messagePort = new IPCMainMessagePort(ipcMain, window, 'channel_name');

messagePort.on('message', event => {
  // Could be either a string or Buffer
  console.log(event.data);
});

messagePort.postMessage('Hello, World!');

Note: to match the paradigm of MessagePort, we do not support synchronous messages and callbacks.

Contributions

Like us? Star us.

Want to make it better? File us an issue.

Don't like something you see? Submit a pull request.

About

Turns Electron IPCMain into HTML MessagePort

Resources

Stars

Watchers

Forks

Packages

No packages published