All Projects → Nickersoft → Push Fcm Plugin

Nickersoft / Push Fcm Plugin

Official Firebase Cloud Messaging plugin for Push.js v1.0 🔥

Programming Languages

javascript
184084 projects - #8 most used programming language
js
455 projects

Projects that are alternatives of or similar to Push Fcm Plugin

React Native Fcm
react native module for firebase cloud messaging and local notification
Stars: ✭ 1,729 (+4572.97%)
Mutual labels:  firebase, notifications, fcm
MongoosePush
MongoosePush is a simple Elixir RESTful service allowing to send push notification via FCM and/or APNS.
Stars: ✭ 101 (+172.97%)
Mutual labels:  notifications, fcm, push
Pushraven
A simple Java library to interface with Firebase Cloud Messaging (FCM) API. Pushraven allows you to push notifications to clients in very few lines of code.
Stars: ✭ 67 (+81.08%)
Mutual labels:  firebase, push, fcm
Easynotifylibproject
Send firebase notifications to your users very easily: A new Android Lib
Stars: ✭ 31 (-16.22%)
Mutual labels:  notifications, push, fcm
Laravel Fcm
Firebase Cloud Messaging (FCM) sender for Laravel
Stars: ✭ 129 (+248.65%)
Mutual labels:  firebase, notifications, fcm
andpush
Android Push Notification in Ruby: The fastest client for FCM (Firebase Cloud Messaging)
Stars: ✭ 83 (+124.32%)
Mutual labels:  notifications, fcm, push
Apprise
Apprise - Push Notifications that work with just about every platform!
Stars: ✭ 4,307 (+11540.54%)
Mutual labels:  framework, notifications
Anahita
Anahita is a platform and framework for developing open science and knowledge sharing applications on a social networking foundation.
Stars: ✭ 369 (+897.3%)
Mutual labels:  framework, notifications
Awesome Firebase
🔥 List of Firebase talks, tools, examples & articles! Translations in 🇬🇧 🇷🇺 Contributions welcome!
Stars: ✭ 448 (+1110.81%)
Mutual labels:  firebase, fcm
Socket.io Push
整合了小米,华为,友盟,谷歌,苹果推送的统一解决方案
Stars: ✭ 605 (+1535.14%)
Mutual labels:  notifications, push
Airnotifier
Push Notifications Server for Human Beings.
Stars: ✭ 522 (+1310.81%)
Mutual labels:  notifications, fcm
Applozic Android Sdk
Android Real Time Chat & Messaging SDK
Stars: ✭ 611 (+1551.35%)
Mutual labels:  notifications, fcm
Firebasepushnotificationplugin
Firebase Push Notification Plugin for Xamarin iOS and Android
Stars: ✭ 307 (+729.73%)
Mutual labels:  firebase, plugin
Juce
JUCE is an open-source cross-platform C++ application framework for desktop and mobile applications, including VST, VST3, AU, AUv3, RTAS and AAX audio plug-ins.
Stars: ✭ 3,841 (+10281.08%)
Mutual labels:  framework, plugin
React Native Notifee
⚛️ A feature rich notifications library for React Native Android & iOS, built by @invertase, the authors of @react-native-firebase.
Stars: ✭ 381 (+929.73%)
Mutual labels:  notifications, fcm
pusherman
queuing system for push notifications
Stars: ✭ 17 (-54.05%)
Mutual labels:  notifications, push
Cp Ddd Framework
A lightweight flexible development framework for complex business architecture with full ecosystem!轻量级业务中台开发框架,中台架构的顶层设计和完整解决方案!
Stars: ✭ 566 (+1429.73%)
Mutual labels:  framework, plugin
Espionage
An android application that can be run in background and give commands from fcm console to share sensor data
Stars: ✭ 18 (-51.35%)
Mutual labels:  firebase, fcm
Angularfire
The official Angular library for Firebase.
Stars: ✭ 7,029 (+18897.3%)
Mutual labels:  firebase, notifications
Intellij jahia plugin
Jahia's definitions.cnd files syntax highlighting, code completion, and other amazing stuff
Stars: ✭ 19 (-48.65%)
Mutual labels:  framework, plugin

Push.js FCM Plugin

What is FCM?

FCM, otherwise known as Firebase Cloud Messaging, is a free feature of the Google Firebase Platform, a collection of services for building scalable, effective web services. FCM allows web servers to send direct messages to a group of subscribers using ServiceWorkers. This means that by using this plugin, Push.js can now send targeted push notifications to a user's desktop without your website being open! Finally! 🎉🎉🎉

