8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Posted at

ズバリ

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にしたら行けましたとさ。

8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?