类:IpcMainServiceWorker
类:IpcMainServiceWorker
¥Class: IpcMainServiceWorker
从主进程异步通信到服务工作线程。
¥Communicate asynchronously from the main process to service workers.
进程:主进程
¥Process: Main
[!NOTE] 此 API 是
IpcMain的微妙变体 - 旨在与服务工作者进行通信。有关与 Web 框架通信,请查阅IpcMain文档。¥[!NOTE] This API is a subtle variation of
IpcMain—targeted for communicating with service workers. For communicating with web frames, consult theIpcMaindocumentation.
[!警告] Electron 的内置类无法在用户代码中进行子类化。更多信息,请参阅 常见问题解答。
¥[!WARNING] Electron's built-in classes cannot be subclassed in user code. For more information, see the FAQ.
实例方法
¥Instance Methods
ipcMainServiceWorker.on(channel, listener)
-
channel字符串¥
channelstring -
listener函数¥
listenerFunction-
...args任何[]¥
...argsany[]
监听 channel,当有新消息到达时,listener 将与 listener(event, args...) 一起调用。
¥Listens to channel, when a new message arrives listener would be called with
listener(event, args...).
ipcMainServiceWorker.once(channel, listener)
-
channel字符串¥
channelstring -
listener函数¥
listenerFunction-
...args任何[]¥
...argsany[]
为该事件添加一次性 listener 功能。仅当下次将消息发送到 channel 时才会调用此 listener,之后将其删除。
¥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字符串¥
channelstring -
listener函数¥
listenerFunction-
...args任何[]¥
...argsany[]
-
从指定 channel 的监听器数组中删除指定的 listener。
¥Removes the specified listener from the listener array for the specified
channel.
ipcMainServiceWorker.removeAllListeners([channel])
-
channel字符串(可选)¥
channelstring (optional)
删除指定 channel 的监听器。
¥Removes listeners of the specified channel.
ipcMainServiceWorker.handle(channel, listener)
-
channel字符串¥
channelstring -
listenerFunction<Promise<any> | any>-
...args任何[]¥
...argsany[]
ipcMainServiceWorker.handleOnce(channel, listener)
-
channel字符串¥
channelstring -
listenerFunction<Promise<any> | any>-
...args任何[]¥
...argsany[]
处理单个 invokeable IPC 消息,然后删除监听器。参见 ipcMainServiceWorker.handle(channel, listener)。
¥Handles a single invokeable IPC message, then removes the listener. See
ipcMainServiceWorker.handle(channel, listener).
ipcMainServiceWorker.removeHandler(channel)
-
channel字符串¥
channelstring
删除 channel 的任何处理程序(如果存在)。
¥Removes any handler for channel, if present.