Though, keep in mind this is the first plugin for Push.js, ever. Expect a few bumps and potholes.

Installing

Just like Push itself, this module is easily installable via NPM or Bower:

$ npm install push-fcm-plugin --save
$ bower install push-fcm-plugin --save 

How to Use

Configuring

With Push.js, managing FCM on your site becomes incredibly easy. To begin, you need to configure FCM Push's SafeConfig: Head on over to your Firebase console and add a new project. Once the project is created, click on it and then click "Add Firebase to your web app". Select the configuration map from the generated code in the popup window and add it to your JavaScript file. Then, add the map to Push's FCM configuration using the config() method. Your finally code should look something like this:

var config = {
    apiKey: "<YOUR_API_KEY>",
    authDomain: "<YOUR_AUTH_DOMAIN>",
    databaseURL: "<YOUR_DATABASE_URL>",
    projectId: "<YOUR_PROJECT_ID>",
    storageBucket: "<YOUR_STORAGE_BUCKET>",
    messagingSenderId: "<YOUR_MESSAGE_SENDER_ID>"
};

Push.config({
    FCM: config
});

Lastly, add a manifest.json file to the root of your web server with the following contents:

{
    "//": "Some browsers will use this to enable push notifications.",
    "//": "It is the same for all projects, this is not your project's sender ID",
    "gcm_sender_id": "103953800507"
}

then import it into your HTML:

<link rel="manifest" href="/manifest.json">

This sender ID is required in order to tell Firebase your website allows messages to be pushed to it. Do not change the above ID. It is the same for all Firebase projects, regardless of who you are or what you've built.

Using with AMD or CommonJS

If you use AMD or CommonJS to load Push, you'll have to manually install the plugin.

For AMD:

define(['push', 'pushjs-fcm'], function (Push, PushFCM) {
    Push.extend(PushFCM);
});

For CommonJS:

const Push = require('pushjs');
const PushFCM = require('pushjs-fcm');

Push.extend(PushFCM);

Initializing

To initialize FCM, just call:

Push.FCM();

And that's it! You can then use the returned promise to run additional functions:

Push.FCM().then(function(FCM) {
    FCM.getToken().then(function(token) {
        console.log("Initialized with token " + token);
    }).catch(function(tokenError) {
       throw tokenError; 
    });
}).catch(function(initError) {
   throw initError; 
});

The available functions are as follows:

Function Description Returns
getToken() generates a new Instance ID token or retrieves the current one if it already exists Promise(token, error)
deleteToken() deletes the current token Promise(deletedToken, error)
isTokenSentToServer() denotes whether the current token has been sent to the server via sendTokenToServer() (see "Additional Options") Boolean

Additional Options

The FCM SafeConfig has a few additional options you can pass to it:

  • serviceWorkerLocation: Specifies directory containing the firebase-messaging-sw ServiceWorker script. May need to change if Push has been installed via NPM or Bower. The default is ./.
  • onTokenFetched(token): Called when a new Instance ID token is retrieved
  • onTokenFetchedError(error): Called if an error occurs while retrieving a new Instance ID token
  • onPermissionRequired() Called when permission is required to retrieve an Instance ID
  • onPermissionGranted(): Called when said permission is granted
  • onPermissionDenied(): Called when said permission is denied
  • onMessage(payload): Called when a new message is received
  • sendTokenToServer(token): Function that sends the given token to your server for future use
  • onTokenDeleted(deletedToken): Called when the current token is deleted
  • onTokenDeletedError(error): Called if an error occurs while deleting the current token

Sending Server-side Notifications

To send a notification to a given Instance ID from your server, simply make a POST request to https://fcm.googleapis.com/fcm/send with the following data:

Header

Authorization: key=<YOUR_SERVER_KEY>
Content-Type: application/json

Body

{ 
  "notification": {
    "title": "Notification Title",
    "body": "Notification Body",
    "click_action" : "http://example.com"
  },
  "to" : "<INSTANCE_ID_TOKEN>"
}

You can find your server key by going to your project console on Firebase, clicking the gear icon on the right sidebar, selecting "Project Settings" and going to the "Cloud Messaging" tab. For more information on messaging types, read Google's documentation on the topic.

Writing Your Own Plugin

Documentation on writing plugins will be coming the official Push.js docs soon!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].