hello world version of address specific socket
This commit is contained in:
parent
542454e2fc
commit
5fe57077d7
@ -1,23 +1,31 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// server-side socket behaviour
|
// server-side socket behaviour
|
||||||
|
|
||||||
// io is a variable already taken in express
|
// io is a variable already taken in express
|
||||||
var ios = null;
|
var ios = null;
|
||||||
|
|
||||||
module.exports.init = function(app, io_ext) {
|
module.exports.init = function(app, io_ext) {
|
||||||
ios = io_ext;
|
ios = io_ext;
|
||||||
ios.set('log level', 1); // reduce logging
|
ios.set('log level', 1); // reduce logging
|
||||||
ios.sockets.on('connection', function() {
|
ios.sockets.on('connection', function(socket) {
|
||||||
|
socket.on('subscribe', function(topic) {
|
||||||
|
socket.join(topic);
|
||||||
|
if (topic !== 'inv') {
|
||||||
|
module.exports.broadcast_address_tx(topic, 'hello world');
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
module.exports.broadcast_tx = function(tx) {
|
module.exports.broadcast_tx = function(tx) {
|
||||||
ios.sockets.emit('tx', tx);
|
ios.sockets.in('inv').emit('tx', tx);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
module.exports.broadcast_block = function(block) {
|
module.exports.broadcast_block = function(block) {
|
||||||
ios.sockets.emit('block', block);
|
ios.sockets.in('inv').emit('block', block);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports.broadcast_address_tx = function(address, tx) {
|
||||||
|
ios.sockets.in(address).emit('tx', tx);
|
||||||
|
};
|
||||||
|
|
||||||
|
|||||||
@ -15,7 +15,6 @@ function spec() {
|
|||||||
|
|
||||||
PeerSync.prototype.init = function(config, cb) {
|
PeerSync.prototype.init = function(config, cb) {
|
||||||
if (!config) config = {};
|
if (!config) config = {};
|
||||||
var that = this;
|
|
||||||
|
|
||||||
var network = config && (config.network || 'testnet');
|
var network = config && (config.network || 'testnet');
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,13 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('insight.address').controller('AddressController', ['$scope', '$routeParams', '$location', 'Global', 'Address', function ($scope, $routeParams, $location, Global, Address) {
|
angular.module('insight.address').controller('AddressController',
|
||||||
|
['$scope',
|
||||||
|
'$routeParams',
|
||||||
|
'$location',
|
||||||
|
'Global',
|
||||||
|
'Address',
|
||||||
|
'socket',
|
||||||
|
function ($scope, $routeParams, $location, Global, Address, socket) {
|
||||||
$scope.global = Global;
|
$scope.global = Global;
|
||||||
|
|
||||||
$scope.findOne = function() {
|
$scope.findOne = function() {
|
||||||
@ -10,6 +17,12 @@ angular.module('insight.address').controller('AddressController', ['$scope', '$r
|
|||||||
$scope.address = address;
|
$scope.address = address;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
socket.on('connect', function() {
|
||||||
|
socket.emit('subscribe', $routeParams.addrStr);
|
||||||
|
});
|
||||||
|
socket.on('tx', function(data) {
|
||||||
|
console.log('Incoming message:', data);
|
||||||
|
});
|
||||||
|
|
||||||
$scope.params = $routeParams;
|
$scope.params = $routeParams;
|
||||||
}]);
|
}]);
|
||||||
|
|||||||
@ -2,9 +2,18 @@
|
|||||||
|
|
||||||
var TRANSACTION_DISPLAYED = 5;
|
var TRANSACTION_DISPLAYED = 5;
|
||||||
var BLOCKS_DISPLAYED = 5;
|
var BLOCKS_DISPLAYED = 5;
|
||||||
angular.module('insight.system').controller('IndexController', ['$scope', 'Global', 'socket', 'Blocks', 'Transactions', function($scope, Global, socket, Blocks, Transactions) {
|
angular.module('insight.system').controller('IndexController',
|
||||||
|
['$scope',
|
||||||
|
'Global',
|
||||||
|
'socket',
|
||||||
|
'Blocks',
|
||||||
|
'Transactions',
|
||||||
|
function($scope, Global, socket, Blocks, Transactions) {
|
||||||
$scope.global = Global;
|
$scope.global = Global;
|
||||||
|
|
||||||
|
socket.on('connect', function() {
|
||||||
|
socket.emit('subscribe', 'inv');
|
||||||
|
});
|
||||||
socket.on('tx', function(tx) {
|
socket.on('tx', function(tx) {
|
||||||
console.log('Transaction received! ' + JSON.stringify(tx));
|
console.log('Transaction received! ' + JSON.stringify(tx));
|
||||||
if ($scope.txs.length === TRANSACTION_DISPLAYED) {
|
if ($scope.txs.length === TRANSACTION_DISPLAYED) {
|
||||||
@ -15,9 +24,9 @@ angular.module('insight.system').controller('IndexController', ['$scope', 'Globa
|
|||||||
|
|
||||||
socket.on('block', function(block) {
|
socket.on('block', function(block) {
|
||||||
console.log('Block received! ' + JSON.stringify(block));
|
console.log('Block received! ' + JSON.stringify(block));
|
||||||
if ($scope.blocks.length === BLOCKS_DISPLAYED) {
|
if ($scope.blocks.length === BLOCKS_DISPLAYED) {
|
||||||
$scope.blocks.pop();
|
$scope.blocks.pop();
|
||||||
}
|
}
|
||||||
$scope.blocks.unshift(block);
|
$scope.blocks.unshift(block);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user