Eneris / push-receiver

A library to subscribe to GCM/FCM and receive notifications within a node process.
https://medium.com/@MatthieuLemoine/my-journey-to-bring-web-push-support-to-node-and-electron-ce70eea1c0b0
MIT License
16 stars 16 forks source link

PHONE_REGISTRATION_ERROR #19

Closed Chicchi7393 closed 4 months ago

Chicchi7393 commented 4 months ago

Hi, I'm trying to initialize an instance of the push receiver with my app's credentials, but when i start the code i get "Register request has failed with Error=PHONE_REGISTRATION_ERROR" I don't have any other info except the full output and the code that I'm running

import {PushReceiver} from '@eneris/push-receiver'

const instance = new PushReceiver({
    debug: true,
    persistentIds: [], // Recover stored ids of all previous notifications
    firebase: {
        projectId: 'xxxxxxxxxxxxxxxx-a0000',
        appId: '1:1234567890123:android:a1a1a11a1a1a1a11a',
        apiKey: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
        messagingSenderId: '00000000000000'
    },
    credentials: undefined, // Insert credentials here after the first run
})

const stopListeningToCredentials = instance.onCredentialsChanged(({ oldCredentials, newCredentials }) => {
    console.log('Client generated new credentials.', newCredentials)
    // Save them somewhere! And decide if thing are needed to re-subscribe
})

const stopListeningToNotifications = instance.onNotification(notification => {
    // Do someting with the notification
    console.log('Notification received', notification)
})

await instance.connect()

console.log('connected')

console.log('server created')

stopListeningToCredentials()
stopListeningToNotifications()
constructor {
  debug: true,
  persistentIds: [],
  firebase: {
      projectId: 'xxxxxxxxxxxxxxxx-a0000',
      appId: '1:1234567890123:android:a1a1a11a1a1a1a11a',
      apiKey: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
      messagingSenderId: '00000000000000'
  },
  credentials: undefined
}
Register request has failed with Error=PHONE_REGISTRATION_ERROR
Retry... 1
Register request has failed with Error=PHONE_REGISTRATION_ERROR
Retry... 2
Register request has failed with <HTML>
<HEAD>
<TITLE>Not Found</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<!-- GSE Default Error -->
<H1>Not Found</H1>
<H2>Error 404</H2>
</BODY>
</HTML>

Retry... 3
Register request has failed with <HTML>
<HEAD>
<TITLE>Not Found</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<!-- GSE Default Error -->
<H1>Not Found</H1>
<H2>Error 404</H2>
</BODY>
</HTML>

Retry... 4
Register request has failed with <HTML>
<HEAD>
<TITLE>Not Found</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<!-- GSE Default Error -->
<H1>Not Found</H1>
<H2>Error 404</H2>
</BODY>
</HTML>

Retry... 5
Register request has failed with <HTML>
<HEAD>
<TITLE>Not Found</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<!-- GSE Default Error -->
<H1>Not Found</H1>
<H2>Error 404</H2>
</BODY>
</HTML>

/home/chri/IdeaProjects/RegistroAPI/notifications/node_modules/@eneris/push-receiver/dist/gcm.js:78
            throw new Error('GCM register has failed');
                  ^

Error: GCM register has failed
    at postRegister (/home/chri/IdeaProjects/RegistroAPI/notifications/node_modules/@eneris/push-receiver/dist/gcm.js:78:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async doRegister (/home/chri/IdeaProjects/RegistroAPI/notifications/node_modules/@eneris/push-receiver/dist/gcm.js:57:22)
    at async exports.default (/home/chri/IdeaProjects/RegistroAPI/notifications/node_modules/@eneris/push-receiver/dist/gcm.js:25:25)
    at async PushReceiver.registerIfNeeded (/home/chri/IdeaProjects/RegistroAPI/notifications/node_modules/@eneris/push-receiver/dist/client.js:163:21)
    at async PushReceiver.connect (/home/chri/IdeaProjects/RegistroAPI/notifications/node_modules/@eneris/push-receiver/dist/client.js:103:9)
    at async file:///home/chri/IdeaProjects/RegistroAPI/notifications/dist/index.js:21:1

Node.js v22.2.0
tsightler commented 4 months ago

With the current version you also need to include the VAPID, otherwise the app will not register.

However, I just figure out this weekend that it is actually possible to register using the default VAPID as with old version, but a small patch is required. I'm working on putting together a PR to submit for this.

Eneris commented 4 months ago

@Chicchi7393 exactly as the @tsightler says

@tsightler that sounds like great news! Looking forward to the PR. Please let me know if you require any assistance

Eneris commented 4 months ago

@Chicchi7393 I've just released new version 4.1.2 which fixes this issue