]>
Commit | Line | Data |
---|---|---|
15046f00 JM |
1 | /* |
2 | * noVNC: HTML5 VNC client | |
3 | * Copyright (C) 2010 Joel Martin | |
4 | * Licensed under LGPL-3 (see LICENSE.LGPL-3) | |
5 | * | |
6 | * See README.md for usage and integration instructions. | |
7 | */ | |
8 | "use strict"; | |
81e5adaf | 9 | /*global $, RFB, Canvas, VNC_uri_prefix, Element, Fx */ |
15046f00 | 10 | |
63708ff5 | 11 | var DefaultControls = { |
91308399 JM |
12 | |
13 | load: function(target) { | |
63708ff5 | 14 | var url, html; |
91308399 JM |
15 | |
16 | /* Handle state updates */ | |
17 | RFB.setUpdateState(DefaultControls.updateState); | |
18 | RFB.setClipboardReceive(DefaultControls.clipReceive); | |
19 | ||
20 | /* Populate the 'target' DOM element with default controls */ | |
21 | if (!target) { target = 'vnc'; } | |
22 | ||
23 | html = ""; | |
24 | html += '<div id="VNC_controls">'; | |
25 | html += ' <ul>'; | |
26 | html += ' <li>Host: <input id="VNC_host"></li>'; | |
27 | html += ' <li>Port: <input id="VNC_port"></li>'; | |
28 | html += ' <li>Password: <input id="VNC_password"'; | |
29 | html += ' type="password"></li>'; | |
30 | html += ' <li>Encrypt: <input id="VNC_encrypt"'; | |
31 | html += ' type="checkbox"></li>'; | |
32 | html += ' <li>True Color: <input id="VNC_true_color"'; | |
33 | html += ' type="checkbox" checked></li>'; | |
34 | html += ' <li><input id="VNC_connect_button" type="button"'; | |
35 | html += ' value="Loading" disabled></li>'; | |
36 | html += ' </ul>'; | |
37 | html += '</div>'; | |
38 | html += '<div id="VNC_screen">'; | |
63708ff5 JM |
39 | html += ' <div id="VNC_status_bar" class="VNC_status_bar" style="margin-top: 0px;">'; |
40 | html += ' <table border=0 width=100%><tr>'; | |
41 | html += ' <td><div id="VNC_status">Loading</div></td>'; | |
42 | html += ' <td width=10%><div id="VNC_buttons">'; | |
43 | html += ' <input type=button value="Send CtrlAltDel"'; | |
160fabf6 | 44 | html += ' id="sendCtrlAltDelButton"'; |
63708ff5 JM |
45 | html += ' onclick="DefaultControls.sendCtrlAltDel();"></div></td>'; |
46 | html += ' </tr></table>'; | |
47 | html += ' </div>'; | |
91308399 JM |
48 | html += ' <canvas id="VNC_canvas" width="640px" height="20px">'; |
49 | html += ' Canvas not supported.'; | |
50 | html += ' </canvas>'; | |
51 | html += '</div>'; | |
52 | html += '<br><br>'; | |
53 | html += '<div id="VNC_clipboard">'; | |
54 | html += ' VNC Clipboard:'; | |
55 | html += ' <input id="VNC_clipboard_clear_button"'; | |
56 | html += ' type="button" value="Clear"'; | |
57 | html += ' onclick="DefaultControls.clipClear();">'; | |
58 | html += ' <br>'; | |
59 | html += ' <textarea id="VNC_clipboard_text" cols=80 rows=5'; | |
60 | html += ' onfocus="DefaultControls.clipFocus();"'; | |
61 | html += ' onblur="DefaultControls.clipBlur();"'; | |
62 | html += ' onchange="DefaultControls.clipSend();"></textarea>'; | |
63 | html += '</div>'; | |
64 | $(target).innerHTML = html; | |
65 | ||
66 | /* Populate the controls if defaults are provided in the URL */ | |
67 | url = document.location.href; | |
68 | $('VNC_host').value = (url.match(/host=([A-Za-z0-9.\-]*)/) || | |
69 | ['',''])[1]; | |
70 | $('VNC_port').value = (url.match(/port=([0-9]*)/) || | |
71 | ['',''])[1]; | |
72 | $('VNC_password').value = (url.match(/password=([^&#]*)/) || | |
73 | ['',''])[1]; | |
74 | $('VNC_encrypt').checked = (url.match(/encrypt=([A-Za-z0-9]*)/) || | |
75 | ['',''])[1]; | |
3954ae14 JM |
76 | |
77 | $('VNC_screen').onmousemove = function () { | |
78 | // Unfocus clipboard when over the VNC area | |
15046f00 | 79 | if (! Canvas.focused) { |
3954ae14 JM |
80 | $('VNC_clipboard_text').blur(); |
81 | } | |
82 | }; | |
91308399 JM |
83 | }, |
84 | ||
f00b1e37 JM |
85 | setPassword: function() { |
86 | console.log("setPassword"); | |
87 | RFB.sendPassword($('VNC_password').value); | |
88 | return false; | |
89 | }, | |
90 | ||
63708ff5 JM |
91 | sendCtrlAltDel: function() { |
92 | RFB.sendCtrlAltDel(); | |
93 | }, | |
94 | ||
91308399 JM |
95 | updateState: function(state, msg) { |
96 | var s, c, klass; | |
97 | s = $('VNC_status'); | |
63708ff5 | 98 | sb = $('VNC_status_bar'); |
91308399 | 99 | c = $('VNC_connect_button'); |
160fabf6 | 100 | cad = $('sendCtrlAltDelButton'); |
91308399 JM |
101 | switch (state) { |
102 | case 'failed': | |
f00b1e37 | 103 | case 'fatal': |
91308399 | 104 | c.disabled = true; |
160fabf6 | 105 | cad.disabled = true; |
91308399 JM |
106 | klass = "VNC_status_error"; |
107 | break; | |
108 | case 'normal': | |
109 | c.value = "Disconnect"; | |
110 | c.onclick = DefaultControls.disconnect; | |
111 | c.disabled = false; | |
160fabf6 | 112 | cad.disabled = false; |
91308399 JM |
113 | klass = "VNC_status_normal"; |
114 | break; | |
115 | case 'disconnected': | |
f00b1e37 | 116 | case 'loaded': |
91308399 JM |
117 | c.value = "Connect"; |
118 | c.onclick = DefaultControls.connect; | |
119 | ||
120 | c.disabled = false; | |
160fabf6 | 121 | cad.disabled = true; |
91308399 JM |
122 | klass = "VNC_status_normal"; |
123 | break; | |
f00b1e37 JM |
124 | case 'password': |
125 | c.value = "Send Password"; | |
126 | c.onclick = DefaultControls.setPassword; | |
127 | ||
128 | c.disabled = false; | |
129 | cad.disabled = true; | |
130 | klass = "VNC_status_warn"; | |
131 | break; | |
91308399 JM |
132 | default: |
133 | c.disabled = true; | |
160fabf6 | 134 | cad.disabled = true; |
91308399 JM |
135 | klass = "VNC_status_warn"; |
136 | break; | |
137 | } | |
138 | ||
139 | if (typeof(msg) !== 'undefined') { | |
140 | s.setAttribute("class", klass); | |
63708ff5 | 141 | sb.setAttribute("class", klass); |
91308399 JM |
142 | s.innerHTML = msg; |
143 | } | |
144 | ||
145 | }, | |
146 | ||
147 | connect: function() { | |
148 | var host, port, password, encrypt, true_color; | |
149 | host = $('VNC_host').value; | |
150 | port = $('VNC_port').value; | |
151 | password = $('VNC_password').value; | |
152 | encrypt = $('VNC_encrypt').checked; | |
153 | true_color = $('VNC_true_color').checked; | |
154 | if ((!host) || (!port)) { | |
63708ff5 | 155 | throw("Must set host and port"); |
91308399 JM |
156 | } |
157 | ||
158 | RFB.connect(host, port, password, encrypt, true_color); | |
159 | }, | |
160 | ||
161 | disconnect: function() { | |
162 | RFB.disconnect(); | |
163 | }, | |
164 | ||
165 | clipFocus: function() { | |
15046f00 | 166 | Canvas.focused = false; |
91308399 JM |
167 | }, |
168 | ||
169 | clipBlur: function() { | |
15046f00 | 170 | Canvas.focused = true; |
91308399 JM |
171 | }, |
172 | ||
173 | clipClear: function() { | |
174 | $('VNC_clipboard_text').value = ""; | |
175 | RFB.clipboardPasteFrom(""); | |
176 | }, | |
177 | ||
178 | clipReceive: function(text) { | |
81e5adaf | 179 | Util.Debug(">> DefaultControls.clipReceive: " + text.substr(0,40) + "..."); |
91308399 | 180 | $('VNC_clipboard_text').value = text; |
81e5adaf | 181 | Util.Debug("<< DefaultControls.clipReceive"); |
91308399 JM |
182 | }, |
183 | ||
184 | clipSend: function() { | |
185 | var text = $('VNC_clipboard_text').value; | |
81e5adaf | 186 | Util.Debug(">> DefaultControls.clipSend: " + text.substr(0,40) + "..."); |
91308399 | 187 | RFB.clipboardPasteFrom(text); |
81e5adaf | 188 | Util.Debug("<< DefaultControls.clipSend"); |
91308399 JM |
189 | } |
190 | ||
63708ff5 | 191 | }; |