Remote-context
Create a virtual context and share it remotely with other peers via ANY stream object 💫.
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 the core of remote-lib module.
Install
npm install remote-context
Usage
On the server
const net = ; // Get the context and the environmentconst Context = ;const envContext = ; // Create a new context under ES6 environment.// You can put any object, class or instance under the context and it will be proxied to the// remote peer automaticallyconst context = envContext // Static vars foo: 'bar' // Dynamic functions Math // Async functions // Classes and objects myThings: 'car' 'keys' 'pizza'; // Create a server and serve each client the context remotelyconst server = net; // Bind on port 3000server;
On the client
const net = ; // Get the context and the environmentconst Context = ;const envContext = ; // Connect to the server and get a streamconst socket = net; // Create the remote contextconst clientContext = envContext;const remoteContext = clientContext; // Get the remote "foo"remoteContext; // Run the remote function "getRandom"remoteContext; // Run the remote async function "getData"remoteContext; // Get remote instance set "myThings"remoteContext;
Supported Environments
Remote-context is currently supporting only limited number of environment contexts. To use an environment you should require it explicitly:
const envContext = ;
When ENV_NAME
is the required environment name.
Name | Status | Description |
---|---|---|
es6-unstable |
AVAILABLE | A development version of ES6 context. This environment consider unstable and may change over the versions. |
node6-unstable |
IN_DEVELOPMENT | This environment will include all Node.js version 6 context. This environment consider unstable and may change over the versions. |
API Reference
This module is a part of the remote-lib
library.
Here is the relevant documentation for this module:
© 2017 Moshe Simantov
Licensed under the Apache License, Version 2.0.