]> khamidou — GitHub mirrors - electron.git/commitdiff
First run at ipc-m-p edits
authorJessica Lord <jlord@github.com>
Thu, 27 Aug 2015 00:27:17 +0000 (17:27 -0700)
committerJessica Lord <jlord@github.com>
Thu, 27 Aug 2015 00:27:17 +0000 (17:27 -0700)
docs/api/ipc-main-process.md

index d558f7fb24d63e72c4845bf43ada82dcd47cfbc6..b29d56f6ba37f6bdd60c472700215326b8a217f7 100644 (file)
@@ -1,17 +1,19 @@
 # ipc (main process)
 
-Handles asynchronous and synchronous message sent from a renderer process (web
-page).
+The `ipc` module, when used in the main process, handles asynchronous and synchronous messages sent from a renderer process (web page). Messages sent from a renderer will be emitted to this module.
 
-The messages sent from a renderer would be emitted to this module, the event name
-is the `channel` when sending message. To reply a synchronous message, you need
-to set `event.returnValue`, to send an asynchronous back to the sender, you can
-use `event.sender.send(...)`.
+## Sending Messages
 
-It's also possible to send messages from main process to the renderer process,
-see [WebContents.send](browser-window.md#webcontentssendchannel-args) for more.
+It is also possible to send messages from the main process to the renderer
+process, see [WebContents.send](browser-window.md#webcontentssendchannel-args)
+for more information.
 
-An example of sending and handling messages:
+- When sending a message, the event name is the `channel`.
+- To reply a synchronous message, you need to set `event.returnValue`.
+- To send an asynchronous back to the sender, you can use `event.sender.send(...)`.
+
+An example of sending and handling messages between the render and main
+processes:
 
 ```javascript
 // In main process.
@@ -38,12 +40,34 @@ ipc.on('asynchronous-reply', function(arg) {
 ipc.send('asynchronous-message', 'ping');
 ```
 
-## Class: Event
+## Methods
+
+The `ipc` module has the following method:
+
+### `ipc.on(channel, callback)`
+
+* `channel` String - The event name.
+* `callback` Function
+
+When the event occurs the `callback` is called with an `event` object and a
+message, `arg`.
+
+## IPC Events
+
+The `event` object passed to the `callback` has the following methods:
+
+### `Event.returnValue`
+
+Set this to the value to be returned in a synchronous message.
+
+### `Event.sender`
 
-### Event.returnValue
+Returns the `WebContents` that sent the message.
 
-Assign to this to return an value to synchronous messages.
+### `Event.sender.send(channel, arg)`
 
-### Event.sender
+* `channel` String - The event name.
+* `arg`
 
-The `WebContents` that sent the message.
+This sends an asynchronous message back to the render process. The message,
+`arg`, can be any value.