'use strict';

var glimpse = require('glimpse');
var polyfill = require('event-source')

var socket = (function() {
    var connection;

    var setup = function() {
        connection = new polyfill.EventSource('/Glimpse/MessageStream');
        connection.onmessage = function(e) {
            if (!FAKE_SERVER) {
                glimpse.emit('data.message.summary.found.stream', e.data);
            }
        };
    }; 
    
    return {
        check: function() {
            if (!connection) {
                setup();
            }
        }
    };
})();

module.exports = {
    subscribeToLastestSummaries: function () {
        socket.check();
    },
    subscribeToDetailsFor: function (requestId) {
        // TODO: Setup SSE code
    }
};

@@ -379,15 +379,27 @@
 m', 
+JSON.parse(
 e.data)
+)
 ;%0A  

Make sure the data is parse out as json from the server for SSE