CloudHost : Cloud host operation support components

更新时间:
2024-05-15
下载文档

CloudHost : Cloud host operation support components

This module provides cloud host connection and management functions. Developers can use this module to implement thin client functions. The currently supported cloud computer connection protocol is the RDP v10 protocol. For details about RDP, please refer to: Remote Desktop Protocolopen in new window. This module is available on EdgerOS 1.8.8 and later.

User can use the following code to import the Connector module.

var Connector = require('cloudhost/connector');

EdgerOS apps needs permission.display permission to use the printer. For details, please refer to permission.

Support

The following shows Connector module APIs available for each permissions.

 User ModePrivilege Mode
Connector
Connector.support
Connector.statis 
connector.connect
connector.disconnect
connector.isConnected
connector.screenshot

Cloud Host Connector Class

new Connector()

  • Returns: {Object} Connector object.

Create a Cloud Host Connector object.

Connector.support()

  • Returns: {Boolean} Whether the current system support this feature.

Get whether the current system support this feature. Limited by the computing power of the hardware carrier, different EdgerOS distributions will selectively provide this feature.

Connector.statis(channel, callback)

  • channel {Integer} Display channel.
  • callback {Function} Callback function.
    • error {Error} Indicate error when get statistic fails.
    • statis {Object} Statistic of specific channel.

Get statistic of specific channel.

Cloud Host Connector Object

connector.connect(host, port, channel[, opt][, callback])

  • host {String} Cloud host IP address or URL.
  • port {Integer} Cloud host port. Typically 3389.
  • channel {Integer} Display channel. For related introduction, please refer to Display.
  • opt {Object} Connection options.
    • login {Object} Login option. Optional according to auth mode.
    • auth {Object} Authentication options. default: auto select.
    • quality {Object} Quality option. default: auto detect.
    • security {Object} Security connection options. Optional according to auth mode.
    • printer {Boolean} Whether to map local printers to cloud hosts. default: false.
    • auxstorage {String} Current App auxiliary storage to the cloud host. default: not mapped.
  • callback {Function} Callback function.
    • error {Error} Indicate error when connection fails.

Create a remote host connection and project the remote host screen and audio to the local display channel. The opt.printer and opt.auxstorage option allows the remote host to use the local auxiliary storage and printer device, but current App must have the relevant permissions (printer and auxstorage). For related introduction, please refer to permission. If you want to map the root directory of the current App auxiliary storage space, then opt.auxstorage can be 'aux:/'.

If you need to specify login information, you can use the opt.login option, which can contain the following information:

  • user {String} User name.
  • passwd {String} Password. default: no password.
  • domain {String} The domain name that the user is in on a Windows(R) system. default: no domain name.

If you need to specify authentication options.

  • mode {Array} Authentication modes that can be selected.

auth.mode can include the following modes, default is ['rdp', 'tls', 'nla']

ModeDescription
'rdp'Standard RDP
'tls'Transport Layer Security (Recommended)
'nla'Network Level Authentication
'ext'NLA Extended

The appropriate connection quality can be selected according to the current processor capacity and network connection quality. the opt.quality option contains the following parameters:

  • graph {String} Graphics quality: 'low', 'medium' or 'high'. default: auto select.
  • network {String} Network quality: 'low', 'medium' or 'high'. default: auto select.

A secure connection to the cloud host can be made using TLS, the opt.security option contains the following parameters:

  • rejectUnauthorized {Boolean} Whether the server certificate should be verified against the list of supplied CAs. default: false.
  • ca {String} Trusted CA certificates chain. default: undefined.
  • server {String} Set the server host name (usually is the server domain name) to verify received server certificate. default: automatically obtain.

Example

var connector = new Connector();

// Connect to LAN host
connector.connect('192.168.128.22', 3389, 0);

// Connect to remote host automatically abort connection for any certificate that can not be validated.
connector.connect('cloudhost.myexample.com', 3389, 0, {
  security: { rejectUnauthorized: true }
});

