Using cluster with Cordova

Anyone been able to get meteorhacks:cluster working with cordova?

Getting the following error on all pages that connect to external DDP server from client.

Uncaught Error: SyntaxError: JSON Parse error: Unrecognized token '<':32:http://localhost:12344/c761cccbc3e2455f4f6110c53664731d1b74f351.js

There’s an open issue on github, but it’s been open for months, so hoping someone might have a fix.

I’m not familiar with meteorhacks:cluster, but this error is the result of Meteor serving index.html when a file is not found. Although this would happen both on the regular server and with Cordova local file serving, I suspect the issue here is that meteorhacks:cluster attempts to connect to meteor.local where it should be connecting to the actual server.


Thanks, @martijnwalraven this will help figuring it out.

When I run DDP.connect and manually enter the URL, the connection seems to work, but when using Cluster.discoverConnection, it does not.

> var connection = DDP.connect('');
< undefined
> connection
< {onReconnect: null, _stream: Object, _lastSessionId: "7h3gtnyeSFnFFmBEF", _versionSuggestion: "1", _version: "1", …}
> connection.status()
< {status: "connected", connected: true, retryCount: 0}
> var connection2 = Cluster.discoverConnection('stores')
< undefined
[Log] Uncaught Error: SyntaxError: JSON Parse error: Unrecognized token '<':32:http://localhost:12344/c761cccbc3e2455f4f6110c53664731d1b74f351.js (console-via-logger.js, line 173)
[Error] SyntaxError: JSON Parse error: Unrecognized token '<'
> connection2
< {onReconnect: null, _stream: Object, _lastSessionId: null, _versionSuggestion: null, _version: null, …}
> connection2.status()
< {status: "connecting", connected: false, retryCount: 1}

Seems like Cluster.discoverConnection may be returning the wrong URL based on this, but with cordova, as the web version works perfectly fine.

@arunoda any ideas why that might happen?

Thanks @patrickleet, I had the same problem and your code in the pull request of meteorhacks:cluster fixed it.

Awesome, glad I could help. It’s been open for so many months that I forgot
about it!