Files
stf/lib/units/device/plugins/solo.js
thinkhy 2dac3d1bbd add the column of CPU Platform in device list (#777)
* add the column of CPU Platform in device list

* Update api.js

* Update solo.js

* Update devutil.js

* Update device-column-service.js

* Update device-list-controller.js
2017-12-16 16:50:25 +08:00

63 lines
1.7 KiB
JavaScript

var crypto = require('crypto')
var syrup = require('stf-syrup')
var logger = require('../../../util/logger')
var wire = require('../../../wire')
var wireutil = require('../../../wire/util')
module.exports = syrup.serial()
.dependency(require('../support/sub'))
.dependency(require('../support/push'))
.dependency(require('../support/router'))
.dependency(require('./util/identity'))
.define(function(options, sub, push, router, identity) {
var log = logger.createLogger('device:plugins:solo')
// The channel should keep the same value between restarts, so that
// having the client side up to date all the time is not horribly painful.
function makeChannelId() {
var hash = crypto.createHash('sha1')
hash.update(options.serial)
return hash.digest('base64')
}
var channel = makeChannelId()
log.info('Subscribing to permanent channel "%s"', channel)
sub.subscribe(channel)
router.on(wire.ProbeMessage, function() {
push.send([
wireutil.global
, wireutil.envelope(new wire.DeviceIdentityMessage(
options.serial
, identity.platform
, identity.manufacturer
, identity.operator
, identity.model
, identity.version
, identity.abi
, identity.sdk
, new wire.DeviceDisplayMessage(identity.display)
, new wire.DevicePhoneMessage(identity.phone)
, identity.product
, identity.cpuPlatform
))
])
})
return {
channel: channel
, poke: function() {
push.send([
wireutil.global
, wireutil.envelope(new wire.DeviceReadyMessage(
options.serial
, channel
))
])
}
}
})