Getting Started
Install via
npm install git+https://github.com/jacobp100/node-gcm-ccs.git
Use via
var GCM = ;var gcm = ;
Getting an API Key
- Go to
https://console.developers.google.com
, create a project and open it - Navigate to
overview
, and you'll see your<project id>
at the top - Go to
APIs & auth -> APIs
, addGoogle Cloud Messaging for Android
- Go to
APIs & auth -> credentials
, and create a new public<api key>
Functions
Send Message
Use send
to send a message.
gcm;
Argument | Details |
---|---|
to | A single user |
data | Data to be sent to the client |
options (optional) | See Message Paremeters from https://developer.android.com/google/gcm/server.html#send-msg. If delivery_receipt_requested = true , an event will be sent when the message is received by the target. |
callback (optional) | function(error, messageId, to) called back individually for each target. |
End Connection
gcm.end;
Events
Events are defined as below.
gcm
Example
var GCM = ;var gcm = ; gcm; gcm; gcm
Echo Client
gcm;
Notes on GCM
- No events are emitted from GCM or this library when a device new registers: you'll have to send a message from the device and process it yourself
- This library doesn't have functions to create user notifications (https://developer.android.com/google/gcm/notifications.html). However, if you implement this yourself, you'll be able to send to a user group by paassing the
notification_key_name
as adevice_id
forgcm.send
. - Occasionally, GCM performs load balancing, so the connection is sometimes restarted. This library handles this transparently, and your messages will be queued in these situations.