類別:IpcMainServiceWorker
類別:IpcMainServiceWorker
從主程序非同步地與服務工作者溝通。
程序:主程序
資訊
此 API 是 IpcMain
的細微變化版本——目標是用於與服務工作者溝通。若要與網頁框架溝通,請查閱 IpcMain
文件。
實例方法
ipcMainServiceWorker.on(channel, listener)
channel
字串listener
函數event
IpcMainServiceWorkerEvent...args
任何[]
監聽 channel
,當新訊息到達時,將會呼叫 listener
,並帶有 listener(event, args...)
。
ipcMainServiceWorker.once(channel, listener)
channel
字串listener
函數event
IpcMainServiceWorkerEvent...args
任何[]
為事件新增一次性的 listener
函數。此 listener
只會在下次訊息傳送到 channel
時調用一次,之後便會移除。
ipcMainServiceWorker.removeListener(channel, listener)
channel
字串listener
函數...args
任何[]
從指定 channel
的監聽器陣列中移除指定的 listener
。
ipcMainServiceWorker.removeAllListeners([channel])
channel
字串 (選用)
移除指定 channel
的所有監聽器。
ipcMainServiceWorker.handle(channel, listener)
channel
字串listener
函數<Promise<any> | any>event
IpcMainServiceWorkerInvokeEvent...args
任何[]
ipcMainServiceWorker.handleOnce(channel, listener)
channel
字串listener
函數<Promise<any> | any>event
IpcMainServiceWorkerInvokeEvent...args
任何[]
處理單次可 invoke
的 IPC 訊息,然後移除監聽器。請參閱 ipcMainServiceWorker.handle(channel, listener)
。
ipcMainServiceWorker.removeHandler(channel)
channel
字串
移除 channel
的任何處理器 (如果存在)。