function to be implemented: click the button on the
page 1 (rendering process 1) to send the event to the main process. After the main process successfully receives the event, it sends the event event through mainWindow.webContents.send. Listen to the event, through the ipcRender.on method in page 2 (rendering process 2). When the event is received, the business processing starts.
problem:
the main process successfully received the event sent by page 1 (rendering process 1), and then sent to event event, page 2 (rendering process 2) via mainWindow.webContents.send in the main process and did not receive it.
Code:
Page 1 (rendering process 1):
const ipcRenderer = require("electron").ipcRenderer;
function playDanmu(){
ipcRenderer.send("sigPlayDanmu", "123456");
};
main process:
const ipcMain = require("electron").ipcMain;
ipcMain.on("sigPlayDanmu", (event, args) => {
console.log("sigPlayDanmu is captured");
mainWindow.webContents.send("ping", "pong");
});
Page 2 (rendering process 2):
<script>
require("electron").ipcRenderer.on("ping", (event, message) => {
...
})
</script>
is there something wrong with the posture?
so I would like to ask you, how does the main thread actively request the rendering thread to call the method of the rendering thread or trigger the event of the rendering thread?
Thank you!