Code Monkey home page Code Monkey logo

peerjs-rpc's Introduction

peerjs-rpc Build status Coverage 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

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', (answer) -> console.log(answer))
# => true

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

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

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', function(answer) {
    return console.log(answer);
});
// => true

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

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

MIT © Rolf Erik Lekang

peerjs-rpc's People

Contributors

relekang avatar

Watchers

James Cloos avatar Joe Young avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.