Skip to content

Commit

Permalink
Merge pull request #45 from rddill-IBM/events
Browse files Browse the repository at this point in the history
Events
  • Loading branch information
Bob Dill authored Oct 16, 2018
2 parents 585dd98 + dc75870 commit 60dbb1d
Show file tree
Hide file tree
Showing 190 changed files with 8,646 additions and 4,998 deletions.
Binary file removed Chapter04/favicon.ico
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ const BusinessNetworkDefinition = require('composer-common').BusinessNetworkDefi
const BusinessNetworkConnection = require('composer-client').BusinessNetworkConnection;
const config = require('../../../env.json');
const NS = 'org.acme.Z2BTestNetwork';
// const svc = require('./Z2B_Services');
// const mod = 'hlcAdmin.js';


/**
* display the admin and network info
Expand Down
43 changes: 5 additions & 38 deletions Chapter05/Documentation/answers/js/z2b-admin_complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

let creds;
let connection;
let msgPort = null;
let _blctr = 0;

/**
Expand All @@ -34,19 +33,6 @@ function loadAdminUX ()
listMemRegistries();
});
}
/**
* connect to the provided web socket
* @param {String} _target - location to post messages
* @param {Integer} _port - web socket port #
*/
function wsDisplay(_target, _port)
{
let content = $('#'+_target);
let wsSocket = new WebSocket('ws://localhost:'+_port);
wsSocket.onopen = function () {wsSocket.send('connected to client');};
wsSocket.onmessage = function (message) {content.append(formatMessage(message.data));};
wsSocket.onerror = function (error) {console.log('WebSocket error on wsSocket: ' + error);};
}
/**
* list the available business networks
*/
Expand Down Expand Up @@ -361,7 +347,7 @@ function preLoad()
$('#body').empty();
let options = {};
$.when($.post('/setup/autoLoad', options)).done(function (_results)
{ msgPort = _results.port; wsDisplay('body', msgPort); });
{ console.log('Autoload Initiated'); $('#body').append('<h2>Autoload Initiated</h2>'); });
}

/**
Expand Down Expand Up @@ -754,28 +740,9 @@ function getHistorian()
*/
function getChainEvents()
{
$.when($.get('fabric/getChainEvents')).done(function(_res)
{ let _str = '<h2> Get Chain events requested. Sending to port: '+_res.port+'</h2>';
let content = $('#blockchain');
let csSocket = new WebSocket('ws://localhost:'+_res.port);
csSocket.onopen = function () {csSocket.send('connected to client');};
csSocket.onmessage = function (message) {
_blctr ++;
if (message.data !== 'connected')
{$(content).append('<span class="block">block '+JSON.parse(message.data).header.number+'<br/>Hash: '+JSON.parse(message.data).header.data_hash+'</span>');
if (_blctr > 4) {let leftPos = $(content).scrollLeft(); $(content).animate({scrollLeft: leftPos + 300}, 250);}
}
};
csSocket.onerror = function (error) {console.log('WebSocket error: ' + error);};
$('#admin-forms').empty();
$('#admin-forms').append(_str);
$.when($.get('/fabric/getChainEvents')).done(function(_res)
{ $('#body').append('<h2> Get Chain events requested. </h2>');
let _host = (host_address.slice(0,9) === 'localhost') ? 'localhost' : host_address;
console.log('getChainEvents host_address: '+_host);
});
}
/**
* display blockchain updates
*/
function displayAdminUpdate()
{
let toLoad = 'adminHelp.html';
$.when($.get(toLoad)).done(function(_page){$('#admin-forms').empty(); $('#admin-forms').append(_page);});
}
Binary file modified Chapter05/HTML/favicon.ico
100755 → 100644
Binary file not shown.
35 changes: 5 additions & 30 deletions Chapter05/HTML/js/z2b-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

let creds;
let connection;
let msgPort = null;
let _blctr = 0;

/**
Expand All @@ -34,19 +33,6 @@ function loadAdminUX ()
listMemRegistries();
});
}
/**
* connect to the provided web socket
* @param {String} _target - location to post messages
* @param {Integer} _port - web socket port #
*/
function wsDisplay(_target, _port)
{
let content = $('#'+_target);
let wsSocket = new WebSocket('ws://localhost:'+_port);
wsSocket.onopen = function () {wsSocket.send('connected to client');};
wsSocket.onmessage = function (message) {content.append(formatMessage(message.data));};
wsSocket.onerror = function (error) {console.log('WebSocket error on wsSocket: ' + error);};
}
/**
* list the available business networks
*/
Expand Down Expand Up @@ -339,7 +325,7 @@ function preLoad()
$('#body').empty();
let options = {};
$.when($.post('/setup/autoLoad', options)).done(function (_results)
{ msgPort = _results.port; wsDisplay('body', msgPort); });
{ console.log('Autoload Initiated'); $('#body').append('<h2>Autoload Initiated</h2>'); });
}

/**
Expand Down Expand Up @@ -732,21 +718,10 @@ function getHistorian()
*/
function getChainEvents()
{
$.when($.get('fabric/getChainEvents')).done(function(_res)
{ let _str = '<h2> Get Chain events requested. Sending to port: '+_res.port+'</h2>';
let content = $('#blockchain');
let csSocket = new WebSocket('ws://localhost:'+_res.port);
csSocket.onopen = function () {csSocket.send('connected to client');};
csSocket.onmessage = function (message) {
_blctr ++;
if (message.data !== 'connected')
{$(content).append('<span class="block">block '+JSON.parse(message.data).header.number+'<br/>Hash: '+JSON.parse(message.data).header.data_hash+'</span>');
if (_blctr > 4) {let leftPos = $(content).scrollLeft(); $(content).animate({scrollLeft: leftPos + 300}, 250);}
}
};
csSocket.onerror = function (error) {console.log('WebSocket error: ' + error);};
$('#admin-forms').empty();
$('#admin-forms').append(_str);
$.when($.get('/fabric/getChainEvents')).done(function(_res)
{ $('#body').append('<h2> Get Chain events requested. </h2>');
let _host = (host_address.slice(0,9) === 'localhost') ? 'localhost' : host_address;
console.log('getChainEvents host_address: '+_host);
});
}
/**
Expand Down
Loading

0 comments on commit 60dbb1d

Please sign in to comment.