mirror of
https://github.com/openstf/stf
synced 2025-10-05 02:29:26 +02:00
add remoteDebugUrl into database so that it is accessible from api
This commit is contained in:
parent
c9a9d3cb06
commit
232163d290
5 changed files with 60 additions and 0 deletions
|
@ -151,6 +151,8 @@ dbapi.saveDeviceInitialState = function(serial, device) {
|
||||||
, statusChangedAt: r.now()
|
, statusChangedAt: r.now()
|
||||||
, ready: false
|
, ready: false
|
||||||
, reverseForwards: []
|
, reverseForwards: []
|
||||||
|
, remoteConnect: false
|
||||||
|
, remoteDebugUrl: null
|
||||||
}
|
}
|
||||||
return db.run(r.table('devices').get(serial).update(data))
|
return db.run(r.table('devices').get(serial).update(data))
|
||||||
.then(function(stats) {
|
.then(function(stats) {
|
||||||
|
@ -163,6 +165,20 @@ dbapi.saveDeviceInitialState = function(serial, device) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dbapi.setDeviceConnectUrl = function(serial, url) {
|
||||||
|
return db.run(r.table('devices').get(serial).update({
|
||||||
|
remoteDebugUrl: url
|
||||||
|
, remoteConnect: true
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
dbapi.unsetDeviceConnectUrl = function(serial, url) {
|
||||||
|
return db.run(r.table('devices').get(serial).update({
|
||||||
|
remoteDebugUrl: null
|
||||||
|
, remoteConnect: false
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
dbapi.saveDeviceStatus = function(serial, status) {
|
dbapi.saveDeviceStatus = function(serial, status) {
|
||||||
return db.run(r.table('devices').get(serial).update({
|
return db.run(r.table('devices').get(serial).update({
|
||||||
status: status
|
status: status
|
||||||
|
|
|
@ -142,6 +142,15 @@ module.exports = syrup.serial()
|
||||||
channel
|
channel
|
||||||
, reply.okay(url)
|
, reply.okay(url)
|
||||||
])
|
])
|
||||||
|
// Update DB
|
||||||
|
push.send([
|
||||||
|
wireutil.global
|
||||||
|
, wireutil.envelope(new wire.ConnectStartedMessage(
|
||||||
|
options.serial
|
||||||
|
, url
|
||||||
|
))
|
||||||
|
])
|
||||||
|
log.info('Remote Connect Started for device "%s" at "%s"', options.serial, url)
|
||||||
})
|
})
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
log.error('Unable to start remote connect service', err.stack)
|
log.error('Unable to start remote connect service', err.stack)
|
||||||
|
@ -159,6 +168,14 @@ module.exports = syrup.serial()
|
||||||
channel
|
channel
|
||||||
, reply.okay()
|
, reply.okay()
|
||||||
])
|
])
|
||||||
|
// Update DB
|
||||||
|
push.send([
|
||||||
|
wireutil.global
|
||||||
|
, wireutil.envelope(new wire.ConnectStoppedMessage(
|
||||||
|
options.serial
|
||||||
|
))
|
||||||
|
])
|
||||||
|
log.info('Remote Connect Stopped for device "%s"', options.serial)
|
||||||
})
|
})
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
log.error('Failed to stop connect service', err.stack)
|
log.error('Failed to stop connect service', err.stack)
|
||||||
|
|
|
@ -165,6 +165,12 @@ module.exports = function(options) {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
.on(wire.ConnectStartedMessage, function(channel, message, data) {
|
||||||
|
dbapi.setDeviceConnectUrl(message.serial, message.url)
|
||||||
|
})
|
||||||
|
.on(wire.ConnectStoppedMessage, function(channel, message, data) {
|
||||||
|
dbapi.unsetDeviceConnectUrl(message.serial)
|
||||||
|
})
|
||||||
.on(wire.JoinGroupMessage, function(channel, message, data) {
|
.on(wire.JoinGroupMessage, function(channel, message, data) {
|
||||||
dbapi.setDeviceOwner(message.serial, message.owner)
|
dbapi.setDeviceOwner(message.serial, message.owner)
|
||||||
appDealer.send([channel, data])
|
appDealer.send([channel, data])
|
||||||
|
|
|
@ -54,10 +54,20 @@ datautil.applyOwner = function(device, user) {
|
||||||
return device
|
return device
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only owner can see this information
|
||||||
|
datautil.applyOwnerOnlyInfo = function(device, user) {
|
||||||
|
if (device.owner && device.owner.email === user.email) {
|
||||||
|
} else {
|
||||||
|
device.remoteConnect = false
|
||||||
|
device.remoteDebugUrl = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
datautil.normalize = function(device, user) {
|
datautil.normalize = function(device, user) {
|
||||||
datautil.applyData(device)
|
datautil.applyData(device)
|
||||||
datautil.applyBrowsers(device)
|
datautil.applyBrowsers(device)
|
||||||
datautil.applyOwner(device, user)
|
datautil.applyOwner(device, user)
|
||||||
|
datautil.applyOwnerOnlyInfo(device, user)
|
||||||
if (!device.present) {
|
if (!device.present) {
|
||||||
device.owner = null
|
device.owner = null
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,17 @@ enum MessageType {
|
||||||
ReverseForwardsEvent = 72;
|
ReverseForwardsEvent = 72;
|
||||||
FileSystemListMessage = 81;
|
FileSystemListMessage = 81;
|
||||||
FileSystemGetMessage = 82;
|
FileSystemGetMessage = 82;
|
||||||
|
ConnectStartedMessage = 92;
|
||||||
|
ConnectStoppedMessage = 93;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ConnectStartedMessage {
|
||||||
|
required string serial = 1;
|
||||||
|
required string url = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ConnectStoppedMessage {
|
||||||
|
required string serial = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message FileSystemListMessage {
|
message FileSystemListMessage {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue