(function() { window.main = function() { var log, source; log = document.getElementById('log'); source = new EventSource('http://wafi.iit.cnr.it/asia/test/sse/sender.php'); source.onopen = function() { return console.log('Connection established!\n'); }; // 'ping' event callback source.addEventListener('ping', (function(e) { var obj; obj = JSON.parse(e.data); // 0: end the connection with the EventSource if (obj.e_code == 0) { source.close(); } // -1: debug printing on the console else if (obj.e_code == -1) { console.log("debug:" + obj.e_value); } // -2: debug with an alert else if (obj.e_code == -2) { alert("debug:" + obj.e_value); } // -3: debug printing on an html div else if (obj.e_code == -3) { $('#debug_message').text("debug:" + obj.e_value); } }), false); return source.onerror = function(e) { return alert('Error!'); }; }; }).call(this);