Using Server-sent Events

In the browser, An EventSource object can be used to receive server-sent event notifications. On creation, the object is connected to the source of notifications (in our case, the Content Store's SSE link, http://host-ip-address/webservice/escenic/changelog/sse. It has an onmessage event that is fired every time a notification is received. So all you need to do is write an event function that responds appropriately to the notifications received. For example:

var source = new EventSource("http://host-ip-address/webservice/escenic/changelog/sse");
source.onmessage = function(event) {
    // handle the SSE notification here:
    // event.data contains the URL of the updated change log
    // event.lastEventId contains a unique ID
};

The notifications generated by the Content Store set two event properties:

data

The URL of the change log that has been updated

lastEventId

A unique ID for the event (not currently used??)

The event data sent by the  Content Store does not directly contain any details of what change has occurred - it simply sends the URL of the change log that has been updated. Your event code can then either ignore the event if the updated change log is not of interest, or send a GET request to the change log URL in order to retrieve the change details and deal with them. The GET request sent to the change log URL is identical to an ordinary polling request, except that in this case, the response is guaranteed to contain some changes.