Categories
DEVELOPMENT

How To Enable Push Notification Using Meteor JS

Over the past few months, we have been busy developing our own revolutionary product. My team and I decided to go with Meteor on this one as the intention is to develop a multi-platform application with real-time updates being a key factor. Along with Meteor, we chose to go with React JS for the template with Meteor for reactivity of data. Working on Meteor has been a great experience so far but every now and then we did hit a roadblock as there is very limited documentation on some of the functionalities – Push Notification being once such case. We had to spend a lot of working hours to decipher the problem and get it to work properly.

So, on this blog titled ‘How to enable push notification using Meteor JS, I’ll share a few important details as to how you can get the push notification to work using the Meteor JS platform. Let’s begin!

The first step towards implementing the push notification feature on Meteor JS is to obtain the Project Number and API Key from the firebase portal.

Use the following steps to get the required details:

1. Access the Firebase Developer Console.

2. Click on ‘create project’ and give it a suitable project name.

3. Once that is done, you’ll be able to see the Firebase Overview page. Now click on the ‘Project Setting’ link found on the top left (part of the hover settings).

4. Now click on ‘Cloud Messaging’ tab.

5. Write down your Sender ID (it should be all digits) and your Server key (has upper and lower case letters, numbers, underscores, and dashes).

How To Enable Push Notification Using MeteorJS

Now Let’s Get Into The Coding Part

We have used “raix/push” for the push notification feature. The first step obviously is to install it. The installation process is as follows:

meteor add raix:push

meteor add cordova:cordova-plugin-device@1.1.5

meteor add cordova:phonegap-plugin-push@1.5.2

Now add Push.Configure as part of the client inside the Meteor Startup () block of main.js

Push.Configure({
   android: {
     senderID: xxxxxxxxxx,
     alert: true,
     badge: true,
     sound: true,
     vibrate: true,
     clearNotifications: true
     // icon: '',
     // iconColor: ''
  },
  ios: {
  alert: true,
  badge: true,
  sound: true
  }
});

How To Enable Push Notification Using MeteorJS

Additionally, you’ll have to include the mobile-config.js as well:

    App.configurePlugin('phonegap-plugin-push', {
        SENDER_ID: xxxxxxxxxxxxx
    });

How To Enable Push Notification Using MeteorJS

Once this part is done, add Push.Configure to the server inside Meteor.startup() block of main.js

Push.Configure({
        gcm: {
        projectNumber: xxxxxxxxxxx,
        apiKey: 'xxxxxxxxxxx'
        }
    });

How To Enable Push Notification Using MeteorJS

Now Try Sending The Push Notification:

The following code has to be included for the push notification to work efficiently:

Push.send({
        from: 'push',
        title: 'Push Notification',
        text: 'Push Notification text',
        badge: 1, //optional, use it to set badge count of the receiver when the app is in background.
        query: {
        // Ex. send to a specific user if using accounts:
            userId: 'xxxxxxxxx'
        } // Query the appCollection
        // token: appId or token eg. "{ apn: token }"
        // tokens: array of appId's or tokens
        // payload: user data
        // delayUntil: Date
    });

We have completed the coding part and now we can test the push notification. The push notification feature will only work on mobile devices, so connect your Android phone (to get push notifications to work on ios refer this link) and input the following command in the terminal:

Meteor run Android-device

That’s it, your push notification feature should start working. Feel free to get in touch with me on Twitter if you run into any difficulties. Do share your thoughts in the comments section as well. Happy Coding!!

 

Categories
DEVELOPMENT

HTML5 Canvas Tag – A Must-Know For Developers

Canvas tags are an integral part of HTML5 coding. Canvas allows the user to draw different raster-based images like geometric 2D figures, load images & media and even provides the option to bring in animations.

However, to make the maximum use of a Canvas tags, one must have expertise in coding, using JavaScript. Here’s how you can draw using canvas:

Use the
<canvas></canvas>
tag to create an element. By default, the canvas will have 300 pixels in width and 150 pixels in height. You could change this by modifying the tag and specifying your requirements. For example,
<canvas height=”100″width=”200″></canvas>

To create a border using Canvas, one could make use of CSS. The below example can be used as a reference:

