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 🙏

© 2026 – Pkg Stats / Ryan Hefner

sc-presence

v0.1.14

Published

Socket Presence Module for SocketCluster

Readme

sc-presence

Socket Presence Module for SocketCluster

Features

Track active users in your SocketCluster based application Store all active socket data and channel subscriptions across multiple workers or hosts Built-in garbage collection prunes abandoned or inactive records Simple to install and use. Requires only a MySQL db and a single line of code. Publishes a user count update whenever someone joins or leaves Works with or without authenticated users

Install

Create Database
CREATE DATABASE IF NOT EXISTS `SCPresence`;
USE SCPresence;

DROP USER 'SCP_user'@'localhost';
FLUSH PRIVILEGES;
CREATE USER 'SCP_user'@'localhost' IDENTIFIED BY 'putyourpasswordhere';
GRANT SELECT ON `SCPresence`.* TO 'SCP_user'@'localhost'; 
GRANT INSERT ON `SCPresence`.* TO 'SCP_user'@'localhost'; 
GRANT UPDATE ON `SCPresence`.* TO 'SCP_user'@'localhost'; 
GRANT DELETE ON `SCPresence`.* TO 'SCP_user'@'localhost'; 
GRANT EXECUTE ON `SCPresence`.* TO 'SCP_user'@'localhost'; 


CREATE TABLE IF NOT EXISTS `SCPresence_users` (
  SCP_id INT(11) NOT NULL AUTO_INCREMENT,
  SCP_socket_id VARCHAR(255) DEFAULT NULL,
  SCP_user_id INT(11) DEFAULT NULL,
  SCP_channel VARCHAR(255) DEFAULT NULL,
  SCP_updated DATETIME DEFAULT CURRENT_TIMESTAMP,
  SCP_authToken VARCHAR(2048) DEFAULT NULL,  
  SCP_ip VARCHAR(255) DEFAULT NULL,
  SCP_origin VARCHAR(1024) DEFAULT NULL,
  PRIMARY KEY (SCP_id),
  UNIQUE INDEX IX_unique_user_channel_socket (SCP_user_id, SCP_channel, SCP_socket_id)
)
ENGINE = INNODB;
Install NPM Package
npm install sc-presence
Attach sc-presence to your workers
module.exports.run = function (worker) {
    require('sc-presence').attach(worker, options);
};

Options

Only scpDbhost and scpDbpassword are required

scpGcWorkerId The worker id of the worker that will handle sc-presence garbage collection duties Default Value: 0

scpGcInterval The interval in number of seconds on which the garbage collection process will run Default Value: 60

scpGcThreshold The number of seconds that must pass without an update before the garbage collection process will remove a record Default Value: 120

scpBlockUsercountThreshold The number of seconds sc-presence will wait after startup before starting to publish user count updates. This prevents sc-presence from spamming user count updates when the system is restarted and sockets are reconnecting. Default Value: 60

scpSCPingsPerUpdate The number of scServer.pingInterval periods that must pass before sc-presence will fire a database update Default Value: 6

scpUsercountChannel The name of the channel on which sc-presence will publish user count updates Default Value: "USERCOUNT"

scpUsercountType The type of user count update sc-presence will publish when a user joins or leaves Possible values are: "SUBSCRIPTIONS", "SOCKETS", "USERS" Default Value: "USERS"

scpPresenceChannel The name of the channel that sc-presence will register primary socket presence under Default Value: "_SCPRESENCE"

scpDbhost The host name of the sc-presence db Default Value: None

scpDbname The name of the sc-presence db Default Value: "SCPresence"

scpDbTablename The name of the db table where sc-presence data is stored Default Value: "SCPresence_users"

scpDbuser The name of the db user that will authenticate to the sc-presence db Default Value: "SCP_user"

scpDbpassword The password for the db user that will authenticate to the sc-presence db Default Value: None

scpConnectUpdateDelay When a new socket connects, sc-presence will wait this many ms before publishing a user count update. This ensures the socket that connected has time to subscribe to the scpUsercountChannel channel before the user count is published Default Value: 3000

scpUserIdField The name of the property in the authToken which will be stored in the SCP_user_id field in the database (numeric or string values are ok) Default Value: "user_id"

Example
{
    
    scpGcWorkerId			    : 0,
    scpGcInterval			    : 60, 
    scpGcThreshold			    : 120,
    scpBlockUsercountThreshold	: 60,
    scpSCPingsPerUpdate         : 6,  
    scpUsercountChannel		    : "USERCOUNT",
    scpUsercountType            : "USERS",
    scpPresenceChannel			: "_SCPRESENCE",
    scpDbhost					: "dbHostname",
    scpDbname					: "SCPresence",
    scpDbTablename				: "SCPresence_users",
    scpDbuser					: "SCP_user",
    scpDbpassword				: "besuretosetpassword",        
    scpConnectUpdateDelay		: 3000,
    scpUserIdField              : "user_id"
}