Keep forwards list up to date on client side.

This commit is contained in:
Simo Kinnunen
2014-04-15 18:02:48 +09:00
parent b0400130ff
commit fb3892ab07
2 changed files with 21 additions and 1 deletions

View File

@@ -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
}