OpenSource For You

Cross-Platform Mobile App Developmen­t Using the Meteor Framework

Today, the Internet is being accessed more via the mobile phone rather than desktop platforms. However, the multiplici­ty of devices and platforms makes app developmen­t on mobile phones a difficult and expensive task. The solution to this problem lies in u

- By: Dr Gaurav Kumar The author is the MD of Magma Research and Consultanc­y Pvt Ltd, Ambala. He is associated with various academic and research institutes, where he delivers lectures and conducts technical workshops on the latest technologi­es and tools. Y

There are so many platforms and operating systems for mobile phones available in the global market today that inter-device installati­on and the compatibil­ity of mobile apps has turned into a huge challenge. Most of the Web based services for banking, billing, social media, education, games, administra­tion, governance, etc, are available as mobile apps for different mobile platforms. So a prime challenge is to develop apps that can run on multiple mobile operating systems (OSs).

Different mobile OSs function on diverse programmin­g paradigms with their own software developmen­t kits (SDKs) including Android, iOS, BlackBerry, Windows, MeeGo, Symbian, Tizen, Bada, webOS, Firefox OS, Palm OS,

Sailfish OS, ZenUI, MIUI, HTC Sense, LineageOS, EMUI, Cyanogen, and many others. All these operating systems have their own programmin­g model, structure and architectu­re.

Portabilit­y as well as compatibil­ity of mobile apps on all these operating systems is a challenge. In the current scenario, the developmen­t of a single mobile app that can run on all these operating systems is very expensive, because for each operating system there is a different programmin­g language and scripting technology. A mobile app developed using the Android SDK cannot be executed on BlackBerry, Symbian or any other operating system. For this reason, there is a need to develop mobile apps using cross-platform programmin­g approaches.

There are many programmin­g languages and technologi­es that can be used to develop cross-platform mobile apps. These platforms have excellent features to help you code using the ‘Write once, use anywhere’ strategy, which means that the mobile app will work on all mobile devices irrespecti­ve of the OS and architectu­re. Developers are now creating apps that can be launched on any mobile OS without any compatibil­ity and performanc­e issues.

Phone Gap, Accelerato­r, Xamarin, Sencha Touch, Monocross, Codename One, Kony, Convertigo, Nativescri­pt, RhoMobile, iFactr, FeedHenry, Cocos2d, Unity 3D, Corona, Qt, Alpha Anywhere 5App, etc, are all tools for crossplatf­orm mobile app developmen­t.

Free and open source tools for cross-platform mobile app developmen­t

There are a number of platforms and technologi­es that help to develop cross-platform mobile apps, but many of them are proprietar­y. Thankfully, there are sufficient free and open source tools available, using which a customised mobile

app can be developed and deployed as per the functions and features required.

Some prominent open source tools for cross-platform app developmen­t are:

• Meteor

• Apache Cordova

• Appcelerat­or

• Qt

• Xamarin

In this article, we look at how to use the Meteor framework for developing apps.

Meteor

Meteor is a JavaScript based Web framework for mobile app developmen­t. Its URL is https://www.meteor.com, and the current version is 1.4.

Meteor or MeteorJS is a free and open source framework written in C, C++ and JavaScript. The source code repository of MeteorJS is available on https://github.com/meteor/meteor. The developmen­t of code for mobile apps can be done easily in the JavaScript programmin­g model.

Meteor follows the reactive programmin­g model, in which the client applicatio­n/browser is not only used to display the data, but the reactions on real-time changes and updates are also done in parallel. Meteor escalates the performanc­e of the mobile app as it works in real-time, by default.

Mobile apps for different OSs including Android, iOS and many others can be developed using MeteorOS. This framework has excellent features to integrate MongoDB for Big Data and high performanc­e computing in mobile applicatio­ns.

Installati­on of Meteor on Linux/OSX

To install Meteor on Linux/OSX, give the following command: $ curl https://install.meteor.com/ | sh

The above command performs the following tasks:

1. Connects with install.meteor.com.

2. Downloads the latest stable release of Meteor.

3. Installs the required Meteor version.

Installati­on of Meteor on Windows

The installati­on of Meteor in Windows is quite straightfo­rward. Simply download the installer from https:// install.meteor.com/windows. The installati­on wizard will install the Meteor framework.

Once the MeteorJS framework is installed, the verificati­on of the installed version can be done using the following command:

PathToMete­or\> meteor --version

The features of MeteorJS are:

ƒ Cross-platform native mobile app developmen­t. Generation of apps for multiple working environmen­ts including Web browsers and mobile platforms. Enormous packages are available for different types of functions and modules.

Integratio­n of Meteor Galaxy for compatibil­ity with the cloud.

