node events notifications

pull/5/head
cubedro 10 years ago
parent 71b1f7503a
commit 1959e77407
  1. 14
      app.js
  2. 12
      models/collection.js
  3. 6
      models/node.js
  4. 5
      public/js/controllers.js
  5. 2
      public/js/services.js
  6. 4
      views/index.jade

@ -34,13 +34,15 @@ api.on('connection', function(spark) {
console.log(spark.address);
console.log(spark.query);
spark.on('hello', function(data) {
spark.on('hello', function(data)
{
console.log('got hello data from ', spark.id);
console.log(data);
if(typeof data.id !== 'undefined' && typeof data.info !== 'undefined')
{
data.ip = spark.address.ip;
data.spark = spark.id;
var info = Nodes.add(data);
spark.emit('ready');
@ -49,7 +51,8 @@ api.on('connection', function(spark) {
}
});
spark.on('update', function(data) {
spark.on('update', function(data)
{
console.log('got update from ' + spark.id);
console.log(data);
@ -61,8 +64,11 @@ api.on('connection', function(spark) {
}
});
spark.on('end', function(data) {
//
spark.on('end', function(data)
{
var stats = Nodes.inactive(spark.id);
client.write({action: 'inactive', data: stats});
});
});

@ -28,6 +28,18 @@ Collection.prototype.update = function(id, stats)
return node.getStats();
}
Collection.prototype.inactive = function(id)
{
var node = this.getNode({ spark: id });
if(!node)
return false;
node.stats.active = false;
return node.getStats();
}
Collection.prototype.getIndex = function(search)
{
return _.findIndex(this._list, search);

@ -36,6 +36,9 @@ var Node = function Node(data)
this.setGeo(data.ip);
}
if(typeof data.spark !== 'undefined')
this.spark = data.spark;
return this;
}
@ -53,6 +56,9 @@ Node.prototype.setInfo = function(data)
this.info.ip = data.ip;
this.setGeo(data.ip);
}
if(typeof data.spark !== 'undefined')
this.spark = data.spark;
}
Node.prototype.getInfo = function()

@ -69,6 +69,11 @@ function StatsCtrl($scope, $filter, socket, _, toastr) {
case "info":
$scope.nodes[findIndex({id: data.id})].info = data.info;
break;
case "inactive":
$scope.nodes[findIndex({id: data.id})].stats = data.stats;
toastr['error']("Node went away!", "Node connection was lost!");
break;
}
updateStats();

@ -32,7 +32,7 @@ app.factory('toastr', function ($rootScope) {
toastr.options = {
"closeButton": false,
"debug": false,
"progressBar": true,
"progressBar": false,
"newestOnTop": true,
"positionClass": "toast-top-right",
"preventDuplicates": false,

@ -6,7 +6,7 @@ block content
div.col-lg-6(ng-cloak)
div.col-sm-12
h1= title
p Welcome to #{title}
//- p Welcome to #{title}
div.clearfix
@ -79,7 +79,7 @@ block content
div.small {{node.info.ip}}
td.small
div.small(ng-bind-html="node.info.node | nodeVersion")
div.small {{node.info.os}}, {{node.info.os_v}}
//- div.small {{node.info.os}}, {{node.info.os_v}}
td(class="{{ node.stats.peers | peerClass }}") {{node.stats.peers}}
td(class="{{ node.stats.mining | miningClass }}")
i(class="{{ node.stats.mining | miningIconClass }}")

Loading…
Cancel
Save