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

sockem

v0.0.3

Published

A wrapper around ActionCable to ensure eventual delivery

Downloads

11

Readme

sockem

Warning: sockem is rated YMMV. At present, this repo doesn't have its own automated tests or many users.

What?

Sockem is a library that wraps the ActionCable client to "dumb it down" so that it can be used for three things:

  1. sockem.subscribe() to a single channel (SockemChannel) and automatically re-subscribe if the connection is lost for as long as the app needs it
  2. Allow the user to sockem.request(payloadObj, cb) with some assurance that the request will be retried until a matching response is received and cb(responseObj) called
  3. sockem.unsubscribe() when the channel is no longer needed

How?

$ npm install sockem
import * as sockem from 'sockem'

sockem.subscribe()

sockem.request({id: 42}, (res) => {
  document.write(res.name)
  sockem.unsubscribe()
})

And, to make that do something, a Ruby class in app/channels/sockem_channel.rb that looks something like:

class SockemChannel < ApplicationCable::Channel
  def subscribed
    stream_for current_user
  end

  def handle_answer(data)
    response = {
      name: data["id"] == 42 ? "Pants" : "Not Pants",
      request_id: data["requestId"]
    }

    self.class.broadcast_to(current_user, response)
  end
end

You'll want to set up the above current_user with some scheme that matches up the HTTP session with the channel (see: connection.rb in the example app)

Why?

Sockem is an extraction from KameSame.com that may help others who want to use ActionCable for use cases that don't resemble chat rooms or push notifications. One example might be an app that can't use HTTP2 but needs to send a lot of very small payload requests with as little latency as possible, because they block the user experience. To be more specific, this code is used by KameSame's client JS to send users' flashcard answers to the server and wait (and retry) until all the outstanding requests get a response, reconnecting as often as necessary.

Warnings

Other than lacking a test suite or many users, keep note that this library's retry mechanism can really go wild if your server ever starts spitting errors, as every affected client will essentially hammer it. If anyone's interested, adding a more sophisticated retry mechanism (like a backoff) would be an improvement. So would a retry limit.