UNPKG

endpointjs

Version:

Endpoint.js enables modules within a web application to discover and use each other, whether that be on the same web page, other browser windows and tabs, iframes, servers and web workers in a reactive way by providing robust discovery, execution and stre

66 lines (55 loc) 2.23 kB
<html> <head></head> <body> <script type="text/javascript"> window.endpointLogLevel = 'trace'; </script> <script src="https://cdn.socket.io/socket.io-1.3.7.js" type="text/javascript"></script> <script src="../build/endpoint.demo.js" type="text/javascript"></script> <p>When the 'grunt demo' command is executed, it creates a child process with Endpoint.js, and establishes a connection between it and the Endpoint.js instance running on Express.js.</p> <p>The child process hosts a simple API that takes input and sends a reply. You can use this instance of Endpoint.js in your browser to execute a command directly to that child process via the instance in Express.</p> <p>Console messages will be output to the text box bellow. To see trace information, open the browser console.</p> <a href='#' onclick='createFacade()'>Step 1: create facade</a><br> <a href='#' onclick='callFacade()'>Step 2: call facade</a><br> <a href='#' onclick='closeFacade()'>Step 3: close facade</a><br> <textarea id='console' style='width: 1000px; height: 500px;'></textarea> <script type="text/javascript"> var sock = io(); var link = window.endpoint.getConfiguration().addLink({ linkId: 'server-connection', type: 'server', settings: { channel: 'endpointjs-default' } }); link.addSocket(sock); var facade; function createFacade() { facade = window.endpoint.createFacade('child-process-api', '1.0', { neighborhood: 'universal' }); facade.on('ready', function() { console.log('Facade is ready'); }); facade.on('closed', function() { console.log('Facade has closed'); }); console.log('Created Facade'); } function callFacade() { facade.getApi().getMessageFromChild('my input') .then(function(result) { console.log('got result: ' + result); }); } function closeFacade() { facade.close(); } console.log = function (message) { var cons = document.getElementById('console'); cons.innerHTML += message + '\n'; } </script> </body> </html>