From: Jessica Lord Date: Thu, 27 Aug 2015 00:56:10 +0000 (-0700) Subject: First run t ipc-r X-Git-Tag: v0.31.2~12^2~3 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=a1f17069ec3a742bc83697c4bbf4c73a1a669834;p=electron.git First run t ipc-r --- diff --git a/docs/api/ipc-renderer.md b/docs/api/ipc-renderer.md index 3aee11d7..0d7b49ab 100644 --- a/docs/api/ipc-renderer.md +++ b/docs/api/ipc-renderer.md @@ -1,29 +1,41 @@ # ipc (renderer) The `ipc` module provides a few methods so you can send synchronous and -asynchronous messages to the main process, and also receive messages sent from -main process. If you want to make use of modules of main process from renderer +asynchronous messages from the render process (web page) to the main process. You can also receive messages returned from the main process. + +**Note**: If you want to make use of modules in the main process from the renderer process, you might consider using the [remote](remote.md) module. -See [ipc (main process)](ipc-main-process.md) for examples. +See [ipc (main process)](ipc-main-process.md) for code examples. + +## Methods + +The `ipc` module has the following methods for sending messages: + +**Note**: When using these methods to send a `message` you must also listen for it in the main process with [`ipc (main process)`](ipc-main-process.md). + +### `ipc.send(channel[, message])` + +* `channel` String - The event name. +* `message` (optional) + +Send a `message` (any type) to the main process asynchronously via a `channel`. The main process handles it by listening for the `channel` event with `ipc`. -## ipc.send(channel[, args...]) +### `ipc.sendSync(channel[, message])` -Send `args..` to the renderer via `channel` in asynchronous message, the main -process can handle it by listening to the `channel` event of `ipc` module. +* `channel` String - The event name. +* `message` (optional) -## ipc.sendSync(channel[, args...]) +Send a `message` (any type) to the main process synchronously via a `channel`. A result is returned from the main process. -Send `args..` to the renderer via `channel` in synchronous message, and returns -the result sent from main process. The main process can handle it by listening to -the `channel` event of `ipc` module, and returns by setting `event.returnValue`. +The main process handles it by listening for the `channel` event with `ipc` and replies by setting the `event.returnValue`. -**Note:** Usually developers should never use this API, since sending -synchronous message would block the whole renderer process. +**Note:** Sending a synchronous message will block the whole renderer process so +using this method is not recommended. -## ipc.sendToHost(channel[, args...]) +### `ipc.sendToHost(channel[, message])` -Like `ipc.send` but the message will be sent to the host page instead of the -main process. +* `channel` String - The event name. +* `message` (optional) -This is mainly used by the page in `` to communicate with host page. +Like `ipc.send` but the message will be sent to the host page in a `` instead of the main process.