Usage Examples (HTTP/HTTPS communication)

Here are some brief examples of how to implement the launcher execution script. The examples are implemented in JavaScript and can be modified to suit the environment used.

The example below is an example of running the Nexacro Platform app in the Google Chrome browser. Please refer to the full code for an example that is operated in the IE browser.

The X Platform or the My Platform applications run in the same method. The platform item value or required property value must be set according to the product.

New id Request

Fill in the item values of platform and action elements and then request a new id.

function start()
{
    objNexacro.platform = 'nexacro';
    objNexacro.action = 'create';
    sendData(true, true, createProcess);
}

function sendData(openpost, is_create, resultCallback) 
{
    delete xhrCreateObject;
    xhrCreateObject = null; 

    var sendObj = null;
    sendObj = new XMLHttpRequest();
    sendObj.reqType = 1;

    xhrCreateObject = sendObj;
    sendObj.onreadystatechange = resultCallback;
    var jsonData;
    jsonData = JSON.stringify(objNexacro);
    var timestamp = "/" + new Date().getTime();
    var send_url = openurl + ":" + openport + openurl_add + timestamp;
    console.log(send_url);

    sendObj.open("POST", send_url, "true");
    sendObj.send(jsonData);
    console.log(jsonData);    
    return sendObj;
}

function createProcess()
{
    if ( xhrCreateObject.readyState == 4 || xhrCreateObject.reqType == 2)  {
        console.log(xhrCreateObject.responseText);
    }          
}

The requested jsonDate item is as follows. Fill in only the element items to transmit.

{"platform":"nexacro","action":"create"}

It receives the request from the launcher service and assigns the id to return it. Check the id and result items. The id value will be used in the subsequent request.

{"action":"create","id":"1522821857","platform":"nexacro","result":"success"}

Required Property Setting

This is a function that is run when the [property setting(basic)] button is clicked in the example. Fill in the key, bjson, and enginesetupkey item values among the properties.

function do_property(test_action, action_sub)
{
    objNexacro.action = 'setproperty';
    objNexacro.value = { "key": "LauncherService", "bjson": "http://127.0.0.1:8080/start.json", "enginesetupkey":enginesetupkey};
    sendData(true, false, resultProcess);
}

In the case of deploying with the Local setting when deploying the Nexacro Platform app, the start.json path must be specified as a local address. In this case, specify the details as follows.

function do_property(test_action, action_sub)
{
    objNexacro.action = 'setproperty';
    objNexacro.value = { "key": "LauncherService", "bjson": "D:\\nexacro\\17\\start.json", "enginesetupkey":enginesetupkey};
    sendData(true, false, resultProcess);
}

The requested jsonDate item is as follows. The id value checked in the previous step is set and the key, bjson, and enginesetupkey item values are filled in.

{"action":"setproperty","id":"1522822903","platform":"nexacro","result":null,"value":{"key":"LauncherService","bjson":"http://127.0.0.1:8080/start.json","enginesetupkey":"{94FAAFF5-0E54-4539-AA67-*******}"}

Save the required property value in the launcher service and return the success or failure ("result":"success").

{"action":"setproperty","id":"1522823068","platform":"nexacro","result":"success","value":{"bjson":"http://127.0.0.1:8080/start.json","enginesetupkey":"{94FAAFF5-0E54-4539-AA67-*******}","key":"LauncherService"}}

Method Execution

This is a function that is run when the [launch] button is clicked in the example.

function do_method(test_action) {
    objNexacro.action = 'method';
    objNexacro.value = {"launch": null};
    sendData(true, false, resultProcess);
}

The key, bjson, and enginesetupkey item values were transmitted in the previous step and the corresponding value is saved in the launcher service. Since the id value is saved as the key value, the operation will be based on the id value when executing the method or performing other actions later.

{"action":"method","id":"1522823068","platform":"nexacro","result":null,"value":{"launch":null}}

Execute the method in the launcher service and return the success or failure ("result":"success"). If the method is executed normally, then the app installed in the operating system is executed.

{"action":"method","id":"1522823068","platform":"nexacro","result":"success","value":{"launch":null}}

Full Code

The usage example code can be downloaded from the link below.

localtest_nexacro_sample.html

The example code contains the following problem processing method.

if (window.XMLHttpRequest) {
    sendObj = new XMLHttpRequest();
    sendObj.reqType = 1;
} else if (window.XDomainRequest) {
    sendObj = new XDomainRequest();
    sendObj.reqType = 2; 
}
function http_onerror()
{
    if (objNexacro.action == 'create') {
        if (findport == false) {
            if ( setport > 0) {
                setport = 0;
                openport = parseInt(getCookie("tplsvcopenport"), 10) | 0;
                if (openport > 0) {
                    sendData(true, true, createProcess);
                    return;
                }
            }
            openport = 7895;
        } else {
            openport++;
        }
        findport = true;

        if (openport <= 7935) //New launcher must open one port between 7895 and 7935; 
            sendData(true, true, createProcess);
        else
            alert("Please check if the launcher service has not been installed or has stopped operation.");          
    }     
}