Problem with GCM sending

98 views
Skip to first unread message

Fryan Valdez

unread,
Jul 25, 2014, 3:26:31 AM7/25/14
to gcm-for-chr...@googlegroups.com
I've been playing around with GCM lately. I tried using it on one my chrome app. I was able to register the device with no problem. I tried sending a test message using the code posted here https://developer.chrome.com/apps/cloudMessaging. Unfortunately, it seems can't reached the destination. There were no errors returned. I think my messages are lost in transit.

function sendMessage() {
 
var message = {
    messageId
: getMessageId(),
    destinationId
: senderId + "@gcm.googleapis.com",
    timeToLive
: 86400,    // 1 day
    data
: {
     
"key1": "value1",
     
"key2": "value2"
   
}
 
};
  chrome
.gcm.send(message, function(messageId) {
   
if (chrome.runtime.lastError) {
     
// Some error occurred. Fail gracefully or try to send
     
// again.
     
return;
   
}

   
// The message has been accepted for delivery. If the message
   
// can not reach the destination, onSendError event will be
   
// fired.
 
});
}


And also the example here https://github.com/GoogleChrome/chrome-app-samples/tree/master/gcm-notifications, requires for API key and Message Key but the sample here https://developer.chrome.com/apps/cloudMessaging doesn't. I'm little confused. All I'm trying to accomplish is to enable message broadcasting from my server to all users who are using my chrome app and android app.


Thank you in advance.

Filip Gorski

unread,
Jul 25, 2014, 4:00:44 PM7/25/14
to gcm-for-chr...@googlegroups.com
Hi, Fryan,

Did you try following the steps in the https://developer.chrome.com/apps/cloudMessaging#set_up_project section?
In order to be able to send messages from your server to the application you need to make sure you register for the right registration Id, send it to your server, and then use it in an HTTP call from the server. (This is what the curl command simulates in the notification sample).

chrome.gcm.send should be used for messaging from your client to the server, and your server requires a bit different setup than for push messaging only. Namely, you'll have to use XMPP connection, which will allow it to both push messages and receive messages from the client.

You don't have to go XMPP if you don't do a lot of two way messaging. E.g. if you only want to send your clients registration ID to the server, an XHR should be enough.

Please respond, if you have more questions.

Thanks.
Filip
Reply all
Reply to author
Forward
0 new messages