2022-05-21 11:30:39 +03:00
|
|
|
var CreateRDPDesktop=function(e){var a={};function n(e){return(!0===a.m.SwapMouse?[2,0,1,0,0]:[1,0,2,0,0])[e]}function o(e){a.State!=e&&(a.State=e,null!=a.onStateChanged&&a.onStateChanged(a,a.State))}function s(e){var t=a.Canvas.canvas.height/a.CanvasId.clientHeight,n=a.Canvas.canvas.width/a.CanvasId.clientWidth,s=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.Canvas.canvas),n=(e.pageX-s[0])*n,t=(e.pageY-s[1])*t;return e.addx&&(n+=e.addx),e.addy&&(t+=e.addy),{x:n,y:t}}a.m={KeyAction:{NONE:0,DOWN:1,UP:2,SCROLL:3,EXUP:4,EXDOWN:5,DBLCLICK:6}},a.State=0,a.canvas=Q(e),"string"==typeof(a.CanvasId=e)&&(a.CanvasId=Q(e)),a.Canvas=a.CanvasId.getContext("2d"),a.ScreenWidth=a.width=1280,a.ScreenHeight=a.height=1024,a.m.onClipboardChanged=null,a.onConsoleMessageChange=null,a.Start=function(e,t,n){o(1),a.nodeid=e,a.port=t;var s={savepass:(a.credentials=n).savecred,useServerCreds:n.servercred,width:n.width,height:n.height,flags:n.flags,workingDir:n.workdir,alternateShell:n.altshell};n.width&&n.height&&(s.width=a.ScreenWidth=a.width=n.width,s.height=a.ScreenHeight=a.height=n.height,delete n.width,delete n.height),a.render=new Mstsc.Canvas.create(a.canvas),a.socket=new WebSocket("wss://"+window.location.host+"/mstscrelay.ashx"),a.socket.binaryType="arraybuffer",a.socket.onopen=function(){o(2),a.socket.send(JSON.stringify(["infos",{ip:a.nodeid,port:a.port,screen:{width:a.width,height:a.height},domain:n.domain,username:n.username,password:n.password,options:s,locale:Mstsc.locale()}]))},a.socket.onmessage=function(e){if("string"==typeof e.data){var t=JSON.parse(e.data);switch(t[0]){case"rdp-connect":o(3),a.rotation=0,a.Canvas.setTransform(1,0,0,1,0,0),a.Canvas.canvas.width=a.ScreenWidth,a.Canvas.canvas.height=a.ScreenHeight,a.Canvas.fillRect(0,0,a.ScreenWidth,a.ScreenHeight),null!=a.m.onScreenSizeChange&&a.m.onScreenSizeChange(a,a.ScreenWidth,a.ScreenHeight,a.CanvasId);break;case"rdp-bitmap":if(null==a.bitmapData)break;var n=t[1];n.data=a.bitmapData,delete a.bitmapData,a.render.update(n);break;case"rdp-close":a.Stop();break;case"rdp-error":switch(a.consoleMessageTimeout=5,a.consoleMessage=t[1],delete a.consoleMessageArgs,2<t.length&&(a.consoleMessageArgs=[t[2]]),t[1]){case"NODE_RDP_PROTOCOL_X224_NEG_FAILURE":1==t[2]?a.consoleMessageId=9:2==t[2]?a.consoleMessageId=10:3==t[2]?a.consoleMessageId=11:4==t[2]?a.consoleMessageId=12:5==t[2]?a.consoleMessageId=13:6==t[2]?a.consoleMessageId=14:a.consoleMessageId=7;break;case"NODE_RDP_PROTOCOL_X224_NLA_NOT_SUPPORTED":a.consoleMessageId=8;break;default:a.consoleMessageId=null}a.onConsoleMessageChange&&a.onConsoleMessageChange(),a.Stop();break;case"rdp-clipboard":a.lastClipboardContent=t[1],a.m.onClipboardChanged&&a.m.onClipboardChanged(t[1]);break;case"ping":a.socket.send('["pong"]')}}else a.bitmapData=e.data},a.socket.onclose=function(){o(0)},o(1)},a.Stop=function(){a.Canvas.fillRect(0,0,a.ScreenWidth,a.ScreenHeight),a.socket&&a.socket.close()},a.m.setClipboard=function(e){a.socket&&a.socket.send(JSON.stringify(["clipboard",e]))},a.m.getClipboard=function(){return a.lastClipboardContent},a.m.mousemove=function(e){if(a.socket&&3==a.State){var t=s(e);if(!(t.x<0||t.y<0||t.x>a.ScreenWidth||t.y>a.ScreenHeight))return a.mouseNagleData=["mouse",t.x,t.y,0,!1],null==a.mouseNagleTimer&&(a.mouseNagleTimer=setTimeout(function(){a.socket.send(JSON.stringify(a.mouseNagleData)),a.mouseNagleTimer=null},50)),e.preventDefault(),!1}},a.m.mouseup=function(e){if(a.socket&&3==a.State){var t=s(e);if(!(t.x<0||t.y<0||t.x>a.ScreenWidth||t.y>a.ScreenHeight))return null!=a.mouseNagleTimer&&(clearTimeout(a.mouseNagleTimer),a.mouseNagleTimer=null),a.socket.send(JSON.stringify(["mouse",t.x,t.y,n(e.button),!1])),e.preventDefault(),!1}},a.m.mousedown=function(e){if(a.socket&&3==a.State){var t=s(e);if(!(t.x<0||t.y<0||t.x>a.ScreenWidth||t.y>a.ScreenHeight))return null!=a.mouseNagleTimer&&(clearTimeout(a.mouseNagleTimer),a.mouseNagleTimer=null),a.socket.send(JSON.stringify(["mouse",t.x,t.y,n(e.button),!0])),e.preventDefault(),!1}},a.m.handleKeyUp=function(e){if(a.socket&&
|