• Stars
    star
    183
  • Rank 210,154 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 11 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PhoneGap/Cordova + Meteor integration approach "DOM hijacking", telling PhoneGap where to get content from, letting Meteor hijack your PhoneGap app's HTML/CSS/JS

DEPRECATION NOTICE

Meteor core now supports a better Meteor + Cordova integration approach.

This project was useful while that didn't exist, but Meteor's integration is great, use it.


MeteorRider

An approach for integrating PhoneGap/Cordova + Meteor.

Your Meteor web app (real time everything), inside a Cordova shell (native APIs) = awesome!

How it works

  • Cordova loads it's normal, compiled www/index.html
  • All normal, compiled Cordova JS loads (this ensures Cordova API versions are maintained, decoupled from Meteor)
  • MeteorRider
  • Step 1) loading
  • MeteorRider looks in localStorage to see if we have cached the last requested HTML
  • Step 2) requesting
  • MeteorRider does an AJAX request to your Meteor Server
  • MeteorRider replaces paths in the HTML response to be full URLs
  • (Step 3) replacing
  • MeteorRider replaces the DOM ("hijacking the DOM")
  • MeteorRider stores the HTML for next time's loading screen
  • The DOM loads all the Meteor JS/CSS
  • NOTE that all of Cordova's JS remains in the DOM (from before)
  • future-feature: planning on caching and inlining this
  • Meteor connects via DDP to the Meteor Server

overview

It's Easy

It might sound a bit complex, but really it's pretty simple.

This approach is good for the following reasons

  • The JS needed for whatever version of Cordova is always bundled with Cordova, updating is easy.
  • All Cordova API and Plugins' remain available, because the Cordova JS is loaded first, we just add to it.
  • Once setup you can mostly ignore Cordova and only update your Meteor app, all updates get to the client FAST (no app updating needed)
  • iframes are the devil!

