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

socket.io.users

v2.0.2

Published

This module finds and manages which socket is from who and visa versa. One user per person. User means: Unlimited (new) browser tabs/windows but same machine. OR You can pass custom authorized id and have one user with it's sockets per group of different

Downloads

122

Readme

socket.io.users

This is a node js module for socket.io applications. This module finds and manages which socket is from who and visa versa. One user per person. User means: Unlimited (new) browser tabs/windows but same machine. OR client can pass custom authorized id and have one user with it's sockets per group of different machines. Make use of the middleware.

Installation

$ npm install socket.io.users

[NPM] https://www.npmjs.com/package/socket.io.users

Live Example (Greek language)

Go to http://chat.ideopod.com

Usage

var express = require('express');
var app = express();
var server = require('http').createServer(app);
var socketUsers = require('socket.io.users');

socketUsers.Session(app);//IMPORTANT

var rootIo = require('socket.io')(server); //default '/' as namespace.
var chatIo = rootIo.of('/chat');


var rootUsers = socketUsers.Users; /* default '/' as namespace. Each namespace has IT's OWN users object list,
but the Id of a user of any other namespace may has the same value if request comes from the same client-machine-user.
This makes easy to keep a kind of synchronization between all users of all different namespaces. */

var chatUsers = socketUsers.Users.of('/chat'); //


rootIo.use(socketUsers.Middleware());//IMPORTANT but no errors if you want to skip it for a io.of(namespace) that you don't want the socket.io.users' support.

chatUsers.use(socketUsers.Middleware());

chatUsers.on('connected',function(user){
    console.log(user.id + ' has connected to the CHAT');
    user.set('username', 'username setted by server side'); /*at the store property you can store any type of properties
    and objects you want to share between your user's sockets. */
    user.socket.on('any event', function(data){ //user.socket is the current socket, to get all connected sockets from this user, use: user.sockets

    });
    chatIo.emit('set username',user.get('username')); //or user.store.username
});

rootUsers.on('connected',function(user){
    console.log('User has connected with ID: '+ user.id);
});



rootUsers.on('connection',function(user){
    console.log('Socket ID: '+user.socket.id+' is user with ID: '+user.id);
});

rootUsers.on('disconnected',function(user){
    console.log('User with ID: '+user.id+'is gone away :(');
});



//You can still use the io.on events, but the execution is after connected and connection of the 'users' and 'chatUsers', no matter the order.
rootIo.on('connection',function(socket){
    console.log('IO DEBUG: Socket '+ socket.id+ ' is ready \n');
});

Look at the Example folder for a complete example using: Server side: express js,socket.io,socket.io.users. Client side: AngularJS,socket.io,bootstrap,jquery.

GPL-3.0 Licensed