2.8.50 • Published 4 months ago

met-generate-int v2.8.50

Weekly downloads
-
License
ISC
Repository
github
Last release
4 months ago

npm.io

Arad Push Notification system (APN)

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

Before start (IMPORTANT)

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

— Firebase Configuration

  1. Create a Firebase project: Open 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...'

Installation

Always get the latest version with the following command:

npm install met-generate-int

Import

import APN from ‘met-generate-int’

How to use

After getting the firebaseConfig and vapidKey try to create an object of APN in your App.js (react) or App.vue (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
  });

Background Notification

The firebase-messaging-sw.js file is a service worker file used by Firebase Cloud Messaging (FCM) to handle the receiving and displaying of push notifications in the background, even when your web app is not currently open in the browser. Here’s how you can use it in your web projects: 1. Create the Service Worker File: Create a new file named firebase-messaging-sw.js in the public folder of your project. The public directory is the root of your server, and the service worker file must be located at the root level to have control over all the pages of your site. 2. Initialize Firebase in the Service Worker: In the firebase-messaging-sw.js file, you’ll need to initialize Firebase and the messaging service. Here’s a basic example:

// Import and configure Firebase
importScripts('https://www.gstatic.com/firebasejs/10.7.1/firebase-app-compat.js');
importScripts('https://www.gstatic.com/firebasejs/10.7.1/firebase-messaging-compat.js');

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",
};

// Retrieve an instance of Firebase Messaging
// so that it can handle background messages.
const messaging = firebase.messaging();

messaging.onBackgroundMessage((payload) => {
 self.registration.showNotification(notificationTitle,
   notificationOptions);
});

Methods in Arad

MethodInfo
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)

Methods in DeviceUtils

MethodInfo
getOs()returns OS name string
getBrowser()returns browser name string

Events

EventInfo
WakeUptrigger when a message received from firebase, here you should call apn.getMessage() apn.on('WakeUp', () => apn.getMessage())
MessageReceivetrigger when a message received from server, here you should handle and show message in your application apn.on('MessageReceive', (message) => handleNotification(message))
2.8.45

4 months ago

2.8.47

4 months ago

2.8.46

4 months ago

2.8.50

4 months ago

2.8.30

5 months ago

2.8.33

5 months ago

2.8.32

5 months ago

2.8.31

5 months ago

2.8.38

5 months ago

2.8.37

5 months ago

2.8.36

5 months ago

2.8.35

5 months ago

2.8.40

5 months ago

2.8.29

5 months ago

2.8.28

5 months ago

2.8.27

5 months ago

2.8.26

5 months ago

2.8.25

5 months ago

2.7.60

5 months ago

2.8.1

5 months ago

2.8.0

5 months ago

2.7.65

5 months ago

2.7.70

5 months ago

2.7.75

5 months ago

2.7.80

5 months ago

2.7.85

5 months ago

2.7.90

5 months ago

2.7.95

5 months ago

2.8.2

5 months ago

2.7.51

5 months ago

2.7.50

5 months ago

2.8.23

5 months ago

2.7.55

5 months ago

2.8.22

5 months ago

2.8.21

5 months ago

2.6.90

5 months ago

2.6.95

5 months ago

2.6.26

5 months ago

2.6.27

5 months ago

2.6.28

5 months ago

2.6.29

5 months ago

2.6.25

5 months ago

2.7.0

5 months ago

2.7.1

5 months ago

2.6.35

5 months ago

2.6.30

5 months ago

2.6.31

5 months ago

2.6.32

5 months ago

2.7.11

5 months ago

2.6.45

5 months ago

2.7.15

5 months ago

2.6.40

5 months ago

2.7.13

5 months ago

2.7.12

5 months ago

2.6.50

5 months ago

2.6.1

5 months ago

2.6.0

5 months ago

2.6.2

5 months ago

2.6.55

5 months ago

2.6.56

5 months ago

2.7.20

5 months ago

2.5.90

5 months ago

2.6.60

5 months ago

2.7.39

5 months ago

2.7.38

5 months ago

2.7.30

5 months ago

2.7.37

5 months ago

2.7.36

5 months ago

2.5.95

5 months ago

2.7.35

5 months ago

2.6.65

5 months ago

2.6.70

5 months ago

2.7.40

5 months ago

2.7.43

5 months ago

2.7.42

5 months ago

2.7.41

5 months ago

2.7.47

5 months ago

2.6.75

5 months ago

2.7.45

5 months ago

2.6.80

5 months ago

2.6.85

5 months ago

2.5.80

5 months ago

2.4.70

5 months ago

2.5.40

5 months ago

2.4.71

5 months ago

2.5.85

5 months ago

2.4.80

5 months ago

2.5.14

5 months ago

2.5.15

5 months ago

2.5.55

5 months ago

2.5.12

5 months ago

2.4.45

5 months ago

2.5.50

5 months ago

2.4.90

5 months ago

2.5.60

5 months ago

2.5.0

5 months ago

2.5.25

5 months ago

2.5.1

5 months ago

2.5.65

5 months ago

2.4.55

5 months ago

2.4.50

5 months ago

2.5.20

5 months ago

2.5.70

5 months ago

2.4.65

5 months ago

2.5.35

5 months ago

2.4.60

5 months ago

2.5.30

5 months ago

2.4.1

5 months ago

2.4.0

5 months ago

2.4.3

5 months ago

2.4.35

5 months ago

2.4.5

5 months ago

2.4.4

5 months ago

2.4.30

5 months ago

2.3.8

5 months ago

2.3.7

5 months ago

2.3.9

5 months ago

2.4.40

5 months ago

2.4.18

5 months ago

2.3.2

5 months ago

2.3.1

5 months ago

2.3.4

5 months ago

2.3.3

5 months ago

2.4.16

5 months ago

2.3.6

5 months ago

2.4.15

5 months ago

2.3.5

5 months ago

2.4.12

5 months ago

2.4.11

5 months ago

2.4.7

5 months ago

2.4.6

5 months ago

2.4.9

5 months ago

2.4.8

5 months ago

2.4.25

5 months ago

2.4.21

5 months ago

2.4.20

5 months ago

2.3.0

5 months ago

2.2.7

5 months ago

2.2.6

5 months ago

2.2.1

5 months ago

2.1.2

5 months ago

2.2.0

5 months ago

2.2.3

5 months ago

2.1.4

5 months ago

2.2.2

5 months ago

2.1.3

5 months ago

2.2.5

5 months ago

2.2.4

5 months ago

1.1.9

5 months ago

1.1.8

5 months ago

1.1.7

5 months ago

1.1.6

5 months ago

1.1.5

5 months ago

1.1.4

5 months ago

1.2.2

5 months ago

1.1.3

5 months ago

1.2.1

5 months ago

1.1.2

5 months ago

2.1.0

5 months ago

1.1.1

5 months ago

1.1.0

5 months ago

1.0.9

5 months ago

1.0.8

5 months ago

1.0.7

5 months ago

1.0.6

5 months ago

1.0.5

5 months ago

1.0.4

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago