All Projects → remotelib → remote-lib

remotelib / remote-lib

Licence: Apache-2.0 license
💫 Convert your JavaScript library to a remote service.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to remote-lib

FISCO-BCOS
FISCO BCOS是由微众牵头的金链盟主导研发、对外开源、安全可控的企业级金融区块链底层技术平台。 单链配置下,性能TPS可达万级。提供群组架构、并行计算、分布式存储、可插拔的共识机制、隐私保护算法、支持全链路国密算法等诸多特性。 经过多个机构、多个应用,长时间在生产环境中的实践检验,具备金融级的高性能、高可用性及高安全性。FISCO BCOS is a secure and reliable financial-grade open-source blockchain platform. The platform provides rich features including group architecture, cross-chain communication protoc…
Stars: ✭ 1,603 (+3907.5%)
Mutual labels:  p2p, rpc
Slacker
Transparent, non-incursive RPC by clojure and for clojure
Stars: ✭ 316 (+690%)
Mutual labels:  remote, rpc
Sharer
Arduino & .NET serial communication library to read/write variables and remote call functions using the Sharer protocol. Works on Windows, Linux and MacOS.
Stars: ✭ 21 (-47.5%)
Mutual labels:  remote, rpc
Client
An alternative Polkadot Runtime Environment implementation acting as a full-node (excluding block production for validators) for syncing with Substrate-based chains.
Stars: ✭ 82 (+105%)
Mutual labels:  p2p, rpc
SpyGlass
Remote process hooking library for .NET
Stars: ✭ 49 (+22.5%)
Mutual labels:  remote
workshop-todo-dapp
A workshop into adding realtime collaboration in a typical To-do app
Stars: ✭ 29 (-27.5%)
Mutual labels:  p2p
rdoc
Conflict-free replicated JSON implementation in native Go
Stars: ✭ 76 (+90%)
Mutual labels:  p2p
squeaknode
Peer-to-peer status feed 📜 with posts unlocked by Lightning ⚡
Stars: ✭ 29 (-27.5%)
Mutual labels:  p2p
viddist
[not functional] A completely decentralized alternative to e.g. YouTube
Stars: ✭ 22 (-45%)
Mutual labels:  p2p
eval-estree-expression
Safely evaluate JavaScript (estree) expressions, sync and async.
Stars: ✭ 22 (-45%)
Mutual labels:  context
cypherpoker.js
An open source peer-to-peer poker platform with cryptocurrency integration written in JavaScript.
Stars: ✭ 72 (+80%)
Mutual labels:  p2p
bittensor
Internet-scale Neural Networks
Stars: ✭ 97 (+142.5%)
Mutual labels:  p2p
gobyte
GoByte Core - GBX
Stars: ✭ 35 (-12.5%)
Mutual labels:  p2p
InterProcessCommunication
Inter-process Communication
Stars: ✭ 11 (-72.5%)
Mutual labels:  rpc
zerorpc-dotnet
A .NET implementation of ZeroRPC
Stars: ✭ 21 (-47.5%)
Mutual labels:  rpc
hprose-as3
Hprose for ActionScript 3.0
Stars: ✭ 18 (-55%)
Mutual labels:  rpc
pace
Remote Access Tool for Windows.
Stars: ✭ 68 (+70%)
Mutual labels:  remote
irmin-rpc
RPC client/server for Irmin
Stars: ✭ 20 (-50%)
Mutual labels:  rpc
c-toxcore
The future of online communications.
Stars: ✭ 1,730 (+4225%)
Mutual labels:  p2p
WinRAT
(Windows/Linux/Mac) Remote Administration Tool
Stars: ✭ 35 (-12.5%)
Mutual labels:  remote


RemoteLib
RemoteLib

Convert your JavaScript library to a remote service 💫.

View On NPM Build Status Dependency Status codecov License


RemoteLib is a library that can be shared remotely with other peers without worrying for API interfaces or RPC integration. Using only a Duplex stream, such as TCP socket, WebSocket or even WebRTC DataChannel, your users will be able to use your code remotely exactly as if it's local library. This, including calling functions with callbacks, Promises, class inheritance, getters and setters support and more. See usage for some examples.

Is it kind of RPC?

No. RemoteLib is based on remote-context and won't just proxying your functions. Instead, you have an entirely shared context between two remote peers. See Features for more details:

