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

sockizy

v1.1.2

Published

Fast and low overhead WebSocket lib for your Games

Downloads

19

Readme

Codacy

npm -g install sockizy
git clone https://github.com/Daeren/sockizy.git

Goals:

  1. Low memory usage;
  2. Maximum performance;
  3. Flexibility;
  4. Games.

Index

Server:

const sockizy = require("sockizy");

//-----------------------------------------------------

const io = sockizy(1337, {
    "packets": [
        null, // srv.on
        null, // srv.emit
        {     // srv.on + srv.emit
            "chat.message": [
                "uid:uint32",
                "text:str8"
            ]
        }
    ]
});

//-----------------------------------------------------

io.on("connection", function(socket, request) {
    socket.on("chat.message", function() {
        const bytes = this.emit("chat.message", {uid: 13, text: "Hello"});
        console.log("Number of bytes sent:", bytes);
    });
});

Client:

<script src="//localhost:1337"></script>

<script>
    const socket = io("localhost:1337");
    socket.on("chat.message", console.log);
</script>

SSL

const ssl = {
    "dir":       "/www/site",

    "key":       "/3_site.xx.key",
    "cert":      "/2_site.xx.crt",
    "ca":       [
        "/AddTrustExternalCARoot.crt",
        "/COMODORSAAddTrustCA.crt",
        "/COMODORSADomainValidationSecureServerCA.crt"
    ]
};

//-----------------------------------------------------

const io = sockizy(1337, {ssl, "maxPayload": 1024});

Verify

/*
    const info = {
        "origin": request.headers.origin,
        "secure": request.connection.authorized !== undefined || request.connection.encrypted !== undefined,
        "req":    request
    };
*/

// Async

io.verifyClient(function(info, callback) {
    setTimeout(callback, 1000 * 2, false, 400, "Client verification failed");
});

// Sync

io.verifyClient(function(info) {
    return true;
});

Packets

// (!) order is important


// Server

io.packets(
    // Unpack | server.socket.on
    {
        "rtt": null
    },

    // Pack | server.socket.emit
    {
        "rtt": null,

        "game.monster": [
            "lvl:uint8",
            "hp:uint8"
        ]
    },

    // Shared | server.socket.on | server.socket.emit
    {
        "user.gold": "uint16",
        "chat.message": [
            "uid:uint32",
            "text:str"
        ],
        "game.hero": [
            "name:str32",
            "lvl:int8",
            "hp:uint8",
            "x:uint16",
            "y:uint16"
        ]
    }
);


// Client

socket.packets(
    // Pack | server.socket.on
    {
        "rtt": null
    },

    // Unpack | server.socket.emit
    {
        "rtt": null,
        "game.monster": [
            "lvl:uint8",
            "hp:uint8"
        ]
    },

    // Shared | server.socket.on | server.socket.emit
    {
        "user.gold": "uint16",
        "chat.message": [
            "uid:uint32",
            "text:str"
        ],
        "game.hero": [
            "name:str32",
            "lvl:int8",
            "hp:uint8",
            "x:uint16",
            "y:uint16"
        ]
    }
);


// Server

io.emit("user.gold", 20);
io.emit("game.monster", {lvl: 13, hp: 69});


// Client

socket.on("game.monster", console.log);


// Server or Client

socket.emit("rtt");
socket.emit("chat.message", [0, "Helword"]);

socket.emit("game.hero", {name: "D", lvl: 13, hp: 69, x: -8, y: -8});
socket.emit("game.hero", ["D", 13, 69, -8, -8]);

Bundle (only Server)

io.packets(
    null,
    null,
    {
        "on.arg.asArray.zCopy ([])": [
            "text:str"
        ],
        "on.arg.asArray.new ([@])": [
            "text:str"
        ],

        "on.arg.asHashTable.zCopy.default": [
            "text:str"
        ],
        "on.arg.asHashTable.new ({@})": [
            "text:str"
        ]
    }
);

io.on("connection", function(socket, request) {
    socket.on("on.arg.asHashTable.new", function(data) {
        const bd = this.bundle(true);

        for(let i = 0; i < 10; ++i) { 
            bd.write("on.arg.asArray.zCopy", {text: `Helword: ${i}`});
        }

        bd.write("on.arg.asArray.zCopy");
        bd.end("on.arg.asArray.zCopy");
    });
});

Packet type

