diff --git a/lib/roles/app.js b/lib/roles/app.js index 0e5a8c3b..01a68246 100644 --- a/lib/roles/app.js +++ b/lib/roles/app.js @@ -505,6 +505,7 @@ module.exports = function(options) { } dbapi.addUserForward(user.email, data) .then(function() { + socket.emit('forward.create', data) joinChannel(responseChannel) push.send([ channel @@ -518,6 +519,7 @@ module.exports = function(options) { .on('forward.remove', function(channel, responseChannel, data) { dbapi.removeUserForward(user.email, data.devicePort) .then(function() { + socket.emit('forward.remove', data) joinChannel(responseChannel) push.send([ channel diff --git a/res/app/components/stf/user/user-service.js b/res/app/components/stf/user/user-service.js index 42bc7450..c6d32b3a 100644 --- a/res/app/components/stf/user/user-service.js +++ b/res/app/components/stf/user/user-service.js @@ -1,4 +1,4 @@ -module.exports = function UserServiceFactory($http) { +module.exports = function UserServiceFactory($http, $rootScope, socket) { var userService = {} userService.user = (function () { @@ -8,5 +8,23 @@ module.exports = function UserServiceFactory($http) { } })() + socket.on('forward.create', function(data) { + userService.user().then(function(user) { + $rootScope.$apply(function() { + user.forwards.push(data) + }) + }) + }) + + socket.on('forward.remove', function(data) { + userService.user().then(function(user) { + $rootScope.$apply(function() { + user.forwards = user.forwards.filter(function(forward) { + return forward.devicePort !== data.devicePort + }) + }) + }) + }) + return userService }