Creating a Connection using WebSockets

In the case of Qlik Sense Desktop, all you need to do is define a WebSocket variable, including its connection string in the following way:

var ws = new WebSocket("ws://localhost:4848/app/");

Once the connection is opened and checking for ws.open(), you can call additional methods to the engine using ws.send().

This example will retrieve the number of available documents in my Qlik Sense Desktop environment, and append them to an HTML list:

<html>
<body>
<ul id='docList'>
</ul>
</body>
</html>
<script>
var ws = new WebSocket("ws://localhost:4848/app/");
var request = {
"handle": -1,
"method": "GetDocList",
"params": {},
"outKey": -1,
"id": 2
}
ws.onopen = function(event){
ws.send(JSON.stringify(request));
// Receive the response
ws.onmessage = function (event) {
var response = JSON.parse(event.data);
if(response.method != ' OnConnected'){
var docList = response.result.qDocList;
var list = '';
docList.forEach(function(doc){
list += '<li>'+doc.qDocName+'</li>';
})
document.getElementById('docList').innerHTML = list;
}
}
}
</script>

The preceding example will produce the following output on your browser if you have Qlik Sense Desktop running in the background:

All Engine methods and calls can be tested in a user-friendly way by exploring the Qlik Engine in the Dev Hub, as also described in Chapter 11, Working with Qlik Sense Dev Hub.
A single WebSocket connection can be associated with only one engine session (consisting of the app context, plus the user). If you need to work with multiple apps, you must open a separate WebSocket for each one.

If you wish to create a WebSocket connection directly to an app, you can extend the configuration URL to include the application name, or in the case of the Qlik Sense Enterprise, the GUID. You can then use the method from the app class and any other classes as you continue to work with objects within the app.

var ws = new WebSocket("ws://localhost:4848/app/MasteringQlikSense.qvf");
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.41.27