Methods
addInterceptor(interceptorFn) → {LuCI.rpc.interceptorFn}
Registers a new interceptor function.
| Name | Type | Description |
|---|---|---|
interceptorFn | LuCI. | The interceptor function to register. |
Returns the given function value.
- Type:
- LuCI.
rpc. interceptorFn
declare(options) → {LuCI.rpc.invokeFn}
Describes a remote RPC call procedure and returns a function implementing it.
| Name | Type | Description |
|---|---|---|
options | LuCI. | If any object names are given, this function will return the method signatures of each given object. |
Returns a new function implementing the method call described in options.
- Type:
- LuCI.
rpc. invokeFn
getBaseURL() → {string}
Returns the current RPC base URL.
Returns the RPC URL endpoint to issue requests against.
- Type:
- string
getSessionID() → {string}
Returns the current RPC session id.
Returns the 32 byte session ID string used for authenticating remote requests.
- Type:
- string
getStatusText(statusCode) → {string}
Translates a numeric ubus error code into a human readable description.
| Name | Type | Description |
|---|---|---|
statusCode | number | The numeric status code. |
Returns the textual description of the code.
- Type:
- string
list(…argsopt) → {Promise.<(Array.<string>|Object.<string, Object.<string, Object.<string, string>>>)>}
Lists available remote ubus objects or the method signatures of specific objects.
This function has two signatures and is sensitive to the number of arguments passed to it:
list()- Returns an array containing the names of all remoteubusobjectslist("objname", ...)Returns method signatures for each givenubusobject name.
| Name | Type | Attributes | Description |
|---|---|---|---|
args | string | <optional> <repeatable> | (objectNames) If any object names are given, this function will return the method signatures of each given object. |
When invoked without arguments, this function will return a promise resolving to an array of ubus object names. When invoked with one or more arguments, a promise resolving to an object describing the method signatures of each requested ubus object name will be returned.
- Type:
- Promise.<(Array.<string>|Object.<string, Object.<string, Object.<string, string>>>)>
removeInterceptor(interceptorFn) → {boolean}
Removes a registered interceptor function.
| Name | Type | Description |
|---|---|---|
interceptorFn | LuCI. | The interceptor function to remove. |
Returns true if the given function has been removed or false if it has not been found.
- Type:
- boolean
setBaseURL(url)
Set the RPC base URL to use.
| Name | Type | Description |
|---|---|---|
url | string | Sets the RPC URL endpoint to issue requests against. |
setSessionID(sid)
Set the RPC session id to use.
| Name | Type | Description |
|---|---|---|
sid | string | Sets the 32 byte session ID string used for authenticating remote requests. |
Type Definitions
DeclareOptions
- Object
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
object | string | The name of the remote | ||
method | string | The name of the remote | ||
params | Array.<string> | <optional> | Lists the named parameters expected by the remote Extraneous parameters passed to the generated function will not be sent to the remote procedure but are passed to the Examples:
| |
expect | Object.<string, *> | <optional> | Describes the expected return data structure. The given object is supposed to contain a single key selecting the value to use from the returned If the received data does not contain The key in the If the Examples:
| |
filter | LuCI. | <optional> | Specifies an optional filter function which is invoked to transform the received reply data before it is returned to the caller. | |
reject | boolean | <optional> | false | If set to |
filterFn(data, args, …extraArgs) → {*}
The filter function is invoked to transform a received ubus RPC call reply before returning it to the caller.
| Name | Type | Attributes | Description |
|---|---|---|---|
data | * | The received | |
args | Array.<*> | The arguments the RPC method has been invoked with. | |
extraArgs | * | <repeatable> | All extraneous arguments passed to the RPC method exceeding the number of arguments describes in the RPC call declaration. |
The return value of the filter function will be returned to the caller of the RPC method as-is.
- Type:
- *
invokeFn(…params) → {Promise.<*>}
The generated invocation function is returned by rpc.declare() and encapsulates a single RPC method call.
Calling this function will execute a remote ubus HTTP call request using the arguments passed to it as arguments and return a promise resolving to the received reply values.
| Name | Type | Attributes | Description |
|---|---|---|---|
params | * | <repeatable> | The parameters to pass to the remote procedure call. The given positional arguments will be named to named RPC parameters according to the names specified in the Any additional parameters exceeding the amount of arguments in the |
Returns a promise resolving to the result data of the remote ubus RPC method invocation, optionally substituted and filtered according to the expect and filter declarations.
- Type:
- Promise.<*>
interceptorFn(msg, req) → {Promise.<*>|*}
Registered interceptor functions are invoked before the standard reply parsing and handling logic.
By returning rejected promises, interceptor functions can cause the invocation function to fail, regardless of the received reply.
Interceptors may also modify their message argument in-place to rewrite received replies before they're processed by the standard response handling code.
A common use case for such functions is to detect failing RPC replies due to expired authentication in order to trigger a new login.
| Name | Type | Description |
|---|---|---|
msg | * | The unprocessed, JSON decoded remote RPC method call reply. Since interceptors run before the standard parsing logic, the reply data is not verified for correctness or filtered according to |
req | Object | The related request object which is an extended variant of the declaration object, allowing access to internals of the invocation function such as |
Interceptor functions may return a promise to defer response processing until some delayed work completed. Any values the returned promise resolves to are ignored.
When the returned promise rejects with an error, the invocation function will fail too, forwarding the error to the caller.
- Type:
- Promise.<*> |
*