diff --git a/lib/db/api.js b/lib/db/api.js index ad5c6c91..adba788e 100644 --- a/lib/db/api.js +++ b/lib/db/api.js @@ -243,16 +243,18 @@ dbapi.setDeviceReverseForwards = function(serial, forwards) { })) } -dbapi.setDeviceChannel = function(serial, channel) { +dbapi.setDeviceReady = function(serial, channel) { return db.run(r.table('devices').get(serial).update({ channel: channel + , ready: true + , owner: null + , reverseForwards: [] })) } dbapi.saveDeviceIdentity = function(serial, identity) { return db.run(r.table('devices').get(serial).update({ - ready: true - , platform: identity.platform + platform: identity.platform , manufacturer: identity.manufacturer , operator: identity.operator , model: identity.model diff --git a/lib/units/device/plugins/solo.js b/lib/units/device/plugins/solo.js index 1f5eeae4..6655829d 100644 --- a/lib/units/device/plugins/solo.js +++ b/lib/units/device/plugins/solo.js @@ -51,7 +51,7 @@ module.exports = syrup.serial() , poke: function() { push.send([ wireutil.global - , wireutil.envelope(new wire.DevicePokeMessage( + , wireutil.envelope(new wire.DeviceReadyMessage( options.serial , channel )) diff --git a/lib/units/processor/index.js b/lib/units/processor/index.js index edb4555e..d2546e77 100644 --- a/lib/units/processor/index.js +++ b/lib/units/processor/index.js @@ -83,13 +83,15 @@ module.exports = function(options) { appDealer.send([channel, data]) }) // Worker initialized - .on(wire.DevicePokeMessage, function(channel, message) { - dbapi.setDeviceChannel(message.serial, message.channel) + .on(wire.DeviceReadyMessage, function(channel, message, data) { + dbapi.setDeviceReady(message.serial, message.channel) .then(function() { devDealer.send([ message.channel , wireutil.envelope(new wire.ProbeMessage()) ]) + + appDealer.send([channel, data]) }) }) // Worker messages diff --git a/lib/units/websocket/index.js b/lib/units/websocket/index.js index 194a9980..aa6a1955 100644 --- a/lib/units/websocket/index.js +++ b/lib/units/websocket/index.js @@ -134,6 +134,18 @@ module.exports = function(options) { } }) }) + .on(wire.DeviceReadyMessage, function(channel, message) { + socket.emit('device.change', { + important: true + , data: { + serial: message.serial + , channel: message.channel + , owner: null // @todo Get rid of need to reset this here. + , ready: true + , reverseForwards: [] // @todo Get rid of need to reset this here. + } + }) + }) .on(wire.DevicePresentMessage, function(channel, message) { socket.emit('device.change', { important: true @@ -192,7 +204,6 @@ module.exports = function(options) { }) .on(wire.DeviceIdentityMessage, function(channel, message) { datautil.applyData(message) - message.ready = true socket.emit('device.change', { important: true , data: message diff --git a/lib/wire/wire.proto b/lib/wire/wire.proto index 8113e4e1..e3e50b9b 100644 --- a/lib/wire/wire.proto +++ b/lib/wire/wire.proto @@ -7,7 +7,7 @@ enum MessageType { DeviceIdentityMessage = 2; DeviceLogcatEntryMessage = 3; DeviceLogMessage = 4; - DevicePokeMessage = 5; + DeviceReadyMessage = 5; DevicePresentMessage = 6; DevicePropertiesMessage = 7; DeviceRegisteredMessage = 8; @@ -136,7 +136,7 @@ message DeviceAbsentMessage { required string serial = 1; } -message DevicePokeMessage { +message DeviceReadyMessage { required string serial = 1; required string channel = 2; }