You can jump to the latest bin by adding /latest to your URL

×
") } this.initText(); $("#clipboardHelper").bind("copy", function(e) { var clipboardData = (window.clipboardData != undefined) ? window.clipboardData : ((e.originalEvent.clipboardData != undefined) ? e.originalEvent.clipboardData : null); if(clipboardData) { clipboardData.setData("Text", TVNC.clipboard.synccopy()) } else { TVNC.clipboard.mozillaCopy(TVNC.clipboard.synccopy()) } setTimeout(function() { TVNC.clipboard.clear(); TVNC.clipboard.setText("XXXX") }, 100) }); $("#clipboardHelper").bind("cut", function(e) { var clipboardData = (window.clipboardData != undefined) ? window.clipboardData : ((e.originalEvent.clipboardData != undefined) ? e.originalEvent.clipboardData : null); if(clipboardData) { clipboardData.setData("Text", TVNC.clipboard.synccopy(true)) } else { TVNC.clipboard.mozillaCopy(TVNC.clipboard.synccopy(true)) } setTimeout(function() { TVNC.clipboard.clear(); TVNC.clipboard.setText("XXXX") }, 100) }); $("#clipboardHelper").bind("paste", function(e) { if(!TVNC.rcParams.mouseControl) { return } e.stopPropagation(); setTimeout(function() { var url = TVNC.baseUrl + "cmd?id=" + TVNC.rcParams.id + "&cmd=cli&type=clipboard&action=paste"; var txt = TVNC.clipboard.getText(); $.post(url, txt); TVNC.clipboard.clear(); TVNC.clipboard.setText("XXXX") }, 100) }); $("#clipboardHelper").keydown(function(e) { if(e.ctrlKey && !e.altKey && e.keyCode != 17 && !TVNC.mac && !$.browser.mozilla) { if(e.keyCode == 88 || e.keyCode == 86 || e.keyCode == 67) { e.stopPropagation(); return } } }) }, deinit: function() { if(document.getElementById("clipboardHelper")) { $("#clipboardHelper").unbind() } }, mozillaCopy: function(copytext) { try { if(netscape.security.PrivilegeManager.enablePrivilege) { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect") } else { clipdata = copytext; return } } catch(ex) { clipdata = copytext; return } var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString); str.data = copytext; var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable); if(!trans) { return false } trans.addDataFlavor("text/unicode"); trans.setTransferData("text/unicode", str, copytext.length * 2); var clipid = Components.interfaces.nsIClipboard; var clip = Components.classes["@mozilla.org/widget/clipboard;1"].getService(clipid); if(!clip) { return false } clip.setData(trans, null, clipid.kGlobalClipboard) }, initText: function() { this.clear(); this.setText("XXXX") }, getText: function() { return $("#clipboardHelper").val() }, setText: function(text) { this.copying = true; $("#clipboardHelper").val(text); var textarea = document.getElementById("clipboardHelper"); if(!textarea) { return } if(textarea.setSelectionRange) { textarea.setSelectionRange(0, textarea.value.length) } else { var r = textarea.createTextRange(); r.collapse(true); r.moveEnd("character", 0); r.moveStart("character", textarea.value.length); r.select() } this.copying = false }, clear: function() { $("#clipboardHelper").val("") }, paste: function() { if(!TVNC.rcParams.mouseControl) { return } var url = TVNC.baseUrl + "cmd?id=" + TVNC.rcParams.id + "&cmd=cli&type=" + this.type + "&action=paste"; var txt = this.getText(); try { $.post(url, txt, fn = function(obj) { delete fn }) } catch(e) { alert(e) } }, synccopy: function(cut) { var result = ""; if(!TVNC.rcParams.mouseControl) { return result } var url = TVNC.baseUrl + "cmd?id=" + TVNC.rcParams.id + "&cmd=cli&type=" + this.type; if(cut != undefined && cut) { url += "&action=cut&dokey=true" } else { url += "&action=copy&dokey=true" } var me = this; try { $.ajax({ url: TVNC.getCrossDomainUrl(url), async: false, dataType: "json", error: function(jqXHR, err) { alert(sprintf(consts.connectError, err)) }, success: function(obj) { me.setText(obj.text); result = obj.text } }) } catch(e) { alert(e) } return result } }; this.clipboard.prototype = this.CommandLineInterface; this.getBodyHeight = function() { var p = this.vncDivElement.parent(); var h = p.height(); if(p[0].tagName == "BODY") { h = $(window).height() } h = h - (this.rcParams.borderTop + this.rcParams.borderBottom); return h }; this.getBodyWidth = function() { var p = this.vncDivElement.parent(); var w = p.width(); if(p[0].tagName == "BODY") { w = $(window).width() } w = w - (this.rcParams.borderLeft + this.rcParams.borderRight); return w }; this.findPos = function(obj) { var curleft = 0; var curtop = 0; do { curleft += obj.offsetLeft; curtop += obj.offsetTop } while (obj = obj.offsetParent); return [curleft, curtop] }; this.serverMouseX = function(e) { var position = this.findPos(TVNC.vncdiv); var left = position[0]; if(TVNC.mobile) { return Math.floor((e.touches[0].pageX - left) / TVNC.scale) } else { return Math.floor((e.pageX - left) / TVNC.scale) } }; this.serverMouseY = function(e) { var position = this.findPos(TVNC.vncdiv); var top = position[1]; if(TVNC.mobile) { return Math.floor((e.touches[0].pageY - top) / TVNC.scale) } else { return Math.floor((e.pageY - top) / TVNC.scale) } }; this.center = function() { var isIE9 = ($.browser.msie && $.browser.version >= 9); var s = (jQuery.browser.mozilla || jQuery.browser.opera || jQuery.browser.webkit || isIE9) ? TVNC.getScale() : 1; var ml = ((TVNC.vncdiv.offsetWidth) * s) / 2 - TVNC.rcParams.borderLeft / 2 + TVNC.rcParams.borderRight / 2; var mt = ((TVNC.vncdiv.offsetHeight) * s) / 2 - TVNC.rcParams.borderTop / 2 + TVNC.rcParams.borderBottom / 2; if(this.rcParams.scaled || TVNC.getBodyHeight() > TVNC.vncdiv.offsetHeight && TVNC.getBodyWidth() > TVNC.vncdiv.offsetWidth) { if(TVNC.rcParams.centeredMode == "horizontal") { TVNC.vncdiv.style.top = TVNC.rcParams.borderTop; TVNC.vncdiv.style.marginTop = "0px" } else { TVNC.vncdiv.style.top = "50%"; TVNC.vncdiv.style.marginTop = -mt + "px" } if(TVNC.rcParams.centeredMode == "vertical") { TVNC.vncdiv.style.left = TVNC.rcParams.borderLeft; TVNC.vncdiv.style.marginLeft = "0px" } else { TVNC.vncdiv.style.left = "50%"; TVNC.vncdiv.style.marginLeft = -ml + "px" } } else { if(TVNC.getBodyHeight() > TVNC.vncdiv.offsetHeight) { if(TVNC.rcParams.centeredMode == "horizontal") { TVNC.vncdiv.style.top = TVNC.rcParams.borderTop; TVNC.vncdiv.style.marginTop = "0px" } else { TVNC.vncdiv.style.top = "50%"; TVNC.vncdiv.style.marginTop = -mt + "px" } TVNC.vncdiv.style.left = "0px"; TVNC.vncdiv.style.marginLeft = "0px" } else { if(TVNC.getBodyWidth() > TVNC.vncdiv.offsetWidth) { if(TVNC.rcParams.centeredMode == "vertical") { TVNC.vncdiv.style.left = TVNC.rcParams.borderLeft; TVNC.vncdiv.style.marginLeft = "0px" } else { TVNC.vncdiv.style.left = "50%"; TVNC.vncdiv.style.marginLeft = -ml + "px" } TVNC.vncdiv.style.top = "0px"; TVNC.vncdiv.style.marginTop = "0px" } else { TVNC.vncdiv.style.top = "0px"; TVNC.vncdiv.style.marginTop = "0px"; TVNC.vncdiv.style.left = "0px"; TVNC.vncdiv.style.marginLeft = "0px" } } } }; this.emptyRecycleImg = function(onetime) { while(TVNC.queueRecycleImg.length > 0) { img = TVNC.queueRecycleImg.pop(); delete img } if(onetime == true) { return } setTimeout(TVNC.emptyRecycleImg, TVNC.recycleImgTimeoutValue) }; this.setMaxSize = function(width, height) { TVNC.rcParams.maxWidth = width; TVNC.rcParams.maxHeight = height; TVNC.setScaled(TVNC.rcParams.scaled) }; this.setScaled = function(value) { if(value) { TVNC.vncdiv.parentElement.style.overflow = "hidden"; if(!TVNC.setScaledDone) { TVNC.zoomDesktop(0.1); TVNC.setScaledDone = true } TVNC.vncdiv.style.width = TVNC.rcParams.viewWidth + "px"; TVNC.vncdiv.style.height = TVNC.rcParams.viewHeight + "px"; TVNC.vncdiv.style.clip = "rect(0px," + TVNC.rcParams.viewWidth + "px," + TVNC.rcParams.viewHeight + "px,0px)" } else { TVNC.vncdiv.style.width = (TVNC.rcParams.borderLeft + TVNC.rcParams.maxWidth + TVNC.rcParams.borderRight) + "px"; TVNC.vncdiv.style.height = (TVNC.rcParams.borderTop + TVNC.rcParams.maxHeight + TVNC.rcParams.borderBottom) + "px"; TVNC.vncdiv.style.clip = "rect(" + TVNC.rcParams.borderLeft + "px," + TVNC.rcParams.maxWidth + "px," + TVNC.rcParams.maxHeight + "px," + TVNC.rcParams.borderBottom + "px)"; TVNC.vncdiv.parentElement.style.overflow = "auto" } TVNC.rcParams.scaled = value; TVNC.scale = TVNC.getScale() }; this.getScale = function() { if(!TVNC.rcParams.scaled) { return TVNC.zoomFactor } var c1 = TVNC.getBodyHeight() / TVNC.rcParams.viewHeight; var c2 = TVNC.getBodyWidth() / TVNC.rcParams.viewWidth; if((c1 > 1) && (c2 > 1)) { return 1 } else { if(c2 < c1) { return c2 * TVNC.zoomFactor } else { return c1 * TVNC.zoomFactor } } }; this.moveCursorCanvas = function(x, y) { if(TVNC.cursorCanvas) { var position = TVNC.findPos(TVNC.vncdiv); var cX = Math.floor((x - position[0]) / TVNC.scale) - TVNC.cursorCanvas.hotspotX; var cY = Math.floor((y - position[1]) / TVNC.scale) - TVNC.cursorCanvas.hotspotY; TVNC.cursorCanvas.style.left = cX + "px"; TVNC.cursorCanvas.style.top = cY + "px" } }; this.getZoom = function() { return TVNC.zoomFactor }; this.zoomDesktop = function(scale) { if(scale != undefined) { if(scale >= 1) { TVNC.zoomFactor = scale } this.scale = scale } else { this.scale = TVNC.getScale() } if(this.centered) { this.center() } var isIE9 = ($.browser.msie && $.browser.version >= 9); if($.browser.mozilla) { this.vncdiv.style.MozTransformOrigin = "top left"; this.vncdiv.style.MozTransform = "scale(" + this.scale + ")" } if($.browser.opera) { this.vncdiv.style.OTransformOrigin = "top left"; this.vncdiv.style.OTransform = "scale(" + this.scale + ")" } if($.browser.webkit) { this.vncdiv.style.WebkitTransformOrigin = "top left"; this.vncdiv.style.WebkitTransform = "scale(" + this.scale + ")" } if($.browser.msie) { if(isIE9) { this.vncdiv.style.msTransformOrigin = "top left"; this.vncdiv.style.msTransform = "scale(" + this.scale + ")" } } }; this.splitKey = function(key) { var sk = { isVolatile: key.length > 6, arr: parseInt(key.substring(0, 2), 10) }; sk.pos = parseInt((sk.isVolatile) ? key.substring(6) : key.substring(2, 6), 10); return sk }; this.getFromImageCache = function(key) { var sk = this.splitKey(key); return(sk.isVolatile) ? this.imageCacheV[sk.arr][sk.pos] : this.imageCache2[sk.arr][sk.pos] }; this.setToImageCache = function(img, key) { if(!img) { logError("Error on setToImageCache: image not found.") } var sk = this.splitKey(key); var aux; if(sk.isVolatile) { aux = this.imageCacheV[sk.arr][sk.pos]; if(aux) { delete aux } this.imageCacheV[sk.arr][sk.pos] = img } else { aux = this.imageCache2[sk.arr][sk.pos]; if(aux) { delete aux } this.imageCache2[sk.arr][sk.pos] = img } }; this.createCanvas = function(win) { var canvas = document.createElement("canvas"); canvas.style.position = "absolute"; canvas.style.left = (win.left - TVNC.rcParams.viewLeft) + "px"; canvas.style.top = (win.top - TVNC.rcParams.viewTop) + "px"; canvas.style.zIndex = this.baseZIndex + win.zidx; canvas.width = win.width; canvas.height = win.height; canvas.id = "canvas" + win.hwnd; canvas.mask = new Object(); canvas.mask.color = "#000"; canvas.mask.visible = false; this.vncdiv.appendChild(canvas); return canvas }; this.decode = function(data) { return codec.decode(data) }; this.cacheFont = function(cmd) { var glyph = new RdpGlyph(cmd.fnt, cmd.chr, cmd.ofs, cmd.bl, cmd.w, cmd.h, this.decode(cmd.data)); if(glyph.font < 12 && glyph.character < 256) { this.rdpGlyphArray[glyph.font][glyph.character] = glyph } else { throw logError("put font: font=" + glyph.font + " c=" + glyph.character), "Could not put font in cache" } }; this.getGlyph = function(font, character) { if(font < 12 && character < 256) { var glyph = this.rdpGlyphArray[font][character]; if(glyph != null) { return glyph } } throw logError("Could not get Font:" + font + ", " + character) }; this.clearFontCache = function() { for(var i = 0; i < 12; i++) { for(var j = 0; j < 256; j++) { delete(this.rdpGlyphArray[i][j]); this.rdpGlyphArray[i][j] = null } } }; this.clearImageCache = function() { var i, j; try { for(i = 0; i < this.imageCache2.length; i++) { for(j = 0; j < this.imageCache2[i].length; j++) { if(this.imageCache2[i][j]) { delete this.imageCache2[i][j]; this.imageCache2[i][j] = null } } for(j = 0; j < this.imageCacheV[i].length; j++) { if(this.imageCacheV[i][j]) { delete(this.imageCacheV[i][j]); this.imageCacheV[i][j] = null } } } } catch(e) { logError(e.Message) } }; this.clearTextCache = function() { for(var i = 0; i < this.textCache.length; i++) { delete(this.textCache[i]); this.textCache[i] = null } }; this.cachePutText = function(cache_id, data, idx, len) { var carray = Array(len); for(n = 0; n < len; n++) { carray[n] = data[idx + n] } textEntry = new TextEntry(len, carray); if(cache_id < this.textCache.length) { this.textCache[cache_id] = textEntry } else { throw "Could not put Text in cache" } }; this.cacheGetText = function(cache_id) { var entry = null; if(cache_id < this.textCache.length) { entry = this.textCache[cache_id]; if(entry != null && entry.data != null) { return entry } } }; this.toRGB = function(color) { var rgb = "rgba(" + (color >> 16 & 255) + ","; rgb += (color >> 8 & 255) + ","; rgb += (color & 255) + ",1)"; return rgb }; this.putRdpText = function(cmd, context) { var text = this.decode(cmd.text), idx = 0, ch = 0; if(typeof cmd.bcx != "undefined") { context.fillStyle = this.toRGB(cmd.bc); context.fillRect(cmd.bx, cmd.by, cmd.bcx, cmd.bcy); cmd.lx = cmd.bx; cmd.ly = cmd.by; cmd.lcx = cmd.bcx; cmd.lcy = cmd.bcy } else { if(cmd.mm == 1) { context.fillStyle = this.toRGB(cmd.bc); context.fillRect(cmd.lx, cmd.ly, cmd.lcx, cmd.lcy) } } cmd.maxX = cmd.lx + cmd.lcx - 1; cmd.maxY = cmd.ly + cmd.lcy - 1; if(cmd.lcx * cmd.lcy == 0) { return } var imgdata = null; var length = cmd.len; var j = 0; var vert = ((cmd.fl & 4) == 4); var horiz_implicit = ((cmd.fl & 32) != 0); while(j < length) { switch(text[j] & 255) { case 255: if(j + 2 < cmd.len) { this.cachePutText(text[j + 1], text, 0, text[j + 2] & 255) } else { throw "Index out of range!" } length -= j + 3; text = text.slice(j + 3); j = 0; break; case 254: var entry = this.cacheGetText(text[j + 1] & 255); if(entry) { if((entry.data[1] == 0) && !horiz_implicit) { if(!vert) { cmd.x += text[j + 2] & 255 } else { cmd.y += text[j + 2] & 255 } } for(k = 0; k < entry.size; k++) { if(!imgdata) { imgdata = context.getImageData(cmd.lx, cmd.ly, cmd.lcx, cmd.lcy) } this.doGlyph(context, imgdata, cmd, entry.data, k); if(!horiz_implicit) { k++ } } }(j + 2 < length) ? j += 3 : j += 2; length -= j; text = text.slice(j); j = 0; break; default: if(!imgdata) { imgdata = context.getImageData(cmd.lx, cmd.ly, cmd.lcx, cmd.lcy) } this.doGlyph(context, imgdata, cmd, text, j); if(!horiz_implicit) { j++ } j++ } } if(imgdata) { context.putImageData(imgdata, cmd.lx, cmd.ly) } }; this.doGlyph = function(context, imgdata, cmd, text, idx) { var xyoffset = 0, j = 0, Bpp = Math.floor((cmd.bpp + 7) / 8); glyph = this.getGlyph(cmd.fnt, text[idx + j] & 255); if(glyph) { if((cmd.fl & 32) == 0) { xyoffset = text[idx + ++j] & 255; if((xyoffset & 128) != 0) { xyoffset = text[idx + j + 1] & 255 | (text[idx + j + 2] & 255 << 8) } if(cmd.fl & 4) { cmd.y += xyoffset } else { cmd.x += xyoffset } } this.drawGlyph(context, imgdata, cmd, glyph, Bpp); if(cmd.fl & 32) { cmd.x += glyph.width } } }; this.drawGlyph = function(context, imgdata, cmd, glyph, Bpp) { var x = cmd.x + glyph.offset & 65535, y = cmd.y + glyph.baseLine & 65535, dataWidth = Math.ceil(glyph.width / 8) * 8, glyphWidth = glyph.width, glyphHeight = glyph.height, fontData = glyph.fontData, desktopWidth = TVNC.rcParams.viewWidth, desktopHeight = TVNC.rcParams.viewHeight, foreColor = cmd.fc, backColor = cmd.bc, bit = 128, line, pixel; if(((x + glyphWidth) < cmd.lx) || (x > cmd.maxX) || ((y + glyphHeight) < cmd.ly) || (y > cmd.maxY)) { return } var data = imgdata.data; if(!(x > desktopWidth || y > desktopHeight)) { for(line = 0; line < glyphHeight; line++) { if(((line + y) >= cmd.ly) && ((line + y) <= cmd.maxY)) { for(var pixel = 0; pixel < glyphWidth; pixel++) { if(((pixel + x) >= cmd.lx) && ((pixel + x) <= cmd.maxX)) { var pixelOffset = ((line + (y - cmd.ly)) * (cmd.lcx) + pixel + (x - cmd.lx)) * 4; var byteIndex = Math.floor((line * dataWidth + pixel) / 8); bit = (fontData[byteIndex] >> (7 - pixel % 8)) & 1; try { if(bit) { this.setPixel(data, pixelOffset, foreColor) } else { if(cmd.mm == 1) { this.setPixel(data, pixelOffset, backColor) } } } catch(err) { logError(err) } } } } } } }; this.setPixel32 = function(data, pixelOffset, color) { data[pixelOffset] = color }; this.setPixel = function(data, pixelOffset, color) { data[pixelOffset] = color >> 16 & 255; data[pixelOffset + 1] = color >> 8 & 255; data[pixelOffset + 2] = color & 255; data[pixelOffset + 3] = 255 }; this.doROP = function(rop, src, dst) { switch(rop) { case 0: return 0; case 1: return ~ (src | dst); case 2: return(~src) & dst; case 3: return ~src; case 4: return src & (~dst); case 5: return ~ (dst); case 6: return src ^ dst; case 7: return ~ (src & dst); case 8: return src & dst; case 9: return ~ (src) ^ dst; case 10: return dst; case 11: return(~src) | dst; case 12: return src; s; case 13: return src | (~dst); case 14: return src | dst; case 15: return ~0; case 16: return ~src & ~dst } return dst }; this.doROP3 = function(rop, src, dst, bc, fc) { switch(rop) { case 0: return 0; case 1: return ~ (src | dst); case 2: return(~src) & dst; case 3: return ~src; case 4: return src & (~dst); case 5: return ~ (dst); case 6: return src ^ dst; case 7: return ~ (src & dst); case 8: return src & dst; case 9: return ~ (src) ^ dst; case 10: return dst; case 11: return(~src) | dst; case 12: return src; case 13: return src | (~dst); case 14: return src | dst; case 15: return ~0; case 16: return ~src & ~dst; case 17: return ~src & fc; case 18: return src == 0 ? bc : fc; case 19: return dst | (fc | ~src); case 20: return src == 0 ? bc ^ dst : fc ^ dst; case 21: return(src & fc) | (~src & dst); case 22: return src & ~fc; case 23: return dst ^ ~fc } return dst }; this.registerDrawCmd = function(cmd, callback) { if(!TVNC.registeredDrawCmds) { TVNC.registeredDrawCmds = new Array() } TVNC.registeredDrawCmds.push({ cmd: cmd, callback: callback }) }; this.drawCmdFillRect = function(cmd, context) { var isXOR = cmd.pm && cmd.pm == 14; var isBSHollow = cmd.bs && cmd.bs == 1; if(isXOR) { context.save(); try { var imgdata = null; try { imgdata = context.getImageData(cmd.x, cmd.y, cmd.w, cmd.h) } catch(e) { if(jQuery.browser.mozilla) { netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"); imgdata = context.getImageData(cmd.x, cmd.y, cmd.w, cmd.h) } } if(imgdata) { var data = imgdata.data; var canPaint = true; var x, y = 0, offset = 0, r, g, b, pixel, color; for(y = 0; y < cmd.h; y++) { for(x = 0; x < cmd.w; x++, offset += 4) { canPaint = !isBSHollow || (y == 0 || y == cmd.h - 1) || (x == 0 || x == cmd.w - 1); if(canPaint) { if(isXOR) { r = 4294967295 & imgdata.data[offset]; g = 4294967295 & imgdata.data[offset + 1]; b = 4294967295 & imgdata.data[offset + 2]; pixel = ((r << 16) & 16777215) | ((g << 8) & 16777215) | b; color = this.doROP(6, pixel, 4294967295 & cmd.clr) } else { color = 4294967295 & cmd.clr } this.setPixel(data, offset, color) } } } context.putImageData(imgdata, cmd.x, cmd.y) } } finally { context.globalCompositeOperation = "source-over"; context.restore() } } else { context.fillStyle = this.toRGB(cmd.clr); if(cmd.pm && cmd.pm == 14) { context.globalCompositeOperation = "xor" } context.fillRect(cmd.x, cmd.y, cmd.w, cmd.h); context.globalCompositeOperation = "source-over" } }; this.drawCmdLineTo = function(cmd, context) { context.save(); try { if(cmd.cw && cmd.ch) { context.beginPath(); context.rect(cmd.cl, cmd.ct, cmd.cw, cmd.ch); context.clip() } var isHorizOrVert = false; var lineW = 1, lineH = 1; if(cmd.ey - cmd.y == 0) { isHorizOrVert = true; lineW = cmd.w; if(lineW == 0) { lineW = 1 } } if(cmd.ex - cmd.x == 0) { isHorizOrVert = true; lineH = cmd.w; if(lineH == 0) { lineH = 1 } } var isXOR = cmd.o && (cmd.o == 7); var isNOT = cmd.o && (cmd.o == 6); if(isHorizOrVert && isXOR) { var ox = Math.min(cmd.ex, cmd.x); var oy = Math.min(cmd.ey, cmd.y); cmd.cx = Math.abs(cmd.ex - cmd.x) + lineW; cmd.cy = Math.abs(cmd.ey - cmd.y) + lineH; var imgdata = null; try { imgdata = context.getImageData(ox, oy, cmd.cx, cmd.cy) } catch(e) { if(jQuery.browser.mozilla) { netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"); imgdata = context.getImageData(ox, oy, cmd.cx, cmd.cy) } } if(imgdata) { var data = imgdata.data; var x, y = 0, offset = 0, r, g, b, pixel, color; for(y = 0; y < cmd.cy; y++) { for(x = 0; x < cmd.cx; x++, offset += 4) { if(isXOR || isNOT) { r = 4294967295 & imgdata.data[offset]; g = 4294967295 & imgdata.data[offset + 1]; b = 4294967295 & imgdata.data[offset + 2]; pixel = ((r << 16) & 16777215) | ((g << 8) & 16777215) | b; if(isXOR) { color = this.doROP(6, pixel, 4294967295 & cmd.fg) } else { color = this.doROP(3, pixel, 4294967295) } } else { color = 4294967295 & cmd.fg } this.setPixel(data, offset, color) } } context.putImageData(imgdata, ox, oy) } } else { if(cmd.ey - cmd.y == 0) { cmd.y += 0.5; cmd.ey += 0.5 } if(cmd.ex - cmd.x == 0) { cmd.x += 0.5; cmd.ex += 0.5 } context.beginPath(); if(isXOR || isNOT) { context.globalCompositeOperation = "xor" } context.moveTo(cmd.x, cmd.y); context.lineTo(cmd.ex, cmd.ey); context.lineWidth = cmd.w; if(isNOT) { context.strokeStyle = this.toRGB(4294967295) } else { context.strokeStyle = this.toRGB(cmd.fg) } context.stroke() } } finally { context.globalCompositeOperation = "source-over"; context.restore() } }; this.drawCmdScreenBltOld = function(cmd, canvas, context) { var imagedata = null; try { imagedata = context.getImageData(cmd.sx, cmd.sy, cmd.cx, cmd.cy) } catch(e) { if(jQuery.browser.mozilla) { netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"); imagedata = context.getImageData(cmd.sx, cmd.sy, cmd.cx, cmd.cy) } } if(imagedata) { context.putImageData(imagedata, cmd.x, cmd.y) } }; this.drawCmdScreenBlt = function(cmd, canvas, context) { var buffer = document.createElement("canvas"); buffer.width = cmd.cx; buffer.height = cmd.cy; buffer.getContext("2d").drawImage(canvas, -cmd.sx, -cmd.sy); context.drawImage(buffer, cmd.x, cmd.y) }; this.drawCmdDrawEdge = function(cmd, context) { cmd.ex = cmd.x + cmd.w; cmd.ey = cmd.y + cmd.h; var borderStyles = { BDR_RAISEDOUTER: 1, BDR_SUNKENOUTER: 2, BDR_RAISEDINNER: 4, BDR_SUNKENINNER: 8, BDR_OUTER: 3, BDR_INNER: 12, BDR_RAISED: 5, BDR_SUNKEN: 10 }; var edge = { EDGE_RAISED: borderStyles.BDR_RAISEDOUTER | borderStyles.BDR_RAISEDINNER, EDGE_SUNKEN: borderStyles.BDR_SUNKENOUTER | borderStyles.BDR_SUNKENINNER, EDGE_ETCHED: borderStyles.BDR_SUNKENOUTER | borderStyles.BDR_RAISEDINNER, EDGE_BUMP: borderStyles.BDR_RAISEDOUTER | borderStyles.BDR_SUNKENINNER }; var borderFlags = { BF_LEFT: 1, BF_TOP: 2, BF_RIGHT: 4, BF_BOTTOM: 8, BF_DIAGONAL: 16, BF_MIDDLE: 2048, BF_SOFT: 4096, BF_ADJUST: 8192, BF_FLAT: 16384, BF_MONO: 32768 }; var borderFlag = { BF_TOPLEFT: borderFlags.BF_TOP | borderFlags.BF_LEFT, BF_TOPRIGHT: borderFlags.BF_TOP | borderFlags.BF_RIGHT, BF_BOTTOMLEFT: borderFlags.BF_BOTTOM | borderFlags.BF_LEFT, BF_BOTTOMRIGHT: borderFlags.BF_BOTTOM | borderFlags.BF_RIGHT, BF_RECT: borderFlags.BF_TOP | borderFlags.BF_LEFT | borderFlags.BF_BOTTOM | borderFlags.BF_RIGHT, BF_DIAGONAL_ENDTOPRIGHT: borderFlags.BF_DIAGONAL | borderFlags.BF_TOP | borderFlags.BF_RIGHT, BF_DIAGONAL_ENDTOPLEFT: borderFlags.BF_DIAGONAL | borderFlags.BF_TOP | borderFlags.BF_LEFT, BF_DIAGONAL_ENDBOTTOMLEFT: borderFlags.BF_DIAGONAL | borderFlags.BF_BOTTOM | borderFlags.BF_LEFT, BF_DIAGONAL_ENDBOTTOMRIGHT: borderFlags.BF_DIAGONAL | borderFlags.BF_BOTTOM | borderFlags.BF_RIGHT }; context.save(); if(cmd.pm && cmd.pm == 14) { context.globalCompositeOperation = "xor" } context.lineWidth = cmd.pw; context.strokestyle = this.toRGB(cmd.clr); if(cmd.e == edge.EDGE_SUNKEN && cmd.f & borderFlags.BF_SOFT == borderFlags.BF_SOFT) {} if(cmd.e == edge.EDGE_RAISED && cmd.f & borderFlags.BF_SOFT == borderFlags.BF_SOFT) {} if(cmd.f & borderFlags.BF_TOP == borderFlags.BF_TOP) { context.beginPath(); context.moveTo(cmd.x, cmd.y); context.lineTo(cmd.ex, cmd.y); context.stroke() } if(cmd.f & borderFlags.BF_LEFT == borderFlags.BF_LEFT) { context.beginPath(); context.moveTo(cmd.x, cmd.y); context.lineTo(cmd.x, cmd.ey); context.stroke() } if(cmd.f & borderFlags.BF_BOTTOM == borderFlags.BF_BOTTOM) { context.beginPath(); context.moveTo(cmd.x, cmd.ey); context.lineTo(cmd.ex, cmd.ey); context.stroke() } if(cmd.f & borderFlags.BF_RIGHT == borderFlags.BF_RIGHT) { context.beginPath(); context.moveTo(cmd.ex, cmd.y); context.lineTo(cmd.ex, cmd.ey); context.stroke() } context.globalCompositeOperation = "source-over"; context.restore() }; this.processDrawCmds = function(root, win, canvas, context) { var oriContext = context; if(win.cmds) { var cmd, i, img, item, sx, sy; for(i = 0; i < win.cmds.length; i++) { if(this.offscreenCanvas) { context = this.offscreenCanvas.getContext("2d") } else { context = oriContext } try { cmd = win.cmds[i]; if(cmd.c == "IC") { if(typeof cmd.qidx != "undefined" && typeof root.imgQueue != "undefined") { if(root.imgQueue && root.imgQueue.items) { item = root.imgQueue.items[cmd.qidx] } if(root.imgQueue && root.imgQueue.items && item) { img = item.img; TVNC.setToImageCache(img, cmd.k) } else { continue } } else { img = TVNC.getFromImageCache(cmd.k) } if(!img || img.width == 0) { logError("Cache: image " + cmd.k + " is not loaded, qidx: " + cmd.qidx); continue } sx = 0, sy = 0; if(typeof cmd.sx != "undefined") { sx = cmd.sx; sy = cmd.sy } if(typeof cmd.o == "undefined" || cmd.o == 12) { try { context.drawImage(img, sx, sy, cmd.cx, cmd.cy, cmd.x, cmd.y, cmd.cx, cmd.cy) } catch(err) { logError("error in drawimage img:" + cmd.k + ",sx:" + sx + ",sy:" + sy + ",cmd.x:" + cmd.x + ",cmd.y:" + cmd.y + ",cmd.cx:" + cmd.cx + ",cmd.cy:" + cmd.cy + ",img.width:" + img.width + ",img.height:" + img.height) } } else { var auxCanvas = document.createElement("canvas"); auxCanvas.width = img.width; auxCanvas.height = img.height; var auxContext = auxCanvas.getContext("2d"); try { auxContext.drawImage(img, 0, 0, img.width, img.height) } catch(err) { logError("error on auxContext.drawImage") } var auxImageData = null; try { auxImageData = auxContext.getImageData(sx, sy, cmd.cx, cmd.cy) } catch(e) { if(jQuery.browser.mozilla) { netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"); auxImageData = auxContext.getImageData(sx, sy, cmd.cx, cmd.cy) } } var imagedata = null; try { imagedata = context.getImageData(cmd.x, cmd.y, cmd.cx, cmd.cy) } catch(e) { if(jQuery.browser.mozilla) { netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"); imagedata = context.getImageData(cmd.x, cmd.y, cmd.cx, cmd.cy) } } if(auxImageData && imagedata) { var data = imagedata.data; var offset = 0; var auxData = auxImageData.data; for(var line = 0; line < cmd.cy; line++) { for(var col = 0; col < cmd.cx; col++, offset += 4) { var r = 4294967295 & auxData[offset]; var g = 4294967295 & auxData[offset + 1]; var b = 4294967295 & auxData[offset + 2]; var color = ((r << 16) & 16777215) | ((g << 8) & 16777215) | b; r = 4294967295 & data[offset]; g = 4294967295 & data[offset + 1]; b = 4294967295 & data[offset + 2]; var pixel = ((r << 16) & 16777215) | ((g << 8) & 16777215) | b; color = this.doROP3(cmd.o, color, pixel, cmd.bc, cmd.fc); data[offset] = (color >> 16) & 255; data[offset + 1] = (color >> 8) & 255; data[offset + 2] = color & 255 } } imagedata.data = data; context.putImageData(imagedata, cmd.x, cmd.y) } } } else { if(cmd.c == "IP") { var sx = 0, sy = 0; if(typeof cmd.sx != "undefined") { sx = cmd.sx; sy = cmd.sy } try { context.drawImage(root.imgQueue.items[cmd.qidx].img, sx, sy, cmd.cx, cmd.cy, cmd.x, cmd.y, cmd.cx, cmd.cy) } catch(ex) { logError("IP: context.drawImage failed. cmd.qidx=" + cmd.qidx); if(root.imgQueue.items[cmd.qidx]) { logError("size: " + root.imgQueue.items[cmd.qidx].img.width + "x" + root.imgQueue.items[cmd.qidx].img.height) } } TVNC.queueRecycleImg.push(cmd.img); win.cmds[i].img = null } else { if(cmd.c == "CB") { var item = root.imgQueue.items[cmd.qidx]; if(item) { TVNC.brushCache[cmd.idx] = item.img } } else { if(cmd.c == "FR") { TVNC.drawCmdFillRect(cmd, context) } else { if(cmd.c == "PB") { var auxCanvas = document.createElement("canvas"); auxCanvas.width = cmd.cx; auxCanvas.height = cmd.cy; var auxContext = auxCanvas.getContext("2d"); cmd.fc &= 16777215; cmd.bc &= 16777215; if(cmd.bs == 0) { auxContext.fillStyle = this.toRGB(cmd.fc); auxContext.fillRect(0, 0, cmd.cx, cmd.cy) } else { var img; if(cmd.cidx >= 0) { img = TVNC.brushCache[cmd.cidx] } else { var item = root.imgQueue.items[cmd.qidx]; if(!item) { logError("pattern missing"); continue } img = item.img } var ptrn = context.createPattern(img, "repeat"); auxContext.fillStyle = ptrn; auxContext.fillRect(0, 0, cmd.cx, cmd.cy) } var auxImageData = auxContext.getImageData(0, 0, cmd.cx, cmd.cy); var imagedata = context.getImageData(cmd.x, cmd.y, cmd.cx, cmd.cy); if(auxImageData && imagedata) { var data = imagedata.data; var offset = 0; var auxData = auxImageData.data; for(var line = 0; line < cmd.cy; line++) { for(var col = 0; col < cmd.cx; col++, offset += 4) { var r = 4294967295 & auxData[offset]; var g = 4294967295 & auxData[offset + 1]; var b = 4294967295 & auxData[offset + 2]; var color = ((r << 16) & 16777215) | ((g << 8) & 16777215) | b; r = 4294967295 & data[offset]; g = 4294967295 & data[offset + 1]; b = 4294967295 & data[offset + 2]; var pixel = ((r << 16) & 16777215) | ((g << 8) & 16777215) | b; color = this.doROP3(cmd.o, color, pixel, cmd.bc, cmd.fc); data[offset] = (color >> 16) & 255; data[offset + 1] = (color >> 8) & 255; data[offset + 2] = color & 255 } } imagedata.data = data; context.putImageData(imagedata, cmd.x, cmd.y) } } else { if(cmd.c == "SB") { TVNC.drawCmdScreenBlt(cmd, canvas, context) } else { if(cmd.c == "LI") { TVNC.drawCmdLineTo(cmd, context) } else { if(cmd.c == "PL") { if(cmd.p.length > 0) { var n; var px = cmd.p[0].x; var py = cmd.p[0].y; var cx; var cy; var vertical = false; var horizontal = false; for(n = 1; n < cmd.p.length; n++) { cx = cmd.p[n].x; cy = cmd.p[n].y; if(cx - px == 0) { if(!vertical) { cmd.p[n - 1].x += 0.5 } vertical = true; cmd.p[n].x += 0.5 } else { vertical = false } if(cy - py == 0) { if(!horizontal) { cmd.p[n - 1].y += 0.5 } horizontal = true; cmd.p[n].y += 0.5 } else { horizontal = false } px = cx; py = cy } context.save(); if(cmd.cw && cmd.ch) { context.beginPath(); context.rect(cmd.cl, cmd.ct, cmd.cw, cmd.ch); context.clip() } if(cmd.pm && cmd.pm == 14) { context.globalCompositeOperation = "xor" } context.beginPath(); context.moveTo(cmd.p[0].x, cmd.p[0].y); for(n = 1; n < cmd.p.length; n++) { context.lineTo(cmd.p[n].x, cmd.p[n].y) } context.lineWidth = cmd.w; context.strokeStyle = this.toRGB(cmd.fg); context.stroke(); context.globalCompositeOperation = "source-over"; context.restore() } } else { if(cmd.c == "DE") { TVNC.drawCmdDrawEdge(cmd, context) } else { if(cmd.c == "CR") { context.save(); if(cmd.r.length == 0) { context.beginPath(); context.rect(0, 0, 0, 0); context.clip() } else { context.beginPath(); for(n = 0; n < cmd.r.length; n++) { var r = cmd.r[n]; context.rect(r.x, r.y, r.cx, r.cy) } context.clip() } } else { if(cmd.c == "ER") { var canvasid = "canvasER"; TVNC.canvasER = document.getElementById(canvasid); if(!TVNC.canvasER) { TVNC.canvasER = document.createElement("canvas"); TVNC.canvasER.style.zIndex = TVNC.baseZIndex + 499; TVNC.canvasER.style.position = "absolute"; TVNC.canvasER.style.left = "0px"; TVNC.canvasER.style.top = "0px"; TVNC.canvasER.id = canvasid; TVNC.vncdiv.appendChild(TVNC.canvasER) } TVNC.canvasER.width = TVNC.rcParams.viewWidth; TVNC.canvasER.height = TVNC.rcParams.viewHeight; var auxContext = TVNC.canvasER.getContext("2d"); auxContext.restore(); auxContext.clearRect(0, 0, TVNC.canvasER.offsetWidth, TVNC.canvasER.offsetHeight); auxContext.fillStyle = canvas.mask.color; for(n = 0; n < cmd.r.length; n++) { var r = cmd.r[n]; auxContext.fillRect(r.x, r.y, r.cx, r.cy) } } else { if(cmd.c == "EA") { $(window).trigger("execRemoteApp", [cmd]) } else { if(cmd.c == "EX") { $(window).trigger("execResult", [cmd]) } else { if(cmd.c == "TX") { try { this.putRdpText(cmd, context) } catch(err) { logError(err) } } else { if(cmd.c == "FC") { this.cacheFont(cmd) } else { if(cmd.c == "DB") { this.dstblt(context, cmd.o, 0, cmd.x, cmd.y, cmd.cx, cmd.cy) } else { if(cmd.c == "OB") { this.CreateOffscreenBitmap(cmd.id, cmd.cx, cmd.cy, cmd.dlist) } else { if(cmd.c == "SS") { this.SwitchSurface(cmd.id) } else { if(cmd.c == "MO") { if(!cmd.sx) { cmd.sx = 0 } if(!cmd.sy) { cmd.sy = 0 } this.MembltOffscreen(oriContext, cmd.o, cmd.id, cmd.x, cmd.y, cmd.cx, cmd.cy, cmd.sx, cmd.sy) } else { if(cmd.c == "RC") { $(window).trigger("remoteCommand", [cmd.r]) } else { if(cmd.c == "FD") { $(window).trigger("fileDownload", [cmd.fn]) } else { if(TVNC.registeredDrawCmds) { for(var n = 0; n < TVNC.registeredDrawCmds.length; n++) { if(TVNC.registeredDrawCmds[n].cmd == cmd.c) { TVNC.registeredDrawCmds[n].callback(cmd, win, context); break } } } } } } } } } } } } } } } } } } } } } } } } } catch(err) { logError("error on processDrawCmds: " + err) } } } this.processImages(root, win, oriContext) }; this.CreateOffscreenBitmap = function(id, cx, cy, dlist) { if(this.offscreenCache[id]) { delete(this.offscreenCache[id]) } var canvas = document.createElement("canvas"); canvas.visibility = "visible"; canvas.display = "block"; canvas.style.position = "absolute"; canvas.style.left = -cx; canvas.style.top = -cy; canvas.style.zIndex = -1; canvas.width = cx; canvas.height = cy; this.offscreenCache[id] = canvas; for(var i = 0; i < dlist.length; i++) { if(this.offscreenCache[dlist[i]]) { delete(this.offscreenCache[dlist[i]]); this.offscreenCache[dlist[i]] = null } } }; this.SwitchSurface = function(id) { if(id == 65535) { this.offscreenCanvas = null } else { this.offscreenCanvas = this.offscreenCache[id] } }; this.MembltOffscreen = function(context, o, id, x, y, cx, cy, sx, sy) { var srcContext = this.offscreenCache[id].getContext("2d"); var srcImageData = srcContext.getImageData(sx, sy, cx, cy); context.putImageData(srcImageData, x, y) }; this.clearOffscreenCache = function() { for(var i = 0; i < this.offscreenCache.length; i++) { if(this.offscreenCache[i]) { delete(this.offscreenCache[i]) } this.offscreenCache[i] = null } }; this.dstblt = function(context, rop, srccolor, x, y, cx, cy) { var imagedata = null; try { imagedata = context.getImageData(x, y, cx, cy) } catch(e) { if(jQuery.browser.mozilla) { netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"); imagedata = context.getImageData(x, y, cx, cy) } } if(imagedata) { var data = imagedata.data; var offset = 0; for(var line = 0; line < cy; line++) { for(var col = 0; col < cx; col++, offset += 4) { var color = srccolor; if(rop != 12) { var r = 4294967295 & data[offset]; var g = 4294967295 & data[offset + 1]; var b = 4294967295 & data[offset + 2]; var pixel = ((r << 16) & 16777215) | ((g << 8) & 16777215) | b; color = this.doROP(rop, color, pixel) } data[offset] = (color >> 16) & 255; data[offset + 1] = (color >> 8) & 255; data[offset + 2] = color & 255 } } imagedata.data = data; context.putImageData(imagedata, x, y) } }; this.processNextScreen = function() { if(TVNC.msgQueue.length > TVNC.rcParams.xoffThreshold) { TVNC.sendXoff() } else { if(TVNC.msgQueue.length < TVNC.rcParams.xonThreshold) { TVNC.sendXon() } } if(TVNC.msgQueue.length > 0) { var m = TVNC.msgQueue[0]; if(!m.imgQueue || m.imgQueue.loaded == m.imgcnt || m.imgQueue.aborted()) { if(TVNC.imageListType == 0 && m.windows && !m.imgQueue) { TVNC.buildImgQueue(m); if(m.imgQueue.loaded < m.imgcnt && !m.imgQueue.aborted()) { return } } m = TVNC.msgQueue.shift(); TVNC.receiveScreen(m) } m = null } }; this.buildImgQueue = function(msg) { try { var w, win, c, cmds, cmd, i; if(!msg.imgQueue) { msg.imgQueue = TVNC.createImageQueue(0) } for(w = 0; w < msg.windows.length; w++) { win = msg.windows[w]; if(win.cmds) { cmds = win.cmds; for(i = 0; i < cmds.length; i++) { cmd = cmds[i]; if((cmd.c == "IC" || cmd.c == "IP" || cmd.c == "PB") && cmd.d) { this.addToImgQueue(msg.imgQueue, cmd, "c"); msg.imgcnt++ } } } if(win.imgs) { imgs = win.imgs; for(i = 0; i < imgs.length; i++) { img = imgs[i]; this.addToImgQueue(msg.imgQueue, img, "i"); msg.imgcnt++ } } } this.processImgQueue(msg.imgQueue) } catch(e) { logError("buildImgQueue error: " + e.message) } }; this.addToImgQueue = function(imgQueue, oJS, srcType) { var i = oJS.qidx = imgQueue.items.length; if(srcType == "c") { imgQueue.items.push({ idx: i, stream: "data:image/" + oJS.t + ";base64," + oJS.d, img: null, ready: false }); oJS.d = null } else { imgQueue.items.push({ idx: i, stream: oJS.img, img: null, ready: false }); oJS.img = null } }; this.InsertIntoImgQueueAndExecute = function(imgQueue, idx, src) { if(typeof imgQueue.items[idx] != "undefined") { logError("image " + idx + " already exists on group " + imgQueue.group + " item: " + imgQueue.items[idx]) } imgQueue.items[idx] = { idx: idx, stream: src, img: null, ready: false }; imgQueue.count++; imgQueue.startTime = (new Date()).getTime(); this.processImgQueueItem(imgQueue, imgQueue.items[idx]) }; this.addToImgQueueAndExecute = function(imgQueue, src) { var i = imgQueue.items.length; imgQueue.items.push({ idx: i, stream: src, img: null, ready: false }); this.processImgQueueItem(imgQueue, imgQueue.items[i]); return i }; this.processImgQueueItem = function(imgQueue, item) { var img = item.img = new Image(); img.onload = function() { item.ready = true; item.error = 0; item.stream = ""; imgQueue.loaded++; TVNC.postCallback(TVNC.processNextScreen) }; img.onerror = function() { item.ready = true; item.error = 1; img = null; logError("image # " + item.idx + " with errors"); imgQueue.loaded++; TVNC.postCallback(TVNC.processNextScreen) }; img.onabort = function() { item.ready = true; item.error = 2; img = null; logError("image # " + item.idx + " with errors"); imgQueue.loaded++ }; img.src = item.stream }; this.purgeImgQueue = function(imgQueue) { if(!imgQueue) { return } try { for(var i = 0; i < imgQueue.items.length; i++) { if(imgQueue.items[i] && imgQueue.items[i].img) { delete imgQueue.items[i].img; imgQueue.items[i] = null } } } finally { imgQueue.items.length = 0; imgQueue.loaded = 0; imgQueue.count = 0; imgQueue.startTime = 0 } }; this.processImgQueue = function(imgQueue) { if(!imgQueue.items) { return } for(var i = 0; i < imgQueue.items.length; i++) { this.processImgQueueItem(imgQueue, imgQueue.items[i]) } }; this.postCallback = function(callback) { if(window.requestAnimationFrame) { window.requestAnimationFrame(callback) } else { if(window.webkitRequestAnimationFrame) { window.webkitRequestAnimationFrame(callback) } else { if(window.mozRequestAnimationFrame) { window.mozRequestAnimationFrame(callback) } else { if(window.msRequestAnimationFrame) { window.msRequestAnimationFrame(callback) } else { setTimeout(callback, 1) } } } } }; this.processImages = function(root, win, context) { if(typeof win.imgs !== "undefined") { var imgpart, imgJS, img; for(var i = 0; i < win.imgs.length; i++) { imgpart = win.imgs[i]; if(!root.imgQueue) { logError("Error on processImages: root.imgQueue not found."); return } imgJS = root.imgQueue.items[imgpart.qidx]; if(!imgJS) { logError("Error on processImages: imgJS not found. Idx:" + imgpart.qidx) } else { try { img = imgJS.img; context.drawImage(img, imgpart.x, imgpart.y, img.width, img.height) } catch(ex) { logError("Error on processImages: " + ex.message) } } } } if(win.last) { this.purgeImgQueue(root.imgQueue); TVNC.postCallback(TVNC.processNextScreen) } }; this.cursorCanvasX = function() { var position = TVNC.findPos(TVNC.vncdiv); return(TVNC.cursorCanvas.offsetLeft + TVNC.cursorCanvas.hotspotX) * TVNC.scale + position[0] }; this.cursorCanvasY = function() { var position = TVNC.findPos(TVNC.vncdiv); return(TVNC.cursorCanvas.offsetTop + TVNC.cursorCanvas.hotspotY) * TVNC.scale + position[1] }; this.processWindow = function(root, win) { var oldCursorCanvasX = null, oldCursorCanvasY = null; if(typeof win.hwnd == "undefined") { setTimeout(TVNC.reload, 1); return } if(win.hwnd == 0 && typeof win.imgs != "undefined" && this.cursorCanvas) { oldCursorCanvasX = this.cursorCanvas.style.left; oldCursorCanvasY = this.cursorCanvas.style.top; this.cursorCanvas.style.display = "none"; if(this.cursorCanvas.mask) { delete this.cursorCanvas.mask; this.cursorCanvas.mask = null } this.cursorCanvas.innerHTML = ""; try { TVNC.vncdiv.removeChild(this.cursorCanvas); delete this.cursorCanvas } catch(err) { logError("processWindow: " + err) } this.cursorCanvas = null } var canvasid = "canvas" + win.hwnd; var canvas = document.getElementById(canvasid); if(!canvas) { canvas = this.createCanvas(win) } if(win.hwnd == 0) { this.cursorCanvas = canvas; if(typeof win.dx != "undefined") { canvas.hotspotX = win.dx; canvas.hotspotY = win.dy } canvas.style.zIndex = this.baseZIndex + 5000; if(typeof win.imgs != "undefined" && typeof win.width != "undefined") { canvas.width = win.width; canvas.height = win.height; canvas.style.left = oldCursorCanvasX; canvas.style.top = oldCursorCanvasY } } if((typeof win.width != "undefined") && ((win.width == 0) || (win.height == 0))) { canvas.style.visibility = "hidden"; canvas.style.zIndex = -1 } else { if(typeof win.left != "undefined" && (this.cursorCanvas != canvas || !TVNC.rcParams.mouseControl)) { canvas.style.left = (win.left - TVNC.rcParams.viewLeft) + "px"; canvas.style.top = (win.top - TVNC.rcParams.viewTop) + "px" } if(typeof win.width != "undefined" && (win.width != canvas.width || win.height != canvas.height)) { if(canvas.width * canvas.height == 0) { canvas.width = win.width; canvas.height = win.height } else { var context = canvas.getContext("2d"); var imagedata = null; try { imagedata = context.getImageData(0, 0, Math.min(canvas.width, win.width), Math.min(canvas.height, win.height)) } catch(e) { if(jQuery.browser.mozilla) { netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"); imagedata = context.getImageData(0, 0, Math.min(canvas.width, win.width), Math.min(canvas.height, win.height)) } } canvas.width = win.width; canvas.height = win.height; if(imagedata) { context.putImageData(imagedata, 0, 0) } else { if(this.cursorCanvas != canvas) { context.fillStyle = "#CCC"; context.fillRect(0, 0, win.width, win.height) } } if(this.cursorCanvas != canvas) { context.strokeRect(0, 0, canvas.width, canvas.height) } context = null; imagedata = null } } if(typeof win.width != "undefined" && typeof win.left != "undefined" && typeof win.height != "undefined" && typeof win.top != "undefined") { canvas.style.clip = "rect(0px," + Math.min(win.width, TVNC.rcParams.viewWidth - win.left) + "px," + Math.min(win.height, TVNC.rcParams.viewHeight - win.top) + "px,0px)" } if(typeof win.width != "undefined") { canvas.style.visibility = "visible" } canvas.style.zIndex = this.baseZIndex + win.zidx } if(!canvas.mask.visible && (typeof win.width != "undefined") && win.mask) { var context = canvas.getContext("2d"); context.fillStyle = canvas.mask.color; context.fillRect(0, 0, canvas.width, canvas.height); context = null } canvas.mask.visible = win.mask; var context = canvas.getContext("2d"); if((typeof win.imgs != "undefined") && (this.cursorCanvas == canvas) && (typeof win.width != "undefined")) { context.clearRect(0, 0, win.width, win.height) } if(TVNC.useBufferedCanvas) { if(!canvas.bufferedCanvas) { canvas.bufferedCanvas = document.createElement("canvas"); canvas.bufferedCanvas.width = canvas.width; canvas.bufferedCanvas.height = canvas.height } var bufferedContext = canvas.bufferedCanvas.getContext("2d"); this.processDrawCmds(root, win, canvas, bufferedContext); context.drawImage(canvas.bufferedCanvas, 0, 0); context = null; offscreenContext = null } else { this.processDrawCmds(root, win, canvas, context); context = null } }; this.getProtocol = function() { var proto = (TVNC.rcParams.protocol) ? TVNC.rcParams.protocol : window.location.protocol; return proto.toLowerCase() }; this.getAjaxUrl = function() { var server = (TVNC.rcParams.server) ? TVNC.getProtocol() + "//" + TVNC.rcParams.server : ""; return(server + TVNC.baseUrl) }; this.getCrossDomainDataType = function() { if(TVNC.crossdomain) { return "json" } else { return "html" } }; this.getCrossDomainUrl = function(url) { if(TVNC.crossdomain) { return url + "&callback?" } else { return url } }; this.wsSend = function(value) { if(TVNC.ackTimeout) { clearTimeout(TVNC.ackTimeout) } TVNC.ws.send(value) }; this.sendAck = function() { if(TVNC.rcParams.clientAck > 0) { if(TVNC.ackTimeout) { clearTimeout(TVNC.ackTimeout) } TVNC.wsSend("cmd=ready"); TVNC.ackTimeout = setTimeout(TVNC.sendAck, 100) } }; this.sendXoff = function() { if(!TVNC.xoff) { logDebug("xoff"); TVNC.wsSend("cmd=xoff"); TVNC.xoff = true } }; this.sendXon = function() { if(TVNC.xoff) { logDebug("xon"); TVNC.wsSend("cmd=xon"); TVNC.xoff = false } }; this.sendServerCmd = function(cmd, query) { if(TVNC.connected) { var url = TVNC.getAjaxUrl() + cmd + "?" + query + "&id=" + this.rcParams.id; if(this.useAjax) { $.ajaxq(this.queueRequestName, { url: TVNC.getCrossDomainUrl(url), dataType: TVNC.getCrossDomainDataType(), success: TVNC.serverCmdResult }) } else { this.wsSend(query + "&id=" + this.rcParams.id) } } }; this.receiveScreen = function(obj) { TVNC.scale = TVNC.getScale(); if((typeof obj == "undefined") || (obj == null) || (obj.status == 2)) { setTimeout(TVNC.reload, 1); return } if(obj.status == 4) { var url = TVNC.getAjaxUrl() + obj.file.substring(1); if(TVNC.runInPublicServer && window.top != window) { url = "https://www.thinvnc.net" + url } TVNC.openPrnWindow(url, true); return } if(obj.status == 9) { $(window).trigger("sessionEnd", consts.thisSessionHasEnded); TVNC.disconnect(); return } if(typeof obj.caret != "undefined") { TVNC.caretX = obj.caret.x; TVNC.caretY = obj.caret.y } if(typeof obj.cursor != "undefined") { var position = this.findPos(TVNC.vncdiv); var left = position[0]; var top = position[1]; var X = Math.floor(obj.cursor.x * TVNC.scale) + left; var Y = Math.floor(obj.cursor.y * TVNC.scale) + top; if(TVNC.lastMouseAction != "move") { TVNC.moveCursorCanvas(X, Y) } TVNC.serverCursorX = obj.cursor.x; TVNC.serverCursorY = obj.cursor.y } if(typeof obj.windows != "undefined") { for(i = 0; i < obj.windows.length; i++) { var win = obj.windows[i]; win.last = i == (obj.windows.length - 1); TVNC.processWindow(obj, win) } for(var i = TVNC.vncdiv.children.length - 1; i >= 0; i--) { var canvas = TVNC.vncdiv.children[i]; if(canvas.tagName == "CANVAS") { var found = false; for(j = 0; j < obj.windows.length && !found; j++) { var canvasid = "canvas" + obj.windows[j].hwnd; if(canvas.id == canvasid) { found = true } } if(canvas == TVNC.canvasER) { found = true } if(!found) { canvas.style.display = "none"; if(canvas.mask) { delete canvas.mask; canvas.mask = null } canvas.innerHTML = ""; try { TVNC.vncdiv.removeChild(canvas) } catch(err) { logError("receiveScreen: " + err) } delete canvas; canvas = null } } } } if(typeof obj.sound != "undefined") { for(i = 0; i < obj.sound.length; i++) { var chunk = obj.sound[i].chunk; TVNC.sound.playText(unescape(chunk)) } } if(!TVNC.rcParams.remotePointer && !TVNC.rcParams.mouseControl) { TVNC.vncdiv.style.cursor = "default" } if(TVNC.rcParams.mouseControl && !TVNC.rcParams.remotePointer && typeof obj.cursor != "undefined") { if(obj.cursor.shape != undefined) { TVNC.vncdiv.style.cursor = obj.cursor.shape } } TVNC.zoomDesktop(); delete obj.windows; if(obj.status == 3) { setTimeout(TVNC.reconnect, 1) } else { if(TVNC.rcParams.active) { setTimeout(TVNC.reload, 1) } } $(window).trigger("screenReceived", obj) }; this.serverCmdResult = function(data) { var obj = null; if(TVNC.useAjax && !TVNC.crossdomain) { obj = eval("(" + data + ")") } else { obj = data } if(typeof obj.id == "undefined") { $(window).trigger("serverConnectionError", "Connection error"); TVNC.disconnect(); return } if(obj.id == 0) { var errormsg = (typeof obj.errormsg != "undefined") ? obj.errormsg : ""; $(window).trigger("serverConnectionError", errormsg); TVNC.disconnect(); return } if(obj.id == "##") { TVNC.disconnect(); return } if(obj.id == "!!") { $(window).trigger("serverCmdResult", [obj]); return } var rcActive = TVNC.rcParams.active; TVNC.rcParams.active = (typeof obj.active != "undefined") ? obj.active : TVNC.rcParams.active; TVNC.rcParams.monitor = (typeof obj.monitor != "undefined") ? obj.monitor : TVNC.rcParams.monitor; TVNC.rcParams.monitorCount = (typeof obj.monitorCount != "undefined") ? obj.monitorCount : TVNC.rcParams.monitorCount; TVNC.rcParams.viewLeft = (typeof obj.viewLeft != "undefined") ? obj.viewLeft : TVNC.rcParams.viewLeft; TVNC.rcParams.viewTop = (typeof obj.viewTop != "undefined") ? obj.viewTop : TVNC.rcParams.viewTop; TVNC.rcParams.viewWidth = (typeof obj.viewWidth != "undefined") ? obj.viewWidth : TVNC.rcParams.viewWidth; TVNC.rcParams.viewHeight = (typeof obj.viewHeight != "undefined") ? obj.viewHeight : TVNC.rcParams.viewHeight; TVNC.rcParams.mouseControl = (typeof obj.mouseControl != "undefined") ? obj.mouseControl : TVNC.rcParams.mouseControl; TVNC.rcParams.kbdControl = (typeof obj.kbdControl != "undefined") ? obj.kbdControl : TVNC.rcParams.kbdControl; if(obj.scraper != null) { TVNC.rcParams.scraper = (typeof obj.scraper != "undefined") ? obj.scraper : TVNC.rcParams.scraper; if(obj.scraperArgs != null) { TVNC.rcParams.scraperArgs = (typeof obj.scraperArgs != "undefined") ? obj.scraperArgs : TVNC.rcParams.scraperArgs } } TVNC.rcParams.quality = (typeof obj.quality != "undefined") ? obj.quality : TVNC.rcParams.quality; TVNC.rcParams.pixelFormat = (typeof obj.pixelFormat != "undefined") ? obj.pixelFormat : TVNC.rcParams.pixelFormat; TVNC.rcParams.grayscale = (typeof obj.grayscale != "undefined") ? obj.grayscale : TVNC.rcParams.grayscale; if(typeof obj.remotePointer != "undefined" && !obj.remotePointer) { TVNC.rcParams.remotePointer = obj.remotePointer } TVNC.rcParams.imageMethod = (typeof obj.imageMethod != "undefined") ? obj.imageMethod : TVNC.rcParams.imageMethod; if(typeof obj.imageList != "undefined") { if(obj.imageList == "json") { TVNC.imageListType = 0 } else { if(obj.imageList == "text") { TVNC.imageListType = 1 } else { if(obj.imageList == "binary") { TVNC.imageListType = 2 } } } } if(TVNC.rcParams.remotePointer) { var bw = navigator.userAgent; if(bw.indexOf("Chrome") == -1) { TVNC.vncdiv.style.cursor = "url(" + relPath + "images/blank.cur),default" } else { TVNC.vncdiv.style.cursor = "url(images/point.cur),url(" + relPath + "images/point.cur),default" } } if(TVNC.rcParams.maxWidth == 0) { TVNC.rcParams.maxWidth = TVNC.rcParams.viewWidth } if(TVNC.rcParams.maxHeight == 0) { TVNC.rcParams.maxHeight = TVNC.rcParams.viewHeight } TVNC.setScaled(TVNC.rcParams.scaled); if(TVNC.rcParams.active && TVNC.rcParams.mouseControl) { setTimeout(TVNC.sendMouseMove, 100) } if(TVNC.startPending) { setTimeout(TVNC.start, 1) } if(rcActive != obj.active) { if(obj.active) { TVNC.hookKM(); TVNC.reload(); $(window).trigger("sessionStart", obj) } else { $(window).trigger("sessionStop", obj) } } $(window).trigger("onServerCommandResult", obj) }; this.sendCmd = function(query) { return this.sendServerCmd("cmd", query) }; this.setMouseControl = function(value) { this.sendCmd("cmd=params&mouseControl=" + value + "&kbdControl=" + !TVNC.rcParams.kbdControl) }; this.setQuality = function(value) { this.sendCmd("cmd=params&quality=" + value) }; this.setimageMethod = function(value) { this.sendCmd("cmd=params&imageMethod=" + value) }; this.setGrayscale = function(value) { this.sendCmd("cmd=params&grayscale=" + value) }; this.setKbdControl = function(value) { this.sendCmd("cmd=params&kbdControl=" + value) }; this.setRemotePointer = function(value) { this.sendCmd("cmd=params&remotePointer=" + value) }; this.setPixelFormat = function(value) { this.sendCmd("cmd=params&pixelFormat=" + value) }; this.setMonitor = function(m) { if(m >= this.rcParams.monitorCount) { m = -1 } this.sendCmd("cmd=params&monitor=" + m) }; this.clearSID = function() { document.cookie = "SID=; expires=-1;" }; this.disconnect = function() { TVNC.endingsession = true; TVNC.closeReconnectDiv(); TVNC.disposeTimeout = setTimeout(TVNC.dispose, TVNC.disposeTimeoutValue); TVNC.sendCmd("cmd=disconnect") }; this.removeListeners = function() { $(document).unbind(); $("#" + TVNC.vncdivId).unbind(); window.removeEventListener("DOMMouseScroll", TVNC.wheel, false); window.onmousewheel = null }; this.dispose = function() { TVNC.wsEnabled = false; clearTimeout(TVNC.ackTimeout); clearTimeout(TVNC.disposeTimeout); if(!TVNC.useAjax) { TVNC.ws.close() } $.ajaxq(TVNC.queueRequestName); TVNC.connected = false; TVNC.connecting = false; TVNC.useAjax = true; TVNC.removeListeners(); $(window).trigger("serverDisconnect"); $(window).unbind(); $("#clipboardHelper").unbind(); TVNC.clipboard.deinit(); TVNC.vncdiv.innerHTML = ""; if(TVNC.xmlHttpJson) { TVNC.xmlHttpJson.abort(); TVNC.xmlHttpJson = null } TVNC.emptyRecycleImg(true); if(TVNC.cursorCanvas) { if(TVNC.cursorCanvas.mask) { delete TVNC.cursorCanvas.mask; TVNC.cursorCanvas.mask = null } delete TVNC.cursorCanvas; TVNC.cursorCanvas = null } if(TVNC.canvasER) { delete TVNC.canvasER; TVNC.canvasER = null } TVNC.clearImageCache(); TVNC.clearTextCache(); TVNC.clearFontCache(); TVNC.clearOffscreenCache() }; this.reset = function() { this.rcParams.maxHeight = 0; this.rcParams.maxWidth = 0; for(var i = TVNC.vncdiv.children.length - 1; i >= 0; i--) { var canvas = TVNC.vncdiv.children[i]; if(canvas.tagName == "CANVAS") { canvas.style.display = "none"; if(canvas.mask) { delete canvas.mask; canvas.mask = null } canvas.innerHTML = ""; try { TVNC.vncdiv.removeChild(canvas) } catch(err) { logError("receiveScreen: " + err) } delete canvas; canvas = null } } TVNC.emptyRecycleImg(true); if(TVNC.cursorCanvas) { if(TVNC.cursorCanvas.mask) { delete TVNC.cursorCanvas.mask; TVNC.cursorCanvas.mask = null } delete TVNC.cursorCanvas; TVNC.cursorCanvas = null } TVNC.clearImageCache(); TVNC.clearTextCache(); TVNC.clearFontCache(); TVNC.clearOffscreenCache() }; this.stop = function() { this.sendCmd("cmd=stop") }; this.start = function(cmdv) { this.startPending = false; this.rcParams.active = false; var cmd = "cmd=start"; if((typeof cmdv != "undefined")) { cmd = cmdv } if(this.rcParams.scraper != null) { cmd = cmd + "&scraper=" + this.rcParams.scraper; if(this.rcParams.scraperArgs != null) { cmd = cmd + "&" + this.rcParams.scraperArgs } } if(!TVNC.useAjax) { if(TVNC.ws.binaryType && (!TVNC.firefox || TVNC.majorVersion > 15)) { cmd += "&imageList=binary"; TVNC.imageListType = 2 } else {} } cmd += "&mouseControl=" + this.rcParams.mouseControl + "&kbdControl=" + this.rcParams.kbdControl; cmd += "&imageMethod=" + this.rcParams.imageMethod + "&quality=" + this.rcParams.quality + "&pixelFormat=" + this.rcParams.pixelFormat; cmd += "&rleThreshold=" + this.rcParams.rleThreshold; cmd += "&monitor=" + this.rcParams.monitor; TVNC.rcParams.clientAck = ((TVNC.rcParams.clientAck <= 0) && !TVNC.useAjax) ? 0 : Math.max(TVNC.rcParams.clientAck, 1); cmd += "&supportsWebP=" + WebPImageFormat.supportsWebP(); cmd += "&clientAck=" + TVNC.rcParams.clientAck; if(TVNC.rcParams.screenResX > 0) { cmd += "&screenResX=" + TVNC.rcParams.screenResX + "&screenResY=" + TVNC.rcParams.screenResY } TVNC.sendCmd(cmd); if(this.rcParams.showOnStart == true) { $("#" + TVNC.vncdivId).show() } }; this.connect = function(userid, password) { if(!this.connecting && !this.connected && TVNC.xmlHttpJson == null) { $(window).trigger("serverAuthenticationRequired"); if((typeof userid == "undefined") && (TVNC.rcParams.userid != null)) { userid = TVNC.rcParams.userid } if((typeof password == "undefined") && (TVNC.rcParams.password != null)) { password = TVNC.rcParams.password } var cmd = "cmd"; var query = "cmd=connect"; if(typeof userid != "undefined") { query += "&userid=" + escape(userid); this.userid = userid; if(typeof password != "undefined") { query += "&password=" + escape(password); this.password = password } } query += "&wscompression=" + this.rcParams.wscompression; if(TVNC.rcParams.ticket != "") { query = query + "&ticket=" + TVNC.rcParams.ticket } if(TVNC.rcParams.pin != "") { query = query + "&pin=" + TVNC.rcParams.pin } query = query + "&destAddr=" + TVNC.rcParams.address; if(TVNC.rcParams.scraper != null) { query = query + "&scraper=" + TVNC.rcParams.scraper; if(TVNC.rcParams.scraperArgs != null) { query = query + "&" + this.rcParams.scraperArgs } } query = query + "&screenWidth=" + TVNC.screenWidth + "&screenHeight=" + TVNC.screenHeight; if(typeof TVNC.rcParams.lfn != "undefined" && TVNC.rcParams.lfn != null && TVNC.rcParams.lfn != "") { query = query + "&lfn=" + TVNC.rcParams.lfn } if(TVNC.sound.audioOggCompatible) { query += "&ogg=true" } var url = TVNC.getAjaxUrl() + cmd + "?" + query + "&id=" + TVNC.rcParams.id; this.connecting = true; TVNC.xmlHttpJson = $.ajax({ url: TVNC.getCrossDomainUrl(url), dataType: TVNC.getCrossDomainDataType(), timeout: 70000, error: function(jqXHR, err) { TVNC.connecting = false; TVNC.xmlHttpJson = null; if(TVNC.reconnecting) { window.setTimeout(function() { TVNC.connect() }, 500) } else { $(window).trigger("connectingError", jqXHR, err) } }, success: TVNC.onConnectResult }); $(window).trigger("serverConnecting") } }; this.ping = function(url, error) { url += "/ping?xxx"; $.ajax({ url: TVNC.getCrossDomainUrl(url), dataType: TVNC.getCrossDomainDataType(), async: false, timeout: 1000, error: error, success: function() { var pathArray = url.split("/"); TVNC.rcParams.protocol = pathArray[0]; TVNC.rcParams.server = pathArray[2] } }) }; this.onConnectResult = function(data) { TVNC.xmlHttpJson = null; TVNC.connecting = false; TVNC.closeReconnectDiv(); if(data != "" && data) { try { var obj = (TVNC.crossdomain) ? data : eval("(" + data + ")"); if(obj.status && typeof obj.status != "undefined") { if(obj.connectUrl) { TVNC.ping(obj.connectUrl, function(e) { if(obj.connectUrl2) { TVNC.ping(obj.connectUrl, function(e) { if(obj.connectPin) { TVNC.baseUrl = "/" + obj.connectPin } else { $(window).trigger("serverRedirect", [obj.connectUrl, obj]) } }) } else { if(obj.connectPin) { TVNC.baseUrl = "/" + obj.connectPin } else { $(window).trigger("serverRedirect", [obj.connectUrl, obj]) } } }); $(window).trigger("serverRedirect", [obj.connectUrl, obj]) } else { if(obj.connectPin) { TVNC.baseUrl = "/" + obj.connectPin } } TVNC.connected = true; TVNC.reconnecting = false; TVNC.rcParams.id = obj.id; TVNC.vncdiv.innerHTML = ""; if(!TVNC.rcParams.forceAjax && ("WebSocket" in window || "MozWebSocket" in window)) { TVNC.connectWebSocket() } else { TVNC.start() } $(window).trigger("serverConnect", obj) } else { if(obj.authStatus == 3) { $(window).trigger("serverAuthenticationFailed", obj.errormsg) } else { if(obj.authStatus == 4) { $(window).trigger("serverNeedCredentials") } else { if(obj.errormsg) { if(!TVNC.reconnecting) { $(window).trigger("serverConnectionError", sprintf(consts.connAttemptFailed, obj.errormsg)); TVNC.dispose() } else { TVNC.reconnect() } } } } } delete obj } catch(err) { var msg = err; if(err.message) { msg = err.message } logError("serverConnectionError: " + msg); $(window).trigger("serverConnectionError", msg) } } else { TVNC.reconnect() } }; this.gup = function(name) { name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); var regexS = "[\\?&]" + name + "=([^&#]*)"; var regex = new RegExp(regexS); var results = regex.exec(window.location.href); delete regex; if(results == null) { return "" } else { return results[1] } }; this.refresh = function() { this.vncdiv.innerHTML = ""; this.cursorCanvas = null; this.sendCmd("cmd=refresh") }; this.onJsonTimeout = function() { if(TVNC.xmlHttpJson) { TVNC.xmlHttpJson.abort() } TVNC.xmlHttpJson = null; TVNC.reconnect() }; this.reload = function() { if(!TVNC.connected) { return } if(TVNC.useAjax) { var url = TVNC.getAjaxUrl() + "json?id=" + TVNC.rcParams.id; clearTimeout(TVNC.jsonTimeout); TVNC.jsonTimeout = setTimeout(TVNC.onJsonTimeout, TVNC.jsonTimeoutValue); if(TVNC.xmlHttpJson == null) { TVNC.xmlHttpJson = $.ajax({ url: TVNC.getCrossDomainUrl(url), dataType: TVNC.getCrossDomainDataType(), error: function() { TVNC.xmlHttpJson = null; setTimeout(TVNC.reload, 1) }, success: function(data) { clearTimeout(TVNC.jsonTimeout); TVNC.xmlHttpJson = null; if(TVNC.connected) { if(data != "" && data) { try { var obj = (TVNC.crossdomain) ? data : eval("(" + data + ")"); TVNC.msgQueue.push(obj); TVNC.processNextScreen() } catch(err) { logError("ajax error: " + err) } } else { TVNC.reconnect() } } } }) } } else { TVNC.sendAck() } }; this.clearMouse = function() { this.mouseMoved = false }; this.sendEvent = function(url) { $.ajaxq(this.queueRequestName, { url: TVNC.getCrossDomainUrl(url), async: true, dataType: TVNC.getCrossDomainDataType() }) }; this.sendKey = function(key, ch, action) { if(TVNC.rcParams.active && TVNC.rcParams.kbdControl) { if(TVNC.rcParams.unicodeKeyboard === false && ch != 0) { key = 0 } if(TVNC.useAjax) { var url = TVNC.getAjaxUrl() + "cmd?cmd=keyb&key=" + key + "&char=" + escape(ch) + "&action=" + action + "&id=" + TVNC.rcParams.id; this.sendEvent(url) } else { var query = "cmd=keyb&key=" + key + "&char=" + ch + "&action=" + action + "&id=" + TVNC.rcParams.id; TVNC.wsSend(query) } } }; this.sendFunctionKey = function(key) { if(TVNC.rcParams.active && TVNC.rcParams.kbdControl) { if(TVNC.useAjax) { var url = TVNC.getAjaxUrl() + "cmd?cmd=fkey&key=" + escape(key) + "&id=" + TVNC.rcParams.id; this.sendEvent(url) } else { var query = "cmd=fkey&key=" + key + "&id=" + TVNC.rcParams.id; TVNC.wsSend(query) } } }; this.sendText = function(text) { for(var c = 0; c < text.length; c++) { this.sendKey(0, text.charCodeAt(c), "down"); this.sendKey(0, text.charCodeAt(c), "up") } }; this.sendKeyStroke = function(key) { this.sendKeyDown(key); this.sendKeyUp(key) }; this.sendKeyDown = function(key) { this.sendKey(key, 0, "down") }; this.sendKeyUp = function(key) { this.sendKey(key, 0, "up") }; this.sendCtrlAltDel = function() { this.sendFunctionKey("CtrlAltDel") }; this.sendShiftCtrlEsc = function() { this.sendFunctionKey("ShiftCtrlEsc") }; this.sendShellExplorer = function() { this.sendFunctionKey("WindowsExplorer") }; this.sendShellRun = function() { this.sendFunctionKey("Run") }; this.sendCtrlEsc = function() { this.sendFunctionKey("CtrlEsc") }; this.sendCut = function() { this.sendFunctionKey("Cut") }; this.sendCopy = function() { this.sendFunctionKey("Copy") }; this.sendPaste = function() { this.sendFunctionKey("Paste") }; this.translateMouseCoordX = function(x) { return x }; this.translateMouseCoordY = function(y) { return y }; this.sendMouse = function(x, y, button, action) { if(TVNC.rcParams.active && TVNC.rcParams.mouseControl) { TVNC.clearMouse(); TVNC.lastMouseAction = action; x = x + TVNC.rcParams.viewLeft; y = y + TVNC.rcParams.viewTop; var query = "cmd=mouse&x=" + TVNC.translateMouseCoordX(x) + "&y=" + TVNC.translateMouseCoordY(y) + "&btn=" + button + "&action=" + action + "&id=" + TVNC.rcParams.id; if(TVNC.useAjax) { var url = TVNC.getAjaxUrl() + "cmd?" + query; TVNC.sendEvent(url) } else { TVNC.wsSend(query) } } }; this.sendMouseMove = function() { if(TVNC.rcParams.active && TVNC.rcParams.mouseControl) { if(TVNC.mouseMoved) { TVNC.sendMouse(TVNC.mouseX, TVNC.mouseY, 0, "move") } else { if(TVNC.lastMouseAction == "move") { TVNC.lastMouseAction = "up" } } setTimeout(TVNC.sendMouseMove, 100) } }; this.sendWheel = function(delta) { if(TVNC.rcParams.active && TVNC.rcParams.mouseControl) { var query = "cmd=mouse&action=wheel&delta=" + delta + "&id=" + TVNC.rcParams.id; if(TVNC.useAjax) { var url = TVNC.getAjaxUrl() + "cmd?" + query; TVNC.sendEvent(url) } else { TVNC.wsSend(query) } } }; this.wheel = function(event) { var delta = 0; if(!event) { event = window.event } if(event.wheelDelta) { delta = event.wheelDelta; if(jQuery.browser.opera) { delta = -delta } } else { if(event.detail) { delta = -event.detail * 120 } } if(delta) { TVNC.sendWheel(delta) } event.stopPropagation(); event.preventDefault() }; this.keyCode = function(e) { var kcode = e.which || e.keyCode; if(kcode >= 96 && kcode <= 105) { kcode = kcode - 48 } return kcode }; this.IsNumKey = function(code) { return(code >= 96 && code <= 111 && code != 108) || (code == 144) }; this.IsFunctionKey = function(keyCode) { return((keyCode >= 112) && (keyCode <= 123) || (keyCode >= 33) && (keyCode <= 40) || (keyCode >= 45) && (keyCode <= 46) || (keyCode >= 16) && (keyCode <= 20) || (keyCode >= 91) && (keyCode <= 93) || (keyCode == 13) || (keyCode == 9) || (keyCode == 8) || (keyCode == 27) || (keyCode == 144) || (keyCode == 12) || (keyCode == 224)) }; this.hookKM = function() { if(!TVNC.MouseHooked) { TVNC.MouseHooked = true; if(TVNC.rcParams.hookMouse) { if(TVNC.mobile) { this.vncdiv.addEventListener("touchstart", TVNC.onTouchStart, false); this.vncdiv.addEventListener("touchmove", TVNC.onTouchMove, false); this.vncdiv.addEventListener("touchend", TVNC.onTouchEnd, false) } else { if(window.addEventListener) { window.addEventListener("DOMMouseScroll", TVNC.wheel, false) } window.onmousewheel = document.onmousewheel = TVNC.wheel; this.vncDivElement.mousedown(TVNC.onTouchStart); this.vncDivElement.mouseup(TVNC.onTouchEnd); this.vncDivElement.mousemove(TVNC.onTouchMove) } } TVNC.bindKeyboardEvents() } this.vncDivElement.bind("contextmenu", function(e) { return false }) }; this.bindKeyboardEvents = function() { if(TVNC.rcParams.hookKeyboard && !TVNC.KeyboadHooked) { TVNC.KeyboadHooked = true; $(document).keydown(function(e) { var keybinfo = { type: e.type, altKey: e.altKey, ctrlKey: e.ctrlKey, charCode: e.charCode, keyCode: e.keyCode, which: e.which, shiftKey: e.shiftKey, metaKey: e.metaKey }; var kcode = TVNC.keyCode(e); if(TVNC.IsFunctionKey(kcode) || (e.altKey || e.ctrlKey) && (e.altKey != e.ctrlKey)) { if(!TVNC.isMacAltKey(e)) { TVNC.sendKey(kcode, 0, "down"); e.stopPropagation(); e.preventDefault() } } if(!TVNC.isMacAltKey(kcode)) { TVNC.lastKeyCode = kcode } if(TVNC.rcParams.kbdLogKeys === true) { logDebug(JSON.stringify(keybinfo)) } $(document).trigger("keyboardEvent", keybinfo) }); $(document).keypress(function(e) { var charCode = ($.browser.opera) ? e.which : e.charCode; var keybinfo = { type: e.type, altKey: e.altKey, ctrlKey: e.ctrlKey, charCode: e.charCode, keyCode: e.keyCode, which: e.which, shiftKey: e.shiftKey, metaKey: e.metaKey }; var kcode = TVNC.keyCode(e); if(!TVNC.isMacAltKey(e) && ((kcode != 0) && TVNC.IsFunctionKey(TVNC.lastKeyCode) || (e.altKey || e.ctrlKey) && (e.altKey != e.ctrlKey))) { e.stopPropagation(); e.preventDefault(); if(TVNC.rcParams.kbdLogKeys === true) { logDebug(JSON.stringify(keybinfo)) } $(document).trigger("keyboardEvent", keybinfo); return } var isMAK = TVNC.isMacAltKey(e) && (TVNC.lastKeyCode == 18); if(isMAK) { TVNC.sendKey(17, 0, "down") } if(TVNC.onlyKeyCode || TVNC.IsNumKey(TVNC.lastKeyCode)) { TVNC.sendKey(TVNC.lastKeyCode, 0, "down") } else { TVNC.sendKey(TVNC.lastKeyCode, charCode, "down") } if(isMAK) { TVNC.sendKey(17, 0, "up") } e.stopPropagation(); e.preventDefault(); if(TVNC.rcParams.kbdLogKeys === true) { logDebug(JSON.stringify(keybinfo)) } $(document).trigger("keyboardEvent", keybinfo) }); $(document).keyup(function(e) { var keybinfo = { type: e.type, altKey: e.altKey, ctrlKey: e.ctrlKey, charCode: e.charCode, keyCode: e.keyCode, which: e.which, shiftKey: e.shiftKey, metaKey: e.metaKey }; var kcode = TVNC.keyCode(e); TVNC.lastKeyCode = 0; TVNC.sendKey(kcode, 0, "up"); if($.browser.mozilla && e.altKey) { TVNC.sendKey(18, 0, "up") } e.stopPropagation(); e.preventDefault(); if(TVNC.rcParams.kbdLogKeys === true) { logDebug(JSON.stringify(keybinfo)) } $(document).trigger("keyboardEvent", keybinfo) }) } }; this.unbindKeyboardEvents = function() { $(document).unbind("keydown"); $(document).unbind("keypress"); $(document).unbind("keyup"); TVNC.KeyboadHooked = false }; this.isMacAltKey = function(e) { return(this.mac && e.altKey) }; this.mouseDown = function(X, Y, button) { TVNC.clipboard.setText(String.fromCharCode(32)); $("#clipboardHelper").focus(); if(TVNC.rcParams.active && TVNC.rcParams.mouseControl) { var position = this.findPos(TVNC.vncdiv); var left = position[0]; var top = position[1]; TVNC.mouseX = Math.floor((X - left) / TVNC.scale); TVNC.mouseY = Math.floor((Y - top) / TVNC.scale); TVNC.MouseClicks.sendMouse(TVNC.mouseX, TVNC.mouseY, button, "down") } }; this.mouseUp = function(X, Y, button) { if(TVNC.rcParams.active && TVNC.rcParams.mouseControl) { var position = this.findPos(TVNC.vncdiv); var left = position[0]; var top = position[1]; TVNC.mouseX = Math.floor((X - left) / TVNC.scale); TVNC.mouseY = Math.floor((Y - top) / TVNC.scale); TVNC.MouseClicks.sendMouse(TVNC.mouseX, TVNC.mouseY, button, "up") } }; this.mouseMove = function(X, Y) { if(TVNC.rcParams.active && TVNC.rcParams.mouseControl) { var position = this.findPos(TVNC.vncdiv); var left = position[0]; var top = position[1]; if(X < left) { X = left } if(Y < top) { Y = top } if(X > (left + TVNC.rcParams.viewWidth * TVNC.zoomFactor)) { X = left + TVNC.rcParams.viewWidth * TVNC.zoomFactor } if(Y > (top + TVNC.rcParams.viewHeight * TVNC.zoomFactor)) { Y = top + TVNC.rcParams.viewHeight * TVNC.zoomFactor } TVNC.mouseX = Math.floor((X - left) / TVNC.scale); TVNC.mouseY = Math.floor((Y - top) / TVNC.scale); TVNC.mouseMoved = true; TVNC.moveCursorCanvas(X, Y) } }; this.onTouchStart = function(e) { if(TVNC.mobile) { var X = e.touches[0].pageX; var Y = e.touches[0].pageY; TVNC.pageX = X; TVNC.pageY = Y; if(e.touches.length == 1) { var button = 0; if(TVNC.delayedMouseDown) { TVNC.touchStart = new Date().getTime(); TVNC.button = button } else { TVNC.moveCursorCanvas(X, Y); TVNC.mouseDown(X, Y, button) } } else { var button = 2; TVNC.mouseDown(X, Y, button); TVNC.mouseUp(X, Y, button) } } else { TVNC.pageX = e.pageX; TVNC.pageY = e.pageY; TVNC.mouseDown(e.pageX, e.pageY, e.button) } e.stopPropagation(); e.preventDefault() }; this.onTouchMove = function(e) { (TVNC.mobile) ? TVNC.pageX = e.touches[0].pageX : TVNC.pageX = e.pageX; (TVNC.mobile) ? TVNC.pageY = e.touches[0].pageY : TVNC.pageY = e.pageY; if(TVNC.touchStart) { var elapsed = new Date().getTime() - TVNC.touchStart; if(elapsed < TVNC.rcParams.delayTouch) { TVNC.moveCursorCanvas(TVNC.pageX, TVNC.pageY); TVNC.mouseDown(TVNC.pageX, TVNC.pageY, TVNC.button) } TVNC.touchStart = null } var currentX = TVNC.serverMouseX(e, false); var currentY = TVNC.serverMouseY(e, false); if((TVNC.mouseX != currentX) || (TVNC.mouseY != currentY)) { TVNC.mouseX = currentX; TVNC.mouseY = currentY; if(!TVNC.mobile) { TVNC.mouseMove(e.pageX, e.pageY) } else { TVNC.mouseMove(e.touches[0].pageX, e.touches[0].pageY) } } }; this.onTouchEnd = function(e) { (TVNC.mobile) ? TVNC.pageX = e.touches[0].pageX : TVNC.pageX = e.pageX; (TVNC.mobile) ? TVNC.pageY = e.touches[0].pageY : TVNC.pageY = e.pageY; if(TVNC.touchStart) { var elapsed = new Date().getTime() - TVNC.touchStart; if(elapsed < TVNC.rcParams.delayTouch) { TVNC.moveCursorCanvas(TVNC.pageX, TVNC.pageY); TVNC.mouseDown(TVNC.pageX, TVNC.pageY, TVNC.button) } else { if(TVNC.delayedMouseDown) { TVNC.delayedMouseDown() } } TVNC.touchStart = null } var button = (TVNC.mobile) ? 0 : e.button; TVNC.mouseUp(TVNC.pageX, TVNC.pageY, button); e.stopPropagation(); e.preventDefault() }; this.connectWebSocket = function() { var buffer = ""; var soundBuffer = ""; logDebug("connectWebSocket. TVNC.connected: " + TVNC.connected); if(TVNC.connected) { var server = (TVNC.rcParams.server) ? TVNC.rcParams.server : window.location.host; var url = "://" + server + TVNC.baseUrl + TVNC.rcParams.id; if(TVNC.getProtocol() == "https:") { url = "wss" + url } else { url = "ws" + url } try { if("WebSocket" in window) { TVNC.ws = new WebSocket(url) } else { TVNC.ws = new MozWebSocket(url) } if(typeof TVNC.ws.binaryType != "undefined") { TVNC.ws.binaryType = "arraybuffer" } var wstimer = setTimeout(function() { try { TVNC.ws.close() } catch(err) {} TVNC.useAjax = true; TVNC.start() }, 2000); TVNC.ws.onopen = function() { clearTimeout(wstimer); TVNC.wsEnabled = true; logDebug("TVNC.ws.onopen. TVNC.wsEnabled = true"); TVNC.useAjax = false; TVNC.imageListHelper.PurgeImgQueues(); TVNC.start() }; TVNC.ws.onmessage = function(msg) { if(!TVNC.connected) { logDebug("TVNC.ws.onmessage -> !TVNC.connected. Return"); return } if(msg.data == "") { logDebug("TVNC.ws.onmessage -> msg.data == ''. Return"); return } var obj = null; if(typeof msg.data == "object") { TVNC.imageListHelper.QueueBinary(msg.data); delete msg.data; msg.data = null } else { var version = msg.data[0]; if(version == "{") { try { obj = eval("(" + msg.data + ")") } catch(err) { logError("ERROR: buffer = " + buffer); buffer = ""; alert("websocket onmessage err: " + err) } } else { var datatype = msg.data[0]; var endofdata = msg.data[1]; if(datatype == "2") { soundBuffer += msg.data.substring(7) } else { buffer += msg.data.substring(7) } if(endofdata == "0") { return } if(datatype == "0") { try { obj = eval("(" + buffer + ")"); buffer = "" } catch(err) { logError("ERROR: buffer = " + buffer); buffer = ""; alert("websocket onmessage err: " + err) } } else { if(datatype == "1") { TVNC.imageListHelper.QueueText(buffer); buffer = ""; return } else { if(datatype == "2") { TVNC.sound.playText(soundBuffer); soundBuffer = ""; return } } } } if(obj) { if(obj.id != undefined) { TVNC.serverCmdResult(obj) } else { if(obj.status) { obj.imgQueue = TVNC.imgQueue; TVNC.imgQueue = null; TVNC.msgQueue.push(obj); TVNC.processNextScreen() } } } } obj = null }; TVNC.ws.onerror = function(e) { logDebug("TVNC.ws.onerror") }; TVNC.ws.onclose = function(e) { clearTimeout(wstimer); logDebug("TVNC.ws.onclose"); if(TVNC.endingsession) { logDebug("TVNC.ws.onclose. TVNC.endingsession: " + TVNC.endingsession); return } if(!TVNC.wsEnabled) { TVNC.useAjax = true } if(TVNC.wsEnabled && !TVNC.useAjax) { logError("TVNC.ws.onclose. Try to reconnect."); TVNC.reconnect() } else { TVNC.start() } } } catch(e) { logDebug("TVNC.ws Try-Catch -> Event Data = " + JSON.stringify(e)); TVNC.start() } } }; this.getNextHighestZindex = function(obj) { var highestIndex = 0; var currentIndex = 0; var elArray = Array(); if(obj) { elArray = obj.getElementsByTagName("*") } else { elArray = document.getElementsByTagName("*") } for(var i = 0; i < elArray.length; i++) { if(elArray[i].currentStyle) { currentIndex = parseFloat(elArray[i].currentStyle.zIndex) } else { if(window.getComputedStyle) { currentIndex = parseFloat(document.defaultView.getComputedStyle(elArray[i], null).getPropertyValue("z-index")) } } if(!isNaN(currentIndex) && currentIndex > highestIndex) { highestIndex = currentIndex } } return(highestIndex + 1) }; this.closeReconnectDiv = function() { $("#cancelRecnx").parent().remove(); $("#" + TVNC.reconnectDivId).remove() }; this.reconnect = function() { clearTimeout(TVNC.jsonTimeout); if(TVNC.endingsession) { return } TVNC.reconnecting = true; TVNC.connected = false; if(document.getElementById(TVNC.reconnectDivId) == null) { TVNC.vncdiv.style.cursor = "default"; $("#" + TVNC.vncdivId).parent().append('
' + consts.connLostReconnecting + '
"); $(window).trigger("serverReconnect"); $("#cancelRecnx").click(function() { TVNC.closeReconnectDiv(); TVNC.disconnect(); $(document).unbind(); $("#" + TVNC.vncdivId).unbind() }); if(TVNC.useAjax) { TVNC.xmlHttpJson = null; $.ajaxq(TVNC.queueRequestName) } } TVNC.connect() }; this.supportsHTML5Storage = function() { try { return "localStorage" in window && window.localStorage != null } catch(err) { return false } }; this.getStorageName = function() { var middle = (this.rcParams.address) ? "_" + this.rcParams.address : ""; return "thinvnc" + middle + "_prefs" }; this.loadPreferences = function() { if(!this.supportsHTML5Storage()) { return } try { var objJson = localStorage.getItem(this.getStorageName()); var objData = JSON.parse(objJson); if(objData != null && typeof objData != "undefined") { this.onlyKeyCode = (objData.onlykeycode != null) ? objData.onlykeycode : this.onlyKeyCode } } catch(err) {} }; this.savePreferences = function() { if(!this.supportsHTML5Storage()) { return } try { var objData = new Object(); objData.onlykeycode = this.onlyKeyCode; var objJson = JSON.stringify(objData); localStorage.setItem(this.getStorageName(), objJson) } catch(err) {} }; this.setParams = function(dd) { for(var o in dd) { TVNC.rcParams[o] = dd[o] } }; this.resolveAgent = function() { var agentInfo = new AgentInfo(); TVNC.majorVersion = agentInfo.majorVersion; TVNC.mac = agentInfo.isMac; TVNC.ios = agentInfo.isIOS; TVNC.iphone = agentInfo.isIphone; TVNC.android = agentInfo.isAndroid; TVNC.hptablet = agentInfo.isHPTablet; TVNC.playbook = agentInfo.isPlaybook; TVNC.chromeOS = agentInfo.isChromeOS; TVNC.surface = agentInfo.isSurface; TVNC.mobile = agentInfo.isMobile; TVNC.firefox = agentInfo.isFirefox; TVNC.opera = agentInfo.isOpera; TVNC.chrome = agentInfo.isChrome; TVNC.safari = agentInfo.isSafari; TVNC.msie = agentInfo.isMSIE; TVNC.agentName = agentInfo.getAgentKey() }; this.init = function(dd) { for(var o in dd) { TVNC.rcParams[o] = dd[o] } TVNC.vncdivId = (TVNC.rcParams.divId) ? TVNC.rcParams.divId : TVNC.vncdivId; TVNC.centered = TVNC.rcParams.centered; if(this.rcParams.showOnStart == false) { $("#" + TVNC.vncdivId).hide() } TVNC.resolveAgent(); TVNC.vncdiv = document.getElementById(TVNC.vncdivId); var serverUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36"; TVNC.rcParams.forceAjax = (serverUserAgent.indexOf("chromeframe") >= 0 && TVNC.getProtocol() == "https:"); if(!TVNC.vncdiv) { throw new Error("the " + TVNC.vncdivId + " is not available") } TVNC.vncDivElement = $("#" + TVNC.vncdivId); TVNC.vncdiv.style.position = "relative"; TVNC.vncdiv.style.overflow = "hidden"; TVNC.vncdiv.style.top = "0px"; TVNC.vncdiv.style.marginTop = "0px"; TVNC.vncdiv.style.left = "0px"; TVNC.vncdiv.style.marginLeft = "0px"; TVNC.supportsCanvas = !! document.createElement("canvas").getContext; var path = (TVNC.rcParams.url) ? TVNC.rcParams.url : window.location.href; var pathArray = path.split("/"); if(TVNC.rcParams.protocol == "" || !TVNC.rcParams.protocol) { TVNC.rcParams.protocol = pathArray[0] } if(TVNC.rcParams.server == "" || !TVNC.rcParams.server) { TVNC.rcParams.server = pathArray[2] } TVNC.baseUrl = "/"; for(i = 3; i < pathArray.length - 1; i++) { TVNC.baseUrl += pathArray[i]; TVNC.baseUrl += "/" } $(window).resize(function() { TVNC.zoomDesktop() }); TVNC.loadPreferences(); setTimeout(TVNC.emptyRecycleImg, TVNC.recycleImgTimeoutValue); for(i = 0; i < 12; i++) { this.rdpGlyphArray[i] = Array(256) } if(!TVNC.mobile) { TVNC.clipboard.init() } TVNC.sound.init() }; this.openPrnWindow = function(url, showCancel) { var msg = ""; $.blockUI({ message: msg, css: { padding: 0, margin: 0, width: "100%", height: "100%", top: "0px", left: "0px", textAlign: "center", backgroundColor: "transparent", border: "none", cursor: "auto" }, centerX: true, centerY: true, onBlock: function() { setTimeout(TVNC.reload, 1) } }) }; this.getCanvasPrinter = function() { if(!this.canvasPrinter) { if(CanvasPrinter) { this.canvasPrinter = new CanvasPrinter() } else { logDebug("ERROR: CanvasPrinter not found") } } return this.canvasPrinter }; this.printScreen = function(divId, idx, title, footer, mode, callback) { if(!this.canvasPrinter) { this.canvasPrinter = this.getCanvasPrinter() } if(this.canvasPrinter) { if(typeof title != "undefined" && title != "") { this.canvasPrinter.setTitle(title) } if(typeof footer != "undefined" && footer != "") { this.canvasPrinter.setFooter(footer) } if(typeof mode != "undefined" && mode.toString() != "") { this.canvasPrinter.printMode = mode } this.canvasPrinter.drawBorder = true; this.canvasPrinter.print(divId, idx) } else { logDebug("ERROR: CanvasPrinter not found") } if(callback) { callback() } }; this.MouseClicks = { doubleClickThreshold: 200, clickDistThreshold: 10, lastDownDblClick: false, mobileClickCallback: null, up: { timeout: null, cacheX: null, cacheY: null, cacheButton: null }, down: { timeout: null, cacheX: null, cacheY: null, cacheButton: null }, createCache: function(timer, x, y, button) { return { timeout: timer, cacheX: x, cacheY: y, cacheButton: button } }, clearCacheUp: function() { window.clearTimeout(this.up.timeout); this.up = this.createCache(null, null, null, null) }, clearCacheDown: function() { window.clearTimeout(this.down.timeout); this.down = this.createCache(null, null, null, null) }, singleClickUp: function() { cd = TVNC.MouseClicks.up; TVNC.sendMouse(cd.cacheX, cd.cacheY, cd.cacheButton, "up"); TVNC.MouseClicks.clearCacheUp() }, singleClickDown: function() { cd = TVNC.MouseClicks.down; TVNC.sendMouse(cd.cacheX, cd.cacheY, cd.cacheButton, "down"); if((TVNC.mobile) && (TVNC.MouseClicks.mobileClickCallback)) { TVNC.MouseClicks.mobileClickCallback(cd.cacheX, cd.cacheY, cd.cacheButton, "down") } TVNC.MouseClicks.clearCacheDown() }, sendMouse: function(X, Y, button, command) { if(!TVNC.rcParams.useDblClick) { TVNC.sendMouse(X, Y, button, command) } else { if(command == "down") { var dist = Math.sqrt((this.down.cacheX - X) * (this.down.cacheX - X) + (this.down.cacheY - Y) * (this.down.cacheY - Y)); if((this.down.cacheButton == button) && (this.down.timeout) && (dist < this.clickDistThreshold)) { window.clearTimeout(TVNC.MouseClicks.down.timeout); window.clearTimeout(TVNC.MouseClicks.up.timeout); TVNC.MouseClicks.up.cacheButton |= 4; TVNC.MouseClicks.down.cacheButton |= 4; TVNC.MouseClicks.down.cacheX = X; TVNC.MouseClicks.down.cacheY = Y; TVNC.MouseClicks.lastDownDblClick = true; TVNC.MouseClicks.singleClickDown() } else { if((TVNC.MouseClicks.down.cacheButton != button) || (dist > this.clickDistThreshold)) { if(TVNC.MouseClicks.down.timeout) { window.clearTimeout(TVNC.MouseClicks.down.timeout); TVNC.MouseClicks.singleClickDown() } this.down = this.createCache(window.setTimeout(this.singleClickDown, this.doubleClickThreshold), X, Y, button) } } } else { if(command == "up") { var dist = Math.sqrt((this.up.cacheX - X) * (this.up.cacheX - X) + (this.up.cacheY - Y) * (this.up.cacheY - Y)); if(TVNC.MouseClicks.lastDownDblClick) { TVNC.MouseClicks.up.cacheX = X; TVNC.MouseClicks.up.cacheY = Y; TVNC.MouseClicks.lastDownDblClick = false; TVNC.MouseClicks.singleClickUp() } else { if((TVNC.MouseClicks.up.cacheButton != button) || (dist > this.clickDistThreshold)) { if(TVNC.MouseClicks.up.timeout) { window.clearTimeout(TVNC.MouseClicks.up.timeout); TVNC.MouseClicks.singleClickUp() } this.up = this.createCache(window.setTimeout(this.singleClickUp, this.doubleClickThreshold), X, Y, button) } } } else { logError("MouseClicks.sendMouse received unexpected command: " + command) } } } } } }; function padRight(c, b) { var a = c.length; while(a < b) { c += " "; a++ } return c } function getISOTime() { var b = new Date(); var a = b.toISOString(); a = a.substr(a.indexOf("T") + 1, 12); return a } function logDebug(a) { a = getISOTime() + ": " + a; if(typeof(MsgLogger) == "undefined") { if(window.console && window.console.log) { window.console.log(a) } } else { logDebugW(a) } } function logError(a) { a = getISOTime() + ": " + a; if(typeof(MsgLogger) == "undefined") { if(window.console && window.console.error) { window.console.error(a) } return a } else { logErrorW(a) } } var oMsgLogger = null; function logDebugW(a) { if(!oMsgLogger) { oMsgLogger = new MsgLogger() } oMsgLogger.log(a) } function logErrorW(a) { logDebugW("ERROR: " + a) } function AgentInfo() { this.agentStr = navigator.userAgent.toLowerCase(); this.majorVersion = parseInt(navigator.appVersion, 10); this.isMac = (this.agentStr.indexOf("macintosh") != -1); this.isIOS = ((this.agentStr.indexOf("iphone") != -1) || (this.agentStr.indexOf("ipod") != -1) || (this.agentStr.indexOf("ipad") != -1)); this.isIphone = ((this.agentStr.indexOf("iphone") != -1) || (this.agentStr.indexOf("ipod") != -1)); this.isAndroid = (this.agentStr.indexOf("android") != -1); this.isHPTablet = (this.agentStr.indexOf("hp-tablet") != -1); this.isPlaybook = (this.agentStr.indexOf("playbook") != -1); this.isChromeOS = (this.agentStr.indexOf(" cros ") != -1); this.isSurface = (this.agentStr.indexOf("iemobile") != -1); this.isMobile = !this.isChromeOS && (this.isIOS || this.isAndroid || this.isHPTablet || this.isPlaybook || this.isSurface || this.agentStr.indexOf("touch") != -1); this.isFirefox = (this.agentStr.indexOf("firefox") != -1); this.isOpera = (this.agentStr.indexOf("opera") != -1); this.isChrome = (this.agentStr.indexOf("chrome") != -1) || (this.agentStr.indexOf("crios") != -1); this.isSafari = (!this.isChrome) && (this.agentStr.indexOf("safari") != -1); this.isMSIE = (this.agentStr.indexOf("msie") != -1); if(this.__proto__ == null) { if(Object.getPrototypeOf) { this.__proto__ = Object.getPrototypeOf(this) } else { this.__proto__ = this.constructor.prototype } } this.__proto__.getAgentKey = function() { var a; if(this.isIOS) { a = "IOS_" } else { if(this.isAndroid) { a = "ANDROID_" } else { if(this.isPlaybook) { a = "PLAYBOOK_" } else { if(this.isHPTablet) { a = "WEBOS_" } else { if(this.isChromeOS) { a = "CHROMEOS_" } else { if(this.isMac) { a = "MAC_" } else { if(this.isSurface) { a += "SURFACE_" } else { a = "PC_" } } } } } } } if(this.isFirefox) { a += "FIREFOX" } else { if(this.isOpera) { a += "OPERA" } else { if(this.isSafari) { a += "SAFARI" } else { if(this.isChrome) { a += "CHROME" } else { if(this.isMSIE) { a += "MSIE" } } } } } return a }; this.__proto__.browserFromAgent = function(e) { var w; if(typeof e != "undefined") { var g = e.toLowerCase(); var m = (g.indexOf("macintosh") != -1); var r = ((g.indexOf("iphone") != -1) || (g.indexOf("ipod") != -1) || (g.indexOf("ipad") != -1)); var h = ((g.indexOf("iphone") != -1) || (g.indexOf("ipod") != -1)); var q = (g.indexOf("android") != -1); var l = (g.indexOf("hp-tablet") != -1); var o = (g.indexOf("playbook") != -1); var b = (g.indexOf(" cros ") != -1); var f = (g.indexOf("iemobile") != -1); var u = (r || q || l || b || o || f || g.indexOf("touch") != -1); var c = (g.indexOf("firefox") != -1); var d = (g.indexOf("opera") != -1); var a = (g.indexOf("chrome") != -1) || (g.indexOf("crios") != -1); var t = (!a) && (g.indexOf("safari") != -1); var v = (g.indexOf("msie") != -1) } else { var m = this.isMac; var r = this.isIOS; var h = this.isIphone; var q = this.isAndroid; var l = this.isHPTablet; var o = this.isPlaybook; var b = this.isChromeOS; var f = this.isSurface; var u = this.isMobile; var c = this.isFirefox; var d = this.isOpera; var a = this.isChrome; var t = this.isSafari; var v = this.isMSIE } if(c) { w = "Mozilla Firefox" } else { if(d) { w = "Opera" } else { if(t) { w = "Safari" } else { if(a) { w = "Google Chrome" } else { if(v) { w = "MS Internet Explorer" } } } } } w += " on "; if(r) { w += "iOS" } else { if(q) { w += "Android" } else { if(o) { w += "BlackBerry Playbook" } else { if(b) { w += "Chrome OS" } else { if(l) { w += "Web OS" } else { if(m) { w += "Mac" } else { if(f) { w += "Surface" } else { w += "PC" } } } } } } } return w } } function NavigatorControl() { var a = this; this.NCM_SIMPLE = 0; this.NCM_WINDROSE = 1; this.NCM_MINIM = 2; this.visible = false; var b = this.NCM_SIMPLE; this.setMode = function(c) { if(c < this.NCM_SIMPLE || c > this.NCM_MINIM) { return false } b = c }; this.insertPane = function() { var d = document.getElementById("navControl"); if(!d) { var d = document.createElement("DIV"); d.id = "navControl"; d.style.display = "none"; if(b == this.NCM_WINDROSE) { d.className = "windrose" } document.body.appendChild(d) } else { d.innerHTML = "" } var c = ""; if(b != this.NCM_MINIM) { c += '' } if(b != this.NCM_MINIM) { c += '' } c += ''; if(b != this.NCM_MINIM) { c += '' } if(b != this.NCM_MINIM) { c += '' } $(d).append(c); $("#move_up, #move_down, #move_left, #move_right, #zoom_in, #zoom_out").bind("click", function(f) { $(window).trigger("nav_" + (f.target || f.srcElement).id); f.stopPropagation() }) }; this.show = function() { $("#navControl").show(); this.visible = true }; this.hide = function() { $("#navControl").hide(); this.visible = false }; this.isVisible = function() { return this.visible }; return this } var button = "left"; var dblClickStartDate = new Date(); var tapholdTimeout = null; var touchstate = 0; var lastEvent = null; var tapintensity = 0; var stdKeyboardVisible = false; var extKeyboardVisible = false; var dialogVisible = false; var THIN = null; var ctrlDown = false; var altDown = false; var shiftDown = false; var backSpacePressed = false; var deltaCursorX = 0; var deltaCursorY = 0; var lastTouchkbdTop = 0; var mouseScrollX = -1; var startMouseX = 0; var startMouseY = 0; var mouseScrollY = -1; var theme = "b"; var zoomChanged = false; var zoomStarted = false; var zoomEnabled = true; var zoomWithKb = false; var ignoreTouch = false; var zoomLimit = 2; var keySentOnKeyPress = 0; var relativeTouch = true; var scrollWithMouse = true; var mouseButtonDown = false; var divScrolling = true; var screenHeight = $(window).height(); var screenWidth = $(window).width(); var currentKey = null; var chkScrSizeTimeout = null; var showToolbar = true; var insertNavigator = true; var relPath = '/vnc'; //window.location.pathname; var kbScreenHeight = -1; var kbScreenWidth = -1; if(relPath == "/" || relPath == "") { relPath = "" } else { aPath = relPath.split("/"); if(aPath[aPath.length - 1] == "") { aPath.splice(aPath.length - 1, 1) } relPath = (aPath[aPath.length - 1] == "rdp" || aPath[aPath.length - 1] == "vnc") ? "../" : ""; relPath = 'http://172.168.0.10:8082/'; } document.write(''); document.write(''); document.write(''); document.write(''); document.write(''); document.write(''); document.write(''); document.write(''); document.write(''); if(insertNavigator) { document.write('') } function byId(a) { return document.getElementById(a) } function isBlocked() { return $(".blockUI.blockMsg").length > 0 } function CtrlKeyToggle() { ctrlDown = !ctrlDown; if(ctrlDown) { $("#keyctrl").addClass("selected") } else { $("#keyctrl").removeClass("selected") } } function CtrlKeyOff() { ctrlDown = false; $("#keyctrl").removeClass("selected") } function AltKeyToggle() { altDown = !altDown; if(altDown) { $("#keyalt").addClass("selected") } else { $("#keyalt").removeClass("selected") } } function AltKeyOff() { altDown = false; $("#keyalt").removeClass("selected") } function ShiftKeyToggle() { shiftDown = !shiftDown; if(shiftDown) { $("#keyshift").addClass("selected") } else { $("#keyshift").removeClass("selected") } } function ShiftKeyOff() { shiftDown = false; $("#keyshift").removeClass("selected") } function sendSpecialKeysBegin() { if(ctrlDown) { THIN.sendKeyDown(17) } if(altDown) { THIN.sendKeyDown(18) } if(shiftDown) { THIN.sendKeyDown(16) } } function sendSpecialKeysEnd() { if(ctrlDown) { THIN.sendKeyUp(17) } if(altDown) { THIN.sendKeyUp(18) } if(shiftDown) { THIN.sendKeyUp(16) } CtrlKeyOff(); AltKeyOff(); ShiftKeyOff() } function sendExtKey(b, a) { sendSpecialKeysBegin(); THIN.sendKeyStroke(a); sendSpecialKeysEnd() } function sendCtrlAltDel() { THIN.sendCtrlAltDel() } function sendShiftCtrlEsc() { THIN.sendShiftCtrlEsc() } function sendShellExplorer() { THIN.sendShellExplorer() } function sendShellRun() { THIN.sendShellRun() } function sendCtrlEsc() { THIN.sendCtrlEsc() } function sendCut() { THIN.sendCut() } function sendCopy() { THIN.sendCopy() } function sendPaste() { THIN.sendPaste() } function btnDblClick() { btnLeftClick(); btnLeftClick() } function btnLeftClick() { mouseDown("left", getTouchX(), getTouchY()); mouseUp("left", getTouchX(), getTouchY()) } function btnRightClick() { mouseDown("right", getTouchX(), getTouchY()); mouseUp("right", getTouchX(), getTouchY()) } function hideExtKeyboard() { var a = document.getElementById("extkeyboard"); a.style.top = "100%"; a.style.marginTop = "2000px" } function openExtKeyboard(b) { if(typeof b == "undefined") { $("#extkeyboard").addClass("slide") } else { $("#extkeyboard").removeClass("slide") } var a = document.getElementById("extkeyboard"); a.style.top = $("body").height() + "px"; a.style.marginTop = -a.offsetHeight + "px"; extKeyboardVisible = true } function closeExtKeyboard() { hideExtKeyboard(); hideExtKeys(); extKeyboardVisible = false } function moveExtKeyboard() { if(!extKeyboardVisible) { return } } function hideExtKeys() { var a = document.getElementById("extkeys"); a.style.top = -a.offsetHeight + "px"; a.style.left = (screenWidth - a.offsetWidth) / 2 + "px" } function ShowExtKeys() { var a = document.getElementById("extkeys"); a.style.top = "0px" } function ShowStdKbd() { var a = document.getElementById("touchkbd"); stdKeyboardVisible = true; var b = THIN.caretY; if(b <= 0) { b = THIN.mouseY } a.style.top = b + "px"; a.focus() } function btnShowStdKbd() { closeExtKeyboard(); ShowStdKbd(); ShowExtKeys() } function btnShowExtKbd() { openExtKeyboard(); ShowExtKeys() } function addKeyImg(e, a, c, b, g, d) { if(typeof b == "undefined") { b = 2 } var f = ' class="key t' + b + '"'; if((typeof g != "undefined") && (g != "")) { f += ' ontouchend="' + g + '"' } else { f += ' ontouchend="sendExtKey(this,' + c + ')"' } $("#extkeyboard_row" + e).append('

