npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-service-worker-emberfire-messaging

v1.0.0

Published

Firebase Cloud Messaging service worker support for Emberfire apps.

Downloads

5

Readme

Build Status Ember Observer Score Ember Version

ember-service-worker-emberfire-messaging

A push notification Ember Service Worker plugin for Firebase Cloud Messaging using Emberfire.

Installation

ember install ember-service-worker-emberfire-messaging

Configuration

Step 1: basic setup is done in the config/environment.js file:

// Ensure Emberfire is correctly configured
var ENV = {
  firebase: {
    appId: 'abc',
    apiKey: 'xyz',
    authDomain: 'YOUR-FIREBASE-APP.firebaseapp.com',
    databaseURL: 'https://YOUR-FIREBASE-APP.firebaseio.com',
    storageBucket: 'YOUR-FIREBASE-APP.appspot.com',
    projectId: 'my-firebase-app', // optional
    messagingSenderId: "123456789012" // Required!
  }
};

Message sender Id can be found in your firebase console > project settings > add app button > Add Firebase to your web app.

Set GCM Sender ID

Step 2: gcm_sender_id must be configured in your manifest.json file. For this purpose I recommend using Ember Web App where in your config/manifest.js you should add the following:

module.exports = function() {
  return {
    // ...
    // gcm_sender_id: '103953800507'
  };
}

This Google Cloud Sender ID is not the same as your message sender ID. You can simply copy the value 103953800507 into your manifest.json!

Request User Permission

Step 3: Use the Firebase Message Service to request the user's permission and subscribe to new message events.

import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

export default Route.extend({
  firebaseMessage: service(),

  actions: {
    requestUserPermission() {
      /*
       Before you can receive any messages you need to request the users'
       permission to get push notifications
       */
      this.get('firebaseMessage').initialize()
      .then((token) => { // FCM registration token
        // Homework: persist this token to your server!
      });
    }
  },

  init() {
    this._super(...arguments);

    /*
     React to Firebase message when app is being viewed by user
     */
    this.get('firebaseMessage').subscribe((message) => {
      console.log('FCM JSON', message);
    });
  }
});

Misc Options:

Customize this addon by adding any of the following to the config/environment.js file:

var ENV = {
  'esw-emberfire-messaging': {
    firebaseVersion: '7.15.0', // default (Firebase version used by SW)
    defaultBackgroundMessageTitle: 'New Message', // default (fallback title for background message)
    notification: { vibrate: [200, 100, 200] } // optional global notification settings
  }
};

Possible global notification options will be overwritten by any individual FCM notification options. Browser support of various notification options may vary.

Triggering a Firebase Message

To test your app's Firebase Messaging try the following in the terminal:

curl -X POST -H "Authorization: key=<YOUR_SERVER_KEY>" -H "Content-Type: application/json" -d '{
  "data": {
    "title": "Portugal vs. Denmark",
    "body": "5 to 1",
    "icon": "firebase-logo.png",
    "click_action": "http://localhost:4200"
  },
  "to": "<DEVICE_REGISTRATION_TOKEN>"
}' "https://fcm.googleapis.com/fcm/send"

YOUR_SERVER_KEY can be found in the firebase console under Project Settings > Cloud Messaging > Server key. DEVICE_REGISTRATION_TOKEN is the token you requested via this addon's firebase-message service.

Please refer to the Firebase docs for more information

Contributing

  • git clone <repository-url> this repository
  • cd ember-service-worker-emberfire-messaging
  • yarn

Installation

ember install ember-service-worker-emberfire-messaging

Usage

[Longer description of how to use the addon in apps.]

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.