0

i have seen many tutorials how to setup LiveQuery (most of them were prepared for back4app servers) However i found some tutorials made for self hosted servers and there was something like "index.js" which I believe is in this app "app.js". I've put like this code inside of var api = new ParseServer({...

liveQuery: {
    classNames: ["Test"] //List of classes to support for query subscritions
},

and after that I put this:

var app = express();
app.use('/', api);
let httpServer = require('http').createServer(app);
httpServer.listen(1337);
var parseLiveQueryServer = ParseServer.createLiveQueryServer(httpServer);

Still doesn't work and I'm not even sure how this url liveQueryUrl: keyLiveQueryUrl looks like.

According to flutter doc's https://pub.dev/packages/parse_server_sdk_flutter i need this to use Live Query.

It's hosted on http so as I know it's:

ws://myIP:port/appname/ <---Like this?

For example in this parser there's index.js with pre setup live query https://github.com/parse-community/parse-server-example/blob/master/index.js I've tried to copy some code to my app.js in many variation but couldn't handle it.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • It would be good if you could share the complete code that you are using to run the server, the code that you are using to connect and the error you have. By default, the address for the live query server will be the same of your parse server, but with ws instead of http or wss instead of https. – Davi Macêdo Aug 25 '21 at 14:08
  • Code is too long, i will send [code here](https://pastebin.com/UEy2XFGf) – Adrian Zalewski Aug 25 '21 at 14:17
  • Some logs from today: `{"code":"EADDRINUSE","errno":"EADDRINUSE","syscall":"listen","address":"::","port":1337,"level":"error","timestamp":"2021-08-26T08:28:48.288Z"}` – Adrian Zalewski Aug 26 '21 at 13:33
  • The code looks good. Have you tried to initialize the sdk in the way I suggested to you? – Davi Macêdo Aug 27 '21 at 17:39
  • @DaviMacêdo My parser is "http", so You mean I need to initialize this like ws://IP:PORT/appname yes? but i set this port 1337 manually I'm not sure if this going to work on it. – Adrian Zalewski Aug 28 '21 at 08:52
  • Yes. Your live query should respond at ws://myIP:1337/appname/ – Davi Macêdo Aug 30 '21 at 22:47
  • @DaviMacêdo I get that error: `I/flutter (19877): LiveQuery: : Error: SocketException: OS Error: No route to host, errno = 113, address = IP HERE, port = 42866 I/flutter (19877): ╭-- Parse Response I/flutter (19877): Class: LiveQuery I/flutter (19877): Function: ParseApiRQ.liveQuery I/flutter (19877): Status Code: -1 I/flutter (19877): Type: UnknownError I/flutter (19877): Exception: SocketException: OS Error: No route to host, errno = 113, address = IP HERE, port = 42866 I/flutter (19877): ╰--` Depending on my connection (wifi/mobile internet) port is changing. – Adrian Zalewski Aug 31 '21 at 07:03

1 Answers1

0

So i finally find out the problem. The problem was this port 1337 that i wanted to use was blocked by default. I checked list of free ports, change it to the other port and now I'm connected:

I/flutter (20494): LiveQuery: : Listen: {"op":"connected","clientId":"1437a932-c260-45b8-a567-417127f68efd"}
I/flutter (20494): ReSubScription:{}
I/flutter (20494): LiveQueryReconnectingController: LiveQueryClientEvent.CONNECTED
I/flutter (20494): LiveQuery: : SubscribeMessage: {op: subscribe, requestId: 1, query: {className: Test, where: {intNumber: 1}}}
I/flutter (20494): LiveQuery: : Listen: {"op":"subscribed","clientId":"1437a932-c260-45b8-a567-417127f68efd","requestId":1}
Shaido
  • 27,497
  • 23
  • 70
  • 73