Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/matthieulemoine/electron-push-receiver
A module to bring Web Push support to Electron allowing it to receive notifications from Firebase Cloud Messaging (FCM).
https://github.com/matthieulemoine/electron-push-receiver
electron fcm firebase-cloud-messaging notifications push-notifications push-receiver webpush
Last synced: about 17 hours ago
JSON representation
A module to bring Web Push support to Electron allowing it to receive notifications from Firebase Cloud Messaging (FCM).
- Host: GitHub
- URL: https://github.com/matthieulemoine/electron-push-receiver
- Owner: MatthieuLemoine
- License: mit
- Created: 2017-10-25T16:24:56.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-07T09:36:31.000Z (about 2 years ago)
- Last Synced: 2025-01-18T13:13:30.152Z (8 days ago)
- Topics: electron, fcm, firebase-cloud-messaging, notifications, push-notifications, push-receiver, webpush
- Language: JavaScript
- Homepage: https://medium.com/@MatthieuLemoine/my-journey-to-bring-web-push-support-to-node-and-electron-ce70eea1c0b0
- Size: 148 KB
- Stars: 195
- Watchers: 10
- Forks: 69
- Open Issues: 56
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# electron-push-receiver
A module to bring Web Push support to [Electron](https://github.com/electron/electron) allowing it to receive notifications from Firebase Cloud Messaging (FCM).
## Why and how ?
See [this blog post](https://medium.com/@MatthieuLemoine/my-journey-to-bring-web-push-support-to-node-and-electron-ce70eea1c0b0).
## Install
```
npm i -S electron-push-receiver
```## Usage
- In `main.js` / in main process :
```javascript
const { setup: setupPushReceiver } = require('electron-push-receiver');// Call it before 'did-finish-load' with mainWindow a reference to your window
setupPushReceiver(mainWindow.webContents);
```- In renderer process :
```javascript
import { ipcRenderer } from 'electron';
import {
START_NOTIFICATION_SERVICE,
NOTIFICATION_SERVICE_STARTED,
NOTIFICATION_SERVICE_ERROR,
NOTIFICATION_RECEIVED as ON_NOTIFICATION_RECEIVED,
TOKEN_UPDATED,
} from 'electron-push-receiver/src/constants';// Listen for service successfully started
ipcRenderer.on(NOTIFICATION_SERVICE_STARTED, (_, token) => // do something);
// Handle notification errors
ipcRenderer.on(NOTIFICATION_SERVICE_ERROR, (_, error) => // do something);
// Send FCM token to backend
ipcRenderer.on(TOKEN_UPDATED, (_, token) => // Send token);
// Display notification
ipcRenderer.on(ON_NOTIFICATION_RECEIVED, (_, notification) => // display notification);
// Start service
ipcRenderer.send(START_NOTIFICATION_SERVICE, senderId);
```## Example
Thanks to [CydeSwype](https://github.com/CydeSwype), you can find an example project [here](https://github.com/CydeSwype/electron-fcm-demo).