| Name | Alias | Note | |---------------------|---------|------------------------------------------------------------------| | | - | | | bin<size (byte)> | b | default: 1024 (0-65535); server: Buffer; client: Uint8Array; | | str<size (byte)> | s | default: 256 (0-65535) | | int<size (bit)> | i | size: 8, 16, 32, 64 (BigInt64Array) | | uint<size (bit)> | u | size: 8, 16, 32, 64 (BigUint64Array) | | float<size (bit)> | f | size: 32, 64 | | json<size (byte)> | j | default: 8192 (0-65535) |

Server options

| Name | Note | |-------------------|------------------------------------------| | | - | | port | default: undefined | | host | default: * | | server | default: http.Server | | path | default: "/" | | | - | | ssl | | | | - | | maxPayload | default: 1024 * 32 | | perMessageDeflate | default: false | | noDelay | default: true | | | - | | ping | default: {"interval": 10000} (ms) | | clientJs | default: true | | packets | dependencies: clientJs;(autointegration) |

Bundle: app.bundle(), socket.bundle([isBroadcast])

| Name | Note | |-------------------|--------------------------------------| | | - | | write(name, data) | returns: number of bytes written | | end([name, data]) | returns: number of bytes sent |

Server: app([port, options])

| Name | | Note | |-----------------------------------------------|---------------------|---------------------------------------------| | | app.property | | | wss | | uws | | | app.method | | | emit(name[, data]) | | returns: number of bytes sent | | bundle() | | | | text(data) | | | | json(data) | | | | broadcast(data[, options]) | | native | | | - | | | listen([port, host, callback]) | | default: "localhost:1337" | | close([callback]) | | | | | - | | | packets([unpack, pack, shared]) | | return this; | | verifyClient(func(info[, callback])) | | return this; | | sendPacketTransform(func(type, data)) | | return this; | | recvPacketTransform(func(data)) | | return this; | | | - | | | on(name, listener) | | return this; | | off([name, listener]) | | return this; | | | app.events | | | connection (socket, request) | | | | close (socket, code, reason, wasClean) | | | | packet (name, data, socket, accept) | | | | listening () | | | | error (e) | | | | | socket.property | | | readyState | | number (read only) | | upgradeReq | | object (read only) | | | - | | | remotePort | | (read only) | | remoteAddress | | (read only) | | remoteFamily | | (read only) | | | socket.method | | | emit(name, [data, isBroadcast]) | | returns: number of bytes sent | | bundle([isBroadcast]) | | | | text (data[, isBroadcast]) | | | | json (data[, isBroadcast]) | | | | send(data[, options]) | | native | | | - | | | disconnect([code, reason]) | | code: 4000-4999 | | terminate() | | | | | - | | | ping([message]) | | | | | - | | | on(name, listener) | | return this; | | once(name, listener) | | return this; | | off([name, listener]) | | return this; | | | socket.events | | | close (code, reason, wasClean) | | | | disconnected (code, reason) | | | | terminated (code) | | | | error (e) | | | | | - | | | message (data) | | | | text (data) | | | | json (data) | | | | arraybuffer (data) | | intercepts and blocks unpacking of packets | | | - | | | ping (message) | | | | pong (message) | | | | | - | | | myEvent (data) | | |

Client options

| Name | Note | |---------------------------|--------------------------------------| | | - | | secure | | | reconnectionDelay | default: 1 sec (minimum) | | reconnectionAttempts | default: Infinity |

Client: app([url, options])

| Name | | Note | |--------------------------------------|------------------|---------------------------------------------| | | app.property | | | url | | string (read only) | | reconnecting | | bool (read only) | | bufferedAmount | | number (read only) | | readyState | | number (read only) | | | app.method | | | emit(name[, data]) | | returns: number of bytes sent | | text(data) | | | | json(data) | | | | send(data) | | native | | | - | | | disconnect(code, reason) | | code: 4000-4999 | | | - | | | packets([pack, unpack, shared]) | | return this; | | sendPacketTransform(func(type, data))| | return this; | | recvPacketTransform(func(data)) | | return this; | | | - | | | on(name, listener) | | return this; | | once(name, listener) | | return this; | | off([name, listener]) | | return this; | | | app.events | | | restoring (attempts) | | | | restored (attempts) | | | | unrestored (attempts) | | | | | - | | | open () | | | | close (code, reason, event) | | code: 1003 - invalid packet | | disconnected (code, reason, event) | | | | terminated (code, event) | | | | | - | | | message (data, event) | | | | text (data, event) | | | | json (data, event) | | | | arraybuffer (data, event) | | intercepts and blocks unpacking of packets | | packet (name, data, accept) | | | | error (e) | | | | | - | | | myEvent (data) | | |

License

MIT


@ Daeren @ Telegram