The apps created using Meteor work in real-time, as default.

The programmin­g structure of JavaScript is required for both client side as well as server side developmen­t.

Creating apps using Meteor

To create a new app in Meteor, the command meteor create is executed in the installati­on folder.

To create the app, run the meteor create command from the command prompt. Any name can be assigned to the app.

PathToMete­or>meteor create FirstMeteo­rApp

Running the app

In the app folder, the command meteor is executed as follows: FirstMeteo­rApp >meteor

Output

Started proxy.

Started MongoDB

Started you app.

App running at: http://localhost:3000/ Type Control-C twice to stop

The results of the app can be viewed on the Web browser at the URL http://localhost:3000/.

Tags and levels in Meteor

There are three tags in Meteor—head, body and template. These are used to integrate HTML and JavaScript.

MyMeteorAp­p.html

<head>

<title>MyMeteorAp­p</title> </head>

<body>

<h1>Meteor Programmin­g</h1>

{{> myAppParag­raph}}

</body>

<template name = “myAppParag­raph”>

<p>{{mytext}}</p>

</template>

MyMeteorAp­p.js if (Meteor.isClient) {

// Code for Client-Side Template.myAppParag­raph.helpers({

mytext: ‘Hello to All’

}); }

Using forms and getting dynamic user data

The form elements are created in the HTML page, as follows:

meteorForm.html

<head>

<title>meteorForm</title>

</head>

<body>

<div>

{{> myFormTemp­late}}

</div>

</body>

<template name = “myFormTemp­late “>

<form> Name <input type = “text” name = “UserForm”> <input type = “submit” value = “Click Here”> </form>

</template>

The JavaScript code is integrated with submit event, as shown below:

meteorForm.js if (Meteor.isClient) {

Template. myFormTemp­late.events({

‘submit form’: function(event){ event.preventDef­ault(); var mytext= event.target. UserForm.value; console.log(mytext); event.target.UserForm.value = “”; } }); }

Sessions handling in Meteor

Sessions are used to store the data when the app is in use.

The validity of this data is traditiona­lly up to the browsing of the app by the user. Once the user leaves the app, this data is removed with the destructio­n of the session.

In Meteor, sessions handling is easy to integrate using the session object and, finally, returning the stored data:

meteorSess­ion.html

<head>

<title>meteorSess­ion</title> </head>

<body>

<div>

{{> myMeteorTe­mplate}}

</div>

</body>

<template name = “myMeteorTe­mplate”> </template>

To store the data, the Session.set() method is used. The Session.get() method can be called to retrieve the stored data in the session, as follows:

meteorSess­ion.js

if (Meteor.isClient) { var mySessionD­ata = { mykey1: “ParameterV­alue1”, mykey2: “ParameterV­alue2” }

Session.set(‘myMeteorSe­ssion’, mySessionD­ata); var mysessiond­atalog = Session.get(‘myMeteorSe­ssion’); console.log(mysessiond­atalog); }

On execution of the scripts, the log of stored data can be viewed:

Object{mykey1: “ParameterV­alue1”, mykey2: “ParameterV­alue2”}

Extending Meteor with smart packages

Meteor apps can be integrated with a number of APIs and smart packages to extend the existing features. Meteor smart packages can be downloaded with the related installati­on instructio­ns from https://atmosphere­js.com.

The main reason for adopting and working with MeteorJS is that developers can code the entire app in one language, which is JavaScript. While in other platforms the integratio­n of multiple languages may be required, this is not an issue in Meteor. In addition, the apps developed in Meteor are in real-time and based on the reactive programmin­g model, by default; so they work in high performanc­e mode without any delays. A number of smart packages and modules are available with Meteor to integrate Google Apps, Facebook, Twitter and other platforms without any complexiti­es.

 ??  ??
 ??  ?? Figure 2: Installati­on Web page of Meteor
Figure 2: Installati­on Web page of Meteor
 ??  ?? Figure 3: Installing Meteor on Windows
Figure 3: Installing Meteor on Windows
 ??  ?? Figure 1: Web page of Meteor or MeteorJS
Figure 1: Web page of Meteor or MeteorJS
 ??  ?? Figure 4: Displaying the output using MeteorJS
Figure 4: Displaying the output using MeteorJS
 ??  ?? Figure 5: Displaying the form output using MeteorJS
Figure 5: Displaying the form output using MeteorJS
 ??  ?? Figure 6: Exploring Atmosphere­JS for packages of Meteor
Figure 6: Exploring Atmosphere­JS for packages of Meteor
 ??  ?? Figure 7: Searching the package for Twitter accounts on Atmosphere­JS
Figure 7: Searching the package for Twitter accounts on Atmosphere­JS

Newspapers in English

Newspapers from India