Permalink
Browse files

added example file and updated documentation

  • Loading branch information...
jlcvp committed Aug 2, 2016
1 parent daa8f24 commit 1f1f77ac5fd0e5b1c1ac50c090e19a52cf1eefc8
Showing with 91 additions and 6 deletions.
  1. +4 −4 README.md
  2. +84 −0 example.js
  3. +3 −2 package.json
View
@@ -1,7 +1,6 @@
fcm-node
fcm-node [![NPM version](https://badge.fury.io/js/fcm-node.svg)](http://badge.fury.io/js/fcm-node)
========
A Node.JS simple interface to Google's Firebase Cloud Messaging (FCM). Supports both android and iOS, including topic messages
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][1]:
@@ -66,7 +65,8 @@ Based on the great work on [fcm-push][7] by [Rasmunandar Rustam][4] cloned and m
[10]: https://firebase.google.com/docs/cloud-messaging/http-server-ref
## Changelog
1.0.13 - Added a error response in case of TopicsMessageRateExceeded response <br/>
1.0.14 - Added example file to quick tests <br />
1.0.13 - Added a error response in case of TopicsMessageRateExceeded response <br />
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 <b>send</b> function. <br />
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 ) <br />
1.0.9 - Updated Documentation <br />
View
@@ -0,0 +1,84 @@
/**
* Created by Leonardo on 02/08/2016.
*/
FCM = require('fcm-node');
var SERVER_API_KEY='your_api_key';//put your api key here
var validDeviceRegistrationToken = 'c1m7I:A ... bjj4SK-'; //put a valid device token here
var fcmCli= new FCM(SERVER_API_KEY);
var payloadOK = {
to: validDeviceRegistrationToken,
data: { //some data object (optional)
url: 'news',
foo:'fooooooooooooo',
bar:'bar bar bar'
},
priority: 'high',
content_available: true,
notification: { //notification object
title: 'HELLO', body: 'World!', sound : "default", badge: "1"
}
};
var payloadError = {
to: "4564654654654654", //invalid registration token
data: {
url: "news"
},
priority: 'high',
content_available: true,
notification: { title: 'TEST HELLO', body: '123', sound : "default", badge: "1" }
};
var payloadMulticast = {
registration_ids:["4564654654654654",
'123123123',
validDeviceRegistrationToken, //valid token among invalid tokens to see the error and ok response
'123133213123123'],
data: {
url: "news"
},
priority: 'high',
content_available: true,
notification: { title: 'Hello', body: 'Multicast', sound : "default", badge: "1" }
};
var callbackLog = function (sender, err, res) {
console.log("\n__________________________________")
console.log("\t"+sender);
console.log("----------------------------------")
console.log("err="+err);
console.log("res="+res);
console.log("----------------------------------\n>>>");
};
function sendOK()
{
fcmCli.send(payloadOK,function(err,res){
callbackLog('sendOK',err,res);
});
}
function sendError() {
fcmCli.send(payloadError,function(err,res){
callbackLog('sendError',err,res);
});
}
function sendMulticast(){
fcmCli.send(payloadMulticast,function(err,res){
callbackLog('sendMulticast',err,res);
});
}
sendOK();
sendMulticast();
sendError();
View
@@ -1,6 +1,6 @@
{
"name": "fcm-node",
"version": "1.0.13",
"version": "1.0.14",
"description": "A Node.JS simple interface to Google's Firebase Cloud Messaging (FCM). Supports both android and iOS, including topic messages, and parallel calls",
"main": "index.js",
"repository": {
@@ -29,5 +29,6 @@
"homepage": "https://github.com/Saber-Tecnologias/fcm-node",
"dependencies": {
"retry": "^0.9.0"
}
},
"tonicExampleFilename": "example.js"
}

0 comments on commit 1f1f77a

Please sign in to comment.