MeshCentral/public/scripts/agent-desktop-0.0.2-min.js
2021-03-18 21:09:56 -07:00

1 line
21 KiB
JavaScript

Uint8Array.prototype.slice||Object.defineProperty(Uint8Array.prototype,"slice",{value:function(e,t){return new Uint8Array(Array.prototype.slice.call(this,e,t))}});var CreateAgentRemoteDesktop=function(e,t){var d={};"string"==typeof(d.CanvasId=e)&&(d.CanvasId=Q(e)),d.Canvas=d.CanvasId.getContext("2d"),d.scrolldiv=t,d.State=0,d.PendingOperations=[],d.tilesReceived=0,d.TilesDrawn=0,d.KillDraw=0,d.ipad=!1,d.tabletKeyboardVisible=!1,d.LastX=0,d.LastY=0,d.touchenabled=0,d.submenuoffset=0,d.touchtimer=null,d.TouchArray={},d.connectmode=0,d.connectioncount=0,d.rotation=0,d.protocol=2,d.debugmode=0,d.firstUpKeys=[],d.stopInput=!1,d.localKeyMap=!0,d.remoteKeyMap=!1,d.pressedKeys=[],d.sessionid=0,d.username,d.oldie=!1,d.CompressionLevel=50,d.ScalingLevel=1024,d.FrameRateTimer=100,d.SwapMouse=!1,d.FirstDraw=!1,d.ScreenWidth=960,d.ScreenHeight=701,d.width=960,d.height=960,d.displays=null,d.selectedDisplay=null,d.onScreenSizeChange=null,d.onMessage=null,d.onConnectCountChanged=null,d.onDebugMessage=null,d.onTouchEnabledChanged=null,d.onDisplayinfo=null;var h=!(d.accumulator=null),g="default";d.mouseCursorActive=function(e){h!=e&&(h=e,d.CanvasId.style.cursor=1==e?g:"default")};var p=["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"];d.Start=function(){d.State=0,d.accumulator=null},d.Stop=function(){d.setRotation(0),d.UnGrabKeyInput(),d.UnGrabMouseInput(),d.touchenabled=0,null!=d.onScreenSizeChange&&d.onScreenSizeChange(d,d.ScreenWidth,d.ScreenHeight,d.CanvasId),d.Canvas.clearRect(0,0,d.CanvasId.width,d.CanvasId.height)},d.xxStateChange=function(e){d.State!=e&&(d.State=e,d.CanvasId.style.cursor="default",0===e&&d.Stop())},d.send=function(e){2<d.debugmode&&console.log("KSend("+e.length+"): "+rstr2hex(e)),null!=d.parent&&d.parent.send(e)},d.ProcessPictureMsg=function(e,t,n){var o=new Image;o.xcount=d.tilesReceived++;for(var a=d.tilesReceived,r=e.slice(4),s=0,i=[];5e4<r.byteLength-s;)i.push(String.fromCharCode.apply(null,r.slice(s,s+5e4))),s+=5e4;0<s?i.push(String.fromCharCode.apply(null,r.slice(s))):i.push(String.fromCharCode.apply(null,r)),o.src="data:image/jpeg;base64,"+btoa(i.join("")),o.onload=function(){if(null!=d.Canvas&&d.KillDraw<a&&0!=d.State)for(d.PendingOperations.push([a,2,o,t,n]);d.DoPendingOperations(););else d.PendingOperations.push([a,0])},o.error=function(){console.log("DecodeTileError")}},d.DoPendingOperations=function(){if(0==d.PendingOperations.length)return!1;for(var e=0;e<d.PendingOperations.length;e++){var t=d.PendingOperations[e];if(t[0]==d.TilesDrawn+1)return 1==t[1]?d.ProcessCopyRectMsg(t[2]):2==t[1]&&(d.Canvas.drawImage(t[2],d.rotX(t[3],t[4]),d.rotY(t[3],t[4])),delete t[2]),d.PendingOperations.splice(e,1),delete t,d.TilesDrawn++,d.TilesDrawn==d.tilesReceived&&d.KillDraw<d.TilesDrawn&&(d.KillDraw=d.TilesDrawn=d.tilesReceived=0),!0}return d.oldie&&0<d.PendingOperations.length&&d.TilesDrawn++,!1},d.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)),e=((255&e.charCodeAt(10))<<8)+(255&e.charCodeAt(11));d.Canvas.drawImage(Canvas.canvas,t,n,r,e,o,a,r,e)},d.SendUnPause=function(){1<d.debugmode&&console.log("SendUnPause"),d.send(String.fromCharCode(0,8,0,5,0))},d.SendPause=function(){1<d.debugmode&&console.log("SendPause"),d.send(String.fromCharCode(0,8,0,5,1))},d.SendCompressionLevel=function(e,t,n,o){t&&(d.CompressionLevel=t),n&&(d.ScalingLevel=n),o&&(d.FrameRateTimer=o),d.send(String.fromCharCode(0,5,0,10,e,d.CompressionLevel)+d.shortToStr(d.ScalingLevel)+d.shortToStr(d.FrameRateTimer))},d.SendRefresh=function(){d.send(String.fromCharCode(0,6,0,4))},d.ProcessScreenMsg=function(e,t){if(0<d.debugmode&&console.log("ScreenSize: "+e+" x "+t),d.ScreenWidth!=e||d.ScreenHeight!=t){for(d.Canvas.setTransform(1,0,0,1,0,0),d.rotation=0,d.FirstDraw=!0,d.ScreenWidth=d.width=e,d.ScreenHeight=d.height=t,d.KillDraw=d.tilesReceived;0<d.PendingOperations.length;)d.PendingOperations.shift();d.SendCompressionLevel(1),d.SendUnPause(),null!=d.onScreenSizeChange&&d.onScreenSizeChange(d,d.ScreenWidth,d.ScreenHeight,d.CanvasId)}},d.ProcessBinaryCommand=function(e,t,n){var o,a;switch(3!=e&&4!=e&&7!=e||(o=(n[4]<<8)+n[5],a=(n[6]<<8)+n[7]),2<d.debugmode&&console.log("CMD",e,t,o,a),null!=d.recordedData&&(65e3<t?d.recordedData.push(S(2,1,d.shortToStr(27)+d.shortToStr(8)+d.intToStr(t)+d.shortToStr(e)+d.shortToStr(0)+d.shortToStr(0)+d.shortToStr(0)+String.fromCharCode.apply(null,n))):d.recordedData.push(S(2,1,String.fromCharCode.apply(null,n)))),e){case 3:d.FirstDraw&&d.onResize(),d.ProcessPictureMsg(n.slice(4),o,a);break;case 7:d.ProcessScreenMsg(o,a),d.SendKeyMsgKC(d.KeyAction.UP,16),d.SendKeyMsgKC(d.KeyAction.UP,17),d.SendKeyMsgKC(d.KeyAction.UP,18),d.SendKeyMsgKC(d.KeyAction.UP,91),d.SendKeyMsgKC(d.KeyAction.UP,92),d.SendKeyMsgKC(d.KeyAction.UP,16),d.send(String.fromCharCode(0,14,0,4));break;case 11:var r=0,s={},i=(n[4]<<8)+n[5];if(0<i)for(var r=(n[6+2*i]<<8)+n[7+2*i],c=0;c<i;c++){var u=(n[6+2*c]<<8)+n[7+2*c];s[u]=65535==u?"All Displays":"Display "+u}d.displays=s,d.selectedDisplay=r,null!=d.onDisplayinfo&&d.onDisplayinfo(d,s,r);break;case 12:break;case 14:d.touchenabled=1,d.TouchArray={},null!=d.onTouchEnabledChanged&&d.onTouchEnabledChanged(d.touchenabled);break;case 15:d.TouchArray={};break;case 17:var l=String.fromCharCode.apply(null,n.slice(4));console.log("Got KVM Message: "+l),null!=d.onMessage&&d.onMessage(l,d);break;case 65:"."!=(l=String.fromCharCode.apply(null,n.slice(4)))[0]?(console.log(l),d.parent&&d.parent.setConsoleMessage&&d.parent.setConsoleMessage(l)):console.log("KVM: "+l.substring(1));break;case 88:if(5!=t||d.stopInput)break;l=n[4];g=p[l=p.length<l?0:l],h&&(d.CanvasId.style.cursor=g);break;default:console.log("Unknown command",e,t)}},d.MouseButton={NONE:0,LEFT:2,RIGHT:8,MIDDLE:32},d.KeyAction={NONE:0,DOWN:1,UP:2,SCROLL:3,EXUP:4,EXDOWN:5,DBLCLICK:6},d.InputType={KEY:1,MOUSE:2,CTRLALTDEL:10,TOUCH:15,KEYUNICODE:85},d.Alternate=0;var o={Pause:19,CapsLock:20,Space:32,Quote:222,Minus:189,NumpadMultiply:106,NumpadAdd:107,PrintScreen:44,Comma:188,NumpadSubtract:109,NumpadDecimal:110,Period:190,Slash:191,NumpadDivide:111,Semicolon:186,Equal:187,OSLeft:91,BracketLeft:219,OSRight:91,Backslash:220,BracketRight:221,ContextMenu:93,Backquote:192,NumLock:144,ScrollLock:145,Backspace:8,Tab:9,Enter:13,NumpadEnter:13,Escape:27,Delete:46,Home:36,PageUp:33,PageDown:34,ArrowLeft:37,ArrowUp:38,ArrowRight:39,ArrowDown:40,End:35,Insert:45,F1:112,F2:113,F3:114,F4:115,F5:116,F6:117,F7:118,F8:119,F9:120,F10:121,F11:122,F12:123,ShiftLeft:16,ShiftRight:16,ControlLeft:17,ControlRight:17,AltLeft:18,AltRight:18,MetaLeft:91,MetaRight:92,VolumeMute:181};function S(e,t,n){var o=Date.now();return"number"==typeof n?(d.recordedSize+=n,d.shortToStr(e)+d.shortToStr(t)+d.intToStr(n)+d.intToStr(o>>32)+d.intToStr(32&o)):(d.recordedSize+=n.length,d.shortToStr(e)+d.shortToStr(t)+d.intToStr(n.length)+d.intToStr(o>>32)+d.intToStr(32&o)+n)}return d.SendKeyMsg=function(e,t){var n;null!=e&&((t=t||window.event).code&&0==d.localKeyMap?null!=(n=(n=t).code.startsWith("Key")&&4==n.code.length?n.code.charCodeAt(3):n.code.startsWith("Digit")&&6==n.code.length?n.code.charCodeAt(5):n.code.startsWith("Numpad")&&7==n.code.length?n.code.charCodeAt(6)+48:o[n.code])&&d.SendKeyMsgKC(e,n):(59==(n=t.keyCode)?n=186:173==n?n=189:61==n&&(n=187),d.SendKeyMsgKC(e,n)))},d.SendMessage=function(e){3==d.State&&d.send(String.fromCharCode(0,17)+d.shortToStr(4+e.length)+e)},d.SendKeyMsgKC=function(e,t){if(3==d.State)if("object"==typeof e)for(var n in e)d.SendKeyMsgKC(e[n][0],e[n][1]);else 1==e?-1==d.pressedKeys.indexOf(t)&&d.pressedKeys.unshift(t):2==e&&-1!=(n=d.pressedKeys.indexOf(t))&&d.pressedKeys.splice(n,1),0<d.debugmode&&console.log("Sending Key "+t+", action "+e),d.send(String.fromCharCode(0,d.InputType.KEY,0,6,e-1,t))},d.SendStringUnicode=function(e){if(3==d.State)for(var t=0;t<e.length;t++)d.send(String.fromCharCode(0,d.InputType.KEYUNICODE,0,7,0)+ShortToStr(e.charCodeAt(t)))},d.SendKeyUnicode=function(e,t){3==d.State&&(0<d.debugmode&&console.log("Sending UnicodeKey "+t),d.send(String.fromCharCode(0,d.InputType.KEYUNICODE,0,7,e-1)+ShortToStr(t)))},d.sendcad=function(){d.SendCtrlAltDelMsg()},d.SendCtrlAltDelMsg=function(){3==d.State&&d.send(String.fromCharCode(0,d.InputType.CTRLALTDEL,0,4))},d.SendEscKey=function(){3==d.State&&d.send(String.fromCharCode(0,d.InputType.KEY,0,6,0,27,0,d.InputType.KEY,0,6,1,27))},d.SendStartMsg=function(){d.SendKeyMsgKC(d.KeyAction.EXDOWN,91),d.SendKeyMsgKC(d.KeyAction.EXUP,91)},d.SendCharmsMsg=function(){d.SendKeyMsgKC(d.KeyAction.EXDOWN,91),d.SendKeyMsgKC(d.KeyAction.DOWN,67),d.SendKeyMsgKC(d.KeyAction.UP,67),d.SendKeyMsgKC(d.KeyAction.EXUP,91)},d.SendTouchMsg1=function(e,t,n,o){3==d.State&&d.send(String.fromCharCode(0,d.InputType.TOUCH)+d.shortToStr(14)+String.fromCharCode(1,e)+d.intToStr(t)+d.shortToStr(n)+d.shortToStr(o))},d.SendTouchMsg2=function(e,t){var n,o,a="";for(o in d.TouchArray)o==e?n=t:1==d.TouchArray[o].f?(n=65542,d.TouchArray[o].f=3,0):2==d.TouchArray[o].f?(n=262144,0):n=131078,a+=String.fromCharCode(o)+d.intToStr(n)+d.shortToStr(d.TouchArray[o].x)+d.shortToStr(d.TouchArray[o].y),2==d.TouchArray[o].f&&delete d.TouchArray[o];3==d.State&&d.send(String.fromCharCode(0,d.InputType.TOUCH)+d.shortToStr(5+a.length)+String.fromCharCode(2)+a),0==Object.keys(d.TouchArray).length&&null!=d.touchtimer&&(clearInterval(d.touchtimer),d.touchtimer=null)},d.SendMouseMsg=function(e,t){var n,o,a,r,s,i;3==d.State&&null!=e&&null!=d.Canvas&&(t=t||window.event,s=d.Canvas.canvas.height/d.CanvasId.clientHeight,r=d.Canvas.canvas.width/d.CanvasId.clientWidth,i=d.GetPositionOfControl(d.Canvas.canvas),n=(t.pageX-i[0])*r,o=(t.pageY-i[1])*s,t.addx&&(n+=t.addx),t.addy&&(o+=t.addy),0<=n&&n<=d.Canvas.canvas.width&&0<=o&&o<=d.Canvas.canvas.height&&(r=a=0,e==d.KeyAction.UP||e==d.KeyAction.DOWN?t.which?a=1==t.which?d.MouseButton.LEFT:2==t.which?d.MouseButton.MIDDLE:d.MouseButton.RIGHT:t.button&&(a=0==t.button?d.MouseButton.LEFT:1==t.button?d.MouseButton.MIDDLE:d.MouseButton.RIGHT):e==d.KeyAction.SCROLL&&(t.detail?r=120*t.detail*-1:t.wheelDelta&&(r=3*t.wheelDelta)),!0===d.SwapMouse&&(a==d.MouseButton.LEFT?a=d.MouseButton.RIGHT:a==d.MouseButton.RIGHT&&(a=d.MouseButton.LEFT)),i="",i=e==d.KeyAction.DBLCLICK?String.fromCharCode(0,d.InputType.MOUSE,0,10,0,136,n/256&255,255&n,o/256&255,255&o):e==d.KeyAction.SCROLL?(t=r<(t=s=0)?(s=255-(Math.abs(r)>>8),255-(255&Math.abs(r))):(s=r>>8,255&r),String.fromCharCode(0,d.InputType.MOUSE,0,12,0,0,n/256&255,255&n,o/256&255,255&o,s,t)):String.fromCharCode(0,d.InputType.MOUSE,0,10,0,e==d.KeyAction.DOWN?a:2*a&255,n/256&255,255&n,o/256&255,255&o),d.Action==d.KeyAction.NONE?0==d.Alternate||d.ipad?(d.send(i),d.Alternate=1):d.Alternate=0:d.send(i)))},d.GetDisplayNumbers=function(){d.send(String.fromCharCode(0,11,0,4))},d.SetDisplay=function(e){d.send(String.fromCharCode(0,12,0,6,e>>8,255&e))},d.intToStr=function(e){return String.fromCharCode(e>>24&255,e>>16&255,e>>8&255,255&e)},d.shortToStr=function(e){return String.fromCharCode(e>>8&255,255&e)},d.onResize=function(){0!=d.ScreenWidth&&0!=d.ScreenHeight&&(d.Canvas.canvas.width==d.ScreenWidth&&d.Canvas.canvas.height==d.ScreenHeight||(d.FirstDraw&&(d.Canvas.canvas.width=d.ScreenWidth,d.Canvas.canvas.height=d.ScreenHeight,d.Canvas.fillRect(0,0,d.ScreenWidth,d.ScreenHeight),null!=d.onScreenSizeChange&&d.onScreenSizeChange(d,d.ScreenWidth,d.ScreenHeight,d.CanvasId)),d.FirstDraw=!1,1<d.debugmode&&console.log("onResize: "+d.ScreenWidth+" x "+d.ScreenHeight)))},d.xxMouseInputGrab=!1,d.xxKeyInputGrab=!1,d.xxMouseMove=function(e){return 3==d.State&&d.SendMouseMsg(d.KeyAction.NONE,e),e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),!1},d.xxMouseUp=function(e){return 3==d.State&&d.SendMouseMsg(d.KeyAction.UP,e),e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),!1},d.xxMouseDown=function(e){return 3==d.State&&d.SendMouseMsg(d.KeyAction.DOWN,e),e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),!1},d.xxMouseDblClick=function(e){return 3==d.State&&d.SendMouseMsg(d.KeyAction.DBLCLICK,e),e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),!1},d.xxDOMMouseScroll=function(e){return 3!=d.State||(d.SendMouseMsg(d.KeyAction.SCROLL,e),!1)},d.xxMouseWheel=function(e){return 3!=d.State||(d.SendMouseMsg(d.KeyAction.SCROLL,e),!1)},d.xxKeyUp=function(e){return"Dead"!=e.key&&3==d.State&&("string"==typeof e.key&&1==e.key.length&&1!=e.ctrlKey&&1!=e.altKey&&(0==d.remoteKeyMap||0<d.debugmode)?d.SendKeyUnicode(d.KeyAction.UP,e.key.charCodeAt(0)):d.SendKeyMsg(d.KeyAction.UP,e)),e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),!1},d.xxKeyDown=function(e){if("Dead"!=e.key&&3==d.State&&("string"!=typeof e.key||1!=e.key.length||1==e.ctrlKey||1==e.altKey||!(0==d.remoteKeyMap||0<d.debugmode)))return d.SendKeyMsg(d.KeyAction.DOWN,e),e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),!1},d.xxKeyPress=function(e){return"Dead"!=e.key&&3==d.State&&"string"==typeof e.key&&1==e.key.length&&1!=e.ctrlKey&&1!=e.altKey&&(0==d.remoteKeyMap||0<d.debugmode)&&d.SendKeyUnicode(d.KeyAction.DOWN,e.key.charCodeAt(0)),e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),!1},d.handleKeys=function(e){return 1!=d.stopInput&&3==desktop.State&&d.xxKeyPress(e)},d.handleKeyUp=function(e){return 1!=d.stopInput&&3==desktop.State&&(d.firstUpKeys.length<5&&(d.firstUpKeys.push(e.keyCode),5==d.firstUpKeys.length&&("16,17,91,91,16"!=(t=d.firstUpKeys.join(","))&&"16,17,18,91,92"!=t||(d.stopInput=!0))),d.xxKeyUp(e));var t},d.handleKeyDown=function(e){return 1!=d.stopInput&&3==desktop.State&&d.xxKeyDown(e)},d.handleReleaseKeys=function(){var e,t=JSON.parse(JSON.stringify(d.pressedKeys));for(e in t)d.SendKeyMsgKC(d.KeyAction.UP,t[e])},d.mousedblclick=function(e){return 1!=d.stopInput&&d.xxMouseDblClick(e)},d.mousedown=function(e){return 1!=d.stopInput&&d.xxMouseDown(e)},d.mouseup=function(e){return 1!=d.stopInput&&d.xxMouseUp(e)},d.mousemove=function(e){return 1!=d.stopInput&&d.xxMouseMove(e)},d.mousewheel=function(e){return 1!=d.stopInput&&d.xxMouseWheel(e)},d.xxMsTouchEvent=function(e){var t,n,o,a;if(4!=e.originalEvent.pointerType)return e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),"MSPointerDown"==e.type||"MSPointerMove"==e.type||"MSPointerUp"==e.type?(t=0,n=e.originalEvent.pointerId%256,o=e.offsetX*(Canvas.canvas.width/d.CanvasId.clientWidth),a=e.offsetY*(Canvas.canvas.height/d.CanvasId.clientHeight),"MSPointerDown"==e.type?t=65542:"MSPointerMove"==e.type?t=131078:"MSPointerUp"==e.type&&(t=262144),d.TouchArray[n]||(d.TouchArray[n]={x:o,y:a}),d.SendTouchMsg2(n,t),"MSPointerUp"==e.type&&delete d.TouchArray[n]):alert(e.type),!0},d.xxTouchStart=function(e){if(3==d.State)if(e.preventDefault&&e.preventDefault(),0==d.touchenabled||1==d.touchenabled){var t;1<e.originalEvent.touches.length||(t=e.originalEvent.touches[0],e.which=1,d.LastX=e.pageX=t.pageX,d.LastY=e.pageY=t.pageY,d.SendMouseMsg(KeyAction.DOWN,e))}else{var n,o,a=d.GetPositionOfControl(Canvas.canvas);for(n in e.originalEvent.changedTouches)e.originalEvent.changedTouches[n].identifier&&(o=e.originalEvent.changedTouches[n].identifier%256,d.TouchArray[o]||(d.TouchArray[o]={x:(e.originalEvent.touches[n].pageX-a[0])*(Canvas.canvas.width/d.CanvasId.clientWidth),y:(e.originalEvent.touches[n].pageY-a[1])*(Canvas.canvas.height/d.CanvasId.clientHeight),f:1}));0<Object.keys(d.TouchArray).length&&null==touchtimer&&(d.touchtimer=setInterval(function(){d.SendTouchMsg2(256,0)},50))}},d.xxTouchMove=function(e){if(3==d.State)if(e.preventDefault&&e.preventDefault(),0==d.touchenabled||1==d.touchenabled){var t;1<e.originalEvent.touches.length||(t=e.originalEvent.touches[0],e.which=1,d.LastX=e.pageX=t.pageX,d.LastY=e.pageY=t.pageY,d.SendMouseMsg(d.KeyAction.NONE,e))}else{var n,o,a=d.GetPositionOfControl(Canvas.canvas);for(n in e.originalEvent.changedTouches)e.originalEvent.changedTouches[n].identifier&&(o=e.originalEvent.changedTouches[n].identifier%256,d.TouchArray[o]&&(d.TouchArray[o].x=(e.originalEvent.touches[n].pageX-a[0])*(d.Canvas.canvas.width/d.CanvasId.clientWidth),d.TouchArray[o].y=(e.originalEvent.touches[n].pageY-a[1])*(d.Canvas.canvas.height/d.CanvasId.clientHeight)))}},d.xxTouchEnd=function(e){if(3==d.State)if(e.preventDefault&&e.preventDefault(),0==d.touchenabled||1==d.touchenabled)1<e.originalEvent.touches.length||(e.which=1,e.pageX=LastX,e.pageY=LastY,d.SendMouseMsg(KeyAction.UP,e));else for(var t in e.originalEvent.changedTouches)e.originalEvent.changedTouches[t].identifier&&(t=e.originalEvent.changedTouches[t].identifier%256,d.TouchArray[t]&&(d.TouchArray[t].f=2))},d.GrabMouseInput=function(){var e;1!=d.xxMouseInputGrab&&((e=d.CanvasId).onmousemove=d.xxMouseMove,e.onmouseup=d.xxMouseUp,e.onmousedown=d.xxMouseDown,e.touchstart=d.xxTouchStart,e.touchmove=d.xxTouchMove,e.touchend=d.xxTouchEnd,e.MSPointerDown=d.xxMsTouchEvent,e.MSPointerMove=d.xxMsTouchEvent,e.MSPointerUp=d.xxMsTouchEvent,navigator.userAgent.match(/mozilla/i)?e.DOMMouseScroll=d.xxDOMMouseScroll:e.onmousewheel=d.xxMouseWheel,d.xxMouseInputGrab=!0)},d.UnGrabMouseInput=function(){var e;0!=d.xxMouseInputGrab&&((e=d.CanvasId).onmousemove=null,e.onmouseup=null,e.onmousedown=null,e.touchstart=null,e.touchmove=null,e.touchend=null,e.MSPointerDown=null,e.MSPointerMove=null,e.MSPointerUp=null,navigator.userAgent.match(/mozilla/i)?e.DOMMouseScroll=null:e.onmousewheel=null,d.xxMouseInputGrab=!1)},d.GrabKeyInput=function(){1!=d.xxKeyInputGrab&&(document.onkeyup=d.xxKeyUp,document.onkeydown=d.xxKeyDown,document.onkeypress=d.xxKeyPress,d.xxKeyInputGrab=!0)},d.UnGrabKeyInput=function(){0!=d.xxKeyInputGrab&&(document.onkeyup=null,document.onkeydown=null,document.onkeypress=null,d.xxKeyInputGrab=!1)},d.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},d.crotX=function(e,t){return 0==d.rotation?e:1==d.rotation?t:2==d.rotation?d.Canvas.canvas.width-e:3==d.rotation?d.Canvas.canvas.height-t:void 0},d.crotY=function(e,t){return 0==d.rotation?t:1==d.rotation?d.Canvas.canvas.width-e:2==d.rotation?d.Canvas.canvas.height-t:3==d.rotation?e:void 0},d.rotX=function(e,t){return 0==d.rotation||1==d.rotation?e:2==d.rotation?e-d.Canvas.canvas.width:3==d.rotation?e-d.Canvas.canvas.height:void 0},d.rotY=function(e,t){return 0==d.rotation||3==d.rotation?t:1==d.rotation?t-d.Canvas.canvas.width:2==d.rotation?t-d.Canvas.canvas.height:void 0},d.tcanvas=null,d.setRotation=function(e){for(;e<0;)e+=4;var t=e%4;if(t==d.rotation)return!0;var n=d.Canvas.canvas.width,o=d.Canvas.canvas.height;1!=d.rotation&&3!=d.rotation||(n=d.Canvas.canvas.height,o=d.Canvas.canvas.width),null==d.tcanvas&&(d.tcanvas=document.createElement("canvas"));var a=d.tcanvas.getContext("2d");return a.setTransform(1,0,0,1,0,0),a.canvas.width=n,a.canvas.height=o,a.rotate(-90*d.rotation*Math.PI/180),0==d.rotation&&a.drawImage(d.Canvas.canvas,0,0),1==d.rotation&&a.drawImage(d.Canvas.canvas,-d.Canvas.canvas.width,0),2==d.rotation&&a.drawImage(d.Canvas.canvas,-d.Canvas.canvas.width,-d.Canvas.canvas.height),3==d.rotation&&a.drawImage(d.Canvas.canvas,0,-d.Canvas.canvas.height),0!=d.rotation&&2!=d.rotation||(d.Canvas.canvas.height=n,d.Canvas.canvas.width=o),1!=d.rotation&&3!=d.rotation||(d.Canvas.canvas.height=o,d.Canvas.canvas.width=n),d.Canvas.setTransform(1,0,0,1,0,0),d.Canvas.rotate(90*t*Math.PI/180),d.rotation=t,d.Canvas.drawImage(d.tcanvas,d.rotX(0,0),d.rotY(0,0)),d.ScreenWidth=d.Canvas.canvas.width,d.ScreenHeight=d.Canvas.canvas.height,null!=d.onScreenSizeChange&&(console.log("s4",d.ScreenWidth,d.ScreenHeight),d.onScreenSizeChange(d,d.ScreenWidth,d.ScreenHeight,d.CanvasId)),!0},d.StartRecording=function(){null==d.recordedData&&d.CanvasId.toBlob(function(e){var s=new FileReader;s.readAsArrayBuffer(e),s.onload=function(e){for(var t="",n=new Uint8Array(s.result),o=n.byteLength,a=0;a<o;a++)t+=String.fromCharCode(n[a]);d.recordedData=[],d.recordedStart=Date.now(),d.recordedSize=0,d.recordedData.push(S(1,0,JSON.stringify({magic:"MeshCentralRelaySession",ver:1,time:(new Date).toLocaleString(),protocol:2}))),d.recordedData.push(S(2,1,d.shortToStr(7)+d.shortToStr(8)+d.shortToStr(d.ScreenWidth)+d.shortToStr(d.ScreenHeight)));var r=8+t.length;65e3<r?d.recordedData.push(S(2,1,d.shortToStr(27)+d.shortToStr(8)+d.intToStr(r)+d.shortToStr(3)+d.shortToStr(0)+d.shortToStr(0)+d.shortToStr(0)+t)):d.recordedData.push(S(2,1,d.shortToStr(3)+d.shortToStr(r)+d.shortToStr(0)+d.shortToStr(0)+t))}})},d.StopRecording=function(){if(null!=d.recordedData){var e=d.recordedData;return e.push(S(3,0,"MeshCentralMCREC")),delete d.recordedData,delete d.recordedStart,delete d.recordedSize,e}},d.MuchTheSame=function(e,t){return Math.abs(e-t)<4},d.Debug=function(e){console.log(e)},d.getIEVersion=function(){var e,t=-1;return"Microsoft Internet Explorer"==navigator.appName&&(e=navigator.userAgent,null!=new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})").exec(e)&&(t=parseFloat(RegExp.$1))),t},d.haltEvent=function(e){return e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),!1},d}