mirror of
https://github.com/openstf/stf
synced 2025-10-05 02:29:26 +02:00
Allow only a single group per device.
This commit is contained in:
parent
6141bdb5ce
commit
6a7e10882f
2 changed files with 34 additions and 18 deletions
|
@ -26,6 +26,7 @@ module.exports = function(options) {
|
|||
, display = Object.create(null)
|
||||
, vendor = Object.create(null)
|
||||
, solo = wireutil.makePrivateChannel()
|
||||
, group = null
|
||||
, channels = new ChannelManager()
|
||||
, vitals = new Vitals()
|
||||
, ports = {
|
||||
|
@ -82,8 +83,9 @@ module.exports = function(options) {
|
|||
// Unsubscribe from temporary channels when they timeout
|
||||
channels.on('timeout', function(channel) {
|
||||
log.info('Channel "%s" timed out', channel)
|
||||
sub.unsubscribe(channel)
|
||||
push.send([channel, wireutil.makeLeaveGroupMessage(options.serial)])
|
||||
if (channel === group) {
|
||||
leaveGroup()
|
||||
}
|
||||
})
|
||||
|
||||
// Closure of vital functionality
|
||||
|
@ -334,24 +336,16 @@ module.exports = function(options) {
|
|||
channels.keepalive(channel)
|
||||
})
|
||||
.on(wire.GroupMessage, function(channel, message) {
|
||||
var groupChannel = message.channel
|
||||
if (devutil.matchesRequirements(identity, message.requirements)) {
|
||||
channels.register(groupChannel, message.timeout)
|
||||
log.info('Subscribing to group channel "%s"', groupChannel)
|
||||
sub.subscribe(groupChannel)
|
||||
push.send([groupChannel,
|
||||
wireutil.makeJoinGroupMessage(options.serial)])
|
||||
if (!isGrouped() &&
|
||||
devutil.matchesRequirements(identity, message.requirements)) {
|
||||
joinGroup(message.channel, message.timeout)
|
||||
}
|
||||
channels.keepalive(channel)
|
||||
})
|
||||
.on(wire.UngroupMessage, function(channel, message) {
|
||||
var groupChannel = message.channel
|
||||
if (devutil.matchesRequirements(identity, message.requirements)) {
|
||||
channels.unregister(groupChannel)
|
||||
log.info('Unsubscribing from group channel "%s"', groupChannel)
|
||||
sub.unsubscribe(groupChannel)
|
||||
push.send([groupChannel,
|
||||
wireutil.makeLeaveGroupMessage(options.serial)])
|
||||
if (isGrouped() &&
|
||||
devutil.matchesRequirements(identity, message.requirements)) {
|
||||
leaveGroup()
|
||||
}
|
||||
channels.keepalive(channel)
|
||||
})
|
||||
|
@ -413,6 +407,26 @@ module.exports = function(options) {
|
|||
wireutil.makeDevicePokeMessage(options.serial, solo)])
|
||||
}
|
||||
|
||||
function isGrouped() {
|
||||
return !!group
|
||||
}
|
||||
|
||||
function joinGroup(channel, timeout) {
|
||||
log.info('Subscribing to group channel "%s"', channel)
|
||||
channels.register(channel, timeout)
|
||||
sub.subscribe(channel)
|
||||
push.send([channel, wireutil.makeJoinGroupMessage(options.serial)])
|
||||
group = channel
|
||||
}
|
||||
|
||||
function leaveGroup() {
|
||||
log.info('Unsubscribing from group channel "%s"', group)
|
||||
channels.unregister(group)
|
||||
sub.unsubscribe(group)
|
||||
push.send([group, wireutil.makeLeaveGroupMessage(options.serial)])
|
||||
group = null
|
||||
}
|
||||
|
||||
function selfDestruct() {
|
||||
process.exit(1)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue