incrementalGet question

I’ve been trying to understand why the incrementalGet function (found in the czmlLayers branch) is using the EventSource api instead of just making a regular AJAX request. The biggest issue I’m having is that I see what the incrementalGetSpec is going to test the function, but I cannot reproduce this in a browser.

The data I am trying to send looks like this:

 data: [{"id":"d2495a96","external":{"url":"http://localhost:8080/Apps/CesiumViewer/test.json","pollingUpdate":{"refreshInterval":30.0},"scope":"SHARED"}},{"id":"36745", ...

I have validated that the json data is correctly formatted. I have also tried removing the “data:” prefix, but get the same errors.

The finish() function does get called, but the message event listener never gets called.

In chrome, I get this error message:

EventSource’s response has a MIME type (“text/plain”) that is not “text/event-stream”. Aborting the connection.

I tried to forcing the mime-type, and it still didn’t work.

In Firefox, I get this error message:

Firefox can’t establish a connection to the server at http://localhost:8080/Apps/CesiumViewer/test.json.

That error comes up no matter what I have tried so far.

The main motivation for using (or abusing) event streams is that it allows us to divide the CZML data into smaller packets, which can be parsed and loaded one packet at a time. This can be very beneficial for large documents which would otherwise lock up the browser while they’re being handled. At one point, we were using multipart MIME messages, but there was still a lot of overhead in JavaScript to parse each piece of the response, plus it generates a lot of GC churn due to all the substringing necessary. With EventSource, the browser natively handles all the work of parsing the stream into chunks for us.

In your case, you do need to make sure the response type exactly matches text/event-stream, and that the structure of the stream matches the spec: https://developer.mozilla.org/en-US/docs/Server-sent_events/Using_server-sent_events Also, make sure that you have one CZML packet per event. Try comparing your file against the structure created by LotsOfSatellites:

curl -H “Accept: text/event-stream” “http://cesium.agi.com/LotsOfSatellites/satellites?start=2013-04-09T15%3A00%3A00Z&stop=2013-04-09T15%3A30%3A00Z&step=120