Giter Site home page Giter Site logo

mobilusoss / react-web-notification Goto Github PK

View Code? Open in Web Editor NEW
270.0 8.0 82.0 4.63 MB

React component with HTML5 Web Notification API

Home Page: http://mobilusoss.github.io/react-web-notification

License: MIT License

JavaScript 99.88% HTML 0.12%
react notifications desktop-notification

react-web-notification's Introduction

React-web-notification Build Status npm version codebeat badge FOSSA Status codecov

React component with HTML5 Web Notification API. This component show nothing in dom element, but trigger HTML5 Web Notification API with render method in the life cycle of React.js.

Demo

View Demo

Installation

npm install --save react-web-notification

API

Notification

React component which wrap web-notification.

Props

Notification.propTypes = {
  ignore: bool,
  disableActiveWindow: bool,
  askAgain: bool,
  notSupported: func,
  onPermissionGranted: func,
  onPermissionDenied: func,
  onShow: func,
  onClick: func,
  onClose: func,
  onError: func,
  timeout: number,
  title: string.isRequired,
  options: object,
  swRegistration: object,
};
  • ignore : if true, nothing will be happen

  • disableActiveWindow : if true, nothing will be happen when window is active

  • askAgain : if true, window.Notification.requestPermission will be called on componentDidMount, even if it was denied before,

  • notSupported() : Called when HTML5 Web Notification API is not supported.

  • onPermissionGranted() : Called when permission granted.

  • onPermissionDenied() : Called when permission denied. Notification will do nothing until permission granted again.

  • onShow(e, tag) : Called when Desktop notification is shown.

  • onClick(e, tag) : Called when Desktop notification is clicked.

  • onClose(e, tag) : Called when Desktop notification is closed.

  • onError(e, tag) : Called when Desktop notification happen error.

  • timeout : milli sec to close notification automatically. Ignored if 0 or less. (Default 5000)

  • title : Notification title.

  • options : Notification options. set body, tag, icon here. See also (https://developer.mozilla.org/en-US/docs/Web/API/Notification/Notification)

  • swRegistration : ServiceWorkerRegistration. Use this prop to delegate the notification creation to a service worker. See also (https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/showNotification) ⚠️ onShow, onClick, onClose and onError handlers won't work when notification is created by the service worker.

Usage example

See example

yarn
yarn run start:example

Tests

yarn test

Update dependencies

Use npm-check-updates

Known Issues

License

FOSSA Status

react-web-notification's People

Contributors

alexnisnevich avatar dependabot[bot] avatar dreamsofimran avatar emirotin avatar foso avatar fossabot avatar georgeosddev avatar jfsiii avatar mariusbrn avatar yanivkalfa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-web-notification's Issues

depending on library

Is there anyway for me to import from 'react-web-notification' as opposed to '../src/components/Notification' ? I believe its more dependable and safer.

React 16

Hi,

I'm having an error similar to this.

Could you update the peer dependencies?

Thanks

no longer showing notifications on latest chrome

I recently updated chrome, and noticed a few of my projects using this lib no longer show notifications. The sound onOpen callback actually does fire, but the notification itself does not show. I have my webpack build pointed to the latest commit on master currently to ensure I have picked up any fixes recently, no luck.

ReferenceError: window is not defined

I am having an issue with creating a Web Notification when I create my own component that uses your lib. It works when I load the app first and then I navigate to another page and I reference your Notification lib from my component. It doesn't work when I load it on the first page that gets loaded.

Not sure how to work around this. I am just wondering if there is a way to check for window and if the feature is available somewhere else besides the constructor.

Typings for Typescript

Have you ever thought about adding Typescript typings to your project? I would really appreciate it.

Why did you choose the latest React as the dependency?

I mean, lower version could also work, right?

You should not use the latest React, otherwise all projects have to upgrade to the latest React, it's gonna be a huge change for old projects, or even new projects, that will make many potential users give up your library, I suggest you make your lib be compatible at least from React v15.5.4, cause that's the most stable version so far, besides, the notification API has nothing to do with latest React APIs, plus the latest React is not stable enough.

firebase-messaging-sw.js is not updated in browser

Hi, I updated the firebase-messaging-sw.js file and I had to unregister it manually in browser to update it, but I can't ask the users to do that it should be done programmatically, is there any way to solve that.

Update gh-pages to use latest version

The demo at https://georgeosddev.github.io/react-web-notification/example/ does not work in Chrome Stable (ver 62)

The following messages are in the console:

  • [Violation] Only request notification permission in response to a user gesture.
  • Permission Denied

I believe this is because the gh-pages branch is using an old version of the component which fires requestPermission in componentDidMount instead of in response to a user action. I see this has been changed in master.

Not working in IE11

Hi Team,

This component is really fit for my requirement where I need to display notifications. I am seeing one issue, looks like it is not working in IE. Can you please let us know do we need to change any browser settings for this to work in IE.

Thanks

Playing a sound

Hey, I'm using a mp3 link in options.sound to play when the notification opens, but I can't get it to work.
Does it work on your side?
Am I missing something?

Thanks!

Multiple identical notifs, for multiple opened tabs

Hi,
my app receives socket.io notifications which I display as web notifications.
If multiple instances of my app are opened in multiple browser tabs, I get as many identical notifs as the number of opened tabs (which seems quite logical). I'm using the "tag" option in the options object to prevent this behaviour, but nothing seems to change.

Am I missing something regarding tags?

Thanks a lot

Compile before publishing

Great component! :-)

But I have a problem using it in a webpack project. When I configure webpack to exclude: /node_modules/ the component doesn't get compiled. The result is at least an error with the JSX in the render function.

I saw at other projects, that the components are published in a compiled format, like a recent one from gaearon: https://github.com/gaearon/react-proxy

Do you have other suggestions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.