MeshCentral/public/scripts/amt-desktop-0.0.2-min.js
Ylian Saint-Hilaire 43e4a41792 Version 0.9.77
2022-02-01 17:11:09 -08:00

1 line
18 KiB
JavaScript

var CreateAmtRemoteDesktop=function(t,e){var S={};function m(t){return String.fromCharCode.apply(null,t)}function p(t,e,a,n,r,o,i){var s,c,h,d,l=t[e++],v={},u=0,f=0;if(0==l){if(2==S.bpp)for(d=0;d<i;d++)y(t[e++]+(t[e++]<<8),d);else for(d=0;d<i;d++)C(t[e++],d);w(S.spare,a,n)}else if(1==l){S.graymode?(c=t[e++],S.lowcolor&&(c<<=4),S.canvas.fillStyle="rgb("+c+","+c+","+c+")"):(c=t[e++]+(2==S.bpp?t[e++]<<8:0),S.canvas.fillStyle="rgb("+(1==S.bpp?(224&c)+","+((28&c)<<3)+","+T((3&c)<<6):(c>>8&248)+","+(c>>3&252)+","+((31&c)<<3))+")");var g=k(a);n=x(0,n),a=g,S.canvas.fillRect(a,n,r,o)}else if(1<l&&l<17){var m=4,p=15;if(2==S.bpp){for(d=0;d<l;d++)v[d]=t[e++]+(t[e++]<<8);for(2==l?p=m=1:l<=4&&(m=2,p=3);u<i&&e<t.byteLength;)for(c=t[e++],d=8-m;0<=d;d-=m)y(v[c>>d&p],u++)}else{for(d=0;d<l;d++)v[d]=t[e++];for(2==l?p=m=1:l<=4&&(m=2,p=3);u<i&&e<t.byteLength;)for(c=t[e++],d=8-m;0<=d;d-=m)C(v[c>>d&p],u++)}w(S.spare,a,n)}else if(128==l){if(2==S.bpp)for(;u<i&&e<t.byteLength;){for(c=t[e++]+(t[e++]<<8),f=1;f+=h=t[e++],255==h;);if(0==S.rotation)D(c,u,f),u+=f;else for(;0<=--f;)y(c,u++)}else for(;u<i&&e<t.byteLength;){for(c=t[e++],f=1;f+=h=t[e++],255==h;);if(0==S.rotation)b(c,u,f),u+=f;else for(;0<=--f;)C(c,u++)}w(S.spare,a,n)}else if(129<l){if(2==S.bpp)for(d=0;d<l-128;d++)v[d]=t[e++]+(t[e++]<<8);else for(d=0;d<l-128;d++)v[d]=t[e++];for(;u<i&&e<t.byteLength;){if(f=1,c=v[(s=t[e++])%128],127<s)for(;f+=h=t[e++],255==h;);if(0==S.rotation)(2==S.bpp?D:b)(c,u,f),u+=f;else if(2==S.bpp)for(;0<=--f;)y(c,u++);else for(;0<=--f;)C(c,u++)}w(S.spare,a,n)}}function w(t,e,a){var n,r,o;1!=S.holding&&(r=e,o=a,n=0==S.rotation?r:1==S.rotation?S.canvas.canvas.width-S.sparew2-o:2==S.rotation?S.canvas.canvas.width-S.sparew2-r:3==S.rotation?o:0,r=e,o=a,a=0==S.rotation?o:1==S.rotation?r:2==S.rotation?S.canvas.canvas.height-S.spareh2-o:3==S.rotation?S.canvas.canvas.height-S.spareh-r:0,e=n,S.canvas.putImageData(t,e,a))}function C(t,e){var a,n,r=e<<2;0<S.rotation&&(1==S.rotation?(a=e%S.sparew,n=Math.floor(e/S.sparew),r=(e=a*S.sparew2+(S.sparew2-1-n))<<2):2==S.rotation?r=S.sparew*S.spareh*4-4-r:3==S.rotation&&(a=e%S.sparew,n=Math.floor(e/S.sparew),r=(e=(S.sparew2-1-a)*S.sparew2+n)<<2)),S.graymode?(S.lowcolor&&(t<<=4),S.spare.data[r]=S.spare.data[r+1]=S.spare.data[r+2]=t):(S.spare.data[r]=224&t,S.spare.data[r+1]=(28&t)<<3,S.spare.data[r+2]=T((3&t)<<6))}function y(t,e){var a,n,r=e<<2;0<S.rotation&&(1==S.rotation?(a=e%S.sparew,n=Math.floor(e/S.sparew),r=(e=a*S.sparew2+(S.sparew2-1-n))<<2):2==S.rotation?r=S.sparew*S.spareh*4-4-r:3==S.rotation&&(a=e%S.sparew,n=Math.floor(e/S.sparew),r=(e=(S.sparew2-1-a)*S.sparew2+n)<<2)),S.spare.data[r]=t>>8&248,S.spare.data[r+1]=t>>3&252,S.spare.data[r+2]=(31&t)<<3}function b(t,e,a){if(S.graymode){var n=e<<2;for(S.lowcolor&&(t<<=4);0<=--a;)S.spare.data[n]=S.spare.data[n+1]=S.spare.data[n+2]=t,n+=4}else for(var n=e<<2,r=224&t,o=(28&t)<<3,i=T((3&t)<<6);0<=--a;)S.spare.data[n]=r,S.spare.data[n+1]=o,S.spare.data[n+2]=i,n+=4}function D(t,e,a){for(var n=e<<2,r=t>>8&248,o=t>>3&252,i=(31&t)<<3;0<=--a;)S.spare.data[n]=r,S.spare.data[n+1]=o,S.spare.data[n+2]=i,n+=4}function k(t){return 0==S.rotation||1==S.rotation?t:2==S.rotation?t-S.canvas.canvas.width:3==S.rotation?t-S.canvas.canvas.height:0}function x(t,e){return 0==S.rotation?e:1==S.rotation?e-S.canvas.canvas.width:2==S.rotation?e-S.canvas.canvas.height:3==S.rotation?e:0}function T(t){return 127<t?t+32:t}function K(){var t;1!=S.holding&&(0<S.focusmode?(t=2*S.focusmode,S.send(String.fromCharCode(3,1)+ShortToStr(Math.max(Math.min(S.ox,S.mx)-S.focusmode,0))+ShortToStr(Math.max(Math.min(S.oy,S.my)-S.focusmode,0))+ShortToStr(t+Math.abs(S.ox-S.mx))+ShortToStr(t+Math.abs(S.oy-S.my))),S.ox=S.mx,S.oy=S.my):S.send(String.fromCharCode(3,1,0,0,0,0)+ShortToStr(S.rwidth)+ShortToStr(S.rheight)))}S.canvasid=t,S.CanvasId=Q(t),S.scrolldiv=e,S.canvas=Q(t).getContext("2d"),S.protocol=2,S.state=0,S.acc=null,S.ScreenWidth=960,S.ScreenHeight=700,S.width=0,S.height=0,S.rwidth=0,S.rheight=0,S.bpp=2,S.useRLE=!0,S.showmouse=!0,S.buttonmask=0,S.localKeyMap=!0,S.spare=null,S.sparew=0,S.spareh=0,S.sparew2=0,S.spareh2=0,S.sparecache={},S.onScreenSizeChange=null,S.frameRateDelay=0,S.noMouseRotate=!1,S.rotation=0,S.kvmDataSupported=!1,S.onKvmData=null,S.onKvmDataPending=[],S.onKvmDataAck=-1,S.holding=!1,S.lastKeepAlive=Date.now(),S.kvmExt={},S.kvmExtChanged=null,S.useZLib=!1,S.decimationMode=0,S.graymode=!1,S.lowcolor=!1,S.mNagleTimer=null,S.mx=0,S.my=0,S.ox=-1,S.oy=-1,S.focusmode=0,S.inflate=ZLIB.inflateInit(-15),S.xxStateChange=function(t){0==t?(S.canvas.fillStyle="#000000",S.canvas.fillRect(0,0,S.width,S.height),S.canvas.canvas.width=S.rwidth=S.width=640,S.canvas.canvas.height=S.rheight=S.height=400,QS(S.canvasid).cursor="default"):QS(S.canvasid).cursor=S.showmouse?"default":"none"},S.ProcessBinaryData=function(t){var e;for(null!=S.recordedData&&!0!==S.recordedHolding&&S.recordedData.push(I(2,1,String.fromCharCode.apply(null,new Uint8Array(t)))),null==S.acc?S.acc=new Uint8Array(t):((e=new Uint8Array(S.acc.byteLength+t.byteLength)).set(S.acc,0),e.set(new Uint8Array(t),S.acc.byteLength),S.acc=e);null!=S.acc&&0<S.acc.byteLength;){var a=0,n=new DataView(S.acc.buffer);if(0==S.state&&12<=S.acc.byteLength)a=12,S.state=1,S.parent&&delete S.parent.connectTime,S.send("RFB 003.008\n");else if(1==S.state&&1<=S.acc.byteLength)a=S.acc[0]+1,S.send(String.fromCharCode(1)),S.state=2;else if(2==S.state&&4<=S.acc.byteLength){if(a=4,0!=n.getUint32(0))return S.Stop();S.send(String.fromCharCode(1)),S.state=3,S.parent&&(S.parent.disconnectCode=5e4)}else if(3==S.state&&24<=S.acc.byteLength){S.rotation=0;var r=n.getUint32(20);if(S.acc.byteLength<24+r)return;a=24+r,S.canvas.canvas.width=S.rwidth=S.width=S.ScreenWidth=n.getUint16(0),S.canvas.canvas.height=S.rheight=S.height=S.ScreenHeight=n.getUint16(2),S.DeskRecordServerInit=String.fromCharCode.apply(null,new Uint8Array(S.acc.buffer.slice(0,24+r)));var o="";S.useRLE&&(o+=IntToStr(16)),o+=IntToStr(0),o+=IntToStr(1092),S.send(String.fromCharCode(2,0)+ShortToStr(o.length/4+1)+o+IntToStr(-223)),0==S.graymode?1==S.bpp&&S.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==S.bpp&&(S.bpp=1),0==S.lowcolor?S.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)):S.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))),S.state=4,S.parent&&(S.parent.connectTime=Date.now(),S.parent.disconnectCode=0,S.parent.xxStateChange(3)),S.ox=-1,null!=S.kvmExtChanged&&(0<S.decimationMode&&S.sendKvmExtCmd(2,S.decimationMode),S.sendKvmExtCmd(4,!0===S.useZLib?1:0)),K(),null!=S.onScreenSizeChange&&S.onScreenSizeChange(S,S.ScreenWidth,S.ScreenHeight),S.parent&&(S.parent.disconnectCode=50001,9216e3<S.bpp*S.width*S.height&&(S.parent.disconnectCode=50002))}else if(4==S.state)switch(S.acc[0]){case 0:if(S.acc.byteLength<4)return;S.state=100+n.getUint16(2),a=4,!0===S.recordedHolding&&(delete S.recordedHolding,S.recordedData.push(I(2,1,String.fromCharCode.apply(null,S.acc))));break;case 2:a=1;break;case 3:if(S.acc.byteLength<8)return;var i=n.getUint32(4)+8;if(S.acc.byteLength<i)return;a=function(t,e){if(t.byteLength<8)return 0;var a=e.getUint32(4)+8;if(t.byteLength<a)return 0;if(null!=S.onKvmData){var n=m(new Uint8Array(t.buffer.slice(8,a)));if(16<=n.length&&"\0KvmDataChannel"==n.substring(0,15)){0==S.kvmDataSupported&&(S.kvmDataSupported=!0),(-1==S.onKvmDataAck&&16==n.length||0!=n.charCodeAt(15))&&(S.onKvmDataAck=!0);try{urlvars&&urlvars.kvmdatatrace&&console.log("KVM-DataChannel-Recv("+(n.length-16)+"): "+n.substring(16))}catch(t){}16<=n.length&&S.onKvmData(n.substring(16)),1==S.onKvmDataAck&&0<S.onKvmDataPending.length&&S.sendKvmData(S.onKvmDataPending.shift())}else if(13<=n.length&&"\0KvmExtCmd\0"==n.substring(0,11)){e=n.charCodeAt(11),t=n.charCodeAt(12);1==e&&(S.kvmExt.decimationMode=t,13<n.length&&(S.kvmExt.decimationState=n.charCodeAt(13)),null!=S.kvmExtChanged&&S.kvmExtChanged(1,S.kvmExt,S.kvmExt)),2==e&&S.sendKvmExtCmd(1),3==e&&(S.kvmExt.compression=t,null!=S.kvmExtChanged&&S.kvmExtChanged(3,S.kvmExt)),4==e&&S.sendKvmExtCmd(3)}else{console.log("Got KVM clipboard data:",n);try{urlvars&&urlvars.kvmdatatrace&&console.log("KVM-ClipBoard-Recv("+n.length+"): "+rstr2hex(n)+", "+n)}catch(t){}}}return a}(S.acc,n)}else if(100<S.state&&12<=S.acc.byteLength){var s=n.getUint16(0),c=n.getUint16(2),h=n.getUint16(4),d=n.getUint16(6),l=h*d,r=n.getUint32(8);if(r<17){if(h<1||64<h||d<1||64<d)return console.log("Invalid tile size ("+h+","+d+"), disconnecting."),S.Stop();if(S.sparew!=h||S.spareh!=d){S.sparew=S.sparew2=h,S.spareh=S.spareh2=d,1!=S.rotation&&3!=S.rotation||(S.sparew2=d,S.spareh2=h);o=S.sparew2+"x"+S.spareh2;if(S.spare=S.sparecache[o],!S.spare){S.sparecache[o]=S.spare=S.canvas.createImageData(S.sparew2,S.spareh2);for(var v=S.sparew2*S.spareh2<<2,u=3;u<v;u+=4)S.spare.data[u]=255}}}if(4294967073==r)S.canvas.canvas.width=S.rwidth=S.width=h,S.canvas.canvas.height=S.rheight=S.height=d,S.send(String.fromCharCode(3,0,0,0,0,0)+ShortToStr(S.width)+ShortToStr(S.height)),a=12,null!=S.onScreenSizeChange&&S.onScreenSizeChange(S,S.ScreenWidth,S.ScreenHeight),S.parent&&9216e3<S.bpp*S.width*S.height&&(S.parent.disconnectCode=50002);else if(0==r){var f=12,g=12+l*S.bpp;if(S.acc.byteLength<g)return;if(a=g,2==S.bpp)for(u=0;u<l;u++)y(n.getUint16(f,!0),u),f+=2;else for(u=0;u<l;u++)C(S.acc[f++],u);w(S.spare,s,c)}else{if(16!=r)return S.Stop();if(S.acc.byteLength<16)return;g=n.getUint32(12);if(S.acc.byteLength<16+g)return;f=16;5<g&&0==S.acc[f]&&n.getUint16(f+1,!0)==g-5?p(S.acc,f+5,s,c,h,d,l):0<(r=S.inflate.inflate(m(new Uint8Array(S.acc.buffer.slice(f,+(f+g)))))).length?p(function(t){for(var e=new Uint8Array(t.length),a=0,n=t.length;a<n;++a)e[a]=t.charCodeAt(a);return e}(r),0,s,c,h,d,l,r.length):console.log("Invalid deflate data"),a=16+g}100==--S.state&&(S.state=4,0==S.frameRateDelay?K():setTimeout(K,S.frameRateDelay))}if(0==a)return;a!=S.acc.byteLength?S.acc=new Uint8Array(S.acc.buffer.slice(a)):S.acc=null}},S.hold=function(t){S.holding!=t&&(S.holding=t,S.canvas.fillStyle="#000000",S.canvas.fillRect(0,0,S.width,S.height),0==S.holding?(S.canvas.canvas.width==S.width&&S.canvas.canvas.height==S.height||(S.canvas.canvas.width=S.width,S.canvas.canvas.height=S.height,null!=S.onScreenSizeChange&&S.onScreenSizeChange(S,S.ScreenWidth,S.ScreenHeight)),S.send(String.fromCharCode(3,0,0,0,0,0)+ShortToStr(S.width)+ShortToStr(S.height))):(S.UnGrabMouseInput(),S.UnGrabKeyInput()))},S.tcanvas=null,S.setRotation=function(t){for(;t<0;)t+=4;var e=t%4;if(1!=S.holding){if(e==S.rotation)return!0;var a=S.canvas.canvas.width,n=S.canvas.canvas.height;1!=S.rotation&&3!=S.rotation||(a=S.canvas.canvas.height,n=S.canvas.canvas.width),null==S.tcanvas&&(S.tcanvas=document.createElement("canvas"));var r=S.tcanvas.getContext("2d");return r.setTransform(1,0,0,1,0,0),r.canvas.width=a,r.canvas.height=n,r.rotate(-90*S.rotation*Math.PI/180),0==S.rotation&&r.drawImage(S.canvas.canvas,0,0),1==S.rotation&&r.drawImage(S.canvas.canvas,-S.canvas.canvas.width,0),2==S.rotation&&r.drawImage(S.canvas.canvas,-S.canvas.canvas.width,-S.canvas.canvas.height),3==S.rotation&&r.drawImage(S.canvas.canvas,0,-S.canvas.canvas.height),0!=S.rotation&&2!=S.rotation||(S.canvas.canvas.height=a,S.canvas.canvas.width=n),1!=S.rotation&&3!=S.rotation||(S.canvas.canvas.height=n,S.canvas.canvas.width=a),S.canvas.setTransform(1,0,0,1,0,0),S.canvas.rotate(90*e*Math.PI/180),S.rotation=e,S.canvas.drawImage(S.tcanvas,k(0),x(0,0)),S.width=S.canvas.canvas.width,S.height=S.canvas.canvas.height,null!=S.onScreenResize&&S.onScreenResize(S,S.width,S.height,S.CanvasId),!0}S.rotation=e},S.Start=function(){for(var t in S.state=0,S.acc=null,S.inflate.inflateReset(),S.onKvmDataPending=[],S.onKvmDataAck=-1,S.kvmDataSupported=!1,S.kvmExt={},S.sparecache)delete S.sparecache[t]},S.Stop=function(){S.UnGrabMouseInput(),S.UnGrabKeyInput(),S.parent&&S.parent.Stop()},S.send=function(t){S.parent&&S.parent.send(t)};var r={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 a(t,e){var a,n;return(e=e||window.event).code&&0==S.localKeyMap?null!=(a=(n=e).code.startsWith("Key")&&4==n.code.length?n.code.charCodeAt(3)+(0==n.shiftKey?32:0):n.code.startsWith("Digit")&&6==n.code.length?n.code.charCodeAt(5):n.code.startsWith("Numpad")&&7==n.code.length?n.code.charCodeAt(6):r[n.code])&&S.sendkey(a,t):(n=a=e.keyCode,0==e.shiftKey&&65<=a&&a<=90&&(n=a+32),112<=a&&a<=124&&(n=a+65358),8==a&&(n=65288),9==a&&(n=65289),13==a&&(n=65293),16==a&&(n=65505),17==a&&(n=65507),18==a&&(n=65513),27==a&&(n=65307),33==a&&(n=65365),34==a&&(n=65366),35==a&&(n=65367),36==a&&(n=65360),37==a&&(n=65361),38==a&&(n=65362),39==a&&(n=65363),40==a&&(n=65364),45==a&&(n=65379),46==a&&(n=65535),96<=a&&a<=105&&(n=a-48),106==a&&(n=42),107==a&&(n=43),109==a&&(n=45),110==a&&(n=46),111==a&&(n=47),186==a&&(n=59),187==a&&(n=61),188==a&&(n=44),189==a&&(n=45),190==a&&(n=46),191==a&&(n=47),192==a&&(n=96),219==a&&(n=91),220==a&&(n=92),221==a&&(n=93),222==a&&(n=39),S.sendkey(n,t)),S.haltEvent(e)}S.sendkey=function(t,e){if("object"==typeof t){var a,n="";for(a in t)n+=String.fromCharCode(4,t[a][1],0,0)+IntToStr(t[a][0]);S.send(n)}else S.send(String.fromCharCode(4,e,0,0)+IntToStr(t))},S.sendKvmExtCmd=function(t,e){e="\0KvmExtCmd\0"+String.fromCharCode(t)+(null!=e?String.fromCharCode(e):"");S.send(String.fromCharCode(6,0,0,0)+IntToStr(e.length)+e)},S.sendKvmData=function(t){if(!0!==S.onKvmDataAck)S.onKvmDataPending.push(t);else{try{urlvars&&urlvars.kvmdatatrace&&console.log("KVM-DataChannel-Send("+t.length+"): "+t)}catch(t){}t="\0KvmDataChannel\0"+t,S.send(String.fromCharCode(6,0,0,0)+IntToStr(t.length)+t),S.onKvmDataAck=!1}},S.sendKeepAlive=function(){S.lastKeepAlive<Date.now()-5e3&&(S.lastKeepAlive=Date.now(),S.send(String.fromCharCode(6,0,0,0)+IntToStr(16)+"\0KvmDataChannel\0"))},S.sendClipboardData=function(t){try{urlvars&&urlvars.kvmdatatrace&&console.log("KVM-ClipBoard-Send("+t.length+"): "+rstr2hex(t)+", "+t)}catch(t){}S.send(String.fromCharCode(6,0,0,0)+IntToStr(t.length)+t)},S.SendCtrlAltDelMsg=function(){S.sendcad()};var n=!(S.sendcad=function(){S.sendkey([[65507,1],[65513,1],[65535,1],[65535,0],[65513,0],[65507,0]])}),o=!1;function I(t,e,a){var n=Date.now();return"number"==typeof a?(S.recordedSize+=a,ShortToStr(t)+ShortToStr(e)+IntToStr(a)+IntToStr(n>>32)+IntToStr(32&n)):(S.recordedSize+=a.length,ShortToStr(t)+ShortToStr(e)+IntToStr(a.length)+IntToStr(n>>32)+IntToStr(32&n)+a)}return S.GrabMouseInput=function(){var t;1!=n&&((t=S.canvas.canvas).onmouseup=S.mouseup,t.onmousedown=S.mousedown,t.onmousemove=S.mousemove,n=!0)},S.UnGrabMouseInput=function(){var t;0!=n&&((t=S.canvas.canvas).onmousemove=null,t.onmouseup=null,t.onmousedown=null,n=!1)},S.GrabKeyInput=function(){1!=o&&(document.onkeyup=S.handleKeyUp,document.onkeydown=S.handleKeyDown,document.onkeypress=S.handleKeys,o=!0)},S.UnGrabKeyInput=function(){0!=o&&(document.onkeyup=null,document.onkeydown=null,document.onkeypress=null,o=!1)},S.handleKeys=function(t){return S.haltEvent(t)},S.handleKeyUp=function(t){return a(0,t)},S.handleKeyDown=function(t){return a(1,t)},S.haltEvent=function(t){return t.preventDefault&&t.preventDefault(),t.stopPropagation&&t.stopPropagation(),!1},S.mousedblclick=function(t){},S.mousedown=function(t){return S.buttonmask|=1<<t.button,S.mousemove(t,1)},S.mouseup=function(t){return S.buttonmask&=65535-(1<<t.button),S.mousemove(t,1)},S.mousemove=function(t,e){if(S.state<4)return!0;var a,n,r,o,i,s=S.canvas.canvas.height/Q(S.canvasid).offsetHeight,c=S.canvas.canvas.width/Q(S.canvasid).offsetWidth,h=S.getPositionOfControl(Q(S.canvasid));return S.mx=(event.pageX-h[0])*c,S.my=(event.pageY-h[1])*s,event.addx&&(S.mx+=event.addx),event.addy&&(S.my+=event.addy),1!=S.rotation&&3!=S.rotation||(S.mx=S.mx*S.rwidth/S.width,S.my=S.my*S.rheight/S.height),1!=S.noMouseRotate&&(a=S.mx,n=S.my,o=0==S.rotation?a:1==S.rotation?n:2==S.rotation?S.canvas.canvas.width-a:3==S.rotation?S.canvas.canvas.height-n:0,S.my=(r=S.mx,i=S.my,0==S.rotation?i:1==S.rotation?S.canvas.canvas.width-r:2==S.rotation?S.canvas.canvas.height-i:3==S.rotation?r:0),S.mx=o),1==e?(S.send(String.fromCharCode(5,S.buttonmask)+ShortToStr(S.mx)+ShortToStr(S.my)),null!=S.mNagleTimer&&(clearTimeout(S.mNagleTimer),S.mNagleTimer=null)):null==S.mNagleTimer&&(S.mNagleTimer=setTimeout(function(){S.send(String.fromCharCode(5,S.buttonmask)+ShortToStr(S.mx)+ShortToStr(S.my)),S.mNagleTimer=null},50)),QV("DeskFocus",S.focusmode),0!=S.focusmode&&(s=Math.min(S.mx,S.canvas.canvas.width-S.focusmode),a=Math.min(S.my,S.canvas.canvas.height-S.focusmode),n=2*S.focusmode,r=(i=Q(S.canvasid)).offsetHeight/S.canvas.canvas.height,o=i.offsetWidth/S.canvas.canvas.width,e=QS("DeskFocus"),i=S.getPositionOfControl(Q(S.canvasid).parentElement),e.left=Math.max((s-S.focusmode)*r,0)+(pos[0]-i[0])+"px",e.top=Math.max((a-S.focusmode)*o,0)+(pos[1]-i[1])+"px",e.width=n*r-6+"px",e.height=n*r-6+"px"),S.haltEvent(t)},S.getPositionOfControl=function(t){var e=Array(2);for(e[0]=e[1]=0;t;)e[0]+=t.offsetLeft,e[1]+=t.offsetTop,t=t.offsetParent;return e},S.StartRecording=function(){return(null==S.recordedData||null==S.DeskRecordServerInit)&&(S.recordedHolding=!0,S.recordedData=[],S.recordedStart=Date.now(),S.recordedSize=0,S.recordedData.push(I(1,0,JSON.stringify({magic:"MeshCentralRelaySession",ver:1,time:(new Date).toLocaleString(),protocol:200,bpp:S.bpp,graymode:S.graymode,lowcolor:S.lowcolor,screenSize:[S.width,S.height]}))),S.DeskRecordServerInit=String.fromCharCode(S.width>>8,255&S.width,S.height>>8,255&S.height)+S.DeskRecordServerInit.substring(4),S.recordedData.push(I(2,1,S.DeskRecordServerInit)),S.recordedData.push(I(3,0,atob(S.CanvasId.toDataURL("image/png").split(",")[1]))),!0)},S.StopRecording=function(){if(null!=S.recordedData){var t=S.recordedData;return t.push(I(3,0,"MeshCentralMCREC")),delete S.recordedData,delete S.recordedStart,delete S.recordedSize,t}},S}