1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 18:29:17 +02:00

Tell the UI why the device became unusable.

This commit is contained in:
Simo Kinnunen 2014-07-23 17:58:08 +09:00
parent d8dec38cad
commit 0ec8082ac1
3 changed files with 10 additions and 4 deletions

View file

@ -72,7 +72,7 @@ module.exports = syrup.serial()
} }
} }
plugin.leave = function() { plugin.leave = function(reason) {
return plugin.get() return plugin.get()
.then(function(group) { .then(function(group) {
log.important('No longer owned by "%s"', group.email) log.important('No longer owned by "%s"', group.email)
@ -86,6 +86,7 @@ module.exports = syrup.serial()
, wireutil.envelope(new wire.LeaveGroupMessage( , wireutil.envelope(new wire.LeaveGroupMessage(
options.serial options.serial
, group , group
, reason
)) ))
]) ])
@ -136,7 +137,7 @@ module.exports = syrup.serial()
var reply = wireutil.reply(options.serial) var reply = wireutil.reply(options.serial)
grouputil.match(ident, message.requirements) grouputil.match(ident, message.requirements)
.then(function() { .then(function() {
return plugin.leave() return plugin.leave('ungroup_request')
}) })
.then(function() { .then(function() {
push.send([ push.send([
@ -154,12 +155,12 @@ module.exports = syrup.serial()
channels.on('timeout', function(channel) { channels.on('timeout', function(channel) {
if (currentGroup && channel === currentGroup.group) { if (currentGroup && channel === currentGroup.group) {
plugin.leave() plugin.leave('automatic_timeout')
} }
}) })
lifecycle.observe(function() { lifecycle.observe(function() {
return plugin.leave() return plugin.leave('lifecycle_ended')
.catch(grouputil.NoGroupError, function() { .catch(grouputil.NoGroupError, function() {
return true return true
}) })

View file

@ -130,6 +130,7 @@ module.exports = function(options) {
, ready: false , ready: false
, lastHeartbeatAt: null , lastHeartbeatAt: null
, using: false , using: false
, likelyLeaveReason: 'device_absent'
} }
}) })
}) })
@ -139,6 +140,7 @@ module.exports = function(options) {
, data: datautil.applyOwner({ , data: datautil.applyOwner({
serial: message.serial serial: message.serial
, owner: message.owner , owner: message.owner
, likelyLeaveReason: 'owner_change'
} }
, user , user
) )
@ -150,12 +152,14 @@ module.exports = function(options) {
, data: datautil.applyOwner({ , data: datautil.applyOwner({
serial: message.serial serial: message.serial
, owner: null , owner: null
, likelyLeaveReason: message.reason
} }
, user , user
) )
}) })
}) })
.on(wire.DeviceStatusMessage, function(channel, message) { .on(wire.DeviceStatusMessage, function(channel, message) {
message.likelyLeaveReason = 'status_change'
socket.emit('device.change', { socket.emit('device.change', {
important: true important: true
, data: message , data: message

View file

@ -236,6 +236,7 @@ message JoinGroupMessage {
message LeaveGroupMessage { message LeaveGroupMessage {
required string serial = 1; required string serial = 1;
required OwnerMessage owner = 2; required OwnerMessage owner = 2;
required string reason = 3;
} }
// Input // Input