Skip to content

Commit

Permalink
Merge pull request fabiocaseri#1 from arabold/master
Browse files Browse the repository at this point in the history
Pulling in some fixes from another fork
  • Loading branch information
lokulin committed May 2, 2015
2 parents 1f8039a + c06eeca commit e24bf02
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
3 changes: 2 additions & 1 deletion javascripts/dashing.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ Dashing.debugMode = false

source = new EventSource('events')
source.addEventListener 'open', (e) ->
console.log("Connection opened")
if Dashing.debugMode
console.log("Connection opened")

source.addEventListener 'error', (e)->
console.log("Connection error")
Expand Down
34 changes: 22 additions & 12 deletions lib/dashing.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module.exports.Dashing = function Dashing() {
dashing.views = dashing.root + '/dashboards';
dashing.default_dashboard = null;
dashing.port = (process.env.PORT || 3030);
dashing.force_close_event_socket = false;

dashing.protected = function(req, res, next) {
next();
Expand Down Expand Up @@ -86,30 +87,39 @@ module.exports.Dashing = function Dashing() {
// let request last as long as possible
req.socket.setTimeout(0);

var conn = {
id: (new Date().getTime().toString() + Math.floor(Math.random() * 1000).toString()),
send: function(body) {
res.write(body);
res.flush(); // need to flush with .compress()
}
};
connections[conn.id] = conn;
if (!dashing.force_close_event_socket) {
// this won't be necessary if we close the connection after each data package
var conn = {
id: (new Date().getTime().toString() + Math.floor(Math.random() * 1000).toString()),
send: function(body) {
res.write(body);
res.flush(); // need to flush with .compress()
}
};
connections[conn.id] = conn;
}

// send headers for event-stream connection
res.writeHead(200, {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'X-Accel-Buffering': 'no' // Disable buffering for nginx
'X-Accel-Buffering': 'no', // Disable buffering for nginx
'Access-Control-Allow-Origin': '*' //fix XHR issue
});
res.write('\n');
res.write(Array(2049).join(' ') + '\n'); // 2kb padding for IE
res.write(latest_events());
res.flush(); // need to flush with .compress()

req.on('close', function() {
delete connections[conn.id];
});
if (!dashing.force_close_event_socket) {
req.on('close', function() {
delete connections[conn.id];
});
}
else {
res.end();
}
});

app.get('/', function(req, res) {
Expand Down
2 changes: 1 addition & 1 deletion templates/project/assets/javascripts/application.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#= require_directory .
#= require_tree ../../widgets

console.log("Yeah! The dashboard has started!")
#console.log("Yeah! The dashboard has started!")

Dashing.on 'ready', ->
Dashing.widget_margins ||= [5, 5]
Expand Down
2 changes: 1 addition & 1 deletion templates/project/dashboards/layout.jade
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ html(lang='en')
meta(charset='utf-8')
meta(name="description", content='')
meta(name="viewport", content='width=device-width')
meta(http-equiv='X-UA-Compatible', content='IE=edge,chrome=1')
meta(http-equiv='X-UA-Compatible', content='IE=9,chrome=1')
title
block title
| dashing-js
Expand Down

0 comments on commit e24bf02

Please sign in to comment.