📝 Simpilify the structure of API references.
This commit is contained in:
parent
fae3cf9a55
commit
5933947000
19 changed files with 26 additions and 26 deletions
45
docs/api/ipc-browser.md
Normal file
45
docs/api/ipc-browser.md
Normal file
|
@ -0,0 +1,45 @@
|
|||
# ipc (browser)
|
||||
|
||||
Handles asynchronous and synchronous message sent from web page.
|
||||
|
||||
The messages sent from web page 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(...)`.
|
||||
|
||||
An example of sending and handling messages:
|
||||
|
||||
```javascript
|
||||
// In browser.
|
||||
var ipc = require('ipc');
|
||||
ipc.on('asynchronous-message', function(event, arg) {
|
||||
console.log(arg); // prints "ping"
|
||||
event.sender.send('asynchronous-reply', 'pong');
|
||||
});
|
||||
|
||||
ipc.on('synchronous-message', function(event, arg) {
|
||||
console.log(arg); // prints "ping"
|
||||
event.returnValue = 'pong'.
|
||||
});
|
||||
```
|
||||
|
||||
```javascript
|
||||
// In web page.
|
||||
var ipc = require('ipc');
|
||||
console.log(ipc.sendSync('synchronous-message', 'ping')); // prints "pong"
|
||||
|
||||
ipc.on('asynchronous-reply', function(arg) {
|
||||
console.log(arg); // prints "pong"
|
||||
});
|
||||
ipc.send('asynchronous-message', 'ping');
|
||||
```
|
||||
|
||||
### Class: Event
|
||||
|
||||
## Event.returnValue
|
||||
|
||||
Assign to this to return an value to synchronous messages.
|
||||
|
||||
## Event.sender
|
||||
|
||||
The `WebContents` of the web page that has sent the message.
|
Loading…
Add table
Add a link
Reference in a new issue