mirror of
https://github.com/openstf/stf
synced 2025-10-05 10:39:25 +02:00
Fix direct device control not extending owner timeout.
This commit is contained in:
parent
9239ee57b4
commit
3ea41c1a4e
4 changed files with 31 additions and 13 deletions
|
@ -10,13 +10,14 @@ var grouputil = require('../../../util/grouputil')
|
|||
var lifecycle = require('../../../util/lifecycle')
|
||||
|
||||
module.exports = syrup.serial()
|
||||
.dependency(require('./solo'))
|
||||
.dependency(require('./identity'))
|
||||
.dependency(require('./service'))
|
||||
.dependency(require('../support/router'))
|
||||
.dependency(require('../support/push'))
|
||||
.dependency(require('../support/sub'))
|
||||
.dependency(require('../support/channels'))
|
||||
.define(function(options, identity, service, router, push, sub, channels) {
|
||||
.define(function(options, solo, ident, service, router, push, sub, channels) {
|
||||
var log = logger.createLogger('device:plugins:group')
|
||||
, currentGroup = null
|
||||
, plugin = new events.EventEmitter()
|
||||
|
@ -44,7 +45,11 @@ module.exports = syrup.serial()
|
|||
log.important('Now owned by "%s"', currentGroup.email)
|
||||
log.info('Subscribing to group channel "%s"', currentGroup.group)
|
||||
|
||||
channels.register(currentGroup.group, timeout || options.groupTimeout)
|
||||
channels.register(currentGroup.group, {
|
||||
timeout: timeout || options.groupTimeout
|
||||
, alias: solo.channel
|
||||
})
|
||||
|
||||
sub.subscribe(currentGroup.group)
|
||||
|
||||
push.send([
|
||||
|
@ -98,7 +103,7 @@ module.exports = syrup.serial()
|
|||
router
|
||||
.on(wire.GroupMessage, function(channel, message) {
|
||||
var reply = wireutil.reply(options.serial)
|
||||
grouputil.match(identity, message.requirements)
|
||||
grouputil.match(ident, message.requirements)
|
||||
.then(function() {
|
||||
return plugin.join(message.owner, message.timeout)
|
||||
})
|
||||
|
@ -123,7 +128,7 @@ module.exports = syrup.serial()
|
|||
})
|
||||
.on(wire.UngroupMessage, function(channel, message) {
|
||||
var reply = wireutil.reply(options.serial)
|
||||
grouputil.match(identity, message.requirements)
|
||||
grouputil.match(ident, message.requirements)
|
||||
.then(function() {
|
||||
return plugin.leave()
|
||||
})
|
||||
|
|
|
@ -7,16 +7,14 @@ var wireutil = require('../../../wire/util')
|
|||
module.exports = syrup.serial()
|
||||
.dependency(require('../support/sub'))
|
||||
.dependency(require('../support/push'))
|
||||
.dependency(require('../support/channels'))
|
||||
.dependency(require('../support/router'))
|
||||
.dependency(require('./identity'))
|
||||
.define(function(options, sub, push, channels, router, identity) {
|
||||
.define(function(options, sub, push, router, identity) {
|
||||
var log = logger.createLogger('device:plugins:solo')
|
||||
var channel = wireutil.makePrivateChannel()
|
||||
|
||||
log.info('Subscribing to permanent channel "%s"', channel)
|
||||
sub.subscribe(channel)
|
||||
channels.register(channel, Infinity)
|
||||
|
||||
router.on(wire.ProbeMessage, function() {
|
||||
push.send([
|
||||
|
|
|
@ -6,8 +6,7 @@ var logger = require('../../../util/logger')
|
|||
var wireutil = require('../../../wire/util')
|
||||
|
||||
module.exports = syrup.serial()
|
||||
.dependency(require('./channels'))
|
||||
.define(function(options, channels) {
|
||||
.define(function(options) {
|
||||
var log = logger.createLogger('device:support:sub')
|
||||
|
||||
// Input
|
||||
|
@ -21,7 +20,6 @@ module.exports = syrup.serial()
|
|||
;[wireutil.global].forEach(function(channel) {
|
||||
log.info('Subscribing to permanent channel "%s"', channel)
|
||||
sub.subscribe(channel)
|
||||
channels.register(channel, Infinity)
|
||||
})
|
||||
|
||||
return sub
|
||||
|
|
|
@ -8,13 +8,27 @@ function ChannelManager() {
|
|||
|
||||
util.inherits(ChannelManager, events.EventEmitter)
|
||||
|
||||
ChannelManager.prototype.register = function(id, timeout) {
|
||||
this.channels[id] = {
|
||||
timeout: timeout
|
||||
ChannelManager.prototype.register = function(id, options) {
|
||||
var channel = this.channels[id] = {
|
||||
timeout: options.timeout
|
||||
, alias: options.alias
|
||||
, lastActivity: Date.now()
|
||||
, timer: null
|
||||
}
|
||||
|
||||
if (channel.alias) {
|
||||
// The alias can only be active for a single channel at a time
|
||||
if (this.channels[channel.alias]) {
|
||||
throw new Error(util.format(
|
||||
'Cannot create alias "%s" for "%s"; the channel already exists'
|
||||
, channel.alias
|
||||
, id
|
||||
))
|
||||
}
|
||||
|
||||
this.channels[channel.alias] = channel
|
||||
}
|
||||
|
||||
// Set timer with initial check
|
||||
this.check(id)
|
||||
}
|
||||
|
@ -24,6 +38,9 @@ ChannelManager.prototype.unregister = function(id) {
|
|||
if (channel) {
|
||||
delete this.channels[id]
|
||||
clearTimeout(channel.timer)
|
||||
if (channel.alias) {
|
||||
delete this.channels[channel.alias]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue