1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-05 02:29:26 +02:00

Integrate new minicap along with a moderate rewrite. What's currently missing is recovering from socket death.

This commit is contained in:
Simo Kinnunen 2015-04-15 18:55:46 +09:00
parent 6fe4f8ae1b
commit 95e9dd0b82
43 changed files with 1138 additions and 438 deletions

View file

@ -1,25 +1,71 @@
var util = require('util')
var syrup = require('stf-syrup')
var EventEmitter = require('eventemitter3').EventEmitter
var logger = require('../../../util/logger')
var streamutil = require('../../../util/streamutil')
module.exports = syrup.serial()
.dependency(require('../support/adb'))
.dependency(require('../resources/minicap'))
.dependency(require('./service'))
.dependency(require('./screen'))
.define(function(options, service, screen) {
.dependency(require('./screen/options'))
.define(function(options, adb, minicap, service, screenOptions) {
var log = logger.createLogger('device:plugins:display')
function fetch() {
log.info('Fetching display info')
return service.getDisplay(0)
.catch(function() {
log.info('Falling back to screen API')
return screen.info(0)
})
.then(function(display) {
display.url = screen.publicUrl
return display
function Display(id, properties) {
this.id = id
this.properties = properties
}
util.inherits(Display, EventEmitter)
Display.prototype.updateRotation = function(newRotation) {
log.info('Rotation changed to %d', newRotation)
this.properties.rotation = newRotation
this.emit('rotationChange', newRotation)
}
function infoFromMinicap(id) {
return minicap.run(util.format('-d %d -i', id))
.then(streamutil.readAll)
.then(function(out) {
var match
if ((match = /^ERROR: (.*)$/.exec(out))) {
throw new Error(match[1])
}
try {
return JSON.parse(out)
}
catch (e) {
throw new Error(out.toString())
}
})
}
return fetch()
function infoFromService(id) {
return service.getDisplay(id)
}
function readInfo(id) {
log.info('Reading display info')
return infoFromService(id)
.catch(function() {
return infoFromMinicap(id)
})
.then(function(properties) {
properties.url = screenOptions.publicUrl
return new Display(id, properties)
})
}
return readInfo(0).then(function(display) {
service.on('rotationChange', function(data) {
display.updateRotation(data.rotation)
})
return display
})
})