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.
const sub = subscriber(objid, (method, data) => { … });
sub.subscribe();
sub.unsubscribe();
sub.remove();- Source
- See
- subscriber()
- notify()
- subscribed()
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.
const sub = conn.subscriber("my.object", (event) => { … });
// … when done …
sub.remove();- Source
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.
| Name | Type | Description |
|---|---|---|
object_name | string | The name of the object to subscribe to. |
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");- Source
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.
| Name | Type | Description |
|---|---|---|
object_name | string | The name of the object to unsubscribe from. |
const sub = conn.subscriber("my.object", (event) => { … });
// … later, to unsubscribe temporarily …
sub.unsubscribe("my.object");- Source