parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

Parse LiveQuery: client never received updates from the server

Open hslorenzo opened this issue 10 years ago • 11 comments

I'm using a locally hosted [email protected] I have been scratching my head for days now and never found a solution (yet). When I update, insert, or delete a related parse object, the client never received any errors or messages from the server.

Environment Setup

Here is how the server was setup:

var api = new ParseServer({
    databaseURI: databaseUri,
    cloud: process.env.CLOUD_CODE_MAIN,
    appId: process.env.APP_ID,
    masterKey: process.env.MASTER_KEY,
    serverURL: 'http://localhost:' + port + '/parse',
 liveQuery: {
        classNames: ['MyTestClass', 'GameScore'] // List of classes to support for query subscriptions
    }

var httpServer = require('http').createServer(app);
httpServer.listen(port, function() {
    console.log('my-parse-server-example running on port ' + port + '.++');
});

// This will enable the Live Query real-time server
ParseServer.createLiveQueryServer(httpServer);

And, this is how the client was setup:

var Parse = require('parse');
Parse.initialize("MyAppId", "myJavascriptId"); // I tried adding the masterkey but didn't work 

Parse.serverURL = 'http://localhost:1337/parse';

let query = new Parse.Query('GameScore');
query.equalTo("playerName", "John Doe");  //I tried to comment this out but didn't work
let subscription = query.subscribe();

subscription.on('open', () => {
    console.log('subscription opened'); // <<---- THIS WORKS!!!!
});

subscription.on('update', (player) => {
    console.log(player.get('playerName')); // <<---- NEVER TRIGGERED :(
});

subscription.on('insert', (player) => {
    console.log(player.get('playerName')); // <<---- NEVER TRIGGERED :(
});

The connection works fine because the client receives the 'open' subscription event when ever the query.subscribe() is executed.

Is this a bug or i just missed something?

hslorenzo avatar Apr 12 '16 18:04 hslorenzo

Hi @hslorenzo , could you paste your parse-server log?

wangmengyan95 avatar Apr 12 '16 18:04 wangmengyan95

Hi @wangmengyan95, here is the content of the log:

{"level":"verbose","message":"Support key pairs Map {\n  'javascriptKey' => 'REDACTED' }","timestamp":"2016-04-13T01:45:53.598Z"}
{"op":"connect","applicationId":"REDACTED","javascriptKey":"REDACTED","level":"verbose","message":"Request: %j","timestamp":"2016-04-13T01:46:01.075Z"}
{"level":"verbose","message":"Push Response : \"{\\\"op\\\":\\\"connected\\\",\\\"clientId\\\":0}\"","timestamp":"2016-04-13T01:46:01.083Z"}
{"op":"subscribe","requestId":1,"query":{"className":"GameScore","where":{}},"level":"verbose","message":"Request: %j","timestamp":"2016-04-13T01:46:01.095Z"}
{"level":"verbose","message":"Push Response : \"{\\\"op\\\":\\\"subscribed\\\",\\\"clientId\\\":0,\\\"requestId\\\":1}\"","timestamp":"2016-04-13T01:46:01.163Z"}
{"level":"verbose","message":"Create client 0 new subscription: 1","timestamp":"2016-04-13T01:46:01.163Z"}
{"level":"verbose","message":"Current client number: 1","timestamp":"2016-04-13T01:46:01.163Z"}

hslorenzo avatar Apr 13 '16 01:04 hslorenzo

Since I can't find a solution, I was thinking of using target push notification in AfterSave in my cloud code as a temporary alternative to LiveQuery. Is there any huge drawback in using this kind of solution?

hslorenzo avatar Apr 14 '16 17:04 hslorenzo

+1

moawiaali avatar Apr 15 '16 02:04 moawiaali

It worked for me after upgrading to 2.2.7

moawiaali avatar Apr 16 '16 04:04 moawiaali

Finally it works!!!! Thank you :)

hslorenzo avatar Apr 18 '16 19:04 hslorenzo

Client never received updates from the server. @hslorenzo How to resolve this issue? I use "parse-server": "~2.2.18". Thanks.

hsz1992 avatar Aug 30 '16 09:08 hsz1992

Add this code should works...

liveQuery: {
    classNames: ["Message"] // List of classes to support for query subscriptions
}

hsz1992 avatar Aug 30 '16 09:08 hsz1992

@hslorenzo in your code snippet, I notice that you have 'app' as the argument for createServer(). Should that be api for the Parse Server, which is an Express app or did you create another express app in your server.js?

danawhite avatar Oct 06 '16 21:10 danawhite

@hslorenzo hey how did you get it to work? Having the same issue

willyyang avatar Nov 23 '16 16:11 willyyang

@hslorenzo hey how did you get it to work? Having the same issue

wahengchang avatar Feb 19 '20 05:02 wahengchang