- Contents
Interaction Web Tools Developer's Guide
Subscribing to Notifications
Consider the following class:
MyClass = Class.create(common.InterfaceImplementation /* …or a subclass thereof */, { initialize : function($super) { $super(); // …do things } });
Making this class respond to Notifications is easy. Here, the class is notified when a message is received within a chat:
MyClass = Class.create(common.InterfaceImplementation /* …or a subclass thereof */, { initialize : function($super) { $super(); // Before registering as an observer, this object must declare // that it implements the appropriate observer interface. this.addImplementedInterface(webservices.Interfaces.IReceivedTextNotificationObserver, webservices); // Register as an observer, and begin receiving Notifications. webservices.NotificationRegistry.registerObserver(this, webservices.Interfaces.IReceivedTextNotificationObserver); }, // Fulfill the implementation contract of the // IReceivedTextNotificationObserver interface. processReceivedTextNotification : function(notification) { var text = notification.get_messageText(); var sender = notification.get_participantId(); var timestamp = notification.get_dateTime(); // Do something with these… } });
A single object can observe any number of Notification types, and a Notification type can be observed by any number of objects.