2020-05-03 17:04:40 -04:00
|
|
|
var CreateAgentRemoteDesktop=function(e,t){var g={};"string"==typeof(g.CanvasId=e)&&(g.CanvasId=Q(e)),g.Canvas=g.CanvasId.getContext("2d"),g.scrolldiv=t,g.State=0,g.PendingOperations=[],g.tilesReceived=0,g.TilesDrawn=0,g.KillDraw=0,g.ipad=!1,g.tabletKeyboardVisible=!1,g.LastX=0,g.LastY=0,g.touchenabled=0,g.submenuoffset=0,g.touchtimer=null,g.TouchArray={},g.connectmode=0,g.connectioncount=0,g.rotation=0,g.protocol=2,g.debugmode=0,g.firstUpKeys=[],g.stopInput=!1,g.localKeyMap=!0,g.pressedKeys=[],g.sessionid=0,g.username,g.oldie=!1,g.CompressionLevel=50,g.ScalingLevel=1024,g.FrameRateTimer=100,g.FirstDraw=!1,g.ScreenWidth=960,g.ScreenHeight=700,g.width=960,g.height=960,g.onScreenSizeChange=null,g.onMessage=null,g.onConnectCountChanged=null,g.onDebugMessage=null,g.onTouchEnabledChanged=null,g.onDisplayinfo=null,g.accumulator=null;var v=["default","progress","crosshair","pointer","help","text","no-drop","move","nesw-resize","ns-resize","nwse-resize","w-resize","alias","wait","none","not-allowed","col-resize","row-resize","copy","zoom-in","zoom-out"];g.Start=function(){g.State=0,g.accumulator=null},g.Stop=function(){g.setRotation(0),g.UnGrabKeyInput(),g.UnGrabMouseInput(),g.touchenabled=0,null!=g.onScreenSizeChange&&g.onScreenSizeChange(g,g.ScreenWidth,g.ScreenHeight,g.CanvasId),g.Canvas.clearRect(0,0,g.CanvasId.width,g.CanvasId.height)},g.xxStateChange=function(e){if(g.State!=e)switch(g.State=e,g.CanvasId.style.cursor="default",e){case 0:g.Stop()}},g.send=function(e){1<g.debugmode&&console.log("KSend("+e.length+"): "+rstr2hex(e)),null!=g.parent&&g.parent.send(e)},g.ProcessPictureMsg=function(e,t,n){var o=new Image;o.xcount=g.tilesReceived++;var a=g.tilesReceived;o.src="data:image/jpeg;base64,"+btoa(e.substring(4,e.length)),o.onload=function(){if(null!=g.Canvas&&g.KillDraw<a&&0!=g.State)for(g.PendingOperations.push([a,2,o,t,n]);g.DoPendingOperations(););},o.error=function(){console.log("DecodeTileError")}},g.DoPendingOperations=function(){if(0==g.PendingOperations.length)return!1;for(var e=0;e<g.PendingOperations.length;e++){var t=g.PendingOperations[e];if(t[0]==g.TilesDrawn+1)return 1==t[1]?g.ProcessCopyRectMsg(t[2]):2==t[1]&&(g.Canvas.drawImage(t[2],g.rotX(t[3],t[4]),g.rotY(t[3],t[4])),delete t[2]),g.PendingOperations.splice(e,1),delete t,g.TilesDrawn++,g.TilesDrawn==g.tilesReceived&&g.KillDraw<g.TilesDrawn&&(g.KillDraw=g.TilesDrawn=g.tilesReceived=0),!0}return g.oldie&&0<g.PendingOperations.length&&g.TilesDrawn++,!1},g.ProcessCopyRectMsg=function(e){var t=((255&e.charCodeAt(0))<<8)+(255&e.charCodeAt(1)),n=((255&e.charCodeAt(2))<<8)+(255&e.charCodeAt(3)),o=((255&e.charCodeAt(4))<<8)+(255&e.charCodeAt(5)),a=((255&e.charCodeAt(6))<<8)+(255&e.charCodeAt(7)),r=((255&e.charCodeAt(8))<<8)+(255&e.charCodeAt(9)),s=((255&e.charCodeAt(10))<<8)+(255&e.charCodeAt(11));g.Canvas.drawImage(Canvas.canvas,t,n,r,s,o,a,r,s)},g.SendUnPause=function(){g.send(String.fromCharCode(0,8,0,5,0))},g.SendPause=function(){g.send(String.fromCharCode(0,8,0,5,1))},g.SendCompressionLevel=function(e,t,n,o){t&&(g.CompressionLevel=t),n&&(g.ScalingLevel=n),o&&(g.FrameRateTimer=o),g.send(String.fromCharCode(0,5,0,10,e,g.CompressionLevel)+g.shortToStr(g.ScalingLevel)+g.shortToStr(g.FrameRateTimer))},g.SendRefresh=function(){g.send(String.fromCharCode(0,6,0,4))},g.ProcessScreenMsg=function(e,t){for(0<g.debugmode&&console.log("ScreenSize: "+e+" x "+t),g.Canvas.setTransform(1,0,0,1,0,0),g.rotation=0,g.FirstDraw=!0,g.ScreenWidth=g.width=e,g.ScreenHeight=g.height=t,g.KillDraw=g.tilesReceived;0<g.PendingOperations.length;)g.PendingOperations.shift();g.SendCompressionLevel(1),g.SendUnPause(),null!=g.onScreenSizeChange&&g.onScreenSizeChange(g,g.ScreenWidth,g.ScreenHeight,g.CanvasId)},g.ProcessData=function(e){for(var t=0;t<e.length;){var n=g.ProcessDataEx(e.substring(t));if(null==n||0==n)break;t+=n}},g.ProcessDataEx=function(e){if(null!=g.accumulator&&(e=g.accumulator+e,g.accumulator=null),1<g.debugmode&&console.log("KRecv("+e.length+"): "+rstr2hex(e.substring(0,Math.min(e.length,40)))),!(e.length<4)){var t=null,n=0,o=0,a=ReadShort(e,0),r=ReadShort(e,2),s=0;if(null!=g.r
|