') } function addKey(e, d, b, a, g, c) { if(typeof a == "undefined") { a = 2 } var f = ""; if((typeof g != "undefined") && (g != "")) { var f = ' class="key t' + a + '"'; f += ' ontouchend="' + g + '"' } else { if((d != "") && (b != 0)) { f = ' class="key t' + a + '" ontouchend="sendExtKey(this,' + b + ')"' } } $("#extkeyboard_row" + e).append('

" + d + "

") } function addExtKey(e, d, b, a, g, c) { if(typeof a == "undefined") { a = 2 } var f = ""; if(d != "") { f = ' class="key t' + a + '"'; if(g != parseInt(g)) { f += ' id="' + g + '"' } else { f += ' ontouchend="sendExtKey(this,' + g + ')"' } } $("#extkeys_row" + e).append('

" + d + "

") } function getRelativeX(b) { if(relativeTouch) { var a = b; b = Math.floor((b - startMouseX) / 1) + THIN.cursorCanvasX(); b = (b < 0) ? 0 : b; startMouseX = a } return b } function getRelativeY(b) { if(relativeTouch) { var a = b; b = Math.floor((b - startMouseY) / 1) + THIN.cursorCanvasY(); b = (b < 0) ? 0 : b; startMouseY = a } return b } function mouseDown(b, d, c) { var a = 0; mouseButtonDown = true; lastY = c; if(b == "right") { a = 2 } THIN.mouseDown(getRelativeX(d) + deltaCursorX, getRelativeY(c) + deltaCursorY, a) } function mouseUp(b, d, c) { var a = 0; mouseButtonDown = false; if(b == "right") { a = 2 } THIN.mouseUp(getRelativeX(d) + deltaCursorX, getRelativeY(c) + deltaCursorY, a) } function mouseMove(b, a) { THIN.mouseMove(getRelativeX(b) + deltaCursorX, getRelativeY(a) + deltaCursorY) } function mouseMoveIntoView() { if(relativeTouch) { var a = THIN.cursorCanvasX(); var b = THIN.cursorCanvasY(); if(a <= THIN.vncdiv.scrollLeft * THIN.getZoom()) { a = THIN.vncdiv.scrollLeft * THIN.getZoom() } else { if(a >= (THIN.rcParams.maxWidth + THIN.vncdiv.scrollLeft) * THIN.getZoom()) { a = (THIN.rcParams.maxWidth + THIN.vncdiv.scrollLeft) * THIN.getZoom() } } if(b <= THIN.vncdiv.scrollTop * THIN.getZoom()) { b = THIN.vncdiv.scrollTop * THIN.getZoom() } else { if(b >= (THIN.rcParams.maxHeight + THIN.vncdiv.scrollTop) * THIN.getZoom()) { b = (THIN.rcParams.maxHeight + THIN.vncdiv.scrollTop) * THIN.getZoom() } } if(a != THIN.cursorCanvasX() || b != THIN.cursorCanvasY()) { THIN.mouseMove(a, b) } } } function divScroll(b, a) { if(divScrolling) { THIN.vncdiv.scrollLeft = Math.min(THIN.rcParams.viewWidth - THIN.rcParams.maxWidth, THIN.vncdiv.scrollLeft + (mouseScrollX - b)); THIN.vncdiv.scrollTop = Math.min(THIN.rcParams.viewHeight - THIN.rcParams.maxHeight, THIN.vncdiv.scrollTop + (mouseScrollY - a)) } else { window.scroll($(window).scrollLeft() + (mouseScrollX - b), $(window).scrollTop() + (mouseScrollY - a)) } mouseScrollX = b; mouseScrollY = a; ignoreTouch = true; return } function windowScroll(b, a) { window.scroll($(window).scrollLeft() + mouseScrollX - b, $(window).scrollTop() + mouseScrollY - a); return } function getTouchX() { var a = lastEvent.touches[0].x; if(!relativeTouch) { a += THIN.vncdiv.scrollLeft * THIN.getZoom() } return a } function getTouchY() { var a = lastEvent.touches[0].y; if(!relativeTouch) { a += THIN.vncdiv.scrollTop * THIN.getZoom() } return a } function isTouchDevice() { try { document.createEvent("TouchEvent"); return true } catch(a) { return false } } function alignPanels() { if(stdKeyboardVisible || extKeyboardVisible) { ShowExtKeys(); if(extKeyboardVisible) { openExtKeyboard(true) } } alignKeypad() } function checkOffsetPane(c) { if(!THIN) { return } if(c == -1) { var b = byId("keypad"); c = (b) ? b.offsetWidth : 0 } var a = document.getElementById("offsetdiv"); if(!a) { a = document.createElement("DIV"); a.id = "offsetdiv"; a.style.zIndex = 0; a.style.margin = 0; a.style.height = "1px"; a.style.padding = 0; THIN.vncdiv.appendChild(a) } a.style.width = ((THIN.rcParams.viewWidth || window.screenWidth) + c + 2) + "px" } function alignKeypad() { var b = byId("keypad"); if(!relativeTouch) { checkOffsetPane(b.offsetWidth) } var a = (screenHeight - b.offsetHeight) / 2; b.style.top = a + "px"; b.style.left = "100%"; b.style.marginLeft = -b.offsetWidth + "px" } function showKeypad() { if(showToolbar) { $("#keypad").show(); alignKeypad() } } function adjustMainSize() { screenHeight = $(window).height(); screenWidth = $(window).width(); if(THIN && THIN.iphone) { window.setTimeout(function() { if(!window.navigator.standalone) { screenHeight += 60 } $("body").height(screenHeight); $("#" + THIN.rcParams.divId).height(screenHeight) }, 500) } $("#main").height(screenHeight); $("#main").width(screenWidth) } function checkScreenSize() { window.scroll(0, 1); adjustMainSize(); moveExtKeyboard(); alignPanels() } function initMobile(b, d) { hideUrlBar(); THIN = b; var c = ""; switch(THIN.rcParams.tbSize) { case("medium"): c = " tbMedium"; break; case("large"): c = " tbLarge" } if(d != undefined) { zoomEnabled = d } var h = '"; h += ''; h += '
'; h += '
'; h += '
Pop out

Help About×

×