|
1 | 1 | # ipcMain |
2 | 2 |
|
3 | | -The `ipcMain` module, when used in the main process, handles asynchronous and |
4 | | -synchronous messages sent from a renderer process (web page). Messages sent from |
5 | | -a renderer will be emitted to this module. |
| 3 | +The `ipcMain` module is an instance of the |
| 4 | +[EventEmitter](https://nodejs.org/api/events.html) class. When used in the main |
| 5 | +process, it handles asynchronous and synchronous messages sent from a renderer |
| 6 | +process (web page). Messages sent from a renderer will be emitted to this |
| 7 | +module. |
6 | 8 |
|
7 | 9 | ## Sending Messages |
8 | 10 |
|
@@ -54,6 +56,28 @@ The `ipcMain` module has the following method to listen for events: |
54 | 56 | When the event occurs the `callback` is called with an `event` object and a |
55 | 57 | message, `arg`. |
56 | 58 |
|
| 59 | +Once done listening for messages, if you longer want to activate this callback |
| 60 | +and for whatever reason can't merely stop sending messages on the channel, you |
| 61 | +can use: |
| 62 | + |
| 63 | +### `ipcMain.removeListener(channel, callback)` |
| 64 | + |
| 65 | +* `channel` String - The event name. |
| 66 | +* `callback` Function - The reference to the same function that you used for |
| 67 | + `ipcMain.on(channel, callback)` |
| 68 | + |
| 69 | +Alternatively, if you don't have access to the same callback, you can use: |
| 70 | + |
| 71 | +### `ipcMain.removeAllListeners(channel)` |
| 72 | + |
| 73 | +* `channel` String - The event name. |
| 74 | + |
| 75 | +This has the expected effect of removing *all* handlers to this ipc channel. |
| 76 | + |
| 77 | +Because of this class' inheritance from the `EventEmitter` node class, you can |
| 78 | +also use `ipcMain.once(channel, callback)` to fire handlers meant to occur only |
| 79 | +once, as in, they won't be activated after one call of `callback` |
| 80 | + |
57 | 81 | ## IPC Event |
58 | 82 |
|
59 | 83 | The `event` object passed to the `callback` has the following methods: |
|
0 commit comments