guacamole-common-zenki-js
Version:
The Guacamole javascript client
1 lines • 66.6 kB
JavaScript
var Guacamole=Guacamole||{};Guacamole.ArrayBufferReader=function(e){var r=this;e.onblob=function(e){for(var t=window.atob(e),n=new ArrayBuffer(t.length),a=new Uint8Array(n),o=0;o<t.length;o++)a[o]=t.charCodeAt(o);r.ondata&&r.ondata(n)},e.onend=function(){r.onend&&r.onend()},this.ondata=null,this.onend=null},(Guacamole=Guacamole||{}).ArrayBufferWriter=function(a){var o=this;function r(e){for(var t="",n=0;n<e.byteLength;n++)t+=String.fromCharCode(e[n]);a.sendBlob(window.btoa(t))}a.onack=function(e){o.onack&&o.onack(e)},this.blobLength=Guacamole.ArrayBufferWriter.DEFAULT_BLOB_LENGTH,this.sendData=function(e){var t=new Uint8Array(e);if(t.length<=o.blobLength)r(t);else for(var n=0;n<t.length;n+=o.blobLength)r(t.subarray(n,n+o.blobLength))},this.sendEnd=function(){a.sendEnd()},this.onack=null},Guacamole.ArrayBufferWriter.DEFAULT_BLOB_LENGTH=6048,(Guacamole=Guacamole||{}).AudioContextFactory={singleton:null,getAudioContext:function(){var e=window.AudioContext||window.webkitAudioContext;if(e)try{return Guacamole.AudioContextFactory.singleton||(Guacamole.AudioContextFactory.singleton=new e),Guacamole.AudioContextFactory.singleton}catch(e){}return null}},(Guacamole=Guacamole||{}).AudioPlayer=function(){this.sync=function(){}},Guacamole.AudioPlayer.isSupportedType=function(e){return Guacamole.RawAudioPlayer.isSupportedType(e)},Guacamole.AudioPlayer.getSupportedTypes=function(){return Guacamole.RawAudioPlayer.getSupportedTypes()},Guacamole.AudioPlayer.getInstance=function(e,t){return Guacamole.RawAudioPlayer.isSupportedType(t)?new Guacamole.RawAudioPlayer(e,t):null},Guacamole.RawAudioPlayer=function(e,t){function r(){var e=function(e){if(e.length<=1)return e[0];var t=0;e.forEach(function(e){t+=e.length});var n=0,a=new d(t);return e.forEach(function(e){a.set(e,n),n+=e.length}),a}(i);return e?(i=function(e){for(var t=Number.MAX_VALUE,n=e.length,a=Math.floor(e.length/u.channels),o=Math.floor(.02*u.rate),r=Math.max(u.channels*o,u.channels*(a-o));r<e.length;r+=u.channels){for(var i=0,s=0;s<u.channels;s++)i+=Math.abs(e[r+s]);i<=t&&(n=r+u.channels,t=i)}return n===e.length?[e]:[new d(e.buffer.slice(0,n*u.bytesPerSample)),new d(e.buffer.slice(n*u.bytesPerSample))]}(e)).shift():null}var u=Guacamole.RawAudioFormat.parse(t),c=Guacamole.AudioContextFactory.getAudioContext(),l=c.currentTime,n=new Guacamole.ArrayBufferReader(e),d=1===u.bytesPerSample?window.Int8Array:window.Int16Array,h=1===u.bytesPerSample?128:32768,i=[];n.ondata=function(e){var t;t=new d(e),i.push(new d(t));var n,a,o=r();o&&(n=c.currentTime,l<n&&(l=n),(a=c.createBufferSource()).connect(c.destination),a.start||(a.start=a.noteOn),a.buffer=function(e){var t=e.length/u.channels,n=c.currentTime;l<n&&(l=n);for(var a=c.createBuffer(u.channels,t,u.rate),o=0;o<u.channels;o++)for(var r=a.getChannelData(o),i=o,s=0;s<t;s++)r[s]=e[i]/h,i+=u.channels;return a}(o),a.start(l),l+=o.length/u.channels/u.rate)},this.sync=function(){var e=c.currentTime;l=Math.min(l,e+.3)}},Guacamole.RawAudioPlayer.prototype=new Guacamole.AudioPlayer,Guacamole.RawAudioPlayer.isSupportedType=function(e){return!!Guacamole.AudioContextFactory.getAudioContext()&&null!==Guacamole.RawAudioFormat.parse(e)},Guacamole.RawAudioPlayer.getSupportedTypes=function(){return Guacamole.AudioContextFactory.getAudioContext()?["audio/L8","audio/L16"]:[]},(Guacamole=Guacamole||{}).AudioRecorder=function(){this.onclose=null,this.onerror=null},Guacamole.AudioRecorder.isSupportedType=function(e){return Guacamole.RawAudioRecorder.isSupportedType(e)},Guacamole.AudioRecorder.getSupportedTypes=function(){return Guacamole.RawAudioRecorder.getSupportedTypes()},Guacamole.AudioRecorder.getInstance=function(e,t){return Guacamole.RawAudioRecorder.isSupportedType(t)?new Guacamole.RawAudioRecorder(e,t):null},Guacamole.RawAudioRecorder=function(e,t){var n=this,u=Guacamole.RawAudioFormat.parse(t),a=Guacamole.AudioContextFactory.getAudioContext();navigator.mediaDevices||(navigator.mediaDevices={}),navigator.mediaDevices.getUserMedia||(navigator.mediaDevices.getUserMedia=(navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia).bind(navigator));function c(e){if(0===e)return 1;var t=Math.PI*e;return Math.sin(t)/t}function l(e,t){for(var n,a,o=(e.length-1)*t,r=Math.floor(o)-3+1,i=Math.floor(o)+3,s=0,u=r;u<=i;u++)s+=(e[u]||0)*(-(a=3)<(n=o-u)&&n<a?c(n)*c(n/a):0);return s}function o(){navigator.mediaDevices.getUserMedia({audio:!0},function(e){(p=a.createScriptProcessor(2048,u.channels,u.channels)).connect(a.destination),p.onaudioprocess=function(e){r.sendData(function(e){var t=e.length;f+=t;var n=Math.round(f*u.rate/e.sampleRate)-m;m+=n;for(var a=new d(n*u.channels),o=0;o<u.channels;o++)for(var r=e.getChannelData(o),i=o,s=0;s<n;s++)a[i]=l(r,s/(n-1))*h,i+=u.channels;return a}(e.inputBuffer).buffer)},(s=a.createMediaStreamSource(e)).connect(p),i=e},function(){r.sendEnd(),n.onerror&&n.onerror()})}var r=new Guacamole.ArrayBufferWriter(e),d=1===u.bytesPerSample?window.Int8Array:window.Int16Array,h=1===u.bytesPerSample?128:32768,f=0,m=0,i=null,s=null,p=null;r.onack=function(e){e.code!==Guacamole.Status.Code.SUCCESS||i?(function(){if(s&&s.disconnect(),p&&p.disconnect(),i)for(var e=i.getTracks(),t=0;t<e.length;t++)e[t].stop();i=s=p=null,r.sendEnd()}(),r.onack=null,e.code===Guacamole.Status.Code.RESOURCE_CLOSED?n.onclose&&n.onclose():n.onerror&&n.onerror()):o()}},Guacamole.RawAudioRecorder.prototype=new Guacamole.AudioRecorder,Guacamole.RawAudioRecorder.isSupportedType=function(e){return!!Guacamole.AudioContextFactory.getAudioContext()&&null!==Guacamole.RawAudioFormat.parse(e)},Guacamole.RawAudioRecorder.getSupportedTypes=function(){return Guacamole.AudioContextFactory.getAudioContext()?["audio/L8","audio/L16"]:[]},(Guacamole=Guacamole||{}).BlobReader=function(r,n){var i=this,s=0,u=new(window.BlobBuilder?BlobBuilder:window.WebKitBlobBuilder?WebKitBlobBuilder:window.MozBlobBuilder?MozBlobBuilder:function(){var t=[];this.append=function(e){t.push(new Blob([e],{type:n}))},this.getBlob=function(){return new Blob(t,{type:n})}});r.onblob=function(e){for(var t=window.atob(e),n=new ArrayBuffer(t.length),a=new Uint8Array(n),o=0;o<t.length;o++)a[o]=t.charCodeAt(o);u.append(n),s+=n.byteLength,i.onprogress&&i.onprogress(n.byteLength),r.sendAck("OK",0)},r.onend=function(){i.onend&&i.onend()},this.getLength=function(){return s},this.getBlob=function(){return u.getBlob()},this.onprogress=null,this.onend=null},(Guacamole=Guacamole||{}).BlobWriter=function(e){var r=this,i=new Guacamole.ArrayBufferWriter(e);i.onack=function(e){r.onack&&r.onack(e)};this.sendBlob=function(t){function n(){var e;a>=t.size?r.oncomplete&&r.oncomplete(t):(e=function(e,t,n){var a=(e.slice||e.webkitSlice||e.mozSlice).bind(e),o=n-t;if(o!==n){var r=a(t,o);if(r.size===o)return r}return a(t,n)}(t,a,a+i.blobLength),a+=i.blobLength,o.readAsArrayBuffer(e))}var a=0,o=new FileReader;o.onload=function(){i.sendData(o.result),i.onack=function(e){r.onack&&r.onack(e),e.isError()||(r.onprogress&&r.onprogress(t,a-i.blobLength),n())}},o.onerror=function(){r.onerror&&r.onerror(t,a,o.error)},n()},this.sendEnd=function(){i.sendEnd()},this.onack=null,this.onerror=null,this.onprogress=null,this.oncomplete=null},(Guacamole=Guacamole||{}).Client=function(o){var c=this,t=2,a=3,u=0,l=0,n=null,d={0:"butt",1:"round",2:"square"},h={0:"bevel",1:"miter",2:"round"},f=new Guacamole.Display,m={},r={},i={},s=[],p=[],g=[],y=new Guacamole.IntegerPool,v=[];function w(e){e!=u&&(u=e,c.onstatechange&&c.onstatechange(u))}function S(){return u==a||u==t}this.exportState=function(r){var e,i={currentState:u,currentTimestamp:l,layers:{}},s={};for(e in m)s[e]=m[e];f.flush(function(){for(var e in s){var t=parseInt(e),n=s[e],a=n.toCanvas(),o={width:n.width,height:n.height};n.width&&n.height&&(o.url=a.toDataURL("image/png")),0<t&&(o.x=n.x,o.y=n.y,o.z=n.z,o.alpha=n.alpha,o.matrix=n.matrix,o.parent=b(n.parent)),i.layers[e]=o}r(i)})},this.importState=function(e,t){var n,a;for(n in u=e.currentState,l=e.currentTimestamp,m)0<(a=parseInt(n))&&f.dispose(m[n]);for(n in m={},e.layers){a=parseInt(n);var o,r,i=e.layers[n],s=T(a);f.resize(s,i.width,i.height),i.url&&(f.setChannelMask(s,Guacamole.Layer.SRC),f.draw(s,0,0,i.url)),0<a&&0<=i.parent&&(o=T(i.parent),f.move(s,o,i.x,i.y,i.z),f.shade(s,i.alpha),r=i.matrix,f.distort(s,r[0],r[1],r[2],r[3],r[4],r[5]))}f.flush(t)},this.getDisplay=function(){return f},this.sendSize=function(e,t){S()&&o.sendMessage("size",e,t)},this.sendKeyEvent=function(e,t){S()&&o.sendMessage("key",t,e)},this.sendMouseState=function(e){var t;S()&&(f.moveCursor(Math.floor(e.x),Math.floor(e.y)),t=0,e.left&&(t|=1),e.middle&&(t|=2),e.right&&(t|=4),e.up&&(t|=8),e.down&&(t|=16),o.sendMessage("mouse",Math.floor(e.x),Math.floor(e.y),t))},this.createOutputStream=function(){var e=y.next();return v[e]=new Guacamole.OutputStream(c,e)},this.createAudioStream=function(e){var t=c.createOutputStream();return o.sendMessage("audio",t.index,e),t},this.createFileStream=function(e,t){var n=c.createOutputStream();return o.sendMessage("file",n.index,e,t),n},this.createPipeStream=function(e,t){var n=c.createOutputStream();return o.sendMessage("pipe",n.index,e,t),n},this.createClipboardStream=function(e){var t=c.createOutputStream();return o.sendMessage("clipboard",t.index,e),t},this.createArgumentValueStream=function(e,t){var n=c.createOutputStream();return o.sendMessage("argv",n.index,e,t),n},this.createObjectOutputStream=function(e,t,n){var a=c.createOutputStream();return o.sendMessage("put",e,a.index,t,n),a},this.requestObjectInputStream=function(e,t){S()&&o.sendMessage("get",e,t)},this.sendAck=function(e,t,n){S()&&o.sendMessage("ack",e,t,n)},this.sendBlob=function(e,t){S()&&o.sendMessage("blob",e,t)},this.endStream=function(e){S()&&(o.sendMessage("end",e),v[e]&&(y.free(e),delete v[e]))},this.onstatechange=null,this.onname=null,this.onerror=null,this.onaudio=null,this.onvideo=null,this.onargv=null,this.onid=null,this.onclipboard=null,this.onfile=null,this.onfilesystem=null,this.onpipe=null,this.onsync=null;var T=function(e){var t=m[e];return t||(t=0===e?f.getDefaultLayer():0<e?f.createLayer():f.createBuffer(),m[e]=t),t},b=function(e){if(!e)return null;for(var t in m)if(e===m[t])return parseInt(t);return null};var G={"miter-limit":function(e,t){f.setMiterLimit(e,parseFloat(t))}},I={ack:function(e){var t=parseInt(e[0]),n=e[1],a=parseInt(e[2]),o=v[t];o&&(o.onack&&o.onack(new Guacamole.Status(a,n)),256<=a&&v[t]===o&&(y.free(t),delete v[t]))},arc:function(e){var t=T(parseInt(e[0])),n=parseInt(e[1]),a=parseInt(e[2]),o=parseInt(e[3]),r=parseFloat(e[4]),i=parseFloat(e[5]),s=parseInt(e[6]);f.arc(t,n,a,o,r,i,0!=s)},argv:function(e){var t,n=parseInt(e[0]),a=e[1],o=e[2];c.onargv?(t=p[n]=new Guacamole.InputStream(c,n),c.onargv(t,a,o)):c.sendAck(n,"Receiving argument values unsupported",256)},id:function(e){c.onid&&c.onid(e)},audio:function(e){var t=parseInt(e[0]),n=e[1],a=p[t]=new Guacamole.InputStream(c,t),o=null;c.onaudio&&(o=c.onaudio(a,n)),(o=o||Guacamole.AudioPlayer.getInstance(a,n))?(r[t]=o,c.sendAck(t,"OK",0)):c.sendAck(t,"BAD TYPE",783)},blob:function(e){var t=parseInt(e[0]),n=e[1],a=p[t];a&&a.onblob&&a.onblob(n)},body:function(e){var t,n=parseInt(e[0]),a=g[n],o=parseInt(e[1]),r=e[2],i=e[3];a&&a.onbody?(t=p[o]=new Guacamole.InputStream(c,o),a.onbody(t,r,i)):c.sendAck(o,"Receipt of body unsupported",256)},cfill:function(e){var t=parseInt(e[0]),n=T(parseInt(e[1])),a=parseInt(e[2]),o=parseInt(e[3]),r=parseInt(e[4]),i=parseInt(e[5]);f.setChannelMask(n,t),f.fillColor(n,a,o,r,i)},clip:function(e){var t=T(parseInt(e[0]));f.clip(t)},clipboard:function(e){var t,n=parseInt(e[0]),a=e[1];c.onclipboard?(t=p[n]=new Guacamole.InputStream(c,n),c.onclipboard(t,a)):c.sendAck(n,"Clipboard unsupported",256)},close:function(e){var t=T(parseInt(e[0]));f.close(t)},copy:function(e){var t=T(parseInt(e[0])),n=parseInt(e[1]),a=parseInt(e[2]),o=parseInt(e[3]),r=parseInt(e[4]),i=parseInt(e[5]),s=T(parseInt(e[6])),u=parseInt(e[7]),c=parseInt(e[8]);f.setChannelMask(s,i),f.copy(t,n,a,o,r,s,u,c)},cstroke:function(e){var t=parseInt(e[0]),n=T(parseInt(e[1])),a=d[parseInt(e[2])],o=h[parseInt(e[3])],r=parseInt(e[4]),i=parseInt(e[5]),s=parseInt(e[6]),u=parseInt(e[7]),c=parseInt(e[8]);f.setChannelMask(n,t),f.strokeColor(n,a,o,r,i,s,u,c)},cursor:function(e){var t=parseInt(e[0]),n=parseInt(e[1]),a=T(parseInt(e[2])),o=parseInt(e[3]),r=parseInt(e[4]),i=parseInt(e[5]),s=parseInt(e[6]);f.setCursor(t,n,a,o,r,i,s)},curve:function(e){var t=T(parseInt(e[0])),n=parseInt(e[1]),a=parseInt(e[2]),o=parseInt(e[3]),r=parseInt(e[4]),i=parseInt(e[5]),s=parseInt(e[6]);f.curveTo(t,n,a,o,r,i,s)},disconnect:function(){c.disconnect()},dispose:function(e){var t,n=parseInt(e[0]);0<n?(t=T(n),f.dispose(t),delete m[n]):n<0&&delete m[n]},distort:function(e){var t,n=parseInt(e[0]),a=parseFloat(e[1]),o=parseFloat(e[2]),r=parseFloat(e[3]),i=parseFloat(e[4]),s=parseFloat(e[5]),u=parseFloat(e[6]);0<=n&&(t=T(n),f.distort(t,a,o,r,i,s,u))},error:function(e){var t=e[0],n=parseInt(e[1]);c.onerror&&c.onerror(new Guacamole.Status(n,t)),c.disconnect()},end:function(e){var t=parseInt(e[0]),n=p[t];n&&(n.onend&&n.onend(),delete p[t])},file:function(e){var t,n=parseInt(e[0]),a=e[1],o=e[2];c.onfile?(t=p[n]=new Guacamole.InputStream(c,n),c.onfile(t,a,o)):c.sendAck(n,"File transfer unsupported",256)},filesystem:function(e){var t,n=parseInt(e[0]),a=e[1];c.onfilesystem&&(t=g[n]=new Guacamole.Object(c,n),c.onfilesystem(t,a))},identity:function(e){var t=T(parseInt(e[0]));f.setTransform(t,1,0,0,1,0,0)},img:function(e){var t=parseInt(e[0]),n=parseInt(e[1]),a=T(parseInt(e[2])),o=e[3],r=parseInt(e[4]),i=parseInt(e[5]),s=p[t]=new Guacamole.InputStream(c,t),u=new Guacamole.DataURIReader(s,o);u.onend=function(){f.setChannelMask(a,n),f.draw(a,r,i,u.getURI())}},jpeg:function(e){var t=parseInt(e[0]),n=T(parseInt(e[1])),a=parseInt(e[2]),o=parseInt(e[3]),r=e[4];f.setChannelMask(n,t),f.draw(n,a,o,"data:image/jpeg;base64,"+r)},lfill:function(e){var t=parseInt(e[0]),n=T(parseInt(e[1])),a=T(parseInt(e[2]));f.setChannelMask(n,t),f.fillLayer(n,a)},line:function(e){var t=T(parseInt(e[0])),n=parseInt(e[1]),a=parseInt(e[2]);f.lineTo(t,n,a)},lstroke:function(e){var t=parseInt(e[0]),n=T(parseInt(e[1])),a=T(parseInt(e[2]));f.setChannelMask(n,t),f.strokeLayer(n,a)},mouse:function(e){var t=parseInt(e[0]),n=parseInt(e[1]);f.showCursor(!0),f.moveCursor(t,n)},move:function(e){var t,n,a=parseInt(e[0]),o=parseInt(e[1]),r=parseInt(e[2]),i=parseInt(e[3]),s=parseInt(e[4]);0<a&&0<=o&&(t=T(a),n=T(o),f.move(t,n,r,i,s))},name:function(e){c.onname&&c.onname(e[0])},nest:function(e){var t,n;(t=parseInt(e[0]),null==(n=s[t])&&((n=s[t]=new Guacamole.Parser).oninstruction=o.oninstruction),n).receive(e[1])},pipe:function(e){var t,n=parseInt(e[0]),a=e[1],o=e[2];c.onpipe?(t=p[n]=new Guacamole.InputStream(c,n),c.onpipe(t,a,o)):c.sendAck(n,"Named pipes unsupported",256)},png:function(e){var t=parseInt(e[0]),n=T(parseInt(e[1])),a=parseInt(e[2]),o=parseInt(e[3]),r=e[4];f.setChannelMask(n,t),f.draw(n,a,o,"data:image/png;base64,"+r)},pop:function(e){var t=T(parseInt(e[0]));f.pop(t)},push:function(e){var t=T(parseInt(e[0]));f.push(t)},rect:function(e){var t=T(parseInt(e[0])),n=parseInt(e[1]),a=parseInt(e[2]),o=parseInt(e[3]),r=parseInt(e[4]);f.rect(t,n,a,o,r)},reset:function(e){var t=T(parseInt(e[0]));f.reset(t)},set:function(e){var t=T(parseInt(e[0])),n=e[1],a=e[2],o=G[n];o&&o(t,a)},shade:function(e){var t,n=parseInt(e[0]),a=parseInt(e[1]);0<=n&&(t=T(n),f.shade(t,a))},size:function(e){var t=parseInt(e[0]),n=T(t),a=parseInt(e[1]),o=parseInt(e[2]);f.resize(n,a,o)},start:function(e){var t=T(parseInt(e[0])),n=parseInt(e[1]),a=parseInt(e[2]);f.moveTo(t,n,a)},sync:function(e){var n=parseInt(e[0]);f.flush(function(){for(var e in r){var t=r[e];t&&t.sync()}n!==l&&(o.sendMessage("sync",n),l=n)}),u===t&&w(a),c.onsync&&c.onsync(n)},transfer:function(e){var t=T(parseInt(e[0])),n=parseInt(e[1]),a=parseInt(e[2]),o=parseInt(e[3]),r=parseInt(e[4]),i=parseInt(e[5]),s=T(parseInt(e[6])),u=parseInt(e[7]),c=parseInt(e[8]);3===i?f.put(t,n,a,o,r,s,u,c):5!==i&&f.transfer(t,n,a,o,r,s,u,c,Guacamole.Client.DefaultTransferFunction[i])},transform:function(e){var t=T(parseInt(e[0])),n=parseFloat(e[1]),a=parseFloat(e[2]),o=parseFloat(e[3]),r=parseFloat(e[4]),i=parseFloat(e[5]),s=parseFloat(e[6]);f.transform(t,n,a,o,r,i,s)},undefine:function(e){var t=parseInt(e[0]),n=g[t];n&&n.onundefine&&n.onundefine()},video:function(e){var t=parseInt(e[0]),n=T(parseInt(e[1])),a=e[2],o=p[t]=new Guacamole.InputStream(c,t),r=null;c.onvideo&&(r=c.onvideo(o,n,a)),(r=r||Guacamole.VideoPlayer.getInstance(o,n,a))?(i[t]=r,c.sendAck(t,"OK",0)):c.sendAck(t,"BAD TYPE",783)}};o.oninstruction=function(e,t){var n=I[e];n&&n(t)},this.disconnect=function(){5!=u&&4!=u&&(w(4),n&&window.clearInterval(n),o.sendMessage("disconnect"),o.disconnect(),w(5))},this.connect=function(e){w(1);try{o.connect(e)}catch(e){throw w(0),e}n=window.setInterval(function(){o.sendMessage("nop")},5e3),w(t)}},Guacamole.Client.DefaultTransferFunction={0:function(e,t){t.red=t.green=t.blue=0},15:function(e,t){t.red=t.green=t.blue=255},3:function(e,t){t.red=e.red,t.green=e.green,t.blue=e.blue,t.alpha=e.alpha},5:function(e,t){},12:function(e,t){t.red=255&~e.red,t.green=255&~e.green,t.blue=255&~e.blue,t.alpha=e.alpha},10:function(e,t){t.red=255&~t.red,t.green=255&~t.green,t.blue=255&~t.blue},1:function(e,t){t.red=e.red&t.red,t.green=e.green&t.green,t.blue=e.blue&t.blue},14:function(e,t){t.red=255&~(e.red&t.red),t.green=255&~(e.green&t.green),t.blue=255&~(e.blue&t.blue)},7:function(e,t){t.red=e.red|t.red,t.green=e.green|t.green,t.blue=e.blue|t.blue},8:function(e,t){t.red=255&~(e.red|t.red),t.green=255&~(e.green|t.green),t.blue=255&~(e.blue|t.blue)},6:function(e,t){t.red=e.red^t.red,t.green=e.green^t.green,t.blue=e.blue^t.blue},9:function(e,t){t.red=255&~(e.red^t.red),t.green=255&~(e.green^t.green),t.blue=255&~(e.blue^t.blue)},4:function(e,t){t.red=~e.red&t.red&255,t.green=~e.green&t.green&255,t.blue=~e.blue&t.blue&255},13:function(e,t){t.red=255&(~e.red|t.red),t.green=255&(~e.green|t.green),t.blue=255&(~e.blue|t.blue)},2:function(e,t){t.red=e.red&~t.red&255,t.green=e.green&~t.green&255,t.blue=e.blue&~t.blue&255},11:function(e,t){t.red=255&(e.red|~t.red),t.green=255&(e.green|~t.green),t.blue=255&(e.blue|~t.blue)}},(Guacamole=Guacamole||{}).DataURIReader=function(e,t){var n=this,a="data:"+t+";base64,";e.onblob=function(e){a+=e},e.onend=function(){n.onend&&n.onend()},this.getURI=function(){return a},this.onend=null},(Guacamole=Guacamole||{}).Display=function(){var s=this,a=0,o=0,r=1,i=document.createElement("div");i.style.position="relative",i.style.width=a+"px",i.style.height=o+"px",i.style.transformOrigin=i.style.webkitTransformOrigin=i.style.MozTransformOrigin=i.style.OTransformOrigin=i.style.msTransformOrigin="0 0";var c=new Guacamole.Display.VisibleLayer(a,o),u=new Guacamole.Display.VisibleLayer(0,0);u.setChannelMask(Guacamole.Layer.SRC),i.appendChild(c.getElement()),i.appendChild(u.getElement());var l=document.createElement("div");l.style.position="relative",l.style.width=a*r+"px",l.style.height=o*r+"px",l.appendChild(i),this.cursorHotspotX=0,this.cursorHotspotY=0,this.cursorX=0,this.cursorY=0,this.onresize=null,this.oncursor=null;var d=[],n=[];function h(){for(var e=0;e<n.length;){var t=n[e];if(!t.isReady())break;t.flush(),e++}n.splice(0,e)}function t(t,n){this.isReady=function(){for(var e=0;e<n.length;e++)if(n[e].blocked)return!1;return!0},this.flush=function(){for(var e=0;e<n.length;e++)n[e].execute();t&&t()}}function f(e,t){var n=this;this.blocked=t,this.unblock=function(){n.blocked&&(n.blocked=!1,h())},this.execute=function(){e&&e()}}function m(e,t){var n=new f(e,t);return d.push(n),n}this.getElement=function(){return l},this.getWidth=function(){return a},this.getHeight=function(){return o},this.getDefaultLayer=function(){return c},this.getCursorLayer=function(){return u},this.createLayer=function(){var e=new Guacamole.Display.VisibleLayer(a,o);return e.move(c,0,0,0),e},this.createBuffer=function(){var e=new Guacamole.Layer(0,0);return e.autosize=1,e},this.flush=function(e){n.push(new t(e,d)),d=[],h()},this.setCursor=function(e,t,n,a,o,r,i){m(function(){s.cursorHotspotX=e,s.cursorHotspotY=t,u.resize(r,i),u.copy(n,a,o,r,i,0,0),s.moveCursor(s.cursorX,s.cursorY),s.oncursor&&s.oncursor(u.toCanvas(),e,t)})},this.showCursor=function(e){var t=u.getElement(),n=t.parentNode;!1===e?n&&n.removeChild(t):n!==i&&i.appendChild(t)},this.moveCursor=function(e,t){u.translate(e-s.cursorHotspotX,t-s.cursorHotspotY),s.cursorX=e,s.cursorY=t},this.resize=function(e,t,n){m(function(){e.resize(t,n),e===c&&(a=t,o=n,i.style.width=a+"px",i.style.height=o+"px",l.style.width=a*r+"px",l.style.height=o*r+"px",s.onresize&&s.onresize(t,n))})},this.drawImage=function(e,t,n,a){m(function(){e.drawImage(t,n,a)})},this.drawBlob=function(e,t,n,a){var o=URL.createObjectURL(a),r=m(function(){i.width&&i.height&&e.drawImage(t,n,i),URL.revokeObjectURL(o)},!0),i=new Image;i.onload=r.unblock,i.onerror=r.unblock,i.src=o},this.draw=function(e,t,n,a){var o=m(function(){r.width&&r.height&&e.drawImage(t,n,r)},!0),r=new Image;r.onload=o.unblock,r.onerror=o.unblock,r.src=a},this.play=function(t,e,n,a){var o=document.createElement("video");o.type=e,o.src=a,o.addEventListener("play",function(){!function e(){t.drawImage(0,0,o),o.ended||window.setTimeout(e,20)}()},!1),m(o.play)},this.transfer=function(e,t,n,a,o,r,i,s,u){m(function(){r.transfer(e,t,n,a,o,i,s,u)})},this.put=function(e,t,n,a,o,r,i,s){m(function(){r.put(e,t,n,a,o,i,s)})},this.copy=function(e,t,n,a,o,r,i,s){m(function(){r.copy(e,t,n,a,o,i,s)})},this.moveTo=function(e,t,n){m(function(){e.moveTo(t,n)})},this.lineTo=function(e,t,n){m(function(){e.lineTo(t,n)})},this.arc=function(e,t,n,a,o,r,i){m(function(){e.arc(t,n,a,o,r,i)})},this.curveTo=function(e,t,n,a,o,r,i){m(function(){e.curveTo(t,n,a,o,r,i)})},this.close=function(e){m(function(){e.close()})},this.rect=function(e,t,n,a,o){m(function(){e.rect(t,n,a,o)})},this.clip=function(e){m(function(){e.clip()})},this.strokeColor=function(e,t,n,a,o,r,i,s){m(function(){e.strokeColor(t,n,a,o,r,i,s)})},this.fillColor=function(e,t,n,a,o){m(function(){e.fillColor(t,n,a,o)})},this.strokeLayer=function(e,t,n,a,o){m(function(){e.strokeLayer(t,n,a,o)})},this.fillLayer=function(e,t){m(function(){e.fillLayer(t)})},this.push=function(e){m(function(){e.push()})},this.pop=function(e){m(function(){e.pop()})},this.reset=function(e){m(function(){e.reset()})},this.setTransform=function(e,t,n,a,o,r,i){m(function(){e.setTransform(t,n,a,o,r,i)})},this.transform=function(e,t,n,a,o,r,i){m(function(){e.transform(t,n,a,o,r,i)})},this.setChannelMask=function(e,t){m(function(){e.setChannelMask(t)})},this.setMiterLimit=function(e,t){m(function(){e.setMiterLimit(t)})},this.dispose=function(e){m(function(){e.dispose()})},this.distort=function(e,t,n,a,o,r,i){m(function(){e.distort(t,n,a,o,r,i)})},this.move=function(e,t,n,a,o){m(function(){e.move(t,n,a,o)})},this.shade=function(e,t){m(function(){e.shade(t)})},this.scale=function(e){i.style.transform=i.style.WebkitTransform=i.style.MozTransform=i.style.OTransform=i.style.msTransform="scale("+e+","+e+")",r=e,l.style.width=a*r+"px",l.style.height=o*r+"px"},this.getScale=function(){return r},this.flatten=function(){var e=document.createElement("canvas");e.width=c.width,e.height=c.height;var u=e.getContext("2d");return function e(t,n,a){if(0<t.width&&0<t.height){var o=u.globalAlpha;u.globalAlpha*=t.alpha/255,u.drawImage(t.getCanvas(),n,a);for(var r=function(e){var t,n=[];for(t in e.children)n.push(e.children[t]);return n.sort(function(e,t){var n=e.z-t.z;if(0!=n)return n;var a=e.getElement(),o=t.getElement().compareDocumentPosition(a);return o&Node.DOCUMENT_POSITION_PRECEDING?-1:o&Node.DOCUMENT_POSITION_FOLLOWING?1:0}),n}(t),i=0;i<r.length;i++){var s=r[i];e(s,n+s.x,a+s.y)}u.globalAlpha=o}}(c,0,0),e}},Guacamole.Display.VisibleLayer=function(e,t){Guacamole.Layer.apply(this,[e,t]);var i=this;this.__unique_id=Guacamole.Display.VisibleLayer.__next_id++,this.alpha=255,this.x=0,this.y=0,this.z=0,this.matrix=[1,0,0,1,0,0],this.parent=null,this.children={};var n=i.getCanvas();n.style.position="absolute",n.style.left="0px",n.style.top="0px";var s=document.createElement("div");s.appendChild(n),s.style.width=e+"px",s.style.height=t+"px",s.style.position="absolute",s.style.left="0px",s.style.top="0px",s.style.overflow="hidden";var a=this.resize;this.resize=function(e,t){s.style.width=e+"px",s.style.height=t+"px",a(e,t)},this.getElement=function(){return s};var u="translate(0px, 0px)",c="matrix(1, 0, 0, 1, 0, 0)";this.translate=function(e,t){i.x=e,i.y=t,u="translate("+e+"px,"+t+"px)",s.style.transform=s.style.WebkitTransform=s.style.MozTransform=s.style.OTransform=s.style.msTransform=u+" "+c},this.move=function(e,t,n,a){i.parent!==e&&(i.parent&&delete i.parent.children[i.__unique_id],(i.parent=e).children[i.__unique_id]=i,e.getElement().appendChild(s)),i.translate(t,n),i.z=a,s.style.zIndex=a},this.shade=function(e){i.alpha=e,s.style.opacity=e/255},this.dispose=function(){i.parent&&(delete i.parent.children[i.__unique_id],i.parent=null),s.parentNode&&s.parentNode.removeChild(s)},this.distort=function(e,t,n,a,o,r){i.matrix=[e,t,n,a,o,r],c="matrix("+e+","+t+","+n+","+a+","+o+","+r+")",s.style.transform=s.style.WebkitTransform=s.style.MozTransform=s.style.OTransform=s.style.msTransform=u+" "+c}},Guacamole.Display.VisibleLayer.__next_id=0,(Guacamole=Guacamole||{}).InputSink=function(){var n=this,t=document.createElement("textarea");t.style.position="fixed",t.style.outline="none",t.style.border="none",t.style.margin="0",t.style.padding="0",t.style.height="0",t.style.width="0",t.style.left="0",t.style.bottom="0",t.style.resize="none",t.style.background="transparent",t.style.color="transparent",t.addEventListener("keypress",function(){t.value=""},!1),t.addEventListener("compositionend",function(e){e.data&&(t.value="")},!1),t.addEventListener("input",function(e){e.data&&!e.isComposing&&(t.value="")},!1),t.addEventListener("focus",function(){window.setTimeout(function(){t.click(),t.select()},0)},!0),this.focus=function(){window.setTimeout(function(){t.focus()},0)},this.getElement=function(){return t},document.addEventListener("keydown",function(){var e=document.activeElement;if(e&&e!==document.body){var t=e.getBoundingClientRect();if(0<t.left+t.width&&0<t.top+t.height)return}n.focus()},!0)},(Guacamole=Guacamole||{}).InputStream=function(n,e){var a=this;this.index=e,this.onblob=null,this.onend=null,this.sendAck=function(e,t){n.sendAck(a.index,e,t)}},(Guacamole=Guacamole||{}).IntegerPool=function(){var e=this,t=[];this.next_int=0,this.next=function(){return 0<t.length?t.shift():e.next_int++},this.free=function(e){t.push(e)}},(Guacamole=Guacamole||{}).JSONReader=function(e){var t=this,n=new Guacamole.StringReader(e),a="";this.getLength=function(){return a.length},this.getJSON=function(){return JSON.parse(a)},n.ontext=function(e){a+=e,t.onprogress&&t.onprogress(e.length)},n.onend=function(){t.onend&&t.onend()},this.onprogress=null,this.onend=null},(Guacamole=Guacamole||{}).Keyboard=function(e){var i=this,t="_GUAC_KEYBOARD_HANDLED_BY_"+Guacamole.Keyboard._nextID++;this.onkeydown=null,this.onkeyup=null;var s={keyupUnreliable:!1,altIsTypableOnly:!1,capsLockKeyupUnreliable:!1};navigator&&navigator.platform&&(navigator.platform.match(/ipad|iphone|ipod/i)?s.keyupUnreliable=!0:navigator.platform.match(/^mac/i)&&(s.altIsTypableOnly=!0,s.capsLockKeyupUnreliable=!0));function r(){var e=this;this.timestamp=(new Date).getTime(),this.defaultPrevented=!1,this.keysym=null,this.reliable=!1,this.getAge=function(){return(new Date).getTime()-e.timestamp}}function u(e,t,n,a){r.apply(this),this.keyCode=e,this.keyIdentifier=t,this.key=n,this.location=a,this.keysym=w(n,a)||T(e,a),this.keyupReliable=!s.keyupUnreliable,this.keysym&&!v(this.keysym)&&(this.reliable=!0),!this.keysym&&b(e,t)&&(this.keysym=w(t,a,i.modifiers.shift)),(i.modifiers.meta&&65511!==this.keysym&&65512!==this.keysym||65509===this.keysym&&s.capsLockKeyupUnreliable)&&(this.keyupReliable=!1);var o=!i.modifiers.ctrl&&!s.altIsTypableOnly;(!i.modifiers.alt&&i.modifiers.ctrl||o&&i.modifiers.alt||i.modifiers.meta||i.modifiers.hyper)&&(this.reliable=!0),m[e]=this.keysym}u.prototype=new r;function c(e){r.apply(this),this.charCode=e,this.keysym=S(e),this.reliable=!0}c.prototype=new r;function l(e,t,n,a){r.apply(this),this.keyCode=e,this.keyIdentifier=t,this.key=n,this.location=a,this.keysym=T(e,a)||w(n,a),i.pressed[this.keysym]||(this.keysym=m[e]||this.keysym),this.reliable=!0}l.prototype=new r;var d=[],n={8:[65288],9:[65289],12:[65291,65291,65291,65461],13:[65293],16:[65505,65505,65506],17:[65507,65507,65508],18:[65513,65513,65027],19:[65299],20:[65509],27:[65307],32:[32],33:[65365,65365,65365,65465],34:[65366,65366,65366,65459],35:[65367,65367,65367,65457],36:[65360,65360,65360,65463],37:[65361,65361,65361,65460],38:[65362,65362,65362,65464],39:[65363,65363,65363,65462],40:[65364,65364,65364,65458],45:[65379,65379,65379,65456],46:[65535,65535,65535,65454],91:[65515],92:[65383],93:null,96:[65456],97:[65457],98:[65458],99:[65459],100:[65460],101:[65461],102:[65462],103:[65463],104:[65464],105:[65465],106:[65450],107:[65451],109:[65453],110:[65454],111:[65455],112:[65470],113:[65471],114:[65472],115:[65473],116:[65474],117:[65475],118:[65476],119:[65477],120:[65478],121:[65479],122:[65480],123:[65481],144:[65407],145:[65300],225:[65027]},h={Again:[65382],AllCandidates:[65341],Alphanumeric:[65328],Alt:[65513,65513,65027],Attn:[64782],AltGraph:[65027],ArrowDown:[65364],ArrowLeft:[65361],ArrowRight:[65363],ArrowUp:[65362],Backspace:[65288],CapsLock:[65509],Cancel:[65385],Clear:[65291],Convert:[65313],Copy:[64789],Crsel:[64796],CrSel:[64796],CodeInput:[65335],Compose:[65312],Control:[65507,65507,65508],ContextMenu:[65383],Delete:[65535],Down:[65364],End:[65367],Enter:[65293],EraseEof:[64774],Escape:[65307],Execute:[65378],Exsel:[64797],ExSel:[64797],F1:[65470],F2:[65471],F3:[65472],F4:[65473],F5:[65474],F6:[65475],F7:[65476],F8:[65477],F9:[65478],F10:[65479],F11:[65480],F12:[65481],F13:[65482],F14:[65483],F15:[65484],F16:[65485],F17:[65486],F18:[65487],F19:[65488],F20:[65489],F21:[65490],F22:[65491],F23:[65492],F24:[65493],Find:[65384],GroupFirst:[65036],GroupLast:[65038],GroupNext:[65032],GroupPrevious:[65034],FullWidth:null,HalfWidth:null,HangulMode:[65329],Hankaku:[65321],HanjaMode:[65332],Help:[65386],Hiragana:[65317],HiraganaKatakana:[65319],Home:[65360],Hyper:[65517,65517,65518],Insert:[65379],JapaneseHiragana:[65317],JapaneseKatakana:[65318],JapaneseRomaji:[65316],JunjaMode:[65336],KanaMode:[65325],KanjiMode:[65313],Katakana:[65318],Left:[65361],Meta:[65511,65511,65512],ModeChange:[65406],NumLock:[65407],PageDown:[65366],PageUp:[65365],Pause:[65299],Play:[64790],PreviousCandidate:[65342],PrintScreen:[65377],Redo:[65382],Right:[65363],RomanCharacters:null,Scroll:[65300],Select:[65376],Separator:[65452],Shift:[65505,65505,65506],SingleCandidate:[65340],Super:[65515,65515,65516],Tab:[65289],UIKeyInputDownArrow:[65364],UIKeyInputEscape:[65307],UIKeyInputLeftArrow:[65361],UIKeyInputRightArrow:[65363],UIKeyInputUpArrow:[65362],Up:[65362],Undo:[65381],Win:[65515],Zenkaku:[65320],ZenkakuHankaku:[65322]},a={65027:!0,65505:!0,65506:!0,65507:!0,65508:!0,65509:!0,65511:!0,65512:!0,65513:!0,65514:!0,65515:!0,65516:!0};this.modifiers=new Guacamole.Keyboard.ModifierState,this.pressed={};var f={},o={},m={},p=null,g=null,y=function(e,t){return e?e[t]||e[0]:null},v=function(e){return 0<=e&&e<=255||16777216==(4294901760&e)};function w(e,t,n){if(!e)return null;var a=e.indexOf("U+");if(0<=a)var o=e.substring(a+2),r=String.fromCharCode(parseInt(o,16));else{if(1!==e.length||3===t)return y(h[e],t);r=e}return!0===n?r=r.toUpperCase():!1===n&&(r=r.toLowerCase()),S(r.charCodeAt(0))}function S(e){return(t=e)<=31||127<=t&&t<=159?65280|e:0<=e&&e<=255?e:256<=e&&e<=1114111?16777216|e:null;var t}function T(e,t){return y(n[e],t)}var b=function(e,t){if(!t)return!1;var n=t.indexOf("U+");return-1===n||(e!==parseInt(t.substring(n+2),16)||(65<=e&&e<=90||48<=e&&e<=57))};this.press=function(e){if(null!==e){if(i.pressed[e]||(i.pressed[e]=!0,!i.onkeydown))return o[e]||!1;var t=i.onkeydown(e);return o[e]=t,window.clearTimeout(p),window.clearInterval(g),a[e]||(p=window.setTimeout(function(){g=window.setInterval(function(){i.onkeyup(e),i.onkeydown(e)},50)},500)),t}},this.release=function(e){i.pressed[e]&&(delete i.pressed[e],delete f[e],window.clearTimeout(p),window.clearInterval(g),null!==e&&i.onkeyup&&i.onkeyup(e))},this.type=function(e){for(var t=0;t<e.length;t++){var n=S(e.codePointAt?e.codePointAt(t):e.charCodeAt(t));i.press(n),i.release(n)}},this.reset=function(){for(var e in i.pressed)i.release(parseInt(e));d=[]};function G(e,t,n,a){var o;if(-1===n.indexOf(a.keysym))if(e&&!1===t)for(o=0;o<n.length;o++)i.release(n[o]);else if(!e&&t){for(o=0;o<n.length;o++)if(i.pressed[n[o]])return;var r=n[0];a.keysym&&(f[r]=!0),i.press(r)}}function I(e,t){var n=Guacamole.Keyboard.ModifierState.fromKeyboardEvent(e);G(i.modifiers.alt,n.alt,[65513,65514,65027],t),G(i.modifiers.shift,n.shift,[65505,65506],t),G(i.modifiers.ctrl,n.ctrl,[65507,65508],t),G(i.modifiers.meta,n.meta,[65511,65512],t),G(i.modifiers.hyper,n.hyper,[65515,65516],t),i.modifiers=n}var E=function(){for(var e in i.pressed)if(!f[e])return!1;return!0};function C(){var e,t=L();if(t){for(;e=t,null!==(t=L()););return E()&&i.reset(),e.defaultPrevented}}function k(e){return"location"in e?e.location:"keyLocation"in e?e.keyLocation:0}function A(e){return!e[t]&&(e[t]=!0)}var L=function(){var e=d[0];if(!e)return null;if(!(e instanceof u))return e instanceof l&&!s.keyupUnreliable?(n=e.keysym)?(i.release(n),delete m[e.keyCode],e.defaultPrevented=!0,d.shift()):(i.reset(),e):d.shift();var t,n=null,a=[];if(e.reliable?(n=e.keysym,a=d.splice(0,1)):d[1]instanceof c?(n=d[1].keysym,a=d.splice(0,2)):d[1]&&(n=e.keysym,a=d.splice(0,1)),0<a.length){if(n){t=n,i.modifiers.ctrl&&i.modifiers.alt&&(65<=t&&t<=90||97<=t&&t<=122||(t<=255||16777216==(4278190080&t))&&(i.release(65507),i.release(65508),i.release(65513),i.release(65514)));var o=!i.press(n);m[e.keyCode]=n,e.keyupReliable||i.release(n);for(var r=0;r<a.length;r++)a[r].defaultPrevented=o}return e}return null};this.listenTo=function(t){t.addEventListener("keydown",function(e){var t,n;i.onkeydown&&A(e)&&(window.event?t=window.event.keyCode:e.which&&(t=e.which),n=new u(t,e.keyIdentifier,e.key,k(e)),I(e,n),229!==t&&(d.push(n),C()&&e.preventDefault()))},!0),t.addEventListener("keypress",function(e){var t,n;(i.onkeydown||i.onkeyup)&&A(e)&&(window.event?t=window.event.keyCode:e.which&&(t=e.which),n=new c(t),I(e,n),d.push(n),C()&&e.preventDefault())},!0),t.addEventListener("keyup",function(e){var t,n;i.onkeyup&&A(e)&&(e.preventDefault(),window.event?t=window.event.keyCode:e.which&&(t=e.which),n=new l(t,e.keyIdentifier,e.key,k(e)),I(e,n),d.push(n),C())},!0);function n(e){(i.onkeydown||i.onkeyup)&&A(e)&&e.data&&!e.isComposing&&(t.removeEventListener("compositionend",a,!1),i.type(e.data))}var a=function(e){(i.onkeydown||i.onkeyup)&&A(e)&&e.data&&(t.removeEventListener("input",n,!1),i.type(e.data))};t.addEventListener("input",n,!1),t.addEventListener("compositionend",a,!1)},e&&i.listenTo(e)},Guacamole.Keyboard._nextID=0,Guacamole.Keyboard.ModifierState=function(){this.shift=!1,this.ctrl=!1,this.alt=!1,this.meta=!1,this.hyper=!1},Guacamole.Keyboard.ModifierState.fromKeyboardEvent=function(e){var t=new Guacamole.Keyboard.ModifierState;return t.shift=e.shiftKey,t.ctrl=e.ctrlKey,t.alt=e.altKey,t.meta=e.metaKey,e.getModifierState&&(t.hyper=e.getModifierState("OS")||e.getModifierState("Super")||e.getModifierState("Hyper")||e.getModifierState("Win")),t},(Guacamole=Guacamole||{}).Layer=function(e,t){var m=this,i=document.createElement("canvas"),p=i.getContext("2d");p.save();function n(e,t){e=e||0,t=t||0;var n,a,o=64*Math.ceil(e/64),r=64*Math.ceil(t/64);i.width!==o||i.height!==r?(n=null,g||0===i.width||0===i.height||((n=document.createElement("canvas")).width=Math.min(m.width,e),n.height=Math.min(m.height,t),n.getContext("2d").drawImage(i,0,0,n.width,n.height,0,0,n.width,n.height)),a=p.globalCompositeOperation,i.width=o,i.height=r,n&&p.drawImage(n,0,0,n.width,n.height,0,0,n.width,n.height),p.globalCompositeOperation=a,u=0,p.save()):m.reset(),m.width=e,m.height=t}var g=!0,s=!0,u=0,a={1:"destination-in",2:"destination-out",4:"source-in",6:"source-atop",8:"source-out",9:"destination-atop",10:"xor",11:"destination-over",12:"copy",14:"source-over",15:"lighter"};function y(e,t,n,a){var o=n+e,r=a+t,i=o>m.width?o:m.width,s=r>m.height?r:m.height;m.resize(i,s)}this.autosize=!1,this.width=e,this.height=t,this.getCanvas=function(){return i},this.toCanvas=function(){var e=document.createElement("canvas");return e.width=m.width,e.height=m.height,e.getContext("2d").drawImage(m.getCanvas(),0,0),e},this.resize=function(e,t){e===m.width&&t===m.height||n(e,t)},this.drawImage=function(e,t,n){m.autosize&&y(e,t,n.width,n.height),p.drawImage(n,e,t),g=!1},this.transfer=function(e,t,n,a,o,r,i,s){var u=e.getCanvas();if(!(t>=u.width||n>=u.height)&&(t+a>u.width&&(a=u.width-t),n+o>u.height&&(o=u.height-n),0!==a&&0!==o)){m.autosize&&y(r,i,a,o);for(var c=e.getCanvas().getContext("2d").getImageData(t,n,a,o),l=p.getImageData(r,i,a,o),d=0;d<a*o*4;d+=4){var h=new Guacamole.Layer.Pixel(c.data[d],c.data[d+1],c.data[d+2],c.data[d+3]),f=new Guacamole.Layer.Pixel(l.data[d],l.data[d+1],l.data[d+2],l.data[d+3]);s(h,f),l.data[d]=f.red,l.data[d+1]=f.green,l.data[d+2]=f.blue,l.data[d+3]=f.alpha}p.putImageData(l,r,i),g=!1}},this.put=function(e,t,n,a,o,r,i){var s,u=e.getCanvas();t>=u.width||n>=u.height||(t+a>u.width&&(a=u.width-t),n+o>u.height&&(o=u.height-n),0!==a&&0!==o&&(m.autosize&&y(r,i,a,o),s=e.getCanvas().getContext("2d").getImageData(t,n,a,o),p.putImageData(s,r,i),g=!1))},this.copy=function(e,t,n,a,o,r,i){var s=e.getCanvas();t>=s.width||n>=s.height||(t+a>s.width&&(a=s.width-t),n+o>s.height&&(o=s.height-n),0!==a&&0!==o&&(m.autosize&&y(r,i,a,o),p.drawImage(s,t,n,a,o,r,i,a,o),g=!1))},this.moveTo=function(e,t){s&&(p.beginPath(),s=!1),m.autosize&&y(e,t,0,0),p.moveTo(e,t)},this.lineTo=function(e,t){s&&(p.beginPath(),s=!1),m.autosize&&y(e,t,0,0),p.lineTo(e,t)},this.arc=function(e,t,n,a,o,r){s&&(p.beginPath(),s=!1),m.autosize&&y(e,t,0,0),p.arc(e,t,n,a,o,r)},this.curveTo=function(e,t,n,a,o,r){s&&(p.beginPath(),s=!1),m.autosize&&y(o,r,0,0),p.bezierCurveTo(e,t,n,a,o,r)},this.close=function(){p.closePath(),s=!0},this.rect=function(e,t,n,a){s&&(p.beginPath(),s=!1),m.autosize&&y(e,t,n,a),p.rect(e,t,n,a)},this.clip=function(){p.clip(),s=!0},this.strokeColor=function(e,t,n,a,o,r,i){p.lineCap=e,p.lineJoin=t,p.lineWidth=n,p.strokeStyle="rgba("+a+","+o+","+r+","+i/255+")",p.stroke(),s=!(g=!1)},this.fillColor=function(e,t,n,a){p.fillStyle="rgba("+e+","+t+","+n+","+a/255+")",p.fill(),s=!(g=!1)},this.strokeLayer=function(e,t,n,a){p.lineCap=e,p.lineJoin=t,p.lineWidth=n,p.strokeStyle=p.createPattern(a.getCanvas(),"repeat"),p.stroke(),s=!(g=!1)},this.fillLayer=function(e){p.fillStyle=p.createPattern(e.getCanvas(),"repeat"),p.fill(),s=!(g=!1)},this.push=function(){p.save(),u++},this.pop=function(){0<u&&(p.restore(),u--)},this.reset=function(){for(;0<u;)p.restore(),u--;p.restore(),p.save(),p.beginPath(),s=!1},this.setTransform=function(e,t,n,a,o,r){p.setTransform(e,t,n,a,o,r)},this.transform=function(e,t,n,a,o,r){p.transform(e,t,n,a,o,r)},this.setChannelMask=function(e){p.globalCompositeOperation=a[e]},this.setMiterLimit=function(e){p.miterLimit=e},n(e,t),i.style.zIndex=-1},Guacamole.Layer.ROUT=2,Guacamole.Layer.ATOP=6,Guacamole.Layer.XOR=10,Guacamole.Layer.ROVER=11,Guacamole.Layer.OVER=14,Guacamole.Layer.PLUS=15,Guacamole.Layer.RIN=1,Guacamole.Layer.IN=4,Guacamole.Layer.OUT=8,Guacamole.Layer.RATOP=9,Guacamole.Layer.SRC=12,Guacamole.Layer.Pixel=function(e,t,n,a){this.red=e,this.green=t,this.blue=n,this.alpha=a},(Guacamole=Guacamole||{}).Mouse=function(o){var n=this;this.touchMouseThreshold=3,this.scrollThreshold=53,this.PIXELS_PER_LINE=18,this.PIXELS_PER_PAGE=16*this.PIXELS_PER_LINE,this.currentState=new Guacamole.Mouse.State(0,0,!1,!1,!1,!1,!1),this.onmousedown=null,this.onmouseup=null,this.onmousemove=null,this.onmouseout=null;var t=0,a=0;function r(e){e.stopPropagation(),e.preventDefault&&e.preventDefault(),e.returnValue=!1}function e(){t=n.touchMouseThreshold}function i(e){var t=e.deltaY||-e.wheelDeltaY||-e.wheelDelta;if(t?1===e.deltaMode?t=e.deltaY*n.PIXELS_PER_LINE:2===e.deltaMode&&(t=e.deltaY*n.PIXELS_PER_PAGE):t=e.detail*n.PIXELS_PER_LINE,(a+=t)<=-n.scrollThreshold){for(;n.onmousedown&&(n.currentState.up=!0,n.onmousedown(n.currentState)),n.onmouseup&&(n.currentState.up=!1,n.onmouseup(n.currentState)),(a+=n.scrollThreshold)<=-n.scrollThreshold;);a=0}if(a>=n.scrollThreshold){for(;n.onmousedown&&(n.currentState.down=!0,n.onmousedown(n.currentState)),n.onmouseup&&(n.currentState.down=!1,n.onmouseup(n.currentState)),(a-=n.scrollThreshold)>=n.scrollThreshold;);a=0}r(e)}o.addEventListener("contextmenu",function(e){r(e)},!1),o.addEventListener("mousemove",function(e){r(e),t?t--:(n.currentState.fromClientPosition(o,e.clientX,e.clientY),n.onmousemove&&n.onmousemove(n.currentState))},!1),o.addEventListener("mousedown",function(e){if(r(e),!t){switch(e.button){case 0:n.currentState.left=!0;break;case 1:n.currentState.middle=!0;break;case 2:n.currentState.right=!0}n.onmousedown&&n.onmousedown(n.currentState)}},!1),o.addEventListener("mouseup",function(e){if(r(e),!t){switch(e.button){case 0:n.currentState.left=!1;break;case 1:n.currentState.middle=!1;break;case 2:n.currentState.right=!1}n.onmouseup&&n.onmouseup(n.currentState)}},!1),o.addEventListener("mouseout",function(e){for(var t=(e=e||window.event).relatedTarget||e.toElement;t;){if(t===o)return;t=t.parentNode}r(e),(n.currentState.left||n.currentState.middle||n.currentState.right)&&(n.currentState.left=!1,n.currentState.middle=!1,n.currentState.right=!1,n.onmouseup&&n.onmouseup(n.currentState)),n.onmouseout&&n.onmouseout()},!1),o.addEventListener("selectstart",function(e){r(e)},!1),o.addEventListener("touchmove",e,!1),o.addEventListener("touchstart",e,!1),o.addEventListener("touchend",e,!1),o.addEventListener("DOMMouseScroll",i,!1),o.addEventListener("mousewheel",i,!1),o.addEventListener("wheel",i,!1);var s=function(){var e=document.createElement("div");if(!("cursor"in e.style))return!1;try{e.style.cursor="url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX///+nxBvIAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJggg==) 0 0, auto"}catch(e){return!1}return/\burl\([^()]*\)\s+0\s+0\b/.test(e.style.cursor||"")}();this.setCursor=function(e,t,n){if(s){var a=e.toDataURL("image/png");return o.style.cursor="url("+a+") "+t+" "+n+", auto",!0}return!1}},Guacamole.Mouse.State=function(e,t,n,a,o,r,i){var s=this;this.x=e,this.y=t,this.left=n,this.middle=a,this.right=o,this.up=r,this.down=i,this.fromClientPosition=function(e,t,n){s.x=t-e.offsetLeft,s.y=n-e.offsetTop;for(var a,o,r=e.offsetParent;r&&r!==document.body;)s.x-=r.offsetLeft-r.scrollLeft,s.y-=r.offsetTop-r.scrollTop,r=r.offsetParent;r&&(a=document.body.scrollLeft||document.documentElement.scrollLeft,o=document.body.scrollTop||document.documentElement.scrollTop,s.x-=r.offsetLeft-a,s.y-=r.offsetTop-o)}},Guacamole.Mouse.Touchpad=function(i){var s=this;this.scrollThreshold=20*(window.devicePixelRatio||1),this.clickTimingThreshold=250,this.clickMoveThreshold=10*(window.devicePixelRatio||1),this.currentState=new Guacamole.Mouse.State(0,0,!1,!1,!1,!1,!1),this.onmousedown=null,this.onmouseup=null,this.onmousemove=null;var u=0,c=0,l=0,d=0,h=0,a={1:"left",2:"right",3:"middle"},o=!1,r=null;i.addEventListener("touchend",function(e){var t,n;e.preventDefault(),o&&0===e.touches.length&&(t=(new Date).getTime(),n=a[u],s.currentState[n]&&(s.currentState[n]=!1,s.onmouseup&&s.onmouseup(s.currentState),r&&(window.clearTimeout(r),r=null)),t-d<=s.clickTimingThreshold&&h<s.clickMoveThreshold&&(s.currentState[n]=!0,s.onmousedown&&s.onmousedown(s.currentState),r=window.setTimeout(function(){s.currentState[n]=!1,s.onmouseup&&s.onmouseup(s.currentState),o=!1},s.clickTimingThreshold)),r||(o=!1))},!1),i.addEventListener("touchstart",function(e){var t;e.preventDefault(),u=Math.min(e.touches.length,3),r&&(window.clearTimeout(r),r=null),o||(o=!0,t=e.touches[0],c=t.clientX,l=t.clientY,d=(new Date).getTime(),h=0)},!1),i.addEventListener("touchmove",function(e){e.preventDefault();var t,n,a=e.touches[0],o=a.clientX-c,r=a.clientY-l;h+=Math.abs(o)+Math.abs(r),1===u?(t=1+h/((new Date).getTime()-d),s.currentState.x+=o*t,s.currentState.y+=r*t,s.currentState.x<0?s.currentState.x=0:s.currentState.x>=i.offsetWidth&&(s.currentState.x=i.offsetWidth-1),s.currentState.y<0?s.currentState.y=0:s.currentState.y>=i.offsetHeight&&(s.currentState.y=i.offsetHeight-1),s.onmousemove&&s.onmousemove(s.currentState),c=a.clientX,l=a.clientY):2===u&&Math.abs(r)>=s.scrollThreshold&&(n=0<r?"down":"up",s.currentState[n]=!0,s.onmousedown&&s.onmousedown(s.currentState),s.currentState[n]=!1,s.onmouseup&&s.onmouseup(s.currentState),c=a.clientX,l=a.clientY)},!1)},Guacamole.Mouse.Touchscreen=function(n){var o=this,a=!1,r=null,i=null,s=null,u=null;function c(e){o.currentState[e]||(o.currentState[e]=!0,o.onmousedown&&o.onmousedown(o.currentState))}function l(e){o.currentState[e]&&(o.currentState[e]=!1,o.onmouseup&&o.onmouseup(o.currentState))}function d(e,t){o.currentState.fromClientPosition(n,e,t),o.onmousemove&&o.onmousemove(o.currentState)}function h(e){var t=e.touches[0]||e.changedTouches[0],n=t.clientX-r,a=t.clientY-i;return Math.sqrt(n*n+a*a)>=o.clickMoveThreshold}function f(){window.clearTimeout(s),window.clearTimeout(u),a=!1}this.scrollThreshold=20*(window.devicePixelRatio||1),this.clickTimingThreshold=250,this.clickMoveThreshold=16*(window.devicePixelRatio||1),this.longPressThreshold=500,this.currentState=new Guacamole.Mouse.State(0,0,!1,!1,!1,!1,!1),this.onmousedown=null,this.onmouseup=null,this.onmousemove=null,n.addEventListener("touchend",function(e){var t;a&&(0===e.touches.length&&1===e.changedTouches.length?(window.clearTimeout(u),l("left"),h(e)||(e.preventDefault(),o.currentState.left||(d((t=e.changedTouches[0]).clientX,t.clientY),c("left"),s=window.setTimeout(function(){l("left"),f()},o.clickTimingThreshold)))):f())},!1),n.addEventListener("touchstart",function(n){var e;1===n.touches.length?(n.preventDefault(),e=n.touches[0],a=!0,r=e.clientX,i=e.clientY,window.clearTimeout(s),u=window.setTimeout(function(){var e,t=n.touches[0];d(t.clientX,t.clientY),c(e="right"),l(e),f()},o.longPressThreshold)):f()},!1),n.addEventListener("touchmove",function(e){var t;a&&(h(e)&&window.clearTimeout(u),1===e.touches.length?o.currentState.left&&(e.preventDefault(),d((t=e.touches[0]).clientX,t.clientY)):f())},!1)},(Guacamole=(Guacamole=Guacamole||{})||{}).Object=function(r,e){var i=this,s={};this.index=e,this.onbody=function(e,t,n){var a=function(e){var t=s[e];if(!t)return null;var n=t.shift();return 0===t.length&&delete s[e],n}(n);a&&a(e,t)},this.onundefine=null,this.requestInputStream=function(e,t){var n,a,o;t&&(a=t,(o=s[n=e])||(o=[],s[n]=o),o.push(a)),r.requestObjectInputStream(i.index,e)},this.createOutputStream=function(e,t){return r.createObjectOutputStream(i.index,e,t)}},Guacamole.Object.ROOT_STREAM="/",Guacamole.Object.STREAM_INDEX_MIMETYPE="application/vnd.glyptodon.guacamole.stream-index+json",(Guacamole=Guacamole||{}).OnScreenKeyboard=function(a){function p(e,t){e.classList?e.classList.add(t):e.className+=" "+t}function r(e,n){e.classList?e.classList.remove(n):e.className=e.className.replace(/([^ ]+)[ ]*/g,function(e,t){return t===n?"":e})}function g(t,n,a,o){this.width=n,this.height=a,this.scale=function(e){t.style.width=n*e+"px",t.style.height=a*e+"px",o&&(t.style.lineHeight=a*e+"px",t.style.fontSize=e+"px")}}function i(e){var t=w.keys[e];if(!t)return null;for(var n=t.length-1;0<=n;n--){var a=t[n];if(function(e){for(var t=0;t<e.length;t++){if(!(e[t]in s))return!1}return!0}(a.requires))return a}return null}function y(e,t){var n,a,o;u[e]||(p(t,"guac-keyboard-pressed"),(n=i(e)).modifier?(a="guac-keyboard-modifier-"+b(n.modifier),(o=s[n.modifier])?(r(c,a),delete s[n.modifier],w.onkeyup&&w.onkeyup(o)):(p(c,a),s[n.modifier]=n.keysym,w.onkeydown&&w.onkeydown(n.keysym))):w.onkeydown&&w.onkeydown(n.keysym),u[e]=!0)}function v(e,t){var n;u[e]&&(r(t,"guac-keyboard-pressed"),!(n=i(e)).modifier&&w.onkeyup&&w.onkeyup(n.keysym),u[e]=!1)}var w=this,s={},u={},S=[],T=0,c=document.createElement("div");c.className="guac-keyboard",c.onselectstart=c.onmousemove=c.onmouseup=c.onmousedown=function(e){return T&&T--,e.stopPropagation(),!1},this.touchMouseThreshold=3,this.onkeydown=null,this.onkeyup=null,this.layout=new Guacamole.OnScreenKeyboard.Layout(a),this.getElement=function(){return c},this.resize=function(e){for(var t=Math.floor(10*e/w.layout.width)/10,n=0;n<S.length;n++){S[n].scale(t)}};this.keys=function(e){var t,n={};for(t in a.keys)n[t]=function(e,t){if(t instanceof Array){for(var n=[],a=0;a<t.length;a++)n.push(new Guacamole.OnScreenKeyboard.Key(t[a],e));return n}return"number"==typeof t?[new Guacamole.OnScreenKeyboard.Key({name:e,keysym:t})]:"string"==typeof t?[new Guacamole.OnScreenKeyboard.Key({name:e,title:t})]:[new Guacamole.OnScreenKeyboard.Key(t,e)]}(t,e[t]);return n}(a.keys);var b=function(e){return e.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[^A-Za-z0-9]+/g,"-").toLowerCase()};!function e(t,n,a){var o=document.createElement("div");if(a&&p(o,"guac-keyboard-"+b(a)),n instanceof Array)for(p(o,"guac-keyboard-group"),i=0;i<n.length;i++)e(o,n[i]);else if(n instanceof Object){p(o,"guac-keyboard-group");for(var r=Object.keys(n).sort(),i=0;i<r.length;i++){a=r[i];e(o,n[a],a)}}else if("number"==typeof n)p(o,"guac-keyboard-gap"),S.push(new g(o,n,n));else if("string"==typeof n){var s=n;1===s.length&&(s="0x"+s.charCodeAt(0).toString(16)),p(o,"guac-keyboard-key-container");var u=document.createElement("div");u.className="guac-keyboard-key guac-keyboard-key-"+b(s);var c=w.keys[n];if(c)for(i=0;i<c.length;i++){var l=c[i],d=document.createElement("div");d.className="guac-keyboard-cap",d.textContent=l.title;for(var h=0;h<l.requires.length;h++){var f=l.requires[h];p(d,"guac-keyboard-requires-"+b(f)),p(u,"guac-keyboard-uses-"+b(f))}u.appendChild(d)}o.appendChild(u),S.push(new g(o,w.layout.keyWidths[n]||1,1,!0));function m(e){e.preventDefault(),0===T&&v(n,u)}u.addEventListener("touchstart",function(e){e.preventDefault(),T=w.touchMouseThreshold,y(n,u)},!0),u.addEventListener("touchend",function(e){e.preventDefault(),T=w.touchMouseThreshold,v(n,u)},!0),u.addEventListener("mousedown",function(e){e.preventDefault(),0===T&&y(n,u)},!0),u.addEventListener("mouseup",m,!0),u.addEventListener("mouseout",m,!0)}t.appendChild(o)}(c,a.layout)},Guacamole.OnScreenKeyboard.Layout=function(e){this.language=e.language,this.type=e.type,this.keys=e.keys,this.layout=e.layout,this.width=e.width,this.keyWidths=e.keyWidths||{}},Guacamole.OnScreenKeyboard.Key=function(e,t){this.name=t||e.name,this.title=e.title||this.name,this.keysym=e.keysym||function(e){if(!e||1!==e.length)return null;var t=e.charCodeAt(0);return 0<=t&&t<=255?t:256<=t&&t<=1114111?16777216|t:null}(this.title),this.modifier=e.modifier,this.requires=e.requires||[]},(Guacamole=Guacamole||{}).OutputStream=function(t,e){var n=this;this.index=e,this.onack=null,this.sendBlob=function(e){t.sendBlob(n.index,e)},this.sendEnd=function(){t.endStream(n.index)}},(Guacamole=Guacamole||{}).Parser=function(){var i=this,s="",u=[],c=-1,l=0;this.receive=function(e){for(4096<l&&l<=c&&(s=s.substring(l),c-=l,l=0),s+=e;c<s.length;){if(l<=c){var t=s.substring(l,c),n=s.substring(c,c+1);if(u.push(t),";"==n){var a=u.shift();null!=i.oninstruction&&i.oninstruction(a,u),u.length=0}else if(","!=n)throw new Error("Illegal terminator.");l=c+1}var o=s.indexOf(".",l);if(-1==o){l=s.length;break}var r=parseInt(s.substring(c+1,o));if(isNaN(r))throw new Error("Non-numeric character in element length.");c=(l=o+1)+r}},this.oninstruction=null},(Guacamole=Guacamole||{}).RawAudioFormat=function(e){this.bytesPerSample=e.bytesPerSample,this.channels=e.channels,this.rate=e.rate},Guacamole.RawAudioFormat.parse=function(e){var t,n=null,a=1;if("audio/L8;"===e.substring(0,9))e=e.substring(9),t=1;else{if("audio/L16;"!==e.substring(0,10))return null;e=e.substring(10),t=2}for(var o=e.split(","),r=0;r<o.length;r++){var i=o[r],s=i.indexOf("=");if(-1===s)return null;var u=i.substring(0,s),c=i.substring(s+1);switch(u){case"channels":a=parseInt(c);break;case"rate":n=parseInt(c);break;default:return null}}return null===n?null:new Guacamole.RawAudioFormat({bytesPerSample:t,channels:a,rate:n})},(Guacamole=Guacamole||{}).SessionRecording=function(t){var i=this,s=[],r=[],u=0,c=0,l=new Guacamole.SessionRecording._PlaybackTunnel,d=new Guacamole.Client(l),h=-1,a=null,o=null,e=null;d.connect(),d.getDisplay().showCursor(!1),t.oninstruction=function(e,t){var n,a,o=new Guacamole.SessionRecording._Frame.Instruction(e,t.slice());r.push(o),u+=o.getSize(),"sync"===e&&(n=parseInt(t[0]),a=new Guacamole.SessionRecording._Frame(n,r),s.push(a),(1===s.length||16384<=u&&5e3<=n-c)&&(a.keyframe=!0,c=n,u=0),r=[],i.onprogress&&i.onprogress(i.getDuration()))};function f(e){return 0===s.length?0:e-s[0].timestamp}function m(a,o,r){n(),e=window.setTimeout(function(){for(var e=a;0<=e;e--){var t=s[e];if(e===h)break;if(t.clientState){d.importState(t.clientState);break}}e++;for(var n=(new Date).getTime();e<=a;e++){if(5<=(new Date).getTime()-n)break;!function(e){for(var t=s[e],n=0;n<t.instructions.length;n++){var a=t.instructions[n];l.receiveInstruction(a.opcode,a.args)}t.keyframe&&!t.clientState&&d.exportState(function(e){t.clientState=e})}(e)}h=e-1,i.onseek&&i.onseek(i.getPosition()),h!==a?m(a,o,Math.max(r-((new Date).getTime()-n),0)):o()},r||0)}var n=function(){window.clearTimeout(e)};this.onprogress=null,this.onplay=null,this.onpause=null,this.onseek=null,this.connect=function(e){t.connect(e)},this.disconnect=function(){t.disconnect()},this.getDisplay=function(){return d.getDisplay()},this.isPlaying=function(){return!!a},this.getPosition=function(){return-1===h?0:f(s[h].timestamp)},this.getDuration=function(){return 0===s.length?0:f(s[s.length-1].timestamp)},this.play=function(){var e;!i.isPlaying()&&h+1<s.length&&(i.onplay&&i.onplay(),e=s[h+1],a=e.timestamp,o=(new Date).getTime(),function e(){var t,n;h+1<s.length?(t=s[h+1].timestamp-a+o,n=Math.max(t-(new Date).getTime(),0),m(h+1,function(){e()},n)):i.pause()}())},this.seek=function(e,t){var n;0!==s.length&&(n=i.isPlaying(),i.pause(),m(function e(t,n,a){if(t===n)return t;var o=Math.floor((t+n)/2),r=f(s[o].timestamp);return a<r&&t<o?e(t,o-1,a):r<a&&o<n?e(o+1,n,a):o}(0,s.length-1,e),function(){n&&i.play(),t&&t()}))},this.pause=function(){n(),i.isPlaying()&&(i.onpause&&i.onpause(),o=a=null)}},Guacamole.SessionRecording._Frame=function(e,t){this.keyframe=!1,this.timestamp=e,this.instructions=t,this.clientState=null},Guacamole.SessionRecording._Frame.Instruction=function(e,t){var n=this;this.opcode=e,this.args=t,this.getSize=function(){for(var e=n.opcode.length,t=0;t<n.args.length;t++)e+=n.args[t].length;return e}},Guacamole.SessionRecording._PlaybackTunnel=function(){var n=this;this.connect=function(){},this.sendMessage=function(){},this.disconnect=function(){},this.receiveInstruction=function(e,t){n.oninstruction&&n.oninstruction(e,t)}},(Guacamole=Guacamole||{}).Status=function(e,t){var n=this;this.code=e,this.message=t,this.isError=function(){return n.code<0||255<n.code}},Guacamole.Status.Code={SUCCESS:0,UNSUPPORTED:256,SERVER_ERROR:512,SERVER_BUSY:513,UPSTREAM_TIMEOUT:514,UPSTREAM_ERROR:515,RESOURCE_NOT_FOUND:516,RESOURCE_CONFLICT:517,RESOURCE_CLOSED:518,UPSTREAM_NOT_FOUND:519,UPSTREAM_UNAVAILABLE:520,SESSION_CONFLICT:521,SESSION_TIMEOUT:522,SESSION_CLOSED:523,CLIENT_BAD_REQUEST:768,CLIENT_UNAUTHORIZED:769,CLIENT_FORBIDDEN:771,CLIENT_TIMEOUT:776,CLIENT_OVERRUN:781,CLIENT_BAD_TYPE:783,CLIENT_TOO_MANY:797},Guacamole.Status.Code.fromHTTPCode=function(e){switch(e){case 400:return Guacamole.Status.Code.CLIENT_BAD_REQUEST;case 403:return Guacamole.Status.Code.CLIENT_FORBIDDEN;case 404:return Guacamole.Status.Code.RESOURCE_NOT_FOUND;case 429:return Guacamole.Status.Code.CLIENT_TOO_MANY;case 503:return Guacamole.Status.Code.SERVER_BUSY}return Guacamole.Status.Code.SERVER_ERROR},Guacamole.Status.Code.fromWebSocketCode=function(e){switch(e){case 1e3:return Guacamole.Status.Code.SUCCESS;case 1006:case 1015:return Guacamole.Status.Code.UPSTREAM_NOT_FOUND;case 1001:case 1012:case 1013:case 1014:return Guacamole.Status.Code.UPSTREAM_UNAVAILABLE}return Guacamole.Status.Code.SERVER_ERROR},(Guacamole=Guacamole||{}).StringReader=function(e){var n=this,t=new Guacamole.ArrayBufferReader(e),r=0,i=0;t.ondata=function(e){var t=function(e){for(var t="",n=new Uint8Array(e),a=0;a<n.length;a++){var o=n[a];0===r?127==(127|o)?t+=String.fromCharCode(o):223==(31|o)?(i=31&o,r=1):239==(15|o)?(i=15&o,r=2):247==(7|o)?(i=7&o,r=3):t+="�":191==(63|o)?(i=i<<6|63&o,0===--r&&(t+=String.fromCharCode(i))):(r=0,t+="�")}return t}(e);n.ontext&&n.ontext(t)},t.onend=function(){n.onend&&n.onend()},this.ontext=null,this.onend=null},(Guacamole=Guacamole||{}).StringWriter=function(e){var t=this,n=new Guacamole.ArrayBufferWriter(e),s=new Uint8Array(8192),u=0;function c(e){var t,n,a,o;if(e<=127)t=0,n=1;else if(e<=2047)t=192,n=2;else if(e<=65535)t=224,n=3;else{if(!(e<=2097151))return void c(65533);t=240,n=4}u+(a=n)>=s.length&&((o=new Uint8Array(2*(u+a))).set(s),s=o);for(var r=(u+=a)-1,i=1;i<n;i++)s[r--]=128|63&e,e>>=6;s[r]=t|e}n.onack=function(e){t.onack&&t.onack(e)},this.sendText=function(e){e.length&&n.sendData(function(e){for(var t=0;t<e.length;t++){c(e.charCodeAt(t))}if(0<u){var n=s.subarray(0,u);return u=0,n}}(e))},this.sendEnd=function(){n.sendEnd()},this.onack=null},(Guacamole=Guacamole||{}).Tunnel=function(){this.connect=function(e){},this.disconnect=function(){},this.sendMessage=function(e){},this.setState=function(e){e!==this.state&&(this.state=e,this.onstatechange&&this.onstatechange(e))},this.isConnected=function(){return this.state===Guacamole.Tunnel.State.OPEN||this.state===Guacamole.Tunnel.State.UNSTABLE},this.state=Guacamole.Tunnel.State.CONNECTING,this.receiveTimeout=15e3,this.unstableThreshold=1500,this.uuid=null,this.onerror=null,this.onstatechange=null,this.oninstruction=null,this.onEvent=null},Guacamole.Tunnel.INTERNAL_DATA_OPCODE="",Guacamole.Tunnel.State={CONNECTING:0,OPEN:1,CLOSED:2,UNSTABLE:3},Guacamole.HTTPTunnel=function(e,t,n){var p=this,a=e+"?connect",o=e+"?read:",r=e+"?write:",g=1,i=0,y=g,s=!1,u="",c=!!t,l=null,d=null,h=null,f=n||{};function m(e,t){for(var n in t)e.setRequestHeader(n,t[n])}function v(){window.clearTimeout(l),window.clearTimeout(d),p.state===Guacamole.Tunnel.State.UNSTABLE&&p.setState(Guacamole.Tunnel.State.OPEN),l=window.setTimeout(function(){w(new Guacamole.Status(Guacamole.Status.Code.UPSTREAM_TIMEOUT,"Server timeout."))},p.receiveTimeout),d=window.setTimeout(function(){p.setState(Guacamole.Tunnel.State.UNSTABLE)},p.unstableThreshold)}function w(e){window.clearTimeout(l),window.clearTimeout(d),window.clearInterval(h),p.state!==Guacamole.Tunnel.State.CLOSED&&(e.code!==Guacamole.Status.Code.SUCCESS&&p.onerror&&(p.state!==Guacamole.Tunnel.State.CONNECTING&&e.code===Guacamole.Status.Code.RESOURCE_NOT_FOUND||p.onerror(e)),s=!1,p.setState(Guacamole.Tunnel.State.CLOSED))}function S(e){var t,n=parseInt(e.getResponseHeader("Guacamole-Status-Code"));n?(t=e.getResponseHeader("Guacamole-Error-Message"),w(new Guacamole.Status(n,t))):e.status?w(new Guacamole.Status(Guacamole.Status.Code.fromHTTPCode(e.status),e.statusText)):w(new Guacamole.Status(Guacamole.Status.Code.UPSTREAM_NOT_FOUND))}this.sendMessage=function(){if(p.isConnected()&&0!==arguments.length){for(var e=n(arguments[0]),t=1;t<arguments.length;t++)e+=","+n(arguments[t]);u+=e+=";",s||function e(){if(!p.isConnected())return;{var t;0<u.length?(s=!0,(t=new XMLHttpRequest).open("POST",r+p.uuid),t.withCredentials=c,m(t,f),t.setRequestHeader("Content-type","application/octet-stream"),t.onreadystatechange=function(){4===t.readyState&&(v(),200!==t.status?S(t):e())},t.send(u),u=""):s=!1}}()}function n(e){var t=new String(e);return t.length+"."+t}};var T=0;function b(){var e=new XMLHttpRequest;return e.open("GET",o+p.uuid+":"+T++),e.withCredentials=c,m(e,f),e.send(null),e}this.connect=function(e){v(),p.setState(Guacamole.Tunnel.State.CONNECTING);var t=new XMLHttpRequest;t.onreadystatechange=function(){4===t.readyState&&(200===t.status?(v(),p.uuid=t.responseText,p.setState(Guacamole.Tunnel.State.OPEN),h=setInterval(function(){p.sendMessage("nop")},500),function s(u){var c=null,l=null,e=0,d=-1,h=0,f=new Array;function m(){if(p.isConnected()){if(!(u.readyState<2)){var t,e,n,a,o;try{t=u.status}catch(e){t=200}if(l||200!==t||(l=b()),3===u.readyState||4===u.readyState){if(v(),y===g&&(3!==u.readyState||c?4===u.readyState&&c&&clearInterval(c):c=setInterval(m,30)),0===u.status)return void p.disconnect();if(200!==u.status)return void S(u);try{e=u.responseText}catch(e){return}for(;d<e.length;){h<=d&&(n=e.substring(h,d),a=e.substring(d,d+1),f.push(n),";"===a&&(o=f.shift(),p.oninstruction&&p.oninstruction(o,f),f.length=0),h=d+1);var r=e.indexOf(".",h);if(-1===r){h=e.length;break}var i=parseInt(e.substring(d+1,r));if(0===i){c&&clearInterval(c),u.onreadystatechange=null,u.abort(),l&&s(l);break}d=(h=r+1)+i}}}}else null!==c&&clearInterval(c)}u.onreadystatechange=y===g?function(){3===u.readyState&&2<=++e&&(y=i,u.onreadystatechange=m),m()}:m,m()}(b())):S(t))},t.open("POST",a,!0),t.withCredentials=c,m(t,f),t.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset=UTF-8"),t.send(e)},this.disconnect=function(){w(new Guacamole.Status(Guacamole.Status.Code.SUCCESS,"Manually closed."))}},Guacamole.HTTPTunnel.prototype=new Guacamole.Tunnel,Guacamole.WebSocketTunnel=function(t){var e,n,a,l=this,o=null,r=null,i=null,s=null;function d(){window.clearTimeout(r),window.clearTimeout(i),l.state===Guacamole.Tunnel.State.UNSTABLE&&l.setState(Guacamole.Tunnel.State.OPEN),r=window.setTimeout(function(){h(new Guacamole.Status(Guacamole.Status.Code.UPSTREAM_TIMEOUT,"Server timeout."))},l.receiveTimeout),i=window.setTimeout(function(){l.setState(Guacamole.Tunnel.State.UNSTABLE)},l.unstableThreshold)}function h(e){window.clearTimeout(r),window.clearTimeout(i),window.clearInterval(s),l.state!==Guacamole.Tunnel.State.CLOSED&&(e.code!==Guacamole.Status.Code.SUCCESS&&l.onerror&&l.onerror(e),l.setState(Guacamole.Tunnel.State.CLOSED),o.close())}"ws:"!==t.substring(0,3)&&"wss:"!==t.substring(0,4)&&(e={"http:":"ws:","https:":"wss:"}[window.location.protocol],t="/"===t.substring(0,1)?e+"//"+window.location.host+t:(n=window.location.pathname.lastIndexOf("/"),a=window.location.pathname.substring(0,n+1),e+"//"+window.location.host+a+t)),this.getsocket=function(){return o},this.sendMessage=function(e){if(l.isConnected()&&0!==arguments.length){for(var t=a(e),n=1;n<arguments.length;n++)t+=","+a(arguments[n]);t+=";",o.send(t)}function a(e){var t=new String(e);return t.length+"."+t}},this.connect=function(e){function c(e){if("string"==typeof e)try{var t=JSON.parse(e);return!("object"!=typeof t||!t)}catch(e){return}}d(),o=new WebSocket(t+"?"+e,"guacamole"),l.setState(Guacamole.Tunnel.State.CONNECTING),o.onopen=function(e){d(),s=setInterval(function(){l.sendMessage(Guacamole.Tunnel.INTERNAL_DATA_OPCODE,"ping",(new Date).getTime())},500)},o.onclose=function(e){e.reason?h(new Guacamole.Status(parseInt(e.reason),e.reason)):e.code?h(new Guacamole.Status(Guacamole.Status.Code.fromWebSocketCode(e.code))):h(new Guacamole.Status(Guacamole.Status.Code.UPSTREAM_NOT_FOUND))},o.onmessage=function(e){d(),c(e.data)&&l.onEvent&&l.onEvent(e);var t=c(e.data)?JSON.parse(e.data).data:e.data,n=0,a=[];do{var o,r=t.indexOf(".",n);-1!==r?o=(n=r+1)+parseInt(t.substring(o+1,r)):h(new Guacamole.Status(Guacamole.Status.Code.SERVER_ERROR,"Incomplete instruction."));var i,s=t.substring(n,o),u=t.substring(o,o+1);a.push(s),";"===u&&(i=a.shift(),null===l.uuid&&(i===Guacamole.Tunnel.INTERNAL_DATA_OPCODE&&(l.uuid=a[0]),l.setState(Guacamole.Tunnel.State.OPEN)),i!==Guacamole.Tunnel.INTERNAL_DATA_OPCODE&&l.oninstruction&&l.oninstruction(i,a),a.length=0),n=o+1}while(n<t.length)}},this.disconnect=function(){h(new Guacamole.Status(Guacamole.Status.Code.SUCCESS,"Manually closed."))}},Guacamole.WebSocketTunnel.prototype=new Guacamole.Tunnel,Guacamole.ChainedTunnel=function(e){for(var o,r=this,i=[],s=null,t=0;t<arguments.length;t++)i.push(arguments[t]);function u(n){r.disconnect=n.disconnect,r.sendMessage=n.sendMessage;function t(e){if(e&&e.code===Guacamole.Status.Code.UPSTREAM_TIMEOUT)return i=[],0;var t=i.shift();return t&&(n.onerror=null,n.oninstruction=null,n.onstatechange=null,n.onEvnet=null,u(t)),t}function a(){n.onstatechange=r.onstatechange,n.oninstruction=r.oninstruction,n.onerror=r.onerror,n.onEvent=r.onEvent,r.uuid=n.uuid,s=n}n.onEvent=function(e){r.onEvent&&r.onEvent(e)},n.onstatechange=function(e){switch(e){case Guacamole.Tunnel.State.OPEN:a(),r.onstatechange&&r.onstatechange(e);break;case Guacamole.Tunnel.State.CLOSED:!t()&&r.onstatechange&&r.onstatechange(e)}},n.oninstruction=function(e,t){a(),r.oninstruction&&r.oninstruction(e,t)},n.onerror=function(e){!t(e)&&r.onerror&&r.onerror(e)},n.connect(o)}this.connect=function(e){o=e;var t=s||i.shift();t?u(t):r.onerror&&r.onerror(Guacamole.Status.Code.SERVER_ERROR,"No tunnels to try.")}},Guacamole.ChainedTunnel.prototype=new Guacamole.Tunnel,Guacamole.StaticHTTPTunnel=function(e,t,n){var o=this,r=null,i=n||{};this.sendMessage=function(){},this.connect=function(){o.disconnect(),o.setState(Guacamole.Tunnel.State.CONNECTING),(r=new XMLHttpRequest).open("GET",e),r.withCredentials=!!t,function(e,t){for(var n in t)e.setRequestHeader(n,t[n])}(r,i),r.responseType="text",r.send(null);var n=0,a=new Guacamole.Parser;a.oninstruction=function(e,t){o.oninstruction&&o.oninstruction(e,t)},r.onreadystatechange=function(){var e,t;3!==r.readyState&&4!==r.readyState||(o.setState(Guacamole.Tunnel.State.OPEN),t=(e=r.responseText).length,n<t&&(a.receive(e.substring(n)),n=t)),4===r.readyState&&o.disconnect()},r.onerror=function(){o.onerror&&o.onerror(new Guacamole.Status(Guacamole.Status.Code.fromHTTPCode(r.status),r.statusText)),o.disconnect()}},this.disconnect=function(){r&&(r.abort(),r=null),o.setState(Guacamole.Tunnel.State.CLOSED)}},Guacamole.StaticHTTPTunnel.prototype=new Guacamole.Tunnel,(Guacamole=Guacamole||{}).API_VERSION="1.1.0",(Guacamole=Guacamole||{}).VideoPlayer=function(){this.sync=function(){}},Guacamole.VideoPlayer.isSupportedType=function(){return!1},Guacamole.VideoPlayer.getSupportedTypes=function(){return[]},Guacamole.VideoPlayer.getInstance=function(){return null},module.exports=Guacamole;