0.7.0 • Published 4 years ago

@jurijtokarski/firepush v0.7.0

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

Firebase Cloud Messaging web-push helper

Install

npm i @jurijtokarski/firepush or yarn add @jurijtokarski/firepush.

Example

import { FirePush } from "@jurijtokarski/firepush";

const isLocalhost = Boolean(
  window.location.hostname === 'localhost' ||
  window.location.hostname === '[::1]' ||
  window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/)
);

if (isLocalhost) {
  return;
}

if (!window.firebase?.messaging || !window.firebase.messaging.isSupported()) {
  return;
}

const KEY = "--your-vapid-key--";

new FirePush(window.firebase.messaging(), KEY)
  .initialize()
  .setCallback((payload: any) => {
    const notification = new Notification(payload.notification.title, {
      body: payload.notification.body
    });

    notification.addEventListener("click", function () {
      window.open("/");
      notification.close();
    });
  });

Definitions

Feel free to check TypeScript's definitions for the package.

0.7.0

4 years ago

0.6.0

4 years ago

0.5.0

4 years ago

0.4.0

4 years ago

0.3.5

4 years ago

0.3.4

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago