All Projects → flauc → Ng Push

flauc / Ng Push

Licence: mit
An Angular wrapper around the Notifications API

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Ng Push

Toasty
A notification package for Elm apps.
Stars: ✭ 39 (-29.09%)
Mutual labels:  notifications
Ntfd
A lightweight notification daemon for fancy desktop integrations
Stars: ✭ 44 (-20%)
Mutual labels:  notifications
Synology Notifications
Synology notifications service
Stars: ✭ 47 (-14.55%)
Mutual labels:  notifications
Cordova Plugin Firebase
Cordova plugin for Google Firebase
Stars: ✭ 997 (+1712.73%)
Mutual labels:  notifications
Godotnotificationcenter
A notification center for Godot Engine
Stars: ✭ 43 (-21.82%)
Mutual labels:  notifications
Ehplainalert
Plain style IOS alert
Stars: ✭ 44 (-20%)
Mutual labels:  notifications
React Native Ua
React Native module for Urban Airship
Stars: ✭ 37 (-32.73%)
Mutual labels:  notifications
Native Notifier
Use native system notifications in node.js without third-party libraries
Stars: ✭ 53 (-3.64%)
Mutual labels:  notifications
Eventd
A simple daemon to track remote or local events and do actions the user wants to
Stars: ✭ 43 (-21.82%)
Mutual labels:  notifications
Robin
A multi-platform notification scheduler written in Swift.
Stars: ✭ 46 (-16.36%)
Mutual labels:  notifications
Builder
Prepare your Laravel apps incredibly fast, with various commands, services, facades and boilerplates.
Stars: ✭ 1,009 (+1734.55%)
Mutual labels:  notifications
Chrome Notifier
Google Chrome extension for PagerDuty desktop notifications.
Stars: ✭ 43 (-21.82%)
Mutual labels:  notifications
Pushkit
All the required components to set up independent web push notifications 🎈
Stars: ✭ 45 (-18.18%)
Mutual labels:  notifications
Onesignal Ane
OneSignal extension for Adobe AIR (iOS & Android)
Stars: ✭ 39 (-29.09%)
Mutual labels:  notifications
Craft Brief
Quick, easy, and customizable user-group notifications for Craft CMS.
Stars: ✭ 47 (-14.55%)
Mutual labels:  notifications
Notify.uno
Get notified when your command is done
Stars: ✭ 38 (-30.91%)
Mutual labels:  notifications
Laravel Notification
Example package for using the (still under development) Messages API from Nexmo as a notification channel in Laravel
Stars: ✭ 44 (-20%)
Mutual labels:  notifications
Giti
Permanent observer of your git directories
Stars: ✭ 54 (-1.82%)
Mutual labels:  notifications
Onesignal Gradle Plugin
Use with OneSignal-Android-SDK to help integrate it into your Android Studio or Gradle project. https://onesignal.com
Stars: ✭ 49 (-10.91%)
Mutual labels:  notifications
Potato Library
Easy to use Utility library for Android
Stars: ✭ 45 (-18.18%)
Mutual labels:  notifications

ng-push

An Angular wrapper around the Notifications API

Build Status NPM Version NPM Downloads

If you arn't familiar with push notifications you can read more about them on the Mozilla developer network.

Installation

To install this library, run:

$ npm install ng-push --save

Setup

Import the PushNotificationsModule in to your AppModule:

@NgModule({
    imports: [PushNotificationsModule],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }

Now import the PushNotificationsService where you want to use it:

constructor( private _pushNotifications: PushNotificationsService ) {}

Requesting Permission

To request permission from the user to display push notifications call the requestPermission() method on the PushNotificationsService.

Create Notification

You can create a notification calling the create(title: string, options: PushNotification) method, like this:

this._pushNotifications.create('Test', {body: 'something'}).subscribe(
            res => console.log(res),
            err => console.log(err)
        )

The create() method returns an observable that emits the notification and the event when ever a show, click, close or error event occurs.

If you don't have permission to display the notification then the Permission not granted error will be thrown.

Options

The following are options that can be passed to the options parameter:

interface PushNotification {
    body?: string
    icon?: string
    tag?: string
    renotify?: boolean
    silent?: boolean
    sound?: string
    noscreen?: boolean
    sticky?: boolean
    dir?: 'auto' | 'ltr' | 'rtl'
    lang?: string
    vibrate?: number[]
}

Options correspond to the Notification interface of the Notification API: Mozilla developer network.

Examples

Registering to click event

this._pushNotifications.create(
    'Example One',
    {body: 'Just an example'}
)
    .subscribe(res => {
        if (res.event.type === 'click') {
            // You can do anything else here
            res.notification.close();
        }
    }
)

Using with universal method one (using injector)

Thank you @anode7 for submitting this example

import {Component, Inject, PLATFORM_ID, Injector} from '@angular/core';
import {isPlatformBrowser} from '@angular/common';

@Component({})
export class ExampleComponent {
    private _push:PushNotificationsService;

    constructor(
        @Inject(PLATFORM_ID) platformId: string,
        private injector: Injector,
    ) {
        if (isPlatformBrowser(platformId)) {
            //inject service only on browser platform
            this._push = this.injector.get(PushNotificationsService);
        }
    }
}

Using with universal method two (mock service)

A standard method used in Universal is creating a mock service which is injected in the ServerModule. A good example can be found here.

Development

To generate all *.js, *.d.ts and *.metadata.json files:

$ npm run build

To lint all *.ts files:

$ npm run lint

License

MIT © Filip Lauc

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].