ipcRenderer

An object that carries handle, invoke and remove methods to manage the asynchronous communication from the renderer to main process.


ipcRenderer.handle[channel / handler name]

Register the IPC handler for the given channel. The handler will be called whenever the ipcMain.invoke method is called with the same channel.


It can be simply used as the following example:


const { handle } = window.api

handle.getPing()

Where getPing is the name of the channel (handler) registered in the createInterprocess or createIpcSlice functions.


Also, you can pass a callback function to handle the request from the main process if you need to do something before sending the response:


const { handle, remove, invoke } = window.api

handle.getPing(async (_, { getPing, data }) => {
  // call the registered handler if needed
  const response = await getPing(_, data)

  await invoke.getPong('pong')

  remove.getPing()

  return 'The getPong ipc was removed'
})

ipcRenderer.invoke[channel / handler name]

Send a message to the main process and wait for the response if needed:


const { invoke } = window.api

const response = await invoke.getPong('pong')

console.log(response)

ipcRenderer.remove[channel / handler name]

Remove the listener from the renderer process:


const { remove } = window.api

remove.getPing()