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

xsocket

v1.0.47

Published

WebSocket server/client module

Downloads

94

Readme

xSocket

##Server:

// Init
const xSocket = require('xsocket');

const xServer = new xSocket.Server({
    'port' : 8752, // Port listen
    'socketObjectTimeout' : 30000, // (Not necessary) Allows the user to reconnect within 30 seconds (Default: 0)
    'https' : {
        "cert" : "<path>/cert.pem",
        "key" : "<path>/private.key>"
    }
});

xServer.on('error', (err) => {
    console.log(err);
});

xServer.on('listen', () => {
    console.log('Listen event', xServer.getPort());
});

xServer.on('connect', (xSocketObject) => {

    console.log(
            'Connect event:',
            xSocketObject.getID(), // ID
            xSocketObject.getIP(),  // IP
            xSocketObject.getOrigin(), // Origin url
            xSocketObject.getQuery(), // Clent query (You can transfer data, for example, for authorization)
            xSocketObject.getReqHeaders() // All headers request
    );

    // Data message event
    xSocketObject.on('data', (xSocketData) => {
        console.log(
            'Data event', 
            xSocketData.getID(),   // ID message
            xSocketData.getType(), // Type message
            xSocketData.getData()  // Data
        );

        // Timeout 5s and response
        setTimeout(() => {
            xSocketData.response({'welcome' : 'Hello ' + xSocketObject.getQuery()['name']}, false).then(function (){
                console.log('Response send success', xSocketData.getID());
            }).catch(function (e) {
                console.log('Response send failed', xSocketData.getID(), e.message);
            });
            // OR
            // xSocketData.response({}, 'Permision denied');
        }, 5000);
    });

    // Disconnect event
    xSocketObject.on('disconnect', (xSocketObject, message) => {
        console.log('Disconnect event:', xSocketObject.getID(), message);
    });

    // Reconnect event (Only works if 'socketObjectTimeout' is specified)
    xSocketObject.on('reconnect', (xSocketObject) => {
        console.log('Reconnect event:', xSocketObject.getID());
    });

    // Destroy SocketObject
    xSocketObject.on('destroy', (xSocketObject, msg) => {
        console.log('Destroy event:', xSocketObject.getID(), msg);
    });
});

// Listen
xServer.listen().then(() => {
    console.log('Listen then');
}).catch(() => {
    console.log('Listen error', e.message);
});

##Client (ECMAScript 5+):

// Init 
var xSocket = require('xsocket'); // OR web <script type="text/javascript" src="./xSocket.min.js"></script>

var xClient = new xSocket(['wss://server_domain.com:8752'], {'name' : 'Bob'}); // Or xSocket.Clent()

// Error event
xClient.on('error', function (err) {
    console.log(err);
});

// Connect event
xClient.on('connect', function (xSocketObject) {
    console.log('connect event:', xSocketObject.getID());


    // Send message 
    xSocketObject.send(
        'helloServer', // Name message
        {'message' : 'Hello server'}, // Data message
        2000 // TTL (ready response (default: 5s)
        ).then(function(xSocketData){
            console.log('Send to server message #'+xSocketData.getID(), xSocketData.getType, xSocketData.getData());
            
            // Ready response
            xSocketData.on('response', function (xSocketData, error){
                if(error){
                    return console.error('Server responsed error', e.message);
                }
                console.log('Server responsed #'+xSocketData.getID(), xSocketData.getType, xSocketData.getResData());
            });
    }).catch(function (e){
        console.log('Message not sended, info:', e.message);
    });
    // OR
    //xSocketObject.sendReady(
    //    'helloServer', // Name message
    //    {'message' : 'Hello server'}, // Data message
    //    2000 // TTL (ready response (default: 5s)
    //).then(function (xSocketObject){
    //    console.log('Server responsed #'+xSocketData.getID(), xSocketData.getType, xSocketData.getResData());
    //}).catch(function (e){
    //    console.error('Server responsed error', e.message);
    //});
    
});

// Reconnect event (Only works if 'socketObjectTimeout' is specified)
xClient.on('reconnect', function (xSocketObject) {
    console.log('reconnect event', xSocketObject.getID());
});

// Disconnect event
xClient.on('disconnect', function(xSocketObject, msg) {
    console.log('disconnect', xSocketObject.getID(), msg);
});

// Destroy SocketObject
xClient.on('destroy', function(xSocketObject) {
    console.log('destroy', xSocketObject.getID(), xSocketObject.getSign());
});