AnyBot/mobile/novnc.js

9 lines
184 KiB
JavaScript
Raw Permalink Normal View History

People watch and help on the bots' computer through VNC (noVNC), carried by the account server The core: the bot works the computer; a person watches it like a colleague, and takes over when it needs them. VNC is made for that (only what changed, every mouse move and key, touch on phones), so the pictures sent one by one go, and with them their own input path. - vnc.rs: a VNC proxy to the box's x11vnc through one docker exec (a Python bridge that ends with either side). It signs in to the box with the box's own password (its VNC_PASSWORD) and offers the viewer no password, so the password never leaves the brain. The person's clicks and keys make the bot's steps wait until 8 s after they stop; text typed in the viewer's box (any language) is pasted in the box. - Account server: /screen (the viewer page) and /novnc.js (noVNC 1.6.0, MPL-2.0, bundled); /relay/vnc/<host> takes the browser's WebSocket (account session, or a 10-minute ticket the app asks for with POST /relay/screen-ticket; owners and admins) and carries it over that AnyBot's lasting connection (vopen / vdata / vtext / vclose). Both ends of that connection wait 2 ms instead of 40 ms to read while things move: a request and its answer took up to 160 ms more than needed. - Phone page: 看 Bot 的電腦 and 接管 open the viewer page (also on the local network: /api/vnc on the AnyBot's own phone server). This Mac's own screen moved to the ⋯ menu. - Mac app: 看畫面 opens the viewer in the browser (a screen of a brain: the brain's computer by ticket; else this computer's box, noVNC straight from it). The in-app picture viewer, the live JPEG stream, the person's click/move/scroll/key endpoints and the input shell are gone. - Opening a Mac app uses LaunchServices (`open -a`): agent-desktop's launch waited on the window through accessibility and failed without 輔助使用 now and then. Measured on this Mac (made-up account, local relay + headless brain + the real box): viewer signed in in 0.4–0.7 s, a request and its answer through relay + brain + box 25–58 ms median; headless Chrome shows the desktop live in /screen. remote_e2e 28/28 ×2, 149 unit tests, relay 11. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 15:05:44 +00:00
/* noVNC 1.6.0 (https://github.com/novnc/noVNC), core library under the Mozilla Public License 2.0
(https://mozilla.org/MPL/2.0/; source: the tag v1.6.0, core/rfb.js and what it imports).
Bundled for AnyBot with: esbuild core/rfb.js --bundle --minify --format=esm --target=es2022 */
function ji(i){return i>>>0}function it(i){return i|0}var qi="warn",L=()=>{},V=()=>{},W=()=>{},U=()=>{};function Zr(i){if(typeof i>"u"?i=qi:qi=i,L=V=W=U=()=>{},typeof window.console<"u")switch(i){case"debug":L=console.debug.bind(window.console);case"info":V=console.info.bind(window.console);case"warn":W=console.warn.bind(window.console);case"error":U=console.error.bind(window.console);case"none":break;default:throw new window.Error("invalid logging type '"+i+"'")}}Zr();function Bt(i,t=!1){try{return decodeURIComponent(escape(i))}catch(e){if(e instanceof URIError&&t)return i;throw e}}function he(i){return unescape(encodeURIComponent(i))}var Pe={toBase64Table:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".split(""),base64Pad:"=",encode(i){"use strict";let t="",e=i.length,s=e%3;for(let n=0;n<e-2;n+=3)t+=this.toBase64Table[i[n]>>2],t+=this.toBase64Table[((i[n]&3)<<4)+(i[n+1]>>4)],t+=this.toBase64Table[((i[n+1]&15)<<2)+(i[n+2]>>6)],t+=this.toBase64Table[i[n+2]&63];let r=e-s;return s===2?(t+=this.toBase64Table[i[r]>>2],t+=this.toBase64Table[((i[r]&3)<<4)+(i[r+1]>>4)],t+=this.toBase64Table[(i[r+1]&15)<<2],t+=this.toBase64Table[64]):s===1&&(t+=this.toBase64Table[i[r]>>2],t+=this.toBase64Table[(i[r]&3)<<4],t+=this.toBase64Table[64],t+=this.toBase64Table[64]),t},toBinaryTable:[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,0,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1],decode(i,t=0){let e=i.indexOf("=")-t;e<0&&(e=i.length-t);let s=(e>>2)*3+Math.floor(e%4/1.5),r=new Array(s),n=0,a=0;for(let h=0,_=t;_<i.length;_++){let o=this.toBinaryTable[i.charCodeAt(_)&127],l=i.charAt(_)===this.base64Pad;if(o===-1){U("Illegal character code "+i.charCodeAt(_)+" at position "+_);continue}a=a<<6|o,n+=6,n>=8&&(n-=8,l||(r[h++]=a>>n&255),a&=(1<<n)-1)}if(n){let h=new Error("Corrupted base64 string");throw h.name="Base64-Error",h}return r}};var _i="ontouchstart"in document.documentElement||document.ontouchstart!==void 0||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0;window.addEventListener("touchstart",function i(){_i=!0,window.removeEventListener("touchstart",i,!1)},!1);var st=10*(window.devicePixelRatio||1),Ji=!1;try{let i=document.createElement("canvas");i.style.cursor='url("data:image/x-icon;base64,AAACAAEACAgAAAIAAgA4AQAAFgAAACgAAAAIAAAAEAAAAAEAIAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAD/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////AAAAAAAAAAAAAAAAAAAAAA==") 2 2, default',i.style.cursor.indexOf("url")===0?(V("Data URI scheme cursor supported"),Ji=!0):W("Data URI scheme cursor not supported")}catch(i){U("Data URI scheme cursor test exception: "+i)}var $i=Ji,Yr=!0;try{let i=document.createElement("div");i.style.visibility="hidden",i.style.overflow="scroll",document.body.appendChild(i);let t=document.createElement("div");i.appendChild(t);let e=i.offsetWidth-t.offsetWidth;i.parentNode.removeChild(i),Yr=e!=0}catch(i){U("Scrollbar test exception: "+i)}var fi=!1;async function jr(){if(!("VideoDecoder"in window))return!1;let i={codec:"avc1.42401f",codedWidth:1920,codedHeight:1080,optimizeForLatency:!0};if(!(await VideoDecoder.isConfigSupported(i)).supported)return!1;let e=new Uint8Array(Pe.decode("AAAAAWdCwBTZnpuAgICgAAADACAAAAZB4oVNAAAAAWjJYyyAAAABBgX//4HcRem95tlIt5Ys2CDZI+7veDI2NCAtIGNvcmUgMTY0IHIzMTA4IDMxZTE5ZjkgLSBILjI2NC9NUEVHLTQgQVZDIGNvZGVjIC0gQ29weWxlZnQgMjAwMy0yMDIzIC0gaHR0cDovL3d3dy52aWRlb2xhbi5vcmcveDI2NC5odG1sIC0gb3B0aW9uczogY2FiYWM9MCByZWY9NSBkZWJsb2NrPTE6MDowIGFuYWx5c2U9MHgxOjB4MTExIG1lPWhleCBzdWJtZT04IHBzeT0xIHBzeV9yZD0xLjAwOjAuMDAgbWl4ZWRfcmVmPTEgbWVfcm
`),this._sock.flush(),L("Sent ProtocolVersion: "+s),this._rfbInitState="Security"}_isSupportedSecurityType(t){return[Ir,hi,Pr,Hr,Yi,Ur,Nr,Or,Gr].includes(t)}_negotiateSecurity(){if(this._rfbVersion>=3.7){let t=this._sock.rQshift8();if(this._sock.rQwait("security type",t,1))return!1;if(t===0)return this._rfbInitState="SecurityReason",this._securityContext="no security types",this._securityStatus=1,!0;let e=this._sock.rQshiftBytes(t);L("Server security types: "+e),this._rfbAuthScheme=-1;for(let s of e)if(this._isSupportedSecurityType(s)){this._rfbAuthScheme=s;break}if(this._rfbAuthScheme===-1)return this._fail("Unsupported security types (types: "+e+")");this._sock.sQpush8(this._rfbAuthScheme),this._sock.flush()}else{if(this._sock.rQwait("security scheme",4))return!1;if(this._rfbAuthScheme=this._sock.rQshift32(),this._rfbAuthScheme==0)return this._rfbInitState="SecurityReason",this._securityContext="authentication scheme",this._securityStatus=1,!0}return this._rfbInitState="Authentication",L("Authenticating using scheme: "+this._rfbAuthScheme),!0}_handleSecurityReason(){if(this._sock.rQwait("reason length",4))return!1;let t=this._sock.rQshift32(),e="";if(t>0){if(this._sock.rQwait("reason",t,4))return!1;e=this._sock.rQshiftStr(t)}return e!==""?(this.dispatchEvent(new CustomEvent("securityfailure",{detail:{status:this._securityStatus,reason:e}})),this._fail("Security negotiation failed on "+this._securityContext+" (reason: "+e+")")):(this.dispatchEvent(new CustomEvent("securityfailure",{detail:{status:this._securityStatus}})),this._fail("Security negotiation failed on "+this._securityContext))}_negotiateXvpAuth(){return this._rfbCredentials.username===void 0||this._rfbCredentials.password===void 0||this._rfbCredentials.target===void 0?(this.dispatchEvent(new CustomEvent("credentialsrequired",{detail:{types:["username","password","target"]}})),!1):(this._sock.sQpush8(this._rfbCredentials.username.length),this._sock.sQpush8(this._rfbCredentials.target.length),this._sock.sQpushString(this._rfbCredentials.username),this._sock.sQpushString(this._rfbCredentials.target),this._sock.flush(),this._rfbAuthScheme=hi,this._negotiateAuthentication())}_negotiateVeNCryptAuth(){if(this._rfbVeNCryptState==0){if(this._sock.rQwait("vencrypt version",2))return!1;let t=this._sock.rQshift8(),e=this._sock.rQshift8();if(!(t==0&&e==2))return this._fail("Unsupported VeNCrypt version "+t+"."+e);this._sock.sQpush8(0),this._sock.sQpush8(2),this._sock.flush(),this._rfbVeNCryptState=1}if(this._rfbVeNCryptState==1){if(this._sock.rQwait("vencrypt ack",1))return!1;let t=this._sock.rQshift8();if(t!=0)return this._fail("VeNCrypt failure "+t);this._rfbVeNCryptState=2}if(this._rfbVeNCryptState==2){if(this._sock.rQwait("vencrypt subtypes length",1))return!1;let t=this._sock.rQshift8();if(t<1)return this._fail("VeNCrypt subtypes empty");this._rfbVeNCryptSubtypesLength=t,this._rfbVeNCryptState=3}if(this._rfbVeNCryptState==3){if(this._sock.rQwait("vencrypt subtypes",4*this._rfbVeNCryptSubtypesLength))return!1;let t=[];for(let e=0;e<this._rfbVeNCryptSubtypesLength;e++)t.push(this._sock.rQshift32());this._rfbAuthScheme=-1;for(let e of t)if(e!==Yi&&this._isSupportedSecurityType(e)){this._rfbAuthScheme=e;break}return this._rfbAuthScheme===-1?this._fail("Unsupported security types (types: "+t+")"):(this._sock.sQpush32(this._rfbAuthScheme),this._sock.flush(),this._rfbVeNCryptState=4,!0)}}_negotiatePlainAuth(){if(this._rfbCredentials.username===void 0||this._rfbCredentials.password===void 0)return this.dispatchEvent(new CustomEvent("credentialsrequired",{detail:{types:["username","password"]}})),!1;let t=he(this._rfbCredentials.username),e=he(this._rfbCredentials.password);return this._sock.sQpush32(t.length),this._sock.sQpush32(e.length),this._sock.sQpushString(t),this._sock.sQpushString(e),this._sock.flush(),this._rfbInitState="SecurityResult",!0}_negotiateStdVNCAuth(){if(this._sock.rQwait("auth challenge",16))return!1;if(this._rfbCredentials.password===void 0)return this.dispatchEvent(new CustomEvent("credentialsrequired",{detail:{types:["password"]}})),!1;let t=Array.p
`,`
`),this.dispatchEvent(new CustomEvent("clipboard",{detail:{text:_}}))}}else return this._fail("Unexpected action in extended clipboard message: "+r)}return!0}_handleServerFenceMsg(){if(this._sock.rQwait("ServerFence header",8,1))return!1;this._sock.rQskipBytes(3);let t=this._sock.rQshift32(),e=this._sock.rQshift8();if(this._sock.rQwait("ServerFence payload",e,9))return!1;e>64&&(W("Bad payload length ("+e+") in fence response"),e=64);let s=this._sock.rQshiftStr(e);return this._supportsFence=!0,t&1<<31?(t&=3,i.messages.clientFence(this._sock,t,s),!0):this._fail("Unexpected fence response")}_handleXvpMsg(){if(this._sock.rQwait("XVP version and message",3,1))return!1;this._sock.rQskipBytes(1);let t=this._sock.rQshift8(),e=this._sock.rQshift8();switch(e){case 0:U("XVP operation failed");break;case 1:this._rfbXvpVer=t,V("XVP extensions enabled (version "+this._rfbXvpVer+")"),this._setCapability("power",!0);break;default:this._fail("Illegal server XVP message (msg: "+e+")");break}return!0}_normalMsg(){let t;this._FBU.rects>0?t=0:t=this._sock.rQshift8();let e,s;switch(t){case 0:return s=this._framebufferUpdate(),s&&!this._enabledContinuousUpdates&&i.messages.fbUpdateRequest(this._sock,!0,0,0,this._fbWidth,this._fbHeight),s;case 1:return this._handleSetColourMapMsg();case 2:return L("Bell"),this.dispatchEvent(new CustomEvent("bell",{detail:{}})),!0;case 3:return this._handleServerCutText();case 150:return e=!this._supportsContinuousUpdates,this._supportsContinuousUpdates=!0,this._enabledContinuousUpdates=!1,e&&(this._enabledContinuousUpdates=!0,this._updateContinuousUpdates(),V("Enabling continuous updates.")),!0;case 248:return this._handleServerFenceMsg();case 250:return this._handleXvpMsg();default:return this._fail("Unexpected server message (type "+t+")"),L("sock.rQpeekBytes(30): "+this._sock.rQpeekBytes(30)),!0}}_framebufferUpdate(){if(this._FBU.rects===0){if(this._sock.rQwait("FBU header",3,1))return!1;if(this._sock.rQskipBytes(1),this._FBU.rects=this._sock.rQshift16(),this._display.pending())return this._flushing=!0,this._display.flush().then(()=>{this._flushing=!1,this._sock.rQwait("message",1)||this._handleMessage()}),!1}for(;this._FBU.rects>0;){if(this._FBU.encoding===null){if(this._sock.rQwait("rect header",12))return!1;this._FBU.x=this._sock.rQshift16(),this._FBU.y=this._sock.rQshift16(),this._FBU.width=this._sock.rQshift16(),this._FBU.height=this._sock.rQshift16(),this._FBU.encoding=this._sock.rQshift32(),this._FBU.encoding>>=0}if(!this._handleRect())return!1;this._FBU.rects--,this._FBU.encoding=null}return this._display.flip(),!0}_handleRect(){switch(this._FBU.encoding){case R.pseudoEncodingLastRect:return this._FBU.rects=1,!0;case R.pseudoEncodingVMwareCursor:return this._handleVMwareCursor();case R.pseudoEncodingCursor:return this._handleCursor();case R.pseudoEncodingQEMUExtendedKeyEvent:return this._qemuExtKeyEventSupported=!0,!0;case R.pseudoEncodingDesktopName:return this._handleDesktopName();case R.pseudoEncodingDesktopSize:return this._resize(this._FBU.width,this._FBU.height),!0;case R.pseudoEncodingExtendedDesktopSize:return this._handleExtendedDesktopSize();case R.pseudoEncodingExtendedMouseButtons:return this._extendedPointerEventSupported=!0,!0;case R.pseudoEncodingQEMULedEvent:return this._handleLedEvent();default:return this._handleDataRect()}}_handleVMwareCursor(){let t=this._FBU.x,e=this._FBU.y,s=this._FBU.width,r=this._FBU.height;if(this._sock.rQwait("VMware cursor encoding",1))return!1;let n=this._sock.rQshift8();this._sock.rQshift8();let a,h=4;if(n==0){if(a=new Array(s*r*h),this._sock.rQwait("VMware cursor classic encoding",s*r*h*2,2))return!1;let o=new Array(s*r);for(let x=0;x<s*r;x++)o[x]=this._sock.rQshift32();let l=new Array(s*r);for(let x=0;x<s*r;x++)l[x]=this._sock.rQshift32();for(let x=0;x<s*r;x++)if(o[x]==0){let u=l[x],d=u>>8&255,X=u>>16&255,F=u>>24&255;a[x*h]=d,a[x*h+1]=X,a[x*h+2]=F,a[x*h+3]=255}else(o[x]&-256)==-256?l[x]==0?(a[x*h]=0,a[x*h+1]=0,a[x*h+2]=0,a[x*h+3]=0):(l[x]&-256,a[x*h]=0,a[x*h+1]=0,a[x*h+2]=0,a[x*h+3]=255):(a[x*h]=0,a[x*h+1]=0,a[x*h+2]=0,a[x*h+3]=255)}else if(n==1){if(th
`);let _=he(e[h]+"\0");r.push(_.length>>24&255,_.length>>16&255,_.length>>8&255,_.length&255);for(let o=0;o<_.length;o++)r.push(_.charCodeAt(o))}let n=s.deflate(new Uint8Array(r)),a=new Uint8Array(4+n.length);a.set(se.messages._buildExtendedClipboardFlags([ci],t)),a.set(n,4),se.messages.clientCutText(i,a,!0)},extendedClipboardNotify(i,t){let e=se.messages._buildExtendedClipboardFlags([Rt],t);se.messages.clientCutText(i,e,!0)},extendedClipboardRequest(i,t){let e=se.messages._buildExtendedClipboardFlags([li],t);se.messages.clientCutText(i,e,!0)},extendedClipboardCaps(i,t,e){let s=Object.keys(e),r=new Uint8Array(4+4*s.length);s.map(a=>parseInt(a)),s.sort((a,h)=>a-h),r.set(se.messages._buildExtendedClipboardFlags(t,[]));let n=4;for(let a=0;a<s.length;a++)r[n]=e[s[a]]>>24,r[n+1]=e[s[a]]>>16,r[n+2]=e[s[a]]>>8,r[n+3]=e[s[a]]>>0,n+=4,r[3]|=1<<s[a];se.messages.clientCutText(i,r,!0)},clientCutText(i,t,e=!1){i.sQpush8(6),i.sQpush8(0),i.sQpush8(0),i.sQpush8(0);let s;e?s=ji(-t.length):s=t.length,i.sQpush32(s),i.sQpushBytes(t),i.flush()},setDesktopSize(i,t,e,s,r){i.sQpush8(251),i.sQpush8(0),i.sQpush16(t),i.sQpush16(e),i.sQpush8(1),i.sQpush8(0),i.sQpush32(s),i.sQpush16(0),i.sQpush16(0),i.sQpush16(t),i.sQpush16(e),i.sQpush32(r),i.flush()},clientFence(i,t,e){i.sQpush8(248),i.sQpush8(0),i.sQpush8(0),i.sQpush8(0),i.sQpush32(t),i.sQpush8(e.length),i.sQpushString(e),i.flush()},enableContinuousUpdates(i,t,e,s,r,n){i.sQpush8(150),i.sQpush8(t),i.sQpush16(e),i.sQpush16(s),i.sQpush16(r),i.sQpush16(n),i.flush()},pixelFormat(i,t,e){let s;t>16?s=32:t>8?s=16:s=8;let r=Math.floor(t/3);i.sQpush8(0),i.sQpush8(0),i.sQpush8(0),i.sQpush8(0),i.sQpush8(s),i.sQpush8(t),i.sQpush8(0),i.sQpush8(e?1:0),i.sQpush16((1<<r)-1),i.sQpush16((1<<r)-1),i.sQpush16((1<<r)-1),i.sQpush8(r*0),i.sQpush8(r*1),i.sQpush8(r*2),i.sQpush8(0),i.sQpush8(0),i.sQpush8(0),i.flush()},clientEncodings(i,t){i.sQpush8(2),i.sQpush8(0),i.sQpush16(t.length);for(let e=0;e<t.length;e++)i.sQpush32(t[e]);i.flush()},fbUpdateRequest(i,t,e,s,r,n){typeof e>"u"&&(e=0),typeof s>"u"&&(s=0),i.sQpush8(3),i.sQpush8(t?1:0),i.sQpush16(e),i.sQpush16(s),i.sQpush16(r),i.sQpush16(n),i.flush()},xvpOp(i,t,e){i.sQpush8(250),i.sQpush8(0),i.sQpush8(t),i.sQpush8(e),i.flush()}};se.cursors={none:{rgbaPixels:new Uint8Array,w:0,h:0,hotx:0,hoty:0},dot:{rgbaPixels:new Uint8Array([255,255,255,255,0,0,0,255,255,255,255,255,0,0,0,255,0,0,0,0,0,0,0,255,255,255,255,255,0,0,0,255,255,255,255,255]),w:3,h:3,hotx:1,hoty:1}};var Lo=se;export{Lo as default};