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

eims-hub

v0.4.5

Published

websockets with reconn, backoff, serialization, pub sub, req res

Downloads

2

Readme

Hub

hoob

Here's a simple client side websocket utililty tool. Create a websocket, audo de/serialize messages across the sockect, auto reconnect with stepped backoff, manage pub/sub style subscribtions to channels on a corresponding server.

~~Uses eims-rest-contract to standardize read/write message payloads and assist~~ ~~in some bookeeping involing message ids, timestamps, and the like.~~ lies

Tests

Gargabe. Tried using Karma to test in like, every friggin browser man it's awesome and it kinda worked. Worth circling back on.

Might work up a suite and mock the WebSocket, but that may be more beneficial as practice as anything.

API

Hub

hub constructor, sets up config for backoff, WebSocket creation, internal message buffer, does some light sanity checking.

Parameters

  • opts Object
    • opts.url string Server endpoint hosting websocket
    • opts.subscribePath string Server side message endpoint that services channel subscriptions. (optional, default '/api/join')
    • opts.factor number Backoff step factor ("to be increased by") (optional, default 200)
    • opts.max number Ceiling for backoff wait time (optional, default 2000)

write

Serialize and write data to WebSocket. Given to the WebSocket instance but bound to the Hub instance.

Parameters

  • data any serializeable object to be sent across socket

request

Write a message to the server expecting a response to come back keyed with the same requestId as aformentioned write.

Parameters

  • req object Request object to be written to WebSocket. Will be deocorated with uuid.v1 and pending = true.

Returns Promise Rejects if error property present on payload from server, resolves otherwise.

subscribe

Initiate write to WebSocket to communicate interest in subscribing to messages across a given channel. Pass subscribePath as option to constructor to configure "endpoint" used to initiate subscription on server.

Parameters

  • channel string Name of channel, to be send on body.channel property of outgoing message.
  • topic string Optional topic in channel, could be used as a sort of subcategory of interest.
  • cb subscribeCallback Callback to be invoked on each message written to channel by server.

unsubscribe

Send message to server indicating desire to unsubscribe from given channel.

Parameters

  • channel string Name of channel to unsub from.
  • cb function Reference to the callback originally passed on subscription creation.

prototype

Create a new websocket and hold the ref to it internally. Also decorates the new WebSocket with a write method to serialized outgoing messages.

subscribeCallback

Type: Function

Parameters

  • msgData object message coming from server