Represents a ubus object published on the bus.
A published object is a service registered with ubusd that provides methods for other processes to call. Objects are created via publish() and can:
- Expose multiple methods for remote invocation
- Receive notifications from subscribers (subscribed(), notify())
- Be removed from the bus when no longer needed (remove())
Objects are identified by their path (e.g., system, network.interface) and can be discovered by other processes using list().
const obj = publish(…, { … });
obj.subscribed();
obj.notify(…);
obj.remove();- Source
- See
- publish()
- subscriber()
Methods
notify(type, dataopt, data_cbopt, status_cbopt, cbopt, timeoutopt) → {notify|number}
Send a notification from a ubus object.
Sends an asynchronous notification of the specified type to all subscribers of the object. Optional callbacks can be provided to handle data, status, and completion events.
Returns a notification request resource for asynchronous operations.
Returns a status code number when a synchronous timeout is specified.
Returns null if the notification could not be sent.
| Name | Type | Description |
|---|---|---|
type | string | The notification type string. |
data | Object | (optional) Optional notification data as an object with field names and values. |
data_cb | function | (optional) Optional callback invoked for each data notification received. |
status_cb | function | (optional) Optional callback invoked for status updates. |
cb | function | (optional) Optional callback invoked when the notification operation completes. |
timeout | number | (optional) Optional timeout in milliseconds. If specified, the operation waits synchronously for completion. |
const obj = publish("my.service", {
"trigger": (req, msg) => {
obj.notify("update", { key: "value" }, (idx, ret) => {
printf("Notification %d: status %d\n", idx, ret);
});
req.reply({ sent: true });
}
});- Source
remove() → {boolean}nullable
Remove a ubus object from the bus.
Unregisters the object from the ubus bus, making it no longer accessible to other clients.
Returns true on success.
Returns null if the object could not be removed.
const obj = publish("my.service", { … });
// … do work …
obj.remove();- Source
subscribed() → {boolean}
Check if a ubus object has subscribers.
Returns true if there are active subscribers to the object.
Returns false if no subscribers are currently connected.
const obj = publish("my.service", {
"trigger": (req, msg) => {
if (obj.subscribed()) {
obj.notify("update", { data: "value" });
}
req.reply({ notified: obj.subscribed() });
}
});- Source