ReactJS Failed to construct 'WebSocket': The subprotocol '[object Object]' is invalid

Viewed 463

I'm getting the following error in my react application using enigma.js (https://qlik.dev/apis/javascript/enigmajs) . I'm trying to initialize a WebSocket connection and im getting the error. "Failed to construct 'WebSocket': The subprotocol '[object Object]' is invalid".

The WebSocket connection URL is correct as it can be tested with https://catwalk.core.qlik.com/?engine_url=wss://sense-demo.qlik.com/app/133dab5d-8f56-4d40-b3e0-a6b401391bde which returns the data. You can try by editing the URL which will return an error.

the code is

async init() {
    
const appId = "133dab5d-8f56-4d40-b3e0-a6b401391bde";
    const url =
      "wss://sense-demo.qlik.com/app/133dab5d-8f56-4d40-b3e0-a6b401391bde"; 

    const session = enigma.create({
      schema,
      createSocket: () =>
        new WebSocket(url, {
        }),
    });

    const global = await session.open();
    const app = await global.openDoc(appId);
    const appLayout = await app.getAppLayout();

    console.log(appLayout);

  }
2 Answers

I found the solution: qDoc.config.js

const enigma = require('enigma.js');
const schema = require('enigma.js/schemas/12.20.0.json');
const SenseUtilities = require('enigma.js/sense-utilities');

const config = {
  host: 'sense-demo.qlik.com',
  secure: true,
  port: 443,
  prefix: '',
  appId: '133dab5d-8f56-4d40-b3e0-a6b401391bde',
};

const url = SenseUtilities.buildUrl(config);

async function init() {
  const session = enigma.create({
    schema,
    url,
    suspendOnClose: true,
  });

  const global = await session.open();
  const app = await global.openDoc(config.appId);
  const appLayout = await app.getAppLayout();

  console.log(appLayout);
}
init();

const session = enigma.create({ schema, url, suspendOnClose: true });

// open doc and return promise which will resolve to doc
export const openDoc = () => (
  session.open().then((global) => global.openDoc(config.appId))
);

// close session
export const closeSession = () => (
  session.close()
);

INSTURCTION

  1. downoad this project
  2. delete package-lock.json file
  3. npm i
  4. npm run-script dev
  • This is the direvtory view:

enter image description here

  • This is result log:
    enter image description here
Related