diff --git a/lib/units/device/plugins/forward.js b/lib/units/device/plugins/forward.js index 33526d3a..9d70b51f 100644 --- a/lib/units/device/plugins/forward.js +++ b/lib/units/device/plugins/forward.js @@ -15,7 +15,8 @@ module.exports = syrup.serial() .dependency(require('../support/router')) .dependency(require('../support/push')) .dependency(require('../resources/minirev')) - .define(function(options, adb, router, push, minirev) { + .dependency(require('./group')) + .define(function(options, adb, router, push, minirev, group) { var log = logger.createLogger('device:plugins:forward') var plugin = Object.create(null) @@ -99,6 +100,12 @@ module.exports = syrup.serial() forwards[port].end() } } + + this.removeAll = function() { + Object.keys(forwards).forEach(function(port) { + forwards[port].end() + }) + } } var manager = new ForwardManager() @@ -187,6 +194,12 @@ module.exports = syrup.serial() }) } + plugin.reset = function() { + manager.removeAll() + } + + group.on('leave', plugin.reset) + return startService() .then(awaitServer) .then(function() {