Add sendToHost method
This commit is contained in:
parent
d46300587a
commit
a8f5a4e2d4
5 changed files with 17 additions and 7 deletions
|
@ -66,8 +66,8 @@ createGuest = (embedder, params) ->
|
||||||
guest.on event, (_, args...) ->
|
guest.on event, (_, args...) ->
|
||||||
embedder.send "ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-#{guest.viewInstanceId}", event, args...
|
embedder.send "ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-#{guest.viewInstanceId}", event, args...
|
||||||
|
|
||||||
# Dispatch guest's asynchronous IPC messages to embedder.
|
# Dispatch guest's IPC messages to embedder.
|
||||||
guest.on 'ipc-message', (_, channel, args...) ->
|
guest.on 'ipc-message-host', (_, channel, args...) ->
|
||||||
embedder.send "ATOM_SHELL_GUEST_VIEW_INTERNAL_IPC_MESSAGE-#{guest.viewInstanceId}", channel, args...
|
embedder.send "ATOM_SHELL_GUEST_VIEW_INTERNAL_IPC_MESSAGE-#{guest.viewInstanceId}", channel, args...
|
||||||
|
|
||||||
# Autosize.
|
# Autosize.
|
||||||
|
|
|
@ -16,6 +16,9 @@ class Ipc extends EventEmitter
|
||||||
sendSync: (args...) ->
|
sendSync: (args...) ->
|
||||||
JSON.parse ipc.sendSync('ipc-message-sync', [args...])
|
JSON.parse ipc.sendSync('ipc-message-sync', [args...])
|
||||||
|
|
||||||
|
sendToHost: (args...) ->
|
||||||
|
ipc.send 'ipc-message-host', [args...]
|
||||||
|
|
||||||
# Discarded
|
# Discarded
|
||||||
sendChannel: -> @send.apply this, arguments
|
sendChannel: -> @send.apply this, arguments
|
||||||
sendChannelSync: -> @sendSync.apply this, arguments
|
sendChannelSync: -> @sendSync.apply this, arguments
|
||||||
|
|
|
@ -20,3 +20,10 @@ the `channel` event of `ipc` module, and returns by setting `event.returnValue`.
|
||||||
|
|
||||||
**Note:** Usually developers should never use this API, since sending
|
**Note:** Usually developers should never use this API, since sending
|
||||||
synchronous message would block the whole web page.
|
synchronous message would block the whole web page.
|
||||||
|
|
||||||
|
## ipc.sendToHost(channel[, args...])
|
||||||
|
|
||||||
|
Like `ipc.send` but the message will be sent to the host page instead of the
|
||||||
|
browser process.
|
||||||
|
|
||||||
|
This is mainly used by the page in `<webview>` to communicate with host page.
|
||||||
|
|
|
@ -311,10 +311,10 @@ webview.addEventListener('close', function() {
|
||||||
* `channel` String
|
* `channel` String
|
||||||
* `args` Array
|
* `args` Array
|
||||||
|
|
||||||
Fired when the guest page has sent an asynchronous message to browser process.
|
Fired when the guest page has sent an asynchronous message to embedder page.
|
||||||
|
|
||||||
With `send` method and `ipc-message` event you can easily communicate between
|
With `sendToHost` method and `ipc-message` event you can easily communicate
|
||||||
guest page and embedder page:
|
between guest page and embedder page:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In embedder page.
|
// In embedder page.
|
||||||
|
@ -329,7 +329,7 @@ webview.send('ping');
|
||||||
// In guest page.
|
// In guest page.
|
||||||
var ipc = require('ipc');
|
var ipc = require('ipc');
|
||||||
ipc.on('ping', function() {
|
ipc.on('ping', function() {
|
||||||
ipc.send('pong');
|
ipc.sendToHost('pong');
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
2
spec/fixtures/pages/ipc-message.html
vendored
2
spec/fixtures/pages/ipc-message.html
vendored
|
@ -1,7 +1,7 @@
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<script type="text/javascript" charset="utf-8">
|
<script type="text/javascript" charset="utf-8">
|
||||||
require('ipc').send('channel', 'arg1', 'arg2');
|
require('ipc').sendToHost('channel', 'arg1', 'arg2');
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue