You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This repository implements a Node.js module for sending push notifications across multiple platforms: Apple (APN), Google (GCM/FCM), Windows (WNS), Amazon (ADM), and Web-Push. The core logic is in `lib/` and `src/`, with each platform handled by a dedicated file (e.g., `sendAPN.js`, `sendFCM.js`).
6
+
7
+
## Architecture & Data Flow
8
+
9
+
-**Entry Point:** Use `PushNotifications` from `lib/index.js` or `src/index.js`.
10
+
-**Settings:** Each platform's credentials/config are passed to the constructor. See the example in `README.md`.
11
+
-**Sending:** The main method is `push.send(registrationIds, data, callback)` or as a Promise. It auto-detects device type and routes to the correct sender.
12
+
-**Platform Senders:** Each sender (e.g., `sendAPN.js`, `sendFCM.js`) implements the logic for its platform. Shared utilities are in `lib/utils/` and `src/utils/`.
13
+
-**RegId Detection:** Device type is inferred from the registration ID structure. See `PN.getPushMethodByRegId` for details.
14
+
15
+
## Developer Workflows
16
+
17
+
-**Install:**`npm install`
18
+
-**Test:** Run all tests with `npm test`. Tests are in `test/` and cover basic flows and platform-specific cases.
19
+
-**Debug:** Use the callback or Promise error/result from `push.send`. Each result object includes method, success/failure counts, and error details per device.
20
+
-**Build:** No build step required for basic usage. ES6 is used, but compatible with ES5 via Babel if needed.
21
+
22
+
## Conventions & Patterns
23
+
24
+
-**Platform-specific files:** Each push service has its own file for isolation and clarity.
25
+
-**Unified Data Model:** The `data` object for notifications is normalized across platforms. See `README.md` for all supported fields.
26
+
-**Error Handling:** Errors are unified and returned in the result array from `push.send`.
27
+
-**RegId Format:** Prefer object format for registration IDs (`{id, type}`), but string format is supported for legacy reasons.
28
+
-**Chunking:** Android tokens are chunked in batches of 1,000 automatically.
29
+
-**Constants:** Use constants from `constants.js` for platform types.
30
+
31
+
## Integration Points
32
+
33
+
-**External Libraries:**
34
+
- APN: `node-apn`
35
+
- FCM: `firebase-admin`
36
+
- GCM: `node-gcm`
37
+
- ADM: `node-adm`
38
+
- WNS: `wns`
39
+
- Web-Push: `web-push`
40
+
-**Credentials:** Place service account keys and certificates in appropriate locations (see `README.md` for examples).
41
+
42
+
## Key Files & Directories
43
+
44
+
-`lib/` and `src/`: Main implementation (mirrored structure)
45
+
-`test/`: Test cases and sample credentials
46
+
-`README.md`: Usage, configuration, and data model reference
47
+
48
+
## Example Usage
49
+
50
+
See `README.md` for a full example of settings, registration ID formats, and sending notifications.
51
+
52
+
---
53
+
54
+
For unclear or incomplete sections, please provide feedback or specify which workflows, patterns, or integrations need further documentation.
Copy file name to clipboardExpand all lines: README.md
+41-23Lines changed: 41 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,6 +21,7 @@ A node.js module for interfacing with Apple Push Notification, Google Cloud Mess
21
21
-[ADM](#adm)
22
22
-[Web-Push](#web-push)
23
23
-[Resources](#resources)
24
+
-[Proxy](#proxy)
24
25
-[LICENSE](#license)
25
26
26
27
## Installation
@@ -118,12 +119,12 @@ You can send to multiple devices, independently of platform, creating an array w
118
119
119
120
```js
120
121
// Single destination
121
-
constregistrationIds='INSERT_YOUR_DEVICE_ID';
122
+
constregistrationIds="INSERT_YOUR_DEVICE_ID";
122
123
123
124
// Multiple destinations
124
125
constregistrationIds= [];
125
-
registrationIds.push('INSERT_YOUR_DEVICE_ID');
126
-
registrationIds.push('INSERT_OTHER_DEVICE_ID');
126
+
registrationIds.push("INSERT_YOUR_DEVICE_ID");
127
+
registrationIds.push("INSERT_OTHER_DEVICE_ID");
127
128
```
128
129
129
130
The `PN.send()` method later detects device type and therefore used push method, based on the id stucture. Check out the method `PN.getPushMethodByRegId` how this detection works.
@@ -146,10 +147,10 @@ It can be of 2 types:
146
147
Where type can be one of: 'apn', 'gcm', 'adm', 'wns', 'webPush'. The types are available as constants:
A working server example implementation can be found at [https://github.com/alex-friedl/webpush-example/blob/master/server/index.js](https://github.com/alex-friedl/webpush-example/blob/master/server/index.js)
- [Crossplatform integration example using this library and a React Native app](https://github.com/alex-friedl/crossplatform-push-notifications-example)
0 commit comments