electron-renderer-to-renderer-bridge

1.1.0 • Public • Published

electron-renderer-to-renderer-bridge

electron-renderer-to-renderer-bridge can helps complete MessagePort access in 3 steps, making it easier to realize communication between independent html windows.

install

npm install electron-renderer-to-renderer-bridge    

Useage

const { R2rBridgeRenderer, R2rBridgeMain } = require("electron-renderer-to-renderer-bridge");
  • main process
// main.js
R2rBridgeMain.init(clientWindow, serviceWindow); // BrowserWindow register
  • client renderer page
// preload_client.js
const port = await R2rBridgeRenderer.getClientPort(); // return a MessgePort

// then process MessagePort
// port.postMessage("hello service,wait reply");
// port.onmessage = (ev) => {
//   console.log("[service reply]:", ev.data);
// };
// preload_service.js
const port = await R2rBridgeRenderer.getServicePort(); // return a MessgePort

// then process MessagePort
// port.onmessage = (ev) => {
//   console.log("[from client message]:", ev.data);
//   port.postMessage("this message is from service!");
// };
// port.start();

Snapshot

1

Link

message-ports
Ipc

Package Sidebar

Install

npm i electron-renderer-to-renderer-bridge

Weekly Downloads

0

Version

1.1.0

License

ISC

Unpacked Size

236 kB

Total Files

10

Last publish

Collaborators

  • zhujm