Once authenticated with the session server, the SDK provides programmatic access to host sessions via the Host Access API, the same rich interface that is available to macros in Host Access for the Cloud.
Building a more complete example
This simple web application was written in vanilla JavaScript for broad compatibility. It demonstrates the following concepts:
- Creating the ZFE object
- Connecting to a session server
- Using the session manager to find a specific session descriptor/configuration
- Using the session manager to create a session
- Using the Wait and PresentationSpace objects to interact with a session
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Embed SDK Basics</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="https://zfe.company.com:7443/webclient/connector/zfe-embed-sdk.js"></script>
</head>
<body>
<div id="my-host-app" style="width: 800px; height: 600px"></div>
<script>
// Create the connector
var zfe = new ZFE.ZFE({
url: 'https://zfe.company.com:7443/webclient/',
username: 'johnsm',
password: '12345',
domain: 'CORPDOM',
target: document.getElementById('my-host-app')
});
// Connect to the session server
zfe.connect()
.then(function() {
// Get the session manager and a list of available descriptors
var sessionManager = zfe.getSessionManager();
sessionManager.getDescriptors()
.then(function(descriptors) {
// Find the desired descriptor
var descriptor;
for (var ii = 0; ii < descriptors.length; ii++) {
if (descriptors[ii].getName() === 'my-session') {
descriptor = descriptors[ii];
break;
}
}
// Create the host session
sessionManager.createSession(descriptor)
.then(function(session) {
// Get APIs for interacting with the host session
var presentationSpace = session.getPresentationSpace();
var wait = new ZFE.Wait(session);
// Wait for specific text on the terminal display
wait.forText('PROMPT', new ZFE.Position(19, 3))
.then(function() {
// Wait for the cursor to appear in a specific location
wait.forCursor(new ZFE.Position(24, 2))
.then(function() {
// Submit a command
presentationSpace.sendKeys('LOGIN');
presentationSpace.sendKeys(ZFE.ControlKey.ENTER);
});
});
});
});
})
.catch(function(error) {
console.error('Unexpected error', error);
});
</script>
</body>
</html>