qlik-oss/enigma.js

Session close is not working

hshahul opened this issue · 9 comments

Hi,
I am using Angular + Enigma JS with Qlik sense for my application. I have common service with promise for getting data from Qlik with different app id.

   return new Promise((resolve, reject) => {
    enigma.create(config).open().then(global=> {
      global.openDoc(appID).then(app => {
        app.createSessionObject(def).then(obj => {
      
          resolve (obj);
        });
      });

    })
   .then(() => session.close())
    .then(() => console.log('Session closed'))
  .catch(err => console.log('Something went wrong :(', err));

I tried app.close() also but not working.
I am getting close is not a function. Can you please provide some suggestion for open and close web socket.

In your code, you are referring a session object that isn't defined.
Try setting you enigma.create(config) as session.

Have a look at https://github.com/qlik-oss/enigma.js/blob/3fb9b15374f3122d33432763b2fed70e2d194a66/examples/basics/lists/app-object-list.js

I tried setting enigma.create(config) as session, but getting the following error

core.js:15723 ERROR Error: Uncaught (in promise): Error: Not connected
Error: Not connected
at RPC.send (enigma.js:1558)
at enigma.js:744
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:391)
at Object.onInvoke (core.js:17298)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:390)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (zone.js:150)
at zone.js:889
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)
at Object.onInvokeTask (core.js:17289)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:422)
at resolvePromise (zone.js:831)
at resolvePromise (zone.js:788)
at zone.js:892
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)
at Object.onInvokeTask (core.js:17289)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:422)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:195)
at drainMicroTaskQueue (zone.js:601)
at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (zone.js:502)
at invokeTask (zone.js:1744)

Verify your config soo that it´s possible to connect to the QIX Engine.

You could add events listeners to the session.on event
https://github.com/qlik-oss/enigma.js/blob/master/docs/api.md#event-traffic-1

You also need a new web socket for each app that you open and if you are connecting through Qlik Sense Proxy there is a limit of 5 concurrent sessions per user.

Thanks for your response.
" Qlik Sense Proxy there is a limit of 5 concurrent sessions per user", so I am trying to close the sessions once data returned. but not able to close that sessions. I tried the following way:

  1. session.close();
    2.app.close();
  2. global.close();

But no luck. I am sure why close function is not working.

Think that there is some idle time in the proxy as well so the sessions isn't reusable right away.

I haven't used angular for a long time but a node.js script against Qlik Core would look something like:

const enigma = require('enigma.js');
const WebSocket = require('ws');
const Promise = require('bluebird');
const schema = require('enigma.js/schemas/12.20.0.json');

const config = {
  schema,
  url: 'ws://localhost:9076/app/',
  createSocket: (url) => new WebSocket(url),
}

const session = enigma.create(config);

(async () => {
  const global = await session.open();
  const apps = await global.getDocList();
  session.close();

  let infos = await Promise.map(apps, async appElm => {
    return await getDocInfo(appElm.qDocName);
  }, {concurrency: 5});

  console.log("INFOS:", infos);

})().catch(err => {
  console.error(err);
});

const getDocInfo = async (appName) => {
  let localconfig = { ...config };
  localconfig.url += `${encodeURIComponent(appName)}`

  const localSession = await enigma.create(localconfig)
  const localGlobal = await localSession.open();
  const app = await localGlobal.openDoc(appName);
  const appInfo = await app.getAppProperties();
  localSession.close();

  return appInfo;
}

And the concurrency for bluebird is set to 5 for not using more sessions than available

I tried same like to close my connection but showing the following error message

core.js:15723 ERROR Event {isTrusted: true, type: "error", target: WebSocket, currentTarget: WebSocket, eventPhase: 0, …}

Try to add some events to verify that you get a session, e.g.
https://github.com/qlik-oss/enigma.js/blob/master/docs/api.md#event-opened

Any progress with your session.close()?

What we can see there is no error in enigma.js and will close this issue if you don't provide a runnable example that demonstrates the issue

NO progress. Actually locally its working fine, i can connect more web sockets (nearly 25) without close connection. It is not working one iPad so i am planning to close that connection and open again whenever i need. But no luck. :(