If you want an alternative, without the extra AJAX request try out

  • Pack Meteor is a great way to compile all of what you need to run meteor (client) on Chrome Packaged Apps for Mobile (etc)
  • upside: super-fast, all Meteor assets live local in the Mobile App
  • upside: build script gets all Meteor JS & assets (well managed)
  • upside: chrome APIs available if you do Chrome Packaged Apps for Mobile
  • upside: decent "offline" support
  • downside: slightly more complicated release proccess
  • downside: you have to re-release the mobile application for every update to your Meteor App
  • downside: you have coordinate your entire user base's apps for releases if your app changes (since they have an old version installed)
  • Meteor Cordova Loader is another great alternative, basically a super-lazy-loader option
  • upside: faster initial load, no Cordova initial load screen
  • upside: load script gets all Cordova core & plugin JS from Meteor (well managed)
  • downside: you can basically never update versions of Cordova after release because client versions are unknown
  • downside: like above, you can never add or upgrade a plugin for the same reasons, the client "version" is lost
  • downside: no "offline" support (though, MeteorRider doesn't offer much for that either)

For more info, a comparison of approaches

Example Projects

  • https://github.com/zeroasterisk/MeteorRiderExample0 Cordova 3.5 Android (2 commits)
  • This is a very basic example, showing how easy it is to implement
  • You can edit the URL to the Meteor App and this will work as a totally functional shell for your app
  • You can add platforms like iOS in the normal Cordova way and be up and working on them in seconds
  • https://github.com/zeroasterisk/MeteorRiderExample-CrossWalk CrossWalk + Cordova 3.5 ~ Android (1 commit)
  • Did you know? CrossWalk is the project behind Chrome Packaged Apps for Mobile, taking Chromium to the mobile device (so you aren't stuck with old-ass-WebKit on Android)
  • this is definitely my recommendation for performance on Android
  • You can edit the URL to the Meteor App and this will work as a totally functional shell for your app
  • Only Android :(

Installation / Usage

NPM installer package under consideration see this npm package and this discussion

There are only a couple of files, and you can choose to manage them however you like...

Get the Code

cd tmp
git clone https://github.com/zeroasterisk/MeteorRider.git MeteorRider

On PhoneGap/Cordova - Setup

Option 1) Replace the whole index.html file

You do not have to replace the whole index.html file, but it's a reasonable "fast start".

  • www/js/meteor-rider.js is our tool for getting the Meteor HTML and taking over the DOM
  • www/js/phonegapapp.js is where you setup your application and initializer for MeteorRider
  • has a basic structure for handling events and firing up MeteorRider
  • has a stub for a test switcher, to bypass loading MeteorRider for testing on device only
  • you can override any of this
cd pathtoyourphonegap/assets/www/
cp index.html index_old.html
cp /tmp/MeteorRider/www/index.html index.html
cp /tmp/MeteorRider/www/js/meteor-rider.js js/

Then edit index.html with the appropriate config (see Configuration)

Option 2) Edit the index.html file

There is very little that is "required" to fire up MeteorRider.

This is the minimum you want in your index.html

    <script type="text/javascript" src="js/meteor-rider.js"></script>
    <script type="text/javascript">
      document.addEventListener('deviceready', function() {
          MeteorRider.init("http://leaderboard.meteor.com/");
      }, false);
    </script>

You just need to call MeteorRider.init() when the deviceready Event is triggered.

MeteorRider.config

Here is the default config

config: {
  meteorUrl: '',
  currentPath: '',
  localStorage: true,
  // step 1) loading text
  doLoading: true,
  // step 2) AJAX request
  doRequest: true,
  // step 3) AJAX response (or cache) replacing DOM
  doReplace: true
},

If this is global variable is found, it sets the default config in MeteorRider

var __MeteorRiderConfig__ = {
  meteorUrl:  "http://leaderboard.meteor.com/",
  currentPath: "/",
  localStorage: true
};

You can pass any part of the config into MeteorRider.init() like so:

MeteorRider.init({ meteorUrl: "http://leaderboard.meteor.com/", localStorage: false });

You can also just pass in a string, and it will be treated like the meteorUrl (simplest config)

MeteorRider.init("http://leaderboard.meteor.com/");

MeteorRider.config.meteorUrl (required)

Set the meteorUrl property, it should be the full URL to your meteor app.

NOTE: full public URLs work best. Localhost or internal IPs probably wont work. If Cordova can't load it, it won't work.


On Meteor

You do not have to put anything in Meteor, but if you copy in this startup.js file, it will handle hot code pushes and reload inside PhoneGap/Cordova, without losing the phonegap context.

cd pathtoyourmeteorapp
cp /tmp/MeteorRider/meteor/startup.js startup.js

Obviously, the best bet is to look for the the Cordova APIs directly

if (_.isObject(device)) {
  console.log(device.cordova);
}

You can also look for the MeteorRider JS object inside your Meteor app and use it as a means of basic knowledge about the client, and status.

You can also force the localStorage to be the "loading" screen on the next pageload... (it should be the full HTML you want rendered)

MeteorRider.meteorHtml = '<!DOCTYPE html><html><head>' +
  '<link rel="stylesheet" href="http://leaderboard.meteor.com/6a545450449411b537bd96111c640ce7d7a1092e.css">' +
  '<script type="text/javascript" src="http://leaderboard.meteor.com/9ebe61ab3cb3e1d4bcd16191207b9f1eb692d512.js"></script>' +
  '</head><body>' +
    'My Cool Loading Content Here :)' +
  '</body></html>';

MeteorRider.replaceStoreHtml();

Meteor Packages for PhoneGap/Cordova

There are probably many more than this list, let me know about `em.

OAuth for Meteor + MeteorRider + PhoneGap/Cordova

Sadly this should "just work" out-of-the-box, but as of now, it is frought with peril.

Luckily there is an excellent project alive which is a very easy mrt add phonegap-oauth away.

Check it out here meteor-phonegap-oauth


Common Problems / Tips

PhoneGap/Cordova Issues? Plugin Issues?

  1. Stop MeteorRider (comment it out, or setup testing conditional bypass)
  2. Run whatever you're doing with just index.html and "on device" JS (without Meteor)
  3. Working locally but not with MeteorRider? Enable MeteorRider again and look for a namespace collision...

Not Loading Meteor?

  1. Check the URL, can Cordova get to it?

  2. Try loading a static file from your Meteor URL (from the /public/ folder) as the meteorUrl.

  3. Check the console from Cordova (Android, iOS, etc)

    MeteorRider requesting MeteorRider url: http://example.com MeteorRider response.status = 404

You can uncomment the lines in MeteorRider where it logs the meteorHtml (the HTML content from Meteor).

PhoneGap/Cordova needs to be setup to allow access to Meteor

In older PhoneGap installs or if you've restrictred <access>, may have to allow access to the Meteor app url/domain. Refer to the configuration documentation for your version of PhoneGap.

http://docs.phonegap.com/en/edge/guide_appdev_security_index.md.html#Security%20Guide

<access origin="*" />

In the Wild

Roadmap / Goals

The main goal is to provide a simple, fast, and standardized way to connect PhoneGap to Meteor.

The combination is very powerful, and I have high hope for the future.

Goals:

  • PhoneGap version agnostic (done)
  • Meteor version agnostic (mostly done)
  • Device agnostic (maybe done ? Android and iOS only ones experiemented with)
  • Minimal configuration / setup (done)
  • Package installer

Tasks:

  • invesigate loading just the HEAD data from the AJAX reques
  • invesigate loading the JS files (from Meteor) via AJAX so that we know when completed and could trigger callbacks
  • implement a warning/alerting system for device/connection state (PhoneGap version dependancies?)
  • we may provide a means of setting up an "offline" page

Authors / Acknowledgements

This is the "Option 3" approach I've been thinking about for a while.

Inspiration and collaboration from:

I'd like to thank all of them for communicating with me while figuring out what my options were and for collaboration on this project.

Background:

http://prezi.com/ig9gjm11mwsi/from-zero-to-mobile-web-app-in-sixty-minutes/

http://zeroasterisk.com/2013/08/22/meteor-phonegapcordova-roundup-fall-2013/

More Repositories

1

meteor-cordova-geolocation-background

Cordova enabled background geolocation, so your Meteor Cordova app can update location even when closed/suspended
JavaScript
61
star
2

react-iframe-resizer-super

inject HTML into an iframe, and/or resize an iframe to the height of it's contents
JavaScript
50
star
3

Meteor-Throttle

A simple serverside throttling (rate limiting) package for MeteorJS
JavaScript
38
star
4

meteor-cordova-geolocation-example

Example Geolocation (BG & FG)
JavaScript
32
star
5

Presenteract

MeteorJS Application to create and run interactive presentations
JavaScript
25
star
6

PhoneGap-BarcodeScanner-Example-iOS

Example iOS PhoneGap Application with a working BarcodeScanner Plugin
Objective-C
24
star
7

CakePHP-ElasticSearchIndex

CakePHP Plugin to facilitate full text indexing across any Model via ElasticSearch
PHP
22
star
8

php-mysql-master-slave-replication-monitor

MySQL Replication Monitor and Heal PHP script
PHP
17
star
9

CakePHP-Eip

Edit in Place Plugin (Helper/Component) for CakePHP (requires jquery)
JavaScript
14
star
10

react-form-simple-schema

DEPRECATED EXPERIMENT: React + Formsy + Meteor Simple Schema = form generation and validation for React
JavaScript
10
star
11

CakePHP-AdobeConnect-Plugin

AdobeConnect Plugin (API implemented as Models/Datasource) and some helpers
PHP
10
star
12

cakephp-behavior-rangeable

CakePHP Behavior for lat/lon Ranged Searches
PHP
10
star
13

npm-s-enum

Super Enums factory for config lists, etc, with helper functions, packaged for Meteor
JavaScript
9
star
14

jquery-autosaveform

jquery plugin to simplify autosaving a form: periodic, window.onbeforeunload, elements.onclick
JavaScript
8
star
15

react-confirm-button

Simple react-confirm button (internal state)
JavaScript
6
star
16

meteor-ghost-markdown-editor

Ghost Markdown Editor. See https://github.com/timsayshey/Ghost-Markdown-Editor.
JavaScript
6
star
17

elixir-101-codelab

A set of basic codelab files, to familiarize developers with Elixir
Elixir
5
star
18

meteor-cordova-geolocation-foreground

JavaScript
5
star
19

meteor-auditlog

Simple, generic, extensible audit logging on collection insert, update, upsert, remove
JavaScript
5
star
20

Presenteract-PhoneGap-ios

Objective-C
5
star
21

CakePHP-Litle-Plugin

CakePHP Plugin to interact with the Litle API
PHP
5
star
22

react-leaflet-polytools

react + leaflet + draw, customized toolset for polygon editing
CSS
4
star
23

CakePHP-cleanable-behaviour

Behaviour for standardizing and cleaning $this->data
PHP
4
star
24

MeteorRiderExample-CrossWalk

CrossWalk + Cordova 3.5 - Android Example
Java
4
star
25

meteor-travis-ci-nightwatch

An Example of Meteor + Travis-ci + Nightwatch
CSS
4
star
26

HouseParty-elixir-libcluster-swarm-demo

Demo libcluster and swarm functionality, deployable to k8 and auto-healing
Elixir
3
star
27

as-library-of-PHP-helper-functions

a helper library of PHP functions (some require cakephp)
3
star
28

Meteor-Throttle-Accounts

An extra layer to simplify throttling of Meteor Accounts
JavaScript
3
star
29

sonos-simple-cli

Control Sonos from CLI with pause|play and Alfred support
JavaScript
2
star
30

Meteor-Throttle-Example

Server side throttling for Meteor
HTML
2
star
31

react-uniforms-widgets

This repo is a library of individual React Uniforms UI components. (collaborate!)
JavaScript
2
star
32

ffmpeginstall-ubuntu

a script to install ffmpeg on ubuntu
Shell
2
star
33

CakePHP-cake_up-shell

A simple shell to help upgrade an old cake1.1 application to cake1.2/1.3 readiness
PHP
2
star
34

home

home and dot files
Vim Script
2
star
35

Meteor-ll-util

Meteor Package: Utilities for Latitude and Longitude
JavaScript
2
star
36

CakePHP-Unionizable

Behavior to manage SELECT UNION finds with CakePHP
PHP
2
star
37

CakePHP-ArrayToXml-Lib

CakePHP lib, static methods to convert an ArrayToXml
PHP
2
star
38

adventofcode2018

adventofcode.com for 2018 for alan
Elixir
2
star
39

CakePHP-DateRange

A Lib and Behavior to facilitate all manner of date-range conditions and calculation
PHP
2
star
40

meteor-flow-dynamics-animation

Simple transitions/animations for FlowRouter using DynamicsJS
JavaScript
2
star
41

RSC-CakePHP-Plugin

Rackspace Cloud Plugin (Cloud Files, Cloud DNS, etc...)
PHP
2
star
42

meteor-simple-schema-transform

Transform Meteor SimpleSchema objects into various other formats/functions
JavaScript
2
star
43

CakePHP-DbBackup

CakePHP Plugin to facilitate standardized database backups
PHP
2
star
44

filepicker-meteor-uploader

quick meteor app to upload to filepicker.io
JavaScript
2
star
45

Sticky-CakePHP-Plugin

Stickyable Behavior to maintain contain and joins for multiple finds
PHP
2
star
46

kyoss-topic-manager-prototype

JavaScript
1
star
47

decryptilito

Decryptilito is a little web-based copy of Decrypto.
TypeScript
1
star
48

phx_gcp_cluster

Elixir (clustered) on GCP via Kubernetes (basic Phoenix app)
Elixir
1
star
49

CakePHP-monitor-plugin

A plugin monitor suite, you can tie into your cakephp application, and export to monitoring services
PHP
1
star
50

CakePHP-Stats

CakePHP Stats Plugin (a basic metrics aggregator and reporter)
PHP
1
star
51

Input-CakePHP-Plugin

Input access, sanitization, security layer to simplify CakeRequest access
PHP
1
star
52

cordova-phonegap

Meteor package that provides support for mobile hardware support via Cordova Phonegap.
JavaScript
1
star
53

cdnmd5

CDN Assets + md5 hash as part of the filename = always unique URL. A CakePHP Plugin/Lib to facilitate (for JS, CSS, Images, etc)
PHP
1
star
54

kyoss-cakephp-unit-tests-example

an example of unit tests in cakephp
PHP
1
star
55

cakedemo-2011-02-09

Just the demo code, used at the KYOSS/Meetup at LVL1
PHP
1
star
56

CakePHP-GoogleCheckout-Plugin

Google Checkout Plugin for CakePHP 2.1
PHP
1
star
57

SublimeText-ExtraCakePHPSnippets

Extra CakePHP snippets for use with Sublime Text 2
1
star
58

faas-cold-start-auditor

Elixir
1
star
59

demo-agents

1
star