Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
66ebbe8
:arrow_up: Bump lodash.merge from 4.6.1 to 4.6.2
dependabot[bot] Sep 8, 2020
609dad7
:arrow_up: Bump http-proxy from 1.16.2 to 1.18.1
dependabot[bot] Sep 8, 2020
2b8e7ed
:arrow_up: Bump ini from 1.3.5 to 1.3.7
dependabot[bot] Dec 11, 2020
b28808b
:arrow_up: Bump y18n from 3.2.1 to 3.2.2
dependabot[bot] Mar 30, 2021
44a60e1
:arrow_up: Bump handlebars from 4.0.11 to 4.7.7
dependabot[bot] May 7, 2021
43c33ea
:arrow_up: Bump lodash from 4.17.5 to 4.17.21
dependabot[bot] May 9, 2021
08912f7
:arrow_up: Bump hosted-git-info from 2.5.0 to 2.8.9
dependabot[bot] May 10, 2021
6517b94
:arrow_up: Bump merge from 1.2.0 to 1.2.1
dependabot[bot] May 12, 2021
b24a063
switch from request-promise to axios
koush Jun 20, 2021
55d4492
axios fixup for binaryu
koush Jun 20, 2021
99df548
arraybuffer return
koush Jun 21, 2021
8dee225
remove redundant arraybufferview
koush Jun 21, 2021
ca873ea
:hammer: Add bundleId option on register
Patrick-Remy Jul 23, 2021
ba034f6
:hammer: Fix linting issues
Patrick-Remy Jul 23, 2021
b5aefc3
:bug: Fix #34, escape endpoint form data param
Patrick-Remy Jul 23, 2021
a267683
:hammer: Git ignore IDE history files
Patrick-Remy Jul 23, 2021
1237bde
:hammer: Add typescript type declarations
selfisekai Apr 12, 2020
271e0b7
:tada: Add skipFcmRegistration option
selfisekai Apr 12, 2020
6bcf56f
:arrow_up: Bump tar from 2.2.1 to 2.2.2
dependabot[bot] Aug 4, 2021
e9f8b5c
:arrow_up: Bump path-parse from 1.0.5 to 1.0.7
dependabot[bot] Aug 11, 2021
fc2758a
:arrow_up: Bump tmpl from 1.0.4 to 1.0.5
dependabot[bot] Sep 21, 2021
38392a7
Merge commit '609dad739601413debc85dc58c884edbc0133ddb'
Eneris Oct 1, 2021
d4b53ef
Merge commit '44a60e111f1813fbff97095084c43131b2e90ff6'
Eneris Oct 1, 2021
d818779
Merge commit '08912f7820b5bdc2b0eebc466712f29bf59ac39f'
Eneris Oct 1, 2021
7be2ca5
Merge commit '2b8e7ede9d483e94d376109a6c8fbca93e8d85e0'
Eneris Oct 1, 2021
cd00c37
Merge commit 'b28808b3c5201305f72765a0bbd21deff988fc87'
Eneris Oct 1, 2021
5c93984
Merge commit '43c33ea457aa977e0d793ef21174c6a32eef1bae'
Eneris Oct 1, 2021
96d1996
Merge commit '6517b946f81cde0545fb60d9d7f9cd284d929bfa'
Eneris Oct 1, 2021
20ad5ca
Merge commit '6bcf56f4f8832ef4c4c8851dc27666d58b66f0eb'
Eneris Oct 1, 2021
5c57c14
Merge commit 'e9f8b5cee79a2a3cde1cc7ebeebdf5888e2c3c09'
Eneris Oct 1, 2021
b00ca86
Merge commit 'fc2758af1ec87c7b1e6b590c5a57e30123c4d280'
Eneris Oct 1, 2021
7a0629e
Merge commit '271e0b7d062957f59d302266a418a13fb57bb3c1'
Eneris Oct 1, 2021
296f349
upgrade packages
Eneris Oct 1, 2021
d682c3c
Merge commit '8dee225e5d92cebb3cbf966fe8d2e66ccd40ef1e'
Eneris Oct 4, 2021
b59e83c
Convert to TypeScript
Eneris Oct 10, 2021
f1ec259
Fix types
Eneris Oct 18, 2021
e899316
Clean up onReady handlers after connect
djm181 May 5, 2022
db55077
Add prepare script
djm181 May 5, 2022
a25979d
Build improvements
djm181 May 11, 2022
c1d39f7
Incremental builds
djm181 May 13, 2022
cda8c2f
Merge pull request #1 from djm181/master
Eneris Jun 3, 2022
f4416bb
Make tests work again & Update modules
Eneris Jun 3, 2022
615ab4c
Upgrade dependencies
Eneris Sep 21, 2022
88840d0
Fix tests again
Eneris Sep 21, 2022
88f0314
Implement Heartbeat
Eneris Sep 21, 2022
2ccc529
Bump version and create changelog
Eneris Sep 21, 2022
130c721
Update README.md
Eneris Sep 22, 2022
47eaad2
Replace "console" with "Logger"
satrik Oct 7, 2022
157e215
Merge pull request #3 from satrik/patch-1
Eneris Oct 10, 2022
c8d6106
More console logs
Eneris Oct 10, 2022
8223f7f
feat: add `axiosConfig` option to the configuration
Dec 13, 2022
b9d9413
refactor: remove `request-promise` dependency and use the `mkdirp` an…
Dec 14, 2022
f4c7b89
refactor: add named export to client.ts
Dec 14, 2022
5a14eea
docs: use the named export in the example
Dec 14, 2022
633fc38
Merge pull request #5 from erikian/feat/proxy
Eneris Dec 14, 2022
91fd3b2
Merge pull request #6 from erikian/refactor/package-json
Eneris Dec 14, 2022
9aa14a4
Merge pull request #7 from erikian/refactor/named-export
Eneris Dec 14, 2022
34b7400
v3.1.3
Eneris Dec 14, 2022
f53e986
Upgrade dependencies
Eneris Dec 14, 2022
f418391
Removed unused old scripts and deps
Eneris Dec 14, 2022
a71ceae
v3.1.4
Eneris Dec 14, 2022
691dfee
fix: clear heartbeat timeouts when the client is destroyed
Dec 19, 2022
f32312c
Merge pull request #8 from erikian/fix/heartbeat
Eneris Dec 19, 2022
8e58d26
fix: invalid object destructuring
jjfufu May 17, 2023
b8d1a36
Merge pull request #11 from jjfufu/fix/invalid-object-destructuring
Eneris May 29, 2023
2e0302c
Update protobuf.js + minor changes to build steps
Eneris Aug 22, 2023
5d8aaad
Migrate to FCM v1
Eneris May 10, 2024
f097669
Removed unmaintaned tests
Eneris May 10, 2024
c649fb1
Removed duplicate example - example is already in readme.md
Eneris May 10, 2024
1ca0e9b
Bump protobuf version
Eneris May 10, 2024
c6f49db
Update README
Eneris May 10, 2024
dfcfa55
Conver client private properties to native # privates
Eneris May 13, 2024
fac7472
Bump version
Eneris May 13, 2024
813fe3e
Merge pull request #16 from Eneris/fcm-v1
Eneris May 13, 2024
bc302de
Update README.md
Eneris May 31, 2024
486ae4b
Support register FCM using default VAPID
Jun 18, 2024
2cd792a
Apply suggestions from code review
tsightler Jun 18, 2024
14f36df
Cleanup unused code
Jun 18, 2024
e4c0798
Merge pull request #20 from tsightler/master
Eneris Jun 19, 2024
90e3e63
Bump version & Update dependencies & Add basic example
Eneris Jun 19, 2024
f9eb975
Respect debug config
dgreif Jun 21, 2024
2685db2
Merge pull request #21 from dgreif/fix-debug-config
Eneris Jun 24, 2024
a297775
Bump version
Eneris Jun 24, 2024
23edb33
Create custom typed EventEmitter and wrap all listeners into try..catch
Eneris Jul 15, 2024
2180e04
Remove extraneous console log
dgreif Jul 24, 2024
f0736ba
Merge pull request #23 from dgreif/dg/remove-log
Eneris Jul 24, 2024
00798e3
Fixed this-context in setTimeout
panther7 Aug 5, 2024
9a05bbd
Merge pull request #24 from panther7/fix-settimeout-context
Eneris Aug 8, 2024
204d439
Remove all socket listeners before destroy
Eneris Aug 8, 2024
d6c39cd
Bump versions
Eneris Aug 22, 2024
0870ccf
Added whenReady promise
Eneris Aug 22, 2024
de3b1cf
Upgrade dependencies
Eneris Oct 21, 2024
9abb2ca
Split request error handling to network and other
Eneris Oct 22, 2024
f26a4f1
Bump version and deps
Eneris Oct 29, 2024
df882d0
End socket connection before destroying it
TheLeoP Apr 26, 2025
5ecdefc
Merge pull request #31 from TheLeoP/fix
Eneris May 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ coverage
storage.json
web/
.esm-cache
dist
src/protos.d.ts
120 changes: 24 additions & 96 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,98 +1,26 @@
{
"parser": "babel-eslint", // https://github.com/babel/babel-eslint
// Extend existing configuration from ESlint and eslint-plugin-react defaults.
"extends": [
"eslint:recommended", // http://eslint.org/docs/rules/
],
// Enable ES6 support. If you want to use custom Babel
// features, you will need to enable a custom parser
// as described in a section below.
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"env": {
"browser": true,
"node": true,
"es6": true,
"jest": true
},
// Enable custom plugin known as eslint-plugin-jest
"plugins": [
"jest"
],
"rules": {
// Default to single quotes and raise an error if something
// else is used
"quotes": [2, "single"],
//Variables
"no-shadow": 2, // http://eslint.org/docs/rules/no-shadow
"no-shadow-restricted-names": 2, // http://eslint.org/docs/rules/no-shadow-restricted-names
"no-use-before-define": 0, // http://eslint.org/docs/rules/no-use-before-define
//Possible errors
"no-alert": 2, // http://eslint.org/docs/rules/no-alert
"block-scoped-var": 0, // http://eslint.org/docs/rules/block-scoped-var
//ES6
"no-var": 2, // http://eslint.org/docs/rules/no-var
"prefer-const": 2, // http://eslint.org/docs/rules/prefer-const
//Best Practices
"curly": [2, "multi-line"], // http://eslint.org/docs/rules/curly
"default-case": 2, // http://eslint.org/docs/rules/default-case
"dot-notation": [2, { // http://eslint.org/docs/rules/dot-notation
"allowKeywords": true,
"allowPattern": "^[a-z]+(-[a-z]+)+$",
}],
"comma-dangle": [2, //http://eslint.org/docs/rules/comma-dangle
"always-multiline"
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"eqeqeq": 2, // http://eslint.org/docs/rules/eqeqeq
"guard-for-in": 0, // http://eslint.org/docs/rules/guard-for-in
"no-caller": 2, // http://eslint.org/docs/rules/no-caller
"no-eq-null": 2, // http://eslint.org/docs/rules/no-eq-null
"no-eval": 2, // http://eslint.org/docs/rules/no-eval
"no-extend-native": 2, // http://eslint.org/docs/rules/no-extend-native
"no-extra-bind": 2, // http://eslint.org/docs/rules/no-extra-bind
"no-fallthrough": 2, // http://eslint.org/docs/rules/no-fallthrough
"no-floating-decimal": 2, // http://eslint.org/docs/rules/no-floating-decimal
"no-implied-eval": 2, // http://eslint.org/docs/rules/no-implied-eval
"no-lone-blocks": 2, // http://eslint.org/docs/rules/no-lone-blocks
"no-loop-func": 2, // http://eslint.org/docs/rules/no-loop-func
"no-multi-str": 2, // http://eslint.org/docs/rules/no-multi-str
"no-native-reassign": 2, // http://eslint.org/docs/rules/no-native-reassign
"no-new": 2, // http://eslint.org/docs/rules/no-new
"no-new-func": 2, // http://eslint.org/docs/rules/no-new-func
"no-new-wrappers": 2, // http://eslint.org/docs/rules/no-new-wrappers
"no-octal-escape": 2, // http://eslint.org/docs/rules/no-octal-escape
"no-param-reassign": 2, // http://eslint.org/docs/rules/no-param-reassign
"no-proto": 2, // http://eslint.org/docs/rules/no-proto
"no-redeclare": 2, // http://eslint.org/docs/rules/no-redeclare
"no-return-assign": 2, // http://eslint.org/docs/rules/no-return-assign
"no-script-url": 2, // http://eslint.org/docs/rules/no-script-url
"no-self-compare": 2, // http://eslint.org/docs/rules/no-self-compare
"no-sequences": 2, // http://eslint.org/docs/rules/no-sequences
"no-throw-literal": 2, // http://eslint.org/docs/rules/no-throw-literal
"no-trailing-spaces": 2, //http://eslint.org/docs/rules/no-trailing-spaces
"no-underscore-dangle": 0, //http://eslint.org/docs/rules/no-underscore-dangle
"no-with": 2, // http://eslint.org/docs/rules/no-with
"radix": 2, // http://eslint.org/docs/rules/radix
"semi": [2, "always", { //http://eslint.org/docs/rules/semi
"omitLastInOneLineBlock": true
}],
"vars-on-top": 2, // http://eslint.org/docs/rules/vars-on-top
"wrap-iife": [2, "any"], // http://eslint.org/docs/rules/wrap-iife
"yoda": 2, // http://eslint.org/docs/rules/yoda
"no-console": 0,
"no-unused-vars": [2, { "ignoreRestSiblings": true }],
"key-spacing": [2, {
"beforeColon": true,
"afterColon": true,
"mode": "minimum",
"align": {
"beforeColon": true,
"afterColon": true,
"on": "colon",
"mode": "strict"
}
}]
}
}
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-duplicate-enum-values": "off"
},
"overrides": [
{
"files": ["**/*.test"],
"plugins": ["jest"],
"extends": ["plugin:jest/recommended"],
"rules": {
"no-undef": "off",
"import/first": "off"
}
}
]
}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ storage.json
web/
.esm-cache
test/keys.js
.history
dist
src/protos.d.ts
*.tsbuildinfo
yarn-error.log
tests
6 changes: 0 additions & 6 deletions .npmignore

