1 | <meta http-equiv="content-type" content="text/html; charset=utf-8" /> |
---|
2 | |
---|
3 | <body> |
---|
4 | |
---|
5 | <title>{{=pc_name}}</title> |
---|
6 | |
---|
7 | <link href="{{=URL('static', 'css/desktop.css')}}" rel="stylesheet" type="text/css" /> |
---|
8 | <!-- <script src="{{=URL('static','js/guacamole-common-js/all.min.js')}}" type="text/javascript"></script> --> |
---|
9 | <script src="{{=URL('static','js/guacamole-common-js/all.js')}}" type="text/javascript"></script> |
---|
10 | |
---|
11 | <!-- |
---|
12 | <script type="text/javascript" src="{{=URL('static','js/guacamole-common-js/gitguac.js')}}"></script> |
---|
13 | <script type="text/javascript" src="{{=URL('static','js/guacamole-common-js/keysyms.js')}}"></script> |
---|
14 | --> |
---|
15 | |
---|
16 | |
---|
17 | <!-- Display --> |
---|
18 | <div id="container"></div> |
---|
19 | |
---|
20 | |
---|
21 | <script type="text/javascript"> /* <![CDATA[ */ |
---|
22 | // Start connect after control returns from onload (allow browser |
---|
23 | // to consider the page loaded). |
---|
24 | |
---|
25 | var guac_global = null; |
---|
26 | var optimal_width = null; |
---|
27 | var optimal_height = null; |
---|
28 | var mouse_global = null; |
---|
29 | |
---|
30 | window.onload = function() { |
---|
31 | if ( "{{=pc_name}}" === undefined ) { |
---|
32 | alert('Error de conexión. \ |
---|
33 | Vuelva a intentarlo o pongase en contacto con el personal de mantenimiento.') |
---|
34 | } |
---|
35 | |
---|
36 | window.setTimeout(function() { |
---|
37 | |
---|
38 | |
---|
39 | // Get display div from document |
---|
40 | var container = document.getElementById("container"); |
---|
41 | |
---|
42 | // Instantiate client, using an HTTP tunnel for communications. |
---|
43 | var guac = new Guacamole.Client( |
---|
44 | new Guacamole.WebSocketTunnel("{{=url_webSocket}}") |
---|
45 | ); |
---|
46 | |
---|
47 | guac_global = guac; |
---|
48 | |
---|
49 | // Returns the element which contains the Guacamole display |
---|
50 | var guac_display = guac.getDisplay().getElement(); |
---|
51 | |
---|
52 | // Add client to container div |
---|
53 | container.appendChild(guac.getDisplay().getElement()); |
---|
54 | |
---|
55 | try { |
---|
56 | |
---|
57 | // Calculate optimal width/height for display |
---|
58 | optimal_width = window.innerWidth; |
---|
59 | optimal_height = window.innerHeight; |
---|
60 | |
---|
61 | // Scale width/height to be at least 600x600 |
---|
62 | //if (optimal_width < 600 || optimal_height < 600) { |
---|
63 | // var scale = Math.max(600 / optimal_width, 600 / optimal_height); |
---|
64 | // optimal_width = Math.floor(optimal_width * scale); |
---|
65 | // optimal_height = Math.floor(optimal_height * scale); |
---|
66 | //} |
---|
67 | |
---|
68 | // Get entire query string, and pass to connect(). |
---|
69 | // Normally, only the "id" parameter is required, but |
---|
70 | // all parameters should be preserved and passed on for |
---|
71 | // the sake of authentication. |
---|
72 | |
---|
73 | var connect_string = |
---|
74 | window.location.search.substring(1) |
---|
75 | + "&width=" + optimal_width |
---|
76 | + "&height=" + optimal_height; |
---|
77 | |
---|
78 | |
---|
79 | if ("{{=sound}}" == "on") { |
---|
80 | // Add audio mimetypes to connect_string |
---|
81 | |
---|
82 | Guacamole.AudioPlayer.getSupportedTypes().forEach(function (mimetype) { |
---|
83 | |
---|
84 | connect_string += "&audio=" + encodeURIComponent(mimetype); |
---|
85 | }); |
---|
86 | |
---|
87 | } |
---|
88 | |
---|
89 | // Connect |
---|
90 | |
---|
91 | connect_string += "&protocol={{=protocol}}&ip={{=ip}}&port={{=port}}&username={{=username}}" + |
---|
92 | "&ignore-cert=true&guacamole-server=guacamole-server" ; |
---|
93 | |
---|
94 | |
---|
95 | guac.connect(connect_string); |
---|
96 | |
---|
97 | } |
---|
98 | catch (e) { |
---|
99 | alert(e.message); |
---|
100 | } |
---|
101 | |
---|
102 | // Mouse |
---|
103 | var mouse = new Guacamole.Mouse(guac.getDisplay().getElement()); |
---|
104 | |
---|
105 | mouse.onmousedown = |
---|
106 | mouse.onmouseup = |
---|
107 | mouse.onmousemove = function(mouseState) { |
---|
108 | guac.sendMouseState(mouseState); |
---|
109 | }; |
---|
110 | |
---|
111 | // Keyboard |
---|
112 | var keyboard = new Guacamole.Keyboard(document); |
---|
113 | |
---|
114 | keyboard.onkeydown = function (keysym) { |
---|
115 | guac.sendKeyEvent(1, keysym); |
---|
116 | |
---|
117 | }; |
---|
118 | |
---|
119 | keyboard.onkeyup = function (keysym) { |
---|
120 | guac.sendKeyEvent(0, keysym); |
---|
121 | |
---|
122 | }; |
---|
123 | |
---|
124 | |
---|
125 | }, 500); |
---|
126 | }; //End onload |
---|
127 | |
---|
128 | window.onresize = function(event) { |
---|
129 | var scale = Math.min(window.innerWidth / Math.max(guac_global.getDisplay().getWidth(), 1), |
---|
130 | window.innerHeight / Math.max(guac_global.getDisplay().getHeight(), 1)); |
---|
131 | guac_global.getDisplay().scale(scale); |
---|
132 | |
---|
133 | mouse_global.onmousemove = function(mousestate) { |
---|
134 | mousestate.x = mousestate.x / scale; |
---|
135 | mousestate.y = mousestate.y / scale; |
---|
136 | guac_global.sendMouseState(mousestate); |
---|
137 | } |
---|
138 | } |
---|
139 | |
---|
140 | window.onunload = function() { |
---|
141 | //guac.disconnect(); |
---|
142 | |
---|
143 | /* |
---|
144 | * No implemento porque al recargar la página también se ejecuta y no me interesa. |
---|
145 | * Puedo refrescar para que me reescale la página o por cualquier otro motivo. |
---|
146 | */ |
---|
147 | |
---|
148 | |
---|
149 | xhr = new XMLHttpRequest(); |
---|
150 | xhr.open("POST", '{{=URL("events", "getEventsWindowUnload")}}', false); |
---|
151 | xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); |
---|
152 | xhr.send("pc_id={{=pc_id}}&lab_id={{=lab_id}}&ou_id={{=ou_id}}"); |
---|
153 | |
---|
154 | } |
---|
155 | |
---|
156 | |
---|
157 | /* ]]> */ </script> |
---|
158 | |
---|
159 | </body> |
---|