VrpcAgent
VrpcAgent ⇐ EventEmitter
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) ⇒
new VrpcAgent(obj)
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>-<installationId>@<hostname>-<platform>-js'- This agent's name; the default is stable for the installation (where this vrpc is installed), however and from wherever the agent is started - [.broker]
String= 'mqtts://broker.hivemq.com:8883'- Broker url in form:<scheme>://<host>:<port> - [.log]
Object= console- Log object (must support debug, info, warn, and error level) - [.bestEffort]
Boolean= true- If true, messages are sent at QoS 0 (best effort), else at QoS 1 - [.version]
String= ''- The (user-defined) version of this agent - [.mqttClientId]
String= '<generated()>'- Explicitly set the mqtt client id. - [.tls]
Object- TLS settings for a secure broker:{ ca, rejectUnauthorized }. Without it the broker's certificate is not verified (the historical behaviour); withcathe broker must present a chain the given certificates anchor.
- [.username]
Example
const agent = new Agent({
domain: 'vrpc'
agent: 'myAgent'
})
vrpcAgent.serve() ⇒ Promise
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 the agent serves - connected, its
request topics subscribed and its info announced - or once it was
explicitly ended before that, never rejects
vrpcAgent.end([obj], [unregister]) ⇒ Promise
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
vrpcAgent.create(options) ⇒ Object
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
"connect"
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 |
"reconnect"
Event 'reconnect'
Emitted when a reconnect starts.
Kind: event emitted by VrpcAgent
"close"
Event 'close'
Emitted after a disconnection.
Kind: event emitted by VrpcAgent
"offline"
Event 'offline'
Emitted when the client goes offline.
Kind: event emitted by VrpcAgent
"error"
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
"end"
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
"clientGone"
Event 'clientGone'
Emitted when a tracked VRPC client connection ended. Listeners receive
the connection id (unique per VrpcClient instance) and an info object
whose clientId is the identity-derived id shared by all connections
of one identity (undefined for clients < 3.8.0).
Kind: event emitted by VrpcAgent
VrpcAgent.fromCommandline(defaults) ⇒ Agent
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 - .broker
String- Broker url in form:<scheme>://<host>:<port> - .version
String- The (user-defined) version of this agent
- .domain
Example
const agent = VrpcAgent.fromCommandline()