Skip to content
/ gcm Public

GCM (Google Cloud Messaging) - CCS (XMPP Cloud Connection Server) and HTTP implementation.

License

Notifications You must be signed in to change notification settings

soygul/gcm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GCM CCS (XMPP)

Build Status GoDoc

GCM (Google Cloud Messaging) CCS (Cloud Connection Server) implementation for application servers as described in Android developer docs.

Uses the XMPP endpoint to have persistent and asynchronous connection with the Google's GCM servers.

The HTTP implementation is a work in progress but it is advisable to use the CCS (XMPP) implementation instead as it is asynchronous and hence utilizes server resources more efficiently.

CCS Example

package main

import (
	"fmt"
	"github.com/soygul/gcm/ccs"
)

func main() {
	c, err := ccs.Connect("gcm-preprod.googleapis.com:5236", "gcm_sender_id", "gcm_api_key", true)
	if err != nil {
		return
	}

	// send a test message to a device
	_, err = c.Send(&ccs.OutMsg{To: "device_registration_id", Data: map[string]string{"test_message": "GCM CCS client testing message."}})

	// start receiving messages from CCS
	for {
		m, err := c.Receive()
		go func(m *ccs.InMsg) {
			log.Printf("message: %v\n error (if any): %v\n", m, err)
		}(m)
	}
}

To see a more comprehensive example, check the godocs.

Testing

All the tests can be executed by go test -race -cover ./... command. Optionally you can add -v flag to observe all connection logs. Integration tests require the following environment variables to be defined. If they are missing, integration tests are skipped.

export GCM_CCS_HOST=gcm-preprod.googleapis.com:5236
export GCM_SENDER_ID=preprod_sender_id
export GOOGLE_API_KEY=preprod_api_key

export GCM_REG_ID=optional_reg_id_from_android_device

GCM_REG_ID is optional and it is a GCM registration ID taken from an Android device or simulator. If provided, it will be used in executing server-to-device messaging tests. Otherwise, these tests will be skipped.

License

MIT

About

GCM (Google Cloud Messaging) - CCS (XMPP Cloud Connection Server) and HTTP implementation.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages