Merge pull request #131 from maraoz/bug/address-socket
fix address sockets
This commit is contained in:
commit
02b191e597
|
@ -23,7 +23,7 @@ module.exports.broadcast_block = function(block) {
|
|||
};
|
||||
|
||||
module.exports.broadcast_address_tx = function(address, tx) {
|
||||
ios.sockets.in(address).emit('atx', tx);
|
||||
ios.sockets.in(address).emit(address, tx);
|
||||
};
|
||||
|
||||
module.exports.broadcastSyncInfo = function(historicSync) {
|
||||
|
|
|
@ -1,29 +1,39 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('insight.address').controller('AddressController',
|
||||
function ($scope, $rootScope, $routeParams, $location, Global, Address, get_socket) {
|
||||
$scope.global = Global;
|
||||
function($scope, $rootScope, $routeParams, $location, Global, Address, get_socket) {
|
||||
$scope.global = Global;
|
||||
|
||||
$scope.findOne = function() {
|
||||
Address.get({
|
||||
addrStr: $routeParams.addrStr
|
||||
}, function(address) {
|
||||
$scope.address = address;
|
||||
}, function(e) {
|
||||
if (e.status === 400) {
|
||||
$rootScope.flashMessage = 'Invalid Address: ' + $routeParams.addrStr;
|
||||
}
|
||||
else if (e.status === 503) {
|
||||
$rootScope.flashMessage = 'Backend Error. ' + e.data;
|
||||
}
|
||||
else {
|
||||
$rootScope.flashMessage = 'Address Not Found';
|
||||
}
|
||||
$location.path('/');
|
||||
});
|
||||
};
|
||||
var socket = get_socket($scope);
|
||||
socket.emit('subscribe', $routeParams.addrStr);
|
||||
$scope.findOne = function() {
|
||||
Address.get({
|
||||
addrStr: $routeParams.addrStr
|
||||
},
|
||||
function(address) {
|
||||
$scope.address = address;
|
||||
},
|
||||
function(e) {
|
||||
if (e.status === 400) {
|
||||
$rootScope.flashMessage = 'Invalid Address: ' + $routeParams.addrStr;
|
||||
}
|
||||
else if (e.status === 503) {
|
||||
$rootScope.flashMessage = 'Backend Error. ' + e.data;
|
||||
}
|
||||
else {
|
||||
$rootScope.flashMessage = 'Address Not Found';
|
||||
}
|
||||
$location.path('/');
|
||||
});
|
||||
};
|
||||
var socket = get_socket($scope);
|
||||
socket.emit('subscribe', $routeParams.addrStr);
|
||||
socket.on($routeParams.addrStr, function(tx) {
|
||||
console.log('atx ' + tx.txid);
|
||||
var beep = new Audio('/sound/transaction.mp3');
|
||||
beep.play();
|
||||
$rootScope.$broadcast('tx', tx.txid);
|
||||
});
|
||||
|
||||
$scope.params = $routeParams;
|
||||
|
||||
$scope.params = $routeParams;
|
||||
});
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('insight.transactions').controller('transactionsController',
|
||||
function ($scope, $rootScope, $routeParams, $location, Global, Transaction, TransactionsByBlock, TransactionsByAddress, get_socket) {
|
||||
function ($scope, $rootScope, $routeParams, $location, Global, Transaction, TransactionsByBlock, TransactionsByAddress) {
|
||||
$scope.global = Global;
|
||||
$scope.loading = false;
|
||||
$scope.loadedBy = null;
|
||||
|
@ -144,14 +144,10 @@ angular.module('insight.transactions').controller('transactionsController',
|
|||
}
|
||||
};
|
||||
|
||||
var socket = get_socket($scope);
|
||||
socket.on('atx', function(tx) {
|
||||
console.log('atx '+tx.txid);
|
||||
var beep = new Audio('/sound/transaction.mp3');
|
||||
beep.play();
|
||||
$scope.findTx(tx.txid);
|
||||
});
|
||||
|
||||
$scope.txs = [];
|
||||
|
||||
$scope.$on('tx', function(event, txid) {
|
||||
$scope.findTx(txid);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -47,11 +47,13 @@ ScopedSocket.prototype.emit = function(event, data, callback) {
|
|||
};
|
||||
|
||||
angular.module('insight.socket').factory('get_socket',
|
||||
function($rootScope) {
|
||||
function($rootScope) {
|
||||
var socket = io.connect();
|
||||
return function(scope) {
|
||||
var scopedSocket = new ScopedSocket(socket, $rootScope);
|
||||
scope.$on('$destroy', function() {
|
||||
scope.$on('$routeChangeStart', function() {
|
||||
});
|
||||
scope.$on('$destroy', function() {
|
||||
scopedSocket.removeAllListeners();
|
||||
});
|
||||
return scopedSocket;
|
||||
|
|
Loading…
Reference in New Issue