🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

@koush/push-receiver

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@koush/push-receiver

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

latest
Source
npmnpm
Version
3.1.4
Version published
Weekly downloads
0
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 @eneris/push-receiver

Requirements

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

Usage

ClientConfig

interface ClientConfig {
    credentials?: Credentials // Will be generated if missing - save this after first use!
    persistentIds?: PersistentId[] // Default - []
    senderId: string // Required
    bundleId?: string // Default - 'receiver.push.com'
    chromeId?: string // Default - 'org.chromium.linux'
    chromeVersion?: string // Default - '94.0.4606.51'
    skipFcmRegistration?: boolean // Default - false
    logLevel?: keyof typeof LogLevels // 'NONE'|'DEBUG'|'VERBOSE' - default: 'NONE'
    vapidKey?: string // Default - default firebase VAPID key
    heartbeatIntervalMs?: number // Default - 5 * 60 * 1000
}

Node example

import { PushReceiver } from '@eneris/push-receiver'
import { argv as parsedArgs } from 'yargs'

if (!parsedArgs.senderId) {
    console.error('Missing senderId')
    return
}

(async () => {
    const instance = new PushReceiver({
        logLevel: parsedArgs.logLevel || 'DEBUG',
        senderId: parsedArgs.senderId,
        persistentIds: [], // Recover stored ids of all previous notifications
    })

    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()

    if (parsedArgs.serverId) {
        await instance.testMessage(parsedArgs.serverId)
    }

    stopListeningToCredentials()
    stopListeningToNotifications()
    instance.destroy()
})()

Keywords

push

FAQs

Package last updated on 13 Jun 2023

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