Features

  • Use RemoteLib on node.js & on the browser (just use browserify or webpack to create a bundle).
  • Pure Javascript (Using ES6 Proxy).
  • Seamless interface (your library will be proxies AS IS to the users remotely!).
  • Proxy anything - from functions and object, to classes and Promises and even Symbols!
  • Builtin support for Promises - Resolve any path on the remote object via the RemoteProxy interface.
  • Builtin support for class inheritance - Your user can use instanceof with the proxyied objects.
  • Use any communication method - connect using simple Stream interface (WebSocket or WebRTC implementation available).
  • Serve multiple peers in parallel.
  • Use RemoteLib for P2P projects (via the remote-context library).

Install

npm install remote-lib

Ways to help

  • Join us in Gitter to help with development or to hang out with some mad science hackers :)
  • Create a new issue to report bugs
  • Fix an issue. RemoteLib is an OPEN Open Source Project!

Getting Started

Simple "Hello World" library

Create a context and a server:

const net = require('net');
const { Library } = require('remote-lib');

// Create the library context
const library = new Library({
  hello: 'World!',
});

// Create a server and serve each client the context remotely
const server = net.createServer(socket => {
  library.serve(socket);
});

// Bind on port 3000
server.listen(3000);

On the client side, we just need to connect to the server an create our remote library. Notice that the server and the client sharing only a single socket without any knowledge of the server library format. You can easily replace the socket it with WebSocket or even WebRTC DataChannel.

const net = require('net');
const { RemoteLibrary } = require('remote-lib');

// Connect to the server and get a stream
const socket = net.createConnection(3000);

// Create the remote library
const remoteLibrary = new RemoteLibrary(socket);

// Get the remote "hello" value
remoteLibrary.hello.then(value => {
  // value === 'World!'
});

Calling remote functions

RemoteLib supporting calling remote functions as well:

// On the server:
const library = new Library({
  // Simple functions
  foo() {
     return 'bar';
  },
  
  // Async functions
  getData: () =>
    new Promise(resolve =>
      setTimeout(() => resolve({ data: 'Tada!' }), 100),
    ),
  
  // Functions with callbacks
  loadInfo: callback => {
    setTimeout(callback(123), 200); // call callback after 200ms
  },
  
  // Functions of functions
  sum: x => y => x + y,
});
// On the client:
remoteLibrary.foo().then(value => {
  // value === 'bar' 
});

// Promises already handled for you 
remoteLibrary.getData().then(value => {
  // value == { data: 'Tada!' }
});

// Send callback as first parameter
remoteLibrary.loadInfo(value => {
  // value === 123
}).catch(err => {
  // catch any errors while calling loadInfo()
});

remoteLibrary.sum(5).then(async sum2 => {
  await sum2(2); // 7 
});

// You can even speed things up by using the virtual-path promise:
remoteLibrary.sum(3)(2).then(value => {
  // value === 5 
});

Using remote classes

Use can use build-in classes or create one by your own:

// On the server
class MyClass {
  constructor(i) {
    this.i = i;
  }
  
  inc() {
    this.i += 1;
    return this.i;
  }
}

const library = new Library({
  myClass: new MyClass(5),

  // native ES6 Set class instance
  myThings: new Set(['car', 'keys', 'pizza']),
});
// On the client:
remoteLibrary.myClass.then(async myClass => {
  // myClass.i === 5
                
  // Call methods with async promises
  await myClass.inc(); // 6
  // myClass.i === 6 
});

remoteLibrary.myThings.then(async myThings => {
  myThings instanceof Set; // true
    
  // Access cached getters instantly
  myThings.size; // 3

  await myThings.has('keys'); // true
  await myThings.has('cat'); // false

  await myThings.add('dog');
  await myThings.has('dog'); // true
});

Handling errors

RemoteLib catch all the errors for you and deliver them back to the user as-if they happens on the client:

// On the server:
const library = new Library({
  doNotCallMe() {
     throw ReferenceError('I told you! :)');
  },
});
// On the client:
remoteLibrary.doNotCallMe().catch(err => {
  err instanceof ReferenceError; // true
  err.message; // "I told you! :)"
});

remoteLibrary.notExistsFunction().catch(err => {
  err instanceof TypeError; // true
  err.message; // "notExistsFunction is not a function"
});

API Reference

Remote-lib is build with many small sub-packages, each package implement a small part of this library. You can read here the full API Reference.

module version description
remote-lib view on npm A high level API for creating remote libraries.
remote-context view on npm The core of remote-lib, creating and serving remote context.
remote-environment view on npm A shared environment context between remote peers.
remote-instance view on npm A stream transformer that can parse and construct instances remotely.
remote-protocol view on npm The core of remote-context protocol.
reference-context view on npm Virtual context implementation on vanilla Javascript.

License

© 2017 Moshe Simantov

Licensed under the Apache License, Version 2.0.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].