diff --git a/lib/units/device/plugins/vnc/index.js b/lib/units/device/plugins/vnc/index.js index 67956b50..0a896993 100644 --- a/lib/units/device/plugins/vnc/index.js +++ b/lib/units/device/plugins/vnc/index.js @@ -1,5 +1,6 @@ var net = require('net') var util = require('util') +var os = require('os') var syrup = require('stf-syrup') var Promise = require('bluebird') @@ -65,6 +66,9 @@ module.exports = syrup.serial() , frameHeight: 0 , sentFrameTime: null , updateRequests: 0 + , frameConfig: { + format: jpeg.FORMAT_RGB + } } var pointerTranslator = new PointerTranslator() @@ -115,7 +119,9 @@ module.exports = syrup.serial() return } - var decoded = jpeg.decompressSync(connState.lastFrame) + var decoded = jpeg.decompressSync( + connState.lastFrame, connState.frameConfig) + conn.writeFramebufferUpdate([ { xPosition: 0 , yPosition: 0 @@ -150,6 +156,35 @@ module.exports = syrup.serial() maybeSendFrame() }) + conn.on('formatchange', function(format) { + var same = os.endianness() == 'BE' == format.bigEndianFlag + switch (format.bitsPerPixel) { + case 8: + connState.frameConfig = { + format: jpeg.FORMAT_GRAY + } + break + case 24: + connState.frameConfig = { + format: ((format.redShift > format.blueShift) === same) + ? jpeg.FORMAT_BGR + : jpeg.FORMAT_RGB + } + break + case 32: + connState.frameConfig = { + format: ((format.redShift > format.blueShift) === same) + ? (format.blueShift === 0 + ? jpeg.FORMAT_BGRX + : jpeg.FORMAT_XBGR) + : (format.redShift === 0 + ? jpeg.FORMAT_RGBX + : jpeg.FORMAT_XRGB) + } + break + } + }) + conn.on('pointer', function(event) { pointerTranslator.push(event) }) diff --git a/lib/units/device/plugins/vnc/util/connection.js b/lib/units/device/plugins/vnc/util/connection.js index 68f3c99f..c80870f0 100644 --- a/lib/units/device/plugins/vnc/util/connection.js +++ b/lib/units/device/plugins/vnc/util/connection.js @@ -1,4 +1,5 @@ var util = require('util') +var os = require('os') var EventEmitter = require('eventemitter3').EventEmitter var debug = require('debug')('vnc:connection') @@ -26,7 +27,7 @@ function VncConnection(conn, options) { this._serverPixelFormat = new PixelFormat({ bitsPerPixel: 24 , depth: 24 - , bigEndianFlag: 0 + , bigEndianFlag: os.endianness() == 'BE' ? 1 : 0 , trueColorFlag: 1 , redMax: 255 , greenMax: 255 @@ -35,7 +36,6 @@ function VncConnection(conn, options) { , greenShift: 8 , blueShift: 0 }) - this._requireServerPixelFormat = true this._serverName = this.options.name this._clientVersion = null @@ -202,6 +202,7 @@ VncConnection.prototype._writeSecurityResult = function(result, reason) { } VncConnection.prototype._writeServerInit = function() { + debug('server pixel format', this._serverPixelFormat) var chunk = new Buffer(2 + 2 + 16 + 4 + this._serverName.length) chunk.writeUInt16BE(this._serverWidth, 0) chunk.writeUInt16BE(this._serverHeight, 2) @@ -318,12 +319,7 @@ 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.emit('formatchange', this._clientPixelFormat) this._changeState(VncConnection.STATE_NEED_CLIENT_MESSAGE) } break diff --git a/package.json b/package.json index 93a20d0a..acb01d95 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "http-proxy": "^1.11.2", "in-publish": "^2.0.0", "jade": "^1.9.2", - "jpeg-turbo": "^0.1.1", + "jpeg-turbo": "^0.2.1", "jws": "^3.1.0", "ldapjs": "git+https://github.com/mcavage/node-ldapjs.git#acc1ca8f4314fd9d67561feabc8ce4c235076a5e", "lodash": "^3.10.1",