<style>
canvas { border:1px solid #333; }
</style>

Canvas

In order to make this work using JavaScript, the user must create an ID. Once that is done, you’ll be able to keep it as a reference.

<canvas height=”100″width=”200″id=”demoCanvas”></canvas>

Inserting the canvas ID into a variable:

<script type=”text/javascript”>
var canvasID = document.getElementById(“demoCanvas”);
</script>

Changing the Canvas to 2D or 3D:
Use the
var canvas = canvas.getContext(“2d”);
to create a canvas according to your need. Once you get a reference to your Canvas, insert a concept, and you are ready to being drawing.

How can you achieve a few basic shapes using Canvas?
Refer to the tags below to create a few basic shapes:
Draw a Line:

var c = document.getElementById(“lineCanvas”);
var ctx = c.getContext(“2d”);
ctx.moveTo (0,0);
ctx.lineTo (100,100);
ctx.stroke ();

Canvas

Text with Stroke:

var c = document.getElementById(“strokeCanvas”);
var ctx = c.getContext(“2d”);
ctx.font “25px arial”;
ctx.strokeText (“Canvas”,10,30);

Canvas

Loading images:

var myImage = new Image();
myImage .src = “logo.jpg”;
myImage .onload function() { context.drawImage(myImage, 30, 15, 130, 110); }

Canvas

A Canvas element could also be used to draw gradients and shadows to scale, rotate and transform the shapes created. One may be curious as to what is so special about Canvas in the age of ActionScript and Flash technology?

Here are a few good reasons for using Canvas:

  • One of the most important reasons is that Canvas, as part of the HTML5 platform is totally free. Users don’t have to spend money on expensive software like ‘Adobe Flash’ to start coding. Canvas provides a great opportunity for developers to learn new things as it is visible in the core source of a site developed using HTML5.
  • Using Canvas, the user could simply start coding and watch the result being displayed in the browser. There is no requirement for any plug-in to be installed first like the Adobe Flash Player.
  • Today’s technology enables a browser to transfer graphic intensive tasks to a GPU for immediate processing instead of overworking the CPU. This gives the user great performance gains while using Canvas.

Advantages of using Canvas:

The advantages of using Canvas elements are manifold. Some of the important ones include the ability for elements to work on any HTML5 web browser. Being part of the HTML5 platform, it is easy to create bitmap graphics and vectors on screen. Canvas has the ability to render images and it doesn’t require parsing of JavaScript. Canvas is text based and can be read by all search engines, thereby creating an impact on SEO as well. Canvas provides cross-platform functionality as it works on both Android and iOS devices as well.

Disadvantages of using Canvas:

The disadvantages of using Canvas is that it is no longer supported by versions prior to IE9. If the JavaScript option is disabled in the browser, then the Canvas will draw-up a blank. Also, there is no option to click individual items; only the entire element can be chosen.

Conclusion:

Canvas is one of the most sought after features in HTML5. In sync with JavaScript, Canvas elements provide a huge variety of shapes and forms. It is a very powerful tool, especially for young developers as it is an open source platform and there is no investment required. It has the ability to turbocharge boring forms to rich, gorgeous animations.

Categories
DEVELOPMENT

How to Become a Full Stack Developer

A few days ago, I got an interesting phone call from my friend. He asked a question – “Has PHP
lost its importance in today’s programming world? – I was taken aback and asked him as to why he is thinking about this all of a sudden. The answer to that came in the form of a graph, as shown below:

55



Our conversation lasted for at least an hour. We spoke about the current trends in the industry and how he could upgrade his skill set to that of a professional developer. This blog is basically intended to share my thoughts as to how a PHP developer can make inroads into the programming world and stay ahead of the competition.

I advised him to spend a minimum of two hours, outside of working hours and on a daily basis, to learn and understand the latest developments in the field. Personally, I think it’s best to take time early in the morning to get this habit going. Worried about your jogging routine? Well, you can always find time for that after work.

For starters, let’s look at two main talking points in the industry to further your growth – The NODE JS and NPM.

Node JS and NPM

According to Wikipedia, and I quote, “Node.js is an open-source, cross-platform JavaScript runtime environment for developing a diverse variety of tools and applications. Although Node.js is not a JavaScript framework, many of its basic modules are written in JavaScript, and developers can write new modules in JavaScript.The runtime environment interprets JavaScript using Google’s V8 JavaScript engine.”

Clearly, node is a tool to write java scripts on the server side and NPM (Node Package Manager) is the package manager for node, more like a composer in the PHP domain. I am listing below a few of the advantages in the nodejs platform:

  • Asynchronous – (More fast)
  • Javascript(Same language on server and client side)
  • Tools (great tools like NPM, Mongo DB, Sails JS , Meteor JS )

It is advisable to familiarize yourself, in detail, the advantages of using nodejs by doing a quick Google search. Most PHP developers are familiar with frameworks like Codeignitor, Laravel, Cake php and ZF to name a few. Similarly the nodejs platform has a few frameworks to work with. They are:

Express.js is a very simple and easy to use a framework, but personally I prefer sails.js as it functions in a similar manner to like Codeignitor and Laravel. I would not like to comment on koa.js as I am not familiar with the framework, but is something that I’ll look into soon.

Database 

Even if you have a good understanding of the MySql platform, one needs to understand that the database concept has undergone a sea change in its operational capacity to accommodate high volume file structures. Earlier, majority of the database generated were based on the sql concept, but there are other contenders like Mongo DB, Couch DB and Hadoop. I strongly suggest that you let go of your sql comfort zone and star learning new database handlers right away. Don’t forget, MySql can still be used for small-medium scale projects and can be made to work in tandem with Mongo DB.

ES2015 (know as ES6)

Another concept to know more about is that of ES2015. It is the latest version of javascript. Note that you may face issues with browser compatibility while using the tool. ES2015 is so flexible that you can use Babel or TypeScript in sync as transpires. To know more, I suggest going through the link below:

Resource-: https://www.codeschool.com/courses/es2015-the-shape-of-javascript-to-come

Front End Frame Works

One can find a lot of front end frameworks, but the point is that all cannot be learned in a jiffy. However, I would like to point out a few options which I think, going forward, would be the trend in the industry.

React JS

Reactjs is a front end library developed by Facebook. It follows an awesome component method for front end development. I believe that React has a great future and it’s very easy to learn. I can assure you that if you familiarize well with React, then you can easily adopt React Native for Hybrid Application development while the aframe-react can be used for development of virtual reality applications. Know more by clicking the links below:

Resource 1-: https://www.codeschool.com/courses/powering-up-with-react

Resource 2-: http://www.webduratech.com/blog/reactjs-tutorial-for-beginners/

Angular 2

Angular is currently the buzz word in the industry. If you have not had a chance to learn Angular 1, then I suggest moving straight to Angular 2 as it utilizes the same operational components. It is one of the most comprehensive and full-fledged MV* frameworks currently available and is developed by Google.

Even though Angular and React are the key trends in the industry, it would be wise to invest your time in learning Emberjs and Vuejs as well.

Miscellaneous

The options to learn are basically endless. That’s why it would be an injustice if I fail to Mention, and also request you all, to look into Gulp, Grunt and Yomen front ends tools to make the leap towards being a full stack developer.

Hybrid App Development

Hybrid App Development holds the key to the future and it is imperative that you learn it right now. There are three major tools to develop Hybrid Applications – Iconic, Meteor Js and React Native. More information on the three can be found by accessing the links below:

I also suggest going through a blog that I had written a few months back on the importance of Hybrid App Development – http://www.webduratech.com/blog/what-are-hybrid-apps-how-it-can-be-helpful-for-small-business-owners/

66



Virtual Reality Apps

Virtual Reality is fast gaining momentum as one of the most important concepts in the programming world. Microsoft and Facebook have already introduced their VR products for the masses. As it is a new concept, efficient learning of associated tools in the VR domain will go a long way in making you a top notch developed with awesome pay.

More on VR can be found here – https://github.com/ngokevin/aframe-react

There is no end to learning, especially for us programmers. We have to stay constantly updated with all the latest trends in the industry to further our chances of making a difference in the field.

How to become a full Stack Developer - Virtual Reality in Google Trends



Keep an open mind and embrace the changes in the industry. Always keep in mind that self-learning is the only way to ensure that you do not get lost amongst the crowd.

Follow me at https://twitter.com/shemeermali for all the latest from the world of programming. Happy Coding Everyone!

 

 

 

 

 

 

 

 

Categories
DEVELOPMENT

React JS Tutorial for Beginners

Last weekend, I was trying to find the boilerplate repo for ReactJS SPA (Single Page Application) to figure out the best folder structure that can be adopted for React js projects. I could not find anything on the folder structure, but was able to find two starter/boilerplate repos. I decided to learn more about the two starter/boilerplate repos in order to make a sample folder structure by myself, to be used in ReactJS projects.

1) create-react-app –
The create-react-app is developed/configured by Facebook as part of the Facebook incubator.  This tool will help you to create React apps without the need for any build configuration.

