Valence
view release on metacpan or search on metacpan
asynchronous messaging between your application and the browser render
process. It does this over the standard input/standard output interface
provided by "valence.js". Without this support we would need to allocate
some kind of network port or unix socket and start something like an
AJAX or websocket server.
BROWSER TO PERL
In order for the browser to send a message to your perl code, it should
execute something like the following javascript code:
var ipcRenderer = require('electron').ipcRenderer;
ipcRenderer.send('my-event', 'my message');
On the perl side, you receive these messages like so:
my $ipcMain = $electron->attr('ipcMain');
$ipcMain->on('my-event' => sub {
my ($event, $message) = @_;
print $message; ## prints 'my message'
});
PERL TO BROWSER
Sending messages from perl to the browser should use code like this:
my $web_contents = $main_window->attr('webContents');
$web_contents->send('my-event' => 'my message');
And the javascript side can receive these messages like so:
var ipcRenderer = require('electron').ipcRenderer;
ipcRenderer.on('my-event', function(event, message) {
console.log(message); // prints 'my message'
});
IPC READY EVENTS
Before applications can send messages from perl to javascript, the
"ipcRenderer.on()" function must have been called to handle these
messages. If you try to send a message before this, it is likely that
the message will be delivered to the browser before the handler has been
installed so your message will be lost. Applications should have
lib/Valence.pm view on Meta::CPAN
=head1 IPC
An essential feature of valence is providing bi-directional, asynchronous messaging between your application and the browser render process. It does this over the standard input/standard output interface provided by C<valence.js>. Without this suppor...
=head2 BROWSER TO PERL
In order for the browser to send a message to your perl code, it should execute something like the following javascript code:
var ipcRenderer = require('electron').ipcRenderer;
ipcRenderer.send('my-event', 'my message');
On the perl side, you receive these messages like so:
my $ipcMain = $electron->attr('ipcMain');
$ipcMain->on('my-event' => sub {
my ($event, $message) = @_;
print $message; ## prints 'my message'
});
=head2 PERL TO BROWSER
Sending messages from perl to the browser should use code like this:
my $web_contents = $main_window->attr('webContents');
$web_contents->send('my-event' => 'my message');
And the javascript side can receive these messages like so:
var ipcRenderer = require('electron').ipcRenderer;
ipcRenderer.on('my-event', function(event, message) {
console.log(message); // prints 'my message'
});
=head2 IPC READY EVENTS
Before applications can send messages from perl to javascript, the C<ipcRenderer.on()> function must have been called to handle these messages. If you try to send a message before this, it is likely that the message will be delivered to the browser b...
For an example of how this is done, see the C<t/ipc.t> test and how the perl side subscribes to a C<ready> IPC message before attempting to send its C<ping> message, and how the C<t/static/remote.html> arranges for javascript to send the C<ready> mes...
t/static/remote.html view on Meta::CPAN
<html>
<body>
Remote test
<script>
var ipc = require('electron').ipcRenderer;
ipc.on('ping', function(event, message) {
ipc.send('pong', message + message);
});
ipc.send('ready');
</script>
</body>
</html>
valence/app/valence.js view on Meta::CPAN
//
// Copyright 2015-2016 Doug Hoyte
//
// This project is licensed under the 2-clause BSD license.
//
"use strict";
var readline = require('readline');
var object_map = {};
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
( run in 0.450 second using v1.01-cache-2.11-cpan-05444aca049 )