code-proxy

A debug tool to proxy js code execution from one browser to another.

npm install code-proxy
21 downloads in the last month

A Node.js tools that give the ability to execute JavaScript code in one client browser and to get the results in another. Based on HTTP (for static files and sync post requests) and WebSocket (for server-host communications) technologies. Supports CommonJS modules and can be used with Browserify on the client-side.

Scheme to illustrate base working principles: scheme

Installation

npm install code-proxy

Use

Start as a standalone server:

node server/main.js

Connect to an existing project:

require('code-proxy')();

// or it's possible to redefine default options

require('code-proxy')({
    portHttp   : 8800,
    portWs     : 8900,
    retryDelay : 100,
    retryLimit : 30,
    logging    : true
});

Examples

Host client (accepts requests, execute them and send back result of execution):

<script type="text/javascript" src="host.js"></script>
// default host/port/session
var proxy = new ProxyHost();

// prepare for guest call
localStorage.setItem('test', 'localStorage test string on the host');

// test func for remote exec
function doSomething ( param ) {
    return 'some host work with "' + param + '" is done';
}

Guest client (send requests to the host):

<script type="text/javascript" src="guest.js"></script>
// default host/port/session
var proxy = new ProxyGuest();

// examples
proxy.eval('1+1');
proxy.eval('window.navigator.userAgent');
proxy.json('screen');
proxy.call('localStorage.getItem', ['test'], 'localStorage');
proxy.call('doSomething', ['test data']);

Proxy server host/port and session name can be redefined on both host and guest:

var proxy = new ProxyGuest({
    host : '127.0.0.1',
    port : 8800,
    name : 'anonymous'
});

ProxyHost has some additional options: reconnect and reconnectInterval to automatically try to restore connection on disconnect every 5 seconds. It's active be default.

npm loves you