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

pushflash

v0.2.7

Published

Notify web app users about background tasks

Downloads

1

Readme

Pushflash

Uses Redis, Socket.io, and Humane.js to make it easy to notify any user of your web app of something that happened.

Server:

var pushflash = require('pushflash');

pushflash(app, server);

Client:

<link rel="stylesheet" href="/pushflash.css">
<script src="/pushflash.js"></script>
<script>
  Pushflash('my_user_id'); // new messages on this channel will appear automatically
</script>

Worker:

var pushflash = require('pushflash');
pushflash.publish('some_user_id', 'error', "something broke!");

Installation

$ npm install pushflash

Usage

Server-side

Express Application Server

For the Application server, you simply call the exported function on your Express application, your HTTP/S server, and with any options you want.

var app = express();
var server = http.createServer(app);

pushflash(app, server, options);

The options available are:

  • namespace The Socket.io namespace for passing notifications. Defaults to /notifications
  • client.name The name that gets exposed on window for the client-side script. Defaults to Pushflash
  • client.path The path where the client-side script can be retrieved. Defaults to /pushflash.js
  • css.theme The CSS theme from humane.js you'll be using. Defaults to jackedup
  • css.path The path where the client-side css can be retrieved. Defaults to /pushflash.css
  • authorize Function called when a client connects to Pushflash with the Socket.io handshake data and a callback. Callback with (null, true) if the client is authorized.
  • authorizeChannel Function called when a client connects to Pushflash with the Socket.io handshake data, the channel id, and a callback. Callback with (null, true) if the client is authorized.
  • redis.port Port number of the redis server. Defaults to 6379.
  • redis.host Host name of the redis server. Defaults to localhost.

The returned value is a Manager instance, but you don't need to do anything with it.

Worker Server

This can be the same server as the Application server, but it doesn't have to be (that's the whole point of Pushflash).

You can use the convenience .publish function like this:

pushflash.publish(channel, options, messageType, messageBody);

The options available are the same as the redis. options for the Applications server.

You can also create a dedicated Publisher instance, by calling the Publisher constructor:

var publisher = new pushflash.Publisher(channel, options);

And send messages with this publisher with the send method:

publisher.send('info', "some info");

Client-side

To use the client-side script, just define a script with the src tag set to the client.path defined in the Application Server options, which defaults to /pushflash.js. Also add a stylesheet to use the styles for humane.js.

<link rel="stylesheet" href="/pushflash.css">

<script src="/pushflash.js"></script>

This will create a global variable with the name of client.name defined in the Application Server options, which defaults to Pushflash.

To subscribe to a channel, just call the Pushflash function with the name of the channel to subscribe to and any options you want.

Pushflash(channel, opts);

The options available are:

  • namespace The Socket.io namespace for passing notifications. Defaults to /notifications
  • baseClass The humane.js baseClass to use for styling notifications. Defaults to humane-jackedup.

Message Types

By default, Pushflash defines the following message types:

  • error - Used both for Socket.io errors, Redis pubsub errors, and user space errors.
  • unauthorized - Used internally for authorization problems.
  • info - Informational messages.
  • success - Success messages.

To add additional message types, just add them to the client instance:

var pushflash = Pushflash('my_channel');

pushflash.addMessageType('custom', 'success'); // adds a `custom` message type that is styled like a `success` message.

Then you can publish messages of that type on the server:

var pushflash = require('pushflash');

pushflash.publish('my_channel', 'custom', 'some custom message goes here.');