Reputation: 523
I am working on an electron video player project and to stream video from a readable stream to HTML video-tag, I want to know is there any solution to send the HTTP request from the renderer process to main process and handle the request in main process.
Upvotes: 1
Views: 3056
Reputation: 1469
You could use the ipcMain
and ipcRenderer
APIs of Electron. You can find the full documentation here https://www.electronjs.org/docs/api/ipc-main
You will have a listener on the main process and a message will be sent from the renderer process after completing the HTTP request:
// main process
const { ipcMain } = require('electron');
ipcMain.on('request-done', (event, content) => {
// process the response, it is in 'content' argument
});
// renderer process
const { ipcRenderer } = require('electron');
await reponse = fetch(...);
await ipcRenderer.send('request-done', reponse);
Upvotes: 2