Advanced HLL - Basics
Here we will introduce some basic API's just to for you to get started with A-HLL API's.
Before start digging into API basics it is important to know that all requests are asynchronous. In order to link request and response we need to use unique request identifier rid. Value can be set to current time in milliseconds.
NOTE: Every request have rid property which is unique request id.
This is standard approach for many frameworks in JavaScript dealing with AJAX requests. Usually, callback function and rid are stored in expiring cache. When response is received, rid from response is matched with rid in cache, and if found, attached callback function is called to signal requester.
Take for example mem-cache.
var Cache = require('mem-cache');
var cache = new Cache();
// create websocket connection to GreenScreens Native Terminal
var ws = new WebSocket('ws://localhost:5250')
// handle response from GreenScreens Native Terminal
ws.onmessage = function (evt) {
// parse received text data into JSON
var data = JSON.parse(evt.data);
// take rid from response and look into cache
var cdata = cache.get(data.rid);
// if request stored into cache and have callback function, execute it
if (cdata && typeof cdata.callback === 'function') {
cdata.callback(data);
}
}
// function to store request into cache and make remote request
function request(req, callback) {
// store request into cache for 30 seconds
cache.set(req.rid, {callback : callback}, 30000);
// send request to GreenScreens Native Terminal
ws.send(req);
}
...
// prepare A-HLL API command
var req = {"cmd": "echo", "rid": Date.now()};
// send A-HLL command to terminal and attach response handler
request(req, function(resp){
console.log(resp.rid);
});
Basic API's
Functions listed here are available only for Green Screens Terminal Client. There are also functions for screen handling like getting field information, setting field data and cursor position, issuing key commands etc...
echo
Send signal to terminal and get the same response back.
-
Request format :
{ "cmd": "echo", "all": true, "rid": Date.now() }
-
Parameters :
- all - terminal will broadcast response to all connected A-HLL API clients
queryConfigs
Get list of available connection configurations
-
Request format :
{ "cmd": "queryConfigs", "rid": Date.now() }
startTerminal
Start new terminal session by given configuration id
-
Request format :
{ "cmd": "startTerminal", "cfgID": "1", "winID": "0", "rid": Date.now() }
-
Parameters
- cfgID - connection configuration ID
- winID - terminal window ID (optional), used to reconnect
if not set new terminal screen will open
queryInstances
Retrieve list of all active terminals
-
Request format :
{ "cmd": "queryInstances", "rid": Date.now() }
-
Response format :
{ "status": true, "rid": 1, "data" : ["1", "2"...] // id's of terminal windows }
closeWindow
Close terminal by given id
-
Request format :
{ "cmd": "closeWindow", "winID" : "1", "rid": Date.now() }
getWindowStatus
Return window data, fields, oia, cursor position
-
Request format :
{ "cmd": "getWindowStatus", "winID" : "1", "rid": Date.now() }