diff --git a/lib/db/api.js b/lib/db/api.js index 85389bf7..c1aa36b8 100644 --- a/lib/db/api.js +++ b/lib/db/api.js @@ -151,6 +151,8 @@ dbapi.saveDeviceInitialState = function(serial, device) { , statusChangedAt: r.now() , ready: false , reverseForwards: [] + , remoteConnect: false + , remoteDebugUrl: null } return db.run(r.table('devices').get(serial).update(data)) .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) { return db.run(r.table('devices').get(serial).update({ status: status diff --git a/lib/units/device/plugins/connect.js b/lib/units/device/plugins/connect.js index d058b176..55d93ef6 100644 --- a/lib/units/device/plugins/connect.js +++ b/lib/units/device/plugins/connect.js @@ -142,6 +142,15 @@ module.exports = syrup.serial() channel , 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) { log.error('Unable to start remote connect service', err.stack) @@ -159,6 +168,14 @@ module.exports = syrup.serial() channel , 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) { log.error('Failed to stop connect service', err.stack) diff --git a/lib/units/processor/index.js b/lib/units/processor/index.js index 7b022d91..733e6852 100644 --- a/lib/units/processor/index.js +++ b/lib/units/processor/index.js @@ -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) { dbapi.setDeviceOwner(message.serial, message.owner) appDealer.send([channel, data]) diff --git a/lib/util/datautil.js b/lib/util/datautil.js index dfbe6b00..8b04b368 100644 --- a/lib/util/datautil.js +++ b/lib/util/datautil.js @@ -54,10 +54,20 @@ datautil.applyOwner = function(device, user) { 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.applyData(device) datautil.applyBrowsers(device) datautil.applyOwner(device, user) + datautil.applyOwnerOnlyInfo(device, user) if (!device.present) { device.owner = null } diff --git a/lib/wire/wire.proto b/lib/wire/wire.proto index 868e507e..52215f09 100644 --- a/lib/wire/wire.proto +++ b/lib/wire/wire.proto @@ -76,6 +76,17 @@ enum MessageType { ReverseForwardsEvent = 72; FileSystemListMessage = 81; FileSystemGetMessage = 82; + ConnectStartedMessage = 92; + ConnectStoppedMessage = 93; +} + +message ConnectStartedMessage { + required string serial = 1; + required string url = 2; +} + +message ConnectStoppedMessage { + required string serial = 1; } message FileSystemListMessage {