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

youyo

v1.0.0

Published

WebSocket Wrapper for WS library

Downloads

3

Readme

YouYo!

WebSocket Wrapper for WS library

  • Minimalist
  • Dynamic Sub-Protocols
  • Communication with Clients by 'Id'
  • Some Security Options (Connections per ip, ...)
  • Configurable Automatic Ping/Pong Handling

Getting Started

Installation

YouYo! is released on npm and can be installed using:

npm install youyo --save

YouYo is dependent on ws package.

Usage (Practice A)

  1. Require: const YouYo = require('YouYo').
  2. Createing a YouYo Definer Object:
var ydo = {
	// Definer Pattern:
	origins: ['appX','appY','file://'], // Optional
	portN : {
    	pathX: { 
    		protocolY: function(message, flags){
            	var yo = this; // YouYo Socket
                return xyz; // object, string, buffer
            }
    	}
    }
}
  1. Initialize: var yoo = new YouYo(ydo);.
  2. Ignite: yoo.go(); // Returns server(s) for each port
Sample: Broadcast Server
const YouYo = require('YouYo');
var yoo = new YouYo({
    80:{
        '/':{
            broadcast: function(message, flags){
                if( !flags.binary ) this.broadcast(message);
                var onlines = this.wss.clients.length;
                return 'Your Message Broadcasted to '+ onlines +' Users' ;
            }
        }
    }
});
yoo.cpip = 10; // connection per ip;
yoo.go();

Usage (Practice B)

  1. Require: const YouYo = require('YouYo').
  2. Createing a YouYo Server on port 'x' : var yoo = new YouYo(x); yoo.go();
Sample: Echo Server
const YouYo = require('YouYo');
var yoo = new YouYo(80);
yoo.on('message', function(yo, message, flags){
	if( !flags.binary ) yo.send(message);
    else yo.send(message.length + ' Bytes Binary Message Received.');
});
yoo.go();

For more detailed examples, please take a look at: [git-repo]/Examples

Api

Instance of YouYo (yoo):

  • .go(): Ignition. Passes WS Server(s array) for each port. + each server has .broadcast() & .sendTo().
  • .broadcastAll(data, options): to all clients of all servers (ports).
  • .servers: Array of WS Servers.
  • .timeout: Socket Timeout - Milliseconds (Default 5 Minutes)
  • .mask: Mask data frames? (False)
  • .compress: Compressing data frames? (False)
  • .cpip: Connections per ip (3)
  • .ppi: Automatic Ping/Pong intervals (Default: 1 minutes)
  • .pol: At Least x Milliseconds Before Next Pong (Default: 1 Minutes)
  • .pil: x Missed Pings Toleration Limit (2)
  • .bpl: Max Bad Pings Limit >> client sends too much pings related to last pong and .pol (5)
  • .dosLimit: After n Wrong Attempts >> Possibly attacker (3)
  • .dosTimer: Delay for Next Handshake (after n wrong attempts) - Milliseconds (Default 1 Minutes)
  • .freePath: Accept connection to any path? [Boolean]
  • .origins = []; // accepted origins (Empty Array == Any)
  • .secure [Boolean] true if req.connection.authorized or req.connection.encrypted should be set to verify client.
  • Ws[s] Options:
    • .disableHixie // true;
    • .clientTracking // true;
    • .perMessageDeflate // true;
    • .maxPayload // Bytes - Default: 1MB

Instance of yo (YouYo socket):

  • .send(data, options, cb) // options{mask, binary, compress [All Boolean] }
  • .id Unique id in related server [setter/getter]
  • .sendTo(user_id_in_server, data, option, cb)
  • .broadcast(data, options) // to All Other Clients [of related server(port)]
  • .broadcastPath(data, options) // to All Other Clients [of related path]
  • .broadcastPrtcl(data, options) // to All Other Clients [of related path & protocol]
  • .ws [this websocket]
  • .wss [related server]
  • .wss.broadcast(data, options) // to All Clients of server (port)
  • .wss.sendTo(user_id_in_server, data, option, cb)

Events

Instance of YouYo is Event Emitter:

  • established: Socket Connection Established. Passes socket yo.
  • signed: Socket id had been set. Passes id and socket yo.
  • message: Recived data is ready to use. passes socket yo, data & flags (binary[boolean], masked[boolean], buffer).
  • closed: Socket's completely closed; Destroyed. passes related server, socket id, status code & message.
  • server-error: passes error and websocket-server (istance of wss).
  • socket-error: passes error and socket yo.