Skip to content

Commit

Permalink
Added back EventSource to the client, writing to console.log() for now
Browse files Browse the repository at this point in the history
  • Loading branch information
njh committed Aug 30, 2014
1 parent 6588c9e commit 94a43c1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
12 changes: 6 additions & 6 deletions marquette.js
Expand Up @@ -116,29 +116,29 @@ client.on('message', function(topic, payload) {
});
});

// Send a ping every 25 seconds to the browsers to keep the HTTP connections open

// Send a ping every 20 seconds to the browsers to keep the HTTP connections open
setInterval(function() {
browsers.forEach(function(res) {
res.write(": ping\n\n");
});
}, 25000);
}, 20000);


app.get('/update-stream', function(req, res) {
req.socket.setTimeout(Infinity);

req.socket.setNoDelay(true);
res.writeHead(200, {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache'
});
res.write("\n");
res.write(":\n");

browsers.push(res);

req.on("close", function() {
index = browsers.indexOf(req);
browsers.splice(index, 1);
});

});


Expand Down
1 change: 1 addition & 0 deletions public/index.html
Expand Up @@ -9,6 +9,7 @@

<script src="./js/jquery-1.11.1.min.js"></script>
<script src="./js/jquery.gridster.min.js"></script>
<script src="./js/eventsource.min.js"></script>
<script src="./js/marquette.js"></script>
</head>

Expand Down
6 changes: 6 additions & 0 deletions public/js/eventsource.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions public/js/marquette.js
Expand Up @@ -54,6 +54,23 @@ $(function(){ //DOM Ready
init_gridster();
});


var source = new EventSource('/update-stream');
console.log("EventSource="+source);

source.onopen = function(e) {
console.log("EventSource connection open");
};

source.onmessage = function(e) {
var obj = JSON.parse(e.data);
console.log(obj);
};

source.onerror = function(e) {
console.log("Event source error: "+e);
};

});


0 comments on commit 94a43c1

Please sign in to comment.