Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cluster and cordova integration #27

Open
banglashi opened this issue Mar 13, 2015 · 22 comments
Open

cluster and cordova integration #27

banglashi opened this issue Mar 13, 2015 · 22 comments

Comments

@banglashi
Copy link

Hi @arunoda,
first of all, thanks for all the great work you are doing for the meteor community ;)

We are trying to build an app and would like to use the cluster package for service-discovery.

As soon as we run the app in the ios simulator or device we get following error:

Uncaught Error: SyntaxError: JSON Parse error: Unrecognized token '<':2087:http://meteor.local/packages/ddp.js?41b62dcceb3ce0de6ca79c6aed088cccde6a44d8

Basically the ddp call returns the raw html.

I have created a small demo project here https://github.com/banglashi/meteor-cordova-cluster to reproduce the issue. Just edit the CLUSTER_DISCOVERY_URL in the dev and mobile shell scripts.
Than lunch the ./dev script for the search service and the ./mobile script for the web service.

It could be possible that I am doing/setting something wrong. Could it be related to the endpoint being localhost?

Any hint or suggestions is really appreciated.

Best regards

@boustanihani
Copy link

It's good to know if cluster supports cordova in its current state 👍

@arunoda
Copy link
Member

arunoda commented Mar 13, 2015

@banglashi not sure what was the issue is. I am having hard time setting up the cordova dev stuff. Let me try again.

@banglashi
Copy link
Author

Hi @arunoda,
The DDP call is actually being made to this base_url: "http://meteor.local/search/sockjs"
Any idea why it's not using the correct endpoint url? Or is this correct like that?
I am trying to read into it and understand the internals, will let you know if I find something more.

@arunoda
Copy link
Member

arunoda commented Mar 18, 2015

Thanks.
I'm not much familiar with this modulus.
May be we can get some help from slava.

On Wed, Mar 18, 2015 at 8:15 PM banglashi [email protected] wrote:

Hi @arunoda https://github.com/arunoda,
The DDP call is actually being made to this base_url: "
http://meteor.local/search/sockjs"
Any idea why it's not using the correct endpoint url? Or is this correct
like that?
I am trying to read into it and understand the internals, will let you
know if I find something more.


Reply to this email directly or view it on GitHub
#27 (comment).

@fishdude
Copy link

Hey @arunoda,

Thanks for all your terrific work!

Was anyone able to figure out a solution to this? When attempting to run on both iOS simulator or device the ddp call is returning raw html as mentioned by @banglashi. Hence the following error being thrown:

Uncaught Error: SyntaxError: JSON Parse error: Unrecognized token '<':2087:http://meteor.local/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706

Any point in the right direction would be awesome, would love to get cluster working in my cordova app. Thanks.

@1nsaneinc
Copy link

I'm getting a similar error on iOS Meteor-Cordova app running on iPhone 5, although this has nothing to do with Cluster.

Uncaught Error: SyntaxError: JSON Parse error: Unrecognized token '<':9:http://meteor.local/5a2b00d42a6ce9eb45c5c48f54778073184a8104.js

Not sure how to debug this, any pointers please?

@patrickleet
Copy link

Also getting this error - no solutions yet?

@patrickleet
Copy link

Or workarounds @1nsaneinc @fishdude @arunoda ?

@patrickleet
Copy link

Started a discussion here:
https://forums.meteor.com/t/using-cluster-with-cordova/10678

@patrickleet
Copy link

Through discussions on the forum, looks like this is caused by connecting to an invalid URL, leading me to believe that Cluster.discoverConnection is returning an invalid endpoint when on cordova.

Manually using DDP.Connect works, but isn't as scalable.

@patrickleet
Copy link

I tried initializing the connection with DDP.connect a few ways, and they all work.

  1. using root_url
  2. using ip address from cluster discovery db
  3. using balancer url from cluster discovery db

Either the lookup is failing, or the lookup is returning the wrong URL, and then failing when trying to connect with an invalid url.

@MasterJames
Copy link

Can you debug with weinre (Web inspector remote) or log it or just display the url in a text component etc. and hopefully test it from there too?

@patrickleet
Copy link

Ok, so here's a little more info, looks like all Cluster.discoverConnection does from a client is call DDP.connect with a '/' prepended to the name of the service passed in. https://github.com/meteorhacks/cluster/blob/master/lib/client/api.js#L2

I'm looking at Meteor's code now to see how that's handled. I don't really understand how that should work on web and not cordova. As is, I'm not even sure why would DDP.connect('/stores') would know that '/stores' is on a different server.

https://github.com/meteor/meteor/blob/devel/packages/ddp-client/livedata_connection.js#L52

@patrickleet
Copy link

Looks like the endpoint ("/" + serviceName) eventually ends up here: https://github.com/meteor/meteor/blob/devel/packages/ddp-client/stream_client_nodejs.js#L12

According the comments above the contstructor, supported endpoints are

// @param endpoint {String} URL to Meteor app
//   "http://subdomain.meteor.com/" or "/" or
//   "ddp+sockjs://foo-**.meteor.com/sockjs"

So the way that cluster is connecting is still a bit of a mystery to me. How does '/stores' even translate to connecting to a different server when on web?

If I could pick an endpoint on the client, and use the fully qualified url that would probably solve the problem, but I couldn't find a way to pick an endpoint on the client, only on the server.

@patrickleet
Copy link

@arunoda why does client only use DDP.connect, while the server uses ConnectionWatcher?

package.js suggests it could be used for both?
https://github.com/meteorhacks/cluster/blob/master/package.js#L46

@arunoda
Copy link
Member

arunoda commented Oct 4, 2015

Okay, this is how /service is working (or suppose to work).

This happens in the initial /sockjs/info call. See:

It will get the service and send a sockjs base_url which is appended to the actual sockjs WS connection. So, we can redirect sockjs traffic into some other service.

Seems like, it's having some issues in cordova.

@arunoda
Copy link
Member

arunoda commented Oct 4, 2015

It seems like cordova directly use the Websocket endpoint bypassing sockjs. In order to cluster to work properly it needs sockjs.

I am not familiar with cordova code. So, need to dig more.

@patrickleet
Copy link

@arunoda I don't see how it would ever get there from the client..
looks like all that happens is DDP.connect:
https://github.com/meteorhacks/cluster/blob/master/lib/client/api.js#L2

My pull request modifies ConnectionWatcher to work on the client as well. The only place it failed was getting the endpoint, so on the client I just have it call to the server to get the endpoint. Is there something wrong with that approach that will cause problems down the line?

@Micjoyce
Copy link

Micjoyce commented Mar 1, 2016

@arunoda @patrickleet
I have encountered this problem , it was solved?

@Micjoyce
Copy link

Micjoyce commented Mar 1, 2016

Very much hope that someone can give me some answers on this issue。

@patrickleet
Copy link

@Micjoyce yes, worked for me, and a few others on the forums have used the code from this PR to solve their issues as well. I have a app in production using this.

More here: https://forums.meteor.com/t/using-cluster-with-cordova/10678/3

@Micjoyce
Copy link

Micjoyce commented Mar 2, 2016

@patrickleet
I did a test according to your method of app, but will still appear this question:
Uncaught Error: SyntaxError: JSON Parse Error: Unrecognized token '<' : 2104: http://meteor.local/packages/ddp-client.js?250 b63e6c919c5383a0511ee4efbf42bb70a650f

this is my test app : https://github.com/Micjoyce/meteor-cluster-accounts-example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants