How to set up the Remote Desktop using the Web APIs

Note: The UBIQUITY APIs invoke the https://ubiquity.asem.it endpoint.

You can set up a Remote Desktop connection in your web page using the UBIQUITY Web APIs. To do so, follow the three steps described below:

  1. Authenticate to your domain in UBIQUITY Manager.
  2. Obtain the UID of the device to which you wish to connect.
  3. Open the Remote Desktop of the selected device.

Authenticate to your domain in UBIQUITY Manager

Authenticate to your domain by using the /api/user/authenticate API.

The authentication may occur in two ways.
  • By entering your email and password
  • By entering your domain, username and password
Note: You might be required to perform a Two-factor authentication, if this latter is activated.

The example below shows an authentication carried out by using email and password as credentials.

var jwt;const login = async (email, password) => {
  var endpoint = document.getElementById ('endpoint').value;
  const response = await fetch (endpoint + '/api/user/authenticate', {
      method: 'POST',
      body: JSON.stringify({
          'Email': email,
          'Password': password
      )},
      headers: {
          'Content-Type': 'application/json'
      }
   });
jwt = await response.text();
document.getEelementById('jwt').innerHTML = jwt;
}

var loginButton = document.getElementById('loginButton');
loginButton.addEventListener('click', () => }
    var email = document.getElementById('email').value;
    var password = document.getElementById('Password').value;
    login(email, password);
});
Once you have entered your credentials and they are correct, a token will be generated and will expire after one week. Use this token to carry out the next operation.
Note: A token includes personal information and shall not be shared.

Obtain the UID of the device to which you wish to connect

Use the /api/devices/find API to identify the device with which you wish to establish a Remote Desktop connection.

You can retrieve the device GUID by providing the device location path within its domain.

var guid;const getGUID = async (path) => {
  var endpoint = document.getElementById ('endpoint').value;
  const response = await fetch (endpoint + '/api/devices/find?path=' + path, {
      method: 'GET',
      headers: {
          'Authorization': 'Bearer' + jwt,
      }
  });
  var jsonResponse = await response.json ();
  guid = jsonResponse.Id;
  document.getElementById('guid').innerHTML = guid;
}var deviceGUIDButton = document.getElementById('deviceGUIDButton');
deviceGUIDButton.addEventListener('click', () => {
    var path = document.getElementById('path').value;
    getGUID(PATH);
});

Once you have entered the path, if correct, you will be provided with the device GUID.

Open the Remote Desktop of the selected device

Once you have gotten both the device UID and the token, you can establish a Remote Desktop connection, by using the URL: Endpoint + /controlcenter/remoteDesktop/ + GUID + Token.

var connectButton = document.getElementById('connectButton');
connectButton.addEventListener('click', () => {var endpoint = document.getElementById('endpoint').value;var url = endpoint + "/controlcenter/remoteDesktop/" + guide + "?accessToken" + jwt;var deviceDesktop = document.getElementById('deviceDesktop');
deviceDesktop.src = url;

It is now possible to view the Remote Desktop of the connected device within the designated web page.