t.state.wmidx&&t.state.wmileft<=a;)t.state.wmileft&&(this.quic_four_uncompress_row0_seg(t,p,r,e,p+t.state.wmileft,Ae[t.state.wmidx],i,n),p+=t.state.wmileft,a-=t.state.wmileft),t.state.wmidx++,t.state.set_wm_trigger(),t.state.wmileft=ot;a&&(this.quic_four_uncompress_row0_seg(t,p,r,e,p+a,Ae[t.state.wmidx],i,n),Ve>t.state.wmidx&&(t.state.wmileft-=a))};ve.prototype.quic_four_uncompress_row_seg=function(t,e,i,n,r,p,a,v){var l=Ae[t.state.wmidx],u,d=0,b,o;for(r==0?(o=ke(t.buckets_ptrs[e.zero].bestcode,this.io_word),e.row[0]=o.rc,n[ne]=me.xlatL2U[o.rc]+i[ne]&v,this.decode_eatbits(o.codewordlen),t.state.waitcnt?--t.state.waitcnt:(t.state.waitcnt=t.state.tabrand()&l,t.buckets_ptrs[e.zero].update_model_8bpc(t.state,e.row[0],a)),u=++r+t.state.waitcnt):u=r+t.state.waitcnt;;){for(var c=0;u2&&n[_+ne]==n[s+ne]){for(t.state.waitcnt=u-r,d=r,b=r+this.decode_run(t.state);r>1)&v,this.decode_eatbits(o.codewordlen)}if(c)break;f.update_model_8bpc(t.state,e.row[u],a),u=r+(t.state.tabrand()&l)}for(;r
2&&n[_+ne]==n[s+ne]){for(t.state.waitcnt=u-r,d=r,b=r+this.decode_run(t.state);r>1)&v,this.decode_eatbits(o.codewordlen)}if(!c){t.state.waitcnt=u-p;return}}};ve.prototype.quic_four_uncompress_row=function(t,e,i){for(var n=8,r=255,p=t.correlate_row,a=0,v=this.width;Ve>t.state.wmidx&&t.state.wmileft<=v;)t.state.wmileft&&(this.quic_four_uncompress_row_seg(t,p,e,i,a,a+t.state.wmileft,n,r),a+=t.state.wmileft,v-=t.state.wmileft),t.state.wmidx++,t.state.set_wm_trigger(),t.state.wmileft=ot;v&&(this.quic_four_uncompress_row_seg(t,p,e,i,a,a+v,n,r),Ve>t.state.wmidx&&(t.state.wmileft-=v))};ve.prototype.quic_decode=function(t,e){var i;switch(this.type){case ye.QUIC_IMAGE_TYPE_RGB32:case ye.QUIC_IMAGE_TYPE_RGB24:for(this.channels[0].correlate_row.zero=0,this.channels[1].correlate_row.zero=0,this.channels[2].correlate_row.zero=0,this.quic_rgb32_uncompress_row0(t),this.rows_completed++,i=1;i0&&(this.rects=[]),n=0;n=0;r--)this.lz_rgb.magic+=String.fromCharCode(t.getUint8(e+r));e+=4,this.lz_rgb.version=t.getUint32(e),e+=4,this.lz_rgb.type=t.getUint32(e),e+=4,this.lz_rgb.width=t.getUint32(e),e+=4,this.lz_rgb.height=t.getUint32(e),e+=4,this.lz_rgb.stride=t.getUint32(e),e+=4,this.lz_rgb.top_down=t.getUint32(e),e+=4;var p=e-n;this.lz_rgb.data=i.slice(e,this.lz_rgb.length+e-p),e+=this.lz_rgb.data.byteLength}if(this.descriptor.type==D.SPICE_IMAGE_TYPE_BITMAP&&(this.bitmap=new xn,e=this.bitmap.from_dv(t,e,i)),this.descriptor.type==D.SPICE_IMAGE_TYPE_SURFACE&&(this.surface_id=t.getUint32(e,!0),e+=4),this.descriptor.type==D.SPICE_IMAGE_TYPE_JPEG&&(this.jpeg=new Object,this.jpeg.data_size=t.getUint32(e,!0),e+=4,this.jpeg.data=i.slice(e),e+=this.jpeg.data.byteLength),this.descriptor.type==D.SPICE_IMAGE_TYPE_JPEG_ALPHA){this.jpeg_alpha=new Object,this.jpeg_alpha.flags=t.getUint8(e,!0),e+=1,this.jpeg_alpha.jpeg_size=t.getUint32(e,!0),e+=4,this.jpeg_alpha.data_size=t.getUint32(e,!0),e+=4,this.jpeg_alpha.data=i.slice(e,this.jpeg_alpha.jpeg_size+e),e+=this.jpeg_alpha.data.byteLength,this.jpeg_alpha.alpha=new Object,this.jpeg_alpha.alpha.length=this.jpeg_alpha.data_size-this.jpeg_alpha.jpeg_size;var n=e;this.jpeg_alpha.alpha.magic="";for(var r=3;r>=0;r--)this.jpeg_alpha.alpha.magic+=String.fromCharCode(t.getUint8(e+r));e+=4,this.jpeg_alpha.alpha.version=t.getUint32(e),e+=4,this.jpeg_alpha.alpha.type=t.getUint32(e),e+=4,this.jpeg_alpha.alpha.width=t.getUint32(e),e+=4,this.jpeg_alpha.alpha.height=t.getUint32(e),e+=4,this.jpeg_alpha.alpha.stride=t.getUint32(e),e+=4,this.jpeg_alpha.alpha.top_down=t.getUint32(e),e+=4;var p=e-n;this.jpeg_alpha.alpha.data=i.slice(e,this.jpeg_alpha.alpha.length+e-p),e+=this.jpeg_alpha.alpha.data.byteLength}return this.descriptor.type==D.SPICE_IMAGE_TYPE_QUIC&&(this.quic=new Sn,e=this.quic.from_dv(t,e,i)),e}};function qi(){}qi.prototype={from_dv:function(t,e,i){this.flags=t.getUint8(e,!0),e++,this.pos=new ii,e=this.pos.from_dv(t,e,i);var n=t.getUint32(e,!0);return e+=4,n==0?(this.bitmap=null,e):(this.bitmap=new ti,this.bitmap.from_dv(t,n,i))}};function An(){}An.prototype={from_dv:function(t,e,i){var n=t.getUint32(e,!0);return e+=4,n==0?this.pat=null:(this.pat=new ti,this.pat.from_dv(t,n,i)),this.pos=new ii,this.pos.from_dv(t,e,i)}};function In(){}In.prototype={from_dv:function(t,e,i){return this.type=t.getUint8(e,!0),e++,this.type==D.SPICE_BRUSH_TYPE_SOLID?(this.color=t.getUint32(e,!0),e+=4):this.type==D.SPICE_BRUSH_TYPE_PATTERN&&(this.pattern=new An,e=this.pattern.from_dv(t,e,i)),e}};function Pn(){}Pn.prototype={from_dv:function(t,e,i){return this.brush=new In,e=this.brush.from_dv(t,e,i),this.rop_descriptor=t.getUint16(e,!0),e+=2,this.mask=new qi,this.mask.from_dv(t,e,i)}};function Tn(){}Tn.prototype={from_dv:function(t,e,i){var n=t.getUint32(e,!0);return e+=4,n==0?this.src_bitmap=null:(this.src_bitmap=new ti,this.src_bitmap.from_dv(t,n,i)),this.src_area=new tt,e=this.src_area.from_dv(t,e,i),this.rop_descriptor=t.getUint16(e,!0),e+=2,this.scale_mode=t.getUint8(e,!0),e++,this.mask=new qi,this.mask.from_dv(t,e,i)}};function zi(){}zi.prototype={from_dv:function(t,e,i){return this.x=t.getUint16(e,!0),e+=2,this.y=t.getUint16(e,!0),e+=2,e}};function ii(){}ii.prototype={from_dv:function(t,e,i){return this.x=t.getUint32(e,!0),e+=4,this.y=t.getUint32(e,!0),e+=4,e}};function Ln(){}Ln.prototype={from_dv:function(t,e,i){return this.unique=t.getUint64(e,!0),e+=8,this.type=t.getUint8(e,!0),e++,this.width=t.getUint16(e,!0),e+=2,this.height=t.getUint16(e,!0),e+=2,this.hot_spot_x=t.getUint16(e,!0),e+=2,this.hot_spot_y=t.getUint16(e,!0),e+=2,e}};function Wi(){}Wi.prototype={from_dv:function(t,e,i){return this.flags=t.getUint16(e,!0),e+=2,this.flags&D.SPICE_CURSOR_FLAGS_NONE?this.header=null:(this.header=new Ln,e=this.header.from_dv(t,e,i),this.data=i.slice(e),e+=this.data.byteLength),e}};function Mn(){}Mn.prototype={from_dv:function(t,e,i){return this.surface_id=t.getUint32(e,!0),e+=4,this.width=t.getUint32(e,!0),e+=4,this.height=t.getUint32(e,!0),e+=4,this.format=t.getUint32(e,!0),e+=4,this.flags=t.getUint32(e,!0),e+=4,e}};var H={KEY_Escape:1,KEY_1:2,KEY_2:3,KEY_3:4,KEY_4:5,KEY_5:6,KEY_6:7,KEY_7:8,KEY_8:9,KEY_9:10,KEY_0:11,KEY_Minus:12,KEY_Equal:13,KEY_BackSpace:14,KEY_Tab:15,KEY_Q:16,KEY_W:17,KEY_E:18,KEY_R:19,KEY_T:20,KEY_Y:21,KEY_U:22,KEY_I:23,KEY_O:24,KEY_P:25,KEY_LBrace:26,KEY_RBrace:27,KEY_Enter:28,KEY_LCtrl:29,KEY_A:30,KEY_S:31,KEY_D:32,KEY_F:33,KEY_G:34,KEY_H:35,KEY_J:36,KEY_K:37,KEY_L:38,KEY_SemiColon:39,KEY_Quote:40,KEY_Tilde:41,KEY_ShiftL:42,KEY_BSlash:43,KEY_Z:44,KEY_X:45,KEY_C:46,KEY_V:47,KEY_B:48,KEY_N:49,KEY_M:50,KEY_Comma:51,KEY_Period:52,KEY_Slash:53,KEY_ShiftR:54,KEY_KP_Multiply:55,KEY_Alt:56,KEY_Space:57,KEY_CapsLock:58,KEY_F1:59,KEY_F2:60,KEY_F3:61,KEY_F4:62,KEY_F5:63,KEY_F6:64,KEY_F7:65,KEY_F8:66,KEY_F9:67,KEY_F10:68,KEY_NumLock:69,KEY_ScrollLock:70,KEY_KP_7:71,KEY_KP_8:72,KEY_KP_9:73,KEY_KP_Minus:74,KEY_KP_4:75,KEY_KP_5:76,KEY_KP_6:77,KEY_KP_Plus:78,KEY_KP_1:79,KEY_KP_2:80,KEY_KP_3:81,KEY_KP_0:82,KEY_KP_Decimal:83,KEY_SysRequest:84,KEY_Less:86,KEY_F11:87,KEY_F12:88,KEY_Prefix0:96,KEY_Prefix1:97};const F=[];F.Escape=1;F.Digit1=2;F.Digit2=3;F.Digit3=4;F.Digit4=5;F.Digit5=6;F.Digit6=7;F.Digit7=8;F.Digit8=9;F.Digit9=10;F.Digit0=11;F.Minus=12;F.Equal=13;F.Backspace=14;F.Tab=15;F.KeyQ=16;F.KeyW=17;F.KeyE=18;F.KeyR=19;F.KeyT=20;F.KeyY=21;F.KeyU=22;F.KeyI=23;F.KeyO=24;F.KeyP=25;F.BracketLeft=26;F.BracketRight=27;F.Enter=28;F.ControlLeft=29;F.KeyA=30;F.KeyS=31;F.KeyD=32;F.KeyF=33;F.KeyG=34;F.KeyH=35;F.KeyJ=36;F.KeyK=37;F.KeyL=38;F.Semicolon=39;F.Quote=40;F.Backquote=41;F.ShiftLeft=42;F.Backslash=43;F.KeyZ=44;F.KeyX=45;F.KeyC=46;F.KeyV=47;F.KeyB=48;F.KeyN=49;F.KeyM=50;F.Comma=51;F.Period=52;F.Slash=53;F.ShiftRight=54;F.NumpadMultiply=55;F.AltLeft=56;F.Space=57;F.CapsLock=58;F.F1=59;F.F2=60;F.F3=61;F.F4=62;F.F5=63;F.F6=64;F.F7=65;F.F8=66;F.F9=67;F.F10=68;F.Pause=69;F.ScrollLock=70;F.Numpad7=71;F.Numpad8=72;F.Numpad9=73;F.NumpadSubtract=74;F.Numpad4=75;F.Numpad5=76;F.Numpad6=77;F.NumpadAdd=78;F.Numpad1=79;F.Numpad2=80;F.Numpad3=81;F.Numpad0=82;F.NumpadDecimal=83;F.PrintScreen=84;F.IntlBackslash=86;F.F11=87;F.F12=88;F.NumpadEqual=89;F.F13=100;F.F14=101;F.F15=102;F.F16=103;F.F17=104;F.F18=105;F.F19=106;F.F20=107;F.F21=108;F.F22=109;F.F23=110;F.KanaMode=112;F.IntlRo=115;F.F24=118;F.Convert=121;F.NonConvert=123;F.IntlYen=125;F.NumpadComma=126;F.MediaTrackPrevious=4320;F.MediaTrackNext=6624;F.NumpadEnter=7392;F.ControlRight=7648;F.AudioVolumeMute=8416;F.LaunchApp2=8672;F.MediaPlayPause=8928;F.MediaStop=9440;F.VolumeDown=12e3;F.VolumeUp=12512;F.BrowserHome=13024;F.NumpadDivide=13792;F.PrintScreen=14304;F.AltRight=14560;F.NumLock=17888;F.Pause=18144;F.Home=18400;F.ArrowUp=18656;F.PageUp=18912;F.ArrowLeft=19424;F.ArrowRight=19936;F.End=20448;F.ArrowDown=20704;F.PageDown=20960;F.Insert=21216;F.Delete=21472;F.MetaLeft=23520;F.MetaRight=23776;F.ContextMenu=24032;F.Power=24288;F.BrowserSearch=26080;F.BrowserFavorites=26336;F.BrowserRefresh=26592;F.BrowserStop=26848;F.BrowserForward=27104;F.BrowserBack=27360;F.LaunchApp1=27616;F.LaunchMail=27872;F.MediaSelect=28128;var Vc=0,Xc="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=";function $c(t,e){var i=new Uint8Array(t),n=new Uint8Array(e),r=new ArrayBuffer(t.byteLength+e.byteLength),p=new Uint8Array(r),a=0,v;for(v=0;v0&&(e+="; start "+t.start(0)+"; end "+t.end(i-1)),e+="}"}else e="N/A";return e}function Bt(t,e){this.magic=D.SPICE_MAGIC,this.major_version=D.SPICE_VERSION_MAJOR,this.minor_version=D.SPICE_VERSION_MINOR,this.size=0,t!==void 0&&this.from_buffer(t,e)}Bt.prototype={from_buffer:function(t,e){e=e||0;var i=new X(t);this.magic="";for(var n=0;n<4;n++)this.magic+=String.fromCharCode(i.getUint8(e+n));e+=4,this.major_version=i.getUint32(e,!0),e+=4,this.minor_version=i.getUint32(e,!0),e+=4,this.size=i.getUint32(e,!0),e+=4},to_buffer:function(t,e){e=e||0;for(var i=new X(t),n=0;n<4;n++)i.setUint8(e+n,this.magic.charCodeAt(n));e+=4,i.setUint32(e,this.major_version,!0),e+=4,i.setUint32(e,this.minor_version,!0),e+=4,i.setUint32(e,this.size,!0),e+=4},buffer_size:function(){return 16}};function On(t,e){this.connection_id=0,this.channel_type=0,this.channel_id=0,this.common_caps=[],this.channel_caps=[],t!==void 0&&this.from_buffer(t,e)}On.prototype={from_buffer:function(t,e){e=e||0;var i,n=e,r=new X(t);this.connection_id=r.getUint32(e,!0),e+=4,this.channel_type=r.getUint8(e,!0),e++,this.channel_id=r.getUint8(e,!0),e++;var p=r.getUint32(e,!0);e+=4;var a=r.getUint32(e,!0);e+=4;var v=r.getUint32(e,!0);for(e+=4,e=n+v,this.common_caps=[],i=0;ie&&(this.data=t.slice(e),e+=this.data.byteLength)},to_buffer:function(t,e){e=e||0;var i,n=new X(t);if(n.setUint16(e,this.type,!0),e+=2,n.setUint32(e,this.data?this.data.byteLength:0,!0),e+=4,this.data&&this.data.byteLength>0){var r=new Uint8Array(this.data);for(i=0;ie&&(this.data=t.slice(e),e+=this.data.byteLength)}};function Ri(t,e){this.from_buffer(t,e)}Ri.prototype={from_buffer:function(t,e){e=e||0;var i=new X(t);this.num_tokens=i.getUint32(e,!0),e+=4}};function Hn(t,e){this.from_buffer(t,e)}Hn.prototype={from_buffer:function(t,e){e=e||0;var i=new X(t);this.generation=i.getUint32(e,!0),e+=4,this.window=i.getUint32(e,!0),e+=4}};function Gn(t){this.generation=t.generation}Gn.prototype={to_buffer:function(t,e){e=e||0;var i=new X(t);i.setUint32(e,this.generation,!0),e+=4},buffer_size:function(){return 4}};function Kn(t){this.mode=t}Kn.prototype={to_buffer:function(t,e){e=e||0;var i=new X(t);i.setUint16(e,this.mode,!0),e+=2},buffer_size:function(){return 2}};function Yn(t){this.num_tokens=t}Yn.prototype={to_buffer:function(t,e){e=e||0;var i=new X(t);i.setUint32(e,this.num_tokens,!0),e+=4},buffer_size:function(){return 4}};function qn(t,e){this.protocol=D.VD_AGENT_PROTOCOL,this.type=t,this.opaque=0,this.size=e.buffer_size(),this.data=e}qn.prototype={to_buffer:function(t,e){e=e||0;var i=new X(t);i.setUint32(e,this.protocol,!0),e+=4,i.setUint32(e,this.type,!0),e+=4,i.setUint64(e,this.opaque,!0),e+=8,i.setUint32(e,this.size,!0),e+=4,this.data.to_buffer(t,e)},buffer_size:function(){return 4+4+8+4+this.data.buffer_size()}};function Vi(t,e){e?(this.request=t,this.caps=e):this.from_buffer(t)}Vi.prototype={to_buffer:function(t,e){e=e||0;var i=new X(t);i.setUint32(e,this.request,!0),e+=4,i.setUint32(e,this.caps,!0),e+=4},from_buffer:function(t,e){e=e||0;var i=new X(t);return this.request=i.getUint32(e,!0),e+=4,this.caps=i.getUint32(e,!0),e+=4,e},buffer_size:function(){return 8}};function zn(t,e,i,n,r,p){this.num_mon=1,this.flags=t,this.width=e,this.height=i,this.depth=n,this.x=r,this.y=p}zn.prototype={to_buffer:function(t,e){e=e||0;var i=new X(t);i.setUint32(e,this.num_mon,!0),e+=4,i.setUint32(e,this.flags,!0),e+=4,i.setUint32(e,this.height,!0),e+=4,i.setUint32(e,this.width,!0),e+=4,i.setUint32(e,this.depth,!0),e+=4,i.setUint32(e,this.x,!0),e+=4,i.setUint32(e,this.y,!0),e+=4},buffer_size:function(){return 28}};function Xi(t,e){e?(this.id=t,this.result=e):this.from_buffer(t)}Xi.prototype={to_buffer:function(t,e){e=e||0;var i=new X(t);i.setUint32(e,this.id,!0),e+=4,i.setUint32(e,this.result,!0),e+=4},from_buffer:function(t,e){e=e||0;var i=new X(t);return this.id=i.getUint32(e,!0),e+=4,this.result=i.getUint32(e,!0),e+=4,e},buffer_size:function(){return 8}};function Wn(t,e,i){this.id=t,this.string=`[vdagent-file-xfer]
name=`+e+`
size=`+i+`
`}Wn.prototype={to_buffer:function(t,e){e=e||0;var i=new X(t);i.setUint32(e,this.id,!0),e+=4;for(var n=0;n0)for(var n=new Uint8Array(this.data),r=0;re&&(this.data=t.slice(e),e+=this.data.byteLength),e}};function os(t,e){this.from_buffer(t,e)}os.prototype={from_buffer:function(t,e,i){e=e||0;var n=new X(t);return this.time=n.getUint32(e,!0),e+=4,this.mode=n.getUint16(e,!0),e+=2,t.byteLength>e&&(this.data=t.slice(e),e+=this.data.byteLength),e}};function as(t,e){this.from_buffer(t,e)}as.prototype={from_buffer:function(t,e,i){e=e||0;var n=new X(t);return this.channels=n.getUint32(e,!0),e+=4,this.format=n.getUint16(e,!0),e+=2,this.frequency=n.getUint32(e,!0),e+=4,this.time=n.getUint32(e,!0),e+=4,e}};function cs(t,e){this.from_buffer(t,e)}cs.prototype={from_buffer:function(t,e,i){e=e||0;var n=new X(t);return this.position=new zi,e=this.position.from_dv(n,e,i),this.visible=n.getUint8(e,!0),e++,this.cursor=new Wi,this.cursor.from_dv(n,e,t)}};function si(t,e){this.display_id=0,this.buttons_state=t.buttons_state,e?(this.x=e.offsetX,this.y=e.offsetY,t.mousex=e.offsetX,t.mousey=e.offsetY):this.x=this.y=this.buttons_state=0}si.prototype={to_buffer:function(t,e){e=e||0;var i=new X(t);return i.setUint32(e,this.x,!0),e+=4,i.setUint32(e,this.y,!0),e+=4,i.setUint16(e,this.buttons_state,!0),e+=2,i.setUint8(e,this.display_id,!0),e+=1,e},buffer_size:function(){return 11}};function $i(t,e){this.display_id=0,this.buttons_state=t.buttons_state,e?(this.x=e.offsetX,this.y=e.offsetY,t.mousex!==void 0&&(this.x-=t.mousex,this.y-=t.mousey),t.mousex=e.offsetX,t.mousey=e.offsetY):this.x=this.y=this.buttons_state=0}$i.prototype.to_buffer=si.prototype.to_buffer;$i.prototype.buffer_size=si.prototype.buffer_size;function xt(t,e){e?(this.button=e.button+1,this.buttons_state=1<>>1)>>>0&4294967295:t=t>>>1;gs[e]=t}bs=1}function il(t,e,i,n){var r=t,p;for(bs||tl(),p=0;p>>8;return r}function rl(t,e,i){return il(4294967295,t,e,i)^4294967295}function Qi(t,e,i){var n=new Uint8Array(t);return rl(n,e,i)}function Ss(t,e){this.width=t,this.height=e,this.depth=8,this.type=6,this.compression=0,this.filter=0,this.interlace=0}Ss.prototype={to_buffer:function(t,e){e=e||0;var i=e,n=new X(t);return n.setUint32(e,this.buffer_size()-12),e+=4,n.setUint8(e,"I".charCodeAt(0)),e++,n.setUint8(e,"H".charCodeAt(0)),e++,n.setUint8(e,"D".charCodeAt(0)),e++,n.setUint8(e,"R".charCodeAt(0)),e++,n.setUint32(e,this.width),e+=4,n.setUint32(e,this.height),e+=4,n.setUint8(e,this.depth),e++,n.setUint8(e,this.type),e++,n.setUint8(e,this.compression),e++,n.setUint8(e,this.filter),e++,n.setUint8(e,this.interlace),e++,n.setUint32(e,Qi(t,i+4,this.buffer_size()-8)),e+=4,e},buffer_size:function(){return 12+13}};function ys(){this.s1=1,this.s2=0}ys.prototype.update=function(t){this.s1+=t,this.s1%=65521,this.s2+=this.s1,this.s2%=65521};function Cs(t,e,i){if(i.byteLength>65535)throw new Error("Cannot handle more than 64K");this.data=i,this.width=t,this.height=e}Cs.prototype={to_buffer:function(t,e){e=e||0;var i=e,n,r,p,a=new X(t),v=new ys;a.setUint32(e,this.buffer_size()-12),e+=4,a.setUint8(e,"I".charCodeAt(0)),e++,a.setUint8(e,"D".charCodeAt(0)),e++,a.setUint8(e,"A".charCodeAt(0)),e++,a.setUint8(e,"T".charCodeAt(0)),e++,a.setUint8(e,120),e++,a.setUint8(e,1),e++,a.setUint8(e,128),e++,a.setUint16(e,this.data.byteLength+this.height),e+=2,a.setUint16(e,~(this.data.byteLength+this.height)),e+=2;var l=new Uint8Array(this.data);for(p=0,r=0;r.cur");'),console.log("And then run following command, redirecting output into .cur:"),console.log(`php -r "echo urldecode('`+e+`');"`))},simulate_cursor:function(t,e,i,n){var r=Pc(n+" "+e.header.hot_spot_x+" "+e.header.hot_spot_y);if(typeof be.cursors<"u"&&typeof be.cursors[r]<"u"){var p="url("+be.cursors[r]+"), default";i.style.cursor=p}window.getComputedStyle(i,null).cursor=="auto"?(be.unknown_cursor(r,be.create_icondir(e.header.width,e.header.height,e.data.byteLength,e.header.hot_spot_x,e.header.hot_spot_y)+n),document.getElementById(t.parent.screen_id).style.cursor="none",t.spice_simulated_cursor||(t.spice_simulated_cursor=document.createElement("img"),t.spice_simulated_cursor.style.position="absolute",t.spice_simulated_cursor.style.display="none",t.spice_simulated_cursor.style.overflow="hidden",t.spice_simulated_cursor.spice_screen=document.getElementById(t.parent.screen_id),t.spice_simulated_cursor.addEventListener("mousemove",be.handle_sim_mousemove),t.spice_simulated_cursor.spice_screen.appendChild(t.spice_simulated_cursor)),t.spice_simulated_cursor.src="data:image/png,"+n,t.spice_simulated_cursor.spice_hot_x=e.header.hot_spot_x,t.spice_simulated_cursor.spice_hot_y=e.header.hot_spot_y,t.spice_simulated_cursor.style.pointerEvents="none"):t.spice_simulated_cursor&&(t.spice_simulated_cursor.spice_screen.removeChild(t.spice_simulated_cursor),delete t.spice_simulated_cursor)},handle_sim_mousemove:function(t){var e=be.duplicate_mouse_event(t,this.spice_screen);return this.spice_screen.dispatchEvent(e)},duplicate_mouse_event:function(t,e){var i=document.createEvent("mouseevent");return i.initMouseEvent(t.type,!0,!0,t.view,t.detail,t.screenX,t.screenY,t.clientX,t.clientY,t.ctrlKey,t.altKey,t.shiftKey,t.metaKey,t.button,t.relatedTarget),i},ICONDIR:function(){},ICONDIRENTRY:function(t,e,i,n,r){this.width=t,this.height=e,this.bytes=i,this.hot_x=n,this.hot_y=r},create_icondir:function(t,e,i,n,r){var p,a=new be.ICONDIR,v=new be.ICONDIRENTRY(t,e,i,n,r),l=new ArrayBuffer(a.buffer_size()+v.buffer_size()),u=a.to_buffer(l);u=v.to_buffer(l,u);var d=new Uint8Array(l),b="";for(p=0;p=this.needed?(t.byteLength>this.needed&&(this.buffers.push(t.slice(this.needed)),t=t.slice(0,this.needed)),this.callback.call(this.sc,t,this.saved_msg_header||void 0)):this.buffers.push(t);this.buffers.length>1&&this.buffers[0].byteLength0&&this.buffers[0].byteLength>=this.needed;)t=this.buffers.shift(),t.byteLength>this.needed&&(this.buffers.unshift(t.slice(this.needed)),t=t.slice(0,this.needed)),this.callback.call(this.sc,t,this.saved_msg_header||void 0)},request:function(t){this.needed=t},save_header:function(t){this.saved_msg_header=t},clear_header:function(){this.saved_msg_header=void 0}};function sl(t){Ji.prototype.inbound.call(this.wire_reader,t.data)}var ol=[26,69,223,163],al=[66,134],cl=[66,247],ll=[66,242],hl=[66,243],ul=[66,130],fl=[66,135],_l=[66,133],dl=[24,83,128,103],ws=[21,73,169,102],Dr=[42,215,177],Or=[77,128],kr=[87,65],pl=[17,77,155,116],ml=[77,187],Nr=[83,171],Ur=[83,172],xs=[22,84,174,107],As=[174],Ft=[215],jt=[115,197],Ht=[131],Gt=[185],Kt=[136],Yt=[85,170],qt=[156],zt=[109,231],Wt=[85,238],Vt=[170],Xt=[86,187],Br=[86,170],Fr=[99,162],$t=[134],vl=[224],jr=[154],Hr=[176],Gr=[186],gl=[225],Kr=[181],Yr=[159],bl=[31,67,182,117],qr=[231],Sl=[163],pe={CLUSTER_SIMPLEBLOCK_FLAG_KEYFRAME:128,OPUS_FREQUENCY:48e3,OPUS_CHANNELS:2,SPICE_PLAYBACK_CODEC:'audio/webm; codecs="opus"',MAX_CLUSTER_TIME:1e3,EXPECTED_PACKET_DURATION:10,GAP_DETECTION_THRESHOLD:50,SPICE_VP8_CODEC:'video/webm; codecs="vp8"'};function it(t,e,i){var n=128|t;return e.setUint8(i,n),i+1}function he(t,e,i,n){return n=ge(t,i,n),n=it(1,i,n),i.setUint8(n,e),n+1}function yt(t,e,i,n){return n=ge(t,i,n),n=it(4,i,n),i.setUint32(n,e),n+4}function Di(t,e,i,n){return n=ge(t,i,n),n=it(2,i,n),i.setUint16(n,e),n+2}function yl(t,e,i,n){return n=ge(t,i,n),n=it(4,i,n),i.setFloat32(n,e),n+4}function Fe(t,e,i){e.setUint8(i++,1),e.setUint8(i++,0),e.setUint8(i++,0),e.setUint8(i++,0);for(var n=t&4294967295,r=24;r>=0;r-=8)e.setUint8(i++,n>>r);return i}function ge(t,e,i){for(var n=0;n500,i.size==0?(this.process_message(i),this.wire_reader.request(fe.prototype.buffer_size())):(this.wire_reader.request(i.size),this.wire_reader.save_header(i))}else e.data=t,this.process_message(e),this.wire_reader.request(fe.prototype.buffer_size()),this.wire_reader.save_header(void 0);else if(this.state=="start")if(this.reply_hdr=new Bt(t),this.reply_hdr.magic!=D.SPICE_MAGIC){this.state="error";var n=new Error("Error: magic mismatch: "+this.reply_hdr.magic);this.report_error(n)}else this.wire_reader.request(this.reply_hdr.size),this.state="link";else if(this.state=="link")if(this.reply_link=new kn(t),this.reply_link.error){this.state="error";var n=new Error("Error: reply link error "+this.reply_link.error);this.report_error(n)}else this.send_ticket(Bc(this.reply_link.pub_key,this.password+String.fromCharCode(0))),this.state="ticket",this.wire_reader.request(Mi.prototype.buffer_size());else if(this.state=="ticket")if(this.auth_reply=new Mi(t),this.auth_reply.auth_code==D.SPICE_LINK_ERR_OK){if(this.type==D.SPICE_CHANNEL_DISPLAY){var r=new $n,p=new fe;p.build_msg(D.SPICE_MSGC_DISPLAY_INIT,r),this.send_msg(p)}this.state="ready",this.wire_reader.request(fe.prototype.buffer_size()),this.timeout&&(window.clearTimeout(this.timeout),delete this.timeout)}else{if(this.state="error",this.auth_reply.auth_code==D.SPICE_LINK_ERR_PERMISSION_DENIED)var n=new Error("Permission denied.");else var n=new Error("Unexpected link error "+this.auth_reply.auth_code);this.report_error(n)}},process_common_messages:function(t){if(t.type==D.SPICE_MSG_SET_ACK){var e=new Hn(t.data);this.ack_window=e.window,this.msgs_until_ack=this.ack_window;var i=new Gn(e),n=new fe;return n.build_msg(D.SPICE_MSGC_ACK_SYNC,i),this.send_msg(n),!0}if(t.type==D.SPICE_MSG_PING){var r=new fe;return r.type=D.SPICE_MSGC_PONG,t.data&&(r.data=t.data.slice(0,12)),r.size=r.buffer_size(),this.send_msg(r),!0}if(t.type==D.SPICE_MSG_NOTIFY){var p=new Xn(t.data);return p.severity==D.SPICE_NOTIFY_SEVERITY_ERROR?this.log_err(p.message):p.severity==D.SPICE_NOTIFY_SEVERITY_WARN?this.log_warn(p.message):this.log_info(p.message),!0}return!1},process_message:function(t){var e,i=Date.now();if(e=this.process_common_messages(t),e||(this.process_channel_message?(e=this.process_channel_message(t),e||this.log_warn(this.channel_type()+": Unknown message type "+t.type+"!")):this.log_err(this.channel_type()+": No message handlers for this channel; message "+t.type)),this.msgs_until_ack!==void 0&&this.ack_window&&(this.msgs_until_ack--,this.msgs_until_ack<=0)){this.msgs_until_ack=this.ack_window;var n=new fe;n.type=D.SPICE_MSGC_ACK,this.send_msg(n)}var r=Date.now()-i;return r>pe.GAP_DETECTION_THRESHOLD&&console.log("delta "+this.channel_type()+":"+t.type+" "+r),e},channel_type:function(){return this.type==D.SPICE_CHANNEL_MAIN?"main":this.type==D.SPICE_CHANNEL_DISPLAY?"display":this.type==D.SPICE_CHANNEL_INPUTS?"inputs":this.type==D.SPICE_CHANNEL_CURSOR?"cursor":this.type==D.SPICE_CHANNEL_PLAYBACK?"playback":this.type==D.SPICE_CHANNEL_RECORD?"record":this.type==D.SPICE_CHANNEL_TUNNEL?"tunnel":this.type==D.SPICE_CHANNEL_SMARTCARD?"smartcard":this.type==D.SPICE_CHANNEL_USBREDIR?"Fusbredir":this.type==D.SPICE_CHANNEL_PORT?"port":this.type==D.SPICE_CHANNEL_WEBDAV?"webdav":"unknown-"+this.type},log_info:function(){var t=Array.prototype.join.call(arguments," ");if(console.log(t),this.message_id){var e=document.createElement("p");e.appendChild(document.createTextNode(t)),e.className+="spice-message-info",document.getElementById(this.message_id).appendChild(e)}},log_warn:function(){var t=Array.prototype.join.call(arguments," ");if(console.log("WARNING: "+t),this.message_id){var e=document.createElement("p");e.appendChild(document.createTextNode(t)),e.className+="spice-message-warning",document.getElementById(this.message_id).appendChild(e)}},log_err:function(){var t=Array.prototype.join.call(arguments," ");if(console.log("ERROR: "+t),this.message_id){var e=document.createElement("p");e.appendChild(document.createTextNode(t)),e.className+="spice-message-error",document.getElementById(this.message_id).appendChild(e)}},known_unimplemented:function(t,e){if(!this.warnings[t]||Vc>1){var i="";i=" [ further notices suppressed ]",this.log_warn("Unimplemented function "+t+"("+e+")"+i),this.warnings[t]=!0}},report_error:function(t){if(this.log_err(t.toString()),this.onerror!=null)this.onerror(t);else throw t},report_success:function(t){this.onsuccess!=null&&this.onsuccess(t)},cleanup:function(){this.timeout&&(window.clearTimeout(this.timeout),delete this.timeout),this.ws&&(this.ws.close(),this.ws=void 0)},handle_timeout:function(){var t=new Error("Connection timed out.");this.report_error(t)}};function El(t){we.prototype.handle_timeout.call(t)}function ci(){we.apply(this,arguments)}ci.prototype=Object.create(we.prototype);ci.prototype.process_channel_message=function(t){if(t.type==D.SPICE_MSG_CURSOR_INIT){var e=new ns(t.data);return this.parent&&this.parent.inputs&&this.parent.inputs.mouse_mode==D.SPICE_MOUSE_MODE_SERVER&&(this.parent.inputs.mousex=e.position.x,this.parent.inputs.mousey=e.position.y),!0}if(t.type==D.SPICE_MSG_CURSOR_SET){var i=new cs(t.data);return i.flags&D.SPICE_CURSOR_FLAGS_NONE?(document.getElementById(this.parent.screen_id).style.cursor="none",!0):(i.flags>0&&this.log_warn("FIXME: No support for cursor flags "+i.flags),i.cursor.header.type!=D.SPICE_CURSOR_TYPE_ALPHA?(this.log_warn("FIXME: No support for cursor type "+i.cursor.header.type),!1):(this.set_cursor(i.cursor),!0))}return t.type==D.SPICE_MSG_CURSOR_MOVE?(this.known_unimplemented(t.type,"Cursor Move"),!0):t.type==D.SPICE_MSG_CURSOR_HIDE?(document.getElementById(this.parent.screen_id).style.cursor="none",!0):t.type==D.SPICE_MSG_CURSOR_TRAIL?(this.known_unimplemented(t.type,"Cursor Trail"),!0):t.type==D.SPICE_MSG_CURSOR_RESET?(document.getElementById(this.parent.screen_id).style.cursor="auto",!0):t.type==D.SPICE_MSG_CURSOR_INVAL_ONE?(this.known_unimplemented(t.type,"Cursor Inval One"),!0):t.type==D.SPICE_MSG_CURSOR_INVAL_ALL};ci.prototype.set_cursor=function(t){var e=nl(t.header.width,t.header.height,t.data),i="url(data:image/png,"+e+") "+t.header.hot_spot_x+" "+t.header.hot_spot_y+", default",n=document.getElementById(this.parent.screen_id);n.style.cursor="auto",n.style.cursor=i,window.getComputedStyle(n,null).cursor=="auto"&&be.simulate_cursor(this,t,n,e)};function li(t,e){this.id=t,this.file=e}li.prototype.create_progressbar=function(){var t=this,e=document.createElement("input");this.progressbar_container=document.createElement("div"),this.progressbar=document.createElement("progress"),e.type="button",e.value="Cancel",e.style.float="right",e.onclick=function(){t.cancelled=!0,t.remove_progressbar()},this.progressbar.setAttribute("max",this.file.size),this.progressbar.setAttribute("value",0),this.progressbar.style.width="100%",this.progressbar.style.margin="4px auto",this.progressbar.style.display="inline-block",this.progressbar_container.style.width="90%",this.progressbar_container.style.margin="auto",this.progressbar_container.style.padding="4px",this.progressbar_container.textContent=this.file.name,this.progressbar_container.appendChild(e),this.progressbar_container.appendChild(this.progressbar),document.getElementById("spice-xfer-area").appendChild(this.progressbar_container)};li.prototype.update_progressbar=function(t){this.progressbar.setAttribute("value",t)};li.prototype.remove_progressbar=function(){this.progressbar_container&&this.progressbar_container.parentNode&&this.progressbar_container.parentNode.removeChild(this.progressbar_container)};var nt=-1,st=-1,ze=-1,vt=-1;function nr(){we.apply(this,arguments),this.mousex=void 0,this.mousey=void 0,this.button_state=0,this.waiting_for_ack=0}nr.prototype=Object.create(we.prototype);nr.prototype.process_channel_message=function(t){if(t.type==D.SPICE_MSG_INPUTS_INIT){var e=new is(t.data);return this.keyboard_modifiers=e.keyboard_modifiers,!0}if(t.type==D.SPICE_MSG_INPUTS_KEY_MODIFIERS){var i=new rs(t.data);return this.keyboard_modifiers=i.keyboard_modifiers,!0}return t.type==D.SPICE_MSG_INPUTS_MOUSE_MOTION_ACK?(this.waiting_for_ack-=D.SPICE_INPUT_MOTION_ACK_BUNCH,!0):!1};function ks(t){var e=new fe,i;this.sc.mouse_mode==D.SPICE_MOUSE_MODE_CLIENT?(i=new si(this.sc,t),e.build_msg(D.SPICE_MSGC_INPUTS_MOUSE_POSITION,i)):(i=new $i(this.sc,t),e.build_msg(D.SPICE_MSGC_INPUTS_MOUSE_MOTION,i)),this.sc&&this.sc.inputs&&this.sc.inputs.state==="ready"&&this.sc.inputs.waiting_for_ack<2*D.SPICE_INPUT_MOTION_ACK_BUNCH&&(this.sc.inputs.send_msg(e),this.sc.inputs.waiting_for_ack++),this.sc&&this.sc.cursor&&this.sc.cursor.spice_simulated_cursor&&(this.sc.cursor.spice_simulated_cursor.style.display="block",this.sc.cursor.spice_simulated_cursor.style.left=t.pageX-this.sc.cursor.spice_simulated_cursor.spice_hot_x+"px",this.sc.cursor.spice_simulated_cursor.style.top=t.pageY-this.sc.cursor.spice_simulated_cursor.spice_hot_y+"px",t.preventDefault())}function Ns(t){var e=new xt(this.sc,t),i=new fe;i.build_msg(D.SPICE_MSGC_INPUTS_MOUSE_PRESS,e),this.sc&&this.sc.inputs&&this.sc.inputs.state==="ready"&&this.sc.inputs.send_msg(i),t.preventDefault()}function Us(t){return t.preventDefault(),!1}function Bs(t){var e=new oi(this.sc,t),i=new fe;i.build_msg(D.SPICE_MSGC_INPUTS_MOUSE_RELEASE,e),this.sc&&this.sc.inputs&&this.sc.inputs.state==="ready"&&this.sc.inputs.send_msg(i),t.preventDefault()}function Fs(t){var e=new xt,i=new oi;t.deltaY<0?e.button=i.button=D.SPICE_MOUSE_BUTTON_UP:e.button=i.button=D.SPICE_MOUSE_BUTTON_DOWN,e.buttons_state=0,i.buttons_state=0;var n=new fe;n.build_msg(D.SPICE_MSGC_INPUTS_MOUSE_PRESS,e),this.sc&&this.sc.inputs&&this.sc.inputs.state==="ready"&&this.sc.inputs.send_msg(n),n.build_msg(D.SPICE_MSGC_INPUTS_MOUSE_RELEASE,i),this.sc&&this.sc.inputs&&this.sc.inputs.state==="ready"&&this.sc.inputs.send_msg(n),t.preventDefault()}function js(t){var e=new dt(t),i=new fe;Gs(t,e.code,this.sc),i.build_msg(D.SPICE_MSGC_INPUTS_KEY_DOWN,e),this.sc&&this.sc.inputs&&this.sc.inputs.state==="ready"&&this.sc.inputs.send_msg(i),t.preventDefault()}function Hs(t){var e=new ai(t),i=new fe;Gs(t,e.code,this.sc),i.build_msg(D.SPICE_MSGC_INPUTS_KEY_UP,e),this.sc&&this.sc.inputs&&this.sc.inputs.state==="ready"&&this.sc.inputs.send_msg(i),t.preventDefault()}function sr(t,e){var i=new fe,n=new dt;n.code=e,i.build_msg(D.SPICE_MSGC_INPUTS_KEY_DOWN,n),t.inputs.send_msg(i),n.code=128|e,i.build_msg(D.SPICE_MSGC_INPUTS_KEY_UP,n),t.inputs.send_msg(i)}function wl(t){t&&t.inputs&&t.inputs.state==="ready"&&(Oe(!0,H.KEY_LCtrl,t),Oe(!0,H.KEY_Alt,t),sr(t,H.KEY_KP_Decimal),st==!1&&Oe(!1,H.KEY_LCtrl,t),ze==!1&&Oe(!1,H.KEY_Alt,t))}function xl(t){t&&t.inputs&&t.inputs.state==="ready"&&(Oe(!0,H.KEY_Alt,t),sr(t,H.KEY_F4),ze==!1&&Oe(!1,H.KEY_Alt,t))}function Al(t){t&&t.inputs&&t.inputs.state==="ready"&&(Oe(!0,H.KEY_Alt,t),sr(t,H.KEY_Tab),ze==!1&&Oe(!1,H.KEY_Alt,t))}function Oe(t,e,i){var n=new fe;if(t){var r=new dt;r.code=e,n.build_msg(D.SPICE_MSGC_INPUTS_KEY_DOWN,r)}else{var r=new ai;r.code=128|e,n.build_msg(D.SPICE_MSGC_INPUTS_KEY_UP,r)}i.inputs.send_msg(n)}function Gs(t,e,i){nt===-1&&(nt=t.shiftKey,st=t.ctrlKey,ze=t.altKey,vt=t.metaKey),e===H.KEY_ShiftL?nt=!0:e===H.KEY_Alt?ze=!0:e===H.KEY_LCtrl?st=!0:e===57525?vt=!0:e===(128|H.KEY_ShiftL)?nt=!1:e===(128|H.KEY_Alt)?ze=!1:e===(128|H.KEY_LCtrl)?st=!1:e===57525&&(vt=!1),i&&i.inputs&&i.inputs.state==="ready"&&(nt!=t.shiftKey&&(console.log("Shift state out of sync"),Oe(t.shiftKey,H.KEY_ShiftL,i),nt=t.shiftKey),ze!=t.altKey&&(console.log("Alt state out of sync"),Oe(t.altKey,H.KEY_Alt,i),ze=t.altKey),st!=t.ctrlKey&&(console.log("Ctrl state out of sync"),Oe(t.ctrlKey,H.KEY_LCtrl,i),st=t.ctrlKey),vt!=t.metaKey&&(console.log("Meta state out of sync"),Oe(t.metaKey,57525,i),vt=t.metaKey))}function wi(t,e,i,n,r){var p=e,a=0,v,l=0;for(v=t[p++];a*4>5,b=(v&31)<<8;if(v>=32){var o;if(d--,d==7-1)do o=t[p++],d+=o;while(o==255);if(o=t[p++],b+=o,o==255&&b-o==7936&&(b=t[p++]<<8,b+=t[p++],b+=8191),d+=1,n==D.LZ_IMAGE_TYPE_RGBA&&(d+=2),b+=1,u-=b,u==a-1)for(var c=u;d;--d){if(n==D.LZ_IMAGE_TYPE_RGBA)i[a*4+3]=i[c*4+3];else for(l=0;l<4;l++)i[a*4+l]=i[c*4+l];a++}else for(;d;--d){if(n==D.LZ_IMAGE_TYPE_RGBA)i[a*4+3]=i[u*4+3];else for(l=0;l<4;l++)i[a*4+l]=i[u*4+l];a++,u++}}else for(v++,n==D.LZ_IMAGE_TYPE_RGBA?i[a*4+3]=t[p++]:(i[a*4+0]=t[p+2],i[a*4+1]=t[p+1],i[a*4+2]=t[p+0],r&&(i[a*4+3]=255),p+=3),a++,--v;v;v--)n==D.LZ_IMAGE_TYPE_RGBA?i[a*4+3]=t[p++]:(i[a*4+0]=t[p+2],i[a*4+1]=t[p+1],i[a*4+2]=t[p+0],r&&(i[a*4+3]=255),p+=3),a++}return p-1}function Il(t){for(var e=t.width*4,i=t.height,n=i,r=new Uint8Array(t.width*t.height*4);n--;)r.set(t.data.subarray(n*e,(n+1)*e),(i-n-1)*e);t.data.set(r)}function zr(t,e){var i;if(e.type===D.LZ_IMAGE_TYPE_RGB32||e.type===D.LZ_IMAGE_TYPE_RGBA){var n=new Uint8Array(e.data),r=t.createImageData(e.width,e.height);i=wi(n,0,r.data,D.LZ_IMAGE_TYPE_RGB32,e.type!=D.LZ_IMAGE_TYPE_RGBA),e.top_down||Il(r),e.type==D.LZ_IMAGE_TYPE_RGBA&&wi(n,i,r.data,D.LZ_IMAGE_TYPE_RGBA,!1)}else if(e.type===D.LZ_IMAGE_TYPE_XXXA){var n=new Uint8Array(e.data),r=t.createImageData(e.width,e.height);wi(n,0,r.data,D.LZ_IMAGE_TYPE_RGBA,!1)}else return;return r}function Pl(t,e){var i,n,r,p=0,a=0,v=new Uint8Array(e.data);if(!(e.format!=D.SPICE_BITMAP_FMT_32BIT&&e.format!=D.SPICE_BITMAP_FMT_RGBA)){for(e.flags&D.SPICE_BITMAP_FLAGS_TOP_DOWN||(p=(e.y-1)*e.stride,a=2*e.stride),i=t.createImageData(e.x,e.y),n=0;n>16)+", "+(b>>8&255)+", "+(b&255)+")";this.surfaces[d.base.surface_id].canvas.context.fillStyle=o,this.surfaces[d.base.surface_id].canvas.context.fillRect(d.base.box.left,d.base.box.top,d.base.box.right-d.base.box.left,d.base.box.bottom-d.base.box.top),this.surfaces[d.base.surface_id].draw_count++}else this.log_warn("FIXME: DrawFill can't handle brush type: "+d.data.brush.type);return!0}if(t.type==D.SPICE_MSG_DISPLAY_DRAW_OPAQUE)return this.known_unimplemented(t.type,"Display Draw Opaque"),!0;if(t.type==D.SPICE_MSG_DISPLAY_DRAW_BLEND)return this.known_unimplemented(t.type,"Display Draw Blend"),!0;if(t.type==D.SPICE_MSG_DISPLAY_DRAW_BLACKNESS)return this.known_unimplemented(t.type,"Display Draw Blackness"),!0;if(t.type==D.SPICE_MSG_DISPLAY_DRAW_WHITENESS)return this.known_unimplemented(t.type,"Display Draw Whiteness"),!0;if(t.type==D.SPICE_MSG_DISPLAY_DRAW_INVERS)return this.known_unimplemented(t.type,"Display Draw Invers"),!0;if(t.type==D.SPICE_MSG_DISPLAY_DRAW_ROP3)return this.known_unimplemented(t.type,"Display Draw ROP3"),!0;if(t.type==D.SPICE_MSG_DISPLAY_DRAW_STROKE)return this.known_unimplemented(t.type,"Display Draw Stroke"),!0;if(t.type==D.SPICE_MSG_DISPLAY_DRAW_TRANSPARENT)return this.known_unimplemented(t.type,"Display Draw Transparent"),!0;if(t.type==D.SPICE_MSG_DISPLAY_DRAW_ALPHA_BLEND)return this.known_unimplemented(t.type,"Display Draw Alpha Blend"),!0;if(t.type==D.SPICE_MSG_DISPLAY_COPY_BITS){var c=new Jn(t.data),f=this.surfaces[c.base.surface_id].canvas,r=f.context,h=f.width-c.src_pos.x,_=f.height-c.src_pos.y;h>c.base.box.right-c.base.box.left&&(h=c.base.box.right-c.base.box.left),_>c.base.box.bottom-c.base.box.top&&(_=c.base.box.bottom-c.base.box.top);var n=r.getImageData(c.src_pos.x,c.src_pos.y,h,_);return Ks(r,n,c.base.box.left,c.base.box.top),this.surfaces[c.base.surface_id].draw_count++,!0}if(t.type==D.SPICE_MSG_DISPLAY_INVAL_ALL_PIXMAPS)return this.known_unimplemented(t.type,"Display Inval All Pixmaps"),!0;if(t.type==D.SPICE_MSG_DISPLAY_INVAL_PALETTE)return this.known_unimplemented(t.type,"Display Inval Palette"),!0;if(t.type==D.SPICE_MSG_DISPLAY_INVAL_ALL_PALETTES)return this.known_unimplemented(t.type,"Inval All Palettes"),!0;if(t.type==D.SPICE_MSG_DISPLAY_SURFACE_CREATE){"surfaces"in this||(this.surfaces=[]);var s=new es(t.data);if(s.surface.format!=D.SPICE_SURFACE_FMT_32_xRGB&&s.surface.format!=D.SPICE_SURFACE_FMT_32_ARGB)return this.log_warn("FIXME: cannot handle surface format "+s.surface.format+" yet."),!1;var i=document.createElement("canvas");return i.setAttribute("width",s.surface.width),i.setAttribute("height",s.surface.height),i.setAttribute("id","spice_surface_"+s.surface.surface_id),i.setAttribute("tabindex",s.surface.surface_id),i.context=i.getContext("2d"),s.surface.canvas=i,s.surface.draw_count=0,this.surfaces[s.surface.surface_id]=s.surface,s.surface.flags&D.SPICE_SURFACE_FLAGS_PRIMARY&&(this.primary_surface=s.surface.surface_id,i.context.save(),document.getElementById(this.parent.screen_id).appendChild(i),document.getElementById(this.parent.screen_id).style.height=s.surface.height+"px",this.hook_events()),!0}if(t.type==D.SPICE_MSG_DISPLAY_SURFACE_DESTROY){var s=new ts(t.data);return this.delete_surface(s.surface_id),!0}if(t.type==D.SPICE_MSG_DISPLAY_STREAM_CREATE){var s=new ls(t.data);if(this.streams||(this.streams=new Array),this.streams[s.id]?console.log("Stream "+s.id+" already exists"):this.streams[s.id]=s,s.codec_type==D.SPICE_VIDEO_CODEC_TYPE_VP8){var g=new MediaSource,m=document.createElement("video");m.src=window.URL.createObjectURL(g),m.setAttribute("muted",!0),m.setAttribute("autoplay",!0),m.setAttribute("width",s.stream_width),m.setAttribute("height",s.stream_height);var S=s.dest.left,y=s.dest.top;this.surfaces[s.surface_id]!==void 0&&(S+=this.surfaces[s.surface_id].canvas.offsetLeft,y+=this.surfaces[s.surface_id].canvas.offsetTop),document.getElementById(this.parent.screen_id).appendChild(m),m.setAttribute("style","pointer-events:none; position: absolute; top:"+y+"px; left:"+S+"px;"),g.addEventListener("sourceopen",Ml,!1),g.addEventListener("sourceended",Rl,!1),g.addEventListener("sourceclosed",Dl,!1);var C=this.streams[s.id];C.video=m,C.media=g,C.queue=new Array,C.start_time=0,C.cluster_time=0,C.append_okay=!1,g.stream=C,g.spiceconn=this,m.spice_stream=C}else s.codec_type==D.SPICE_VIDEO_CODEC_TYPE_MJPEG?this.streams[s.id].frames_loading=0:console.log("Unhandled stream codec: "+s.codec_type);return!0}if(t.type==D.SPICE_MSG_DISPLAY_STREAM_DATA||t.type==D.SPICE_MSG_DISPLAY_STREAM_DATA_SIZED){var s;if(t.type==D.SPICE_MSG_DISPLAY_STREAM_DATA_SIZED?s=new us(t.data):s=new hs(t.data),!this.streams[s.base.id])return console.log("no stream for data"),!1;var w=s.base.multi_media_time-this.parent.relative_now();return this.streams[s.base.id].codec_type===D.SPICE_VIDEO_CODEC_TYPE_MJPEG&&Ll(this,s,w),this.streams[s.base.id].codec_type===D.SPICE_VIDEO_CODEC_TYPE_VP8&&Nl(this.streams[s.base.id],s),!0}if(t.type==D.SPICE_MSG_DISPLAY_STREAM_ACTIVATE_REPORT){var s=new ds(t.data),I=new ps(s.stream_id,s.unique_id);return this.streams[s.stream_id]&&(this.streams[s.stream_id].report=I,this.streams[s.stream_id].max_window_size=s.max_window_size,this.streams[s.stream_id].timeout_ms=s.timeout_ms),!0}if(t.type==D.SPICE_MSG_DISPLAY_STREAM_CLIP){var s=new fs(t.data);return this.streams[s.id].clip=s.clip,!0}if(t.type==D.SPICE_MSG_DISPLAY_STREAM_DESTROY){var s=new _s(t.data);return this.streams[s.id].codec_type==D.SPICE_VIDEO_CODEC_TYPE_VP8&&(document.getElementById(this.parent.screen_id).removeChild(this.streams[s.id].video),this.streams[s.id].source_buffer=null,this.streams[s.id].media=null,this.streams[s.id].video=null),this.streams[s.id]=void 0,!0}if(t.type==D.SPICE_MSG_DISPLAY_STREAM_DESTROY_ALL)return this.known_unimplemented(t.type,"Display Stream Destroy All"),!0;if(t.type==D.SPICE_MSG_DISPLAY_INVAL_LIST){var s=new ms(t.data),l;for(l=0;l0||t.src_area.top>0)&&this.log_warn("FIXME: DrawCopy not shifting draw copies just yet..."),t.descriptor&&t.descriptor.flags&D.SPICE_IMAGE_FLAGS_CACHE_ME&&("cache"in this||(this.cache={}),this.cache[t.descriptor.id]=t.image_data),this.surfaces[t.base.surface_id].draw_count++,!0};Ke.prototype.log_draw=function(t,e){var i=t+"."+e.base.surface_id+"."+this.surfaces[e.base.surface_id].draw_count+": ";i+="base.box "+e.base.box.left+", "+e.base.box.top+" to "+e.base.box.right+", "+e.base.box.bottom,i+="; clip.type "+e.base.clip.type,e.data&&(e.data.src_area&&(i+="; src_area "+e.data.src_area.left+", "+e.data.src_area.top+" to "+e.data.src_area.right+", "+e.data.src_area.bottom),e.data.src_bitmap&&e.data.src_bitmap!=null?(i+="; src_bitmap id: "+e.data.src_bitmap.descriptor.id,i+="; src_bitmap width "+e.data.src_bitmap.descriptor.width+", height "+e.data.src_bitmap.descriptor.height,i+="; src_bitmap type "+e.data.src_bitmap.descriptor.type+", flags "+e.data.src_bitmap.descriptor.flags,e.data.src_bitmap.surface_id!==void 0&&(i+="; src_bitmap surface_id "+e.data.src_bitmap.surface_id),e.data.src_bitmap.bitmap&&(i+="; BITMAP format "+e.data.src_bitmap.bitmap.format+"; flags "+e.data.src_bitmap.bitmap.flags+"; x "+e.data.src_bitmap.bitmap.x+"; y "+e.data.src_bitmap.bitmap.y+"; stride "+e.data.src_bitmap.bitmap.stride),e.data.src_bitmap.quic&&(i+="; QUIC type "+e.data.src_bitmap.quic.type+"; width "+e.data.src_bitmap.quic.width+"; height "+e.data.src_bitmap.quic.height),e.data.src_bitmap.lz_rgb&&(i+="; LZ_RGB length "+e.data.src_bitmap.lz_rgb.length+"; magic "+e.data.src_bitmap.lz_rgb.magic+"; version 0x"+e.data.src_bitmap.lz_rgb.version.toString(16)+"; type "+e.data.src_bitmap.lz_rgb.type+"; width "+e.data.src_bitmap.lz_rgb.width+"; height "+e.data.src_bitmap.lz_rgb.height+"; stride "+e.data.src_bitmap.lz_rgb.stride+"; top down "+e.data.src_bitmap.lz_rgb.top_down)):i+="; src_bitmap is null",e.data.brush&&(e.data.brush.type==D.SPICE_BRUSH_TYPE_SOLID&&(i+="; brush.color 0x"+e.data.brush.color.toString(16)),e.data.brush.type==D.SPICE_BRUSH_TYPE_PATTERN&&(i+="; brush.pat ",e.data.brush.pattern.pat!=null?i+="[SpiceImage]":i+="[null]",i+=" at "+e.data.brush.pattern.pos.x+", "+e.data.brush.pattern.pos.y)),i+="; rop_descriptor "+e.data.rop_descriptor,e.data.scale_mode!==void 0&&(i+="; scale_mode "+e.data.scale_mode),i+="; mask.flags "+e.data.mask.flags,i+="; mask.pos "+e.data.mask.pos.x+", "+e.data.mask.pos.y,e.data.mask.bitmap!=null?(i+="; mask.bitmap width "+e.data.mask.bitmap.descriptor.width+", height "+e.data.mask.bitmap.descriptor.height,i+="; mask.bitmap type "+e.data.mask.bitmap.descriptor.type+", flags "+e.data.mask.bitmap.descriptor.flags):i+="; mask.bitmap is null"),console.log(i)};Ke.prototype.hook_events=function(){if(this.primary_surface!==void 0){var t=this.surfaces[this.primary_surface].canvas;t.sc=this.parent,t.addEventListener("mousemove",ks),t.addEventListener("mousedown",Ns),t.addEventListener("contextmenu",Us),t.addEventListener("mouseup",Bs),t.addEventListener("keydown",js),t.addEventListener("keyup",Hs),t.addEventListener("mouseout",qs),t.addEventListener("mouseover",Ys),t.addEventListener("wheel",Fs),t.focus()}};Ke.prototype.unhook_events=function(){if(this.primary_surface!==void 0){var t=this.surfaces[this.primary_surface].canvas;t.removeEventListener("mousemove",ks),t.removeEventListener("mousedown",Ns),t.removeEventListener("contextmenu",Us),t.removeEventListener("mouseup",Bs),t.removeEventListener("keydown",js),t.removeEventListener("keyup",Hs),t.removeEventListener("mouseout",qs),t.removeEventListener("mouseover",Ys),t.removeEventListener("wheel",Fs)}};Ke.prototype.destroy_surfaces=function(){for(var t in this.surfaces)this.delete_surface(this.surfaces[t].surface_id);this.surfaces=void 0};function Ys(t){this.focus()}function qs(t){this.sc&&this.sc.cursor&&this.sc.cursor.spice_simulated_cursor&&(this.sc.cursor.spice_simulated_cursor.style.display="none"),this.blur()}function ki(){var t=null,e;if("streams"in this.o.sc&&this.o.sc.streams[this.o.id]&&this.o.sc.streams[this.o.id].frames_loading--,this.o.sc.surfaces[this.o.base.surface_id]===void 0?(t=document.createElement("canvas"),t.setAttribute("width",this.o.base.box.right),t.setAttribute("height",this.o.base.box.bottom),e=t.getContext("2d")):e=this.o.sc.surfaces[this.o.base.surface_id].canvas.context,this.alpha_img){var i=document.createElement("canvas"),n=i.getContext("2d");i.setAttribute("width",this.alpha_img.width),i.setAttribute("height",this.alpha_img.height),n.putImageData(this.alpha_img,0,0),n.globalCompositeOperation="source-in",n.drawImage(this,0,0),e.drawImage(i,this.o.base.box.left,this.o.base.box.top),this.o.descriptor&&this.o.descriptor.flags&D.SPICE_IMAGE_FLAGS_CACHE_ME&&("cache"in this.o.sc||(this.o.sc.cache={}),this.o.sc.cache[this.o.descriptor.id]=n.getImageData(0,0,this.alpha_img.width,this.alpha_img.height))}else e.drawImage(this,this.o.base.box.left,this.o.base.box.top),this.onload=void 0,this.src=Xc,this.o.descriptor&&this.o.descriptor.flags&D.SPICE_IMAGE_FLAGS_CACHE_ME&&("cache"in this.o.sc||(this.o.sc.cache={}),this.o.sc.cache[this.o.descriptor.id]=e.getImageData(this.o.base.box.left,this.o.base.box.top,this.o.base.box.right-this.o.base.box.left,this.o.base.box.bottom-this.o.base.box.top));t==null&&this.o.sc.surfaces[this.o.base.surface_id].draw_count++,this.o.sc.streams[this.o.id]&&"report"in this.o.sc.streams[this.o.id]&&zs(this.o.sc,this.o.id,this.o.msg_mmtime,this.o.msg_mmtime-this.o.sc.parent.relative_now())}function Ll(t,e,i){if(i<0&&t.streams[e.base.id].frames_loading>0){"report"in t.streams[e.base.id]&&t.streams[e.base.id].report.num_drops++;return}var n="data:image/jpeg,",r=new Image,p;for(p=0;pt.streams[e].max_window_size||i-t.streams[e].report.start_frame_mm_time>t.streams[e].timeout_ms){t.streams[e].report.end_frame_mm_time=i,t.streams[e].report.last_frame_delay=n;var r=new fe;r.build_msg(D.SPICE_MSGC_DISPLAY_STREAM_REPORT,t.streams[e].report),t.send_msg(r),t.streams[e].report.start_frame_mm_time=0,t.streams[e].report.num_frames=0,t.streams[e].report.num_drops=0}}function Ml(t){var e=this.stream,i=this.spiceconn;if(!e.source_buffer){var n=this.addSourceBuffer(pe.SPICE_VP8_CODEC);if(!n){i.log_err("Codec "+pe.SPICE_VP8_CODEC+" not available.");return}e.source_buffer=n,n.spiceconn=i,n.stream=e,Fl(e);var r=new rr,p=new Os(this.stream.stream_width,this.stream.stream_height),a=new er(p),v=new ArrayBuffer(r.buffer_size()+a.buffer_size()),l=r.to_buffer(v);a.to_buffer(v,l),n.addEventListener("error",kl,!1),n.addEventListener("updateend",Ol,!1),or(n,v)}}function Rl(t){var e=this.spiceconn;e.log_err("Video source unexpectedly ended.")}function Dl(t){var e=this.spiceconn;e.log_err("Video source unexpectedly closed.")}function or(t,e){try{t.stream.append_okay=!1,t.appendBuffer(e)}catch(n){var i=t.spiceconn;i.log_err("Error invoking appendBuffer: "+n.message)}}function Ol(t){var e=this.stream;if(e.current_frame&&"report"in e){var i=this.stream.media.spiceconn,n=this.stream.current_frame.msg_mmtime;zs(i,e.id,n,n-i.parent.relative_now())}if(e.queue.length>0?(e.current_frame=e.queue.shift(),or(e.source_buffer,e.current_frame.mb)):e.append_okay=!0,!!e.video&&(e.video.buffered.length>0&&e.video.currentTime=2))var r=this.stream.video.play()}function kl(t){var e=this.spiceconn;e.log_err("source_buffer error "+t.message)}function Ws(t,e,i){var n={msg_mmtime:e.base.multi_media_time};t.append_okay?(t.current_frame=n,or(t.source_buffer,i)):(n.mb=i,t.queue.push(n))}function Vs(t,e,i){var n=new ir(e.base.multi_media_time-t.cluster_time,e.data,i),r=new ArrayBuffer(n.buffer_size());n.to_buffer(r),Ws(t,e,r)}function Wr(t,e){t.cluster_time=e.base.multi_media_time;var i=new tr(t.cluster_time-t.start_time,e.data),n=new ArrayBuffer(i.buffer_size());i.to_buffer(n),Ws(t,e,n),Vs(t,e,!0)}function Nl(t,e){t.start_time==0?(t.start_time=e.base.multi_media_time,Wr(t,e)):e.base.multi_media_time-t.cluster_time>=pe.MAX_CLUSTER_TIME?Wr(t,e):Vs(t,e,!1)}function Ul(t){var e=this.spice_stream;e.video&&e.video.buffered.len>1&&console.log(e.video.currentTime+":id "+e.id+" event "+t.type+Dn(e.video)),e.queue.length>1&&console.log(" queue len "+e.queue.length+"; append_okay: "+e.append_okay)}function Bl(t){this.addEventListener(t,Ul)}function Fl(t){var e=["abort","error"];e.forEach(Bl,t.video)}function pt(){we.apply(this,arguments),this.queue=new Array,this.append_okay=!1,this.start_time=0}pt.prototype=Object.create(we.prototype);pt.prototype.process_channel_message=function(t){if(!window.MediaSource)return this.log_err("MediaSource API is not available"),!1;if(t.type==D.SPICE_MSG_PLAYBACK_START){var e=new as(t.data);if(e.frequency!=pe.OPUS_FREQUENCY)return this.log_err("This player cannot handle frequency "+e.frequency),!1;if(e.channels!=pe.OPUS_CHANNELS)return this.log_err("This player cannot handle "+e.channels+" channels"),!1;if(e.format!=D.SPICE_AUDIO_FMT_S16)return this.log_err("This player cannot format "+e.format),!1;if(!this.source_buffer)return this.media_source=new MediaSource,this.media_source.spiceconn=this,this.audio=document.createElement("audio"),this.audio.spiceconn=this,this.audio.setAttribute("autoplay",!0),this.audio.src=window.URL.createObjectURL(this.media_source),document.getElementById(this.parent.screen_id).appendChild(this.audio),this.media_source.addEventListener("sourceopen",jl,!1),this.media_source.addEventListener("sourceended",Hl,!1),this.media_source.addEventListener("sourceclosed",Gl,!1),this.bytes_written=0,!0}if(t.type==D.SPICE_MSG_PLAYBACK_DATA){var i=new ss(t.data);return this.source_buffer&&(this.audio.readyState>=3&&this.audio.buffered.length>1&&this.audio.currentTime==this.audio.buffered.end(0)&&this.audio.currentTime=pe.MAX_CLUSTER_TIME?this.new_cluster(i):this.simple_block(i,!1)),!0}if(t.type==D.SPICE_MSG_PLAYBACK_MODE){var n=new os(t.data);return n.mode!=D.SPICE_AUDIO_DATA_MODE_OPUS&&(this.log_err("This player cannot handle mode "+n.mode),delete this.source_buffer),!0}return t.type==D.SPICE_MSG_PLAYBACK_STOP&&this.source_buffer?(document.getElementById(this.parent.screen_id).removeChild(this.audio),window.URL.revokeObjectURL(this.audio.src),delete this.source_buffer,delete this.media_source,delete this.audio,this.append_okay=!1,this.queue=new Array,this.start_time=0,!0):t.type==D.SPICE_MSG_PLAYBACK_VOLUME?(this.known_unimplemented(t.type,"Playback Volume"),!0):t.type==D.SPICE_MSG_PLAYBACK_MUTE?(this.known_unimplemented(t.type,"Playback Mute"),!0):t.type==D.SPICE_MSG_PLAYBACK_LATENCY?(this.known_unimplemented(t.type,"Playback Latency"),!0):!1};pt.prototype.start_playback=function(t){this.start_time=t.time;var e=new rr,i=new Ds,n=new er(i),r=new ArrayBuffer(e.buffer_size()+n.buffer_size());this.bytes_written=e.to_buffer(r),this.bytes_written=n.to_buffer(r,this.bytes_written),this.source_buffer.addEventListener("error",ql,!1),this.source_buffer.addEventListener("updateend",Yl,!1),hi(this,r),this.new_cluster(t)};pt.prototype.new_cluster=function(t){this.cluster_time=t.time;var e=new tr(t.time-this.start_time),i=new ArrayBuffer(e.buffer_size());this.bytes_written+=e.to_buffer(i),this.append_okay?hi(this,i):this.queue.push(i),this.simple_block(t,!0)};pt.prototype.simple_block=function(t,e){var i=new ir(t.time-this.cluster_time,t.data,e),n=new ArrayBuffer(i.buffer_size());this.bytes_written+=i.to_buffer(n),this.append_okay?hi(this,n):this.queue.push(n)};function jl(t){var e=this.spiceconn;if(!e.source_buffer){if(e.source_buffer=this.addSourceBuffer(pe.SPICE_PLAYBACK_CODEC),!e.source_buffer){e.log_err("Codec "+pe.SPICE_PLAYBACK_CODEC+" not available.");return}Vl(e),e.source_buffer.spiceconn=e,e.source_buffer.mode="segments"}}function Hl(t){var e=this.spiceconn;e.log_err("Audio source unexpectedly ended.")}function Gl(t){var e=this.spiceconn;e.log_err("Audio source unexpectedly closed.")}function Kl(t){if(t.length==1)return t.shift();var e=0,i=0;for(i=0;i0){var i=Kl(e.queue);hi(e,i)}else e.append_okay=!0}function ql(t){var e=this.spiceconn;e.log_err("source_buffer error "+t.message)}function hi(t,e){try{t.source_buffer.appendBuffer(e),t.append_okay=!1}catch(i){t.log_err("Error invoking appendBuffer: "+i.message)}}function zl(t){var e=this.spiceconn;e.audio&&e.audio.buffered.len>1&&console.log(e.audio.currentTime+": event "+t.type+Dn(e.audio)),e.queue.length>1&&console.log(" queue len "+e.queue.length+"; append_okay: "+e.append_okay)}function Wl(t){this.addEventListener(t,zl)}function Vl(t){var e=["abort","error"];e.forEach(Wl,t.audio)}function ar(){we.apply(this,arguments),this.port_name=null}ar.prototype=Object.create(we.prototype);ar.prototype.process_channel_message=function(t){if(t.type==D.SPICE_MSG_PORT_INIT){if(this.port_name===null){var e=new vs(t.data);return this.portName=Zc(new Uint8Array(e.name)),this.portOpened=e.opened,!0}}else if(t.type==D.SPICE_MSG_PORT_EVENT){var i=new CustomEvent("spice-port-event",{detail:{channel:this,spiceEvent:new Uint8Array(t.data)},bubbles:!0,cancelable:!0});return window.dispatchEvent(i),!0}else if(t.type==D.SPICE_MSG_SPICEVMC_DATA){var i=new CustomEvent("spice-port-data",{detail:{channel:this,data:t.data},bubbles:!0,cancelable:!0});return window.dispatchEvent(i),!0}return!1};function Xl(t){if(t){var e=document.getElementById(t.screen_id).clientWidth,i=document.getElementById("spice-area"),n=document.isFullScreen||document.fullscreenElement||document.webkitIsFullScreen||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement,r=window.innerHeight-i.getBoundingClientRect().top;n||(r=r-20),r<200&&(r=200),r%8>0&&(r-=r%8),e%8>0&&(e-=e%8),t.resize_window(0,e,r,32,0,0),t.spice_resize_timer=void 0}}function $l(t){var e=window.spice_connection;e&&(e.spice_resize_timer&&(window.clearTimeout(e.spice_resize_timer),e.spice_resize_timer=void 0),e.spice_resize_timer=window.setTimeout(Xl,200,e))}function xe(){if(typeof WebSocket>"u")throw new Error("WebSocket unavailable. You need to use a different browser.");we.apply(this,arguments),this.agent_msg_queue=[],this.file_xfer_tasks={},this.file_xfer_task_id=0,this.file_xfer_read_queue=[],this.ports=[]}xe.prototype=Object.create(we.prototype);xe.prototype.process_channel_message=function(t){if(t.type==D.SPICE_MSG_MAIN_MIGRATE_BEGIN)return this.known_unimplemented(t.type,"Main Migrate Begin"),!0;if(t.type==D.SPICE_MSG_MAIN_MIGRATE_CANCEL)return this.known_unimplemented(t.type,"Main Migrate Cancel"),!0;if(t.type==D.SPICE_MSG_MAIN_INIT){this.log_info("Connected to "+this.ws.url),this.report_success("Connected"),this.main_init=new Bn(t.data),this.connection_id=this.main_init.session_id,this.agent_tokens=this.main_init.agent_tokens,this.our_mm_time=Date.now(),this.mm_time=this.main_init.multi_media_time,this.handle_mouse_mode(this.main_init.current_mouse_mode,this.main_init.supported_mouse_modes),this.main_init.agent_connected&&this.connect_agent();var e=new fe;return e.type=D.SPICE_MSGC_MAIN_ATTACH_CHANNELS,e.size=e.buffer_size(),this.send_msg(e),!0}if(t.type==D.SPICE_MSG_MAIN_MOUSE_MODE){var i=new Fn(t.data);return this.handle_mouse_mode(i.current_mode,i.supported_modes),!0}if(t.type==D.SPICE_MSG_MAIN_MULTI_MEDIA_TIME)return this.known_unimplemented(t.type,"Main Multi Media Time"),!0;if(t.type==D.SPICE_MSG_MAIN_CHANNELS_LIST){var n,r;for(r=new Un(t.data),n=0;n0&&this.file_xfer_read_queue.length>0;){var u=this.file_xfer_read_queue.shift();this.file_xfer_read(u,u.read_bytes),v--}return!0}if(t.type==D.SPICE_MSG_MAIN_AGENT_DISCONNECTED)return this.agent_connected=!1,!0;if(t.type==D.SPICE_MSG_MAIN_AGENT_DATA){var d=new jn(t.data);if(d.type==D.VD_AGENT_ANNOUNCE_CAPABILITIES){var b=new Vi(d.data);return b.request&&this.announce_agent_capabilities(0),!0}else if(d.type==D.VD_AGENT_FILE_XFER_STATUS)return this.handle_file_xfer_status(new Xi(d.data)),!0;return!1}return t.type==D.SPICE_MSG_MAIN_MIGRATE_SWITCH_HOST?(this.known_unimplemented(t.type,"Main Migrate Switch Host"),!0):t.type==D.SPICE_MSG_MAIN_MIGRATE_END?(this.known_unimplemented(t.type,"Main Migrate End"),!0):t.type==D.SPICE_MSG_MAIN_NAME?(this.known_unimplemented(t.type,"Main Name"),!0):t.type==D.SPICE_MSG_MAIN_UUID?(this.known_unimplemented(t.type,"Main UUID"),!0):t.type==D.SPICE_MSG_MAIN_MIGRATE_BEGIN_SEAMLESS?(this.known_unimplemented(t.type,"Main Migrate Begin Seamless"),!0):t.type==D.SPICE_MSG_MAIN_MIGRATE_DST_SEAMLESS_ACK?(this.known_unimplemented(t.type,"Main Migrate Dst Seamless ACK"),!0):t.type==D.SPICE_MSG_MAIN_MIGRATE_DST_SEAMLESS_NACK?(this.known_unimplemented(t.type,"Main Migrate Dst Seamless NACK"),!0):!1};xe.prototype.stop=function(t){if(this.state="closing",this.inputs&&(this.inputs.cleanup(),this.inputs=void 0),this.cursor&&(this.cursor.cleanup(),this.cursor=void 0),this.display&&(this.display.cleanup(),this.display.destroy_surfaces(),this.display=void 0),this.cleanup(),"extra_channels"in this)for(var e in this.extra_channels)this.extra_channels[e].cleanup();this.extra_channels=void 0};xe.prototype.send_agent_message_queue=function(t){if(this.agent_connected)for(t&&this.agent_msg_queue.push(t);this.agent_tokens>0&&this.agent_msg_queue.length>0;){var e=this.agent_msg_queue.shift();this.send_msg(e),this.agent_tokens--}};xe.prototype.send_agent_message=function(t,e){var i=new qn(t,e),n=0,r=D.VD_AGENT_MAX_DATA_SIZE-fe.prototype.buffer_size(),p=new ArrayBuffer(i.buffer_size());for(i.to_buffer(p);n0&&e==t.file.size)){if(t.cancelled){var l=new Xi(t.id,D.VD_AGENT_FILE_XFER_STATUS_CANCELLED);this.send_agent_message(D.VD_AGENT_FILE_XFER_STATUS,l),delete this.file_xfer_tasks[t.id];return}if(r=e||0,p=Math.min(r+i,t.file.size),!this.agent_tokens){t.read_bytes=r,this.file_xfer_read_queue.push(t);return}v=new FileReader,v.onload=function(u){var d=new Vn(t.id,u.target.result.byteLength,u.target.result);n.send_agent_message(D.VD_AGENT_FILE_XFER_DATA,d),n.file_xfer_read(t,p),t.update_progressbar(p)},a=t.file.slice(r,p),v.readAsArrayBuffer(a)}};xe.prototype.file_xfer_completed=function(t,e){e?this.log_err(e):this.log_info("transfer of '"+t.file.name+"' was successful"),t.remove_progressbar(),delete this.file_xfer_tasks[t.id]};xe.prototype.connect_agent=function(){this.agent_connected=!0;var t=new Yn(-1),e=new fe;e.build_msg(D.SPICE_MSGC_MAIN_AGENT_START,t),this.send_msg(e),this.announce_agent_capabilities(1),this.onagent!==void 0&&this.onagent(this)};xe.prototype.handle_mouse_mode=function(t,e){if(this.mouse_mode=t,t!=D.SPICE_MOUSE_MODE_CLIENT&&e&D.SPICE_MOUSE_MODE_CLIENT){var i=new Kn(D.SPICE_MOUSE_MODE_CLIENT),n=new fe;n.build_msg(D.SPICE_MSGC_MAIN_MOUSE_MODE_REQUEST,i),this.send_msg(n)}this.inputs&&(this.inputs.mouse_mode=t)};xe.prototype.relative_now=function(){var t=Date.now()-this.our_mm_time+this.mm_time;return t};const Zl=({instance:t,onMount:e,onFailure:i,inTabNotification:n,clearNotification:r})=>{var _;const{name:p,project:a}=ct(),v=K.useNotify(),l=Z.useRef(null),[u,d]=Z.useState(!1),b=t.status==="Running",o=s=>{i("Error",s)},c=()=>{lt("spice-wrapper",void 0,10),$l()},f=async()=>{if(!p){i("Missing name",new Error);return}if(!a){i("Missing project",new Error);return}d(!0);const s=await _o(p,a).catch(C=>{d(!1),b&&i("Connection failed",C)});if(!s)return;const g=s.operation.split("?")[0],m=`wss://${location.host}${g}/websocket?secret=${s.metadata.metadata.fds[0]}`,S=`wss://${location.host}${g}/websocket?secret=${s.metadata.metadata.fds.control}`,y=new WebSocket(S);y.onerror=o,y.onclose=C=>{C.code!==1005&&i("Error",C.reason,bt(C.code))},y.onmessage=C=>{console.log("control message",C)};try{window.spice_connection=new xe({uri:m,screen_id:"spice-screen",onerror:o,onsuccess:()=>{d(!1),c()},onagent:c})}catch(C){b&&i("Connection failed",C)}return y};return He("resize",c),Z.useEffect(c,[(_=v.notification)==null?void 0:_.message,n==null?void 0:n.message]),Z.useEffect(()=>{r();const s=f();return()=>{var g;try{(g=window.spice_connection)==null||g.stop()}catch(m){console.error(m)}s.then(m=>m==null?void 0:m.close())}},[t.status]),e(()=>{const s=l.current;s&&s.requestFullscreen().then(c).catch(g=>{i("Failed to enter full-screen mode",g)})}),E.jsx(E.Fragment,{children:u?E.jsx(Ge,{text:"Loading VGA session..."}):E.jsx("div",{id:"spice-area",ref:l,children:E.jsx("div",{id:"spice-screen",className:"spice-screen"})})})},Ql=({instance:t,onFailure:e,showNotRunningInfo:i,clearNotification:n})=>{const{name:r,project:p}=ct(),a=Z.useRef(null),v=new TextEncoder,[l,u]=Z.useState(!1),[d,b]=Z.useState(""),[o,c]=Z.useState(null),[f]=Z.useState(new cn.FitAddon),[h,_]=Z.useState(!1);Vr({when:h,message:"Are you sure you want to leave this page?"}),He("beforeunload",C=>{h&&(C.returnValue="Are you sure you want to leave this page?")});const g=t.status==="Running",m=C=>{e("Error",C)},S=async()=>{if(!r){e("Missing name",new Error);return}if(!p){e("Missing project",new Error);return}u(!0),po(r,p).then(b).catch(console.error);const C=await mo(r,p).catch(x=>{u(!1),g?e("Connection failed",x):i()});if(!C)return;const w=C.operation.split("?")[0],I=`wss://${location.host}${w}/websocket?secret=${C.metadata.metadata.fds[0]}`,R=`wss://${location.host}${w}/websocket?secret=${C.metadata.metadata.fds.control}`,k=new WebSocket(I),P=new WebSocket(R);return P.onopen=()=>{u(!1)},P.onerror=m,P.onclose=x=>{x.code!==1005&&e("Error",x.reason,bt(x.code))},P.onmessage=x=>{console.log("control message",x)},k.onopen=()=>{c(k)},k.onerror=m,k.onclose=x=>{x.code!==1005&&e("Error",x.reason,bt(x.code)),c(null)},k.binaryType="arraybuffer",k.onmessage=x=>{var A;(A=a.current)==null||A.terminal.writeUtf8(new Uint8Array(x.data))},[k,P]};Z.useEffect(()=>{var C;g&&((C=a.current)==null||C.terminal.focus())},[g,a.current]),Z.useEffect(()=>{if(o)return;n();const C=S();return()=>{C.then(w=>{w==null||w.map(I=>I.close())})}},[a,f,t.status]),Z.useEffect(()=>{!d||!a.current||l||(a.current.terminal.write(d),b(""))},[d,a,l]);const y=()=>{var C,w;lt("p-terminal",void 0,10),(w=(C=a.current)==null?void 0:C.terminal.element)==null||w.style.setProperty("padding","1rem"),a.current&&a.current.terminal.options===void 0&&(a.current.terminal.options={}),f.fit()};return He("resize",()=>{y(),setTimeout(y,500)}),Z.useLayoutEffect(()=>{y()},[f,a,l]),E.jsx(E.Fragment,{children:l?E.jsx(Ge,{text:"Loading text console..."}):E.jsx(on,{ref:a,addons:[f],className:"p-terminal",onData:C=>{_(!0),o==null||o.send(v.encode(C))}})})},Jl=({instance:t})=>{const[e,i]=Z.useState(null),n=t.type==="virtual-machine",[r,p]=Z.useState(n),a=t.status==="Running",v=(f,h,_)=>{i(K.failure(f,h,_))},l=()=>{i(K.info("Start the instance to interact with the text console.","Instance not running"))};let u=()=>{};const d=f=>{u=f},b=f=>{i(null),p(f)},{handleStart:o,isLoading:c}=Xr(t);return E.jsxs("div",{className:"instance-console-tab",children:[n&&E.jsxs("div",{className:"p-panel__controls",children:[E.jsxs("div",{className:"console-radio-wrapper",children:[E.jsx(K.RadioInput,{labelClassName:"right-margin",label:"Graphic",checked:r,onChange:()=>b(!0)}),E.jsx(K.RadioInput,{label:"Text console",checked:!r,onChange:()=>b(!1)})]}),r&&a&&E.jsxs("div",{children:[E.jsx(K.Button,{className:"u-no-margin--bottom",onClick:()=>u(),children:E.jsx("span",{children:"Fullscreen"})}),E.jsx(K.ContextualMenu,{hasToggleIcon:!0,toggleLabel:"Shortcuts",toggleClassName:"u-no-margin--bottom",links:[{children:"Send Ctrl + Alt + Del",onClick:()=>wl(window.spice_connection)},{children:"Send Alt + TAB",onClick:()=>Al(window.spice_connection)},{children:"Send Alt + F4",onClick:()=>xl(window.spice_connection)}]})]})]}),E.jsx(Zt,{notification:e,onDismiss:()=>i(null)}),r&&!a&&E.jsxs(K.EmptyState,{className:"empty-state",image:E.jsx(K.Icon,{name:"containers",className:"empty-state-icon"}),title:"Instance stopped",children:[E.jsx("p",{children:"Start the instance to access the graphic console."}),E.jsx(Et,{isSubmitting:c,isDisabled:!1,buttonLabel:"Start instance",onClick:o})]}),r&&a&&E.jsx("div",{className:"spice-wrapper",children:E.jsx(Zl,{instance:t,onMount:d,onFailure:v,inTabNotification:e,clearNotification:()=>i(null)})}),!r&&E.jsx(Ql,{instance:t,onFailure:v,showNotRunningInfo:l,clearNotification:()=>i(null)})]})},eh=({instance:t,content:e,fileName:i})=>{const n=Z.useRef(null),r=(a,v)=>{const l=document.createElement("a");return l.setAttribute("href",v),l.setAttribute("target","_blank"),l.setAttribute("download",i),l.setAttribute("id",a),l.style.display="none",l},p=async()=>{var o;const a=`link-${i.toLowerCase().replace(" ","-")}`,v=document.getElementById(a);if(v){v.click();return}const l=e||await tn(t.name,t.project,i),u=new Blob([l],{type:"text/plain"}),d=URL.createObjectURL(u),b=r(a,d);(o=n.current)==null||o.appendChild(b),b.click()};return E.jsx(K.Button,{appearance:"base",className:"u-no-margin--bottom",onClick:()=>void p(),title:`Download ${i}`,"aria-label":`Download ${i} file`,hasIcon:!0,dense:!0,ref:n,children:E.jsx(K.Icon,{name:"begin-downloading",alt:"download"})})},th=({instance:t,path:e})=>{const i=e.split("/").at(-1)??"",n=`/ui/project/${t.project}/instances/detail/${t.name}/logs/?file=${i}`,[r,p]=Z.useState(vo("file")===i),{data:a,isLoading:v,isSuccess:l}=at({queryKey:[Ee.instances,t.name,t.project,Ee.logs,i],queryFn:()=>tn(t.name,t.project,i),enabled:r}),u=()=>{p(d=>!d)};return E.jsxs("div",{className:"p-code-snippet file-row",children:[E.jsxs("div",{className:"p-code-snippet__header file-row-header",children:[E.jsxs(K.Button,{appearance:"base",hasIcon:!0,className:"u-no-margin--bottom file-row-toggle","aria-label":`Toggle ${i} visibility`,"aria-controls":i,"aria-hidden":!r,onClick:u,children:[E.jsx(K.Icon,{name:r?"chevron-up":"chevron-down"}),E.jsx("h3",{className:"p-code-snippet__title file-row-title",children:i})]}),E.jsx("a",{href:n,"aria-label":`File ${i} URL`,className:"p-button--base u-no-margin--bottom",children:E.jsx(K.Icon,{name:"get-link",alt:"link"})}),E.jsx(eh,{fileName:i,instance:t,content:a??""})]}),r&&E.jsx("pre",{id:i,className:"p-code-snippet__block","aria-hidden":!r,children:E.jsxs("code",{children:[v&&E.jsx(E.Fragment,{children:"Downloading file content..."}),l&&!a&&E.jsx(E.Fragment,{children:"This file is empty."}),l&&a&&E.jsx(E.Fragment,{children:a})]})})]})},ih=({instance:t})=>{const{data:e=[],isLoading:i}=at({queryKey:[Ee.instances,t.name,t.project,Ee.logs],queryFn:()=>go(t.name,t.project)});return E.jsxs(E.Fragment,{children:[i&&E.jsx(Ge,{text:"Loading logs..."}),!i&&e.length===0&&E.jsx("div",{className:"u-align-text--center",children:"There are no log files for this instance."}),!i&&e.length>0&&e.map(n=>E.jsx(th,{instance:t,path:n},n))]})},rh=({instance:t})=>{var h;const e=Xe(),i=K.useNotify(),{project:n,activeSection:r}=ct(),p=et(),a=Bi(),[v,l]=Z.useState(!0);if(!n)return E.jsx(E.Fragment,{children:"Missing project"});const u=()=>{lt("form-contents","p-bottom-controls")};Z.useEffect(u,[(h=i.notification)==null?void 0:h.message,r]),He("resize",u);const d=ht({initialValues:Dt(t),validationSchema:nn,onSubmit:_=>{const s=_.yaml?Bo(_.yaml):sn(t,_);s.etag=t.etag,en(s,n).then(g=>{e.set(g.metadata.id,()=>{i.success("Instance updated."),d.setValues(Dt(s))},m=>i.failure("Instance update failed",new Error(m)),()=>{d.setSubmitting(!1),p.invalidateQueries({queryKey:[Ee.instances]})})})}}),b=_=>{d.values.yaml&&_!==pr&&d.setFieldValue("yaml",void 0);const s=`/ui/project/${n}/instances/detail/${t.name}/configuration`;a(_===ui?s:`${s}/${Ne(_)}`)},o=()=>{l(_=>!_)},c=()=>{const _=new Set(["backups","snapshots","state","expanded_config","expanded_devices","etag"]),s=Object.fromEntries(Object.entries(t).filter(g=>!_.has(g[0])));return jo(s)},f=d.values.readOnly;return E.jsxs("div",{className:"edit-instance",children:[E.jsxs(K.Form,{onSubmit:d.handleSubmit,stacked:!0,className:"form",children:[E.jsx(Ho,{active:r??Ne(ui),setActive:b,isConfigDisabled:!1,isConfigOpen:v,toggleConfigOpen:o,hasDiskError:_r(d),hasNetworkError:dr(d)}),E.jsx(K.Row,{className:"form-contents",children:E.jsxs(K.Col,{size:12,children:[(r===Ne(ui)||!r)&&E.jsx(Uo,{formik:d,project:n}),r===Ne(Go)&&E.jsx(Ro,{formik:d,project:n}),r===Ne(Ko)&&E.jsx(Do,{formik:d,project:n}),r===Ne(Yo)&&E.jsx(Oo,{formik:d}),r===Ne(qo)&&E.jsx(ko,{formik:d}),r===Ne(zo)&&E.jsx(rn,{formik:d}),r===Ne(Wo)&&E.jsx(No,{formik:d}),r===Ne(pr)&&E.jsx(Fo,{yaml:c(),setYaml:_=>void d.setFieldValue("yaml",_),isReadOnly:f,children:!f&&E.jsx(K.Notification,{severity:"caution",title:"Before you edit the YAML",children:"Changes will be discarded, when switching back to the guided forms."})})]})},r)]}),E.jsxs("div",{className:"p-bottom-controls",id:"form-footer",children:[E.jsx("hr",{}),E.jsx(K.Row,{className:"u-align--right",children:E.jsx(K.Col,{size:12,children:f?E.jsx(K.Button,{appearance:"positive",onClick:()=>{d.setFieldValue("readOnly",!1),i.clear()},children:"Edit instance"}):E.jsxs(E.Fragment,{children:[E.jsx(K.Button,{appearance:"base",onClick:()=>d.setValues(Dt(t)),children:"Cancel"}),E.jsx(Et,{isSubmitting:d.isSubmitting,isDisabled:!d.isValid||_r(d)||dr(d),buttonLabel:"Save changes",onClick:()=>void d.submitForm()})]})})})]})]})},nh=({instance:t})=>{const e=Xe(),i=bo(),n=K.useNotify(),r=et(),[p,a]=Z.useState(!1),v=Bi(),l=()=>{a(!0),So(t).then(o=>{e.set(o.metadata.id,()=>{r.invalidateQueries({queryKey:[Ee.projects,t.project]}),v(`/ui/project/${t.project}/instances`,n.queue(n.success(`Instance ${t.name} deleted.`)))},c=>n.failure("Instance deletion failed",new Error(c),E.jsxs(E.Fragment,{children:["Instance ",E.jsx(Ue,{item:t,bold:!0}),":"]})),()=>a(!1))})},u=Mo.includes(t.status),d=p||!u,b=()=>u?"Delete instance":"Stop the instance to delete it";return E.jsxs(K.ConfirmationButton,{onHoverText:b(),appearance:i?"base":"default",className:Ui("u-no-margin--bottom",{"has-icon":i}),loading:p,confirmationModalProps:{title:"Confirm delete",children:E.jsxs("p",{children:["This will permanently delete instance"," ",E.jsx(Ue,{item:t,bold:!0}),".",E.jsx("br",{}),"This action cannot be undone, and can result in data loss."]}),onConfirm:l,confirmButtonLabel:"Delete"},disabled:d,shiftClickEnabled:!0,showShiftClickHint:!0,children:[i&&E.jsx(K.Icon,{name:"delete"}),!i&&E.jsx("span",{children:"Delete instance"})]})},sh=({name:t,instance:e,project:i})=>{const n=Xe(),r=Bi(),p=K.useNotify(),a=Z.useState(null),v=Nt().shape({name:Ze().test("deduplicate","An instance with this name already exists",u=>(e==null?void 0:e.name)===u||$r(u,i,a,"instances")).matches(/^[A-Za-z0-9-]+$/,{message:"Only alphanumeric and hyphen characters are allowed"}).matches(/^[A-Za-z].*$/,{message:"Instance name must start with a letter"}).required("Instance name is required")}),l=ht({initialValues:{name:t,isRenaming:!1},validationSchema:v,onSubmit:u=>{if(t===u.name){l.setFieldValue("isRenaming",!1),l.setSubmitting(!1);return}yo(t,u.name,i).then(d=>{n.set(d.metadata.id,()=>{r(`/ui/project/${i}/instances/detail/${u.name}`,p.queue(p.success("Instance renamed."))),l.setFieldValue("isRenaming",!1)},b=>p.failure("Renaming failed",new Error(b)),()=>l.setSubmitting(!1))})}});return E.jsx(Vo,{name:t,titleClassName:"instance-detail-title",parentItems:[E.jsx(Ni,{to:`/ui/project/${i}/instances`,children:"Instances"},1)],renameDisabledReason:(e==null?void 0:e.status)!=="Stopped"?"Stop the instance to rename":void 0,centerControls:e?E.jsxs("div",{children:[E.jsx("i",{className:"status u-text--muted",children:e.status}),E.jsx(Co,{instance:e},"state")]}):null,controls:e?E.jsx(nh,{instance:e},"delete"):null,isLoaded:!!e,formik:l})},oh=["Overview","Configuration","Snapshots","Terminal","Console","Logs"],Th=()=>{const t=K.useNotify(),{name:e,project:i,activeTab:n}=ct();if(!e)return E.jsx(E.Fragment,{children:"Missing name"});if(!i)return E.jsx(E.Fragment,{children:"Missing project"});const{data:r,error:p,isLoading:a}=at({queryKey:[Ee.instances,e,i],queryFn:()=>xo(e,i)});return p&&t.failure("Loading instance failed",p),E.jsxs(Eo,{header:E.jsx(sh,{name:e,instance:r,project:i}),contentClassName:"detail-page",children:[E.jsx(Qr,{}),a&&E.jsx(Ge,{text:"Loading instance details..."}),!a&&!r&&E.jsx(E.Fragment,{children:"Loading instance failed"}),!a&&r&&E.jsxs(K.Row,{children:[E.jsx(wo,{tabs:oh,activeTab:n,tabUrl:`/ui/project/${i}/instances/detail/${e}`}),!n&&E.jsx("div",{role:"tabpanel","aria-labelledby":"overview",children:E.jsx(ha,{instance:r})}),n==="configuration"&&E.jsx("div",{role:"tabpanel","aria-labelledby":"configuration",children:E.jsx(rh,{instance:r})}),n==="snapshots"&&E.jsx("div",{role:"tabpanel","aria-labelledby":"snapshots",children:E.jsx(Da,{instance:r})}),n==="terminal"&&E.jsx("div",{role:"tabpanel","aria-labelledby":"terminal",children:E.jsx(ma,{instance:r})}),n==="console"&&E.jsx("div",{role:"tabpanel","aria-labelledby":"console",children:E.jsx(Jl,{instance:r})}),n==="logs"&&E.jsx("div",{role:"tabpanel","aria-labelledby":"logs",children:E.jsx(ih,{instance:r})})]})]})};export{Th as default};