Cannot connect to Live Queries

I’m trying to connect to Live Queries via Node JS.

I’m using the latest version of parse and I’ve installed via docker. In my docker I have the following environnement variables:
PARSE_SERVER_START_LIVE_QUERY_SERVER=1
PARSE_SERVER_LIVE_QUERY={“classNames”:[“testClass”,“xxxx”]}

Here is my js code :

const Parse = require('parse/node');
Parse.initialize(process.env.PARSE_APP_ID, "", process.env.PARSE_MASTER)
Parse.serverURL = "https://xxx.com/parse"

let query = new Parse.Query("testClass");
let subscription = await query.subscribe()

subscription.on('open', () => {
        console.log('subscription opened');
    });

Nothing happens/nothing shows in my console

Can anyone help me?

Do you see any error message or useful information on your docker logs? Are you using any reverse proxy on top of your docker container? Is it ready to receive ws connections? Could you please also add this code and let me know the results?

Parse.LiveQuery.on('open', () => {
  console.log('socket connection established');
});
Parse.LiveQuery.on('close', () => {
  console.log('socket connection closed');
});
Parse.LiveQuery.on('error', (error) => {
  console.log(error);
});

Your “proxy” answer got me on the right track !!! I’m using Caprover as my PaaS, and I had to enable websockets

Thanks @davimacedo

…however @davimacedo , I’m not seing any updates when my table is updated.

Now, in my console, I have

sub {"_events":{},"_eventsCount":1,"id":1,"query":{"where":{}},"subscribePromise":{},"subscribed":true}
subscription opened

However, when I add data into my class, nothing happens.

How do you create objects? objects need to be created through parse server which means if you are creating or modifying objects directly in database live query will not work. Try creating objects with dashboard. Also you need to specify classes that you will listen on parse server constructor

Objects are created using a function, using

const Object = Parse.Object.extend("xxx");
        const object = new Object();
        object.set("dateUnix", timestamp)

        object.save()
            .then((object) => {
})
etc.

My feeling is that the issues comes from the fact that I have to provide a list of live queries like:

liveQuery: {
      classNames: ["xxxx"]
    }

I’m using docker so I’m specifying this in the env variables, like presented here: https://github.com/parse-community/parse-server/blob/alpha/src/Options/Definitions.js#L325 (so adding PARSE_SERVER_LIVEQUERY_CLASSNAMES=xxxx). But it does not seem to work.

Ok, finally made it work. I must say the documentation is not very clear/misleading. The environment variable must be
PARSE_SERVER_LIVE_QUERY={“classNames”:[“people”,“monitor”]}

Thanks for sharing the solution. Would you be interested in sending a PR to the documentation repository improving that for the community?

I’m more than happy to help and contribute. I’m a hobby developer and never done this before. Can you guide me or can I just send you an explication of my final solution for you to update ?

Here is the steps:

1- Fork the doc repo.
2- Clone the repo to your computer with git clone method.
3- create a new branch with git branch myfix
4- switch to that branch git checkout myfix
5- modify the files you want to contribute.
6- commit changes with git commit -a -m "doc improvments or whatever you can modify this"
7- push commit with git push

After all of this, Go to the repository on your profile. You will see a message with a button which says create a pull request. Click that and create a pull request. After that team members will review your changes and if the changes are ok, they will merge it.

Edit: ıf this is the first time you use git, ıt will ask you to configure global config. If thats the case
run these commands

git config --global user.email your-mail-adress
git config --global user.name your-name

Also it may ask for your credentials. You will enter your username. And for the password you have to enter token. You can create token here https://github.com/settings/tokens