2) generator-react-webpack –
The “generator-react-webpack” is a yomen generator for ReactJS applications and can be used to quickly set up a project along with the karma test runner and the Webpack module system.

 

I have installed  the create-react-app in my local system –  it has a very simple installation procedure and doesn’t require any configuration. I suggest going through the “README.md” file to know more about the installation procedure to create-react-app.

 

I have created another repo to implement sma-react-boilerplate. You should make sure that the repo is cloned to see the related files as shown in the image below. I have not worked on developing a CSS to make the page more attractive as this tutorial is just a basic demonstration of the tool.

 

React js tutorial for beginners



The “public” folder contains index.html and .favicon files, and they should not be messed with. The folder that requires our utmost attention is “src” – more commonly known as ‘a developer’s playground.’ This folder contains an index.js file, which is one of the core elements of the application. This file is used to write the router characteristics of the application. The root(“/”) router here is pointed to Home components for the user to see the ‘Home Page’ when attempting a call.

 

React js tutorial - react js app tutorial



Inside the “src” folder, I have created separate files for each page like Home.js, About.js, Contact.js, etc. Each file contains a “components” folder. This folder is used to keep the components of each page. You can refer the Contact.js file and the Contact folder for more clarity. Each folder may have different components and can be saved in different files.



React js tutorial - contact-js-react-app



Finally, we have three more folders –  “Common”, “layout” and “Forms” – within the “components” folder. The “Common” folder is used for generic components while the “Layout” folder is used to save files related to the Header and the Footer. The “Form” folder can be accessed for elements like Textbox, Textarea, etc. These folders can be considered as common components depending on the scenario.

 

I hope that you have got a general idea about developing a sample application and the folder structure associated with it. These simple concepts can be used in developing small and large scale applications, but keep in mind that the heavy applications require a more modular folder structure. You can reach out to me at https://twitter.com/shemeermali for any queries that you may have on the subject.

 

Happy Reactive Coding