Files
stf-DeviceFarmer/lib/units/device/plugins/solo.js
2024-11-29 11:02:11 +01:00

69 lines
1.9 KiB
JavaScript

/**
* Copyright © 2024 contains code contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
**/
var crypto = require('crypto')
var syrup = require('@devicefarmer/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(Object.assign({}, identity.phone))
, identity.product
, identity.cpuPlatform
, identity.openGLESVersion
, identity.marketName
))
])
})
return {
channel: channel
, poke: function() {
push.send([
wireutil.global
, wireutil.envelope(new wire.DeviceReadyMessage(
options.serial
, channel
))
])
}
}
})