I’m working on a project in React Native and want to connect to a Meteor server using a headless Meteor client (Meteor on the client without Blaze). I am well aware of Asteroid, which is fine, but I’d like to leverage Meteor itself, perhaps as a package. Something like:
myMeteor = require(‘meteor-app’)
// Someone indicate http://myawesomeapp.com as the location of my Meteor app
AwesomeCollection = myMeteor.AwesomeCollection
AwesomeCollection.insert({})
…
foo = myMeteor.Meteor.call(…)
…
AwesomeCollection might be a GroundDB collection or Collection2/SimpleSchema etc.
Any advise steering me in the right direction would be much appreciated. My initial thoughts are to use something like Demeteorize yet not totally clear on the details.
I’m thinking that since Meteor packages itself into the client browser or Cordova, it should be that difficult for it to be simply decoupled and included as anyone might wish, in this case, within React Native; yet broadly speaking anywhere Javascript runs.
Hey Riaan53, of course. Actually Asteroid is even better than DDP and full Meteor would be even better than that. You are aware of Asteroid? https://github.com/mondora/asteroid
My question is broader, the ability to package a Meteor project into an NPM package lets would theoretically let it be used fully within any JS front-end framework and give it far greater exposure.
Great question actually it got me thinking about how I wanted it all just headless. Meteor.Tracker, Meteor.subscribe, all the collections, blaze independent packages, etc.
I came across a great article by Ronen Babayoff on running Meteor on the command line, without Blaze. I’m still working this out and any suggestions by you or anyone appreciated.
Another quick way to get meteor integrated with ReactNative or Titanium is to build an empty meteor app which will generate the necessary clientside js file. Create an npm package with the generated clientside js file. You will need to export the right properties from the clientside js file to be accessible in your ReactNative/Titanium app.
Hey @emmanuelbuah, that is a great suggestion and what I was thinking as well; yet how do we pass in the location of the Meteor server / Mongo to the client script from within the context of require? These are normally environment variables. (process.env.FOO = ‘value’; // won’t work on the client)
I’ve read many people mention utilizing the client bundle of Meteor, yet no pattern for this online. So perhaps my question is really this:
How do I pass in the environment variables Meteor’s client expects from within the context of it being included via require?
Your point about having to repeat the process is true; i’d automate it. There is another consideration that I’ve learn about as well. That web-sockets need to be polyfilled on both React Native and Native Script.