All Projects → parse-community → node-apn

parse-community / node-apn

Licence: other
Apple Push Notification module for Node.js

Projects that are alternatives of or similar to node-apn

browser-push
Complete workout and guidelines to add web push notifications support for your webapp without third-party notification provider
Stars: ✭ 67 (-47.66%)
Mutual labels:  push-notifications
hms-cordova-plugin
This repo contains all of Cordova HMS plugins.
Stars: ✭ 78 (-39.06%)
Mutual labels:  push-notifications
Pure
Pure is a free social networking App. it is simple, reliable and it makes it easy to keep in touch with your friends and family. Pure works across mobile devices even on slow internet connections.
Stars: ✭ 28 (-78.12%)
Mutual labels:  push-notifications
fcmpush
Firebase Cloud Messaging API wrapper for Ruby, suppot HTTP v1 API including access_token auto refresh feature.
Stars: ✭ 44 (-65.62%)
Mutual labels:  push-notifications
node-xcs
NodeJS implementation of Google's XMPP Connection Server
Stars: ✭ 37 (-71.09%)
Mutual labels:  push-notifications
WaiterBell
WaiterBell - The ticketing system in real world!
Stars: ✭ 16 (-87.5%)
Mutual labels:  push-notifications
node-onesignal
Node.js wrapper for the One Signal API
Stars: ✭ 33 (-74.22%)
Mutual labels:  push-notifications
OneSignal-Codeigniter-Push-Notification
OneSignal is a free push notification service for web and mobile apps. This Codeigniter example makes it easy to integrate your website with OneSignal Push Notifications. https://onesignal.com/ DEMO - http://ci3onesignal.codefort.ru/
Stars: ✭ 27 (-78.91%)
Mutual labels:  push-notifications
one-signal
Laravel One Signal Wrapper
Stars: ✭ 90 (-29.69%)
Mutual labels:  push-notifications
mobile-messaging-cordova-plugin
Mobile Messaging SDK plugin for Cordova projects
Stars: ✭ 19 (-85.16%)
Mutual labels:  push-notifications
mobpush-api-java-client
MobPush 服务端集成SDK for Java
Stars: ✭ 14 (-89.06%)
Mutual labels:  push-notifications
parse-react
[EXPERIMENTAL] React, React Native, and React with SSR (e.g. Next.js) packages to interact with Parse Server backend
Stars: ✭ 58 (-54.69%)
Mutual labels:  parse-server
notifire
The open-source notification infrastructure for developers
Stars: ✭ 12,436 (+9615.63%)
Mutual labels:  push-notifications
homebridge-http-rgb-push
Homebridge plugin to control a web/http-based RGB device.
Stars: ✭ 16 (-87.5%)
Mutual labels:  push-notifications
Batch-iOS-SDK
Batch SDK for iOS
Stars: ✭ 28 (-78.12%)
Mutual labels:  push-notifications
parse-server-test-runner
A tool for programmatically starting Parse Server
Stars: ✭ 18 (-85.94%)
Mutual labels:  parse-server
apprise-ga
GitHub Action to send a dynamic push notification to every single platform thanks to the Apprise library
Stars: ✭ 18 (-85.94%)
Mutual labels:  push-notifications
local-reminders
Local Scheduled Push Notification using Firebase
Stars: ✭ 26 (-79.69%)
Mutual labels:  push-notifications
gotify-push
Chrome Extension for Send Push Notification 🔔 to gotify/server ☁
Stars: ✭ 32 (-75%)
Mutual labels:  push-notifications
nativescript-pushy
Easy push notifications for your NativeScript app!
Stars: ✭ 19 (-85.16%)
Mutual labels:  push-notifications

Node APN

Build Status Snyk Badge Coverage auto-release

npm latest version


A Node.js module for interfacing with the Apple Push Notification service.


Features

  • Based on HTTP/2 based provider API
  • Maintains a connection to the server to maximize notification batching and throughput.
  • Automatically re-sends unsent notifications if an error occurs

Installation

$ npm install @parse/node-apn --save

Quick Start

This readme is a brief introduction, please refer to the full documentation in doc/ for more details.

If you have previously used v1.x and wish to learn more about what's changed in v2.0, please see What's New

Load in the module

var apn = require('@parse/node-apn');

Connecting

Create a new connection to the Apple Push Notification provider API, passing a dictionary of options to the constructor. You must supply your token credentials in the options.

var options = {
  token: {
    key: "path/to/APNsAuthKey_XXXXXXXXXX.p8",
    keyId: "key-id",
    teamId: "developer-team-id"
  },
  production: false
};

var apnProvider = new apn.Provider(options);

By default, the provider will connect to the sandbox unless the environment variable NODE_ENV=production is set.

For more information about configuration options consult the provider documentation.

Help with preparing the key and certificate files for connection can be found in the [wiki][certificateWiki]

Connecting through an HTTP proxy

If you need to connect through an HTTP proxy, you simply need to provide the proxy: {host, port} option when creating the provider. For example:

var options = {
  token: {
    key: "path/to/APNsAuthKey_XXXXXXXXXX.p8",
    keyId: "key-id",
    teamId: "developer-team-id"
  },
  proxy: {
    host: "192.168.10.92",
    port: 8080
  }
  production: false
};

var apnProvider = new apn.Provider(options);

The provider will first send an HTTP CONNECT request to the specified proxy in order to establish an HTTP tunnel. Once established, it will create a new secure connection to the Apple Push Notification provider API through the tunnel.

Using a pool of http/2 connections

Because http/2 already uses multiplexing, you probably don't need to use more than one client unless you are hitting http/2 concurrent request limits.

var options = {
  // Round robin pool with 2 clients. More can be used if needed.
  clientCount: 2,
  token: {
    key: "path/to/APNsAuthKey_XXXXXXXXXX.p8",
    keyId: "key-id",
    teamId: "developer-team-id"
  },
  proxy: {
    host: "192.168.10.92",
    port: 8080
  },
  production: false
};

var apnProvider = new apn.MultiProvider(options);

Sending a notification

To send a notification you will first need a device token from your app as a string

let deviceToken = "a9d0ed10e9cfd022a61cb08753f49c5a0b0dfb383697bf9f9d750a1003da19c7"

Create a notification object, configuring it with the relevant parameters (See the notification documentation for more details.)

var note = new apn.Notification();

note.expiry = Math.floor(Date.now() / 1000) + 3600; // Expires 1 hour from now.
note.badge = 3;
note.sound = "ping.aiff";
note.alert = "\uD83D\uDCE7 \u2709 You have a new message";
note.payload = {'messageFrom': 'John Appleseed'};
note.topic = "<your-app-bundle-id>";

Send the notification to the API with send, which returns a promise.

apnProvider.send(note, deviceToken).then( (result) => {
  // see documentation for an explanation of result
});

This will result in the the following notification payload being sent to the device

{"messageFrom":"John Appelseed","aps":{"badge":3,"sound":"ping.aiff","alert":"\uD83D\uDCE7 \u2709 You have a new message"}}

You should only create one Provider per-process for each certificate/key pair you have. You do not need to create a new Provider for each notification. If you are only sending notifications to one app then there is no need for more than one Provider.

If you are constantly creating Provider instances in your app, make sure to call Provider.shutdown() when you are done with each provider to release its resources and memory.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].