This file was deleted.

2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8
20
1 change: 1 addition & 0 deletions .yarnclean
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/*
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# @eneris/push-receiver

## 4.0.1-beta
### Braking changes
- New parametrer `firebase` is now requried in the config - this is used mainly for FCM installation
- FCM `installation` data were added into `fcm` part of `Credentials` containing Firebase Install credentials - Token refreshing is in TODO
- Removed the `logLevel` option and replaced it with `debug: boolean`
- Moved `sentTestMessage` into separate class called `PushSender`

### Major changes
- Replaced `axios` with native `fetch` in Node v20+
- Added `index` export for `PushReceiver` and `PushSender`

## 3.1.0

### Minor Changes

- Added automated Heartbeat messages
- new option `heartbeatIntervalMs` DEFAULT: 5 * 60 * 1000
- new events `ON_HEARTBEAT` - this is emited when socket recieves `ping` or `ack` messages

### Patch Changes

- Updated devDependencies
104 changes: 63 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

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

For [Electron](https://github.com/electron/electron), you can use [electron-push-receiver](https://github.com/MatthieuLemoine/electron-push-receiver) instead which provides a convenient wrapper.

See [this blog post](https://medium.com/@MatthieuLemoine/my-journey-to-bring-web-push-support-to-node-and-electron-ce70eea1c0b0) for more details.

## When should I use `push-receiver` ?

- I want to **receive** push notifications sent using Firebase Cloud Messaging in an [electron](https://github.com/electron/electron) desktop application.
Expand All @@ -19,53 +15,79 @@ See [this blog post](https://medium.com/@MatthieuLemoine/my-journey-to-bring-web
## Install

`
npm i -S push-receiver
npm i -S @eneris/push-receiver
`

## Requirements
## Requirements

- Node v8 (async/await support)
- Firebase sender id to receive notification
- Firebase serverKey to send notification (optional)
- Node v20 (async/await/randomUUID/fetch support)
- Firebase credentials from `Step 1` - https://firebase.google.com/docs/web/setup

## Usage
## Acknowledgements
- https://github.com/MatthieuLemoine - for creating initial module on wich uppon in iterated

### Electron
## Usage

You can use [electron-push-receiver](https://github.com/MatthieuLemoine/electron-push-receiver) instead which provides a convenient wrapper.
### ClientConfig

```typescript
interface ClientConfig {
credentials?: Credentials // Will be generated if missing - save this after first use!
persistentIds?: PersistentId[] // Default - []
bundleId?: string // Default - 'receiver.push.com'
chromeId?: string // Default - 'org.chromium.linux'
chromeVersion?: string // Default - '94.0.4606.51'
debug?: boolean // Enables debug console logs
heartbeatIntervalMs?: number // Default - 5 * 60 * 1000
firebase: FirebaseConfig // Full client firebase credentials are now needed
}
```

### Node
### Node example

```javascript
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)
}
```
import { PushReceiver } from '@eneris/push-receiver'

### Test notification
(async () => {
const instance = new PushReceiver({
debug: true,
persistentIds: [], // Recover stored ids of all previous notifications
firebase: {
// ...Firebase web credentials
},
credentials: null, // Insert credentials here after the first run
})

To test, you can use the [send script](scripts/send/index.js) provided in this repo, you need to pass your serverKey and the FCM token as arguments :
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
})

```
node scripts/send --serverKey="<FIREBASE_SERVER_KEY>" --token="<FIREBASE_TOKEN>"
const stopListeningToNotifications = instance.onNotification(notification => {
// Do someting with the notification
console.log('Notification received', notification)
})

await instance.connect()


await instance.connect()

console.log('connected')

const sender = new PushSender({
// Firebase service account credentials here
})

console.log('server created')

await sender.testMessage(instance.config.credentials.fcm.token)

console.log('message sent')

stopListeningToCredentials()
stopListeningToNotifications()

instance.destroy()
})()
```
21 changes: 21 additions & 0 deletions example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const {
PushReceiver,
PushSender,
} = require('./dist');

(async () => {
const client = new PushReceiver({
debug: true,
persistentIds: [],
firebase: /* Insert firebase config here */,
credentials: null
})

await client.connect();

client.on('ON_MESSAGE_RECEIVED', console.log)

const sender = new PushSender(/* FIREBASE SERVICE ACCOUNT JSON */);

sender.testMessage(client.fcmToken);
})()
25 changes: 0 additions & 25 deletions example/index.js

This file was deleted.

6 changes: 6 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */

module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
}
Loading