googlearchive / go-gcm Goto Github PK
View Code? Open in Web Editor NEWGCM library for Go.
License: Apache License 2.0
GCM library for Go.
License: Apache License 2.0
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.
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
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.
Re-structure the code in the process
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?
Any plans to implement the server-side changes to support encrypted payload data into go-gcm so that notifications to Chrome 50 (and in the current version of Firefox on desktop) can contain extra information?
https://developers.google.com/web/updates/2016/03/web-push-encryption
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.
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"`
....
}
xmppAddress is currently defined as a constant (https://sourcegraph.com/github.com/google/go-gcm/-/blob/gcm.go#L42) - this prevents clients from specifying the pre-prod server at gcm-preprod.googleapis.com:5236
, or (more importantly for my use-case) connecting to the newer fcm-xmpp.googleapis.com:5235
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?
Check the flow, add some more detail
@silvolu please take a look at our fork https://github.com/rounds/go-gcm
The project runs in production for a couple of months, looks good)
For XMPP there shouldn't be more than 100 messages pending:
https://developers.google.com/cloud-messaging/ccs#flow
http.DefaultTransport and http.DefaultClient are not available in App Engine.
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?
I don't know if it's possible, but it would be nice to have ability to check and validate the format of the device registration token before we pass to the server.
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)
}
}
Can someone post a sample code of basic use of this library.(Listen , Send, Receive)
There are two problems with this library
1.you must change Priority in HttpMessage struct in file gcm.go to int
2.if every things is ok but you get error Error=DeprecatedEndpoint
go to gcm.go again and on const section change httpAddress from this "https://gcm-http.googleapis.com/gcm/send" to "https://fcm.googleapis.com/fcm/send"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.