mirror of
https://github.com/openstf/stf
synced 2025-10-05 10:39:25 +02:00
Translate pointer events into touch events.
This commit is contained in:
parent
2ee767ffed
commit
a98cc67e2c
3 changed files with 98 additions and 6 deletions
|
@ -11,10 +11,12 @@ var lifecycle = require('../../../../util/lifecycle')
|
||||||
|
|
||||||
var VncServer = require('./util/server')
|
var VncServer = require('./util/server')
|
||||||
var VncConnection = require('./util/connection')
|
var VncConnection = require('./util/connection')
|
||||||
|
var PointerTranslator = require('./util/pointertranslator')
|
||||||
|
|
||||||
module.exports = syrup.serial()
|
module.exports = syrup.serial()
|
||||||
.dependency(require('../screen/stream'))
|
.dependency(require('../screen/stream'))
|
||||||
.define(function(options, screenStream) {
|
.dependency(require('../touch'))
|
||||||
|
.define(function(options, screenStream, touch) {
|
||||||
var log = logger.createLogger('device:plugins:vnc')
|
var log = logger.createLogger('device:plugins:vnc')
|
||||||
|
|
||||||
function createServer() {
|
function createServer() {
|
||||||
|
@ -63,6 +65,24 @@ module.exports = syrup.serial()
|
||||||
, updateRequests: 0
|
, updateRequests: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var pointerTranslator = new PointerTranslator()
|
||||||
|
|
||||||
|
pointerTranslator.on('touchdown', function(event) {
|
||||||
|
touch.touchDown(event)
|
||||||
|
})
|
||||||
|
|
||||||
|
pointerTranslator.on('touchmove', function(event) {
|
||||||
|
touch.touchMove(event)
|
||||||
|
})
|
||||||
|
|
||||||
|
pointerTranslator.on('touchup', function(event) {
|
||||||
|
touch.touchUp(event)
|
||||||
|
})
|
||||||
|
|
||||||
|
pointerTranslator.on('touchcommit', function() {
|
||||||
|
touch.touchCommit()
|
||||||
|
})
|
||||||
|
|
||||||
function vncStartListener(frameProducer) {
|
function vncStartListener(frameProducer) {
|
||||||
return new Promise(function(resolve/*, reject*/) {
|
return new Promise(function(resolve/*, reject*/) {
|
||||||
connState.frameWidth = frameProducer.banner.virtualWidth
|
connState.frameWidth = frameProducer.banner.virtualWidth
|
||||||
|
@ -126,6 +146,10 @@ module.exports = syrup.serial()
|
||||||
maybeSendFrame()
|
maybeSendFrame()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
conn.on('pointer', function(event) {
|
||||||
|
pointerTranslator.push(event)
|
||||||
|
})
|
||||||
|
|
||||||
conn.on('close', function() {
|
conn.on('close', function() {
|
||||||
screenStream.broadcastSet.remove(id)
|
screenStream.broadcastSet.remove(id)
|
||||||
})
|
})
|
||||||
|
|
|
@ -21,8 +21,8 @@ function VncConnection(conn, options) {
|
||||||
|
|
||||||
this._serverVersion = VncConnection.V3_008
|
this._serverVersion = VncConnection.V3_008
|
||||||
this._serverSupportedSecurity = [VncConnection.SECURITY_NONE]
|
this._serverSupportedSecurity = [VncConnection.SECURITY_NONE]
|
||||||
this._serverWidth = 720
|
this._serverWidth = 1080
|
||||||
this._serverHeight = 1280
|
this._serverHeight = 1920
|
||||||
this._serverPixelFormat = new PixelFormat({
|
this._serverPixelFormat = new PixelFormat({
|
||||||
bitsPerPixel: 32
|
bitsPerPixel: 32
|
||||||
, depth: 24
|
, depth: 24
|
||||||
|
@ -368,9 +368,11 @@ VncConnection.prototype._read = function() {
|
||||||
break
|
break
|
||||||
case VncConnection.STATE_NEED_CLIENT_MESSAGE_POINTEREVENT:
|
case VncConnection.STATE_NEED_CLIENT_MESSAGE_POINTEREVENT:
|
||||||
if ((chunk = this._consume(5))) {
|
if ((chunk = this._consume(5))) {
|
||||||
// buttonMask = chunk[0]
|
this.emit('pointer', {
|
||||||
// xPosition = chunk.readUInt16BE(1, true)
|
buttonMask: chunk[0]
|
||||||
// yPosition = chunk.readUInt16BE(3, true)
|
, xPosition: chunk.readUInt16BE(1, true) / this._serverWidth
|
||||||
|
, yPosition: chunk.readUInt16BE(3, true) / this._serverHeight
|
||||||
|
})
|
||||||
this._changeState(VncConnection.STATE_NEED_CLIENT_MESSAGE)
|
this._changeState(VncConnection.STATE_NEED_CLIENT_MESSAGE)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
66
lib/units/device/plugins/vnc/util/pointertranslator.js
Normal file
66
lib/units/device/plugins/vnc/util/pointertranslator.js
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
var util = require('util')
|
||||||
|
|
||||||
|
var EventEmitter = require('eventemitter3').EventEmitter
|
||||||
|
|
||||||
|
function PointerTranslator() {
|
||||||
|
this.previousEvent = null
|
||||||
|
}
|
||||||
|
|
||||||
|
util.inherits(PointerTranslator, EventEmitter)
|
||||||
|
|
||||||
|
PointerTranslator.prototype.push = function(event) {
|
||||||
|
if (event.buttonMask & 0xFE) {
|
||||||
|
// Non-primary buttons included, ignore.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.previousEvent) {
|
||||||
|
var buttonChanges = event.buttonMask ^ this.previousEvent.buttonMask
|
||||||
|
|
||||||
|
// If the primary button changed, we have an up/down event.
|
||||||
|
if (buttonChanges & 1) {
|
||||||
|
// If it's pressed now, that's a down event.
|
||||||
|
if (event.buttonMask & 1) {
|
||||||
|
this.emit('touchdown', {
|
||||||
|
contact: 1
|
||||||
|
, x: event.xPosition
|
||||||
|
, y: event.yPosition
|
||||||
|
})
|
||||||
|
this.emit('touchcommit')
|
||||||
|
}
|
||||||
|
// It's not pressed, so we have an up event.
|
||||||
|
else {
|
||||||
|
this.emit('touchup', {
|
||||||
|
contact: 1
|
||||||
|
})
|
||||||
|
this.emit('touchcommit')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Otherwise, if we're still holding the primary button down,
|
||||||
|
// that's a move event.
|
||||||
|
else if (event.buttonMask & 1) {
|
||||||
|
this.emit('touchmove', {
|
||||||
|
contact: 1
|
||||||
|
, x: event.xPosition
|
||||||
|
, y: event.yPosition
|
||||||
|
})
|
||||||
|
this.emit('touchcommit')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// If it's the first event we get and the primary button's pressed,
|
||||||
|
// it's a down event.
|
||||||
|
if (event.buttonMask & 1) {
|
||||||
|
this.emit('touchdown', {
|
||||||
|
contact: 1
|
||||||
|
, x: event.xPosition
|
||||||
|
, y: event.yPosition
|
||||||
|
})
|
||||||
|
this.emit('touchcommit')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.previousEvent = event
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = PointerTranslator
|
Loading…
Add table
Add a link
Reference in a new issue