3 The interface of the noVNC client consists of a single RFB object that
4 is instantiated once per connection.
8 The `RFB` object represents a single connection to a VNC server. It
9 communicates using a WebSocket that must provide a standard RFB
15 - Creates and returns a new `RFB` object.
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.
25 - Is a `long` controlling the button mask that should be simulated
26 when a touch event is recieved. Uses the same values as
27 [`MouseEvent.button`](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button).
28 Is set to `1` by default.
31 - Is a `double` indicating how the framebuffer contents should be
32 scaled before being rendered on to the canvas. See also
33 [`RFB.autoscale()`](#rfbautoscale). Is set to `1.0` by default.
36 - Is a `boolean` indicating if the canvas should be clipped to its
37 container. When disabled the container must be able to handle the
38 resulting overflow. Disabled by default.
41 - Is a `boolean` indicating if mouse events should control the
42 relative position of a clipped canvas. Only relevant if
43 `clipViewport` is enabled. Disabled by default.
45 `isClipped` *Read only*
46 - Is a `boolean` indicating if the framebuffer is larger than the
47 current canvas, i.e. it is being clipped.
49 `capabilities` *Read only*
50 - Is an `Object` indicating which optional extensions are available
51 on the server. Some methods may only be called if the corresponding
52 capability is set. The following capabilities are defined:
54 | name | type | description
55 | -------- | --------- | -----------
56 | `power` | `boolean` | Machine power control is available
57 | `resize` | `boolean` | The framebuffer can be resized
61 [`RFB.onupdatestate()`](#rfbonupdatestate)
62 - An event handler called when the connection state of the `RFB`
65 [`RFB.onnotification()`](#rfbonnotification)
66 - An event handler called when the `RFB` usage has a message to
69 [`RFB.ondisconnected()`](#rfbondisconnected)
70 - An event handler called when the `RFB` object disconnects.
72 [`RFB.oncredentialsrequired()`](#rfboncredentialsrequired)
73 - An event hander called when more credentials must be given to
76 [`RFB.onclipboard()`](#rfbonclipboard)
77 - An event handler called when clipboard data is received from the
80 [`RFB.onbell()`](#rfbonbell)
81 - An event handler called when a audible bell request is received
84 [`RFB.onfbresize()`](#rfbonfbresize)
85 - An event handler called when the framebuffer size is changed.
87 [`RFB.ondesktopname()`](#rfbondesktopname)
88 - An event handler called when the remote desktop name changes.
90 [`RFB.oncapabilities()`](#rfboncapabilities)
91 - An event handler called when `RFB.capabilities` is updated.
95 [`RFB.connect()`](#rfbconnect)
96 - Connect to a server.
98 [`RFB.disconnect()`](#rfbdisconnect)
99 - Disconnect from the server.
101 [`RFB.sendCredentials()`](#rfbsendcredentials)
102 - Send credentials to server. Should be called after
103 [`oncredentialsrequired`](#rfboncredentialsrequired) has been
106 [`RFB.sendKey()`](#rfbsendKey)
109 [`RFB.sendCtrlAltDel()`](#rfbsendctrlaltdel)
110 - Send Ctrl-Alt-Del key sequence.
112 [`RFB.machineShutdown()`](#rfbmachineshutdown)
113 - Request a shutdown of the remote machine.
115 [`RFB.machineReboot()`](#rfbmachinereboot)
116 - Request a reboot of the remote machine.
118 [`RFB.machineReset()`](#rfbmachinereset)
119 - Request a reset of the remote machine.
121 [`RFB.clipboardPasteFrom()`](#rfbclipboardPasteFrom)
122 - Send clipboard contents to server.
124 [`RFB.autoscale()`](#rfbautoscale)
125 - Set `RFB.viewportScale` so that the framebuffer fits a specified
128 [`RFB.requestDesktopSize()`](#rfbrequestDesktopSize)
129 - Send a request to change the remote desktop size.
131 [`RFB.viewportChangeSize()`](#rfbviewportChangeSize)
132 - Change size of the viewport.
138 The `RFB()` constructor returns a new `RFB` object. The object will
139 initially be disconnected and [`RFB.connect()`](#rfbconnect) must be
140 called before the object will be useful.
144 var rfb = new RFB( target );
149 - A [`HTMLCanvasElement`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement)
150 that specifies where graphics should be rendered and input events
153 #### RFB.onupdatestate
155 The `onupdatestate` event handler is fired after the noVNC connection
156 state changes. Here is a list of the states that are reported:
158 | connection state | description
159 | ----------------- | ------------
160 | `"connecting"` | starting to connect
161 | `"connected"` | connected normally
162 | `"disconnecting"` | starting to disconnect
163 | `"disconnected"` | disconnected
165 Note that a `RFB` objects can not transition from the disconnected
166 state in any way, a new instance of the object has to be created for
171 RFB.onupdatestate = function(rfb, state) { ... }
173 #### RFB.onnotification
175 The `onnotification` event handler is fired when the `RFB` object wants
176 a message displayed to the user. **`msg`** is a `DOMString` specifying
177 the actual message, and **`level`** is a `DOMString` indicating the
178 severity of the message. The following levels are currently defined:
184 **`options`** is currently unused.
188 RFB.onnotification = function(rfb, msg, level, options) { ... }
190 #### RFB.ondisconnected
192 The `ondisconnected` event handler is fired when the connection has
193 been terminated. **`reason`** is `undefined` for a clean termination
194 and a `DOMString` specifying the reason in the event of an unexpected
199 RFB.ondisconnected = function(rfb, reason) { ... }
201 #### RFB.oncredentialsrequired
203 The `oncredentialsrequired` event handler is fired when the server
204 requests more credentials than were specified to
205 [`RFB.connect()`](#rfbconnect). The **`types`** argument is a list of
206 all the credentials that are required.
210 RFB.oncredentialsrequired = function(rfb, types) { ... }
214 The `onclipboard` event handler is fired when the server has sent
219 RFB.onclipboard = function(rfb, text) { ... }
223 The `onbell` event handler is fired when the server has requested an
228 RFB.onbell = function(rfb) { ... }
232 The `onfbresize` event handler is fired when the framebuffer has
237 RFB.onfbresize = function(rfb, width, height) { ... }
239 #### RFB.ondesktopname
241 The `ondesktopname` event handler is fired when the name of the remote
246 RFB.ondesktopname = function(rfb, name) { ... }
248 #### RFB.oncapabilities
250 The `oncapabilities` event handler is fired whenever an entry is added
251 or removed from `RFB.capabilities`.
255 RFB.oncapabilities = function(rfb, capabilites) { ... }
259 The `RFB.connect()` method is used to initiate a new connection to a
260 specified VNC server.
264 RFB.connect( url [, options] );
269 - A `DOMString` specifying the VNC server to connect to. This must be
270 a valid WebSocket URL.
272 **`options`** *Optional*
273 - An `Object` specifying extra details about how the connection
279 - A `boolean` indicating if the remote server should be shared or
280 if any other connected clients should be disconnected. Enabled
284 - An `Object` specifying the credentials to provide to the server
285 when authenticating. The following credentials are possible:
287 | name | type | description
288 | ------------ | ----------- | -----------
289 | `"username"` | `DOMString` | The user that authenticates
290 | `"password"` | `DOMString` | Password for the user
291 | `"target"` | `DOMString` | Target machine or session
294 - A `DOMString` specifying the ID to provide to any VNC repeater
297 #### RFB.disconnect()
299 The `RFB.disconnect()` method is used to disconnect from the currently
306 #### RFB.sendCredentials()
308 The `RFB.sendCredentials()` method is used to provide the missing
309 credentials after `RFB.oncredentialsrequired` has been fired.
313 RFB.sendCredentials( credentials );
318 - An `Object` specifying the credentials to provide to the server
319 when authenticating. See [`RFB.connect()`](#rfbconnect) for
324 The `RFB.sendKey()` method is used to send a key event to the server.
328 RFB.sendKey( keysym, code [, down] );
333 - A `long` specifying the RFB keysym to send. Can be `0` if a valid
334 **`code`** is specified.
337 - A `DOMString` specifying the physical key to send. Valid values are
338 those that can be specified to
339 [`KeyboardEvent.code`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code).
340 If the physical key cannot be determined then `null` shall be
343 **`down`** *Optional*
344 - A `boolean` specifying if a press or a release event should be
345 sent. If omitted then both a press and release event are sent.
347 #### RFB.sendCtrlAltDel()
349 The `RFB.sendCtrlAltDel()` method is used to send the key sequence
350 *left Control*, *left Alt*, *Delete*. This is a convenience wrapper
351 around [`RFB.sendKey()`](#rfbsendkey).
355 RFB.sendCtrlAltDel( );
357 #### RFB.machineShutdown()
359 The `RFB.machineShutdown()` method is used to request to shut down the
360 remote machine. The capability `power` must be set for this method to
365 RFB.machineShutdown( );
367 #### RFB.machineReboot()
369 The `RFB.machineReboot()` method is used to request a clean reboot of
370 the remote machine. The capability `power` must be set for this method
375 RFB.machineReboot( );
377 #### RFB.machineReset()
379 The `RFB.machineReset()` method is used to request a forced reset of
380 the remote machine. The capability `power` must be set for this method
387 #### RFB.clipboardPasteFrom()
389 The `RFB.clipboardPasteFrom()` method is used to send clipboard data
390 to the remote server.
394 RFB.clipboardPasteFrom( text );
399 - A `DOMString` specifying the clipboard data to send. Currently only
400 characters from ISO 8859-1 are supported.
404 The `RFB.autoscale()` method is used to automatically adjust
405 `RFB.viewportScale` to fit given dimensions.
409 RFB.autoscale( width, height );
414 - A `long` specifying the maximum width of the canvas in CSS pixels.
417 - A `long` specifying the maximum height of the canvas in CSS pixels.
419 #### RFB.requestDesktopSize()
421 The `RFB.requestDesktopSize()` method is used to request a change of
422 the framebuffer. The capability `resize` must be set for this method to
425 Note that this is merely a request and the server may deny it.
426 [`RFB.onfbresize`](#rfbonfbresize) will be called when the framebuffer
427 actually changes dimensions.
431 RFB.requestDesktopSize( width, height );
436 - A `long` specifying the new requested width in CSS pixels.
439 - A `long` specifying the new requested height in CSS pixels.
441 #### RFB.viewportChangeSize()
443 The `RFB.viewportChangeSize()` method is used to change the size of the
444 canvas rather than the underlying framebuffer.
446 This method has no effect if `RFB.clipViewport` is set to `false`.
450 RFB.viewportChangeSize( width, height );
455 - A `long` specifying the new width in CSS pixels.
458 - A `long` specifying the new height in CSS pixels.