Skip to content

Commit

Permalink
added example file and updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jlcvp committed Aug 2, 2016
1 parent daa8f24 commit 1f1f77a
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 6 deletions.
8 changes: 4 additions & 4 deletions README.md
@@ -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 ## Installation


Via [npm][1]: Via [npm][1]:
Expand Down Expand Up @@ -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 [10]: https://firebase.google.com/docs/cloud-messaging/http-server-ref


## Changelog ## 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.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.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 /> 1.0.9 - Updated Documentation <br />
Expand Down
84 changes: 84 additions & 0 deletions example.js
@@ -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();
5 changes: 3 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{ {
"name": "fcm-node", "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", "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", "main": "index.js",
"repository": { "repository": {
Expand Down Expand Up @@ -29,5 +29,6 @@
"homepage": "https://github.com/Saber-Tecnologias/fcm-node", "homepage": "https://github.com/Saber-Tecnologias/fcm-node",
"dependencies": { "dependencies": {
"retry": "^0.9.0" "retry": "^0.9.0"
} },
"tonicExampleFilename": "example.js"
} }

0 comments on commit 1f1f77a

Please sign in to comment.