Using only a Duplex stream such as TCP soocket, WebSocket or even WebRTC DataChannel with this library you can just share your code with other peers without worrying for API interfaces or RPC integration. Your users will be able to use your code remotely exactly as you write it. Including calling functions with callbacks, Promises, class inheritance and more.
This library is based on the remote-context module.
npm install remote-lib
On the server
const net = ;const Library = ;// You can put any object, class or instance under the context and it will be proxied to the// remote peer automaticallyconst library =// Static varsfoo: 'bar'// Dynamic functionsMath// Async functions// Classes and objectsmyThings: 'car' 'keys' 'pizza'// Functions that return functions'Yes!';// Create a server and serve each client the context remotelyconst server = net;// Bind on port 3000server;
On the client
const net = ;const RemoteLibrary = ;// Connect to the server and get a streamconst socket = net;// Create the remote libraryconst remoteLibrary = socket;// Get the remote "foo"remoteLibraryfoo;// Run the remote function "getRandom"remoteLibrary;// Run the remote async function "getData"remoteLibrary;// Get remote instance set "myThings"remoteLibrarymyThings;// Use RemotePromise virtual path:remoteLibrary;
This module is a part of the
Here is the relevant documentation for this module:
© 2017 Moshe Simantov
Licensed under the Apache License, Version 2.0.