Parse LiveQuery: client never received updates from the server
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.
- [x] I've met the prerequisites.
- [x] I'm running the latest version of Parse Server.
- [x] I've searched through existing issues.
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?
Hi @hslorenzo , could you paste your parse-server log?
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"}
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?
+1
It worked for me after upgrading to 2.2.7
Finally it works!!!! Thank you :)
Client never received updates from the server. @hslorenzo How to resolve this issue? I use "parse-server": "~2.2.18". Thanks.
Add this code should works...
liveQuery: {
classNames: ["Message"] // List of classes to support for query subscriptions
}
@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?
@hslorenzo hey how did you get it to work? Having the same issue
@hslorenzo hey how did you get it to work? Having the same issue