時間:2019-05-21
noVNC API
The interface of the noVNC client consists of a single RFB object that is instantiated once per connection.
noVNC客戶端的接口由單個RFB對象組成,每個連接實例化一次
RFB
The RFB object represents a single connection to a VNC server. It communicates using a WebSocket that must provide a standard RFB protocol stream.
RFB對象表示與VNC服務器的單個連接。它使用必須提供標准RFB協議流的WebSocket進行通信。
Constructor(構造函數)
RFB()
Creates and returns a new RFB object.
創建並返回一個新的RFB對象。
Properties(屬性)
viewOnly
Is a boolean indicating if any events (e.g. key presses or mouse movement) should be prevented from being sent to the server. Disabled by default.
是一個布爾值,指示是否應該阻止將任何事件(例如按鍵或鼠標移動)發送到服務器。默認情況下禁用。
focusOnClick
Is a boolean indicating if keyboard focus should automatically be moved to the remote session when a mousedown or touchstart event is received.
是一個布爾值,指示在收到mousedown或touchstart事件時是否應自動將鍵盤焦點移動到遠程會話。
touchButton
Is a long controlling the button mask that should be simulated when a touch event is recieved. Uses the same values as MouseEvent.button. Is set to 1 by default.
是一個長控制按鈕蒙版,應該在收到觸摸事件時模擬。使用與MouseEvent.button相同的值。默認設置為1。
clipViewport
Is a boolean indicating if the remote session should be clipped to its container. When disabled scrollbars will be shown to handle the resulting overflow. Disabled by default.
是一個布爾值,指示是否應將遠程會話剪切到其容器。禁用時,將顯示滾動條以處理產生的溢出。默認情況下禁用。
dragViewport
Is a boolean indicating if mouse events should control the relative position of a clipped remote session. Only relevant if clipViewport is enabled. Disabled by default.
是一個布爾值,指示鼠標事件是否應控制剪切的遠程會話的相對位置。僅在啟用clipViewport時相關。默認情況下禁用。
scaleViewport
Is a boolean indicating if the remote session should be scaled locally so it fits its container. When disabled it will be centered if the remote session is smaller than its container, or handled according to clipViewport if it is larger. Disabled by default.
是一個布爾值,指示遠程會話是否應在本地擴展,以便它適合其容器。禁用時,如果遠程會話小於其容器,則它將居中,或者如果它更大,則根據clipViewport處理。默認情況下禁用。
resizeSession
Is a boolean indicating if a request to resize the remote session should be sent whenever the container changes dimensions. Disabled by default.
是一個布爾值,指示每當容器更改維度時是否應發送調整遠程會話大小的請求。默認情況下禁用。
showDotCursor
Is a boolean indicating whether a dot cursor should be shown instead of a zero-sized or fully-transparent cursor if the server sets such invisible cursor. Disabled by default.
是一個布爾值,指示如果服務器設置此類不可見光標,是否應顯示點光標而不是零大小或完全透明的光標。默認情況下禁用。
background
Is a valid CSS background style value indicating which background style should be applied to the element containing the remote session screen. The default value is rgb(40, 40, 40) (solid gray color).
是一個有效的CSS背景樣式值,指示應將哪種背景樣式應用於包含遠程會話屏幕的元素。默認值為rgb(40,40,40)(純灰色)。
capabilities Read only
Is an Object indicating which optional extensions are available on the server. Some methods may only be called if the corresponding capability is set. The following capabilities are defined:
是一個Object,指示服務器上可用的可選擴展。如果設置了相應的功能,則只能調用某些方法。定義了以下功能:
name
|
type
|
description
|
power
|
boolen
|
Machine power control is available(機器功率控制可用)
|
Events(事件)
connect
The connect event is fired when the RFB object has completed the connection and handshaking with the server.
當RFB對象完成與服務器的連接和握手時,將觸發connect事件。
disconnect
The disconnect event is fired when the RFB object disconnects.
當RFB對象斷開連接時,將觸發disconnect事件。
credentialsrequired
The credentialsrequired event is fired when more credentials must be given to continue.
當必須提供更多憑據以繼續時,將觸發credentialsrequired事件。
securityfailure
The securityfailure event is fired when the security negotiation with the server fails.
與服務器的安全協商失敗時會觸發securityfailure事件。
clipboard
The clipboard event is fired when clipboard data is received from the server.
從服務器收到剪貼板數據時會觸發剪貼板事件。
bell
The bell event is fired when a audible bell request is received from the server.
當從服務器收到聲音響鈴請求時,將觸發鈴聲事件。
desktopname
The desktopname event is fired when the remote desktop name changes.
遠程桌面名稱更改時會觸發desktopname事件。
capabilities
The capabilities event is fired when RFB.capabilities is updated.
更新rfb.capabilities時將觸發Capabilities事件。
Methods(方法)
RFB.disconnect()
Disconnect from the server.
斷開與服務器的連接。
RFB.sendCredentials()
Send credentials to server. Should be called after the credentialsrequired event has fired.
將憑據發送到服務器。應在credentialsrequired事件觸發后調用。
RFB.sendKey()
Send a key event.
發送重要事件。
RFB.sendCtrlAltDel()
Send Ctrl-Alt-Del key sequence.
發送Ctrl-Alt-Del鍵序列。
RFB.focus()
Move keyboard focus to the remote session.
將鍵盤焦點移動到遠程會話。
RFB.blur()
Remove keyboard focus from the remote session.
從遠程會話中刪除鍵盤焦點。
RFB.machineShutdown()
Request a shutdown of the remote machine.
請求關閉遠程計算機。
RFB.machineReboot()
Request a reboot of the remote machine.
請求重新啟動遠程計算機。
RFB.machineReset()
Request a reset of the remote machine.
請求重置遠程計算機。
RFB.clipboardPasteFrom()
Send clipboard contents to server.
將剪貼板內容發送到服務器
Details(細節)
RFB()
The RFB() constructor returns a new RFB object and initiates a new connection to a specified VNC server.
RFB()構造函數返回一個新的RFB對象,並啟動與指定VNC服務器的新連接。
Syntax
let rfb = new RFB( target, url [, options] );
Parameters
target
A block HTMLElement that specifies where the RFB object should attach itself. The existing contents of the HTMLElement will be untouched, but new elements will be added during the lifetime of the RFB object.
一個塊HTMLElement,指定RFB對象應該附加到哪里。 HTMLElement的現有內容將不受影響,但在RFB對象的生命周期內將添加新元素。
url
A DOMString specifying the VNC server to connect to. This must be a valid WebSocket URL.
指定要連接的VNC服務器的DOMString。這必須是有效的WebSocket URL。
options Optional
An Object specifying extra details about how the connection should be made.
一個Object,指定有關如何建立連接的額外詳細信息。
Possible options:
shared
A boolean indicating if the remote server should be shared or if any other connected clients should be disconnected. Enabled by default.
一個布爾值,指示是否應該共享遠程服務器或是否應斷開任何其他連接的客戶端。默認情況下啟用。
credentials
An Object specifying the credentials to provide to the server when authenticating. The following credentials are possible:
一個Object,指定在進行身份驗證時提供給服務器的憑據。可以使用以下憑據:
name type description
"username" DOMString The user that authenticates
"password" DOMString Password for the user
"target" DOMString Target machine or session
repeaterID
A DOMString specifying the ID to provide to any VNC repeater encountered.
DOMString,指定要提供給遇到的任何VNC轉發器的ID。
connect
The connect event is fired after all the handshaking with the server is completed and the connection is fully established. After this event the RFB object is ready to recieve graphics updates and to send input.
在完成與服務器的所有握手並完全建立連接之后,將觸發connect事件。在此事件之后,RFB對象已准備好接收圖形更新並發送輸入。
disconnect
The disconnect event is fired when the connection has been terminated. The detail property is an Object that contains the property clean. clean is a boolean indicating if the termination was clean or not. In the event of an unexpected termination or an error clean will be set to false.
終止連接時會觸發disconnect事件。 detail屬性是一個包含屬性clean的Object。 clean是一個布爾值,表示終止是否干凈。如果發生意外終止或錯誤,則清除將設置為false。
credentialsrequired
The credentialsrequired event is fired when the server requests more credentials than were specified to
RFB(). The detail property is an Object containing the property types which is an Array of DOMString listing the credentials that are required.
當服務器請求的憑據多於為RFB()指定的憑據時,將觸發credentialsrequired事件。 detail屬性是一個包含屬性類型的Object,它是一個DOMString數組,列出了所需的憑據。
securityfailure
The securityfailure event is fired when the handshaking process with the server fails during the security negotiation step. The detail property is an Object containing the following properties:
在安全協商步驟期間與服務器的握手過程失敗時會觸發securityfailure事件。 detail屬性是一個包含以下屬性的Object:
Property
|
Type
|
Description
|
status
|
long
|
The failure status code(失敗狀態代碼)
|
reason
|
DOMString
|
The optional reason for the failure(失敗的可選原因)
|
The property status corresponds to the
SecurityResult status code in cases of failure. A status of zero will not be sent in this event since that indicates a successful security handshaking process. The optional property reason is provided by the server and thus the language of the string is not known. However most servers will probably send English strings. The server can choose to not send a reason and in these cases the reason property will be omitted.
在失敗的情況下,屬性狀態對應於SecurityResult狀態代碼。在此事件中不會發送狀態為零,因為這表示成功的安全握手過程。可選屬性原因由服務器提供,因此字符串的語言未知。但是大多數服務器可能會發送英文字符串服務器可以選擇不發送原因,在這些情況下,將省略屬性。
clipboard
The clipboard event is fired when the server has sent clipboard data. The detail property is an Object containing the property text which is a DOMString with the clipboard data.
服務器發送剪貼板數據時會觸發剪貼板事件。 detail屬性是一個包含屬性文本的Object,它是帶有剪貼板數據的DOMString。
bell
The bell event is fired when the server has requested an audible bell.
當服務器請求響鈴時,會觸發鈴聲事件。
desktopname
The desktopname event is fired when the name of the remote desktop changes. The detail property is an Object with the property name which is a DOMString specifying the new name.
當遠程桌面的名稱更改時,將觸發desktopname事件。 detail屬性是一個Object,其屬性名稱是指定新名稱的DOMString。
capabilities
The capabilities event is fired whenever an entry is added or removed from RFB.capabilities. The detail property is an Object with the property capabilities containing the new value of RFB.capabilities.
只要在RFB.capabilities中添加或刪除條目,就會觸發capabilities事件。 detail屬性是一個Object,其屬性功能包含RFB.capabilities的新值。
RFB.disconnect()
The RFB.disconnect() method is used to disconnect from the currently connected server.
RFB.disconnect()方法用於斷開與當前連接的服務器的連接。
Syntax(語法)
RFB.disconnect( );
RFB.sendCredentials()
The RFB.sendCredentials() method is used to provide the missing credentials after a credentialsrequired event has been fired.
RFB.sendCredentials()方法用於在觸發憑證所需事件后提供缺少的憑據。
Syntax
RFB.sendCredentials( credentials );
Parameters
credentials(證書)
- An Object specifying the credentials to provide to the server when authenticating. See RFB() for details.
- 一個Object,指定在進行身份驗證時提供給服務器的憑據。有關詳細信息,請參閱RFB()。
RFB.sendKey()
The RFB.sendKey() method is used to send a key event to the server.
RFB.sendKey()方法用於將密鑰事件發送到服務器。
Syntax
RFB.sendKey( keysym, code [, down] );
Parameters
keysym
- A long specifying the RFB keysym to send. Can be 0 if a valid code is specified.
- 指定要發送的RFB密鑰的long。如果指定了有效代碼,則可以為0。
code
- A DOMString specifying the physical key to send. Valid values are those that can be specified toKeyboardEvent.code. If the physical key cannot be determined then null shall be specified.
- 指定要發送的物理密鑰的DOMString。有效值是可以指定給KeyboardEvent.code的值。如果無法確定物理密鑰,則應指定null。
down Optional
- A boolean specifying if a press or a release event should be sent. If omitted then both a press and release event are sent.
- 一個布爾值,指定是否應發送按下或釋放事件。如果省略,則發送按下和釋放事件。
RFB.sendCtrlAltDel()
The RFB.sendCtrlAltDel() method is used to send the key sequence left Control, left Alt, Delete. This is a convenience wrapper around
RFB.sendKey().
RFB.sendCtrlAltDel()方法用於發送左鍵Control,左Alt,Delete的鍵序列。這是RFB.sendKey()的便利包裝器。
Syntax
RFB.sendCtrlAltDel( );
RFB.focus()
The RFB.focus() method sets the keyboard focus on the remote session. Keyboard events will be sent to the remote server after this point.
RFB.focus()方法將鍵盤焦點設置在遠程會話上。此后,鍵盤事件將發送到遠程服務器。
Syntax
RFB.focus( );
RFB.blur()
The RFB.blur() method remove keyboard focus on the remote session. Keyboard events will no longer be sent to the remote server after this point.
RFB.blur()方法刪除遠程會話上的鍵盤焦點。此后,鍵盤事件將不再發送到遠程服務器。
Syntax
RFB.blur( );
RFB.machineShutdown()
The RFB.machineShutdown() method is used to request to shut down the remote machine. The capability power must be set for this method to have any effect.
RFB.machineShutdown()方法用於請求關閉遠程計算機。必須為此方法設置能力才能產生任何效果。
Syntax
RFB.machineShutdown( );
RFB.machineReboot()
The RFB.machineReboot() method is used to request a clean reboot of the remote machine. The capability power must be set for this method to have any effect.
RFB.machineReboot()方法用於請求徹底重啟遠程計算機。必須為此方法設置能力才能產生任何效果。
Syntax
RFB.machineReboot( );
RFB.machineReset()
The RFB.machineReset() method is used to request a forced reset of the remote machine. The capability power must be set for this method to have any effect.
RFB.machineReset()方法用於請求強制重置遠程計算機。必須為此方法設置能力才能產生任何效果。
Syntax
RFB.machineReset( );
RFB.clipboardPasteFrom()
The RFB.clipboardPasteFrom() method is used to send clipboard data to the remote server.
RFB.clipboardPasteFrom()方法用於將剪貼板數據發送到遠程服務器。
Syntax
RFB.clipboardPasteFrom( text );
Parameters
text
- A DOMString specifying the clipboard data to send. Currently only characters from ISO 8859-1 are supported.
- 指定要發送的剪貼板數據的DOMString。目前僅支持ISO 8859-1中的字符。