Electron 渲染進程與渲染進程之間的實時通信 (實時觸發及接收消息)

1、首先在渲染進程A裏面獲取到所有的窗口id信息,然後給所有的窗口發送事件

remote.webContents.getAllWebContents().forEach((item,index)=>{
    if(remote.BrowserWindow.fromId(item.id) && remote.BrowserWindow.fromId(item.id).webContents){
        remote.BrowserWindow.fromId(item.id).webContents.send('to-render-all', "datainfo");
    }
});

 

2、在所需要接收內容的渲染進程裏面 ,通過ipcRenderer.on兼容,即可實時收到消息

ipcRenderer.on('to-render-all', (event, arg) => {
      console.log(999999999,arg)
});

交流

可添加qq羣共同進階學習: 進軍全棧工程師疑難解  羣號:   856402057

我是老禮,公衆號「進軍全棧攻城獅」作者 ,對前端技術保持學習愛好者。我會經常分享自己所學所看的乾貨,在進階的路上,共勉!

                                                  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章