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

sockjsio

v0.0.3

Published

Sockjsio is an extention on the great, great sockjs-node server. Providing multiroom functionality.

Downloads

9

Readme

Warning: Version 0.0.1 is in the absolute alpha fase and created by a Node beginner. I must be doing some things wrong, please feel free to correct me with feedback.

Sockjsio is a multiroom manager based on the sockjs client (https://github.com/sockjs/sockjs-client) and sockjs-node (https://github.com/sockjs/sockjs-node) server.

Dependecies are aync and sockjs. Install if not allready done

npm install sockjs
npm install async

Defining a server is plane and simple:

var sockjsio = require('./sockjsio');

sockjsio.listen( port[int], url[string], prefix[string], sendRoomNames[bool] );

If 'SendRoomNames' is true, every response to a room hase a property roomName, corresponding that roomname. Just pick a prefix like '/A', channels are not used since we use rooms.

A simple echo example:

var sockjsio = require('./sockjsio');
sockjsio.listen( 8080 , '0.0.0.0', "/A", true );

sockjsio.on('connection', function( connection )
{
connection.on('roomopen', function( roomName )
	{
	console.log(connection.id + " opened room " + roomName );
	});

    connection.join("room1");
    connection.join("room2");
    connection.leave("room2");

    connection.on('data', function( response )
        {
        	var data = JSON.parse( response );
  
        	// possible ways to send a message
        	connection.emitRoom( data.roomName, data.message );  		// Send to whole room including connection
        	connection.broadcastRoom( data.roomName, data.message );  	// Send to all in this room but connection
        	connection.sendRoom( data.roomName, data.message );  	    // Send to this connection if in this room

        	connection.emitClient( data.message );				        // Send to all clients on the server
        	connection.broadcastClient( data.message );			        // Send to all except connection
        	connection.sendClient( data.message );				        // Send to this connection
        	});

    var isInroom = connection.isInRoom('room1'); 				    // = true if in 'room1'	
    var joined = connection.joined(); 				                // Array with roomnames
    });

Within the connections there are some handy events they all return the roomName.

connection.on('roomopen', function( roomName )
    {
    console.log(connection.id + " opened room " + roomName );
    });
  • roomopen: fired when room hase opened.
  • roomclose : fired after a room hase closed.
  • leaving: fired when a client left a room.
  • joining: fired when a client hase joined a room.

There are two other functions within connections:

var isInroom = connection.isInRoom('room1'); 		    // Bool true / false	
var joined = connection.joined(); 				        // Array with roomnames the client joined

To make it complete:

var roomExists = sockjsio.roomExists("room2");		    // False: this user hase left the room
var usersInRoom = sockjsio.usersInRoom("room1");	    // Array with connection id's of joined sockets
var clients = sockjsio.clients();				        // Array with all connection id's on the server
var client = sockjsio.client(socketID);				    // Get a socket with that ID