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

instantly

v1.4.3

Published

Convenience wrapper for EventSource

Downloads

43

Readme

Instantly

instantly

Code Climate Test Coverage Travis Known Vulnerabilities

What is this?

EventSource wrapper.

The EventSource API is easy as it is. Reason I created this was to hide all logic used when I implement EventSource.

IMPORTANT. This is NOT EventSource Polyfill!

Installation

It's available on npm.

npm install --save instantly

How can I use this library?

It's an UMD module. If you don't know what UMD is: https://github.com/umdjs/umd

The UMD build is also available on unpkg:

<script src="//unpkg.com/instantly/dist/instantly.umd.js"></script>

Usage

// Example
var es = new Instantly("http://your-sse-endpoint.codes/channel", {
    origin: "http://your-sse-endpoint.codes", // Optional. Just an extra level of precaution to verify your event origin matches your app's origin.
    retries: 2, // Optional. Default: 5 retries if connection to your endpoint fails.
    timeout: 1000, // Optional. Default: 15 seconds (15000). This is how often we should retry.
    closeConnNotFocus: true, // Optional. Default: false. This will close the SSE connection if the tab/window is not in focus. Will reconnect when in focus.
    error: function(err) {
        console.log(err);
    }, // Optional. Extending the internal error handler.
    open: function(event) {
        console.log(event);
    }, // Optional. Extend when you open a connection to SSE.
    close: function() {
        console.log("closed");
    }, // Optional. Extend when a connection to SSE is closed. (Usually when an error occur)
    injectEventSourceNode: require("eventsource") // Optional. If the module is being used in Node you're able to inject [eventsource-node](https://www.npmjs.com/package/eventsource)
});

// If you want to use default options
// var es = new Instantly('http://your-sse-endpoint.codes/channel');

// Listen to messages without any event set
es.on("message", function newMessage(msg) {
    console.log(msg.data);
});

// Listen to messages with an event set
es.on("eventName", function newMessage(msg) {
    console.log(msg.data);
});

// Start to listen for events send by SSE
es.listen();

If you need to close the connection client side

// Close
es.close();

// Need to open the connection again?
es.listen();

Built in features

  • If you send an event with event id 'CLOSE', it'll close your SSE connection with no retries.

Example

Navigate to example folder

npm install
npm start

Open your browser in http://localhost:1337

High performance SSE server

SSEHub (Server-Sent Events streaming server)

Contribution

Contributions are appreciated.

License

MIT-licensed. See LICENSE.