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C1B,IAAI,EAAQ,EAAK,GACjB,GAAU,EAEV,IAAI,EAAM,CACZ,GAAS,KAAK,YAAY,OAAU,KAAK,YAAY,KACrD,GAAS,KAAK,YAAY,OAAU,KAAK,YAAY,KACrD,GAAS,KAAK,YAAY,OAAU,KAAK,YAAY,MAEnD,EAAK,KAAK,EACd,CACA,EAAO,KAAK,EACT,CAEA,KAAK,KAAK,OAAQ,CACrB,EAAG,EAAG,EAAG,EACT,EAAG,EAAG,EAAG,EACT,OAAQ,GA5CL,MAFH,KAAK,MAAM,4CAgDZ,EAEA,UAAU,UAAU,cAAgB,SAAS,EAAG,EAAG,EAAG,GAClD,IAAI,EAAI,IAAI,OAAO,IAOnB,OANA,EAAE,GAAK,EACP,EAAE,GAAK,EACP,EAAE,cAAc,EAAG,GACnB,EAAE,cAAc,EAAG,GACnB,EAAE,cAAc,EAAG,GACnB,EAAE,cAAc,EAAG,GACZ,KAAK,OAAO,MAAM,EAC7B","file":"/npm/vnc-client@0.0.0/vnc-client.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/vnc-client@0.0.0/vnc-client.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","var util = require('util');\nvar net = require('net');\nvar des = require('des');\n\nconst STATE_HANDSHAKE = 0,\n    STATE_AUTH = 1,\n    STATE_AUTH_VNC = 2,\n    STATE_AUTH_RES = 3,\n    STATE_INIT = 4,\n    STATE_MSG = 5,\n    STATE_RECTANGLES = 6;\n\nconst MSG_FRAMEBUFFER_UPDATE = 0;\n\nconst ENCODING_RAW = 0,\n    ENCODING_COPY_RECT = 1;\n\n\nfunction parsePixelFormat(buf) {\n    return {\n\tbpp: buf.readUInt8(0),\n\tdepth: buf.readUInt8(1),\n\tbigEndian: buf.readUInt8(2),\n\ttrueColor: buf.readUInt8(3),\n\trMax: buf.readUInt16BE(4),\n\tgMax: buf.readUInt16BE(6),\n\tbMax: buf.readUInt16BE(8),\n\trShift: buf.readUInt8(10),\n\tgShift: buf.readUInt8(11),\n\tbShift: buf.readUInt8(12)\n    };\n}\n\n\nfunction VNCClient(host, display, password) {\n    this.password = password;\n    this.socket = net.createConnection((display || 0) + 5900, host);\n    this.recvBuf = new Buffer(0);\n    this.socket.on('connect', this.onConnect.bind(this));\n    this.socket.on('data', this.onData.bind(this));\n    this.socket.on('close', this.onClose.bind(this));\n}\nutil.inherits(VNCClient, process.EventEmitter);\nexports.VNCClient = VNCClient;\n\nVNCClient.prototype.error = function(message) {\n    if (this.socket.writable)\n\tthis.socket.end();\n\n    this.emit('error', new Error(message));\n};\n\nVNCClient.prototype.onConnect = function() {\n    this.state = STATE_HANDSHAKE;\n\n    var emit = this.emit.bind(this);\n    var socket = this.socket;\n    function proxyEvent(event) {\n\tsocket.on(event, emit.bind(null, event));\n    }\n    proxyEvent('drain');\n    proxyEvent('end');\n    proxyEvent('close');\n    proxyEvent('error');\n};\n\nVNCClient.prototype.onClose = function() {\n    console.warn(\"RFB connection closed\");\n};\n\nVNCClient.prototype.onData = function(data) {\n    if (data) {\n\tvar recvBuf = new Buffer(this.recvBuf.length + data.length);\n\tthis.recvBuf.copy(recvBuf);\n\tdata.copy(recvBuf, this.recvBuf.length);\n\tthis.recvBuf = recvBuf;\n    }\n\n    //console.log(\"data\", this.state, data, this.recvBuf);\n\n    switch(this.state) {\n    case STATE_HANDSHAKE:\n\tif (this.recvBuf.length >= 12) {\n\t    var s = this.recvBuf.slice(0, 12).toString();\n\t    this.recvBuf = this.recvBuf.slice(12);\n\t    var m;\n\t    if ((m = s.match(/^RFB (\\d\\d\\d)\\.(\\d\\d\\d)/))) {\n\t\tvar maj = parseInt(m[1], 10);\n\t\tvar min = parseInt(m[2], 10);\n\t\tconsole.log(\"Server speaks \"+maj+\".\"+min);\n\t\tif (maj >= 3 && min >= 7) {\n\t\t    this.version = [maj, min];\n\t\t    this.socket.write(\"RFB 003.007\\n\");\n\t\t    this.state = STATE_AUTH;\n\t\t} else {\n\t\t    this.error(\"Protocol version \"+maj+\".\"+min+\" not implemented\");\n\t\t}\n\t    } else {\n\t\tthis.error(\"Invalid protocol handshake\");\n\t    }\n\t}\n\tbreak;\n    case STATE_AUTH:\n\tif (this.recvBuf.length > 0 &&\n\t    this.recvBuf.length >= this.recvBuf[0] + 1) {\n\n\t    var secTypes = this.recvBuf.slice(1, this.recvBuf[0] + 1);\n\t    this.recvBuf = this.recvBuf.slice(this.recvBuf[0] + 1);\n\n\t    var noAuth = false, vncAuth = false;\n\t    for(var i = 0; i < secTypes.length; i++) {\n\t\tswitch(secTypes[i]) {\n\t\t    case 1:\n\t\t\tnoAuth = true;\n\t\t\tbreak;\n\t\t    case 2:\n\t\t\tvncAuth = true;\n\t\t\tbreak;\n\t\t}\n\t    }\n\t    if (noAuth) {\n\t\tthis.socket.write(new Buffer([1]));\n\t\tthis.socket.write(new Buffer([1]));\n\t\tthis.state = STATE_INIT;\n\t    } else if (vncAuth) {\n\t\tif (typeof this.password === 'string') {\n\t\t    this.socket.write(new Buffer([2]));\n\t\t    this.state = STATE_AUTH_VNC;\n\t\t} else {\n\t\t    this.error(\"Password required\");\n\t\t}\n\t    } else {\n\t\tthis.error(\"VNC Authentication not offered\");\n\t    }\n\t}\n\tbreak;\n    case STATE_AUTH_VNC:\n\tif (this.recvBuf.length >= 16) {\n\t    var challenge = this.recvBuf.slice(0, 16);\n\t    this.recvBuf = this.recvBuf.slice(16);\n\n\t    var response = des.encrypt(this.password, challenge);\n\t    this.socket.write(response);\n\t    this.state = STATE_AUTH_RES;\n\t}\n\tbreak;\n    case STATE_AUTH_RES:\n\tif (this.recvBuf.length >= 4) {\n\t    var ok = this.recvBuf[3] === 0;\n\t    this.recvBuf = this.recvBuf.slice(4);\n\t    if (ok) {\n\t\tthis.socket.write(new Buffer([1]));\n\t\tthis.state = STATE_INIT;\n\t    } else {\n\t\tthis.error(\"Authentication failure\");\n\t    }\n\t}\n\tbreak;\n    case STATE_INIT:\n\tif (this.recvBuf.length >= 24) {\n\t    var nameLen = this.recvBuf.readUInt32BE(20);\n\t    if (this.recvBuf.length >= 24 + nameLen) {\n\t\tthis.width = this.recvBuf.readUInt16BE(0);\n\t\tthis.height = this.recvBuf.readUInt16BE(2);\n\t\tthis.name = this.recvBuf.slice(24, 24 + nameLen).toString();\n\t\tthis.pixelFormat = parsePixelFormat(this.recvBuf.slice(4, 20));\n\n\t\tthis.recvBuf = this.recvBuf.slice(24 + nameLen);\n\t\tthis.state = STATE_MSG;\n\t\tthis.emit('init', {\n\t\t    width: this.width,\n\t\t    height: this.height,\n\t\t    name: this.name,\n\t\t    pixelFormat: this.pixelFormat\n\t\t});\n\t    }\n\t}\n\tbreak;\n    case STATE_MSG:\n\tif (this.recvBuf.length >= 1) {\n\t    switch(this.recvBuf[0]) {\n\t    case MSG_FRAMEBUFFER_UPDATE:\n\t\tif (this.recvBuf.length >= 4) {\n\t\t    this.rectangles = this.recvBuf.readUInt16BE(2);\n\t\t    this.recvBuf = this.recvBuf.slice(4);\n\n\t\t    this.state = STATE_RECTANGLES;\n\t\t    this.onData();\n\t\t}\n\t\tbreak;\n\t    default:\n\t\tthis.error(\"Unknown message type\");\n\t    }\n\t}\n\tbreak;\n    case STATE_RECTANGLES:\n\tif (this.recvBuf.length >= 12) {\n\t    var x = this.recvBuf.readUInt16BE(0);\n\t    var y = this.recvBuf.readUInt16BE(2);\n\t    var w = this.recvBuf.readUInt16BE(4);\n\t    var h = this.recvBuf.readUInt16BE(6);\n\t    var encoding = this.recvBuf.readInt32BE(8);\n\t    var pixelsLen = Math.ceil(w * h * this.pixelFormat.bpp / 8);\n\t    if (this.recvBuf.length >= 12 + pixelsLen) {\n\t\tvar pixels = this.recvBuf.slice(12, 12 + pixelsLen);\n\t\tthis.recvBuf = this.recvBuf.slice(12 + pixelsLen);\n\n\t\tthis.onRectangle(x, y, w, h, encoding, pixels);\n\n\t\t/* One frame received */\n\t\tthis.rectangles--;\n\t\tif (this.rectangles < 1) {\n\t\t    this.state = STATE_MSG;\n\t\t    this.onData();\n\t\t}\n\t    }\n\t}\n\tbreak;\n    default:\n\tconsole.log(\"Received in state\", this.state, this.recvBuf);\n    }\n};\n\nVNCClient.prototype.onRectangle = function(x, y, w, h, encoding, data) {\n    if (encoding !== ENCODING_RAW) {\n\tthis.error(\"Received something else than RAW encoding\");\n\treturn;\n    }\n\n    var readFun;\n    switch(this.pixelFormat.bpp) {\n\tcase 8:\n\t    readFun = 'readInt8';\n\t    break;\n\tcase 16:\n\t    readFun = this.pixelFormat.bigEndian ?\n\t\t'readUInt16BE' :\n\t\t'readUInt16LE';\n\t    break;\n\tcase 32:\n\t    readFun = this.pixelFormat.bigEndian ?\n\t\t'readUInt32BE' :\n\t\t'readUInt32LE';\n\t    break;\n\tdefault:\n\t    this.error(\"Unsupported bpp \" + this.pixelFormat.bpp);\n\t    return;\n    }\n    var read = data[readFun].bind(data);\n    var offsetDelta = Math.ceil(this.pixelFormat.bpp / 8);\n\n    var x1, y1, offset = 0, pixels = [];\n    for(y1 = y; y1 < y + h; y1++) {\n\tvar line = [];\n\tfor(x1 = x; x1 < x + w; x1++) {\n\t    var pixel = read(offset);\n\t    offset += offsetDelta;\n\n\t    var rgb = [\n\t\t(pixel >> this.pixelFormat.rShift) & this.pixelFormat.rMax,\n\t\t(pixel >> this.pixelFormat.gShift) & this.pixelFormat.gMax,\n\t\t(pixel >> this.pixelFormat.bShift) & this.pixelFormat.bMax\n\t    ];\n\t    line.push(rgb);\n\t}\n\tpixels.push(line);\n    }\n\n    this.emit('rect', {\n\tx: x, y: y,\n\tw: w, h: h,\n\tpixels: pixels\n    });\n};\n\nVNCClient.prototype.requestUpdate = function(x, y, w, h) {\n    var b = new Buffer(10);\n    b[0] = 3;\n    b[1] = 0;\n    b.writeUInt16BE(x, 2);\n    b.writeUInt16BE(y, 4);\n    b.writeUInt16BE(w, 6);\n    b.writeUInt16BE(h, 8);\n    return this.socket.write(b);\n};\n"]}