Skip to content
hecking edited this page Apr 28, 2014 · 16 revisions

NotificationClient

Through the notificationClient, ILS apps can register with the Learning Analytics Backend Services to receive notifications sent by the Notification Broker.

The connection happens over Websockets via socket.io. A combination of the provider id, actor id and generator id, taken from the metadataHandler you pass on instantiation identifies the notification client instance on the server.

API

NotificationClient(metadataHandler)

Instantiates the notification client. A websockets connection to the server will be established. The metadataHandler supplies the data (actor id, generator id and provider id) that enables the server to identify the socket connection to the specific instance of the notification client uniquely. Actor is the current user. Generator is the app. Provider is the ILS in which an app lives.

notificationClient.register(premise, handle)

Registers listeners with the notificationClient to receive notifications.

premise is a function that receives the notification and returns true if the notification is of interest, and false if it is not.

handle is a function that receives the notification if premise returned true. This is where you put the logic that takes action when a notification arrives. If false is returned from the function, the notification will be passed on to other listeners registered after this one. If true is returned, the listener is considered greedy, and the notification is not passed on to following listeners.

notificationClient.processNotification(notification)

The method is called if the client receives a notification. All registered listeners will be iterated and if the notification is of interest for a listener (determined by the premise-function as mentioned before), the registered callback will be performed. The notification will be passed as a parameter to the callback.

Example notification

{
    type : "prompt",  // other possible types are "configuration" or "resource."
    importance : "8",  // importance level with range [1, ..., 10].
    target : {
        type : "app",  
        id : "provider_id-actor_id-generator_id"   // unique id to adress a particular app.
    },
    content : {
        text : "This is an example message"  // message content if notification type is "promt".
        url : "http:\\..."  // url if notification type is "resource".
        configuration : { App configuration as property−value list. }
    }
}

Usage Example

var metadata = {
  actor:     { id: '123' },
  generator: { id: 'abc' },
  provider:  { id: 'xyz' },
};
var metadataHandler    = new golab.ils.metadata.GoLabMetadataHandler(metadata);
var notificationClient = new ude.commons.NotificationClient(metadataHandler);

var premise = function(notification) {
  // depends on the format of the notification. This is just an example.
  return (notification.target === 'my_app') 
           && (notification.importance > 5);
};

var handle = function(notification) {
  alert('The notification I care for:' + JSON.stringify(notification));
};

notificationClient.register(premise, handle);
Clone this wiki locally