Code Monkey home page Code Monkey logo

fcm-node's Introduction

fcm-node NPM version

A Node.JS simple interface to Google's Firebase Cloud Messaging (FCM). Supports both android and iOS, including topic messages, and parallel calls.

Installation

Via npm:

$ npm install fcm-node

Usage

var FCM = require('fcm-node');

var serverKey = '';
var fcm = new FCM(serverKey);

var message = { //this may vary according to the message type (single recipient, multicast, topic, et cetera)
    to: 'registration_token', 
    collapse_key: 'your_collapse_key',
    
    notification: {
        title: 'Title of your push notification', 
        body: 'Body of your push notification' 
    },
    
    data: {  //you can send only notification or only data(or include both)
        my_key: 'my value',
        my_another_key: 'my another value'
    }
};

fcm.send(message, function(err, response){
    if (err) {
        console.log("Something has gone wrong!");
    } else {
        console.log("Successfully sent with response: ", response);
    }
});

Notes

  • See FCM documentation for general details.
  • See Firebase Cloud Messaging HTTP Protocol for details about the HTTP syntax used and JSON fields, notification and data objects. (STRONGLY RECOMMENDED)
  • On iOS, set content_available when the app server needs to send a Send-to-Sync message. An inactive client app executes your logic in the background, while an app in the foreground passes the message to didReceiveRemoteNotification. (As seen in FCM Docs)
  • Some iOS users report a delay receiving the notifications and even a 'not receive at all' scenario if the priority field is not set. This is due to a delivery policy with APN (See APNs Provider API for a more detailed info)

Credits

Extended by Leonardo Pereira. Based on the great work on fcm-push by Rasmunandar Rustam cloned and modified from there, which in its turn, was cloned and modified from Changshin Lee's node-gcm

License

GNU LESSER GENERAL PUBLIC LICENSE v3

Changelog

1.0.14 - Added example file to quick tests
1.0.13 - Added a error response in case of TopicsMessageRateExceeded response
1.0.12 - Refactored the client removing the Event Emitter's Logic to fix concurrency issues. Using pure callbacks now also avoids memory leak in specific scenarios with lots of parallel calls to send function.
1.0.11 - <FIX> send function returning error objects when multicast messages (or individually targeted) returned both error and success keys on response message (even with error counter = 0 )
1.0.9 - Updated Documentation
1.0.8 - <FIX> 'icon' field no longer required in notification
1.0.7 - renaming repository
1.0.6 - bugfix: send function was always returning an error object for multicast messages (multiple registration ids)
1.0.5 - bugfix with UTF-8 enconding and chunk-encoded transfers
1.0.1 - forked from fcm-push and extended to accept topic messages without errors

fcm-node's People

Contributors

endast avatar jlcvp avatar nandarustam avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.