node events notifications

This commit is contained in:
cubedro 2015-02-18 08:06:41 +02:00
parent 71b1f7503a
commit 1959e77407
6 changed files with 36 additions and 7 deletions

14
app.js
View File

@ -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});
});
});

View File

@ -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);

View File

@ -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()

View File

@ -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();

View File

@ -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,

View File

@ -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 }}")