Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

Electronでレンダラプロセス同士のIPC

More than 1 year has passed since last update.

ズバリ

Renderer1
const ipcRenderer= require("electron").ipcRenderer;
ipcRenderer.send("message", body);
Renderer2
const ipcMain = require("electron").remote.ipcMain;
ipcMain.on("message", (event, body)=>{...});

レンダラプロセス => メインプロセス
メインプロセス => レンダラプロセス
これはよくやるのですが。

レンダラプロセス => レンダラプロセス
をやろうとして躓いたので備忘録。

NG集

Renderer1
const ipcRenderer= require("electron").ipcRenderer;
ipcRenderer.send("message", body);
Renderer2
const ipcRenderer= require("electron").ipcRenderer;
ipcRenderer.on("message", (event, body)=>{...});

チャネルが同じならipcRenderer同士でもワンチャン...
しかし世の中そんなに甘くは無かった。

Renderer1
const ipcRenderer= require("electron").ipcRenderer;
ipcRenderer.send("message-to-main", body);
Main
const ipcRenderer= require("electron").ipcMain;
ipcMain.on("message-to-main", (event, body)=>{
    event.sender.send("message-to-renderer2", body);
});
Renderer2
const ipcRenderer= require("electron").ipcrenderer;
ipcRenderer.on("message-to-renderer2", (event, body)=>{...});

メインプロセスをリレーさせる暴挙に出るも、折り返せず失敗。

Renderer1
const ipcRenderer= require("electron").ipcRenderer;
ipcRenderer.send("message", body);
Renderer2
const ipcRenderer= require("electron").ipcMain;
ipcMain.on("message", (event, body)=>{...});

Electron「ipcMain?そんなモジュールねーよ」

ここでBrowserWindowの存在を思い出して、受信側をremote経由でipcMainにしたら行けましたとさ。

dojyorin
独学でJavaScriptとC++やってます。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away