Skip to content

Commit

Permalink
Added READMEs and improved the packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Sashko Stubailo committed Sep 6, 2014
1 parent fb1a4ad commit ca8eed9
Show file tree
Hide file tree
Showing 15 changed files with 138 additions and 11 deletions.
41 changes: 34 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
Mobile Packages
===============

A repository for mobile-focused core packages and example apps of how to use them.
This repository contains three simple Meteor packages that work on mobile and desktop. There are also three small example apps that demonstrate their usage.

### Goals
## Packages

- Camera
- Device Orientation
- Geolocation
- reload-on-resume
- mobile-status-bar
### Camera

The package `mdg:camera` allows you to take photos on desktop and mobile with a single function call.

[Read the full Camera documentation here.](packages/mdg:camera/README.md)

### Geolocation

The package `mdg:geolocation` provides a reactive interface to the device's GPS location.

[Read the full Geolocation documentation here.](packages/mdg:geolocation/README.md)

### reload-on-resume

The package `mdg:reload-on-resume` delays hot code push on mobile devices until the user has closed and re-opened the app, so that their experience is not interrupted by a reload.

[Read the full reload-on-resume documentation here.](packages/mdg:geolocation/README.md)

## Example Apps

### simple-photo

This example app has one button that takes a photo and displays it on the screen. It demonstrates usage of the Camera package.

### simple-map

