logo

Get Started

The @aracna/fcm package depends on the @aracna/core package as a peer dependency, which is required for it to function.

This package works only on Node.js.

npm install @aracna/fcm
npmyarnpnpm

Use to receive messages

The @aracna/fcm library is capable of registering to Firebase Cloud Messaging and listen to incoming messages through a socket connection with Google MTalk.

  1. Create a new project on the Firebase Console.
  2. Add a new web app to the project.
  3. Create a new web push certificate under the Cloud Messaging tab of the project settings.
  4. Create a new auth secret and ECDH key pair with the generateFcmAuthSecret and createFcmECDH functions.
  5. Store the auth secret and ECDH key pair securely.
  6. Register to Firebase Cloud Messaging with the registerToFCM function.
  7. Store the ACG ID, ACG security token and FCM token.
  8. Create a new FcmClient instance using the values from the previous steps.
  9. Connect with the connect method of the client.
  10. Listen to incoming messages with the on method of the client, see the FcmClient docs for more information.

Use to send messages

The @aracna/fcm library is capable of sending messages to Firebase Cloud Messaging.

  1. Create a new project on the Firebase Console.
  2. Create a new private key under the Service Accounts tab of the project settings.
  3. Use the sendFcmMessage function with the google-service-account.json file.

Migrate from push-receiver

The @aracna/fcm library is almost a drop-in replacement for the push-receiver library.

  1. Add a new web app to the Firebase project on the Firebase Console.
  2. Create a new web push certificate under the Cloud Messaging tab of the project settings.
  3. Register to Firebase Cloud Messaging with the registerToFCM function using the same values that were used with the push-receiver library.
  4. Store the FCM token, this one is generated with the latest APIs from Google/Firebase.
  5. Create a new FcmClient instance using the values from the previous steps.
  6. Connect with the connect method of the client.
  7. Listen to incoming messages with the on method of the client, see the FcmClient docs for more information.