Giter Club home page Giter Club logo

gcm's Introduction

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/nbusy/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

gcm's People

Contributors

soygul avatar deepakchoudhary avatar

Watchers

James Cloos avatar  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.