- VrpcAdapter
Generates an adapter layer for existing code and enables further VRPC-based communication.
- VrpcAgent ⇐
EventEmitter
Agent capable of making existing code available to remote control by clients.
- VrpcClient ⇐
EventEmitter
Client capable of creating proxy objects and remotely calling functions as provided through one or more (distributed) agents.
- VrpcNative
Client capable of creating proxy classes and objects to locally call functions as provided through native addons.
- MetaData :
Object.<String, Func>
Associates meta data to any function
- Func
- Param :
Object
- Ret :
Object
Generates an adapter layer for existing code and enables further VRPC-based communication.
Kind: global class
- VrpcAdapter
- instance
- static
- .addPluginPath(dirPath, [maxLevel])
- .register(code, [options])
- .registerInstance(obj, options)
- .create(options) ⇒
Object
- .delete(instance) ⇒
Boolean
- .getInstance(instance) ⇒
Object
- .getAvailableClasses() ⇒
Array.<String>
- .getAvailableInstances(className) ⇒
Array.<String>
Event 'create'
Emitted on creation of shared instance
Kind: event emitted by VrpcAdapter
Properties
Name | Type | Description |
---|---|---|
className | String |
The class name of the create instance |
instance | String |
The instance name |
args | Array.<Any> |
The constructor arguments |
Event 'delete'
Emitted on deletion of shared instance
Kind: event emitted by VrpcAdapter
Properties
Name | Type | Description |
---|---|---|
className | String |
The class name of the deleted instance |
instance | String |
The instance name |
Automatically requires .js files for auto-registration.
Kind: static method of VrpcAdapter
Params
- dirPath
String
- Relative path to start the auto-registration from - [maxLevel]
Number
- Maximum search depth (default: unlimited)
Registers existing code and makes it (remotely) callable
Kind: static method of VrpcAdapter
Params
- code
Any
- Existing code to be registered, can be a class or function object or a relative path to a module - [options]
Object
- [.onlyPublic]
Boolean
= true
- If true, only registers functions that do not begin with an underscore - [.withNew]
Boolean
= true
- If true, class will be constructed using thenew
operator - [.schema]
Object
=
- If provided is used to validate ctor parameters (only works if registered code reflects a single class) - .jsdocPath
String
- if provided, parses documentation and provides it as meta information
- [.onlyPublic]
NOTE: This function currently only supports registration of classes (either when provided as object or when exported on the provided module path)
Registers an existing instance and make it (remotely) callable
Kind: static method of VrpcAdapter
Params
- obj
Object
- The instance to be registered - options
Object
- .className
String
- Class name of the instance - .instance
String
- Name of the instance - [.onlyPublic]
Boolean
= true
- If true, only registers functions that do not begin with an underscore - [.jsdocPath]
String
- if provided, parses documentation and provides it as meta information
- .className
Creates a new instance
Kind: static method of VrpcAdapter
Returns: Object
- The real instance (not a proxy!)
Params
- options
Object
- .className
String
- Name of the class which should be instantiated - [.instance]
String
- Name of the created instance. If not provided an id will be generated - [.args]
Array
- Positional arguments for the constructor call - [.isIsolated]
bool
= false
- If true the created instance will be visible only to the client who created it
- .className
Deletes an instance
Kind: static method of VrpcAdapter
Returns: Boolean
- True in case of success, false otherwise
Params
- instance
String
|Object
- Instance (name or object itself) to be deleted
Retrieves an existing instance by name
Kind: static method of VrpcAdapter
Returns: Object
- The real instance (not a proxy!)
Params
- instance
String
- Name of the instance to be acquired
Retrieves an array of all available classes (names only)
Kind: static method of VrpcAdapter
Returns: Array.<String>
- Array of class names
Provides the names of all currently running instances.
Kind: static method of VrpcAdapter
Returns: Array.<String>
- Array of instance names
Params
- className
String
- Name of class to retrieve the instances for
Agent capable of making existing code available to remote control by clients.
Kind: global class
Extends: EventEmitter
- VrpcAgent ⇐
EventEmitter
- new VrpcAgent(obj)
- instance
- .serve() ⇒
Promise
- .end([obj], [unregister]) ⇒
Promise
- .create(options) ⇒
Object
- "connect"
- "reconnect"
- "close"
- "offline"
- "error"
- "end"
- "clientGone"
- .serve() ⇒
- static
- .fromCommandline(defaults) ⇒
Agent
- .fromCommandline(defaults) ⇒
Constructs an agent instance
Params
- obj
Object
- [.username]
String
- MQTT username - [.password]
String
- MQTT password (if no token is provided) - [.token]
String
- Access token - [.domain]
String
= 'vrpc'
- The domain under which the agent-provided code is reachable - [.agent]
String
= '<user>-<pathId>@<hostname>-<platform>-js'
- This agent's name - [.broker]
String
= 'mqtts://vrpc.io:8883'
- Broker url in form:<scheme>://<host>:<port>
- [.log]
Object
= console
- Log object (must support debug, info, warn, and error level) - [.bestEffort]
String
= true
- If true, message will be sent with best effort, i.e. no caching if offline - [.version]
String
= ''
- The (user-defined) version of this agent - [.mqttClientId]
String
= '<generated()>'
- Explicitly set the mqtt client id.
- [.username]
Example
const agent = new Agent({
domain: 'vrpc'
agent: 'myAgent'
})
Starts the agent
The returned promise will only resolve once the agent is connected to the
broker. If the connection can't be established it will try connecting
forever. You may want to listen to the 'offline' (initial connect attempt
failed) or 'reconnect' (any further fail) event and call agent.end()
to
stop trying to connect and resolve the returned promise.
If the connection could not be established because of authorization failure, the 'error' event will be emitted.
Kind: instance method of VrpcAgent
Returns: Promise
- Resolves once connected or explicitly ended, never
rejects
Stops the agent
Kind: instance method of VrpcAgent
Returns: Promise
- Resolves when disconnected and ended
Params
- [obj]
Object
- [unregister]
Boolean
= false
- If true, fully un-registers agent from broker
Creates a new instance locally
NOTE: The instance must previously be registered by the local VrpcAdapter
Kind: instance method of VrpcAgent
Returns: Object
- The real instance (not a proxy!)
Params
- options
Object
- .className
String
- Name of the class which should be instantiated - [.instance]
String
- Name of the created instance. If not provided an id will be generated - [.args]
Array
- Positional arguments for the constructor call - [.isIsolated]
bool
= false
- If true the created instance will be visible only to the client who created it
- .className
Event 'connect'
Emitted on successful (re)connection (i.e. connack rc=0).
Kind: event emitted by VrpcAgent
Properties
Name | Type | Description |
---|---|---|
sessionPresent | Boolean |
A session from a previous connection is already present |
Event 'reconnect'
Emitted when a reconnect starts.
Kind: event emitted by VrpcAgent
Event 'close'
Emitted after a disconnection.
Kind: event emitted by VrpcAgent
Event 'offline'
Emitted when the client goes offline.
Kind: event emitted by VrpcAgent
Event 'error'
Emitted when the client cannot connect (i.e. connack rc != 0) or when a parsing error occurs. The following TLS errors will be emitted as an error event:
- ECONNREFUSED
- ECONNRESET
- EADDRINUSE
- ENOTFOUND
Kind: event emitted by VrpcAgent
Event 'end'
Emitted when mqtt.Client#end() is called. If a callback was passed to mqtt.Client#end(), this event is emitted once the callback returns.
Kind: event emitted by VrpcAgent
Event 'clientGone'
Emitted when a tracked VRPC client exited.
Kind: event emitted by VrpcAgent
Constructs an agent by parsing command line arguments
Kind: static method of VrpcAgent
Returns: Agent
- Agent instance
Params
- defaults
Object
- Allows to specify defaults for the various command line options- .domain
String
- The domain under which the agent-provided code is reachable - .agent
String
- This agent's name - .username
String
- MQTT username (if no token is used) - .password
String
- MQTT password (if no token is provided) - .token
String
- Access token as generated by: https://app.vrpc.io - .broker
String
- Broker url in form:<scheme>://<host>:<port>
- .version
String
- The (user-defined) version of this agent
- .domain
Example
const agent = VrpcAgent.fromCommandline()
Client capable of creating proxy objects and remotely calling functions as provided through one or more (distributed) agents.
Kind: global class
Extends: EventEmitter
- VrpcClient ⇐
EventEmitter
- new VrpcClient(options)
- .getClientId() ⇒
String
- .connect() ⇒
Promise
- .create(options) ⇒
Promise.<Proxy>
- .getInstance(instance, [options]) ⇒
Promise.<Proxy>
- .delete(instance, [options]) ⇒
Promise.<Boolean>
- .callStatic(options) ⇒
Promise.<Any>
- .callAll(options) ⇒
Promise.<Array.<Object>>
- .getSystemInformation() ⇒
Object
- .getAvailableAgents([options]) ⇒
Array
- .getAvailableClasses([options]) ⇒
Array
- .getAvailableInstances([options]) ⇒
Array
- .getAvailableMemberFunctions([options]) ⇒
Array
- .getAvailableStaticFunctions([options]) ⇒
Array
- .reconnectWithToken(token, [options]) ⇒
Promise
- .unregisterAgent(agent) ⇒
Promise.<Boolean>
- .end() ⇒
Promise
- "agent" (info)
- "class" (info)
- "instanceNew" (addedInstances, info)
- "instanceGone" (removedInstances, info)
- "connect"
- "reconnect"
- "close"
- "offline"
- "error"
- "end"
Constructs a remote client, able to communicate with any distributed agents
NOTE: Each instance creates its own physical connection to the broker.
Params
- options
Object
- [.username]
String
- MQTT username - [.password]
String
- MQTT password (if no token is provided) - [.token]
String
- Access token - .domain
String
- Sets the domain - [.agent]
String
= "*"
- Sets default agent - [.broker]
String
= "mqtts://vrpc.io:8883"
- Broker url in form:<scheme>://<host>:<port>
- [.timeout]
Number
= 12000
- Maximum time in ms to wait for a RPC answer - [.log]
Object
= console
- Log object (must support debug, info, warn, and error level) - [.bestEffort]
Boolean
= true
- If true, message will be sent with best effort, i.e. no caching if offline - [.mqttClientId]
String
= '<generated()>'
- Explicitly sets the mqtt client id - [.identity]
String
- Explicitly sets a vrpc client identity - [.keepalive]
String
- Sets the MQTT keepalive interval (in seconds) - [.requiresSchema]
Boolean
= false
- If true, any available schema information is shipped
- [.username]
Example
const client = new VrpcClient({
domain: 'vrpc',
broker: 'mqtt://vrpc.io'
})
Provides a unique id for this client instance
Kind: instance method of VrpcClient
Returns: String
- clientId
Actually connects to the MQTT broker.
Kind: instance method of VrpcClient
Returns: Promise
- Resolves once connected within [timeout], rejects otherwise
Emits: event:connected
Example
try {
await client.connect()
} catch (err) {
console.error(`Could not connect because: ${err.message}`)
}
Creates a new remote instance and provides a proxy to it.
Remote instances can be "shared" or "isolated". Shared instances are
visible and re-attachable across clients as long as they are not
explicitly deleted. Life-cycle changes of shared instances are available
under the class
, instanceNew
, and instanceGone
events. A shared
instance is created by default (isIsolated: false
).
When the isIsolated
option is true, the remote instance stays invisible
to other clients and the corresponding proxy object is the only way to
issue commands.
NOTE When creating an instance that already exists, the new proxy will
simply attach to (and not re-create) it - just like getInstance()
was
called.
Kind: instance method of VrpcClient
Returns: Promise.<Proxy>
- Object reflecting a proxy to the original object
which is handled by the agent
Params
- options
Object
- .className
String
- Name of the class which should be instantiated - [.instance]
String
- Name of the created instance. If not provided an id will be generated - [.args]
Array
- Positional arguments for the constructor call - [.agent]
String
- Agent name. If not provided class default is used - [.cacheProxy]
bool
= false
- If true the proxy object for a given instance is cached and (re-)used in subsequent calls - [.isIsolated]
bool
= false
- If true the created proxy will be visible only to the client who created it
- .className
Example
// create isolated instance
const proxy1 = await client.create({
className: 'Foo',
instance: 'myPersonalInstance',
isIsolated: true
})
// create shared instance
const proxy2 = await client.create({
className: 'Foo',
instance: 'aSharedFooInstance'
})
// create shared instance providing three constructor arguments
const proxy3 = await client.create({
className: 'Bar',
instance: 'mySharedBarInstance',
args: [42, "second argument", { some: 'option' }]
})
Get a remotely existing instance.
Either provide a string only, then VRPC tries to find the instance using client information, or additionally provide an object with explicit meta data.
Kind: instance method of VrpcClient
Returns: Promise.<Proxy>
- Proxy object reflecting the remotely existing instance
Params
- instance
String
- The instance to be retrieved - [options]
Object
- Explicitly define agent and class- [.className]
String
- Name of the instance's class - [.agent]
String
- Agent name. If not provided class default is used as priority hit - [.noWait]
bool
= false
- If true immediately fail if instance could not be found in local cache
- [.className]
Delete a remotely existing instance
Either provide a string only, then VRPC tries to find the instance using client information, or provide an object with explicit meta data.
Kind: instance method of VrpcClient
Returns: Promise.<Boolean>
- true if successful, false otherwise
Params
- instance
String
- The instance to be deleted - [options]
Object
- Explicitly define agent and class- .className
String
- Name of the instance's class - .agent
String
- Agent name. If not provided class default is used as priority hit
- .className
Calls a static function on a remote class
Kind: instance method of VrpcClient
Returns: Promise.<Any>
- Return value of the remotely called function
Params
- options
Object
- .className
String
- Name of the static function's class - .functionName
String
- Name of the static function to be called - [.args]
Array
- Positional arguments of the static function call - [.agent]
String
- Agent name. If not provided class default is used
- .className
Calls the same function on all instances of a given class and returns an aggregated result. It as well allows for batch event and callback registrations. In this case the instanceId of the emitter is injected as first argument of any event callback.
NOTE: When no agent was specified as class default and no agent is specified when calling this function, callAll will act on the requested class across all available agents. The same is true when explicitly using a wildcard (*) as agent value.
Kind: instance method of VrpcClient
Returns: Promise.<Array.<Object>>
- An array of objects { id, val, err }
carrying the instance id, the return value and potential errors
Params
- options
Object
- .className
String
- Name of the static function's class - [.args]
Array
- Positional arguments of the static function call - [.agent]
String
- Agent name. If not provided class default is used
- .className
Retrieves all information about the currently available components.
Kind: instance method of VrpcClient
Returns: Object
- SystemInformation
type SystemInformation = {
[agent].status: string, // 'offline' or 'online'
[agent].hostname: string,
[agent].version: string,
[agent].classes[className].instances: string[],
[agent].classes[className].memberFunctions: string[],
[agent].classes[className].staticFunctions: string[],
[agent].classes[className].meta?: MetaData
}
Retrieves all available agents.
Kind: instance method of VrpcClient
Returns: Array
- Array of agent names.
Params
- [options]
Object
- [.mustBeOnline]
Boolean
= true
- Only retrieve currently online agents
- [.mustBeOnline]
Retrieves all available classes on specific agent.
Kind: instance method of VrpcClient
Returns: Array
- Array of class names.
Params
- [options]
Object
- [.agent]
String
- Agent name. If not provided class default is used. - [.mustBeOnline]
Boolean
= true
- Only retrieve currently online classes
- [.agent]
Retrieves all (shared) instances on specific class and agent.
Kind: instance method of VrpcClient
Returns: Array
- Array of instance names
Params
- [options]
Object
- .className
String
- Class name - [.agent]
String
- Agent name. If not provided class default is used - [.mustBeOnline]
Boolean
= true
- Only retrieve currently online classes
- .className
Retrieves all member functions of specific class and agent.
Kind: instance method of VrpcClient
Returns: Array
- Array of member function names
Params
- [options]
Object
- .className
String
- Class name - [.agent]
String
- Agent name. If not provided class default is used - [.mustBeOnline]
Boolean
= true
- Only retrieve currently online classes
- .className
Retrieves all static functions of specific class and agent.
Kind: instance method of VrpcClient
Returns: Array
- Array of static function names
Params
- [options]
Object
- .className
String
- Class name - [.agent]
String
- Agent name. If not provided class default is used - [.mustBeOnline]
Boolean
= true
- Only retrieve currently online classes
- .className
Reconnects to the broker by using a different token
Kind: instance method of VrpcClient
Returns: Promise
- Promise that resolves once re-connected
Params
- token
String
- Access token as generated by: https://app.vrpc.io - [options]
Object
- .agent
String
- Agent name. If not provided class default is used
- .agent
Unregisters (= removal of persisted information) an offline agent
Kind: instance method of VrpcClient
Returns: Promise.<Boolean>
- Resolves to true in case of success, false otherwise
Params
- agent - The agent to be unregistered
Ends the connection to the broker
Kind: instance method of VrpcClient
Returns: Promise
- Resolves when ended
Event 'agent'
This event is fired whenever an agent is added or removed, or whenever an agent changes its status (switches between online or offline).
Kind: event emitted by VrpcClient
Params
- info
Object
- .domain
String
- Domain name - .agent
String
- Agent name - .status
String
- Agent status, can be 'offline' or 'online' - .hostname
String
- Name of the host running the agent - .version
String
- User-defined version of the agent
- .domain
Event 'class'
Emitted whenever a class is added or removed, or when instances or functions of this class have changed.
Kind: event emitted by VrpcClient
Params
- info
Object
- .domain
String
- Domain name - .agent
String
- Agent name - .className
String
- Class name - .instances
Array.<String>
- Array of instances - .memberFunctions
Array.<String>
- Array of member functions - .staticFunctions
Array.<String>
- Array of static functions - .meta
MetaData
- Object associating further information to functions
- .domain
Event 'instanceNew'
Emitted whenever a new instance was created.
Kind: event emitted by VrpcClient
Params
- addedInstances
Array.<String>
- An array of newly added instances - info
Object
- .domain
String
- Domain name - .agent
String
- Agent name - .className
String
- Class name
- .domain
Event 'instanceGone'
Emitted whenever a new instance was removed.
Kind: event emitted by VrpcClient
Params
- removedInstances
Array.<String>
- An array of removed instances - info
Object
- .domain
String
- Domain name - .agent
String
- Agent name - .className
String
- Class name
- .domain
Event 'connect'
Emitted on successful (re)connection (i.e. connack rc=0).
Kind: event emitted by VrpcClient
Properties
Name | Type | Description |
---|---|---|
sessionPresent | Boolean |
A session from a previous connection is already present |
Event 'reconnect'
Emitted when a reconnect starts.
Kind: event emitted by VrpcClient
Event 'close'
Emitted after a disconnection.
Kind: event emitted by VrpcClient
Event 'offline'
Emitted when the client goes offline.
Kind: event emitted by VrpcClient
Event 'error'
Emitted when the client cannot connect (i.e. connack rc != 0) or when a parsing error occurs. The following TLS errors will be emitted as an error event:
- ECONNREFUSED
- ECONNRESET
- EADDRINUSE
- ENOTFOUND
Kind: event emitted by VrpcClient
Event 'end'
Emitted when mqtt.Client#end() is called. If a callback was passed to mqtt.Client#end(), this event is emitted once the callback returns.
Kind: event emitted by VrpcClient
Client capable of creating proxy classes and objects to locally call functions as provided through native addons.
Kind: global class
Constructs a local caller object, able to communicate to natively added C++
Params
- adapter
Object
- An adapter object, typically loaded as native addon
Provides a proxy class to an existing one in the native addon
You can use the returned class in the usual way. Static function calls are forwarded to the native addon, as are any instantiations and member function calls.
Kind: instance method of VrpcNative
Returns: Proxy Class
Params
- className
String
- The name of the class
Deletes a proxy object and its underlying instance
Kind: instance method of VrpcNative
Returns: True in case of success, false otherwise
Params
- proxy
Object
- A proxy object
Secondary option to call a static function (when creation of a proxy class seems to be too much overhead)
Kind: instance method of VrpcNative
Returns: The output of the underlying static function
Params
- className
String
- The class on which the static function should be called - functionName
String
- Name of the static function - ...args
any
- The function arguments
Retrieves an array of all available classes (names only)
Kind: instance method of VrpcNative
Returns: Array.<String>
- Array of class names
Associates meta data to any function
Kind: global typedef
Kind: global typedef
Params
- description
String
- Function description - params
Array.<Param>
- Array of parameter details in order of signature - ret
Ret
- Object associating further information to return value
Kind: global typedef
Params
- name
String
- Parameter name - optional
Boolean
- Whether parameter is optional - description
String
- Parameter description - [type]
String
- Parameter type - [default]
Any
- The default to be injected when not provided
Kind: global typedef
Params
- description
String
- Return value description - [type]
String
- Return value type