npm.io
1.0.2 • Published 8 years ago

bridle

Licence
ISC
Version
1.0.2
Deps
4
Size
811 kB
Vulns
2
Weekly
0

Bridle: Black magic Javascript RPC

Version npm Linux Build Coverage Status Known Vulnerabilities License

Installation

npm install --save bridle

Bridle allows exporting functions from a Node.js server and then calling them natively from a client (both Node and browsers are supported).

Remote functions will be ran on the server, with communication occurring using WebSocket transport. Local functions will be ran natively on the client as is.

Note: This project exists because it can, not because it should. The author takes no responsibility for any [mis]use.

Usage

Server:
const Bridle = require('bridle');

new Bridle.Server({
    port: 7777,
    localFunctions: {
        foo: () => {
            console.log('bar');
        }
    },
    remoteFunctions: {
        hello: (name) => 'Hello ' + name
    }
});
Client:
import {Client} from 'bridle';

const rpc = new Client();

rpc.connect('ws://localhost:7777')

    .then(functions => {

        functions.foo();

        functions.hello('world!').then(result => {
            console.log(result);
        }).catch(error => {
            console.log(error);
        });
    });

Output:

$ bar
$ Hello world!

Support

Tested in Node.js v6.10.0, Chrome 63

License

ISC

Keywords