meshcentral
Version:
Web based remote computer management server
1 lines • 19.2 kB
JavaScript
var CreateAmtRemoteDesktop=function(e,t){var a={};function n(e){return String.fromCharCode.apply(null,e)}function r(e){for(var t=new Uint8Array(e.length),a=0,n=e.length;a<n;++a)t[a]=e.charCodeAt(a);return t}function o(e,t,n,r,o,f,m,g){var p,S,w,C,y=e[t++],b={},D=0,k=0;if(0==y){if(2==a.bpp)for(C=0;C<m;C++)c(e[t++]+(e[t++]<<8),C);else for(C=0;C<m;C++)s(e[t++],C);i(a.spare,n,r)}else if(1==y){a.graymode?(S=e[t++],a.lowcolor&&(S<<=4),a.canvas.fillStyle="rgb("+S+","+S+","+S+")"):(S=e[t++]+(2==a.bpp?e[t++]<<8:0),a.canvas.fillStyle="rgb("+(1==a.bpp?(224&S)+","+((28&S)<<3)+","+u((3&S)<<6):(S>>8&248)+","+(S>>3&252)+","+((31&S)<<3))+")");var x=l(n,r);r=v(n,r),n=x,a.canvas.fillRect(n,r,o,f)}else if(y>1&&y<17){var T=4,K=15;if(2==a.bpp){for(C=0;C<y;C++)b[C]=e[t++]+(e[t++]<<8);for(2==y?(T=1,K=1):y<=4&&(T=2,K=3);D<m&&t<e.byteLength;)for(S=e[t++],C=8-T;C>=0;C-=T)c(b[S>>C&K],D++)}else{for(C=0;C<y;C++)b[C]=e[t++];for(2==y?(T=1,K=1):y<=4&&(T=2,K=3);D<m&&t<e.byteLength;)for(S=e[t++],C=8-T;C>=0;C-=T)s(b[S>>C&K],D++)}i(a.spare,n,r)}else if(128==y){if(2==a.bpp)for(;D<m&&t<e.byteLength;){S=e[t++]+(e[t++]<<8),k=1;do{k+=w=e[t++]}while(255==w);if(0==a.rotation)d(S,D,k),D+=k;else for(;--k>=0;)c(S,D++)}else for(;D<m&&t<e.byteLength;){S=e[t++],k=1;do{k+=w=e[t++]}while(255==w);if(0==a.rotation)h(S,D,k),D+=k;else for(;--k>=0;)s(S,D++)}i(a.spare,n,r)}else if(y>129){if(2==a.bpp)for(C=0;C<y-128;C++)b[C]=e[t++]+(e[t++]<<8);else for(C=0;C<y-128;C++)b[C]=e[t++];for(;D<m&&t<e.byteLength;){if(k=1,S=b[(p=e[t++])%128],p>127)do{k+=w=e[t++]}while(255==w);if(0==a.rotation)2==a.bpp?(d(S,D,k),D+=k):(h(S,D,k),D+=k);else if(2==a.bpp)for(;--k>=0;)c(S,D++);else for(;--k>=0;)s(S,D++)}i(a.spare,n,r)}}function i(e,t,n){if(1!=a.holding){var r=function(e,t){return 0==a.rotation?e:1==a.rotation?a.canvas.canvas.width-a.sparew2-t:2==a.rotation?a.canvas.canvas.width-a.sparew2-e:3==a.rotation?t:0}(t,n);n=function(e,t){return 0==a.rotation?t:1==a.rotation?e:2==a.rotation?a.canvas.canvas.height-a.spareh2-t:3==a.rotation?a.canvas.canvas.height-a.spareh-e:0}(t,n),t=r,a.canvas.putImageData(e,t,n)}}function s(e,t){var n=t<<2;if(a.rotation>0)if(1==a.rotation){var r=t%a.sparew,o=Math.floor(t/a.sparew);n=(t=r*a.sparew2+(a.sparew2-1-o))<<2}else if(2==a.rotation)n=a.sparew*a.spareh*4-4-n;else if(3==a.rotation){r=t%a.sparew,o=Math.floor(t/a.sparew);n=(t=(a.sparew2-1-r)*a.sparew2+o)<<2}a.graymode?(a.lowcolor&&(e<<=4),a.spare.data[n]=a.spare.data[n+1]=a.spare.data[n+2]=e):(a.spare.data[n]=224&e,a.spare.data[n+1]=(28&e)<<3,a.spare.data[n+2]=u((3&e)<<6))}function c(e,t){var n=t<<2;if(a.rotation>0)if(1==a.rotation){var r=t%a.sparew,o=Math.floor(t/a.sparew);n=(t=r*a.sparew2+(a.sparew2-1-o))<<2}else if(2==a.rotation)n=a.sparew*a.spareh*4-4-n;else if(3==a.rotation){r=t%a.sparew,o=Math.floor(t/a.sparew);n=(t=(a.sparew2-1-r)*a.sparew2+o)<<2}a.spare.data[n]=e>>8&248,a.spare.data[n+1]=e>>3&252,a.spare.data[n+2]=(31&e)<<3}function h(e,t,n){if(a.graymode){var r=t<<2;for(a.lowcolor&&(e<<=4);--n>=0;)a.spare.data[r]=a.spare.data[r+1]=a.spare.data[r+2]=e,r+=4}else{r=t<<2;for(var o=224&e,i=(28&e)<<3,s=u((3&e)<<6);--n>=0;)a.spare.data[r]=o,a.spare.data[r+1]=i,a.spare.data[r+2]=s,r+=4}}function d(e,t,n){for(var r=t<<2,o=e>>8&248,i=e>>3&252,s=(31&e)<<3;--n>=0;)a.spare.data[r]=o,a.spare.data[r+1]=i,a.spare.data[r+2]=s,r+=4}function l(e,t){return 0==a.rotation||1==a.rotation?e:2==a.rotation?e-a.canvas.canvas.width:3==a.rotation?e-a.canvas.canvas.height:0}function v(e,t){return 0==a.rotation?t:1==a.rotation?t-a.canvas.canvas.width:2==a.rotation?t-a.canvas.canvas.height:3==a.rotation?t:0}function u(e){return e>127?e+32:e}function f(){if(1!=a.holding)if(a.focusmode>0){var e=2*a.focusmode;a.send(String.fromCharCode(3,1)+ShortToStr(Math.max(Math.min(a.ox,a.mx)-a.focusmode,0))+ShortToStr(Math.max(Math.min(a.oy,a.my)-a.focusmode,0))+ShortToStr(e+Math.abs(a.ox-a.mx))+ShortToStr(e+Math.abs(a.oy-a.my))),a.ox=a.mx,a.oy=a.my}else a.send(String.fromCharCode(3,1,0,0,0,0)+ShortToStr(a.rwidth)+ShortToStr(a.rheight))}a.canvasid=e,a.CanvasId=Q(e),a.scrolldiv=t,a.canvas=Q(e).getContext("2d"),a.protocol=2,a.state=0,a.acc=null,a.ScreenWidth=960,a.ScreenHeight=700,a.width=0,a.height=0,a.rwidth=0,a.rheight=0,a.bpp=2,a.useRLE=!0,a.showmouse=!0,a.buttonmask=0,a.localKeyMap=!0,a.spare=null,a.sparew=0,a.spareh=0,a.sparew2=0,a.spareh2=0,a.sparecache={},a.onScreenSizeChange=null,a.frameRateDelay=0,a.noMouseRotate=!1,a.rotation=0,a.kvmDataSupported=!1,a.onKvmData=null,a.onKvmDataPending=[],a.onKvmDataAck=-1,a.holding=!1,a.lastKeepAlive=Date.now(),a.kvmExt={},a.kvmExtChanged=null,a.useZLib=!1,a.decimationMode=0,a.graymode=!1,a.lowcolor=!1,a.mNagleTimer=null,a.mx=0,a.my=0,a.ox=-1,a.oy=-1,a.focusmode=0,a.inflate=ZLIB.inflateInit(-15),a.xxStateChange=function(e){0==e?(a.canvas.fillStyle="#000000",a.canvas.fillRect(0,0,a.width,a.height),a.canvas.canvas.width=a.rwidth=a.width=640,a.canvas.canvas.height=a.rheight=a.height=400,QS(a.canvasid).cursor="default"):QS(a.canvasid).cursor=a.showmouse?"default":"none"},a.ProcessBinaryData=function(e){if(null!=a.recordedData&&!0!==a.recordedHolding&&a.recordedData.push(C(2,1,String.fromCharCode.apply(null,new Uint8Array(e)))),null==a.acc)a.acc=new Uint8Array(e);else{var t=new Uint8Array(a.acc.byteLength+e.byteLength);t.set(a.acc,0),t.set(new Uint8Array(e),a.acc.byteLength),a.acc=t}for(;null!=a.acc&&a.acc.byteLength>0;){var h=0,d=new DataView(a.acc.buffer);if(0==a.state&&a.acc.byteLength>=12)h=12,a.state=1,a.parent&&delete a.parent.connectTime,a.send("RFB 003.008\n");else if(1==a.state&&a.acc.byteLength>=1)h=a.acc[0]+1,a.send(String.fromCharCode(1)),a.state=2;else if(2==a.state&&a.acc.byteLength>=4){if(h=4,0!=d.getUint32(0))return a.Stop();a.send(String.fromCharCode(1)),a.state=3,a.parent&&(a.parent.disconnectCode=5e4)}else if(3==a.state&&a.acc.byteLength>=24){a.rotation=0;var l=d.getUint32(20);if(a.acc.byteLength<24+l)return;h=24+l,a.canvas.canvas.width=a.rwidth=a.width=a.ScreenWidth=d.getUint16(0),a.canvas.canvas.height=a.rheight=a.height=a.ScreenHeight=d.getUint16(2),a.DeskRecordServerInit=String.fromCharCode.apply(null,new Uint8Array(a.acc.buffer.slice(0,24+l)));var v="";a.useRLE&&(v+=IntToStr(16)),v+=IntToStr(0),v+=IntToStr(1092),a.send(String.fromCharCode(2,0)+ShortToStr(v.length/4+1)+v+IntToStr(-223)),0==a.graymode?1==a.bpp&&a.send(String.fromCharCode(0,0,0,0,8,8,0,1)+ShortToStr(7)+ShortToStr(7)+ShortToStr(3)+String.fromCharCode(5,2,0,0,0,0)):(2==a.bpp&&(a.bpp=1),0==a.lowcolor?a.send(String.fromCharCode(0,0,0,0,8,8,0,1)+ShortToStr(255)+ShortToStr(0)+ShortToStr(0)+String.fromCharCode(0,0,0,0,0,0)):a.send(String.fromCharCode(0,0,0,0,8,4,0,1)+ShortToStr(15)+ShortToStr(0)+ShortToStr(0)+String.fromCharCode(0,0,0,0,0,0))),a.state=4,a.parent&&(a.parent.connectTime=Date.now(),a.parent.disconnectCode=0,a.parent.xxStateChange(3)),a.ox=-1,null!=a.kvmExtChanged&&(a.decimationMode>0&&a.sendKvmExtCmd(2,a.decimationMode),a.sendKvmExtCmd(4,!0===a.useZLib?1:0)),f(),null!=a.onScreenSizeChange&&a.onScreenSizeChange(a,a.ScreenWidth,a.ScreenHeight),a.parent&&(a.parent.disconnectCode=50001,a.bpp*a.width*a.height>9216e3&&(a.parent.disconnectCode=50002))}else if(4==a.state)switch(a.acc[0]){case 0:if(a.acc.byteLength<4)return;a.state=100+d.getUint16(2),h=4,!0===a.recordedHolding&&(delete a.recordedHolding,a.recordedData.push(C(2,1,String.fromCharCode.apply(null,a.acc))));break;case 2:h=1;break;case 3:if(a.acc.byteLength<8)return;var u=d.getUint32(4)+8;if(a.acc.byteLength<u)return;h=p(a.acc,d)}else if(a.state>100&&a.acc.byteLength>=12){var m=d.getUint16(0),g=d.getUint16(2),S=d.getUint16(4),w=d.getUint16(6),y=S*w,b=d.getUint32(8);if(b<17){if(S<1||S>64||w<1||w>64)return console.log("Invalid tile size ("+S+","+w+"), disconnecting."),a.Stop();if(a.sparew!=S||a.spareh!=w){a.sparew=a.sparew2=S,a.spareh=a.spareh2=w,1!=a.rotation&&3!=a.rotation||(a.sparew2=w,a.spareh2=S);var D=a.sparew2+"x"+a.spareh2;if(a.spare=a.sparecache[D],!a.spare){a.sparecache[D]=a.spare=a.canvas.createImageData(a.sparew2,a.spareh2);for(var k=a.sparew2*a.spareh2<<2,x=3;x<k;x+=4)a.spare.data[x]=255}}}if(4294967073==b)a.canvas.canvas.width=a.rwidth=a.width=S,a.canvas.canvas.height=a.rheight=a.height=w,a.send(String.fromCharCode(3,0,0,0,0,0)+ShortToStr(a.width)+ShortToStr(a.height)),h=12,null!=a.onScreenSizeChange&&a.onScreenSizeChange(a,a.ScreenWidth,a.ScreenHeight),a.parent&&a.bpp*a.width*a.height>9216e3&&(a.parent.disconnectCode=50002);else if(0==b){var T=12,K=12+y*a.bpp;if(a.acc.byteLength<K)return;if(h=K,2==a.bpp)for(x=0;x<y;x++)c(d.getUint16(T,!0),x),T+=2;else for(x=0;x<y;x++)s(a.acc[T++],x);i(a.spare,m,g)}else{if(16!=b)return a.Stop();if(a.acc.byteLength<16)return;var I=d.getUint32(12);if(a.acc.byteLength<16+I)return;T=16;if(I>5&&0==a.acc[T]&&d.getUint16(T+1,!0)==I-5)o(a.acc,T+5,m,g,S,w,y,I);else{var M=a.inflate.inflate(n(new Uint8Array(a.acc.buffer.slice(T,T+I-0))));M.length>0?o(r(M),0,m,g,S,w,y,M.length):console.log("Invalid deflate data")}h=16+I}100==--a.state&&(a.state=4,0==a.frameRateDelay?f():setTimeout(f,a.frameRateDelay))}if(0==h)return;h!=a.acc.byteLength?a.acc=new Uint8Array(a.acc.buffer.slice(h)):a.acc=null}},a.hold=function(e){a.holding!=e&&(a.holding=e,a.canvas.fillStyle="#000000",a.canvas.fillRect(0,0,a.width,a.height),0==a.holding?(a.canvas.canvas.width==a.width&&a.canvas.canvas.height==a.height||(a.canvas.canvas.width=a.width,a.canvas.canvas.height=a.height,null!=a.onScreenSizeChange&&a.onScreenSizeChange(a,a.ScreenWidth,a.ScreenHeight)),a.send(String.fromCharCode(3,0,0,0,0,0)+ShortToStr(a.width)+ShortToStr(a.height))):(a.UnGrabMouseInput(),a.UnGrabKeyInput()))},a.tcanvas=null,a.setRotation=function(e){for(;e<0;)e+=4;var t=e%4;if(1!=a.holding){if(t==a.rotation)return!0;var n=a.canvas.canvas.width,r=a.canvas.canvas.height;1!=a.rotation&&3!=a.rotation||(n=a.canvas.canvas.height,r=a.canvas.canvas.width),null==a.tcanvas&&(a.tcanvas=document.createElement("canvas"));var o=a.tcanvas.getContext("2d");return o.setTransform(1,0,0,1,0,0),o.canvas.width=n,o.canvas.height=r,o.rotate(-90*a.rotation*Math.PI/180),0==a.rotation&&o.drawImage(a.canvas.canvas,0,0),1==a.rotation&&o.drawImage(a.canvas.canvas,-a.canvas.canvas.width,0),2==a.rotation&&o.drawImage(a.canvas.canvas,-a.canvas.canvas.width,-a.canvas.canvas.height),3==a.rotation&&o.drawImage(a.canvas.canvas,0,-a.canvas.canvas.height),0!=a.rotation&&2!=a.rotation||(a.canvas.canvas.height=n,a.canvas.canvas.width=r),1!=a.rotation&&3!=a.rotation||(a.canvas.canvas.height=r,a.canvas.canvas.width=n),a.canvas.setTransform(1,0,0,1,0,0),a.canvas.rotate(90*t*Math.PI/180),a.rotation=t,a.canvas.drawImage(a.tcanvas,l(0),v(0,0)),a.width=a.canvas.canvas.width,a.height=a.canvas.canvas.height,null!=a.onScreenResize&&a.onScreenResize(a,a.width,a.height,a.CanvasId),!0}a.rotation=t},a.Start=function(){for(var e in a.state=0,a.acc=null,a.inflate.inflateReset(),a.onKvmDataPending=[],a.onKvmDataAck=-1,a.kvmDataSupported=!1,a.kvmExt={},a.sparecache)delete a.sparecache[e]},a.Stop=function(){a.UnGrabMouseInput(),a.UnGrabKeyInput(),a.parent&&a.parent.Stop()},a.send=function(e){a.parent&&a.parent.send(e)};var m={Pause:19,CapsLock:20,Space:32,Quote:39,Minus:45,NumpadMultiply:42,NumpadAdd:43,PrintScreen:44,Comma:44,NumpadSubtract:45,NumpadDecimal:46,Period:46,Slash:47,NumpadDivide:47,Semicolon:59,Equal:61,OSLeft:91,BracketLeft:91,OSRight:91,Backslash:92,BracketRight:93,ContextMenu:93,Backquote:96,NumLock:144,ScrollLock:145,Backspace:65288,Tab:65289,Enter:65293,NumpadEnter:65293,Escape:65307,Delete:65535,Home:65360,PageUp:65365,PageDown:65366,ArrowLeft:65361,ArrowUp:65362,ArrowRight:65363,ArrowDown:65364,End:65367,Insert:65379,F1:65470,F2:65471,F3:65472,F4:65473,F5:65474,F6:65475,F7:65476,F8:65477,F9:65478,F10:65479,F11:65480,F12:65481,ShiftLeft:65505,ShiftRight:65506,ControlLeft:65507,ControlRight:65508,AltLeft:65513,AltRight:65514,MetaLeft:65511,MetaRight:65512};function g(e,t){if(t||(t=window.event),t.code&&0==a.localKeyMap){var n=function(e){return e.code.startsWith("Key")&&4==e.code.length?e.code.charCodeAt(3)+(0==e.shiftKey?32:0):e.code.startsWith("Digit")&&6==e.code.length?e.code.charCodeAt(5):e.code.startsWith("Numpad")&&7==e.code.length?e.code.charCodeAt(6):m[e.code]}(t);null!=n&&a.sendkey(n,e)}else{var r=n=t.keyCode;0==t.shiftKey&&n>=65&&n<=90&&(r=n+32),n>=112&&n<=124&&(r=n+65358),8==n&&(r=65288),9==n&&(r=65289),13==n&&(r=65293),16==n&&(r=65505),17==n&&(r=65507),18==n&&(r=65513),27==n&&(r=65307),33==n&&(r=65365),34==n&&(r=65366),35==n&&(r=65367),36==n&&(r=65360),37==n&&(r=65361),38==n&&(r=65362),39==n&&(r=65363),40==n&&(r=65364),45==n&&(r=65379),46==n&&(r=65535),n>=96&&n<=105&&(r=n-48),106==n&&(r=42),107==n&&(r=43),109==n&&(r=45),110==n&&(r=46),111==n&&(r=47),186==n&&(r=59),187==n&&(r=61),188==n&&(r=44),189==n&&(r=45),190==n&&(r=46),191==n&&(r=47),192==n&&(r=96),219==n&&(r=91),220==n&&(r=92),221==n&&(r=93),222==n&&(r=39),a.sendkey(r,e)}return a.haltEvent(t)}function p(e,t){if(e.byteLength<8)return 0;var r=t.getUint32(4)+8;if(e.byteLength<r)return 0;if(null!=a.onKvmData){var o=n(new Uint8Array(e.buffer.slice(8,r)));if(o.length>=16&&"\0KvmDataChannel"==o.substring(0,15)){0==a.kvmDataSupported&&(a.kvmDataSupported=!0),(-1==a.onKvmDataAck&&16==o.length||0!=o.charCodeAt(15))&&(a.onKvmDataAck=!0);try{urlvars&&urlvars.kvmdatatrace&&console.log("KVM-DataChannel-Recv("+(o.length-16)+"): "+o.substring(16))}catch(e){}o.length>=16&&a.onKvmData(o.substring(16)),1==a.onKvmDataAck&&a.onKvmDataPending.length>0&&a.sendKvmData(a.onKvmDataPending.shift())}else if(o.length>=13&&"\0KvmExtCmd\0"==o.substring(0,11)){var i=o.charCodeAt(11),s=o.charCodeAt(12);1==i&&(a.kvmExt.decimationMode=s,o.length>13&&(a.kvmExt.decimationState=o.charCodeAt(13)),null!=a.kvmExtChanged&&a.kvmExtChanged(1,a.kvmExt,a.kvmExt)),2==i&&a.sendKvmExtCmd(1),3==i&&(a.kvmExt.compression=s,null!=a.kvmExtChanged&&a.kvmExtChanged(3,a.kvmExt)),4==i&&a.sendKvmExtCmd(3)}else{console.log("Got KVM clipboard data:",o);try{urlvars&&urlvars.kvmdatatrace&&console.log("KVM-ClipBoard-Recv("+o.length+"): "+rstr2hex(o)+", "+o)}catch(e){}}}return r}a.sendkey=function(e,t){if("object"==typeof e){var n="";for(var r in e)n+=String.fromCharCode(4,e[r][1],0,0)+IntToStr(e[r][0]);a.send(n)}else a.send(String.fromCharCode(4,t,0,0)+IntToStr(e))},a.sendKvmExtCmd=function(e,t){var n="\0KvmExtCmd\0"+String.fromCharCode(e)+(null!=t?String.fromCharCode(t):"");a.send(String.fromCharCode(6,0,0,0)+IntToStr(n.length)+n)},a.sendKvmData=function(e){if(!0!==a.onKvmDataAck)a.onKvmDataPending.push(e);else{try{urlvars&&urlvars.kvmdatatrace&&console.log("KVM-DataChannel-Send("+e.length+"): "+e)}catch(e){}e="\0KvmDataChannel\0"+e,a.send(String.fromCharCode(6,0,0,0)+IntToStr(e.length)+e),a.onKvmDataAck=!1}},a.sendKeepAlive=function(){a.lastKeepAlive<Date.now()-5e3&&(a.lastKeepAlive=Date.now(),a.send(String.fromCharCode(6,0,0,0)+IntToStr(16)+"\0KvmDataChannel\0"))},a.sendClipboardData=function(e){try{urlvars&&urlvars.kvmdatatrace&&console.log("KVM-ClipBoard-Send("+e.length+"): "+rstr2hex(e)+", "+e)}catch(e){}a.send(String.fromCharCode(6,0,0,0)+IntToStr(e.length)+e)},a.SendCtrlAltDelMsg=function(){a.sendcad()},a.sendcad=function(){a.sendkey([[65507,1],[65513,1],[65535,1],[65535,0],[65513,0],[65507,0]])};var S=!1,w=!1;function C(e,t,n){var r=Date.now();return"number"==typeof n?(a.recordedSize+=n,ShortToStr(e)+ShortToStr(t)+IntToStr(n)+IntToStr(r>>32)+IntToStr(32&r)):(a.recordedSize+=n.length,ShortToStr(e)+ShortToStr(t)+IntToStr(n.length)+IntToStr(r>>32)+IntToStr(32&r)+n)}return a.GrabMouseInput=function(){if(1!=S){var e=a.canvas.canvas;e.onmouseup=a.mouseup,e.onmousedown=a.mousedown,e.onmousemove=a.mousemove,e.onwheel=a.mousewheel,S=!0}},a.UnGrabMouseInput=function(){if(0!=S){var e=a.canvas.canvas;e.onmousemove=null,e.onmouseup=null,e.onmousedown=null,e.onwheel=null,S=!1}},a.GrabKeyInput=function(){1!=w&&(document.onkeyup=a.handleKeyUp,document.onkeydown=a.handleKeyDown,document.onkeypress=a.handleKeys,w=!0)},a.UnGrabKeyInput=function(){0!=w&&(document.onkeyup=null,document.onkeydown=null,document.onkeypress=null,w=!1)},a.handleKeys=function(e){return a.haltEvent(e)},a.handleKeyUp=function(e){return g(0,e)},a.handleKeyDown=function(e){return g(1,e)},a.haltEvent=function(e){return e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),!1},a.mousedblclick=function(e){},a.mousewheel=function(e){var t=0;if("number"==typeof e.deltaY?t=-1*e.deltaY:"number"==typeof e.detail?t=-1*e.detail:"number"==typeof e.wheelDelta&&(t=e.wheelDelta),0!=t){a.ReverseMouseWheel&&(t*=-1);var n=a.buttonmask;return a.buttonmask|=1<<(t>0?3:4),a.mousemove(e,1),a.buttonmask=n,a.mousemove(e,1)}},a.mousedown=function(e){return a.buttonmask|=1<<e.button,a.mousemove(e,1)},a.mouseup=function(e){return a.buttonmask&=65535-(1<<e.button),a.mousemove(e,1)},a.mousemove=function(e,t){if(a.state<4)return!0;var n=a.canvas.canvas.height/Q(a.canvasid).offsetHeight,r=a.canvas.canvas.width/Q(a.canvasid).offsetWidth,o=a.getPositionOfControl(Q(a.canvasid));if(a.mx=(event.pageX-o[0])*r,a.my=(event.pageY-o[1])*n,event.addx&&(a.mx+=event.addx),event.addy&&(a.my+=event.addy),1!=a.rotation&&3!=a.rotation||(a.mx=a.mx*a.rwidth/a.width,a.my=a.my*a.rheight/a.height),1!=a.noMouseRotate){var i=function(e,t){return 0==a.rotation?e:1==a.rotation?t:2==a.rotation?a.canvas.canvas.width-e:3==a.rotation?a.canvas.canvas.height-t:0}(a.mx,a.my);a.my=function(e,t){return 0==a.rotation?t:1==a.rotation?a.canvas.canvas.width-e:2==a.rotation?a.canvas.canvas.height-t:3==a.rotation?e:0}(a.mx,a.my),a.mx=i}if(1==t?(a.send(String.fromCharCode(5,a.buttonmask)+ShortToStr(a.mx)+ShortToStr(a.my)),null!=a.mNagleTimer&&(clearTimeout(a.mNagleTimer),a.mNagleTimer=null)):null==a.mNagleTimer&&(a.mNagleTimer=setTimeout((function(){a.send(String.fromCharCode(5,a.buttonmask)+ShortToStr(a.mx)+ShortToStr(a.my)),a.mNagleTimer=null}),50)),QV("DeskFocus",a.focusmode),0!=a.focusmode){var s=Math.min(a.mx,a.canvas.canvas.width-a.focusmode),c=Math.min(a.my,a.canvas.canvas.height-a.focusmode),h=2*a.focusmode,d=Q(a.canvasid),l=d.offsetHeight/a.canvas.canvas.height,v=d.offsetWidth/a.canvas.canvas.width,u=QS("DeskFocus"),f=a.getPositionOfControl(Q(a.canvasid).parentElement);u.left=Math.max((s-a.focusmode)*l,0)+(pos[0]-f[0])+"px",u.top=Math.max((c-a.focusmode)*v,0)+(pos[1]-f[1])+"px",u.width=h*l-6+"px",u.height=h*l-6+"px"}return a.haltEvent(e)},a.getPositionOfControl=function(e){var t=Array(2);for(t[0]=t[1]=0;e;)t[0]+=e.offsetLeft,t[1]+=e.offsetTop,e=e.offsetParent;return t},a.StartRecording=function(){return(null==a.recordedData||null==a.DeskRecordServerInit)&&(a.recordedHolding=!0,a.recordedData=[],a.recordedStart=Date.now(),a.recordedSize=0,a.recordedData.push(C(1,0,JSON.stringify({magic:"MeshCentralRelaySession",ver:1,time:(new Date).toLocaleString(),protocol:102,bpp:a.bpp,graymode:a.graymode,lowcolor:a.lowcolor,screenSize:[a.width,a.height]}))),a.DeskRecordServerInit=String.fromCharCode(a.width>>8,255&a.width,a.height>>8,255&a.height)+a.DeskRecordServerInit.substring(4),a.recordedData.push(C(2,1,a.DeskRecordServerInit)),a.recordedData.push(C(3,0,atob(a.CanvasId.toDataURL("image/png").split(",")[1]))),!0)},a.StopRecording=function(){if(null!=a.recordedData){var e=a.recordedData;return e.push(C(3,0,"MeshCentralMCREC")),delete a.recordedData,delete a.recordedStart,delete a.recordedSize,e}},a}