// Connect to host and specify the CA certificate and server common name.
connector.connect('10.0.0.2', 3389, 0, {
  security: { rejectUnauthorized: true, ca: '...', server: 'cloudhost.myexample.com' }
});

If the cloud hosting provider develops the App, it is recommended to use mutual authentication, and the client certificate scope is the scope of use and purchase.

connector.disconnect([callback])

  • callback {Function} Callback function.
    • error {Error} Indicate error when disconnect fails.

Disconnect from the cloud host.

connector.isConnected()

  • Returns: {Boolean} Is connected.

Whether the current object establishes a connection with the cloud host.

connector.screenshot(callback)

  • callback {Function} Callback function.
    • error {Error} Indicate error when screenshot fails.
    • picture {Buffer} Screenshot picture with JPEG format.

Get a screenshot of the currently connected cloud host.

Example

var connector = new Connector();

connector.connect(..., function(error) {
  if (error == undefined) {
    connector.screenshot(function(error, picture) {
      if (Buffer.isBuffer(picture)) {
        // save this picture...
      }
    });
  }
});

This feature is available on EdgerOS 2.0.6 and above.

Cloud Host Connector Object Events

The Cloud Host Connector Object inherits from the EventEmitter class. The following events are thrown in some specific situations.

connect

This event is generated when the cloud host is successfully connected.

disconnect

  • info {Object} Disconnect information.
    • passive {Boolean} Whether to passively disconnect.

This event is generated when the cloud host is disconnected.

error

  • error {Error}

This event is generated when the cloud host connect error.

Example

var connector = new Connector();

connector.on('connect', function() {
  console.info('Remote host connected!');
});

connector.on('disconnect', function() {
  console.info('Remote host disconnected!');
});

connector.on('error', function(error) {
  console.error('Remote host connect error:', error);
});

// Connect to LAN host
connector.connect('192.168.128.22', 3389, 0);

As long as any application has the auxstorage permission, it can use the 'cloudhost/storage' module to add storage mapping to the running cloud host.

var storage = require('cloudhost/storage');

Support

The following shows storage module APIs available for each permissions.

 User ModePrivilege Mode
storage.plugin
storage.plugout
storage.possible

Cloud Host Storage Object

storage.plugin(channel, path[, name][, callback])

  • channel {Integer} The display channel of the currently working cloud host.
  • path {String} Auxiliary storage path.
  • name {String} Mounted name displayed on the cloud host. default: 'DYNAMIC_PLUGIN'.
  • callback {Function} Callback function.
    • error {Error} Indicate error when plugin fails.

Map the specified auxiliary storage path to the specified cloud host. name length range is 1 ~ 32.

Example

// Map auxiliary storage root dir
storage.plugin(0, 'aux:/', error => {
  // ...
});

// Map auxiliary storage specified dir
storage.plugin(0, 'aux:/camera_save/', 'CAMERA', error => {
  // ...
});

storage.plugout(channel, path[, callback])

  • channel {Integer} The display channel of the currently working cloud host.
  • path {String} Auxiliary storage path.
  • callback {Function} Callback function.
    • error {Error} Indicate error when plugout fails.

Unmap the path that has been plugin before.

storage.possible(channel, callback)

  • channel {Integer} The display channel.

Check storage plugin possibility on specified display channel. This function is available on EdgerOS 2.1.1 and above.

Example

storage.possible(0, function(error) {
  if (error) {
    // This channel cannot perform storage plug operations
  } else {
    // This channel can perform storage plug operations
  }
});

Cloud Host Storage Object Events

The Cloud Host Storage Object inherits from the EventEmitter class. The following events are thrown in some specific situations.

plugin

  • channel {Integer} The display channel.
  • path {String} Auxiliary storage path.

This event is emit when the specified auxiliary storage plugin succeeds.

plugout

  • channel {Integer} The display channel.
  • path {String} Auxiliary storage path.

This event is emit when the specified auxiliary storage plugout succeeds. When the corresponding could host is disconnected, the storage of the previous plugin will be automatically plugged out.

文档内容是否对您有所帮助?
有帮助
没帮助