mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-20 07:53:38 +02:00
Add owners to groups.
This commit is contained in:
@@ -25,8 +25,8 @@ module.exports = function(options) {
|
||||
, identity = Object.create(null)
|
||||
, display = Object.create(null)
|
||||
, vendor = Object.create(null)
|
||||
, owner = null
|
||||
, solo = wireutil.makePrivateChannel()
|
||||
, group = null
|
||||
, channels = new ChannelManager()
|
||||
, vitals = new Vitals()
|
||||
, ports = {
|
||||
@@ -83,7 +83,7 @@ module.exports = function(options) {
|
||||
// Unsubscribe from temporary channels when they timeout
|
||||
channels.on('timeout', function(channel) {
|
||||
log.info('Channel "%s" timed out', channel)
|
||||
if (channel === group) {
|
||||
if (channel === owner.group) {
|
||||
leaveGroup()
|
||||
}
|
||||
})
|
||||
@@ -342,7 +342,7 @@ module.exports = function(options) {
|
||||
.on(wire.GroupMessage, function(channel, message) {
|
||||
if (!isGrouped() &&
|
||||
devutil.matchesRequirements(identity, message.requirements)) {
|
||||
joinGroup(message.channel, message.timeout)
|
||||
joinGroup(message.owner, message.timeout)
|
||||
}
|
||||
channels.keepalive(channel)
|
||||
})
|
||||
@@ -436,23 +436,37 @@ module.exports = function(options) {
|
||||
}
|
||||
|
||||
function isGrouped() {
|
||||
return !!group
|
||||
return !!owner
|
||||
}
|
||||
|
||||
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 joinGroup(newOwner, timeout) {
|
||||
log.info('Now owned by "%s"', newOwner.email)
|
||||
log.info('Subscribing to group channel "%s"', newOwner.group)
|
||||
channels.register(newOwner.group, timeout)
|
||||
sub.subscribe(newOwner.group)
|
||||
push.send([
|
||||
wireutil.global
|
||||
, wireutil.envelope(new wire.JoinGroupMessage(
|
||||
options.serial
|
||||
, newOwner
|
||||
))
|
||||
])
|
||||
owner = newOwner
|
||||
}
|
||||
|
||||
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
|
||||
log.info('No longer owned by "%s"', owner.email)
|
||||
log.info('Unsubscribing from group channel "%s"', owner.group)
|
||||
channels.unregister(owner.group)
|
||||
sub.unsubscribe(owner.group)
|
||||
push.send([
|
||||
wireutil.global
|
||||
, wireutil.envelope(new wire.LeaveGroupMessage(
|
||||
options.serial
|
||||
, owner
|
||||
))
|
||||
])
|
||||
owner = null
|
||||
}
|
||||
|
||||
function selfDestruct() {
|
||||
|
||||
Reference in New Issue
Block a user