How to set up the Remote Desktop using the Web APIs
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:
- Authenticate to your domain in UBIQUITY Manager.
- Obtain the UID of the device to which you wish to connect.
- 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.
- By entering your email and password
- By entering your domain, username and password
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);
});
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.