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 🙏

© 2025 – Pkg Stats / Ryan Hefner

dugmm-client

v0.0.1

Published

A TypeScript/JavaScript client wrapper for Socket.IO communication with the game server.

Readme

Game Client

A TypeScript/JavaScript client wrapper for Socket.IO communication with the game server.

Features

  • Room Management: Create, join, and manage game rooms.
  • Player Management: Handle player identity and state.
  • State Synchronization: Real-time updates for room and player data.
  • Host Controls: Specific privileges for host clients.
  • Reconnection: Built-in support for reconnecting players.

Setup

Save the built client file (e.g., client.js) to your project directory. This file includes necessary dependencies.

Usage

Initialization

Instantiate the Client class with your configuration. You define event handlers in the on property.

import { Client } from './client.js'; // Adjust path to your saved file

const client = new Client({
    isHost: false, // Set to true if this client controls the room
    url: "http://localhost:3000", // Server URL
    on: {
        // Define hooks for events
        createPlayer: {
            success: (data) => {
                console.log("Joined room successfully", data);
            },
            error: (msg) => {
                console.error("Failed to join:", msg);
            }
        },
        updateRoom: {
            broadcast: (data) => {
                // Parse the room data string
                const gameState = JSON.parse(data.room.data);
                console.log("New game state:", gameState);
            }
        }
    }
});

Methods

Room Actions

  • createRoom()

    • Host only. Creates a new room on the server.
    • Triggers: createRoom (success).
  • getRoom(roomKey: string)

    • Retrieves current room state.
    • Triggers: getRoom (success).
  • updateRoom(roomKey: string, data: any)

    • Host only. Updates the shared room data. data is automatically stringified if it is an object.
    • Triggers: updateRoom (success, broadcast).
  • deleteRoom(roomKey: string)

    • Host only. Deletes the room and disconnects all players.
    • Triggers: deleteRoom (success, broadcast).

Player Actions

  • createPlayer(displayName: string, roomKey: string)

    • Joins a room as a new player.
    • Triggers: createPlayer (success, broadcast).
  • getPlayer(id: number)

    • Retrieves specific player info.
    • Triggers: getPlayer (success).
  • getPlayersInRoom(roomKey: string)

    • Retrieves list of all players in a room.
    • Triggers: getPlayersInRoom (success).
  • updatePlayer(id: number, data: any)

    • Updates player-specific data. data is automatically stringified if it is an object.
    • Triggers: updatePlayer (success, broadcast).
  • deletePlayer(id: number)

    • Removes a player from the room.
    • Triggers: deletePlayer (success, broadcast).

Connection

  • reconnect(id: number)

    • Re-establishes connection for an existing player ID.
    • Triggers: reconnect (success, broadcast).
  • disconnect()

    • Manually disconnects the socket.

Event Hooks

The on object allows you to listen for responses and server broadcasts.

Structure of Handlers:

type Handlers<T, U = T> = {
    success?: (data: T) => void;    // Response to your action
    broadcast?: (data: U) => void;  // Notification from other clients/server
    error?: (message: string) => void; // Error response
}

Available Hooks

| Hook | Description | Success Data | Broadcast Data | | :--- | :--- | :--- | :--- | | createRoom | Room created | { key } | N/A | | createPlayer | Player joined | { id, player, players } | { id, player, players } | | getPlayer | Get player info | { player } | N/A | | getRoom | Get room info | { room } | N/A | | getPlayersInRoom | Get player list | { players } | N/A | | updateRoom | Room data updated | { room, players } | { room, players } | | updatePlayer | Player data updated | { player, id } | { player, id, time } | | deletePlayer | Player removed | { success } | { player } | | deleteRoom | Room deleted | { success } | { roomKey } | | reconnect | Player reconnected | { player, room } | { player, room } | | disconnect | Player disconnected | N/A | { player, id } |

Data Structures

Room

{
    key: string;
    data: string; // JSON stringified data
    createdAt: number;
    updatedAt: number;
}

Player

{
    id: number;
    displayName: string;
    roomKey: string;
    data: string; // JSON stringified data
    connected: number; // 1 or 0
    createdAt: number;
    updatedAt: number;
}