Meteor-Community-Packages / Meteor-Community-Packages/raix-push

Error: Push.sendGCM.... has no method 'sendGCM' - EDIT FOUND WORKAROUND

Open
#23 16 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
505
Forks
191
PR merge metrics
No merged PRs in 30d

Description

EDIT - FOUND WORKAROUND! See one of my comments, below.

I had push notifications working on Android in one of your old packages, but not anymore. Here's the error I'm getting. I'll post my setup below. Note the method 'sendMessage' is a server side method that I'm calling from the client to send a push notification (I'm sending notifcations out from the server).

I'm getting the following error with Push.sendGCM and Push.sendAPN. I'm also not able to get Push.send to work.

Here's my effort with Push.sendGCM. Scroll much further down below to see my setup for Push.send

**error in the server console**

```
I20150109-19:10:39.952(-5)? Exception while invoking method 'sendMessage' TypeError: Object # has no method 'sendGCM'
I20150109-19:10:40.930(-5)? at Meteor.methods.sendMessage (app/server/server.js:160:12)
I20150109-19:10:40.931(-5)? at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1599)
I20150109-19:10:40.931(-5)? at packages/ddp/livedata_server.js:648
I20150109-19:10:40.932(-5)? at _.extend.withValue (packages/meteor/dynamics_nodejs.js:56)
I20150109-19:10:40.932(-5)? at packages/ddp/livedata_server.js:647
I20150109-19:10:40.932(-5)? at _.extend.withValue (packages/meteor/dynamics_nodejs.js:56)
I20150109-19:10:40.933(-5)? at _.extend.protocol_handlers.method (packages/ddp/livedata_server.js:646)
I20150109-19:10:40.936(-5)? at packages/ddp/livedata_server.js:546
```

**App Structure**

```
client\client.js
server\server.js
lib
private
public
resources
config.push.json
mobile-config.js
```

**client.js**

``` javascript
Meteor.call("sendMessage", options, function (err, res) { ... };

Push.addListener('token', function(token) {
if (token) {
Meteor.call("updatePushToken", token, function(err, res) {});
};
});

Push.id(); // Unified id - not a token
```

**server.js**

``` javascript
Push.debug = true;

// Internal events
// do we need this both on client and server?
Push.addListener('token', function(currentToken, newToken) {
// Token is { apn: 'xxxx' } or { gcm: 'xxxx' } or null
// if newToken is null then the currentToken is invalid
// if newToken is set then this should replace the currentToken
if (newToken) {
Meteor.users.update( { _id: this.userId }, { $set: { pushToken: newToken } } );
};
});

Meteor.methods({
'updatePushToken': function(token) {
Meteor.users.update( { _id: this.userId }, { $set: { pushToken: token } } )
},
'sendMessage': function(options) {
//some code that looks up the gcm token of the recipient has been ommitted
//code code code

Push.sendGCM(
{ gcm: 'the token for the user I am sending to }',
{
from: options.stuff,
title: options.title,
text: options.text
}
);
}
});
```

**config.push.json**

``` javascript
{
"apn": {
"passphrase": "myPassword",
"key": "myKey",
"cert": "myCert"
},
"gcm": {
"apiKey": "myAPIKey",
"projectNumber": myNumber
},
"production": false,
// "badge": true,
// "sound": true,
"alert": true,
"vibrate": true
}
```

Here's my effort for Push.send. Everything is the same except the end of the server method "sendMessage". This successfully writes to the collection "_raix_push_notifications" but I never receive a notification.

**server/server.js**

``` javascript
//inside the server method "sendMessage"
Push.send({
from: senderUsername,
title: 'New BCBC video!',
text: oRecipientVideo.title,
// query: {}
token: token object from elsewhere in the code // token: appId or token eg. "{ apn: token }"
// tokens: array of appId's or tokens
// payload: user data
});
```

**_raix_push_notifications**

``` javascript
{
from: "stuff",
title: "stuff",
text: "stuff",
count: 0,
createdAt: ISODate("2015-01-10T00:32:04.000Z"),
createdBy: "",
token: {
gcm: "token string"
},
_id: "id stuff"
}
```

Contributor guide

Open the contributing guide

Research direction

Start with the failing call in server/server.js, reported at app/server/server.js:160, and compare Push.sendGCM, Push.sendAPN, and Push.send using the configuration in config.push.json. Reproduce the server-side sendMessage path and inspect the resulting _raix_push_notifications record. Done would require a confirmed cause and a documented supported sending path, but the report already mentions a workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend, mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.