Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to construct 'WebSocket': The subprotocol '[object Object]' is invalid. #889

Closed
gangataarun opened this issue Sep 1, 2021 · 2 comments

Comments

@gangataarun
Copy link

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

Websocket connection not working

I'm trying to run the basic example in ReactJs on the browser from https://qlik.dev/libraries-and-tools/enigmajs on the QlikSense SaaS platform. Below is my code

`async init() {
var auth = await this.connect();

const appId = "xxx";
const tenant = "xxx.eu.qlikcloud.com";
const apiKey = key;  //apikey

const url = `wss://${tenant}/app/${appId}`;

console.log(url);
const session = enigma.create({
  schema,
  createSocket: () =>
    new WebSocket(url, {
      headers: { Authorization: `Bearer ${apiKey}` }
    })
});
session.on("traffic:sent", (data) => console.log("sent:", data));
session.on("traffic:received", (data) => console.log("received:", data));

console.log(`Bearer ${apiKey}`);

const global = await session.open();
console.log("session created");
const app = await global.openDoc(appId);
const appLayout = await app.getAppLayout();

console.log(appLayout);

}

`

image

I'm expecting the app layout to console.log

@countnazgul
Copy link

The example, you are following, is for Node.js.
In browser environment you cant set the web socket headers. The browser will send the relevant headers with your request. If the relevant headers/url parammes are not passed then the connection will fail.

If your case you should authenticate first, get yourself csrf token and then open enigma connection (passing the web intergration id and the csrf token in the web socket url)

Have a look at this tutorial https://qlik.dev/tutorials/build-a-simple-web-app

@gangataarun
Copy link
Author

Hi @countnazgul,

Thank you for your help. I got the csrf token and was able to connect to the engine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants