Communicate asynchronously from the main process to service workers.
Process: Main
[!NOTE] This API is a subtle variation of
IpcMain
—targeted for communicating with service workers. For communicating with web frames, consult theIpcMain
documentation.
ipcMainServiceWorker.on(channel, listener)
channel
stringlistener
Function
event
IpcMainServiceWorkerEvent...args
any[]Listens to channel
, when a new message arrives listener
would be called with
listener(event, args...)
.
ipcMainServiceWorker.once(channel, listener)
channel
stringlistener
Function
event
IpcMainServiceWorkerEvent...args
any[]Adds a one time listener
function for the event. This listener
is invoked
only the next time a message is sent to channel
, after which it is removed.
ipcMainServiceWorker.removeListener(channel, listener)
channel
stringlistener
Function
...args
any[]Removes the specified listener
from the listener array for the specified
channel
.
ipcMainServiceWorker.removeAllListeners([channel])
channel
string (optional)Removes listeners of the specified channel
.
ipcMainServiceWorker.handle(channel, listener)
channel
stringlistener
Function<Promise<any> | any>
event
IpcMainServiceWorkerInvokeEvent...args
any[]ipcMainServiceWorker.handleOnce(channel, listener)
channel
stringlistener
Function<Promise<any> | any>
event
IpcMainServiceWorkerInvokeEvent...args
any[]Handles a single invoke
able IPC message, then removes the listener. See
ipcMainServiceWorker.handle(channel, listener)
.
ipcMainServiceWorker.removeHandler(channel)
channel
stringRemoves any handler for channel
, if present.