Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

push-receiver

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

push-receiver

A module to subscribe to GCM/FCM and receive notifications within a node process.

  • 2.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.7K
decreased by-27.26%
Maintainers
1
Weekly downloads
 
Created
Source

push-receiver

A library to subscribe to GCM/FCM and receive notifications within a node process.

For Electron, you can use electron-push-receiver instead which provides a convenient wrapper.

See this blog post for more details.

When should I use push-receiver ?

  • I want to receive push notifications sent using Firebase Cloud Messaging in an electron desktop application.
  • I want to communicate with a node process/server using Firebase Cloud Messaging infrastructure.

When should I not use push-receiver ?

  • I want to send push notifications (use the firebase SDK instead)
  • My application is running on a FCM supported platform (Android, iOS, Web).

Install

npm i -S push-receiver

Requirements

  • Node v8 (async/await support)
  • Firebase sender id to receive notification
  • Firebase serverKey to send notification (optional)

Usage

Electron

You can use electron-push-receiver instead which provides a convenient wrapper.

Node

const { register, listen } = require('push-receiver');

// First time
// Register to GCM and FCM
const credentials = await register(senderId); // You should call register only once and then store the credentials somewhere
storeCredentials(credentials) // Store credentials to use it later
const fcmToken = credentials.fcm.token; // Token to use to send notifications
sendTokenToBackendOrWhatever(fcmToken);


// Next times
const credentials = getSavedCredentials() // get your saved credentials from somewhere (file, db, etc...)
// persistentIds is the list of notification ids received to avoid receiving all already received notifications on start.
const persistentIds = getPersistentIds() || [] // get all previous persistentIds from somewhere (file, db, etc...)
await listen({ ...credentials, persistentIds}, onNotification);

// Called on new notification
function onNotification({ notification, persistentId }) {
  // Update list of persistentId in file/db/...
  updatePersistentIds([...persistentIds, persistentId]);
  // Do someting with the notification
  display(notification)
}

Test notification

To test, you can use the send script provided in this repo, you need to pass your serverKey and the FCM token as arguments :

node scripts/send --serverKey="<FIREBASE_SERVER_KEY>" --token="<FIREBASE_TOKEN>"

Keywords

FAQs

Package last updated on 08 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc