]>
Commit | Line | Data |
---|---|---|
4f90c1d3 | 1 | # noVNC API |
5ce91550 | 2 | |
6929a0a1 PO |
3 | The interface of the noVNC client consists of a single RFB object that |
4 | is instantiated once per connection. | |
5ce91550 | 5 | |
4f90c1d3 | 6 | ## RFB |
5ce91550 | 7 | |
4f90c1d3 PO |
8 | The `RFB` object represents a single connection to a VNC server. It |
9 | communicates using a WebSocket that must provide a standard RFB | |
10 | protocol stream. | |
5ce91550 | 11 | |
4f90c1d3 | 12 | ### Constructor |
5ce91550 | 13 | |
4f90c1d3 PO |
14 | [`RFB()`](#rfb-1) |
15 | - Creates and returns a new `RFB` object. | |
5ce91550 | 16 | |
4f90c1d3 | 17 | ### Properties |
5ce91550 | 18 | |
4f90c1d3 PO |
19 | `viewOnly` |
20 | - Is a `boolean` indicating if any events (e.g. key presses or mouse | |
21 | movement) should be prevented from being sent to the server. | |
22 | Disabled by default. | |
5ce91550 | 23 | |
a201bfc5 PO |
24 | `focusOnClick` |
25 | - Is a `boolean` indicating if keyboard focus should automatically be | |
9b84f516 PO |
26 | moved to the remote session when a `mousedown` or `touchstart` |
27 | event is received. | |
5ce91550 | 28 | |
4f90c1d3 PO |
29 | `touchButton` |
30 | - Is a `long` controlling the button mask that should be simulated | |
31 | when a touch event is recieved. Uses the same values as | |
32 | [`MouseEvent.button`](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button). | |
33 | Is set to `1` by default. | |
5ce91550 | 34 | |
0460e5fd | 35 | `clipViewport` |
9b84f516 PO |
36 | - Is a `boolean` indicating if the remote session should be clipped |
37 | to its container. When disabled scrollbars will be shown to handle | |
38 | the resulting overflow. Disabled by default. | |
5ce91550 | 39 | |
0460e5fd | 40 | `dragViewport` |
4f90c1d3 | 41 | - Is a `boolean` indicating if mouse events should control the |
9b84f516 | 42 | relative position of a clipped remote session. Only relevant if |
0460e5fd | 43 | `clipViewport` is enabled. Disabled by default. |
5ce91550 | 44 | |
9b84f516 PO |
45 | `scaleViewport` |
46 | - Is a `boolean` indicating if the remote session should be scaled | |
47 | locally so it fits its container. When disabled it will be centered | |
48 | if the remote session is smaller than its container, or handled | |
49 | according to `clipViewport` if it is larger. Disabled by default. | |
50 | ||
51 | `resizeSession` | |
52 | - Is a `boolean` indicating if a request to resize the remote session | |
53 | should be sent whenever the container changes dimensions. Disabled | |
54 | by default. | |
5ce91550 | 55 | |
4c38179d AP |
56 | `showDotCursor` |
57 | - Is a `boolean` indicating whether a dot cursor should be shown | |
58 | instead of a zero-sized or fully-transparent cursor if the server | |
59 | sets such invisible cursor. Disabled by default. | |
60 | ||
d7791ebb MM |
61 | `background` |
62 | - Is a valid CSS [background](https://developer.mozilla.org/en-US/docs/Web/CSS/background) | |
63 | style value indicating which background style should be applied | |
64 | to the element containing the remote session screen. The default value is `rgb(40, 40, 40)` | |
65 | (solid gray color). | |
66 | ||
4f90c1d3 PO |
67 | `capabilities` *Read only* |
68 | - Is an `Object` indicating which optional extensions are available | |
69 | on the server. Some methods may only be called if the corresponding | |
70 | capability is set. The following capabilities are defined: | |
5ce91550 | 71 | |
4f90c1d3 PO |
72 | | name | type | description |
73 | | -------- | --------- | ----------- | |
74 | | `power` | `boolean` | Machine power control is available | |
5ce91550 | 75 | |
e89eef94 | 76 | ### Events |
5ce91550 | 77 | |
ee5cae9f SM |
78 | [`connect`](#connect) |
79 | - The `connect` event is fired when the `RFB` object has completed | |
80 | the connection and handshaking with the server. | |
5ce91550 | 81 | |
e89eef94 PO |
82 | [`disconnect`](#disconnected) |
83 | - The `disconnect` event is fired when the `RFB` object disconnects. | |
5ce91550 | 84 | |
e89eef94 PO |
85 | [`credentialsrequired`](#credentialsrequired) |
86 | - The `credentialsrequired` event is fired when more credentials must | |
87 | be given to continue. | |
5ce91550 | 88 | |
d472f3f1 SM |
89 | [`securityfailure`](#securityfailure) |
90 | - The `securityfailure` event is fired when the security negotiation | |
91 | with the server fails. | |
92 | ||
e89eef94 PO |
93 | [`clipboard`](#clipboard) |
94 | - The `clipboard` event is fired when clipboard data is received from | |
95 | the server. | |
5ce91550 | 96 | |
e89eef94 PO |
97 | [`bell`](#bell) |
98 | - The `bell` event is fired when a audible bell request is received | |
4f90c1d3 | 99 | from the server. |
f5d40c6a | 100 | |
e89eef94 PO |
101 | [`desktopname`](#desktopname) |
102 | - The `desktopname` event is fired when the remote desktop name | |
103 | changes. | |
f5d40c6a | 104 | |
e89eef94 PO |
105 | [`capabilities`](#capabilities) |
106 | - The `capabilities` event is fired when `RFB.capabilities` is | |
107 | updated. | |
f5d40c6a | 108 | |
4f90c1d3 | 109 | ### Methods |
f5d40c6a | 110 | |
4f90c1d3 PO |
111 | [`RFB.disconnect()`](#rfbdisconnect) |
112 | - Disconnect from the server. | |
5ce91550 | 113 | |
4f90c1d3 | 114 | [`RFB.sendCredentials()`](#rfbsendcredentials) |
e89eef94 PO |
115 | - Send credentials to server. Should be called after the |
116 | [`credentialsrequired`](#credentialsrequired) event has fired. | |
5ce91550 | 117 | |
4f90c1d3 PO |
118 | [`RFB.sendKey()`](#rfbsendKey) |
119 | - Send a key event. | |
5ce91550 | 120 | |
4f90c1d3 PO |
121 | [`RFB.sendCtrlAltDel()`](#rfbsendctrlaltdel) |
122 | - Send Ctrl-Alt-Del key sequence. | |
123 | ||
9b84f516 PO |
124 | [`RFB.focus()`](#rfbfocus) |
125 | - Move keyboard focus to the remote session. | |
126 | ||
127 | [`RFB.blur()`](#rfbblur) | |
128 | - Remove keyboard focus from the remote session. | |
129 | ||
4f90c1d3 PO |
130 | [`RFB.machineShutdown()`](#rfbmachineshutdown) |
131 | - Request a shutdown of the remote machine. | |
132 | ||
133 | [`RFB.machineReboot()`](#rfbmachinereboot) | |
134 | - Request a reboot of the remote machine. | |
135 | ||
136 | [`RFB.machineReset()`](#rfbmachinereset) | |
137 | - Request a reset of the remote machine. | |
138 | ||
139 | [`RFB.clipboardPasteFrom()`](#rfbclipboardPasteFrom) | |
140 | - Send clipboard contents to server. | |
141 | ||
4f90c1d3 PO |
142 | ### Details |
143 | ||
144 | #### RFB() | |
145 | ||
2f4516f2 PO |
146 | The `RFB()` constructor returns a new `RFB` object and initiates a new |
147 | connection to a specified VNC server. | |
4f90c1d3 PO |
148 | |
149 | ##### Syntax | |
150 | ||
2b5f94fa | 151 | let rfb = new RFB( target, url [, options] ); |
4f90c1d3 PO |
152 | |
153 | ###### Parameters | |
154 | ||
155 | **`target`** | |
9b84f516 PO |
156 | - A block [`HTMLElement`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement) |
157 | that specifies where the `RFB` object should attach itself. The | |
158 | existing contents of the `HTMLElement` will be untouched, but new | |
159 | elements will be added during the lifetime of the `RFB` object. | |
4f90c1d3 | 160 | |
2f4516f2 PO |
161 | **`url`** |
162 | - A `DOMString` specifying the VNC server to connect to. This must be | |
163 | a valid WebSocket URL. | |
164 | ||
165 | **`options`** *Optional* | |
166 | - An `Object` specifying extra details about how the connection | |
167 | should be made. | |
168 | ||
169 | Possible options: | |
170 | ||
171 | `shared` | |
172 | - A `boolean` indicating if the remote server should be shared or | |
173 | if any other connected clients should be disconnected. Enabled | |
174 | by default. | |
175 | ||
176 | `credentials` | |
177 | - An `Object` specifying the credentials to provide to the server | |
178 | when authenticating. The following credentials are possible: | |
179 | ||
180 | | name | type | description | |
181 | | ------------ | ----------- | ----------- | |
182 | | `"username"` | `DOMString` | The user that authenticates | |
183 | | `"password"` | `DOMString` | Password for the user | |
184 | | `"target"` | `DOMString` | Target machine or session | |
185 | ||
186 | `repeaterID` | |
187 | - A `DOMString` specifying the ID to provide to any VNC repeater | |
188 | encountered. | |
189 | ||
ee5cae9f | 190 | #### connect |
4f90c1d3 | 191 | |
ee5cae9f SM |
192 | The `connect` event is fired after all the handshaking with the server |
193 | is completed and the connection is fully established. After this event | |
194 | the `RFB` object is ready to recieve graphics updates and to send input. | |
4f90c1d3 | 195 | |
e89eef94 | 196 | #### disconnect |
4f90c1d3 | 197 | |
e89eef94 | 198 | The `disconnect` event is fired when the connection has been |
d472f3f1 SM |
199 | terminated. The `detail` property is an `Object` that contains the |
200 | property `clean`. `clean` is a `boolean` indicating if the termination | |
201 | was clean or not. In the event of an unexpected termination or an error | |
202 | `clean` will be set to false. | |
4f90c1d3 | 203 | |
e89eef94 | 204 | #### credentialsrequired |
4f90c1d3 | 205 | |
e89eef94 PO |
206 | The `credentialsrequired` event is fired when the server requests more |
207 | credentials than were specified to [`RFB()`](#rfb-1). The `detail` | |
208 | property is an `Object` containing the property `types` which is an | |
209 | `Array` of `DOMString` listing the credentials that are required. | |
4f90c1d3 | 210 | |
d472f3f1 SM |
211 | #### securityfailure |
212 | ||
213 | The `securityfailure` event is fired when the handshaking process with | |
214 | the server fails during the security negotiation step. The `detail` | |
215 | property is an `Object` containing the following properties: | |
216 | ||
217 | | Property | Type | Description | |
218 | | -------- | ----------- | ----------- | |
219 | | `status` | `long` | The failure status code | |
220 | | `reason` | `DOMString` | The **optional** reason for the failure | |
221 | ||
222 | The property `status` corresponds to the | |
223 | [SecurityResult](https://github.com/rfbproto/rfbproto/blob/master/rfbproto.rst#securityresult) | |
224 | status code in cases of failure. A status of zero will not be sent in | |
225 | this event since that indicates a successful security handshaking | |
226 | process. The optional property `reason` is provided by the server and | |
227 | thus the language of the string is not known. However most servers will | |
228 | probably send English strings. The server can choose to not send a | |
229 | reason and in these cases the `reason` property will be omitted. | |
230 | ||
e89eef94 | 231 | #### clipboard |
4f90c1d3 | 232 | |
e89eef94 PO |
233 | The `clipboard` event is fired when the server has sent clipboard data. |
234 | The `detail` property is an `Object` containing the property `text` | |
235 | which is a `DOMString` with the clipboard data. | |
4f90c1d3 | 236 | |
e89eef94 | 237 | #### bell |
4f90c1d3 | 238 | |
e89eef94 PO |
239 | The `bell` event is fired when the server has requested an audible |
240 | bell. | |
4f90c1d3 | 241 | |
e89eef94 | 242 | #### desktopname |
4f90c1d3 | 243 | |
e89eef94 PO |
244 | The `desktopname` event is fired when the name of the remote desktop |
245 | changes. The `detail` property is an `Object` with the property `name` | |
246 | which is a `DOMString` specifying the new name. | |
4f90c1d3 | 247 | |
e89eef94 | 248 | #### capabilities |
4f90c1d3 | 249 | |
e89eef94 PO |
250 | The `capabilities` event is fired whenever an entry is added or removed |
251 | from `RFB.capabilities`. The `detail` property is an `Object` with the | |
252 | property `capabilities` containing the new value of `RFB.capabilities`. | |
4f90c1d3 | 253 | |
4f90c1d3 PO |
254 | #### RFB.disconnect() |
255 | ||
256 | The `RFB.disconnect()` method is used to disconnect from the currently | |
257 | connected server. | |
258 | ||
259 | ##### Syntax | |
260 | ||
261 | RFB.disconnect( ); | |
262 | ||
263 | #### RFB.sendCredentials() | |
264 | ||
265 | The `RFB.sendCredentials()` method is used to provide the missing | |
e89eef94 | 266 | credentials after a `credentialsrequired` event has been fired. |
4f90c1d3 PO |
267 | |
268 | ##### Syntax | |
269 | ||
270 | RFB.sendCredentials( credentials ); | |
271 | ||
272 | ###### Parameters | |
273 | ||
274 | **`credentials`** | |
275 | - An `Object` specifying the credentials to provide to the server | |
2f4516f2 | 276 | when authenticating. See [`RFB()`](#rfb-1) for details. |
4f90c1d3 PO |
277 | |
278 | #### RFB.sendKey() | |
279 | ||
280 | The `RFB.sendKey()` method is used to send a key event to the server. | |
281 | ||
282 | ##### Syntax | |
283 | ||
284 | RFB.sendKey( keysym, code [, down] ); | |
285 | ||
286 | ###### Parameters | |
287 | ||
288 | **`keysym`** | |
289 | - A `long` specifying the RFB keysym to send. Can be `0` if a valid | |
290 | **`code`** is specified. | |
291 | ||
292 | **`code`** | |
293 | - A `DOMString` specifying the physical key to send. Valid values are | |
294 | those that can be specified to | |
295 | [`KeyboardEvent.code`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code). | |
296 | If the physical key cannot be determined then `null` shall be | |
297 | specified. | |
298 | ||
299 | **`down`** *Optional* | |
300 | - A `boolean` specifying if a press or a release event should be | |
301 | sent. If omitted then both a press and release event are sent. | |
302 | ||
303 | #### RFB.sendCtrlAltDel() | |
304 | ||
305 | The `RFB.sendCtrlAltDel()` method is used to send the key sequence | |
306 | *left Control*, *left Alt*, *Delete*. This is a convenience wrapper | |
307 | around [`RFB.sendKey()`](#rfbsendkey). | |
308 | ||
309 | ##### Syntax | |
310 | ||
311 | RFB.sendCtrlAltDel( ); | |
312 | ||
9b84f516 PO |
313 | #### RFB.focus() |
314 | ||
315 | The `RFB.focus()` method sets the keyboard focus on the remote session. | |
316 | Keyboard events will be sent to the remote server after this point. | |
317 | ||
318 | ##### Syntax | |
319 | ||
320 | RFB.focus( ); | |
321 | ||
322 | #### RFB.blur() | |
323 | ||
324 | The `RFB.blur()` method remove keyboard focus on the remote session. | |
325 | Keyboard events will no longer be sent to the remote server after this | |
326 | point. | |
327 | ||
328 | ##### Syntax | |
329 | ||
330 | RFB.blur( ); | |
331 | ||
4f90c1d3 PO |
332 | #### RFB.machineShutdown() |
333 | ||
334 | The `RFB.machineShutdown()` method is used to request to shut down the | |
335 | remote machine. The capability `power` must be set for this method to | |
336 | have any effect. | |
337 | ||
338 | ##### Syntax | |
339 | ||
340 | RFB.machineShutdown( ); | |
341 | ||
342 | #### RFB.machineReboot() | |
343 | ||
344 | The `RFB.machineReboot()` method is used to request a clean reboot of | |
345 | the remote machine. The capability `power` must be set for this method | |
346 | to have any effect. | |
347 | ||
348 | ##### Syntax | |
349 | ||
350 | RFB.machineReboot( ); | |
351 | ||
352 | #### RFB.machineReset() | |
353 | ||
354 | The `RFB.machineReset()` method is used to request a forced reset of | |
355 | the remote machine. The capability `power` must be set for this method | |
356 | to have any effect. | |
357 | ||
358 | ##### Syntax | |
359 | ||
360 | RFB.machineReset( ); | |
361 | ||
362 | #### RFB.clipboardPasteFrom() | |
363 | ||
364 | The `RFB.clipboardPasteFrom()` method is used to send clipboard data | |
365 | to the remote server. | |
366 | ||
367 | ##### Syntax | |
368 | ||
369 | RFB.clipboardPasteFrom( text ); | |
370 | ||
371 | ###### Parameters | |
372 | ||
373 | **`text`** | |
374 | - A `DOMString` specifying the clipboard data to send. Currently only | |
375 | characters from ISO 8859-1 are supported. |