mirror of
https://github.com/openstf/stf
synced 2025-10-05 19:42:01 +02:00
Invite/kick now uses transactions so that you can know whether the device actually joined or not. It's a bit messy right now, should introduce some sugar to make it cleaner.
This commit is contained in:
parent
b177d198b3
commit
be9d1c9579
3 changed files with 116 additions and 37 deletions
|
@ -342,15 +342,65 @@ module.exports = function(options) {
|
|||
wireutil.makeDeviceIdentityMessage(options.serial, identity)])
|
||||
})
|
||||
.on(wire.GroupMessage, function(channel, message) {
|
||||
if (!isGrouped() &&
|
||||
devutil.matchesRequirements(identity, message.requirements)) {
|
||||
joinGroup(message.owner, message.timeout)
|
||||
var seq = 0
|
||||
if (devutil.matchesRequirements(identity, message.requirements)) {
|
||||
if (!isGrouped()) {
|
||||
joinGroup(message.owner, message.timeout)
|
||||
push.send([
|
||||
channel
|
||||
, wireutil.envelope(new wire.TransactionDoneMessage(
|
||||
options.serial
|
||||
, seq++
|
||||
, true
|
||||
))
|
||||
])
|
||||
}
|
||||
else if (isOwnedBy(message.owner)) {
|
||||
push.send([
|
||||
channel
|
||||
, wireutil.envelope(new wire.TransactionDoneMessage(
|
||||
options.serial
|
||||
, seq++
|
||||
, true
|
||||
))
|
||||
])
|
||||
}
|
||||
else {
|
||||
push.send([
|
||||
channel
|
||||
, wireutil.envelope(new wire.TransactionDoneMessage(
|
||||
options.serial
|
||||
, seq++
|
||||
, false
|
||||
))
|
||||
])
|
||||
}
|
||||
}
|
||||
})
|
||||
.on(wire.UngroupMessage, function(channel, message) {
|
||||
if (isGrouped() &&
|
||||
devutil.matchesRequirements(identity, message.requirements)) {
|
||||
leaveGroup()
|
||||
var seq = 0
|
||||
if (devutil.matchesRequirements(identity, message.requirements)) {
|
||||
if (isGrouped()) {
|
||||
leaveGroup()
|
||||
push.send([
|
||||
channel
|
||||
, wireutil.envelope(new wire.TransactionDoneMessage(
|
||||
options.serial
|
||||
, seq++
|
||||
, true
|
||||
))
|
||||
])
|
||||
}
|
||||
else {
|
||||
push.send([
|
||||
channel
|
||||
, wireutil.envelope(new wire.TransactionDoneMessage(
|
||||
options.serial
|
||||
, seq++
|
||||
, true
|
||||
))
|
||||
])
|
||||
}
|
||||
}
|
||||
})
|
||||
.on(wire.TouchDownMessage, function(channel, message) {
|
||||
|
@ -526,6 +576,10 @@ module.exports = function(options) {
|
|||
])
|
||||
}
|
||||
|
||||
function isOwnedBy(someOwner) {
|
||||
return owner && owner.group == someOwner.group
|
||||
}
|
||||
|
||||
function joinGroup(newOwner, timeout) {
|
||||
log.info('Now owned by "%s"', newOwner.email)
|
||||
log.info('Subscribing to group channel "%s"', newOwner.group)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue