-
Notifications
You must be signed in to change notification settings - Fork 2
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.
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.
notificationServerUrl
is an optional string containing the URL of the notification server. If this is the string 'null', the notification client will not make a connection to the notification server.
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. Alternatively, you can pass in the type of notification you want to receive as a string. It is a shorthand for the premise being function(notification) { return notification.type === 'my type' }
.
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 a falsey value 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.
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.
{
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. }
}
}
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 === 'xyz-123-abc') && (notification.importance > 5);
};
var handle = function(notification) {
alert('The notification I care for:' + JSON.stringify(notification));
};
notificationClient.register(premise, handle);