npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@janiscommerce/app-push-notification

v0.0.4

Published

This package will take care of performing the main actions for registration to receive notifications in the foreground and background.

Downloads

113

Readme

@janiscommerce/app-push-notification

janis-logo

Library for receiving notifications issued from firebase/janis.

PeerDependencies installation:

In order to receive notifications it is necessary to include the dependency

    npm install @react-native-firebase/messaging

Installation:

    npm install @janis-commerce/app-push-notification

What is received from firebase?

What is received is an object called RemoteMessage, which contains the data emitted from Firebase and is what triggers the notification listeners. Inside remoteMessage you get the notifications object that contains the information that we could use to render a component with the application in the foreground

For more information about this, read https://rnfirebase.io/reference/messaging/remotemessage

This library provides the following components and methods:

Functions

NotificationProvider(children, appName, events, environment, additionalInfo, channelConfigs) ⇒ null | React.element

It is the main component of the package, it is a HOC that is responsible for handling the logic of subscribing to notifications and receiving messages from the Firebase console. The HOC contains listeners to listen to notifications in the foreground and background, so (unless we cancel the subscription), we will receive notifications from the app even when it is closed.

Kind: global function
Throws:

  • null when not receive a children argument

| Param | Type | Description | | --- | --- | --- | | children | React.element | Component that will be rendered within the HOC, and about which the notification will be displayed | | appName | string | name of the aplication | | events | Array.<string> | is an array that will contain the events to which the user wants to subscribe | | environment | string | The environment is necessary for the API that we are going to use to subscribe the device to notifications. | | additionalInfo | object | fields to be sent as part of the body of the subscription request | | channelConfigs | Array.<(string|object)> | is the configuration that will be used to create new notification channels |

Example

import NotificationProvider from '@janiscommerce/app-push-notification'

return (
 <NotificationProvider
   appName='pickingApp'
   events={["picking:session:created","picking:session:assigned"]}
   environment='beta'
   >
   <MyComponent/>
 </NotificationProvider>
)

setupBackgroundMessageHandler(callback)

This function is responsible for handling any callbacks from Firebase cloud messaging in the background or with the application closed

Kind: global function

| Param | Type | Description | | --- | --- | --- | | callback | function | is the function that will receive the payload and render it as appropriate |

usePushNotification() ⇒ object

is a hook, which returns the elements contained within the notifications context. Returns an object containing: | name | description | |----------|----------| | deviceToken | Is the token linked to the device, which we use to subscribe it to notifications. | | foregroundNotification | An object containing all data received when a foreground push notification is triggered. | | backgroundNotification | An object containing all data received when a background push notification is triggered. | | subscribeError | An object containing all data received from a notification service subscription failure. | | cancelNotifications | This util is responsible for making the request to unsubscribe from all notification events. If no arguments are received, the request will be made with the previously registered events. | | updateSuscription | This function is responsible for updating the subscription to the notification service | | addNewEvent | This function allows you to add a new event to receive notifications. | | deleteReceivedNotification | An util that clears the foreground or background notification state to the depending on the type it receives by parameter | getSubscribedEvents | This function returns an array with the events to which the user is subscribed. |

Kind: global function
Example

import {usePushNotification} from '@janiscommerce/app-push-notification'

const { deviceToken, foregroundNotification, backgroundNotification} = usePushNotification()