Receiving topic notifications
Receive topic notifications using topic selectors. This enables a client to receive updates when topics are added or removed, without the topic values.
Note: Topic notifications are supported by the Android™
API, Java™
API and JavaScript® API.
The client must register a listener object to receive notifications about selected topics. Use a topic selector to specify the topics.
For more details about topic notifications, see Topic notifications.
Required permissions:
and permissions for the specified topicsReceiving topic notifications
A client can register to receive notifications about a set of topics via a listener object.
JavaScript
var listener = { onDescendantNotification: function(topicPath, type) {}, onTopicNotification: function(topicPath, topicSpecification, type) {}, onClose: function() {}, onError: function(error) {} }; session.notifications.addListener(listener).then(function(reg) { reg.select("foo"); });
Java and Android
final TopicNotifications notifications = session.feature(TopicNotifications.class); final TopicNotificationListener listener = new TopicNotificationListener() { @Override public void onTopicNotification(String topicPath, TopicSpecification specification, NotificationType type) { // Handle notifications for selected/deselected topics } @Override public void onDescendantNotification(String topicPath, NotificationType type) { // Handle notifications for immediate descendants } @Override public void onClose() { // The listener has been closed } @Override public void onError(ErrorReason error) { // The listener has encountered an error } }; final CompletableFuture<NotificationRegistration> future = notifications.addListener(listener); final NotificationRegistration registration = future.get(); registration.select("foo");
This page last modified: 2019/11/22