2017-05-23 36 views
1

我知道如何使用ipcRenderer.send()ipcMain.on()從渲染進程向主進程發送事件。我也可以使用event.sender.send()將回復發回給渲染器進程,但是我怎麼能從主進程向所有渲染進程發送事件,更像廣播。從主進程到所有渲染進程的廣播事件電子

+0

這個問題已經問了你一小時之前:https://stackoverflow.com/questions/44126768/broadcasting-message-from-ipcmain-in-electron/44134535#44134535。它應該幫助你。 – KeitIG

+0

[ipcMain在電子廣播訊息]的可能重複(https://stackoverflow.com/questions/44126768/broadcasting-message-from-ipcmain-in-electron) – Mike

回答

2

您可以創建引用數組BrowserWindow情況下,當全球性的活動是必要的,你可以發送功能映射它,像這樣的例子:

let windows = []; 

let backgroundComputation = new BrowserWindow(options); 
let webInteractions = new BrowserWindow(different_options); 
let imageProcessing = new BrowserWindow(another_options); 

windows.push(backgroundComputation) 
windows.push(webInteractions) 
windows.push(imageProcessing) 

let sender = (message, windows) => 
     windows.map((ref) => ref.webContents.send('event_name', message)) 

這可能將是方便,如果你有一大堆他們。您還可以將選項alwaysOnTop:true中的標誌設置爲true,以便頂部的窗口保持爲true,以便其他任何窗口都會保留在下面。希望這可以幫助!