Configuring a mobile app to connect to user-hosted servers?

I’m developing a project with Meteor where users install their own server instances locally. How do I set up the mobile apps so they’ll ask for a server URL on startup instead of using some default?

Rocket.Chat did this with their mobile apps before they created native ones, but after digging through the code for a while I still haven’t been able to figure out how they did it.

Here’s a quick example of subscribing to a collection from another server (try it in the console from your app)

var connection = DDP.connect('https://www.meteor.com')
var partners = new Mongo.Collection('partners', {connection:connection})
connection.subscribe('partners')
setTimeout(()=>{
  console.log(partners.find().fetch())
},3000)

You can also use new AccountsClient({connection:connection}) docs to get accounts working with other servers.

2 Likes

Thanks, that should work for connecting to other servers. But doesn’t Meteor auto-connect to a default app server on startup? Would setting the server to, say, http://example.com cause a problem for the app? The app users will sometimes have no internet connection, only the local network.

There shouldn’t be any problem if Meteor fails to connect to the default server I think.

Btw, It’d be nice if you could change the default connection at runtime, It’s something I’ve wanted, but it seems pretty tricky :thinking:

1 Like