This example app uses the [Google Maps Static Maps API](https://developers.google.com/maps/documentation/staticmaps/) to show a map with a marker at your current location. It demonstrates usage of the Geolocation package.

### SoLoMo

This is the app that was first used to demonstrate Meteor Cordova functionality at the Meteor Devshop in August 2014. It uses the Camera, Geolocation, and reload-on-resume packages, in addition to local packages for [Ionic Framework CSS](http://ionicframework.com/) and a simple implementation of the [Google Maps Javascript API](https://developers.google.com/maps/documentation/javascript/).

<img src="examples/map-photos/screenshot.jpg" width="300" />
7 changes: 7 additions & 0 deletions examples/map-photos/.meteor/.id
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file contains a token that is unique to your project.
# Check it into your repository along with the rest of this directory.
# It can be used for purposes such as:
# - ensuring you don't accidentally deploy one app on top of another
# - providing package authors with aggregated statistics

282sea1kd5tvnp4qkqz
2 changes: 0 additions & 2 deletions examples/map-photos/.meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
standard-app-packages
autopublish
insecure
geolocation
camera
mrt:moment
iron-router
ionic
Expand Down
2 changes: 1 addition & 1 deletion examples/map-photos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Devshop Demo for Meteor Mobile: SoLoMo

> Making Social, Local, Mobile Easier than Ever Before!
<img src="cordova.jpg" width="300" />
<img src="screenshot.jpg" width="300" />

The developers at [Meteor](https://www.meteor.com/) have been hard at work building mobile support into the framework. Our goal is to make Meteor the easiest, fastest, and best way to build a great cross-platform application. This is an app we showed at Meteor Devshop August 2014 to demonstrate some of the features of the initial preview release of mobile support for Meteor.

Expand Down
1 change: 1 addition & 0 deletions examples/map-photos/packages/mdg:geolocation
File renamed without changes
1 change: 1 addition & 0 deletions examples/simple-photo/.meteor/cordova-platforms
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
android
22 changes: 22 additions & 0 deletions packages/mdg:camera/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Meteor Camera Package

Add it to your [Meteor](http://meteor.com) app with `meteor add mdg:camera`. The api is super simple - there is only one function to call:

### MeteorCamera.getPicture([options], callback)

Prompt the user to take a photo with their device and get the picture as a Data URI in JPEG format.

#### options

`options` is an optional argument that is an Object with the following possible keys:

- `width` An integer that specifies the minimum width of the returned photo.
- `height` An integer that specifies the minimum height of the returned photo.
- `quality` A number from 0 to 100 specifying the desired quality of JPEG encoding.

#### callback(error, data)

`callback` is a required argument that is a function that takes two arguments:

- `error` A [Meteor.Error](http://docs.meteor.com/#meteor_error) with a message dependent on the reason for failure and a platform-specific error message.
- `data` A base64-encoded data URI for the image taken by the camera. This parameter can be used directly in the 'src' attribute of an image tag.
2 changes: 2 additions & 0 deletions packages/mdg:camera/photo-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ Template.camera.events({
closeAndCallback(new Meteor.Error("permissionDenied", "Camera permissions were denied."));
} else if (browserNotSupportedError()) {
closeAndCallback(new Meteor.Error("browserNotSupported", "This browser isn't supported."));
} else if (error.get()) {
closeAndCallback(new Meteor.Error("unknownError", "There was an error while accessing the camera."));
} else {
closeAndCallback(new Meteor.Error("cancel", "Photo taking was cancelled."));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/mdg:camera/photo-cordova.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ MeteorCamera.getPicture = function (options, callback) {
};

var failure = function (error) {
callback(error);
callback(new Meteor.Error("cordovaError", error));
};

navigator.camera.getPicture(success, failure, {
Expand Down
19 changes: 19 additions & 0 deletions packages/mdg:geolocation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Meteor Geolocation Package

Add it to your [Meteor](http://meteor.com) app with `meteor add mdg:geolocation`.

## API Documentation

There are currently no options to set. Every method is reactive using [Tracker](http://docs.meteor.com/#tracker), and will automatically update with new location data from the device.

### Geolocation.error()

Returns the [position error](https://developer.mozilla.org/en-US/docs/Web/API/PositionError) that is currently preventing position updates.

### Geolocation.currentLocation()

Returns the [position](https://developer.mozilla.org/en-US/docs/Web/API/Position) that is reported by the device, or null if no position is available.

### Geolocation.latLng()

A simple shorthand for currentLocation() when all you need is the latitude and longitude. Returns an object that has `lat` and `lng` keys.
7 changes: 7 additions & 0 deletions packages/mdg:reload-on-resume/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Meteor reload-on-resume Package

Add it to your [Meteor](http://meteor.com) app with `meteor add mdg:reload-on-resume`. There is no API - this package changes the behavior of Meteor's hot code push feature on mobile devices only.

Normally, your app will update on the user's device as soon as you push a new version. This process is always smooth in a desktop web browser, but might momentarily interrupt the user's experience if they are on a mobile device.

With this package, the app will only update itself to the newest version if the user closes and re-opens the app (hence, it "reloads on resume").
4 changes: 4 additions & 0 deletions packages/mdg:reload-on-resume/browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Provide the same API on browser
Reload.isWaitingForResume = function () {
return false;
};
11 changes: 11 additions & 0 deletions packages/mdg:reload-on-resume/package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Package.describe({
name: "mdg:reload-on-resume",
summary: "On Cordova, only allow the app to reload when the app is resumed.",
version: '1.0.0'
});

Package.on_use(function (api) {
api.use(['reload', 'reactive-var'], 'web.cordova');
api.add_files("reload-on-resume.js", 'web.cordova');
api.add_files("browser.js", 'web.browser');
});
28 changes: 28 additions & 0 deletions packages/mdg:reload-on-resume/reload-on-resume.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var newVersionAvailable = new ReactiveVar(false);

var hasResumed = false;
document.addEventListener("resume", function () {
hasResumed = true;
}, false);

Reload._onMigrate(function (retry) {
if (! newVersionAvailable) {
newVersionAvailable.set(true);
}

if (hasResumed) {
return [true, {}];
} else {
document.addEventListener("resume", retry, false);
return [false];
}
});

/**
* @summary Reactive function that returns true when there is a new version of
* the app downloaded, can be used to prompt the user to close and reopen the
* app to get the new version.
*/
Reload.isWaitingForResume = function () {
return newVersionAvailable.get();
};

0 comments on commit ca8eed9

Please sign in to comment.