mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 08:03:30 +02:00
VNC screen is visible (w/ RAW encoding). Size of VNC screen is still
hardcoded, preventing real use.
This commit is contained in:
@@ -7,7 +7,10 @@ var PixelFormat = require('./pixelformat')
|
||||
|
||||
function VncConnection(conn) {
|
||||
this._bound = {
|
||||
_readableListener: this._readableListener.bind(this)
|
||||
_errorListener: this._errorListener.bind(this)
|
||||
, _readableListener: this._readableListener.bind(this)
|
||||
, _endListener: this._endListener.bind(this)
|
||||
, _closeListener: this._closeListener.bind(this)
|
||||
}
|
||||
|
||||
this._buffer = null
|
||||
@@ -16,12 +19,12 @@ function VncConnection(conn) {
|
||||
|
||||
this._serverVersion = VncConnection.V3_008
|
||||
this._serverSupportedSecurity = [VncConnection.SECURITY_NONE]
|
||||
this._serverWidth = 800
|
||||
this._serverHeight = 600
|
||||
this._serverWidth = 720
|
||||
this._serverHeight = 1280
|
||||
this._serverPixelFormat = new PixelFormat({
|
||||
bitsPerPixel: 32
|
||||
, depth: 24
|
||||
, bigEndianFlag: 1
|
||||
, bigEndianFlag: 0
|
||||
, trueColorFlag: 1
|
||||
, redMax: 255
|
||||
, greenMax: 255
|
||||
@@ -30,6 +33,7 @@ function VncConnection(conn) {
|
||||
, greenShift: 8
|
||||
, blueShift: 0
|
||||
})
|
||||
this._requireServerPixelFormat = true
|
||||
this._serverName = 'stf'
|
||||
|
||||
this._clientVersion = null
|
||||
@@ -42,7 +46,10 @@ function VncConnection(conn) {
|
||||
this._clientCutTextLength = 0
|
||||
|
||||
this.conn = conn
|
||||
.on('error', this._bound._errorListener)
|
||||
.on('readable', this._bound._readableListener)
|
||||
.on('end', this._bound._endListener)
|
||||
.on('close', this._bound._closeListener)
|
||||
|
||||
this._writeServerVersion()
|
||||
this._read()
|
||||
@@ -67,6 +74,8 @@ VncConnection.CLIENT_MESSAGE_KEYEVENT = 4
|
||||
VncConnection.CLIENT_MESSAGE_POINTEREVENT = 5
|
||||
VncConnection.CLIENT_MESSAGE_CLIENTCUTTEXT = 6
|
||||
|
||||
VncConnection.SERVER_MESSAGE_FBUPDATE = 0
|
||||
|
||||
var StateReverse = Object.create(null), State = {
|
||||
STATE_NEED_CLIENT_VERSION: 10
|
||||
, STATE_NEED_CLIENT_SECURITY: 20
|
||||
@@ -82,11 +91,61 @@ var StateReverse = Object.create(null), State = {
|
||||
, STATE_NEED_CLIENT_MESSAGE_CLIENTCUTTEXT_VALUE: 101
|
||||
}
|
||||
|
||||
VncConnection.ENCODING_RAW = 0
|
||||
|
||||
Object.keys(State).map(function(name) {
|
||||
VncConnection[name] = State[name]
|
||||
StateReverse[State[name]] = name
|
||||
})
|
||||
|
||||
VncConnection.prototype.end = function() {
|
||||
this.conn.end()
|
||||
}
|
||||
|
||||
VncConnection.prototype.writeFramebufferUpdate = function(rectangles) {
|
||||
var chunk = new Buffer(4)
|
||||
chunk[0] = VncConnection.SERVER_MESSAGE_FBUPDATE
|
||||
chunk[1] = 0
|
||||
chunk.writeUInt16BE(rectangles.length, 2)
|
||||
this._write(chunk)
|
||||
|
||||
rectangles.forEach(function(rect) {
|
||||
var chunk = new Buffer(12)
|
||||
chunk.writeUInt16BE(rect.xPosition, 0)
|
||||
chunk.writeUInt16BE(rect.yPosition, 2)
|
||||
chunk.writeUInt16BE(rect.width, 4)
|
||||
chunk.writeUInt16BE(rect.height, 6)
|
||||
chunk.writeInt32BE(rect.encodingType, 8)
|
||||
this._write(chunk)
|
||||
|
||||
switch (rect.encodingType) {
|
||||
case VncConnection.ENCODING_RAW:
|
||||
this._write(rect.data)
|
||||
break
|
||||
default:
|
||||
throw new Error(util.format(
|
||||
'Unsupported encoding type', rect.encodingType))
|
||||
}
|
||||
}, this)
|
||||
}
|
||||
|
||||
VncConnection.prototype._error = function(err) {
|
||||
this.emit('error', err)
|
||||
this.end()
|
||||
}
|
||||
|
||||
VncConnection.prototype._errorListener = function(err) {
|
||||
this._error(err)
|
||||
}
|
||||
|
||||
VncConnection.prototype._endListener = function() {
|
||||
this.emit('end')
|
||||
}
|
||||
|
||||
VncConnection.prototype._closeListener = function() {
|
||||
this.emit('close')
|
||||
}
|
||||
|
||||
VncConnection.prototype._writeServerVersion = function() {
|
||||
// Yes, we could just format the string instead. Didn't feel like it.
|
||||
switch (this._serverVersion) {
|
||||
@@ -171,7 +230,10 @@ VncConnection.prototype._read = function() {
|
||||
switch (this._state) {
|
||||
case VncConnection.STATE_NEED_CLIENT_VERSION:
|
||||
if ((chunk = this._consume(12))) {
|
||||
this._clientVersion = this._parseVersion(chunk)
|
||||
if ((this._clientVersion = this._parseVersion(chunk)) === null) {
|
||||
this.end()
|
||||
return
|
||||
}
|
||||
debug('client version', this._clientVersion)
|
||||
this._writeSupportedSecurity()
|
||||
this._changeState(VncConnection.STATE_NEED_CLIENT_SECURITY)
|
||||
@@ -179,7 +241,12 @@ VncConnection.prototype._read = function() {
|
||||
break
|
||||
case VncConnection.STATE_NEED_CLIENT_SECURITY:
|
||||
if ((chunk = this._consume(1))) {
|
||||
this._clientSecurity = this._parseSecurity(chunk)
|
||||
if ((this._clientSecurity = this._parseSecurity(chunk)) === null) {
|
||||
this._writeSecurityResult(
|
||||
VncConnection.SECURITYRESULT_FAIL, 'Unsupported security type')
|
||||
this.end()
|
||||
return
|
||||
}
|
||||
debug('client security', this._clientSecurity)
|
||||
this._writeSecurityResult(VncConnection.SECURITYRESULT_OK)
|
||||
this._changeState(VncConnection.STATE_NEED_CLIENT_INIT)
|
||||
@@ -197,25 +264,33 @@ VncConnection.prototype._read = function() {
|
||||
if ((chunk = this._consume(1))) {
|
||||
switch (chunk[0]) {
|
||||
case VncConnection.CLIENT_MESSAGE_SETPIXELFORMAT:
|
||||
this._changeState(VncConnection.STATE_NEED_CLIENT_MESSAGE_SETPIXELFORMAT)
|
||||
this._changeState(
|
||||
VncConnection.STATE_NEED_CLIENT_MESSAGE_SETPIXELFORMAT)
|
||||
break
|
||||
case VncConnection.CLIENT_MESSAGE_SETENCODINGS:
|
||||
this._changeState(VncConnection.STATE_NEED_CLIENT_MESSAGE_SETENCODINGS)
|
||||
this._changeState(
|
||||
VncConnection.STATE_NEED_CLIENT_MESSAGE_SETENCODINGS)
|
||||
break
|
||||
case VncConnection.CLIENT_MESSAGE_FBUPDATEREQUEST:
|
||||
this._changeState(VncConnection.STATE_NEED_CLIENT_MESSAGE_FBUPDATEREQUEST)
|
||||
this._changeState(
|
||||
VncConnection.STATE_NEED_CLIENT_MESSAGE_FBUPDATEREQUEST)
|
||||
break
|
||||
case VncConnection.CLIENT_MESSAGE_KEYEVENT:
|
||||
this._changeState(VncConnection.STATE_NEED_CLIENT_MESSAGE_KEYEVENT)
|
||||
this._changeState(
|
||||
VncConnection.STATE_NEED_CLIENT_MESSAGE_KEYEVENT)
|
||||
break
|
||||
case VncConnection.CLIENT_MESSAGE_POINTEREVENT:
|
||||
this._changeState(VncConnection.STATE_NEED_CLIENT_MESSAGE_POINTEREVENT)
|
||||
this._changeState(
|
||||
VncConnection.STATE_NEED_CLIENT_MESSAGE_POINTEREVENT)
|
||||
break
|
||||
case VncConnection.CLIENT_MESSAGE_CLIENTCUTTEXT:
|
||||
this._changeState(VncConnection.STATE_NEED_CLIENT_MESSAGE_CLIENTCUTTEXT)
|
||||
this._changeState(
|
||||
VncConnection.STATE_NEED_CLIENT_MESSAGE_CLIENTCUTTEXT)
|
||||
break
|
||||
default:
|
||||
throw new Error(util.format('Unsupported message type %d', chunk[0]))
|
||||
this._error(new Error(util.format(
|
||||
'Unsupported message type %d', chunk[0])))
|
||||
return
|
||||
}
|
||||
}
|
||||
break
|
||||
@@ -236,6 +311,12 @@ VncConnection.prototype._read = function() {
|
||||
})
|
||||
// [16b, 19b) padding
|
||||
debug('client pixel format', this._clientPixelFormat)
|
||||
if (this._requireServerPixelFormat &&
|
||||
this._clientPixelFormat.bitsPerPixel <
|
||||
this._serverPixelFormat.bitsPerPixel) {
|
||||
this.end()
|
||||
return
|
||||
}
|
||||
this._changeState(VncConnection.STATE_NEED_CLIENT_MESSAGE)
|
||||
}
|
||||
break
|
||||
@@ -243,7 +324,8 @@ VncConnection.prototype._read = function() {
|
||||
if ((chunk = this._consume(3))) {
|
||||
// [0b, 1b) padding
|
||||
this._clientEncodingCount = chunk.readUInt16BE(1, true)
|
||||
this._changeState(VncConnection.STATE_NEED_CLIENT_MESSAGE_SETENCODINGS_VALUE)
|
||||
this._changeState(
|
||||
VncConnection.STATE_NEED_CLIENT_MESSAGE_SETENCODINGS_VALUE)
|
||||
}
|
||||
break
|
||||
case VncConnection.STATE_NEED_CLIENT_MESSAGE_SETENCODINGS_VALUE:
|
||||
@@ -261,11 +343,13 @@ VncConnection.prototype._read = function() {
|
||||
break
|
||||
case VncConnection.STATE_NEED_CLIENT_MESSAGE_FBUPDATEREQUEST:
|
||||
if ((chunk = this._consume(9))) {
|
||||
// incremental = chunk[0]
|
||||
// xPosition = chunk.readUInt16BE(1, true)
|
||||
// yPosition = chunk.readUInt16BE(3, true)
|
||||
// width = chunk.readUInt16BE(5, true)
|
||||
// height = chunk.readUInt16BE(7, true)
|
||||
this.emit('fbupdaterequest', {
|
||||
incremental: chunk[0]
|
||||
, xPosition: chunk.readUInt16BE(1, true)
|
||||
, yPosition: chunk.readUInt16BE(3, true)
|
||||
, width: chunk.readUInt16BE(5, true)
|
||||
, height: chunk.readUInt16BE(7, true)
|
||||
})
|
||||
this._changeState(VncConnection.STATE_NEED_CLIENT_MESSAGE)
|
||||
}
|
||||
break
|
||||
@@ -289,7 +373,8 @@ VncConnection.prototype._read = function() {
|
||||
if ((chunk = this._consume(7))) {
|
||||
// [0b, 3b) padding
|
||||
this._clientCutTextLength = chunk.readUInt32BE(3)
|
||||
this._changeState(VncConnection.STATE_NEED_CLIENT_MESSAGE_CLIENTCUTTEXT_VALUE)
|
||||
this._changeState(
|
||||
VncConnection.STATE_NEED_CLIENT_MESSAGE_CLIENTCUTTEXT_VALUE)
|
||||
}
|
||||
break
|
||||
case VncConnection.STATE_NEED_CLIENT_MESSAGE_CLIENTCUTTEXT_VALUE:
|
||||
@@ -319,7 +404,7 @@ VncConnection.prototype._parseVersion = function(chunk) {
|
||||
return VncConnection.V3_003
|
||||
}
|
||||
|
||||
throw new Error('Unsupported version')
|
||||
return null
|
||||
}
|
||||
|
||||
VncConnection.prototype._parseSecurity = function(chunk) {
|
||||
@@ -328,7 +413,7 @@ VncConnection.prototype._parseSecurity = function(chunk) {
|
||||
case VncConnection.SECURITY_VNC:
|
||||
return chunk[0]
|
||||
default:
|
||||
throw new Error('Unsupported security type')
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user