diff --git a/endpoint.js b/endpoint.js index 1f473b0c1bcb5bfd941825432ce2865671676a20..b6b61410e52c1b4593f291668c0f4a75769c7dc5 100644 --- a/endpoint.js +++ b/endpoint.js @@ -14,7 +14,8 @@ let is_path = function (to_test, endpoint) { class BMAEndpoint{ - constructor(raw_endpoint) { + constructor(raw_endpoint, pubkey) { + this.pubkey = pubkey let infos = raw_endpoint.split(" "); this.type = this.get_endpoint_type(infos); @@ -33,6 +34,7 @@ class BMAEndpoint{ // TODO manage IPv4/v6 this.has_url = this.create_root_url(); + this.is_member(); } get_endpoint_type(raw_endpoint_array) { @@ -162,8 +164,27 @@ class BMAEndpoint{ this.row = document.createElement('tr') fields.forEach(field => { let cell = document.createElement('td') - cell.innerText = (this[field] == undefined) ? '' : this[field] + cell.innerText = (this[field] == undefined) ? 'ø' : this[field] this.row.appendChild(cell) }); } + + get_version = async function() { + return fetch(this.url_protocol + this.url_root + '/node/summary/') + .then(response => response.json()) + .then(data => this.version = data.duniter.version) + .catch(error => { this.version = "ø" }) + } + + is_member = async function() { + let url = this.url_protocol + this.url_root + '/wot/identity-of/' + this.pubkey + console.log(url) + return fetch(url) + .then(response => response.json()) + .then(data => { + this.member = (data.pubkey ? 'Oui' : 'Non') + }) + .catch(error => { this.member = "ø" }) + + } } \ No newline at end of file diff --git a/index.html b/index.html index e2c53a6aa4d7244ea92405ee270c0ae0b7c4b2dc..6b7e532665dda4f2803801e7a7abe8576742f0d7 100644 --- a/index.html +++ b/index.html @@ -45,6 +45,8 @@ <th>Bloc</th> <th>Type</th> <th>Rapidité (ms)</th> + <th>version</th> + <th>Membre</th> </tr> </thead> </table> diff --git a/node.js b/node.js index a459778a85e53cabbf2784f9bf343dfe31a502e8..4ed6dd2c8c5859a8c9def2a468daaabb456e7be8 100644 --- a/node.js +++ b/node.js @@ -1,7 +1,7 @@ class DuniterNodes { constructor (peers) { - this.fields = ['url_root', 'head_block', 'type', 'speed'] + this.fields = ['url_root', 'head_block', 'type', 'speed', 'version', 'member'] this.ep_body = document.createElement('tbody') this.draw() @@ -21,7 +21,7 @@ class DuniterNodes peers.forEach(peer => { let endpoints = peer.endpoints; endpoints.forEach(endpoint => { - let ep = new BMAEndpoint(endpoint) + let ep = new BMAEndpoint(endpoint, peer.pubkey) if (ep.has_url) { this.endpoints.push(ep) } @@ -38,6 +38,7 @@ class DuniterNodes ep.draw_row(fields) this.insert(ep) }) + ep.get_version() }) } @@ -100,6 +101,7 @@ class DuniterNodes let rows = this.ep_body.childNodes rows.forEach(row => { let cells = row.childNodes + switch (cells[1].innerText) { case consensus_block: cells[1].setAttribute('class', 'consensus') @@ -107,13 +109,22 @@ class DuniterNodes case 'undefined': cells[1].setAttribute('class', 'unreachable') break - case '': + case 'ø': cells[1].setAttribute('class', 'unreachable') break default: cells[1].setAttribute('class', 'desynchronized') break } + + switch(cells[5].innerText) { + case 'Oui': + cells[5].setAttribute('class', 'consensus') + break + case 'Non': + cells[5].setAttribute('class', 'desynchronized') + break + } }) }