Giter Site home page Giter Site logo

onode / multigcm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pavlospt/multigcm

0.0 1.0 0.0 128 KB

Node.JS module to send GCM Push Notifications for both iOS & Android

Home Page: https://www.npmjs.com/package/multi-gcm

License: Apache License 2.0

JavaScript 100.00%

multigcm's Introduction

MultiGCM

Node.JS module to send GCM Push Notifications for both iOS & Android

#Installation

npm install -g multi-gcm (Latest available version 1.0.2)

#How To Use var gcm = require('multi-gcm'); var MultiGCM = new gcm.MultiGCM('AIza...');

var messageAndroid = new gcm.GCMMessage({
  registration_ids:['your_registration_ids'],
  type: 'device type', //Android or iOS
  data: {
    'Your own payload.'
  }
});

MultiGCM.send(messageAndroid,function(err,response){
    if(err){
        console.error(err);
    }else{
        console.log(response); //Containing the custom result object of this Library
        console.log(response.result); //Containing the JSON object response from GCM
    }
});

#Message Object - Properties registration_ids(array of Strings): Array containing the GCM Tokens to send the notifications.

type: The type of devices (iOS,Android). Needed to make checks on the notification payload properties. (Some properties are required when sending to Android using notification, so it needs to be checked before sending it.)

notification(object): Notification object payload.

data(object): Data object payload.

collapse_key(string): Collapse_key, if not applicable it will not get sent.

dry_run(boolean): Dry_run, if not applicable it will not get sent.

time_to_live(number): Time_to_live, if not applicable it will not get sent.

delay_while_idle(boolean): Delay_while_idle, if not applicable it will not get sent.

priority(number): Priority, if not applicable it will not get sent.

content_available(boolean): Content_available (iOS only). Used in APNS payload to wake the client app.

restricted_package_name(string): Restricted_package_name, if not applicable it will not get sent.

For more information on the properties of notification or the message, visit: GCM Connection Server Reference

#Notification Payload - Properties body(string): Notification body text.

sound(string): By default default is only supported.

title(string): Required when sending a notification to Android devices. (Throws error if not sent, before sending).

icon(string): Required when sending a notification to Android devices. (Throws error if not sent, before sending).On Android: sets value to myicon for drawable resource myicon.png.

#Result Object - Properties code(number): Response status code.

error(string): Human readable error message. If the request was successful it will be null.

result(object): The raw GCM response body.

multicastId(string): The multicast_id of the sent Push Notification.

numOfSuccesses(number): Number of successful deliveries.

numOfFailures(number): Number of failed deliveries.

numOfCanonicalIds(number): Number of canonical ids.

errors(array of objects): Custom error objects containing the error message and the error position from the GCM result. Will be null if there are no errors.

errorPositions(array of numbers): Array containing the error positions. Will be null if there are no errors.

deletablePositions(array of numbers): Array containing positions for deletable GCM tokens, if the error received is NotRegistered. Will be null if there are no errors.

canonicalIdsPositions(array of numbers): Array containing positions of Canonical Ids, if there are any. Will be null if there are no Canonical Ids.

canonicalIds(array of strings): Array containing the Canonical Ids, if there are any. Will be null if there are no Canonical Ids.

messageIds(array of strings): Array containing the Message Ids. Useful to check things with GCM Diagnostics in Play Store.

deletableTokens(array of strings): Array containing the GCM Tokens that you can delete from your server. These GCM Tokens are either derived from Canonical Ids or errors with NotRegistered message.

Credits

Author : Pavlos-Petros Tournaris ([email protected])

Google+ : +Pavlos-Petros Tournaris

Facebook : Pavlos-Petros Tournaris

LinkedIn : Pavlos-Petros Tournaris

(In case you use this in your app let me know to make a list of apps that use it! )

License

Copyright 2015 Pavlos-Petros Tournaris

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

multigcm's People

Contributors

pavlospt 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.