Giter Club home page Giter Club logo

go-gcm's Introduction

Project status

status: inactive

This project is no longer actively maintained, and remains here as an archive of this work.

For a replacement, check out this actively maintained fork of the library.

GCM Library for Go

Provides the following functionality for Google Cloud Messaging:

  1. Sending messages.
  2. Listening to receiving messages.

Documentation: http://godoc.org/github.com/google/go-gcm

Installation

$ go get github.com/google/go-gcm

Status

This library is in Alpha. We will make an effort to support the library, but we reserve the right to make incompatible changes when necessary.

Feedback

Please read CONTRIBUTING and raise issues here in Github.

go-gcm's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-gcm's Issues

Incorrect XMPP user string generation

Hi,

xmppUser method is generating XMPP user string by concatenating "senderId" with "xmppHost". It's a problem as host is set to "gcm-xmpp.googleapis.com". This results in auth error as GCM seems to be accepting only "[email protected]" as user. Changing "xmppHost" const to "xmpp.googleapis.com" solves the problem.

If my assumption on the problem is correct, I would suggest separating xmppHost from user string generation.

Potential problem with TimeToLive field in HttpMessage and XmppMessage

Hi folks,
I noticed that the TimeToLive field in the message structs is tagged as `json:"time_to_live,omitempty". From what I understand, this means that if TimeToLive has the default value (zero), then it will be omitted when marshaling the struct. If this is indeed the case (and according to my tests it is), then there is a discrepancy in the time_to_live usage, according to [https://developers.google.com/cloud-messaging/http-server-ref]:
time_to_live = 0, means that the notification should not be throttled and delivered immediately, and if this is not possible, then it should be discarded. However if I set TimeToLive = 0, it will be omitted from the message sent to the GCM server, and then the server will assume the default value, which is 4 weeks -- clearly, not what my intention was.

Refactored and improved project

@silvolu please take a look at our fork https://github.com/rounds/go-gcm

  • code refactored, http and xmpp clients separated
  • monitors xmpp connection with xmpp pings, redials when it fails
  • handles CONNECTION_DRAINING properly
  • graceful close
  • improved logging with logrus
  • various govet/golint fixes
  • Travis and Codecov added

The project runs in production for a couple of months, looks good)

FCM

What about: Firebase Cloud Messaging (FCM) is the new version of GCM. It inherits the reliable and scalable GCM infrastructure, plus new features! See the FAQ to learn more. If you are integrating messaging in a new app, start with FCM. GCM users are strongly recommended to upgrade to FCM, in order to benefit from new FCM features today and in the future.

How to use FCM endpoints?
fcm.googleapis.com/fcm/ and fcm-xmpp.googleapis.com

Listen connection dropping - use model

This is more of a usage question. I have started using this code in a server to listen to incoming GCM messages. I noticed that the GCM's stopped reaching my server suddenly but on restarting the server I got all the queued up GCM's. I am guessing that the listen connection had dropped in the night.

Should the the gcm.Listen call be in a forever loop like so:

func (r *Receiver) startListener() {
    for {
        err := gcm.Listen(r.gcmSenderId, r.googleApiKey, messageHandler, stopChannel)
        revel.INFO.Println("Restarted listener because of err", err)
    }
}

Unmarshalling HttpRespose fails on dry runs

When a message is sent with the DryRun field set to true, FCM returns -1 as the MessageId. This causes unmarshalling to fail since the MessageId field is of type uint. Here's the fix

type HttpResponse struct {
    ...
    MessageId    int     `json:"message_id,omitempty"`
    ....
}

Proper error handling when sending XMPP message

Recently, SendXmpp() started failing for me with the following error:

write tcp <IP>:<port>-><IP>:<port>: write: connection timed out

Restarting the Go process that called SendXmpp() makes this error go away, and push notifications start working again. But of course, restarting the Go process isn't ideal. Is there something I can do explicitly to handle this kind of error? For instance, is there a way to close the current XmppClient and retry sending the message, so that the retry instantiates a new XmppClient and opens a new connection?

Long multicast_id

After attempt to send message:

gcm.SendHttp(apiKey, message)

I'm receiving error:

error sending request to GCM HTTP server: error unmarshaling json from body: json: cannot unmarshal number 7168156478862157292 into Go value of type int

DebugMode = true:

sending:{"to":"dQmz...CRyA","data":{"message":"hello world"}}
received body:{"multicast_id":7168156478862157292,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1469779167530028%d86f1c9df9fd7ecd"}]}

May be is necessary to change the type of HttpResponse.MulticastId to int64 or string?

Handle connection draining

Need to handle cases where we need to connection open (one is draining, one is new), and understand how long should the connection under draining be kept open.

Expose GCM as an interface for easier testing

Writing test code for packages using this lib is difficult because of the static send methods. Exposing an interface wrapping the public facing methods will help writing more testable code for users depending on this lib.

Thoughts?

sample code

Can someone post a sample code of basic use of this library.(Listen , Send, Receive)

App Engine support

http.DefaultTransport and http.DefaultClient are not available in App Engine.

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.