0.1.21 • Published 4 years ago

@consento/notification-server v0.1.21

Weekly downloads
40
License
MIT
Repository
github
Last release
4 years ago

@consento/notification-server

The @consento/notification-server is a expo based notification implementation for Consento. It consists of two parts: The Server & The Client.

Why?

Consento is supposed to run as decentralized as possible. Initially the decentralization of the notification system is not just a lot of work (please contact us if you want to support implement this) but also a risk in the current development phase. For that reason we are using Expo Push Notifications in the current version of Consento.

The Server

Rationale

Expo has one push-token per device/app! If this were to be directly shared with other devices, they would be able to spam/send the device without the possibility to for the other device to stop listening to these notifications.

The centralized server also open the possibility to later implement other notification systems that run on the same system. i.e. a decentralized system or desktop system that has different requirements.

Start the server

You can start the server using:

npx @consento/notification-server

It will log any messages as json to stdout.

You can change the port using env PORT=8080 npx @consento/notification-server

Storage

The server persists the current state in a HyperDB instance. This system could in future be used to distribute the state over multiple instances of the notification server running on different devices.

The Client

The client implements the INotificationTransport interface of @consento/api. It can be setup as follows:

const { ExpoTransport } = require('@consento/notification-server')
const { setup } = require('@consento/api')
const { sodium } = require('@consento/crypto/core/sodium')
const * as Notifications = require('expo-notifications')

const api = setup({
  cryptoCore: sodium,
  notificationTransport: new ExpoTransport({
    address: 'https://server.com/api', // insert the root of the running notification-server here
    getToken: async () => Notifications.getExpoPushTokenAsync() // Read more https://docs.expo.io/versions/latest/sdk/notifications/
  })
})

With this API you can send/receive notifications like this:

const { receiver, sender } = api.crypto.createReceiver()

api.notifications.on('message', (receiver/*: IReceiver*/, message) => {
  console.log('hello world')
})
api.notifications.subscribe(receiver) // Usually this happens on a different device
api.notifications.send(sender, 'Hello World')

License

MIT

0.1.20

4 years ago

0.1.21

4 years ago

0.1.19

4 years ago

0.1.18

4 years ago

0.1.17

4 years ago

0.1.16

4 years ago

0.1.14

4 years ago

0.1.15

4 years ago

0.1.13

4 years ago

0.1.11

4 years ago

0.1.12

4 years ago

0.1.10

4 years ago

0.1.8

4 years ago

0.1.9

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.19

5 years ago

0.0.18

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago