Represents a channel connection to the ubus bus.
Channels provide bidirectional communication between two ubus objects through file descriptors. They are created via open_channel() or from an incoming request via new_channel().
Channels are useful for:
- Establishing dedicated communication paths between specific objects
- Streaming data or multiple requests over a single connection
- File descriptor passing between processes
const chan = open_channel(…);
chan.request(…);
chan.defer(…);
chan.disconnect();
chan.error();- Source
Methods
defer(method, dataopt, cbopt, data_cbopt, fdopt, fd_cbopt) → {deferred}nullable
Send an asynchronous request on a channel connection.
Similar to defer() but uses object ID 0 for channel-based communication.
Returns a deferred request resource representing the pending operation.
Returns null if the deferred call could not be initiated.
| Name | Type | Description |
|---|---|---|
method | string | The name of the method to invoke. |
data | Object | (optional) Optional method arguments as an object with field names and values. |
cb | function | (optional) Callback function invoked when the operation completes. |
data_cb | function | (optional) Optional callback invoked for intermediate data notifications. |
fd | number | (optional) Optional file descriptor to send along with the request. |
fd_cb | function | (optional) Optional callback function invoked when a file descriptor is received. |
const chan = open_channel(…);
const req = chan.defer("method_name", { arg: "value" },
(status, data) => {
printf("Status: %d\n", status);
});- Source
error(numericopt) → {string|number}
Query ubus error information.
Returns a string containing a description of the last ubus error when the numeric argument is absent or false.
Returns a ubus status code number when the numeric argument is true.
Returns null if there is no error information.
| Name | Type | Description |
|---|---|---|
numeric | boolean | (optional) Whether to return a numeric status code ( |
- Source
request(method, dataopt, returnopt, fdopt, fd_cbopt) → {*}nullable
Send a request on a channel connection.
Similar to call() but uses object ID 0 for channel-based communication.
Returns the method response data.
Returns null if the request failed.
| Name | Type | Description |
|---|---|---|
method | string | The name of the method to invoke. |
data | Object | (optional) Optional method arguments as an object with field names and values. |
return | string | | (optional, default: "single")Controls how multiple responses are handled. |
fd | number | (optional) Optional file descriptor to send along with the request. |
fd_cb | function | (optional) Optional callback function invoked when a file descriptor is received. |
const chan = open_channel(…);
const result = chan.request("method_name", { arg: "value" });- Source