• Stars
    star
    176
  • Rank 216,987 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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>"

More Repositories

1

electron-push-receiver

A module to bring Web Push support to Electron allowing it to receive notifications from Firebase Cloud Messaging (FCM).
JavaScript
186
star
2

unused-webpack-plugin

A webpack plugin to find unused modules/source files.
JavaScript
176
star
3

remnants

Find unused files. Spot these residues, leftovers, relics of an ancient past.
JavaScript
21
star
4

open-image-feed

A open source self-hosted real-time image feed.
JavaScript
19
star
5

shelljs-plugin-ssh

A ssh plugin for shelljs
JavaScript
10
star
6

ssh2-client

A Promise based wrapper around ssh2 to exec commands or setup a live shell on a remote host.
JavaScript
6
star
7

create-pr

Open github create PR page for the given branch.
JavaScript
5
star
8

git-training

Yet another git training.
HTML
4
star
9

immersive

A framework to build immersive CLIs & great developer tools.
JavaScript
4
star
10

terminal-joystick

🎮 A joystick for your terminal.
JavaScript
3
star
11

from-and-to-json

An Atom package to convert selected JSON to Javascript object and vice versa
JavaScript
3
star
12

ionic-gulp

Gulp tasks for Ionic development
JavaScript
2
star
13

connected-house

A open source connected house.
JavaScript
2
star
14

lxcjs

A Node JS wrapper around lxc commands
JavaScript
2
star
15

autoclicker

👆 An autoclicker built with Node.js.
JavaScript
2
star
16

hacker-typer

A hacker typer using streams.
JavaScript
2
star
17

angular-material-express-seed

A Angular Material and Express seed
JavaScript
2
star
18

blessed-circle

🎨 Draw a circle in your terminal using blessed.
JavaScript
1
star
19

liner

Show a specific line from a file.
JavaScript
1
star
20

smart-home

A open source smart home powered by Raspberry Pi and Node JS
JavaScript
1
star
21

Scripts

A bunch of scripts
Shell
1
star
22

quick-actions

A macOS menubar app to execute quick actions
JavaScript
1
star
23

javascript-tooling

A Javascript tooling presentation
JavaScript
1
star
24

JunkBot

A junk but awesome bot
Python
1
star
25

vorpal-seed

A vorpal seed with storage, ssh support and sample commands
JavaScript
1
star
26

CreateFolderAndMove

Add an entry to the contextual menu under Windows when you right click on a file to create a Folder with the name of the selected file and move the file in it
Batchfile
1
star