diff --git a/app/controllers/socket.js b/app/controllers/socket.js index 25a846e..3b19c11 100644 --- a/app/controllers/socket.js +++ b/app/controllers/socket.js @@ -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) { diff --git a/public/js/controllers/address.js b/public/js/controllers/address.js index fde4660..016da8b 100644 --- a/public/js/controllers/address.js +++ b/public/js/controllers/address.js @@ -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; }); + diff --git a/public/js/controllers/transactions.js b/public/js/controllers/transactions.js index 6190c43..05d54ff 100644 --- a/public/js/controllers/transactions.js +++ b/public/js/controllers/transactions.js @@ -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); + }); + }); diff --git a/public/js/services/socket.js b/public/js/services/socket.js index 6dc0749..b1efff4 100644 --- a/public/js/services/socket.js +++ b/public/js/services/socket.js @@ -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;