Cordova Build Status Donate

Simple common api for coding with Cordova / Phonegap. The functions fallback if Cordova is not loaded, degrading to browser functionality.

This package consists of multiple features:

  • Running Meteor in Cordova on a device
  • Allow appcache to work
  • Fallback url if meteor cant load - when using appcache this would be the case until appcache is initialized (working on a fallback model on the runtime branch)
  • Allowing Meteor to interact with Cordova and plugins

Getting started

  1. Use the cordova CLI to install the plugin in the project
$ cordova plugin add
  1. Use meteorite to add the package to the meteor app
mrt add cordova

Add some boilerplate checkout www/index.example.html inspiration. When the device is ready MeteorCordova can be used, the plugin is loaded by Cordova so no need for script tags.

  <iframe id="meteor" src=""></iframe>

  <script type="text/javascript">

    shellVersion = '0.1.4';

    meteor = new MeteorCordova('meteor');

    // meteor.initPush({ senderID: 'xGoogleKeyx' });



Have a look at the plugin/index.html file for more a basic boilerplate

The Meteor client API


  cordova = new Cordova();

adding options:

  cordova = new Cordova({
    plugins: {
      notification: true // More docs below in the native section

Call device scope javascript

To call functions or read variables on the device we have a simple function call Call takes three parametres: command, [arguments], returningCallback The returning callback is optional

Examples: Read a variable'foo', [], function(value) {
    console.log('We got value = ' + value);

Call a function with no returning callback'console.log', ['Hello world']);

Call with callbacks in the parametres

  function onSuccess(heading) {
      alert('Heading: ' + heading.magneticHeading);

  function onError(error) {
      alert('CompassError: ' + error.code);

  cordova.addEventListener('deviceready', function() {'navigator.compass.getCurrentHeading', [onSuccess, onError]);

Call with callbacks in parametres and a returning callback

  function onSuccess(heading) {
      var element = document.getElementById('heading');
      element.innerHTML = 'Heading: ' + heading.magneticHeading;

  function onError(compassError) {
      alert('Compass error: ' + compassError.code);

  var options = {
      frequency: 3000
  }; // Update every 3 seconds'navigator.compass.watchHeading', [onSuccess, onError, options], function(watchID) {
    console.log('We've got a watch id: ' + watchID);

Add event listeners

To add an event listener it follows the cordova api closely

cordova.addEventListener('deviceready', function() {
  // Got a ready device

Device ready

cordova.isReady is reactive and holds the state of the device

  Template.hello.deviceready = function() {
    return cordova.isReady();

Adding a template helper

Notification API

This api works in browsers and on devices - It's also ment as an example howto extend the Meteor Cordova api for supporting more plugins.

Native support:

For native support install the package

$ cordova plugin add
$ cordova plugin add

Tell meteor's cordova to use native notifications when device is ready.

Activate the native notification:

cordova = new Cordova({
  plugins: {
    notification: true, // If we have both native plugins installed
    // vibration: true, // only the vibration plugin
    // dialogs: true, // only the dialogs plugin


cordova.alert(message, alertCallback, [title], [buttonName])

    cordova.alert("Hello", function() {
        // Alert is closed
    }, 'Greeting', 'Ok')


cordova.confirm(message, confirmCallback, title, buttonLabels)`


cordova.prompt(message, promptCallback, title, buttonLabels, defaultText)`




In a browser without cordova support it defaults to low vibrating sound in speakers. cordova.vibrate(milliseconds)

For more detailed info on the api I'll point to for now