JSPM

  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q81228F
  • License ISC

return a random int between two int numbers

Package Exports

  • met-generate-int
  • met-generate-int/dist/arad.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (met-generate-int) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Arad Push Notification system (APN)

You can use this sdk in node.js applications such as ReactJS, VueJS or AngularJS.

Installation

Always get the latest version with the following code npm install met-generate-int

Import

import APN from ‘met-generate-int’

Usage

BEFORE START

You need The firebase configuration object and vapidKey before initialize APN sdk.

Firebase Configuration

  1. Create a Firebase project: Go to the Firebase console and click on >“Add project”. Follow the instructions to create your project.
  2. Get your Firebase configuration: After your project is created, click on the gear icon next to “Project Overview” and select “Project settings”. Here, you’ll find your Firebase SDK snippet under the “General” tab. It will look something like this:
 const firebaseConfig = {
   apiKey: "AIzaSy...",
   authDomain: "your-project-id.firebaseapp.com",
   databaseURL: "https://your-project-id.firebaseio.com",
   projectId: "your-project-id",
   storageBucket: "your-project-id.appspot.com",
   messagingSenderId: "sender-id",
   appId: "app-id",
   measurementId: "G-measurement-id",
 };

VAPID Key

  1. Enable Cloud Messaging in your Firebase project: In the Firebase console, navigate to “Cloud Messaging” under the “Grow” section. Here, you can enable Firebase Cloud Messaging for your project.
  2. Get your VAPID key: After enabling Cloud Messaging, you’ll find your VAPID key under the “Cloud Messaging” settings. It will be labeled as “Web Push certificates”. It will look something like this: const vapidkey = 'BB0rUaCvQVl1NA9sENxz9y...'

After getting the firebase configurations try to create an object of APN in your App.js (in react) or App.vue (in vuejs) and start coding:

  const firebaseConfig = {
    apiKey: "AIzaSy...",
    authDomain: "your-project-id.firebaseapp.com",
    databaseURL: "https://your-project-id.firebaseio.com",
    projectId: "your-project-id",
    storageBucket: "your-project-id.appspot.com",
    messagingSenderId: "sender-id",
    appId: "app-id",
    measurementId: "G-measurement-id",
  };
  const vapidkey = 'BB0rUaCvQVl1NA9sENxz9y...';

  // create apn object from APN
  const apn = new APN();

  //  initialize apn ↓
  apn.init(firebaseConfig, vapidKey).then(() => {
    console.log('Initialize successful');
    apn.setKey('arad-secret-key');
    if (!apn.checkConfig()) {
      apn.setConfig('clientUserName', 'clientPassword', 'connectionURL');
    }
  }).catch((error) => {
    console.error('Error: ', error);
    // here you can handle retry to call apn.init()
  });

  // this will listen to notifications
  apn.on('message', (message) => {
    console.log('notification: ', message);
    // do something with notification data
  });

Methods

Method Info
init(firebaseConfig, vapidKey) initialize sdk width firebaseConfig (object) and vapidKey (string) promise
setKey(key) set a secretKey to ecnrypt configs void
checkConfig() check if configs defined and valid boolean
setConfig() set connection data void
getToken() return firebase token string (return null before initilize complete)
getOs() returns OS name string
getBrowser() returns browser name string

Events

Event Info
message trigger when a message received from server apn.on('message', (message) => handleNotification())