gcm

package module
v0.0.0-...-08c1e33 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2016 License: MIT Imports: 0 Imported by: 0

README

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

Documentation

Overview

Package gcm contains functions for queueing and sending messages through GCM CCS and HTTP.

Directories

Path Synopsis
Package ccs provides GCM CCS (Cloud Connection Server) client implementation using XMPP.
Package ccs provides GCM CCS (Cloud Connection Server) client implementation using XMPP.
Package http provides GCM HTTP client implementation.
Package http provides GCM HTTP client implementation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL