ubus. subscriber

Represents a subscriber to an object's notifications.

A subscriber is registered via subscriber() to receive notifications from a specific object. Subscribers are part of the subscribe/notify communication scheme, where the target object can send notifications that are delivered to all registered subscribers.

When a subscriber is registered, the target object receives a notification about the new subscription. Similarly, when a subscriber is removed, the target object is notified of the unsubscription.

Example
const sub = subscriber(objid, (method, data) => { … });

sub.subscribe();
sub.unsubscribe();
sub.remove();
See

Methods

remove() → {boolean}nullable

Remove a subscriber from the bus.

Unregisters the subscriber, stopping it from receiving further notifications.

Returns true on success.

Returns null if the subscriber could not be removed.

Returns: boolean
Example
const sub = conn.subscriber("my.object", (event) => { … });
// … when done …
sub.remove();

subscribe(object_name) → {boolean}nullable

Subscribe to a ubus object.

Registers interest in notifications from the specified object.

Returns true on success.

Returns null if the subscription failed.

Parameters:
NameTypeDescription
object_namestring

The name of the object to subscribe to.

Returns: boolean
Example
const conn = connect();
const sub = conn.subscriber("my.object", (event) => {
    printf("Notification: type=%s, data=%.J\n", event.type, event.data);
});
// … later, to re-subscribe …
sub.subscribe("my.object");

unsubscribe(object_name) → {boolean}nullable

Unsubscribe from a ubus object.

Stops receiving notifications from the specified object.

Returns true on success.

Returns null if the unsubscription failed.

Parameters:
NameTypeDescription
object_namestring

The name of the object to unsubscribe from.

Returns: boolean
Example
const sub = conn.subscriber("my.object", (event) => { … });
// … later, to unsubscribe temporarily …
sub.unsubscribe("my.object");