mirror of
https://github.com/antos-rde/antosdk-apps.git
synced 2024-12-27 04:28:21 +01:00
1 line
11 KiB
JavaScript
1 line
11 KiB
JavaScript
(function(){var t,e,n;(t=class t extends this.OS.GUI.BasicDialog{constructor(){super("ConnectionDialog",t.scheme)}main(){return super.main(),this.find("bbp").data=[{text:"16 bits",value:16,selected:!0},{text:"32 bits",value:32}],this.find("compression").data=[{text:"No compression",value:0},{text:"JPEG",value:1},{text:"zLib",value:2},{text:"JPEG & zLib",value:3,selected:!0}],this.find("jq").value=40,this.find("bt-ok").onbtclick=t=>{var e;if(this.handle)return e={wvnc:this.find("txtWVNC").value,server:this.find("txtServer").value,bbp:this.find("bbp").selectedItem.data.value,flag:this.find("compression").selectedItem.data.value,quality:this.find("jq").value},this.handle(e),this.quit()},this.find("bt-cancel").onbtclick=t=>this.quit()}}).scheme='<afx-app-window width=\'350\' height=\'270\'>\n <afx-hbox>\n <div data-width="5"></div>\n <afx-vbox>\n <afx-label text="__(WVNC Websocket)" data-height="25" class="header" ></afx-label>\n <input data-height="25" data-id="txtWVNC" value="wss://localhost/wvnc"></input>\n <afx-label text="__(VNC Server)" data-height="25" class="header" ></afx-label>\n <input data-height="25" data-id="txtServer" value="192.168.1.10:5900"></input>\n <div data-height="5"></div>\n <afx-label text="__(Bits per pixel)" data-height="25" class="header" ></afx-label>\n <afx-list-view dropdown = "true" data-id ="bbp" data-height="25" ></afx-list-view>\n <div data-height="5"></div>\n <afx-label text="__(Compression)" data-height="25" class="header" ></afx-label>\n <afx-list-view dropdown = "true" data-id ="compression" data-height="25" ></afx-list-view>\n <div data-height="5"></div>\n <afx-label text="__(JPEG quality)" data-height="25" class="header" ></afx-label>\n <afx-slider data-id ="jq" data-height="25" ></afx-slider>\n <afx-hbox data-height = \'30\'>\n <div style=\' text-align:right;\'>\n <afx-button data-id = "bt-ok" text = "__(Connect)"></afx-button>\n <afx-button data-id = "bt-cancel" text = "__(Cancel)"></afx-button>\n </div>\n <div data-width="5"></div>\n </afx-hbox>\n </afx-vbox>\n <div data-width="5"></div>\n </afx-hbox>\n</afx-app-window>\n',(e=class t extends this.OS.GUI.BasicDialog{constructor(){super("CredentialDialog",t.scheme)}main(){return this.find("bt-ok").onbtclick=()=>{var t;return this.handle?(t={username:this.find("txtUser").value,password:this.find("txtPass").value},this.handle(t),this.quit()):this.quit()},this.find("bt-cancel").onbtclick=()=>this.quit()}}).scheme='<afx-app-window width=\'350\' height=\'150\'>\n <afx-vbox>\n <afx-label text="__(Username)" data-height="25" class="header" ></afx-label>\n <input data-height="30" data-id="txtUser"></input>\n <afx-label text="__(Password)" data-height="25" class="header" ></afx-label>\n <input type="password" data-height="30" data-id="txtPass"></input>\n <afx-hbox data-height = \'30\'>\n <div style=\' text-align:right;\'>\n <afx-button data-id = "bt-ok" text = "__(Ok)"></afx-button>\n <afx-button data-id = "bt-cancel" text = "__(Cancel)"></afx-button>\n </div>\n <div data-width="5"></div>\n </afx-hbox>\n </afx-vbox>\n</afx-app-window>\n',n=class extends this.OS.application.BaseApplication{constructor(t){super("RemoteDesktop",t)}main(){return this.canvas=this.find("screen"),this.container=this.find("container"),this.client=new WVNC({element:this.canvas,worker:`${this._api.handle.get}/${this.meta().path}/decoder.js`}),this.client.onerror=t=>(this.error(t),this.showConnectionDialog()),this.client.onresize=()=>this.setScale(),this.client.onpassword=()=>new Promise((t,e)=>this.openDialog("PromptDialog",{title:__("VNC password"),label:__("VNC password"),value:"!x$@n9ph",type:"password"}).then((function(e){return t(e)}))),this.client.oncredential=()=>new Promise((t,n)=>this.openDialog(new e,{title:__("User credential")}).then((function(e){return t(e.username,e.password)}))),this.on("resize",t=>this.setScale()),this.on("focus",t=>$(this.canvas).focus()),this.client.init().then(()=>this.showConnectionDialog())}setScale(){var t,e,n,a;if(this.client&&this.client.resolution)return a=$(this.container).width(),t=$(this.container).height(),(e=a/this.client.resolution.w)>(n=t/this.client.resolution.h)?this.client.setScale(n):this.client.setScale(e)}menu(){return[{text:"__(Connection)",nodes:[{text:"__(New Connection)",dataid:this.name+"-new"},{text:"__(Disconnect)",dataid:this.name+"-close"}],onchildselect:t=>this.actionConnection()}]}actionConnection(t){return this.client&&this.client.disconnect(),this.showConnectionDialog()}showConnectionDialog(){return this.openDialog(new t,{title:__("Connection")}).then(t=>(this.client.ws=t.wvnc,console.log(t),this.client.connect(t.server,t)))}cleanup(){if(this.client)return this.client.disconnect()}},this.OS.register("RemoteDesktop",n)}).call(this),function(){var t;t=function(){function t(t){var e,n;this.socket=void 0,this.ws=void 0,this.canvas=void 0,n="decoder.js",this.scale=1,t.ws&&(this.ws=t.ws),this.canvas=t.element,"string"==typeof this.canvas&&(this.canvas=document.getElementById(this.canvas)),t.worker&&(n=t.worker),this.decoder=new Worker(n),this.enableEvent=!0,(e=this).mouseMask=0,this.decoder.onmessage=function(t){return e.process(t.data)}}return t.prototype.init=function(){var t;return t=this,new Promise((function(e,n){return t.canvas?($(t.canvas).attr("tabindex","1"),t.initInputEvent(),e()):n("Canvas is not set")}))},t.prototype.initInputEvent=function(){var t,e,n,a;if((n=this).canvas&&(e=function(t){var e;return e=n.canvas.getBoundingClientRect(),{x:Math.floor((t.clientX-e.left)/n.scale),y:Math.floor((t.clientY-e.top)/n.scale)}},a=function(t){var a;if(n.enableEvent)return a=e(t),n.sendPointEvent(a.x,a.y,n.mouseMask)},n.canvas))return n.canvas.oncontextmenu=function(t){return t.preventDefault(),!1},n.canvas.onmousemove=function(t){return a(t)},n.canvas.onmousedown=function(t){var e;return e=1<<t.button,n.mouseMask=n.mouseMask|e,a(t)},n.canvas.onmouseup=function(t){var e;return e=1<<t.button,n.mouseMask=n.mouseMask&~e,a(t)},n.canvas.onkeydown=n.canvas.onkeyup=function(t){var e;switch(t.keyCode){case 8:e=65288;break;case 9:e=65417;break;case 13:e=65293;break;case 27:e=65307;break;case 46:e=65535;break;case 38:e=65362;break;case 40:e=65364;break;case 37:e=65361;break;case 39:e=65363;break;case 91:e=65511;break;case 93:e=65512;break;case 16:e=65505;break;case 17:e=65507;break;case 18:e=65513;break;case 20:e=65509;break;case 113:e=65471;break;case 112:e=65470;break;case 114:e=65472;break;case 115:e=65473;break;case 116:e=65474;break;case 117:e=65475;break;case 118:e=65476;break;case 119:e=65477;break;case 120:e=65478;break;case 121:e=65479;break;case 122:e=65480;break;case 123:e=65481;break;default:e=t.key.charCodeAt(0)}if(t.preventDefault(),e)return"keydown"===t.type?n.sendKeyEvent(e,1):"keyup"===t.type?n.sendKeyEvent(e,0):void 0},this.canvas.addEventListener("wheel",(function(t){var a;if(n.enableEvent)return a=e(t),t.preventDefault(),t.deltaY<0?(n.sendPointEvent(a.x,a.y,8),void n.sendPointEvent(a.x,a.y,0)):(n.sendPointEvent(a.x,a.y,16),n.sendPointEvent(a.x,a.y,0))})),this.canvas.onpaste=function(t){var e;if(n.enableEvent)return e=void 0,window.clipboardData&&window.clipboardData.getData?e=window.clipboardData.getData("Text"):t.clipboardData&&t.clipboardData.getData&&(e=t.clipboardData.getData("text/plain")),!!e&&(t.preventDefault(),n.sendTextAsClipboard(e))},t=function(t){if(console.log("unload"),n.socket)return n.socket.close()},window.addEventListener("unload",t),window.addEventListener("beforeunload",t)},t.prototype.initCanvas=function(t,e,n){return this.depth=n,this.canvas.width=t,this.canvas.height=e,this.resolution={w:t,h:e,depth:this.depth},this.decoder.postMessage(this.resolution),this.canvas.style.cursor="none",this.setScale(this.scale)},t.prototype.process=function(t){var e,n,a;if(this.socket)return n=new Uint8Array(t.pixels),(a=(e=this.canvas.getContext("2d",{alpha:!1})).createImageData(t.w,t.h)).data.set(n),e.putImageData(a,t.x,t.y)},t.prototype.setScale=function(t){if(this.scale=t,this.canvas)return this.canvas.style.transformOrigin="0 0",this.canvas.style.transform="scale("+t+")"},t.prototype.connect=function(t,e){var n;if((n=this).socket&&this.socket.close(),this.ws)return this.socket=new WebSocket(this.ws),this.socket.binaryType="arraybuffer",this.socket.onopen=function(){return console.log("socket opened"),n.initConnection(t,e)},this.socket.onmessage=function(t){return n.consume(t)},this.socket.onclose=function(){return n.socket=null,n.canvas.style.cursor="auto",n.canvas&&n.resolution&&n.canvas.getContext("2d").clearRect(0,0,n.resolution.w,n.resolution.h),console.log("socket closed")}},t.prototype.disconnect=function(){if(this.socket)return this.socket.close()},t.prototype.initConnection=function(t,e){var n;return(n=new Uint8Array(t.length+3))[0]=32,n[1]=2,n[2]=50,e&&(e.bbp&&(n[0]=e.bbp),e.flag&&(n[1]=e.flag),e.quality&&(n[2]=e.quality)),n.set((new TextEncoder).encode(t),3),this.socket.send(this.buildCommand(1,n))},t.prototype.sendPointEvent=function(t,e,n){var a;if(this.socket)return(a=new Uint8Array(5))[0]=255&t,a[1]=t>>8,a[2]=255&e,a[3]=e>>8,a[4]=n,this.socket.send(this.buildCommand(5,a))},t.prototype.sendKeyEvent=function(t,e){var n;if(this.socket&&this.enableEvent)return(n=new Uint8Array(3))[0]=255&t,n[1]=t>>8,n[2]=e,this.socket.send(this.buildCommand(6,n))},t.prototype.buildCommand=function(t,e){var n,a;switch(a=void 0,typeof e){case"string":a=(new TextEncoder).encode(e);break;case"number":a=new Uint8Array([e]);break;default:a=e}return(n=new Uint8Array(a.length+3))[0]=t,n[2]=a.length>>8,n[1]=15&a.length,n.set(a,3),n.buffer},t.prototype.oncopy=function(t){return console.log("Get clipboard text: "+t)},t.prototype.onpassword=function(){return new Promise((function(t,e){return e("onpassword is not implemented")}))},t.prototype.sendTextAsClipboard=function(t){if(this.socket)return console.log("send ",t),this.socket.send(this.buildCommand(7,t))},t.prototype.oncredential=function(){return new Promise((function(t,e){return e("oncredential is not implemented")}))},t.prototype.onerror=function(t){return console.log("Error",t)},t.prototype.onresize=function(){return console.log("resize")},t.prototype.consume=function(t){var e,n,a,i,s,o,r;switch(e=(n=new Uint8Array(t.data))[0],o=this,e){case 254:return n=n.subarray(1,n.length-1),a=new TextDecoder("utf-8"),this.onerror(a.decode(n));case 129:return console.log("Request for password"),this.enableEvent=!1,this.onpassword().then((function(t){return o.socket.send(o.buildCommand(2,t)),o.enableEvent=!0}));case 130:return console.log("Request for login"),this.enableEvent=!1,this.oncredential().then((function(t,e){var n;return(n=new Uint8Array(t.length+e.length+1)).set((new TextEncoder).encode(t),0),n.set(["\0"],t.length),n.set((new TextEncoder).encode(e),t.length+1),o.socket.send(o.buildCommand(3,n)),o.enableEvent=!0}));case 131:return r=n[1]|n[2]<<8,s=n[3]|n[4]<<8,i=n[5],this.initCanvas(r,s,i),this.socket.send(this.buildCommand(4,1)),this.onresize();case 132:return this.decoder.postMessage(n.buffer,[n.buffer]);case 133:return n=n.subarray(1),a=new TextDecoder("utf-8"),this.oncopy(a.decode(n)),this.socket.send(this.buildCommand(4,1));default:return console.log(e)}},t}(),window.WVNC=t}.call(this); |