- Contents
Interaction Web Tools Developer's Guide
Custom Notification Types
In addition to the built-in Notification types, customers can create their own Notification types within Interaction Web Tools’ Notification framework.
Declare a new Notification interface. The arguments are: its name, the names of its methods, the name of its superinterface, and the package containing the superinterface. This example Notification interface represents indication that a latitude and longitude have been mentioned in a chat.
MyPackage.Interfaces.IGeoNotification = new common.Interface('MyPackage.Interfaces.IGeoNotification', ['get_latitude', 'get_longitude'], ['webservices.Interfaces.INotification'], webservices);
To implement this new interface, declare a Notification object:
MyPackage.GeoNotification = Class.create(webservices._Internal.NotificationBase,
{
_className : “MyPackage.GeoNotification”, // This is required!
initialize($super, latitude, longitude)
{
$super();
// This class implements the previously-created interface.
this.addImplementedInterface(MyPackage.Interfaces.IGeoNotification);
this.latitude = latitude;
this.longitude = longitude;
},
// Implement the methods defined by the interface
get_latitude()
{
return this.latitude;
},
get_longitude()
{
return this.longitude;
}
}
Add this new Notification type to the NotificationRegistry so that it can be used. Pass the name of the interface, and a function that can create an instance of the class which implements that interface:
webservices.NotificationRegistry.registerNotificationType(MyPackage.Interfaces.IGeoNotification,
function(lat, lng) { return new MyPackage.GeoNotification(lat, lng); });
An instance of this Notification can be created and sent to observers as follows:
var geoNotification = webservices.NotificationFactory.createGeoNotification(39.8905251,-86.2678351);
webservices.NotificationRegistry.process(geoNotification);
An object can be registered as an observer of this new Notification type in the way that was described in the previous section. For instance:
MapDisplayer = Class.create(common.InterfaceImplementation,
{
initialize : function($super) {
$super();
// Before registering as an observer, this object must
// implement the appropriate observer interface.
this.addImplementedInterface(MyPackage.Interfaces.IGeoNotificationObserver, MyPackage);
// Register as an observer, and begin receiving Notifications.
webservices.NotificationRegistry.registerObserver(this, MyPackage.Interfaces.IGeoNotificationObserver);
},
processGeoNotification : function(notification)
{
showMap(document.getElementById('map'), notification.get_latitude(), notification.get_longitude());
},
showMap : function(domElement, latitude, longitude)
{
// …
}
});
Here is a class which observes ReceivedTextNotifications as in the previous section, and creates and sends GeoNotifications:
CoordsParser = Class.create(common.InterfaceImplementation /* …or a subclass thereof */,
{
initialize : function($super) {
$super();
// Before registering as an observer, this object must
// implement 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 coords = this.parseCoordsFromString(text);
if (coords)
{
var geoNotification = webservices.NotificationFactory.createGeoNotification(coords.lat, coords.long);
webservices.NotificationRegistry.process(geoNotification); // The Notification will be sent to MapDisplayer
}
},
parseCoordsFromString : function(string)
{
// …
}
});

