1
0
Fork 0
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:
Simo Kinnunen 2014-06-02 21:03:21 +09:00
parent 9239ee57b4
commit 3ea41c1a4e
4 changed files with 31 additions and 13 deletions

View file

@ -10,13 +10,14 @@ var grouputil = require('../../../util/grouputil')
var lifecycle = require('../../../util/lifecycle') var lifecycle = require('../../../util/lifecycle')
module.exports = syrup.serial() module.exports = syrup.serial()
.dependency(require('./solo'))
.dependency(require('./identity')) .dependency(require('./identity'))
.dependency(require('./service')) .dependency(require('./service'))
.dependency(require('../support/router')) .dependency(require('../support/router'))
.dependency(require('../support/push')) .dependency(require('../support/push'))
.dependency(require('../support/sub')) .dependency(require('../support/sub'))
.dependency(require('../support/channels')) .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') var log = logger.createLogger('device:plugins:group')
, currentGroup = null , currentGroup = null
, plugin = new events.EventEmitter() , plugin = new events.EventEmitter()
@ -44,7 +45,11 @@ module.exports = syrup.serial()
log.important('Now owned by "%s"', currentGroup.email) log.important('Now owned by "%s"', currentGroup.email)
log.info('Subscribing to group channel "%s"', currentGroup.group) 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) sub.subscribe(currentGroup.group)
push.send([ push.send([
@ -98,7 +103,7 @@ module.exports = syrup.serial()
router router
.on(wire.GroupMessage, function(channel, message) { .on(wire.GroupMessage, function(channel, message) {
var reply = wireutil.reply(options.serial) var reply = wireutil.reply(options.serial)
grouputil.match(identity, message.requirements) grouputil.match(ident, message.requirements)
.then(function() { .then(function() {
return plugin.join(message.owner, message.timeout) return plugin.join(message.owner, message.timeout)
}) })
@ -123,7 +128,7 @@ module.exports = syrup.serial()
}) })
.on(wire.UngroupMessage, function(channel, message) { .on(wire.UngroupMessage, function(channel, message) {
var reply = wireutil.reply(options.serial) var reply = wireutil.reply(options.serial)
grouputil.match(identity, message.requirements) grouputil.match(ident, message.requirements)
.then(function() { .then(function() {
return plugin.leave() return plugin.leave()
}) })

View file

@ -7,16 +7,14 @@ var wireutil = require('../../../wire/util')
module.exports = syrup.serial() module.exports = syrup.serial()
.dependency(require('../support/sub')) .dependency(require('../support/sub'))
.dependency(require('../support/push')) .dependency(require('../support/push'))
.dependency(require('../support/channels'))
.dependency(require('../support/router')) .dependency(require('../support/router'))
.dependency(require('./identity')) .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 log = logger.createLogger('device:plugins:solo')
var channel = wireutil.makePrivateChannel() var channel = wireutil.makePrivateChannel()
log.info('Subscribing to permanent channel "%s"', channel) log.info('Subscribing to permanent channel "%s"', channel)
sub.subscribe(channel) sub.subscribe(channel)
channels.register(channel, Infinity)
router.on(wire.ProbeMessage, function() { router.on(wire.ProbeMessage, function() {
push.send([ push.send([

View file

@ -6,8 +6,7 @@ var logger = require('../../../util/logger')
var wireutil = require('../../../wire/util') var wireutil = require('../../../wire/util')
module.exports = syrup.serial() module.exports = syrup.serial()
.dependency(require('./channels')) .define(function(options) {
.define(function(options, channels) {
var log = logger.createLogger('device:support:sub') var log = logger.createLogger('device:support:sub')
// Input // Input
@ -21,7 +20,6 @@ module.exports = syrup.serial()
;[wireutil.global].forEach(function(channel) { ;[wireutil.global].forEach(function(channel) {
log.info('Subscribing to permanent channel "%s"', channel) log.info('Subscribing to permanent channel "%s"', channel)
sub.subscribe(channel) sub.subscribe(channel)
channels.register(channel, Infinity)
}) })
return sub return sub

View file

@ -8,13 +8,27 @@ function ChannelManager() {
util.inherits(ChannelManager, events.EventEmitter) util.inherits(ChannelManager, events.EventEmitter)
ChannelManager.prototype.register = function(id, timeout) { ChannelManager.prototype.register = function(id, options) {
this.channels[id] = { var channel = this.channels[id] = {
timeout: timeout timeout: options.timeout
, alias: options.alias
, lastActivity: Date.now() , lastActivity: Date.now()
, timer: null , 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 // Set timer with initial check
this.check(id) this.check(id)
} }
@ -24,6 +38,9 @@ ChannelManager.prototype.unregister = function(id) {
if (channel) { if (channel) {
delete this.channels[id] delete this.channels[id]
clearTimeout(channel.timer) clearTimeout(channel.timer)
if (channel.alias) {
delete this.channels[channel.alias]
}
} }
} }