jlcvp / fcm-node

A Node.JS simple interface to Google's Firebase Cloud Messaging (FCM) for Android & iOS & Web Notification and data push
MIT License
125 stars 46 forks source link

Buffer.js Error Unknown Encoding #9

Closed hebbian closed 7 years ago

hebbian commented 7 years ago

It successfully send push notification but then it crash in buffer.js as follows :

Successfully sent with response:  {"multicast_id":4628760918450252159,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1476179380585829%1243539d1243539d"}]}
buffer.js:618
          throw new TypeError('Unknown encoding: ' + encoding);
          ^

TypeError: Unknown encoding: {"multicast_id":4628760918450252159,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1476179380585829%1243539d1243539d"}]}
    at Buffer.write (buffer.js:618:17)
    at fromString (buffer.js:113:26)
    at new Buffer (buffer.js:58:12)
    at createWriteReq (net.js:719:38)
    at Socket._writeGeneric (net.js:671:11)
    at Socket._write (net.js:694:8)
    at doWrite (_stream_writable.js:292:12)
    at clearBuffer (_stream_writable.js:396:7)
    at Socket.Writable.uncork (_stream_writable.js:230:7)
    at ServerResponse.OutgoingMessage.end (_http_outgoing.js:586:21)
[nodemon] app crashed - waiting for file changes before starting...

I tried it on Mac OSX El Capitan if that helps. Thanks

jlcvp commented 7 years ago

@hebbian Looks like it's a problem with your encoding. Can you post the code right before and right after the send call? Additionally can you inform your node version?

haneefatel commented 7 years ago

There is an undefined variable error for two variables anyFail && anySuccess which are used in /lib/fcm line 78 - 86. We couldn't see the declaration in the code. Please share the updated version. code snippet you can find bellow,

       `anyFail = ((JSON.parse(data)).failure > 0);

                        if (anyFail) {
                            error = data.substring(0).trim();
                        }

                        anySuccess = ((JSON.parse(data)).success > 0);

                        if (anySuccess) {
                            id = data.substring(0).trim();
                        }`
jlcvp commented 7 years ago

@haneefatel, these variables are implicitly declared. This isn't the best approach but cannot imply the error described in this issue.