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

webgram-sessions

v0.1.0

Published

recognize devices and store session state for webgram

Downloads

2

Readme

Add securely-resumable-sessions to webgram, using secrets kept in localStorage (or pseudo localStorage for node clients). Basically, makes it easy for server code to remember which client it's talking to, like cookies.

In our model, a webgram connection, when in-session, has exactly one sessionID, which is a sequence number assigned by the server and used to maintain persistent state in a leveldb. That sessionID and the associated data is available server-side as conn.sessionData. After changing it, call conn.save() and it'll be there for future connections and future runs of the server. Multiple connections from the same browser will end up sharing one sessionData object.

Clients are free to make different connections using different pairs of (sessionID, secret). This can be useful for switching user logins without re-authenticating at the user-level.

See examples/plus_one

On the client if you're just using one identity:

const webgrams = require('webgram')
const sessions = require('webgram-sessions')

const c = new webgram.Client('ws://localhost:5678')
sessions.hook(c)   // this does what it needs to

// everything else is the same
// ...

The server isn't bad: just attach the sessions plugin and ignore connections until they trigger $session-active:

const webgram = require('webgram')
const sessions = require('webgram-sessions')

const server = new webgram.Server({port: 5678})
sessions.attach(server)
server.on('$session-active', conn => {    // instead of '$opened'

  // read and write conn.sessionData including .id
  conn.save()   // after modifying

})

Hopefully this wont break when we add TLS, reconnecting, and authstreams-style cbor + encryption.

Note that conn.sessionData is the same shared object when multiple connections are made with the same sessionID, as will happen if you connect in multiple windows of the same browser. conn.save() emits $save which can be used to be notified about changes.

Some fields in sessionData are maintainted by the system:

  • _sessionID

  • _firstVistTime, _previousVisitTime, _latestVisitTime

  • _fromClient points to an object passed by client during session creation