3.6.2 • Published 9 years ago

peerjs-rpc v3.6.2

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

peerjs-rpc Build status Coverage status Dependency Status

RPC module for WebRTC using peerjs.

Installation

npm install peerjs-rpc

Usage

ping(nodeId, callback)

Calls callback with either true or false.

attr(nodeId, attrName, callback)

Calls callback with (err, result), where result is the attribute in the given scope on the remote node.

invoke(nodeId, functionName, arguments, callback)

Calls callback with (err, result), where result is the value returned by the callback given to the function in the given scope on the remote node. arguments can be one argument or an array with arguments.

Examples

Javascript

var RPC = require("peerjs-rpc");
var scope = {
    'hi': function(name, callback) {
        return callback("hi there " + name + "!");
    },
    'answer': 42
};

var rpc = new RPC('node-id', scope);
var rpc2 = new RPC('another-node', scope);

rpc.ping('another-node')
  .then(function(answer) {
    return console.log(answer);
});
// => true

rpc.invoke('another-node', 'hi', ['R2'])
  .then(function(answer) {
    return console.log(answer);
});
// => hi there R2!

rpc.attr('another-node', 'answer')
  .then(function(answer) {
    return console.log(answer);
});
// => 42

Bailey.js

import peerjs-rpc as RPC

scope = {
  hi: (name, callback) -> callback("hi there #{name}!")
  answer: 42
}

rpc = new RPC('node-id', scope)
rpc2 = new RPC('another-node', scope) # running on another node

rpc.ping('another-node'.then((answer) -> console.log(answer))
# => true

rpc.invoke('another-node', 'hi', ['R2']).then((answer) -> console.log(answer))
# => hi there R2!

rpc.attr('another-node', 'answer').then((answer) -> console.log(answer))
# => 42

MIT © Rolf Erik Lekang

3.6.2

9 years ago

3.6.1

9 years ago

3.6.0

9 years ago

3.5.2

9 years ago

3.5.1

9 years ago

3.5.0

9 years ago

3.4.0

9 years ago

3.3.0

9 years ago

3.2.0

9 years ago

3.1.1

9 years ago

3.1.0

9 years ago

3.0.1

9 years ago

3.0.0

9 years ago

2.1.1

9 years ago

2.1.0

9 years ago

2.0.0

9 years ago

1.2.0

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago

0.3.0

9 years ago